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)
13 // (1) Figure out why error productions dont work. `type-declaration' is a
14 // great spot to put an `error' because you can reproduce it with this input:
17 // Possible optimization:
18 // Run memory profiler with parsing only, and consider dropping
19 // arraylists where not needed. Some pieces can use linked lists.
27 using System.Collections;
32 public class CSharpParser {
33 NamespaceEntry current_namespace;
34 TypeContainer current_container;
35 TypeContainer current_class;
37 IIteratorContainer iterator_container;
40 /// Current block is used to add statements as we find
47 /// If true, creates a toplevel block in the block production
48 /// This is flagged by the delegate creation
50 bool create_toplevel_block;
52 Delegate current_delegate;
55 /// This is used by the unary_expression code to resolve
56 /// a name against a parameter.
58 Parameters current_local_parameters;
61 /// Using during property parsing to describe the implicit
62 /// value parameter that is passed to the "set" and "get"accesor
63 /// methods (properties and indexers).
65 Expression implicit_value_parameter_type;
66 Parameters indexer_parameters;
69 /// Used to determine if we are parsing the get/set pair
70 /// of an indexer or a property
75 /// An out-of-band stack.
84 public bool yacc_verbose_flag;
86 // Name of the file we are parsing
95 /// Current attribute target
96 string current_attr_target;
98 /// assembly and module attribute definition is enabled
99 bool global_attrs_enabled = true;
103 %token NONE /* This token is never returned by our lexer */
104 %token ERROR // This is used not by the parser, but by the tokenizer.
108 *These are the C# keywords
195 /* C# keywords which are not really keywords */
201 /* C# single character operators/punctuation. */
202 %token OPEN_BRACE "{"
203 %token CLOSE_BRACE "}"
204 %token OPEN_BRACKET "["
205 %token CLOSE_BRACKET "]"
206 %token OPEN_PARENS "("
207 %token CLOSE_PARENS ")"
219 %token OP_GENERICS_LT "<"
221 %token OP_GENERICS_GT ">"
222 %token BITWISE_AND "&"
223 %token BITWISE_OR "|"
230 /* C# multi-character operators. */
233 %token OP_SHIFT_LEFT "<<"
234 %token OP_SHIFT_RIGHT ">>"
241 %token OP_MULT_ASSIGN "*="
242 %token OP_DIV_ASSIGN "/="
243 %token OP_MOD_ASSIGN "%="
244 %token OP_ADD_ASSIGN "+="
245 %token OP_SUB_ASSIGN "-="
246 %token OP_SHIFT_LEFT_ASSIGN "<<="
247 %token OP_SHIFT_RIGHT_ASSIGN ">>="
248 %token OP_AND_ASSIGN "&="
249 %token OP_XOR_ASSIGN "^="
250 %token OP_OR_ASSIGN "|="
254 %token LITERAL_INTEGER "int literal"
255 %token LITERAL_FLOAT "float literal"
256 %token LITERAL_DOUBLE "double literal"
257 %token LITERAL_DECIMAL "decimal literal"
258 %token LITERAL_CHARACTER "character literal"
259 %token LITERAL_STRING "string literal"
262 %token CLOSE_PARENS_CAST
263 %token CLOSE_PARENS_NO_CAST
264 %token CLOSE_PARENS_OPEN_PARENS
265 %token CLOSE_PARENS_MINUS
266 %token DEFAULT_OPEN_PARENS
267 %token GENERIC_DIMENSION
269 /* Add precedence rules to solve dangling else s/r conflict */
278 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
280 %left STAR DIV PERCENT
281 %right BANG CARRET UMINUS
282 %nonassoc OP_INC OP_DEC
284 %left OPEN_BRACKET OPEN_BRACE
288 %start compilation_unit
292 : outer_declarations opt_EOF
293 | outer_declarations global_attributes opt_EOF
294 | global_attributes opt_EOF
295 | opt_EOF /* allow empty files */
305 | outer_declarations outer_declaration
310 | namespace_member_declaration
315 | using_directives using_directive
319 : using_alias_directive
320 | using_namespace_directive
323 using_alias_directive
324 : USING IDENTIFIER ASSIGN
325 namespace_or_type_name SEMICOLON
327 current_namespace.UsingAlias ((string) $2, (MemberName) $4, lexer.Location);
330 CheckIdentifierToken (yyToken);
334 using_namespace_directive
335 : USING namespace_name SEMICOLON
337 current_namespace.Using ((string) $2, lexer.Location);
342 // Strictly speaking, namespaces don't have attributes but
343 // we parse global attributes along with namespace declarations and then
346 namespace_declaration
347 : opt_attributes NAMESPACE namespace_name
350 Report.Error(1518, Lexer.Location, "Attributes cannot be applied to namespaces."
351 + " Expected class, delegate, enum, interface, or struct");
354 if (current_namespace.Parent != null && $3 is MemberAccess) {
355 // Cannot use qualified namespace names in nested namespace declarations
356 Report.Error (134, lexer.Location, "Cannot use qualified namespace names in nested namespace declarations");
359 current_namespace = new NamespaceEntry (
360 current_namespace, file, (string) $3, lexer.Location);
362 namespace_body opt_semicolon
364 current_namespace = current_namespace.Parent;
379 : namespace_or_type_name {
380 MemberName name = (MemberName) $1;
382 if (name.TypeArguments != null)
383 syntax_error (lexer.Location, "namespace name expected");
385 $$ = name.GetName ();
392 opt_namespace_member_declarations
403 opt_namespace_member_declarations
405 | namespace_member_declarations
408 namespace_member_declarations
409 : namespace_member_declaration
410 | namespace_member_declarations namespace_member_declaration
413 namespace_member_declaration
420 Class c = (Class) $1;
421 mod_flags = c.ModFlags;
423 } else if ($1 is Struct){
424 Struct s = (Struct) $1;
425 mod_flags = s.ModFlags;
430 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
432 1527, lexer.Location,
433 "Namespace elements cant be explicitly " +
434 "declared private or protected in `" + name + "'");
436 current_namespace.DeclarationFound = true;
438 | namespace_declaration {
439 current_namespace.DeclarationFound = true;
442 | field_declaration {
443 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
445 | method_declaration {
446 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
453 | interface_declaration
455 | delegate_declaration
457 // Enable this when we have handled all errors, because this acts as a generic fallback
460 // Console.WriteLine ("Token=" + yyToken);
461 // Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
473 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
481 global_attrs_enabled = false;
486 global_attrs_enabled = false;
495 ArrayList sect = (ArrayList) $1;
497 if (global_attrs_enabled) {
498 if (current_attr_target == "module") {
499 CodeGen.Module.AddAttributes (sect);
501 } else if (current_attr_target == "assembly") {
502 CodeGen.Assembly.AddAttributes (sect);
505 $$ = new Attributes (sect);
508 $$ = new Attributes (sect);
510 current_attr_target = null;
512 | attribute_sections attribute_section
514 Attributes attrs = $1 as Attributes;
515 ArrayList sect = (ArrayList) $2;
517 if (global_attrs_enabled) {
518 if (current_attr_target == "module") {
519 CodeGen.Module.AddAttributes (sect);
521 } else if (current_attr_target == "assembly") {
522 CodeGen.Assembly.AddAttributes (sect);
526 attrs = new Attributes (sect);
528 attrs.AddAttributes (sect);
532 attrs = new Attributes (sect);
534 attrs.AddAttributes (sect);
537 current_attr_target = null;
542 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
546 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
552 attribute_target_specifier
553 : attribute_target COLON
555 current_attr_target = (string)$1;
563 CheckAttributeTarget ((string) $1);
566 | EVENT { $$ = "event"; }
567 | RETURN { $$ = "return"; }
573 ArrayList attrs = new ArrayList (4);
579 | attribute_list COMMA attribute
581 ArrayList attrs = (ArrayList) $1;
593 opt_attribute_arguments
595 MemberName mname = (MemberName) $1;
596 if (mname.IsGeneric) {
597 Report.Error (404, lexer.Location,
598 "'<' unexpected: attributes cannot be generic");
601 string name = mname.GetName ();
602 if (current_attr_target == "assembly" || current_attr_target == "module")
603 $$ = new GlobalAttribute (current_container, current_attr_target,
604 name, (ArrayList) $3, (Location) $2);
606 $$ = new Attribute (current_attr_target, name, (ArrayList) $3,
612 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
615 opt_attribute_arguments
616 : /* empty */ { $$ = null; }
617 | OPEN_PARENS attribute_arguments CLOSE_PARENS
625 : opt_positional_argument_list
630 ArrayList args = new ArrayList (4);
636 | positional_argument_list COMMA named_argument_list
638 ArrayList args = new ArrayList (4);
644 | named_argument_list
646 ArrayList args = new ArrayList (4);
655 opt_positional_argument_list
656 : /* empty */ { $$ = null; }
657 | positional_argument_list
660 positional_argument_list
663 ArrayList args = new ArrayList (4);
664 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
668 | positional_argument_list COMMA expression
670 ArrayList args = (ArrayList) $1;
671 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
680 ArrayList args = new ArrayList (4);
685 | named_argument_list COMMA named_argument
687 ArrayList args = (ArrayList) $1;
695 : IDENTIFIER ASSIGN expression
697 $$ = new DictionaryEntry (
699 new Argument ((Expression) $3, Argument.AType.Expression));
705 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
708 opt_class_member_declarations
710 | class_member_declarations
713 class_member_declarations
714 : class_member_declaration
715 | class_member_declarations
716 class_member_declaration
719 class_member_declaration
720 : constant_declaration // done
721 | field_declaration // done
722 | method_declaration // done
723 | property_declaration // done
724 | event_declaration // done
725 | indexer_declaration // done
726 | operator_declaration // done
727 | constructor_declaration // done
728 | destructor_declaration // done
738 MemberName name = MakeName ((MemberName) $5);
739 bool partial = (bool) $3;
740 int mod_flags = (int) $2;
743 ClassPart part = PartialContainer.CreatePart (
744 current_namespace, current_container, name, mod_flags,
745 (Attributes) $1, Kind.Struct, lexer.Location);
747 current_container = part.PartialContainer;
748 current_class = part;
750 if ((mod_flags & Modifiers.STATIC) != 0) {
751 current_class = new StaticClass (
752 current_namespace, current_container, name,
753 mod_flags, (Attributes) $1, lexer.Location);
755 current_class = new Struct (
756 current_namespace, current_container, name,
757 mod_flags, (Attributes) $1, lexer.Location);
759 current_container = current_class;
760 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
763 lexer.ConstraintsParsing = true;
766 opt_type_parameter_constraints_clauses
768 lexer.ConstraintsParsing = false;
771 current_class.Bases = (ArrayList) $7;
773 CheckDef (current_class.SetParameterInfo ((ArrayList) $8), current_class.Name,
774 current_class.Location);
776 current_class.Register ();
783 current_container = current_container.Parent;
784 current_class = current_container;
786 | opt_attributes opt_modifiers opt_partial STRUCT error {
787 CheckIdentifierToken (yyToken);
792 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
795 opt_struct_member_declarations
797 | struct_member_declarations
800 struct_member_declarations
801 : struct_member_declaration
802 | struct_member_declarations struct_member_declaration
805 struct_member_declaration
806 : constant_declaration
809 | property_declaration
811 | indexer_declaration
812 | operator_declaration
813 | constructor_declaration
817 * This is only included so we can flag error 575:
818 * destructors only allowed on class types
820 | destructor_declaration
831 foreach (VariableDeclaration constant in (ArrayList) $5){
832 Location l = constant.Location;
834 Const c = new Const (
835 current_class, (Expression) $4, (string) constant.identifier,
836 (Expression) constant.expression_or_array_initializer, (int) $2,
839 CheckDef (current_container.AddConstant (c), c.Name, l);
845 : constant_declarator
847 ArrayList constants = new ArrayList (4);
852 | constant_declarators COMMA constant_declarator
855 ArrayList constants = (ArrayList) $1;
862 : IDENTIFIER ASSIGN constant_expression
864 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
868 // A const field requires a value to be provided
869 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
881 Expression type = (Expression) $3;
884 foreach (VariableDeclaration var in (ArrayList) $4){
885 Location l = var.Location;
887 Field field = new Field (current_class, type, mod, var.identifier,
888 var.expression_or_array_initializer,
891 CheckDef (current_container.AddField (field), field.Name, l);
899 Report.Error (670, lexer.Location, "void type is not allowed for fields");
904 : variable_declarator
906 ArrayList decl = new ArrayList (4);
910 | variable_declarators COMMA variable_declarator
912 ArrayList decls = (ArrayList) $1;
919 : IDENTIFIER ASSIGN variable_initializer
921 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
925 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
938 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
940 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
946 iterator_container = (IIteratorContainer) $1;
950 Method method = (Method) $1;
951 Block b = (Block) $3;
952 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
955 if ((method.ModFlags & extern_abstract) == 0){
957 501, lexer.Location, current_container.MakeName (method.Name) +
958 "must declare a body because it is not marked abstract or extern");
961 if ((method.ModFlags & Modifiers.EXTERN) != 0){
963 179, lexer.Location, current_container.MakeName (method.Name) +
964 " is declared extern, but has a body");
968 method.Block = (Block) $3;
969 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
971 current_local_parameters = null;
972 iterator_container = null;
986 1585, lexer.Location, "Member modifier `" +
987 Modifiers.Name (i) + "' must precede member type and name");
998 type namespace_or_type_name
999 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1001 lexer.ConstraintsParsing = true;
1003 opt_type_parameter_constraints_clauses
1005 lexer.ConstraintsParsing = false;
1007 MemberName name = (MemberName) $4;
1009 if ($9 != null && name.TypeArguments == null)
1010 Report.Error (80, lexer.Location,
1011 "Contraints are not allowed on non-generic declarations");
1015 GenericMethod generic = null;
1016 if (name.TypeArguments != null) {
1017 generic = new GenericMethod (current_namespace, current_class,
1018 name, lexer.Location);
1020 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
1023 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1024 name, (Parameters) $6, (Attributes) $1, lexer.Location);
1026 current_local_parameters = (Parameters) $6;
1032 VOID namespace_or_type_name
1033 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1035 lexer.ConstraintsParsing = true;
1037 opt_type_parameter_constraints_clauses
1039 lexer.ConstraintsParsing = false;
1041 MemberName name = (MemberName) $4;
1043 if ($9 != null && name.TypeArguments == null)
1044 Report.Error (80, lexer.Location,
1045 "Contraints are not allowed on non-generic declarations");
1048 GenericMethod generic = null;
1049 if (name.TypeArguments != null) {
1050 generic = new GenericMethod (current_namespace, current_class,
1051 name, lexer.Location);
1054 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
1057 method = new Method (current_class, generic, TypeManager.system_void_expr,
1058 (int) $2, false, name, (Parameters) $6, (Attributes) $1,
1061 current_local_parameters = (Parameters) $6;
1068 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1070 Report.Error (1585, lexer.Location,
1071 String.Format ("Modifier {0} should appear before type",
1072 Modifiers.Name ((int) $4)));
1073 MemberName name = (MemberName) $4;
1075 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1076 0, false, name, (Parameters) $6, (Attributes) $1,
1079 current_local_parameters = (Parameters) $6;
1086 | SEMICOLON { $$ = null; }
1089 opt_formal_parameter_list
1090 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1091 | formal_parameter_list
1094 formal_parameter_list
1097 ArrayList pars_list = (ArrayList) $1;
1099 Parameter [] pars = new Parameter [pars_list.Count];
1100 pars_list.CopyTo (pars);
1102 $$ = new Parameters (pars, null, lexer.Location);
1104 | fixed_parameters COMMA parameter_array
1106 ArrayList pars_list = (ArrayList) $1;
1108 Parameter [] pars = new Parameter [pars_list.Count];
1109 pars_list.CopyTo (pars);
1111 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
1113 | fixed_parameters COMMA ARGLIST
1115 ArrayList pars_list = (ArrayList) $1;
1117 Parameter [] pars = new Parameter [pars_list.Count];
1118 pars_list.CopyTo (pars);
1120 $$ = new Parameters (pars, true, lexer.Location);
1124 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1128 $$ = new Parameters (null, true, lexer.Location);
1135 ArrayList pars = new ArrayList (4);
1140 | fixed_parameters COMMA fixed_parameter
1142 ArrayList pars = (ArrayList) $1;
1151 opt_parameter_modifier
1155 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1158 opt_parameter_modifier
1161 CheckIdentifierToken (yyToken);
1166 opt_parameter_modifier
1167 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1168 | parameter_modifier
1172 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1173 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1177 : opt_attributes PARAMS type IDENTIFIER
1179 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1180 note ("type must be a single-dimension array type");
1182 | opt_attributes PARAMS type error {
1183 CheckIdentifierToken (yyToken);
1188 property_declaration
1191 type namespace_or_type_name
1194 implicit_value_parameter_type = (Expression) $3;
1196 lexer.PropertyParsing = true;
1198 $$ = lexer.Location;
1200 iterator_container = SimpleIteratorContainer.GetSimple ();
1202 accessor_declarations
1204 lexer.PropertyParsing = false;
1209 Pair pair = (Pair) $7;
1210 Accessor get_block = (Accessor) pair.First;
1211 Accessor set_block = (Accessor) pair.Second;
1213 MemberName name = (MemberName) $4;
1214 if (name.TypeArguments != null)
1215 syntax_error (lexer.Location, "a property can't have type arguments");
1217 Location loc = (Location) $6;
1218 prop = new Property (current_container, (Expression) $3, (int) $2, false,
1219 name, (Attributes) $1, get_block, set_block, loc);
1220 if (SimpleIteratorContainer.Simple.Yields)
1223 CheckDef (current_container.AddProperty (prop), prop.Name, loc);
1224 implicit_value_parameter_type = null;
1225 iterator_container = null;
1229 accessor_declarations
1230 : get_accessor_declaration opt_set_accessor_declaration
1232 $$ = new Pair ($1, $2);
1234 | set_accessor_declaration opt_get_accessor_declaration
1236 $$ = new Pair ($2, $1);
1240 opt_get_accessor_declaration
1241 : /* empty */ { $$ = null; }
1242 | get_accessor_declaration
1245 opt_set_accessor_declaration
1246 : /* empty */ { $$ = null; }
1247 | set_accessor_declaration
1250 get_accessor_declaration
1251 : opt_attributes GET
1253 // If this is not the case, then current_local_parameters has already
1254 // been set in indexer_declaration
1255 if (parsing_indexer == false)
1256 current_local_parameters = null;
1258 current_local_parameters = indexer_parameters;
1259 lexer.PropertyParsing = false;
1263 $$ = new Accessor ((Block) $4, (Attributes) $1);
1264 current_local_parameters = null;
1265 lexer.PropertyParsing = true;
1269 set_accessor_declaration
1270 : opt_attributes SET
1273 Parameter implicit_value_parameter = new Parameter (
1274 implicit_value_parameter_type, "value",
1275 Parameter.Modifier.NONE, null);
1277 if (parsing_indexer == false) {
1278 args = new Parameter [1];
1279 args [0] = implicit_value_parameter;
1280 current_local_parameters = new Parameters (args, null, lexer.Location);
1282 Parameter [] fpars = indexer_parameters.FixedParameters;
1285 int count = fpars.Length;
1287 args = new Parameter [count + 1];
1288 fpars.CopyTo (args, 0);
1289 args [count] = implicit_value_parameter;
1292 current_local_parameters = new Parameters (
1293 args, indexer_parameters.ArrayParameter, lexer.Location);
1296 lexer.PropertyParsing = false;
1300 $$ = new Accessor ((Block) $4, (Attributes) $1);
1301 current_local_parameters = null;
1302 lexer.PropertyParsing = true;
1308 | SEMICOLON { $$ = null; }
1311 interface_declaration
1315 INTERFACE member_name
1317 MemberName name = MakeName ((MemberName) $5);
1318 bool partial = (bool) $3;
1321 ClassPart part = PartialContainer.CreatePart (
1322 current_namespace, current_container, name, (int) $2,
1323 (Attributes) $1, Kind.Interface, lexer.Location);
1325 current_container = part.PartialContainer;
1326 current_class = part;
1328 current_class = new Interface (
1329 current_namespace, current_container, name, (int) $2,
1330 (Attributes) $1, lexer.Location);
1332 current_container = current_class;
1333 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
1336 lexer.ConstraintsParsing = true;
1339 opt_type_parameter_constraints_clauses
1341 lexer.ConstraintsParsing = false;
1344 current_class.Bases = (ArrayList) $7;
1346 CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
1347 current_class.Name, current_class.Location);
1349 current_class.Register ();
1351 interface_body opt_semicolon
1355 current_container = current_container.Parent;
1356 current_class = current_container;
1358 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1359 CheckIdentifierToken (yyToken);
1365 opt_interface_member_declarations
1369 opt_interface_member_declarations
1371 | interface_member_declarations
1374 interface_member_declarations
1375 : interface_member_declaration
1376 | interface_member_declarations interface_member_declaration
1379 interface_member_declaration
1380 : interface_method_declaration
1382 Method m = (Method) $1;
1384 CheckDef (current_container.AddMethod (m), m.Name, m.Location);
1386 | interface_property_declaration
1388 Property p = (Property) $1;
1390 CheckDef (current_container.AddProperty (p), p.Name, p.Location);
1392 | interface_event_declaration
1395 Event e = (Event) $1;
1396 CheckDef (current_container.AddEvent (e), e.Name, lexer.Location);
1399 | interface_indexer_declaration
1401 Indexer i = (Indexer) $1;
1403 current_container.AddIndexer (i);
1411 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1416 interface_method_declaration
1417 : opt_attributes opt_new type namespace_or_type_name
1418 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1420 lexer.ConstraintsParsing = true;
1422 opt_type_parameter_constraints_clauses
1425 lexer.ConstraintsParsing = false;
1427 MemberName name = (MemberName) $4;
1429 if ($9 != null && name.TypeArguments == null)
1430 Report.Error (80, lexer.Location,
1431 "Contraints are not allowed on non-generic declarations");
1433 GenericMethod generic = null;
1434 if (name.TypeArguments != null) {
1435 generic = new GenericMethod (current_namespace, current_class,
1436 name, lexer.Location);
1438 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
1441 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1442 (Parameters) $6, (Attributes) $1, lexer.Location);
1444 | opt_attributes opt_new VOID namespace_or_type_name
1445 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1447 lexer.ConstraintsParsing = true;
1449 opt_type_parameter_constraints_clauses
1452 lexer.ConstraintsParsing = false;
1454 MemberName name = (MemberName) $4;
1456 if ($9 != null && name.TypeArguments == null)
1457 Report.Error (80, lexer.Location,
1458 "Contraints are not allowed on non-generic declarations");
1460 GenericMethod generic = null;
1461 if (name.TypeArguments != null) {
1462 generic = new GenericMethod (current_namespace, current_class,
1463 name, lexer.Location);
1465 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
1468 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1469 true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
1473 interface_property_declaration
1478 { lexer.PropertyParsing = true; }
1480 { lexer.PropertyParsing = false; }
1483 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1485 $$ = new Property (current_class, (Expression) $3, (int) $2, true,
1486 new MemberName ((string) $4), (Attributes) $1,
1487 pinfo.Get, pinfo.Set, lexer.Location);
1492 CheckIdentifierToken (yyToken);
1498 : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null); }
1499 | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1); }
1500 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1501 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3); }
1502 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1503 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1); }
1506 interface_event_declaration
1507 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1509 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1510 new MemberName ((string) $5), null,
1511 (Attributes) $1, lexer.Location);
1513 | opt_attributes opt_new EVENT type error {
1514 CheckIdentifierToken (yyToken);
1517 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1518 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1521 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1522 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1527 interface_indexer_declaration
1528 : opt_attributes opt_new type THIS
1529 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1531 { lexer.PropertyParsing = true; }
1533 { lexer.PropertyParsing = false; }
1536 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1538 $$ = new Indexer (current_class, (Expression) $3, (int) $2, true,
1539 MemberName.Null, (Parameters) $6, (Attributes) $1,
1540 info.Get, info.Set, lexer.Location);
1544 operator_declaration
1545 : opt_attributes opt_modifiers operator_declarator
1547 iterator_container = SimpleIteratorContainer.GetSimple ();
1551 OperatorDeclaration decl = (OperatorDeclaration) $3;
1553 Operator op = new Operator (
1554 current_class, decl.optype, decl.ret_type, (int) $2, decl.arg1type,
1555 decl.arg1name, decl.arg2type, decl.arg2name, (Block) $5,
1556 (Attributes) $1, decl.location);
1558 if (SimpleIteratorContainer.Simple.Yields)
1561 // Note again, checking is done in semantic analysis
1562 current_container.AddOperator (op);
1564 current_local_parameters = null;
1565 iterator_container = null;
1571 | SEMICOLON { $$ = null; }
1574 : type OPERATOR overloadable_operator
1575 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1577 Operator.OpType op = (Operator.OpType) $3;
1578 CheckUnaryOperator (op);
1580 if (op == Operator.OpType.Addition)
1581 op = Operator.OpType.UnaryPlus;
1583 if (op == Operator.OpType.Subtraction)
1584 op = Operator.OpType.UnaryNegation;
1586 Parameter [] pars = new Parameter [1];
1588 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1590 current_local_parameters = new Parameters (pars, null, lexer.Location);
1592 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1593 null, null, lexer.Location);
1595 | type OPERATOR overloadable_operator
1597 type IDENTIFIER COMMA
1601 CheckBinaryOperator ((Operator.OpType) $3);
1603 Parameter [] pars = new Parameter [2];
1605 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1606 pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1608 current_local_parameters = new Parameters (pars, null, lexer.Location);
1610 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1611 (Expression) $5, (string) $6,
1612 (Expression) $8, (string) $9, lexer.Location);
1614 | conversion_operator_declarator
1617 overloadable_operator
1619 : BANG { $$ = Operator.OpType.LogicalNot; }
1620 | TILDE { $$ = Operator.OpType.OnesComplement; }
1621 | OP_INC { $$ = Operator.OpType.Increment; }
1622 | OP_DEC { $$ = Operator.OpType.Decrement; }
1623 | TRUE { $$ = Operator.OpType.True; }
1624 | FALSE { $$ = Operator.OpType.False; }
1625 // Unary and binary:
1626 | PLUS { $$ = Operator.OpType.Addition; }
1627 | MINUS { $$ = Operator.OpType.Subtraction; }
1629 | STAR { $$ = Operator.OpType.Multiply; }
1630 | DIV { $$ = Operator.OpType.Division; }
1631 | PERCENT { $$ = Operator.OpType.Modulus; }
1632 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1633 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1634 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1635 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1636 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1637 | OP_EQ { $$ = Operator.OpType.Equality; }
1638 | OP_NE { $$ = Operator.OpType.Inequality; }
1639 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1640 | OP_LT { $$ = Operator.OpType.LessThan; }
1641 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1642 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1645 conversion_operator_declarator
1646 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1648 Parameter [] pars = new Parameter [1];
1650 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1652 current_local_parameters = new Parameters (pars, null, lexer.Location);
1654 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1655 null, null, lexer.Location);
1657 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1659 Parameter [] pars = new Parameter [1];
1661 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1663 current_local_parameters = new Parameters (pars, null, lexer.Location);
1665 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1666 null, null, lexer.Location);
1670 syntax_error (lexer.Location, "'operator' expected");
1674 syntax_error (lexer.Location, "'operator' expected");
1678 constructor_declaration
1681 constructor_declarator
1684 Constructor c = (Constructor) $3;
1685 c.Block = (Block) $4;
1686 c.OptAttributes = (Attributes) $1;
1687 c.ModFlags = (int) $2;
1689 if (c.Name == current_container.Basename){
1690 if ((c.ModFlags & Modifiers.STATIC) != 0){
1691 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1693 515, c.Location, String.Format (
1694 "`{0}.{1}': static constructor can not have access modifiers",
1695 c.Name, current_container.Name));
1698 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1700 if (c.Initializer != null){
1703 "Static constructors can not have an explicit this or base " +
1704 "constructor invocations");
1707 if (!c.Parameters.Empty){
1709 132, c.Location, "Static constructors should not have parameters");
1712 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1715 // We let another layer check the validity of the constructor.
1716 Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1719 CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
1721 current_local_parameters = null;
1725 constructor_declarator
1727 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1729 oob_stack.Push (lexer.Location);
1731 current_local_parameters = (Parameters) $3;
1733 opt_constructor_initializer
1735 Location l = (Location) oob_stack.Pop ();
1736 $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $3,
1737 (ConstructorInitializer) $6, l);
1743 | SEMICOLON { $$ = null; }
1746 opt_constructor_initializer
1747 : /* empty */ { $$ = null; }
1748 | constructor_initializer
1751 constructor_initializer
1752 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1754 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1756 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1758 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1761 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1767 : /* EMPTY */ { $$ = 0; }
1768 | UNSAFE { $$ = Modifiers.UNSAFE; }
1769 | EXTERN { $$ = Modifiers.EXTERN; }
1772 destructor_declaration
1773 : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1775 if ((string) $4 != current_container.Basename){
1776 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1777 } else if (!(current_container is Class)){
1778 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1780 Location l = lexer.Location;
1783 if (!RootContext.StdLib && current_container.Name == "System.Object")
1784 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1786 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1788 if ((m & Modifiers.UNSAFE) != 0){
1789 if (!RootContext.Unsafe){
1790 Report.Error (227, l,
1791 "Unsafe code requires the -unsafe command " +
1792 "line option to be specified");
1796 Method d = new Destructor (
1797 current_class, TypeManager.system_void_expr, m, "Finalize",
1798 new Parameters (null, null, l), (Attributes) $1, l);
1800 d.Block = (Block) $7;
1801 CheckDef (current_container.AddMethod (d), d.Name, d.Location);
1804 | opt_attributes opt_modifiers EVENT type member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
1805 string mn = (string) $5;
1807 if (mn.IndexOf ('.') != -1)
1808 Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
1810 Report.Error (71, lexer.Location, "Event declaration should use property syntax");
1817 EVENT type variable_declarators SEMICOLON
1819 foreach (VariableDeclaration var in (ArrayList) $5) {
1821 MemberName name = new MemberName (var.identifier);
1823 Event e = new EventField (current_class, (Expression) $4, (int) $2,
1825 var.expression_or_array_initializer,
1826 (Attributes) $1, lexer.Location);
1828 CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1834 EVENT type namespace_or_type_name
1837 implicit_value_parameter_type = (Expression) $4;
1838 lexer.EventParsing = true;
1839 oob_stack.Push (lexer.Location);
1841 event_accessor_declarations
1843 lexer.EventParsing = false;
1847 Location loc = (Location) oob_stack.Pop ();
1850 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1853 Pair pair = (Pair) $8;
1855 MemberName name = (MemberName) $5;
1856 if (name.TypeArguments != null)
1857 syntax_error (lexer.Location, "an event can't have type arguments");
1859 Event e = new EventProperty (current_class, (Expression) $4, (int) $2,
1860 false, name, null, (Attributes) $1,
1861 (Accessor) pair.First, (Accessor) pair.Second,
1864 CheckDef (current_container.AddEvent (e), e.Name, loc);
1865 implicit_value_parameter_type = null;
1870 event_accessor_declarations
1871 : add_accessor_declaration remove_accessor_declaration
1873 $$ = new Pair ($1, $2);
1875 | remove_accessor_declaration add_accessor_declaration
1877 $$ = new Pair ($2, $1);
1879 | add_accessor_declaration { $$ = null; }
1880 | remove_accessor_declaration { $$ = null; }
1883 add_accessor_declaration
1884 : opt_attributes ADD
1886 Parameter [] args = new Parameter [1];
1887 Parameter implicit_value_parameter = new Parameter (
1888 implicit_value_parameter_type, "value",
1889 Parameter.Modifier.NONE, null);
1891 args [0] = implicit_value_parameter;
1893 current_local_parameters = new Parameters (args, null, lexer.Location);
1894 lexer.EventParsing = false;
1898 $$ = new Accessor ((Block) $4, (Attributes) $1);
1899 lexer.EventParsing = true;
1901 | opt_attributes ADD error {
1902 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1907 remove_accessor_declaration
1908 : opt_attributes REMOVE
1910 Parameter [] args = new Parameter [1];
1911 Parameter implicit_value_parameter = new Parameter (
1912 implicit_value_parameter_type, "value",
1913 Parameter.Modifier.NONE, null);
1915 args [0] = implicit_value_parameter;
1917 current_local_parameters = new Parameters (args, null, lexer.Location);
1918 lexer.EventParsing = false;
1922 $$ = new Accessor ((Block) $4, (Attributes) $1);
1923 lexer.EventParsing = true;
1925 | opt_attributes REMOVE error {
1926 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1932 : opt_attributes opt_modifiers indexer_declarator
1935 IndexerDeclaration decl = (IndexerDeclaration) $3;
1937 implicit_value_parameter_type = decl.type;
1939 lexer.PropertyParsing = true;
1940 parsing_indexer = true;
1942 indexer_parameters = decl.param_list;
1943 oob_stack.Push (lexer.Location);
1945 accessor_declarations
1947 lexer.PropertyParsing = false;
1948 parsing_indexer = false;
1952 // The signature is computed from the signature of the indexer. Look
1953 // at section 3.6 on the spec
1954 Location loc = (Location) oob_stack.Pop ();
1956 IndexerDeclaration decl = (IndexerDeclaration) $3;
1957 Pair pair = (Pair) $6;
1958 Accessor get_block = (Accessor) pair.First;
1959 Accessor set_block = (Accessor) pair.Second;
1962 if (decl.interface_type != null)
1963 name = new MemberName (decl.interface_type, "", null);
1965 name = MemberName.Null;
1967 indexer = new Indexer (current_class, decl.type, (int) $2, false,
1968 name, decl.param_list, (Attributes) $1,
1969 get_block, set_block, loc);
1971 // Note that there is no equivalent of CheckDef for this case
1972 // We shall handle this in semantic analysis
1974 current_container.AddIndexer (indexer);
1976 current_local_parameters = null;
1977 implicit_value_parameter_type = null;
1978 indexer_parameters = null;
1983 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1985 Parameters pars = (Parameters) $4;
1986 if (pars.HasArglist) {
1987 // "__arglist is not valid in this context"
1988 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
1989 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
1990 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1993 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1995 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1997 Parameters pars = (Parameters) $6;
1999 if (pars.HasArglist) {
2000 // "__arglist is not valid in this context"
2001 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2002 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2003 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2005 MemberName name = (MemberName) $2;
2006 if (name.TypeArguments != null)
2007 syntax_error (lexer.Location, "an indexer can't have type arguments");
2009 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
2021 Location enum_location = lexer.Location;
2023 MemberName full_name = MakeName (new MemberName ((string) $4));
2024 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
2025 full_name, (Attributes) $1, enum_location);
2027 foreach (VariableDeclaration ev in (ArrayList) $6) {
2028 Location loc = (Location) ev.Location;
2030 CheckDef (e.AddEnumMember (ev.identifier,
2031 (Expression) ev.expression_or_array_initializer,
2032 loc, ev.OptAttributes),
2033 ev.identifier, loc);
2036 string name = full_name.GetName (false);
2037 CheckDef (current_container.AddEnum (e), name, enum_location);
2038 RootContext.Tree.RecordDecl (name, e);
2044 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2045 | COLON type { $$ = $2; }
2049 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
2055 opt_enum_member_declarations
2056 : /* empty */ { $$ = new ArrayList (4); }
2057 | enum_member_declarations opt_comma { $$ = $1; }
2060 enum_member_declarations
2061 : enum_member_declaration
2063 ArrayList l = new ArrayList (4);
2068 | enum_member_declarations COMMA enum_member_declaration
2070 ArrayList l = (ArrayList) $1;
2078 enum_member_declaration
2079 : opt_attributes IDENTIFIER
2081 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
2083 | opt_attributes IDENTIFIER
2085 $$ = lexer.Location;
2089 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
2093 delegate_declaration
2096 DELEGATE type member_name
2097 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2099 Location l = lexer.Location;
2100 Delegate del = new Delegate (
2101 current_namespace, current_container, (Expression) $4, (int) $2,
2102 MakeName ((MemberName) $5), (Parameters) $7, (Attributes) $1, l);
2104 CheckDef (current_container.AddDelegate (del), del.Name, l);
2106 current_delegate = del;
2108 lexer.ConstraintsParsing = true;
2110 opt_type_parameter_constraints_clauses
2112 lexer.ConstraintsParsing = false;
2116 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
2118 current_delegate = null;
2122 DELEGATE VOID member_name
2123 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2125 Location l = lexer.Location;
2126 Delegate del = new Delegate (
2127 current_namespace, current_container,
2128 TypeManager.system_void_expr, (int) $2, MakeName ((MemberName) $5),
2129 (Parameters) $7, (Attributes) $1, l);
2131 CheckDef (current_container.AddDelegate (del), del.Name, l);
2133 current_delegate = del;
2135 lexer.ConstraintsParsing = true;
2137 opt_type_parameter_constraints_clauses
2139 lexer.ConstraintsParsing = false;
2143 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
2145 current_delegate = null;
2149 namespace_or_type_name
2151 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2152 $$ = new MemberName ((MemberName) $1, (string) $3, (TypeArguments) $4);
2157 : IDENTIFIER opt_type_argument_list {
2158 $$ = new MemberName ((string) $1, (TypeArguments) $2);
2162 opt_type_argument_list
2163 : /* empty */ { $$ = null; }
2164 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2170 $$ = new TypeArguments ((int) $1, lexer.Location);
2176 TypeArguments type_args = new TypeArguments (lexer.Location);
2177 type_args.Add ((Expression) $1);
2180 | type_arguments COMMA type {
2181 TypeArguments type_args = (TypeArguments) $1;
2182 type_args.Add ((Expression) $3);
2188 * Before you think of adding a return_type, notice that we have been
2189 * using two rules in the places where it matters (one rule using type
2190 * and another identical one that uses VOID as the return type). This
2191 * gets rid of a shift/reduce couple
2194 : namespace_or_type_name
2196 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2207 // Note that here only unmanaged types are allowed but we
2208 // can't perform checks during this phase - we do it during
2209 // semantic analysis.
2211 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2215 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2221 | non_expression_type rank_specifier
2223 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2225 | non_expression_type STAR
2227 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2229 | expression rank_specifiers
2231 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2235 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2239 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2240 // through this different path
2242 | multiplicative_expression STAR
2244 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2251 ArrayList types = new ArrayList (4);
2256 | type_list COMMA type
2258 ArrayList types = (ArrayList) $1;
2266 * replaces all the productions for isolating the various
2267 * simple types, but we need this to reuse it easily in local_variable_type
2270 : OBJECT { $$ = TypeManager.system_object_expr; }
2271 | STRING { $$ = TypeManager.system_string_expr; }
2272 | BOOL { $$ = TypeManager.system_boolean_expr; }
2273 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2274 | FLOAT { $$ = TypeManager.system_single_expr; }
2275 | DOUBLE { $$ = TypeManager.system_double_expr; }
2280 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2281 | BYTE { $$ = TypeManager.system_byte_expr; }
2282 | SHORT { $$ = TypeManager.system_int16_expr; }
2283 | USHORT { $$ = TypeManager.system_uint16_expr; }
2284 | INT { $$ = TypeManager.system_int32_expr; }
2285 | UINT { $$ = TypeManager.system_uint32_expr; }
2286 | LONG { $$ = TypeManager.system_int64_expr; }
2287 | ULONG { $$ = TypeManager.system_uint64_expr; }
2288 | CHAR { $$ = TypeManager.system_char_expr; }
2289 | VOID { $$ = TypeManager.system_void_expr; }
2293 : type rank_specifiers
2295 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2300 // Expressions, section 7.5
2310 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2312 | parenthesized_expression
2313 | default_value_expression
2315 | invocation_expression
2319 | post_increment_expression
2320 | post_decrement_expression
2324 | checked_expression
2325 | unchecked_expression
2326 | pointer_member_access
2327 | anonymous_method_expression
2334 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2335 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2336 | NULL { $$ = NullLiteral.Null; }
2340 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2341 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2342 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2347 object v = lexer.Value;
2353 $$ = IntLiteral.Zero;
2355 $$ = IntLiteral.One;
2357 $$ = new IntLiteral (i);
2358 } else if (v is uint)
2359 $$ = new UIntLiteral ((UInt32) v);
2361 $$ = new LongLiteral ((Int64) v);
2362 else if (v is ulong)
2363 $$ = new ULongLiteral ((UInt64) v);
2365 Console.WriteLine ("OOPS. Unexpected result from scanner");
2370 : TRUE { $$ = new BoolLiteral (true); }
2371 | FALSE { $$ = new BoolLiteral (false); }
2374 parenthesized_expression_0
2375 : OPEN_PARENS expression CLOSE_PARENS
2378 lexer.Deambiguate_CloseParens ();
2379 // After this, the next token returned is one of
2380 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2381 // or CLOSE_PARENS_MINUS.
2385 parenthesized_expression
2386 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2390 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2392 // If a parenthesized expression is followed by a minus, we need to wrap
2393 // the expression inside a ParenthesizedExpression for the CS0075 check
2394 // in Binary.DoResolve().
2395 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2400 : primary_expression DOT IDENTIFIER opt_type_argument_list
2402 $$ = new MemberAccess ((Expression) $1, (string) $3,
2403 (TypeArguments) $4, lexer.Location);
2405 | predefined_type DOT IDENTIFIER opt_type_argument_list
2407 $$ = new MemberAccess ((Expression) $1, (string) $3,
2408 (TypeArguments) $4, lexer.Location);
2416 invocation_expression
2417 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2420 Location l = lexer.Location;
2421 Report.Error (1, l, "Parse error");
2423 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2425 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2427 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2429 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2431 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2436 : /* empty */ { $$ = null; }
2443 ArrayList list = new ArrayList (4);
2447 | argument_list COMMA argument
2449 ArrayList list = (ArrayList) $1;
2453 | argument_list error {
2454 CheckToken (1026, yyToken, ", or ) expected");
2461 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2463 | REF variable_reference
2465 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2467 | OUT variable_reference
2469 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2471 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
2473 ArrayList list = (ArrayList) $3;
2474 Argument[] args = new Argument [list.Count];
2475 list.CopyTo (args, 0);
2477 Expression expr = new Arglist (args, lexer.Location);
2478 $$ = new Argument (expr, Argument.AType.Expression);
2482 $$ = new Argument (new ArglistAccess (lexer.Location), Argument.AType.ArgList);
2487 : expression { note ("section 5.4"); $$ = $1; }
2491 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2493 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2495 | primary_expression rank_specifiers
2497 // So the super-trick is that primary_expression
2498 // can only be either a SimpleName or a MemberAccess.
2499 // The MemberAccess case arises when you have a fully qualified type-name like :
2501 // SimpleName is when you have
2504 Expression expr = (Expression) $1;
2505 if (expr is ComposedCast){
2506 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2507 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2508 Error_ExpectingTypeName (lexer.Location, expr);
2509 $$ = TypeManager.system_object_expr;
2512 // So we extract the string corresponding to the SimpleName
2515 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2523 ArrayList list = new ArrayList (4);
2527 | expression_list COMMA expression
2529 ArrayList list = (ArrayList) $1;
2538 $$ = new This (current_block, lexer.Location);
2543 : BASE DOT IDENTIFIER
2545 $$ = new BaseAccess ((string) $3, lexer.Location);
2547 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2549 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2552 Report.Error (175, "Use of keyword `base' is not valid in this context");
2557 post_increment_expression
2558 : primary_expression OP_INC
2560 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2561 (Expression) $1, lexer.Location);
2565 post_decrement_expression
2566 : primary_expression OP_DEC
2568 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2569 (Expression) $1, lexer.Location);
2574 : object_or_delegate_creation_expression
2575 | array_creation_expression
2578 object_or_delegate_creation_expression
2579 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2581 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2585 array_creation_expression
2586 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2588 opt_array_initializer
2590 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2592 | NEW type rank_specifiers array_initializer
2594 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2598 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2614 : rank_specifier opt_rank_specifier
2616 $$ = (string) $2 + (string) $1;
2621 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2623 $$ = "[" + (string) $2 + "]";
2643 | dim_separators COMMA
2645 $$ = (string) $1 + ",";
2649 opt_array_initializer
2661 : OPEN_BRACE CLOSE_BRACE
2663 ArrayList list = new ArrayList (4);
2666 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2668 $$ = (ArrayList) $2;
2672 variable_initializer_list
2673 : variable_initializer
2675 ArrayList list = new ArrayList (4);
2679 | variable_initializer_list COMMA variable_initializer
2681 ArrayList list = (ArrayList) $1;
2688 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2690 $$ = new TypeOfVoid (lexer.Location);
2692 | TYPEOF OPEN_PARENS
2694 lexer.TypeOfParsing = true;
2698 lexer.TypeOfParsing = false;
2699 $$ = new TypeOf ((Expression) $4, lexer.Location);
2704 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2705 $$ = new SizeOf ((Expression) $3, lexer.Location);
2710 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2712 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2716 unchecked_expression
2717 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2719 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2723 pointer_member_access
2724 : primary_expression OP_PTR IDENTIFIER
2728 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2729 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2733 anonymous_method_expression
2734 : DELEGATE opt_anonymous_method_signature {
2735 oob_stack.Push (current_local_parameters);
2736 current_local_parameters = (Parameters)$2;
2737 create_toplevel_block = true;
2740 Report.Error (-213, lexer.Location, "Anonymous methods are not supported in this branch");
2743 create_toplevel_block = false;
2744 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2745 if (!RootContext.V2){
2746 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2749 $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
2750 current_local_parameters = (Parameters) oob_stack.Pop ();
2755 opt_anonymous_method_signature
2756 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
2757 | anonymous_method_signature
2760 anonymous_method_signature
2761 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2764 $$ = Parameters.EmptyReadOnlyParameters;
2766 ArrayList par_list = (ArrayList) $2;
2767 Parameter [] pars = new Parameter [par_list.Count];
2768 par_list.CopyTo (pars);
2769 $$ = new Parameters (pars, null, lexer.Location);
2774 opt_anonymous_method_parameter_list
2775 : /* empty */ { $$ = null; }
2776 | anonymous_method_parameter_list { $$ = $1; }
2779 anonymous_method_parameter_list
2780 : anonymous_method_parameter
2782 ArrayList a = new ArrayList (4);
2786 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2788 ArrayList a = (ArrayList) $1;
2794 anonymous_method_parameter
2795 : opt_parameter_modifier type IDENTIFIER {
2796 $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
2800 default_value_expression
2801 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
2803 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
2808 : primary_expression
2809 | BANG prefixed_unary_expression
2811 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2813 | TILDE prefixed_unary_expression
2815 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2821 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2823 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2825 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2827 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2833 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2835 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2840 // The idea to split this out is from Rhys' grammar
2841 // to solve the problem with casts.
2843 prefixed_unary_expression
2845 | PLUS prefixed_unary_expression
2847 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2849 | MINUS prefixed_unary_expression
2851 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2853 | OP_INC prefixed_unary_expression
2855 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2856 (Expression) $2, lexer.Location);
2858 | OP_DEC prefixed_unary_expression
2860 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2861 (Expression) $2, lexer.Location);
2863 | STAR prefixed_unary_expression
2865 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2867 | BITWISE_AND prefixed_unary_expression
2869 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2873 pre_increment_expression
2874 : OP_INC prefixed_unary_expression
2876 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2877 (Expression) $2, lexer.Location);
2881 pre_decrement_expression
2882 : OP_DEC prefixed_unary_expression
2884 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2885 (Expression) $2, lexer.Location);
2889 multiplicative_expression
2890 : prefixed_unary_expression
2891 | multiplicative_expression STAR prefixed_unary_expression
2893 $$ = new Binary (Binary.Operator.Multiply,
2894 (Expression) $1, (Expression) $3, lexer.Location);
2896 | multiplicative_expression DIV prefixed_unary_expression
2898 $$ = new Binary (Binary.Operator.Division,
2899 (Expression) $1, (Expression) $3, lexer.Location);
2901 | multiplicative_expression PERCENT prefixed_unary_expression
2903 $$ = new Binary (Binary.Operator.Modulus,
2904 (Expression) $1, (Expression) $3, lexer.Location);
2909 : multiplicative_expression
2910 | additive_expression PLUS multiplicative_expression
2912 $$ = new Binary (Binary.Operator.Addition,
2913 (Expression) $1, (Expression) $3, lexer.Location);
2915 | additive_expression MINUS multiplicative_expression
2917 $$ = new Binary (Binary.Operator.Subtraction,
2918 (Expression) $1, (Expression) $3, lexer.Location);
2923 : additive_expression
2924 | shift_expression OP_SHIFT_LEFT additive_expression
2926 $$ = new Binary (Binary.Operator.LeftShift,
2927 (Expression) $1, (Expression) $3, lexer.Location);
2929 | shift_expression OP_SHIFT_RIGHT additive_expression
2931 $$ = new Binary (Binary.Operator.RightShift,
2932 (Expression) $1, (Expression) $3, lexer.Location);
2936 relational_expression
2938 | relational_expression OP_LT shift_expression
2940 $$ = new Binary (Binary.Operator.LessThan,
2941 (Expression) $1, (Expression) $3, lexer.Location);
2943 | relational_expression OP_GT shift_expression
2945 $$ = new Binary (Binary.Operator.GreaterThan,
2946 (Expression) $1, (Expression) $3, lexer.Location);
2948 | relational_expression OP_LE shift_expression
2950 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2951 (Expression) $1, (Expression) $3, lexer.Location);
2953 | relational_expression OP_GE shift_expression
2955 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2956 (Expression) $1, (Expression) $3, lexer.Location);
2958 | relational_expression IS type
2960 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2962 | relational_expression AS type
2964 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2969 : relational_expression
2970 | equality_expression OP_EQ relational_expression
2972 $$ = new Binary (Binary.Operator.Equality,
2973 (Expression) $1, (Expression) $3, lexer.Location);
2975 | equality_expression OP_NE relational_expression
2977 $$ = new Binary (Binary.Operator.Inequality,
2978 (Expression) $1, (Expression) $3, lexer.Location);
2983 : equality_expression
2984 | and_expression BITWISE_AND equality_expression
2986 $$ = new Binary (Binary.Operator.BitwiseAnd,
2987 (Expression) $1, (Expression) $3, lexer.Location);
2991 exclusive_or_expression
2993 | exclusive_or_expression CARRET and_expression
2995 $$ = new Binary (Binary.Operator.ExclusiveOr,
2996 (Expression) $1, (Expression) $3, lexer.Location);
3000 inclusive_or_expression
3001 : exclusive_or_expression
3002 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3004 $$ = new Binary (Binary.Operator.BitwiseOr,
3005 (Expression) $1, (Expression) $3, lexer.Location);
3009 conditional_and_expression
3010 : inclusive_or_expression
3011 | conditional_and_expression OP_AND inclusive_or_expression
3013 $$ = new Binary (Binary.Operator.LogicalAnd,
3014 (Expression) $1, (Expression) $3, lexer.Location);
3018 conditional_or_expression
3019 : conditional_and_expression
3020 | conditional_or_expression OP_OR conditional_and_expression
3022 $$ = new Binary (Binary.Operator.LogicalOr,
3023 (Expression) $1, (Expression) $3, lexer.Location);
3027 conditional_expression
3028 : conditional_or_expression
3029 | conditional_or_expression INTERR expression COLON expression
3031 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
3035 assignment_expression
3036 : prefixed_unary_expression ASSIGN expression
3038 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
3040 | prefixed_unary_expression OP_MULT_ASSIGN expression
3042 Location l = lexer.Location;
3044 $$ = new CompoundAssign (
3045 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
3047 | prefixed_unary_expression OP_DIV_ASSIGN expression
3049 Location l = lexer.Location;
3051 $$ = new CompoundAssign (
3052 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
3054 | prefixed_unary_expression OP_MOD_ASSIGN expression
3056 Location l = lexer.Location;
3058 $$ = new CompoundAssign (
3059 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
3061 | prefixed_unary_expression OP_ADD_ASSIGN expression
3063 Location l = lexer.Location;
3065 $$ = new CompoundAssign (
3066 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
3068 | prefixed_unary_expression OP_SUB_ASSIGN expression
3070 Location l = lexer.Location;
3072 $$ = new CompoundAssign (
3073 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
3075 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3077 Location l = lexer.Location;
3079 $$ = new CompoundAssign (
3080 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
3082 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3084 Location l = lexer.Location;
3086 $$ = new CompoundAssign (
3087 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
3089 | prefixed_unary_expression OP_AND_ASSIGN expression
3091 Location l = lexer.Location;
3093 $$ = new CompoundAssign (
3094 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
3096 | prefixed_unary_expression OP_OR_ASSIGN expression
3098 Location l = lexer.Location;
3100 $$ = new CompoundAssign (
3101 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
3103 | prefixed_unary_expression OP_XOR_ASSIGN expression
3105 Location l = lexer.Location;
3107 $$ = new CompoundAssign (
3108 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
3113 : conditional_expression
3114 | assignment_expression
3134 MemberName name = MakeName ((MemberName) $5);
3135 bool partial = (bool) $3;
3138 ClassPart part = PartialContainer.CreatePart (
3139 current_namespace, current_container, name, (int) $2,
3140 (Attributes) $1, Kind.Class, lexer.Location);
3142 current_container = part.PartialContainer;
3143 current_class = part;
3145 current_class = new Class (
3146 current_namespace, current_container, name, (int) $2,
3147 (Attributes) $1, lexer.Location);
3149 current_container = current_class;
3150 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
3153 lexer.ConstraintsParsing = true;
3156 opt_type_parameter_constraints_clauses
3158 lexer.ConstraintsParsing = false;
3161 if (current_class.Name == "System.Object") {
3162 Report.Error (537, current_class.Location,
3163 "The class System.Object cannot have a base " +
3164 "class or implement an interface.");
3166 current_class.Bases = (ArrayList) $7;
3169 CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
3170 current_class.Name, current_class.Location);
3172 current_class.Register ();
3179 current_container = current_container.Parent;
3180 current_class = current_container;
3186 { $$ = (bool) false; }
3188 { $$ = (bool) true; }
3192 : /* empty */ { $$ = (int) 0; }
3198 | modifiers modifier
3203 if ((m1 & m2) != 0) {
3204 Location l = lexer.Location;
3205 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3207 $$ = (int) (m1 | m2);
3212 : NEW { $$ = Modifiers.NEW; }
3213 | PUBLIC { $$ = Modifiers.PUBLIC; }
3214 | PROTECTED { $$ = Modifiers.PROTECTED; }
3215 | INTERNAL { $$ = Modifiers.INTERNAL; }
3216 | PRIVATE { $$ = Modifiers.PRIVATE; }
3217 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3218 | SEALED { $$ = Modifiers.SEALED; }
3219 | STATIC { $$ = Modifiers.STATIC; }
3220 | READONLY { $$ = Modifiers.READONLY; }
3221 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3222 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3223 | EXTERN { $$ = Modifiers.EXTERN; }
3224 | VOLATILE { $$ = Modifiers.VOLATILE; }
3225 | UNSAFE { $$ = Modifiers.UNSAFE; }
3229 : /* empty */ { $$ = null; }
3230 | class_base { $$ = $1; }
3234 : COLON type_list { $$ = $2; }
3237 opt_type_parameter_constraints_clauses
3238 : /* empty */ { $$ = null; }
3239 | type_parameter_constraints_clauses
3243 type_parameter_constraints_clauses
3244 : type_parameter_constraints_clause {
3245 ArrayList constraints = new ArrayList (1);
3246 constraints.Add ($1);
3249 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3250 ArrayList constraints = (ArrayList) $1;
3252 constraints.Add ($2);
3257 type_parameter_constraints_clause
3258 : WHERE IDENTIFIER COLON type_parameter_constraints {
3259 $$ = new Constraints ((string) $2, (ArrayList) $4, lexer.Location);
3263 type_parameter_constraints
3264 : type_parameter_constraint {
3265 ArrayList constraints = new ArrayList (1);
3266 constraints.Add ($1);
3269 | type_parameter_constraints COMMA type_parameter_constraint {
3270 ArrayList constraints = (ArrayList) $1;
3272 constraints.Add ($3);
3277 type_parameter_constraint
3279 | NEW OPEN_PARENS CLOSE_PARENS {
3280 $$ = SpecialConstraint.Constructor;
3283 $$ = SpecialConstraint.ReferenceType;
3286 $$ = SpecialConstraint.ValueType;
3295 // A block is "contained" on the following places:
3297 // property_declaration as part of the accessor body (get/set)
3298 // operator_declaration
3299 // constructor_declaration
3300 // destructor_declaration
3301 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3306 if (current_block == null || create_toplevel_block){
3307 current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
3309 current_block = new Block (current_block, current_local_parameters,
3310 lexer.Location, Location.Null);
3313 opt_statement_list CLOSE_BRACE
3315 while (current_block.Implicit)
3316 current_block = current_block.Parent;
3318 current_block.SetEndLocation (lexer.Location);
3319 current_block = current_block.Parent;
3330 | statement_list statement
3334 : declaration_statement
3336 if ($1 != null && (Block) $1 != current_block){
3337 current_block.AddStatement ((Statement) $1);
3338 current_block = (Block) $1;
3341 | valid_declaration_statement
3343 current_block.AddStatement ((Statement) $1);
3348 valid_declaration_statement
3351 | expression_statement
3352 | selection_statement
3353 | iteration_statement
3357 | unchecked_statement
3365 : valid_declaration_statement
3366 | declaration_statement
3368 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
3373 Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
3381 $$ = EmptyStatement.Value;
3388 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3390 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3391 current_block.AddStatement (labeled);
3396 declaration_statement
3397 : local_variable_declaration SEMICOLON
3400 DictionaryEntry de = (DictionaryEntry) $1;
3402 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3406 | local_constant_declaration SEMICOLON
3409 DictionaryEntry de = (DictionaryEntry) $1;
3411 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3417 * The following is from Rhys' grammar:
3418 * > Types in local variable declarations must be recognized as
3419 * > expressions to prevent reduce/reduce errors in the grammar.
3420 * > The expressions are converted into types during semantic analysis.
3423 : primary_expression opt_rank_specifier
3425 // FIXME: Do something smart here regarding the composition of the type.
3427 // Ok, the above "primary_expression" is there to get rid of
3428 // both reduce/reduce and shift/reduces in the grammar, it should
3429 // really just be "type_name". If you use type_name, a reduce/reduce
3430 // creeps up. If you use namespace_or_type_name (which is all we need
3431 // really) two shift/reduces appear.
3434 // So the super-trick is that primary_expression
3435 // can only be either a SimpleName or a MemberAccess.
3436 // The MemberAccess case arises when you have a fully qualified type-name like :
3438 // SimpleName is when you have
3441 Expression expr = (Expression) $1;
3442 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3443 Error_ExpectingTypeName (lexer.Location, expr);
3447 // So we extract the string corresponding to the SimpleName
3451 if ((string) $2 == "")
3454 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3457 | builtin_types opt_rank_specifier
3459 if ((string) $2 == "")
3462 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3466 local_variable_pointer_type
3467 : primary_expression STAR
3469 Expression expr = (Expression) $1;
3470 Location l = lexer.Location;
3472 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3473 Error_ExpectingTypeName (l, expr);
3477 $$ = new ComposedCast ((Expression) $1, "*", l);
3479 | builtin_types STAR
3481 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3485 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3487 | local_variable_pointer_type STAR
3489 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3493 local_variable_declaration
3494 : local_variable_type variable_declarators
3497 $$ = new DictionaryEntry ($1, $2);
3501 | local_variable_pointer_type opt_rank_specifier variable_declarators
3506 if ((string) $2 == "")
3507 t = (Expression) $1;
3509 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3510 $$ = new DictionaryEntry (t, $3);
3516 local_constant_declaration
3517 : CONST local_variable_type constant_declarators
3520 $$ = new DictionaryEntry ($2, $3);
3526 expression_statement
3527 : statement_expression SEMICOLON
3534 // We have to do the wrapping here and not in the case above,
3535 // because statement_expression is used for example in for_statement
3537 statement_expression
3538 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3539 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3540 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3541 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3542 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3543 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3544 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3546 Report.Error (1002, lexer.Location, "Expecting `;'");
3551 object_creation_expression
3552 : object_or_delegate_creation_expression
3553 { note ("complain if this is a delegate maybe?"); }
3562 : if_statement_open if_statement_rest
3571 oob_stack.Push (lexer.Location);
3576 : boolean_expression CLOSE_PARENS
3579 Location l = (Location) oob_stack.Pop ();
3581 $$ = new If ((Expression) $1, (Statement) $3, l);
3583 if (RootContext.WarningLevel >= 3){
3584 if ($3 == EmptyStatement.Value)
3585 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3589 | boolean_expression CLOSE_PARENS
3590 embedded_statement ELSE embedded_statement
3592 Location l = (Location) oob_stack.Pop ();
3594 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3599 : SWITCH OPEN_PARENS
3601 oob_stack.Push (lexer.Location);
3602 switch_stack.Push (current_block);
3604 expression CLOSE_PARENS
3607 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3608 current_block = (Block) switch_stack.Pop ();
3624 Report.Error (1522, lexer.Location, "Empty switch block");
3632 ArrayList sections = new ArrayList (4);
3637 | switch_sections switch_section
3639 ArrayList sections = (ArrayList) $1;
3649 current_block = current_block.CreateSwitchBlock (lexer.Location);
3653 Block topmost = current_block;
3655 while (topmost.Implicit)
3656 topmost = topmost.Parent;
3657 $$ = new SwitchSection ((ArrayList) $1, topmost);
3664 ArrayList labels = new ArrayList (4);
3669 | switch_labels switch_label
3671 ArrayList labels = (ArrayList) ($1);
3679 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3680 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3683 1523, lexer.Location,
3684 "The keyword case or default must precede code in switch block");
3698 oob_stack.Push (lexer.Location);
3700 boolean_expression CLOSE_PARENS embedded_statement
3702 Location l = (Location) oob_stack.Pop ();
3703 $$ = new While ((Expression) $4, (Statement) $6, l);
3705 if (RootContext.WarningLevel >= 3){
3706 if ($6 == EmptyStatement.Value)
3707 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3713 : DO embedded_statement
3715 oob_stack.Push (lexer.Location);
3717 boolean_expression CLOSE_PARENS SEMICOLON
3719 Location l = (Location) oob_stack.Pop ();
3721 $$ = new Do ((Statement) $2, (Expression) $6, l);
3727 opt_for_initializer SEMICOLON
3729 Block assign_block = new Block (current_block);
3730 current_block = assign_block;
3732 if ($3 is DictionaryEntry){
3733 DictionaryEntry de = (DictionaryEntry) $3;
3735 Expression type = (Expression) de.Key;
3736 ArrayList var_declarators = (ArrayList) de.Value;
3738 foreach (VariableDeclaration decl in var_declarators){
3742 vi = current_block.AddVariable (
3743 type, decl.identifier, current_local_parameters, decl.Location);
3747 Location l = lexer.Location;
3749 if (decl.expression_or_array_initializer is Expression){
3750 expr = (Expression) decl.expression_or_array_initializer;
3751 } else if (decl.expression_or_array_initializer == null) {
3754 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3755 expr = new ArrayCreation (type, "", init, decl.Location);
3758 LocalVariableReference var;
3759 var = new LocalVariableReference (assign_block, decl.identifier, l);
3762 Assign a = new Assign (var, expr, decl.Location);
3764 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3770 oob_stack.Push (lexer.Location);
3772 opt_for_condition SEMICOLON
3773 opt_for_iterator CLOSE_PARENS
3776 Location l = (Location) oob_stack.Pop ();
3778 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3780 if (RootContext.WarningLevel >= 3){
3781 if ($10 == EmptyStatement.Value)
3782 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3785 current_block.AddStatement (f);
3786 while (current_block.Implicit)
3787 current_block = current_block.Parent;
3789 current_block = current_block.Parent;
3794 : /* empty */ { $$ = EmptyStatement.Value; }
3799 : local_variable_declaration
3800 | statement_expression_list
3804 : /* empty */ { $$ = null; }
3805 | boolean_expression
3809 : /* empty */ { $$ = EmptyStatement.Value; }
3814 : statement_expression_list
3817 statement_expression_list
3818 : statement_expression
3820 // CHANGE: was `null'
3821 Block b = new Block (current_block, Block.Flags.Implicit);
3823 b.AddStatement ((Statement) $1);
3826 | statement_expression_list COMMA statement_expression
3828 Block b = (Block) $1;
3830 b.AddStatement ((Statement) $3);
3836 : FOREACH OPEN_PARENS type IDENTIFIER IN
3838 oob_stack.Push (lexer.Location);
3840 expression CLOSE_PARENS
3842 oob_stack.Push (current_block);
3844 Block foreach_block = new Block (current_block);
3845 LocalVariableReference v = null;
3846 Location l = lexer.Location;
3849 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3853 // Get a writable reference to this read-only variable.
3854 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3856 current_block = foreach_block;
3859 oob_stack.Push (current_block);
3863 Block foreach_block = (Block) oob_stack.Pop ();
3864 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3865 Block prev_block = (Block) oob_stack.Pop ();
3866 Location l = (Location) oob_stack.Pop ();
3868 current_block = prev_block;
3871 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3872 foreach_block.AddStatement (f);
3881 | continue_statement
3891 $$ = new Break (lexer.Location);
3896 : CONTINUE SEMICOLON
3898 $$ = new Continue (lexer.Location);
3903 : GOTO IDENTIFIER SEMICOLON
3905 $$ = new Goto (current_block, (string) $2, lexer.Location);
3907 | GOTO CASE constant_expression SEMICOLON
3909 $$ = new GotoCase ((Expression) $3, lexer.Location);
3911 | GOTO DEFAULT SEMICOLON
3913 $$ = new GotoDefault (lexer.Location);
3918 : RETURN opt_expression SEMICOLON
3920 $$ = new Return ((Expression) $2, lexer.Location);
3925 : THROW opt_expression SEMICOLON
3927 $$ = new Throw ((Expression) $2, lexer.Location);
3932 : IDENTIFIER RETURN expression SEMICOLON
3934 string s = (string) $1;
3936 Report.Error (1003, lexer.Location, "; expected");
3939 if (!RootContext.V2){
3940 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3943 if (iterator_container == null){
3944 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3947 iterator_container.SetYields ();
3948 $$ = new Yield ((Expression) $3, lexer.Location);
3951 | IDENTIFIER BREAK SEMICOLON
3953 string s = (string) $1;
3955 Report.Error (1003, lexer.Location, "; expected");
3958 if (!RootContext.V2){
3959 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3962 if (iterator_container == null){
3963 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3966 iterator_container.SetYields ();
3967 $$ = new YieldBreak (lexer.Location);
3978 : TRY block catch_clauses
3981 ArrayList s = new ArrayList (4);
3983 foreach (Catch cc in (ArrayList) $3) {
3990 // Now s contains the list of specific catch clauses
3991 // and g contains the general one.
3993 $$ = new Try ((Block) $2, s, g, null, lexer.Location);
3995 | TRY block opt_catch_clauses FINALLY block
3998 ArrayList s = new ArrayList (4);
3999 ArrayList catch_list = (ArrayList) $3;
4001 if (catch_list != null){
4002 foreach (Catch cc in catch_list) {
4010 $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
4014 Report.Error (1524, lexer.Location, "Expected catch or finally");
4019 : /* empty */ { $$ = null; }
4026 ArrayList l = new ArrayList (4);
4031 | catch_clauses catch_clause
4033 ArrayList l = (ArrayList) $1;
4041 : /* empty */ { $$ = null; }
4046 : CATCH opt_catch_args
4048 Expression type = null;
4052 DictionaryEntry cc = (DictionaryEntry) $2;
4053 type = (Expression) cc.Key;
4054 id = (string) cc.Value;
4057 ArrayList one = new ArrayList (4);
4058 Location loc = lexer.Location;
4060 one.Add (new VariableDeclaration (id, null, loc));
4063 current_block = new Block (current_block);
4064 Block b = declare_local_variables (type, one, loc);
4069 Expression type = null;
4073 DictionaryEntry cc = (DictionaryEntry) $2;
4074 type = (Expression) cc.Key;
4075 id = (string) cc.Value;
4079 // FIXME: I can change this for an assignment.
4081 while (current_block != (Block) $1)
4082 current_block = current_block.Parent;
4087 $$ = new Catch (type, id , (Block) $4, lexer.Location);
4092 : /* empty */ { $$ = null; }
4097 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4099 $$ = new DictionaryEntry ($2, $3);
4106 $$ = new Checked ((Block) $2);
4113 $$ = new Unchecked ((Block) $2);
4120 if (!RootContext.Unsafe){
4121 Report.Error (227, lexer.Location,
4122 "Unsafe code can only be used if --unsafe is used");
4125 $$ = new Unsafe ((Block) $3);
4131 type fixed_pointer_declarators
4134 Block assign_block = new Block (current_block, Block.Flags.Implicit);
4135 ArrayList list = (ArrayList) $4;
4136 Expression type = (Expression) $3;
4137 Location l = lexer.Location;
4138 int top = list.Count;
4140 for (int i = 0; i < top; i++){
4141 Pair p = (Pair) list [i];
4144 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4153 current_block.AddStatement (assign_block);
4154 current_block = assign_block;
4155 oob_stack.Push (assign_block);
4160 Location l = (Location) oob_stack.Pop ();
4163 $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4167 fixed_pointer_declarators
4168 : fixed_pointer_declarator {
4169 ArrayList declarators = new ArrayList (4);
4171 declarators.Add ($1);
4174 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4176 ArrayList declarators = (ArrayList) $1;
4178 declarators.Add ($3);
4183 fixed_pointer_declarator
4184 : IDENTIFIER ASSIGN expression
4186 $$ = new Pair ($1, $3);
4190 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
4196 : LOCK OPEN_PARENS expression CLOSE_PARENS
4202 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4207 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4209 Block assign_block = new Block (current_block);
4210 current_block = assign_block;
4212 oob_stack.Push (lexer.Location);
4214 if ($3 is DictionaryEntry){
4215 DictionaryEntry de = (DictionaryEntry) $3;
4216 Location l = lexer.Location;
4218 Expression type = (Expression) de.Key;
4219 ArrayList var_declarators = (ArrayList) de.Value;
4221 ArrayList vars = new ArrayList (4);
4223 foreach (VariableDeclaration decl in var_declarators){
4225 LocalInfo vi = current_block.AddVariable (
4226 type, decl.identifier,
4227 current_local_parameters, decl.Location);
4233 if (decl.expression_or_array_initializer is Expression){
4234 expr = (Expression) decl.expression_or_array_initializer;
4236 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4238 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4241 expr = new ArrayCreation (type, "", init, decl.Location);
4244 LocalVariableReference var;
4246 // Get a writable reference to this read-only variable.
4247 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4249 // This is so that it is not a warning on using variables
4252 vars.Add (new DictionaryEntry (var, expr));
4254 // Assign a = new Assign (var, expr, decl.Location);
4255 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4257 $3 = new DictionaryEntry (type, vars);
4262 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4263 current_block.AddStatement (u);
4264 while (current_block.Implicit)
4265 current_block = current_block.Parent;
4267 current_block = current_block.Parent;
4271 resource_acquisition
4272 : local_variable_declaration
4279 // A class used to pass around variable declarations and constants
4281 public class VariableDeclaration {
4282 public string identifier;
4283 public object expression_or_array_initializer;
4284 public Location Location;
4285 public Attributes OptAttributes;
4287 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4289 this.identifier = id;
4290 this.expression_or_array_initializer = eoai;
4292 this.OptAttributes = opt_attrs;
4295 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4301 /// Used to pass around interface property information
4303 public class InterfaceAccessorInfo {
4305 public readonly Accessor Get, Set;
4307 public InterfaceAccessorInfo (bool has_get, bool has_set,
4308 Attributes get_attrs, Attributes set_attrs)
4311 Get = new Accessor (null, get_attrs);
4313 Set = new Accessor (null, set_attrs);
4319 // A class used to hold info about an indexer declarator
4321 public class IndexerDeclaration {
4322 public Expression type;
4323 public MemberName interface_type;
4324 public Parameters param_list;
4326 public IndexerDeclaration (Expression type, MemberName interface_type,
4327 Parameters param_list)
4330 this.interface_type = interface_type;
4331 this.param_list = param_list;
4336 // We use this when we do not have an object in advance that is an IIteratorContainer
4338 public class SimpleIteratorContainer : IIteratorContainer {
4341 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4346 public static SimpleIteratorContainer GetSimple () {
4347 Simple.Yields = false;
4351 public void SetYields () { Yields = true; }
4355 // A class used to hold info about an operator declarator
4357 public class OperatorDeclaration {
4358 public Operator.OpType optype;
4359 public Expression ret_type, arg1type, arg2type;
4360 public string arg1name, arg2name;
4361 public Location location;
4363 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4364 Expression arg1type, string arg1name,
4365 Expression arg2type, string arg2name, Location location)
4368 this.ret_type = ret_type;
4369 this.arg1type = arg1type;
4370 this.arg1name = arg1name;
4371 this.arg2type = arg2type;
4372 this.arg2name = arg2name;
4373 this.location = location;
4378 void Error_ExpectingTypeName (Location l, Expression expr)
4380 if (expr is Invocation){
4381 Report.Error (1002, l, "; expected");
4383 Report.Error (-1, l, "Invalid Type definition");
4388 // Given the @class_name name, it creates a fully qualified name
4389 // based on the containing declaration space
4392 MakeName (MemberName class_name)
4394 string ns = current_namespace.FullName;
4396 if (current_container.Name == ""){
4398 return new MemberName (new MemberName (ns), class_name);
4402 return new MemberName (current_container.MemberName, class_name);
4407 // Used to report back to the user the result of a declaration
4408 // in the current declaration space
4411 CheckDef (DeclSpace.AdditionResult result, string name, Location l)
4413 current_container.CheckDef (result, name, l);
4417 CheckDef (bool result, string name, Location l)
4421 CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
4424 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4426 Block implicit_block;
4427 ArrayList inits = null;
4430 // We use the `Used' property to check whether statements
4431 // have been added to the current block. If so, we need
4432 // to create another block to contain the new declaration
4433 // otherwise, as an optimization, we use the same block to
4434 // add the declaration.
4436 // FIXME: A further optimization is to check if the statements
4437 // that were added were added as part of the initialization
4438 // below. In which case, no other statements have been executed
4439 // and we might be able to reduce the number of blocks for
4440 // situations like this:
4442 // int j = 1; int k = j + 1;
4444 if (current_block.Used)
4445 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4447 implicit_block = current_block;
4449 foreach (VariableDeclaration decl in variable_declarators){
4451 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4452 if (decl.expression_or_array_initializer != null){
4454 inits = new ArrayList (4);
4461 return implicit_block;
4463 foreach (VariableDeclaration decl in inits){
4467 if (decl.expression_or_array_initializer is Expression){
4468 expr = (Expression) decl.expression_or_array_initializer;
4471 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4473 expr = new ArrayCreation (type, "", init, decl.Location);
4476 LocalVariableReference var;
4477 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4479 assign = new Assign (var, expr, decl.Location);
4481 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4484 return implicit_block;
4487 Block declare_local_constants (Expression type, ArrayList declarators)
4489 Block implicit_block;
4491 if (current_block.Used)
4492 implicit_block = new Block (current_block, Block.Flags.Implicit);
4494 implicit_block = current_block;
4496 foreach (VariableDeclaration decl in declarators){
4497 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4498 current_local_parameters, decl.Location);
4501 return implicit_block;
4504 void CheckAttributeTarget (string a)
4508 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4512 Location l = lexer.Location;
4513 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4519 void CheckUnaryOperator (Operator.OpType op)
4523 case Operator.OpType.LogicalNot:
4524 case Operator.OpType.OnesComplement:
4525 case Operator.OpType.Increment:
4526 case Operator.OpType.Decrement:
4527 case Operator.OpType.True:
4528 case Operator.OpType.False:
4529 case Operator.OpType.Addition:
4530 case Operator.OpType.Subtraction:
4535 Location l = lexer.Location;
4536 Report.Error (1019, l, "Overloadable unary operator expected");
4542 void CheckBinaryOperator (Operator.OpType op)
4546 case Operator.OpType.Addition:
4547 case Operator.OpType.Subtraction:
4548 case Operator.OpType.Multiply:
4549 case Operator.OpType.Division:
4550 case Operator.OpType.Modulus:
4551 case Operator.OpType.BitwiseAnd:
4552 case Operator.OpType.BitwiseOr:
4553 case Operator.OpType.ExclusiveOr:
4554 case Operator.OpType.LeftShift:
4555 case Operator.OpType.RightShift:
4556 case Operator.OpType.Equality:
4557 case Operator.OpType.Inequality:
4558 case Operator.OpType.GreaterThan:
4559 case Operator.OpType.LessThan:
4560 case Operator.OpType.GreaterThanOrEqual:
4561 case Operator.OpType.LessThanOrEqual:
4565 Location l = lexer.Location;
4566 Report.Error (1020, l, "Overloadable binary operator expected");
4572 void syntax_error (Location l, string msg)
4574 Report.Error (1003, l, "Syntax error, " + msg);
4577 void output (string s)
4579 Console.WriteLine (s);
4582 void note (string s)
4584 // Used to put annotations
4589 public Tokenizer Lexer {
4595 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4597 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4598 this.name = file.Name;
4600 current_container = RootContext.Tree.Types;
4601 current_container.NamespaceEntry = current_namespace;
4602 oob_stack = new Stack ();
4603 switch_stack = new Stack ();
4605 lexer = new Tokenizer (reader, file, defines);
4608 public void parse ()
4611 if (yacc_verbose_flag)
4612 yyparse (lexer, new yydebug.yyDebugSimple ());
4615 Tokenizer tokenizer = lexer as Tokenizer;
4616 tokenizer.cleanup ();
4617 } catch (Exception e){
4618 // Please do not remove this, it is used during debugging
4621 Console.WriteLine (e);
4622 Report.Error (-25, lexer.Location, "Parsing error");
4623 if (Driver.parser_verbose)
4624 Console.WriteLine (e);
4628 void CheckToken (int error, int yyToken, string msg)
4630 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4631 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4634 Report.Error (error, lexer.Location, msg);
4637 void CheckIdentifierToken (int yyToken)
4639 CheckToken (1041, yyToken, "Identifier expected");