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
46 /// If true, creates a toplevel block in the block production
47 /// This is flagged by the delegate creation
49 bool create_toplevel_block;
51 Delegate current_delegate;
54 /// This is used by the unary_expression code to resolve
55 /// a name against a parameter.
57 Parameters current_local_parameters;
60 /// Using during property parsing to describe the implicit
61 /// value parameter that is passed to the "set" and "get"accesor
62 /// methods (properties and indexers).
64 Expression implicit_value_parameter_type;
65 Parameters indexer_parameters;
68 /// Used to determine if we are parsing the get/set pair
69 /// of an indexer or a property
74 /// An out-of-band stack.
83 public bool yacc_verbose_flag;
85 // Name of the file we are parsing
94 /// Current attribute target
95 string current_attr_target;
97 /// assembly and module attribute definition is enabled
98 bool global_attrs_enabled = true;
102 %token NONE /* This token is never returned by our lexer */
103 %token ERROR // This is used not by the parser, but by the tokenizer.
107 *These are the C# keywords
194 /* C# keywords which are not really keywords */
200 /* C# single character operators/punctuation. */
201 %token OPEN_BRACE "{"
202 %token CLOSE_BRACE "}"
203 %token OPEN_BRACKET "["
204 %token CLOSE_BRACKET "]"
205 %token OPEN_PARENS "("
206 %token CLOSE_PARENS ")"
218 %token OP_GENERICS_LT "<"
220 %token OP_GENERICS_GT ">"
221 %token BITWISE_AND "&"
222 %token BITWISE_OR "|"
229 /* C# multi-character operators. */
232 %token OP_SHIFT_LEFT "<<"
233 %token OP_SHIFT_RIGHT ">>"
240 %token OP_MULT_ASSIGN "*="
241 %token OP_DIV_ASSIGN "/="
242 %token OP_MOD_ASSIGN "%="
243 %token OP_ADD_ASSIGN "+="
244 %token OP_SUB_ASSIGN "-="
245 %token OP_SHIFT_LEFT_ASSIGN "<<="
246 %token OP_SHIFT_RIGHT_ASSIGN ">>="
247 %token OP_AND_ASSIGN "&="
248 %token OP_XOR_ASSIGN "^="
249 %token OP_OR_ASSIGN "|="
253 %token LITERAL_INTEGER "int literal"
254 %token LITERAL_FLOAT "float literal"
255 %token LITERAL_DOUBLE "double literal"
256 %token LITERAL_DECIMAL "decimal literal"
257 %token LITERAL_CHARACTER "character literal"
258 %token LITERAL_STRING "string literal"
261 %token CLOSE_PARENS_CAST
262 %token CLOSE_PARENS_NO_CAST
263 %token CLOSE_PARENS_OPEN_PARENS
264 %token CLOSE_PARENS_MINUS
265 %token DEFAULT_OPEN_PARENS
266 %token GENERIC_DIMENSION
268 /* Add precedence rules to solve dangling else s/r conflict */
277 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
279 %left STAR DIV PERCENT
280 %right BANG CARRET UMINUS
281 %nonassoc OP_INC OP_DEC
283 %left OPEN_BRACKET OPEN_BRACE
287 %start compilation_unit
291 : outer_declarations opt_EOF
292 | outer_declarations global_attributes opt_EOF
293 | global_attributes opt_EOF
294 | opt_EOF /* allow empty files */
304 | outer_declarations outer_declaration
309 | namespace_member_declaration
314 | using_directives using_directive
318 : using_alias_directive
319 | using_namespace_directive
322 using_alias_directive
323 : USING IDENTIFIER ASSIGN
324 namespace_or_type_name SEMICOLON
326 current_namespace.UsingAlias ((string) $2, (MemberName) $4, lexer.Location);
329 CheckIdentifierToken (yyToken);
333 using_namespace_directive
334 : USING namespace_name SEMICOLON
336 current_namespace.Using ((string) $2, lexer.Location);
341 // Strictly speaking, namespaces don't have attributes but
342 // we parse global attributes along with namespace declarations and then
345 namespace_declaration
346 : opt_attributes NAMESPACE namespace_or_type_name
349 Report.Error(1518, Lexer.Location, "Attributes cannot be applied to namespaces."
350 + " Expected class, delegate, enum, interface, or struct");
353 MemberName name = (MemberName) $3;
355 if (name.TypeArguments != null)
356 syntax_error (lexer.Location, "namespace name expected");
357 else if ((current_namespace.Parent != null) && (name.Left != null)) {
358 Report.Error (134, lexer.Location,
359 "Cannot use qualified namespace names in nested " +
360 "namespace declarations");
363 current_namespace = new NamespaceEntry (
364 current_namespace, file, name.GetName (), lexer.Location);
366 namespace_body opt_semicolon
368 current_namespace = current_namespace.Parent;
383 : namespace_or_type_name {
384 MemberName name = (MemberName) $1;
386 if (name.TypeArguments != null)
387 syntax_error (lexer.Location, "namespace name expected");
389 $$ = name.GetName ();
396 opt_namespace_member_declarations
407 opt_namespace_member_declarations
409 | namespace_member_declarations
412 namespace_member_declarations
413 : namespace_member_declaration
414 | namespace_member_declarations namespace_member_declaration
417 namespace_member_declaration
424 Class c = (Class) $1;
425 mod_flags = c.ModFlags;
427 } else if ($1 is Struct){
428 Struct s = (Struct) $1;
429 mod_flags = s.ModFlags;
434 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
436 1527, lexer.Location,
437 "Namespace elements cant be explicitly " +
438 "declared private or protected in `" + name + "'");
440 current_namespace.DeclarationFound = true;
442 | namespace_declaration {
443 current_namespace.DeclarationFound = true;
446 | field_declaration {
447 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
449 | method_declaration {
450 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
457 | interface_declaration
459 | delegate_declaration
461 // Enable this when we have handled all errors, because this acts as a generic fallback
464 // Console.WriteLine ("Token=" + yyToken);
465 // Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
477 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
485 global_attrs_enabled = false;
490 global_attrs_enabled = false;
499 ArrayList sect = (ArrayList) $1;
501 if (global_attrs_enabled) {
502 if (current_attr_target == "module") {
503 CodeGen.Module.AddAttributes (sect);
505 } else if (current_attr_target == "assembly") {
506 CodeGen.Assembly.AddAttributes (sect);
509 $$ = new Attributes (sect);
512 $$ = new Attributes (sect);
514 current_attr_target = null;
516 | attribute_sections attribute_section
518 Attributes attrs = $1 as Attributes;
519 ArrayList sect = (ArrayList) $2;
521 if (global_attrs_enabled) {
522 if (current_attr_target == "module") {
523 CodeGen.Module.AddAttributes (sect);
525 } else if (current_attr_target == "assembly") {
526 CodeGen.Assembly.AddAttributes (sect);
530 attrs = new Attributes (sect);
532 attrs.AddAttributes (sect);
536 attrs = new Attributes (sect);
538 attrs.AddAttributes (sect);
541 current_attr_target = null;
546 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
550 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
556 attribute_target_specifier
557 : attribute_target COLON
559 current_attr_target = (string)$1;
567 CheckAttributeTarget ((string) $1);
570 | EVENT { $$ = "event"; }
571 | RETURN { $$ = "return"; }
577 ArrayList attrs = new ArrayList (4);
583 | attribute_list COMMA attribute
585 ArrayList attrs = (ArrayList) $1;
597 opt_attribute_arguments
599 MemberName mname = (MemberName) $1;
600 if (mname.IsGeneric) {
601 Report.Error (404, lexer.Location,
602 "'<' unexpected: attributes cannot be generic");
605 string name = mname.GetName ();
606 if (current_attr_target == "assembly" || current_attr_target == "module")
607 $$ = new GlobalAttribute (current_container, current_attr_target,
608 name, (ArrayList) $3, (Location) $2);
610 $$ = new Attribute (current_attr_target, name, (ArrayList) $3,
616 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
619 opt_attribute_arguments
620 : /* empty */ { $$ = null; }
621 | OPEN_PARENS attribute_arguments CLOSE_PARENS
629 : opt_positional_argument_list
634 ArrayList args = new ArrayList (4);
640 | positional_argument_list COMMA named_argument_list
642 ArrayList args = new ArrayList (4);
648 | named_argument_list
650 ArrayList args = new ArrayList (4);
659 opt_positional_argument_list
660 : /* empty */ { $$ = null; }
661 | positional_argument_list
664 positional_argument_list
667 ArrayList args = new ArrayList (4);
668 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
672 | positional_argument_list COMMA expression
674 ArrayList args = (ArrayList) $1;
675 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
684 ArrayList args = new ArrayList (4);
689 | named_argument_list COMMA named_argument
691 ArrayList args = (ArrayList) $1;
699 : IDENTIFIER ASSIGN expression
701 $$ = new DictionaryEntry (
703 new Argument ((Expression) $3, Argument.AType.Expression));
709 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
712 opt_class_member_declarations
714 | class_member_declarations
717 class_member_declarations
718 : class_member_declaration
719 | class_member_declarations
720 class_member_declaration
723 class_member_declaration
724 : constant_declaration // done
725 | field_declaration // done
726 | method_declaration // done
727 | property_declaration // done
728 | event_declaration // done
729 | indexer_declaration // done
730 | operator_declaration // done
731 | constructor_declaration // done
732 | destructor_declaration // done
742 MemberName name = MakeName ((MemberName) $5);
743 bool partial = (bool) $3;
746 ClassPart part = PartialContainer.CreatePart (
747 current_namespace, current_container, name, (int) $2,
748 (Attributes) $1, Kind.Struct, lexer.Location);
750 current_container = part.PartialContainer;
751 current_class = part;
753 current_class = new Struct (
754 current_namespace, current_container, name, (int) $2,
755 (Attributes) $1, lexer.Location);
757 current_container = current_class;
758 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
761 lexer.ConstraintsParsing = true;
764 opt_type_parameter_constraints_clauses
766 lexer.ConstraintsParsing = false;
769 current_class.Bases = (ArrayList) $7;
771 current_class.SetParameterInfo ((ArrayList) $8);
773 current_class.Register ();
780 current_container = current_container.Parent;
781 current_class = current_container;
783 | opt_attributes opt_modifiers opt_partial STRUCT error {
784 CheckIdentifierToken (yyToken);
789 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
792 opt_struct_member_declarations
794 | struct_member_declarations
797 struct_member_declarations
798 : struct_member_declaration
799 | struct_member_declarations struct_member_declaration
802 struct_member_declaration
803 : constant_declaration
806 | property_declaration
808 | indexer_declaration
809 | operator_declaration
810 | constructor_declaration
814 * This is only included so we can flag error 575:
815 * destructors only allowed on class types
817 | destructor_declaration
828 int modflags = (int) $2;
829 foreach (VariableDeclaration constant in (ArrayList) $5){
830 Location l = constant.Location;
831 if ((modflags & Modifiers.STATIC) != 0) {
832 Report.Error (504, l, "The constant '{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
836 Const c = new Const (
837 current_class, (Expression) $4, (string) constant.identifier,
838 (Expression) constant.expression_or_array_initializer, modflags,
841 current_container.AddConstant (c);
847 : constant_declarator
849 ArrayList constants = new ArrayList (4);
854 | constant_declarators COMMA constant_declarator
857 ArrayList constants = (ArrayList) $1;
864 : IDENTIFIER ASSIGN constant_expression
866 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
870 // A const field requires a value to be provided
871 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
883 Expression type = (Expression) $3;
886 foreach (VariableDeclaration var in (ArrayList) $4){
887 Location l = var.Location;
889 Field field = new Field (current_class, type, mod, var.identifier,
890 var.expression_or_array_initializer,
893 current_container.AddField (field);
901 Report.Error (670, lexer.Location, "void type is not allowed for fields");
906 : variable_declarator
908 ArrayList decl = new ArrayList (4);
912 | variable_declarators COMMA variable_declarator
914 ArrayList decls = (ArrayList) $1;
921 : IDENTIFIER ASSIGN variable_initializer
923 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
927 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
940 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
942 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
948 iterator_container = (IIteratorContainer) $1;
952 Method method = (Method) $1;
953 Block b = (Block) $3;
954 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
957 if ((method.ModFlags & extern_abstract) == 0){
959 501, lexer.Location, current_container.MakeName (method.Name) +
960 "must declare a body because it is not marked abstract or extern");
963 if ((method.ModFlags & Modifiers.EXTERN) != 0){
965 179, lexer.Location, current_container.MakeName (method.Name) +
966 " is declared extern, but has a body");
970 method.Block = (Block) $3;
971 current_container.AddMethod (method);
973 current_local_parameters = null;
974 iterator_container = null;
988 1585, lexer.Location, "Member modifier `" +
989 Modifiers.Name (i) + "' must precede member type and name");
1000 type namespace_or_type_name
1001 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1003 lexer.ConstraintsParsing = true;
1005 opt_type_parameter_constraints_clauses
1007 lexer.ConstraintsParsing = false;
1009 MemberName name = (MemberName) $4;
1011 if ($9 != null && name.TypeArguments == null)
1012 Report.Error (80, lexer.Location,
1013 "Contraints are not allowed on non-generic declarations");
1017 GenericMethod generic = null;
1018 if (name.TypeArguments != null) {
1019 generic = new GenericMethod (current_namespace, current_class,
1020 name, lexer.Location);
1022 generic.SetParameterInfo ((ArrayList) $9);
1025 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1026 name, (Parameters) $6, (Attributes) $1, lexer.Location);
1028 current_local_parameters = (Parameters) $6;
1034 VOID namespace_or_type_name
1035 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1037 lexer.ConstraintsParsing = true;
1039 opt_type_parameter_constraints_clauses
1041 lexer.ConstraintsParsing = false;
1043 MemberName name = (MemberName) $4;
1045 if ($9 != null && name.TypeArguments == null)
1046 Report.Error (80, lexer.Location,
1047 "Contraints are not allowed on non-generic declarations");
1050 GenericMethod generic = null;
1051 if (name.TypeArguments != null) {
1052 generic = new GenericMethod (current_namespace, current_class,
1053 name, lexer.Location);
1055 generic.SetParameterInfo ((ArrayList) $9);
1058 method = new Method (current_class, generic, TypeManager.system_void_expr,
1059 (int) $2, false, name, (Parameters) $6, (Attributes) $1,
1062 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);
1165 opt_parameter_modifier
1171 Report.Error (241, lexer.Location, "Default parameter specifiers are not permitted");
1176 opt_parameter_modifier
1177 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1178 | parameter_modifier
1182 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1183 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1187 : opt_attributes PARAMS type IDENTIFIER
1189 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1190 note ("type must be a single-dimension array type");
1192 | opt_attributes PARAMS type error {
1193 CheckIdentifierToken (yyToken);
1198 property_declaration
1201 type namespace_or_type_name
1204 implicit_value_parameter_type = (Expression) $3;
1206 lexer.PropertyParsing = true;
1208 $$ = lexer.Location;
1210 iterator_container = SimpleIteratorContainer.GetSimple ();
1212 accessor_declarations
1214 lexer.PropertyParsing = false;
1219 Pair pair = (Pair) $7;
1220 Accessor get_block = (Accessor) pair.First;
1221 Accessor set_block = (Accessor) pair.Second;
1223 Location loc = (Location) $6;
1224 MemberName name = (MemberName) $4;
1226 if (name.TypeArguments != null)
1227 syntax_error (lexer.Location, "a property can't have type arguments");
1229 prop = new Property (current_container, (Expression) $3, (int) $2, false,
1230 name, (Attributes) $1, get_block, set_block, loc);
1231 if (SimpleIteratorContainer.Simple.Yields)
1234 current_container.AddProperty (prop);
1235 implicit_value_parameter_type = null;
1236 iterator_container = null;
1240 accessor_declarations
1241 : get_accessor_declaration opt_set_accessor_declaration
1243 $$ = new Pair ($1, $2);
1245 | set_accessor_declaration opt_get_accessor_declaration
1247 $$ = new Pair ($2, $1);
1251 opt_get_accessor_declaration
1252 : /* empty */ { $$ = null; }
1253 | get_accessor_declaration
1256 opt_set_accessor_declaration
1257 : /* empty */ { $$ = null; }
1258 | set_accessor_declaration
1261 get_accessor_declaration
1262 : opt_attributes GET
1264 // If this is not the case, then current_local_parameters has already
1265 // been set in indexer_declaration
1266 if (parsing_indexer == false)
1267 current_local_parameters = null;
1269 current_local_parameters = indexer_parameters;
1270 lexer.PropertyParsing = false;
1274 $$ = new Accessor ((Block) $4, (Attributes) $1, lexer.Location);
1275 current_local_parameters = null;
1276 lexer.PropertyParsing = true;
1280 set_accessor_declaration
1281 : opt_attributes SET
1284 Parameter implicit_value_parameter = new Parameter (
1285 implicit_value_parameter_type, "value",
1286 Parameter.Modifier.NONE, null);
1288 if (parsing_indexer == false) {
1289 args = new Parameter [1];
1290 args [0] = implicit_value_parameter;
1291 current_local_parameters = new Parameters (args, null, lexer.Location);
1293 Parameter [] fpars = indexer_parameters.FixedParameters;
1296 int count = fpars.Length;
1298 args = new Parameter [count + 1];
1299 fpars.CopyTo (args, 0);
1300 args [count] = implicit_value_parameter;
1303 current_local_parameters = new Parameters (
1304 args, indexer_parameters.ArrayParameter, lexer.Location);
1307 lexer.PropertyParsing = false;
1311 $$ = new Accessor ((Block) $4, (Attributes) $1, lexer.Location);
1312 current_local_parameters = null;
1313 lexer.PropertyParsing = true;
1319 | SEMICOLON { $$ = null; }
1322 interface_declaration
1326 INTERFACE member_name
1328 MemberName name = MakeName ((MemberName) $5);
1329 bool partial = (bool) $3;
1332 ClassPart part = PartialContainer.CreatePart (
1333 current_namespace, current_container, name, (int) $2,
1334 (Attributes) $1, Kind.Interface, lexer.Location);
1336 current_container = part.PartialContainer;
1337 current_class = part;
1339 current_class = new Interface (
1340 current_namespace, current_container, name, (int) $2,
1341 (Attributes) $1, lexer.Location);
1343 current_container = current_class;
1344 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
1347 lexer.ConstraintsParsing = true;
1350 opt_type_parameter_constraints_clauses
1352 lexer.ConstraintsParsing = false;
1355 current_class.Bases = (ArrayList) $7;
1357 current_class.SetParameterInfo ((ArrayList) $8);
1359 current_class.Register ();
1361 interface_body opt_semicolon
1365 current_container = current_container.Parent;
1366 current_class = current_container;
1368 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1369 CheckIdentifierToken (yyToken);
1375 opt_interface_member_declarations
1379 opt_interface_member_declarations
1381 | interface_member_declarations
1384 interface_member_declarations
1385 : interface_member_declaration
1386 | interface_member_declarations interface_member_declaration
1389 interface_member_declaration
1390 : interface_method_declaration
1392 Method m = (Method) $1;
1394 current_container.AddMethod (m);
1396 | interface_property_declaration
1398 Property p = (Property) $1;
1400 current_container.AddProperty (p);
1402 | interface_event_declaration
1405 Event e = (Event) $1;
1406 current_container.AddEvent (e);
1409 | interface_indexer_declaration
1411 Indexer i = (Indexer) $1;
1413 current_container.AddIndexer (i);
1421 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1426 interface_method_declaration
1427 : opt_attributes opt_new type namespace_or_type_name
1428 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1430 lexer.ConstraintsParsing = true;
1432 opt_type_parameter_constraints_clauses
1435 lexer.ConstraintsParsing = false;
1437 MemberName name = (MemberName) $4;
1439 if ($9 != null && name.TypeArguments == null)
1440 Report.Error (80, lexer.Location,
1441 "Contraints are not allowed on non-generic declarations");
1443 GenericMethod generic = null;
1444 if (name.TypeArguments != null) {
1445 generic = new GenericMethod (current_namespace, current_class,
1446 name, lexer.Location);
1448 generic.SetParameterInfo ((ArrayList) $9);
1451 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1452 (Parameters) $6, (Attributes) $1, lexer.Location);
1454 | opt_attributes opt_new VOID namespace_or_type_name
1455 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1457 lexer.ConstraintsParsing = true;
1459 opt_type_parameter_constraints_clauses
1462 lexer.ConstraintsParsing = false;
1464 MemberName name = (MemberName) $4;
1466 if ($9 != null && name.TypeArguments == null)
1467 Report.Error (80, lexer.Location,
1468 "Contraints are not allowed on non-generic declarations");
1470 GenericMethod generic = null;
1471 if (name.TypeArguments != null) {
1472 generic = new GenericMethod (current_namespace, current_class,
1473 name, lexer.Location);
1475 generic.SetParameterInfo ((ArrayList) $9);
1478 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1479 true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
1483 interface_property_declaration
1488 { lexer.PropertyParsing = true; }
1490 { lexer.PropertyParsing = false; }
1493 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1495 $$ = new Property (current_class, (Expression) $3, (int) $2, true,
1496 new MemberName ((string) $4), (Attributes) $1,
1497 pinfo.Get, pinfo.Set, lexer.Location);
1502 CheckIdentifierToken (yyToken);
1508 : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, lexer.Location, lexer.Location); }
1509 | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1, lexer.Location, lexer.Location); }
1510 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1511 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3, lexer.Location, lexer.Location); }
1512 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1513 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1, lexer.Location, lexer.Location); }
1516 interface_event_declaration
1517 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1519 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1520 new MemberName ((string) $5), null,
1521 (Attributes) $1, lexer.Location);
1523 | opt_attributes opt_new EVENT type error {
1524 CheckIdentifierToken (yyToken);
1527 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1528 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1531 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1532 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1537 interface_indexer_declaration
1538 : opt_attributes opt_new type THIS
1539 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1541 { lexer.PropertyParsing = true; }
1543 { lexer.PropertyParsing = false; }
1546 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1548 $$ = new Indexer (current_class, (Expression) $3,
1549 new MemberName (TypeContainer.DefaultIndexerName),
1550 (int) $2, true, (Parameters) $6, (Attributes) $1,
1551 info.Get, info.Set, lexer.Location);
1555 operator_declaration
1556 : opt_attributes opt_modifiers operator_declarator
1558 iterator_container = SimpleIteratorContainer.GetSimple ();
1562 OperatorDeclaration decl = (OperatorDeclaration) $3;
1564 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
1566 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null);
1567 if (decl.arg2type != null)
1568 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null);
1570 Operator op = new Operator (
1571 current_class, decl.optype, decl.ret_type, (int) $2,
1572 new Parameters (param_list, null, decl.location),
1573 (Block) $5, (Attributes) $1, decl.location);
1575 if (SimpleIteratorContainer.Simple.Yields)
1578 // Note again, checking is done in semantic analysis
1579 current_container.AddOperator (op);
1581 current_local_parameters = null;
1582 iterator_container = null;
1588 | SEMICOLON { $$ = null; }
1591 : type OPERATOR overloadable_operator
1592 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1594 Operator.OpType op = (Operator.OpType) $3;
1595 CheckUnaryOperator (op);
1597 if (op == Operator.OpType.Addition)
1598 op = Operator.OpType.UnaryPlus;
1600 if (op == Operator.OpType.Subtraction)
1601 op = Operator.OpType.UnaryNegation;
1603 Parameter [] pars = new Parameter [1];
1605 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1607 current_local_parameters = new Parameters (pars, null, lexer.Location);
1609 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1610 null, null, lexer.Location);
1612 | type OPERATOR overloadable_operator
1614 type IDENTIFIER COMMA
1618 CheckBinaryOperator ((Operator.OpType) $3);
1620 Parameter [] pars = new Parameter [2];
1622 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1623 pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1625 current_local_parameters = new Parameters (pars, null, lexer.Location);
1627 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1628 (Expression) $5, (string) $6,
1629 (Expression) $8, (string) $9, lexer.Location);
1631 | conversion_operator_declarator
1634 overloadable_operator
1636 : BANG { $$ = Operator.OpType.LogicalNot; }
1637 | TILDE { $$ = Operator.OpType.OnesComplement; }
1638 | OP_INC { $$ = Operator.OpType.Increment; }
1639 | OP_DEC { $$ = Operator.OpType.Decrement; }
1640 | TRUE { $$ = Operator.OpType.True; }
1641 | FALSE { $$ = Operator.OpType.False; }
1642 // Unary and binary:
1643 | PLUS { $$ = Operator.OpType.Addition; }
1644 | MINUS { $$ = Operator.OpType.Subtraction; }
1646 | STAR { $$ = Operator.OpType.Multiply; }
1647 | DIV { $$ = Operator.OpType.Division; }
1648 | PERCENT { $$ = Operator.OpType.Modulus; }
1649 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1650 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1651 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1652 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1653 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1654 | OP_EQ { $$ = Operator.OpType.Equality; }
1655 | OP_NE { $$ = Operator.OpType.Inequality; }
1656 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1657 | OP_LT { $$ = Operator.OpType.LessThan; }
1658 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1659 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1662 conversion_operator_declarator
1663 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1665 Parameter [] pars = new Parameter [1];
1667 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1669 current_local_parameters = new Parameters (pars, null, lexer.Location);
1671 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1672 null, null, lexer.Location);
1674 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1676 Parameter [] pars = new Parameter [1];
1678 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1680 current_local_parameters = new Parameters (pars, null, lexer.Location);
1682 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1683 null, null, lexer.Location);
1687 syntax_error (lexer.Location, "'operator' expected");
1691 syntax_error (lexer.Location, "'operator' expected");
1695 constructor_declaration
1698 constructor_declarator
1701 Constructor c = (Constructor) $3;
1702 c.Block = (Block) $4;
1703 c.OptAttributes = (Attributes) $1;
1704 c.ModFlags = (int) $2;
1706 if (c.Name == current_container.Basename){
1707 if ((c.ModFlags & Modifiers.STATIC) != 0){
1708 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1710 515, c.Location, String.Format (
1711 "`{0}.{1}': static constructor can not have access modifiers",
1712 c.Name, current_container.Name));
1715 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1717 if (c.Initializer != null){
1720 "Static constructors can not have an explicit this or base " +
1721 "constructor invocations");
1724 if (!c.Parameters.Empty){
1726 132, c.Location, "Static constructors should not have parameters");
1729 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1732 // We let another layer check the validity of the constructor.
1733 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1736 current_container.AddConstructor (c);
1738 current_local_parameters = null;
1742 constructor_declarator
1744 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1746 oob_stack.Push (lexer.Location);
1748 current_local_parameters = (Parameters) $3;
1750 opt_constructor_initializer
1752 Location l = (Location) oob_stack.Pop ();
1753 $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $3,
1754 (ConstructorInitializer) $6, l);
1760 | SEMICOLON { $$ = null; }
1763 opt_constructor_initializer
1764 : /* empty */ { $$ = null; }
1765 | constructor_initializer
1768 constructor_initializer
1769 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1771 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1773 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1775 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1778 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1784 : /* EMPTY */ { $$ = 0; }
1785 | UNSAFE { $$ = Modifiers.UNSAFE; }
1786 | EXTERN { $$ = Modifiers.EXTERN; }
1789 destructor_declaration
1790 : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1792 if ((string) $4 != current_container.Basename){
1793 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1794 } else if (!(current_container is Class)){
1795 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1797 Location l = lexer.Location;
1800 if (!RootContext.StdLib && current_container.Name == "System.Object")
1801 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1803 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1805 if ((m & Modifiers.UNSAFE) != 0){
1806 if (!RootContext.Unsafe){
1807 Report.Error (227, l,
1808 "Unsafe code requires the -unsafe command " +
1809 "line option to be specified");
1813 Method d = new Destructor (
1814 current_class, TypeManager.system_void_expr, m, "Finalize",
1815 new Parameters (null, null, l), (Attributes) $1, l);
1817 d.Block = (Block) $7;
1818 current_container.AddMethod (d);
1826 EVENT type variable_declarators SEMICOLON
1828 foreach (VariableDeclaration var in (ArrayList) $5) {
1830 MemberName name = new MemberName (var.identifier);
1832 Event e = new EventField (
1833 current_class, (Expression) $4, (int) $2, false, name,
1834 var.expression_or_array_initializer, (Attributes) $1,
1837 current_container.AddEvent (e);
1843 EVENT type namespace_or_type_name
1846 implicit_value_parameter_type = (Expression) $4;
1847 lexer.EventParsing = true;
1848 oob_stack.Push (lexer.Location);
1850 event_accessor_declarations
1852 lexer.EventParsing = false;
1856 Location loc = (Location) oob_stack.Pop ();
1859 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1862 Pair pair = (Pair) $8;
1864 MemberName name = (MemberName) $5;
1866 if (name.TypeArguments != null)
1867 syntax_error (lexer.Location, "an event can't have type arguments");
1869 Event e = new EventProperty (
1870 current_class, (Expression) $4, (int) $2, false, name, null,
1871 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
1874 current_container.AddEvent (e);
1875 implicit_value_parameter_type = null;
1878 | opt_attributes opt_modifiers EVENT type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
1879 MemberName mn = (MemberName) $5;
1881 if (mn.Left != null)
1882 Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
1884 Report.Error (71, lexer.Location, "Event declaration should use property syntax");
1888 event_accessor_declarations
1889 : add_accessor_declaration remove_accessor_declaration
1891 $$ = new Pair ($1, $2);
1893 | remove_accessor_declaration add_accessor_declaration
1895 $$ = new Pair ($2, $1);
1897 | add_accessor_declaration { $$ = null; }
1898 | remove_accessor_declaration { $$ = null; }
1901 add_accessor_declaration
1902 : opt_attributes ADD
1904 Parameter [] args = new Parameter [1];
1905 Parameter implicit_value_parameter = new Parameter (
1906 implicit_value_parameter_type, "value",
1907 Parameter.Modifier.NONE, null);
1909 args [0] = implicit_value_parameter;
1911 current_local_parameters = new Parameters (args, null, lexer.Location);
1912 lexer.EventParsing = false;
1916 $$ = new Accessor ((Block) $4, (Attributes) $1, lexer.Location);
1917 lexer.EventParsing = true;
1919 | opt_attributes ADD error {
1920 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1925 remove_accessor_declaration
1926 : opt_attributes REMOVE
1928 Parameter [] args = new Parameter [1];
1929 Parameter implicit_value_parameter = new Parameter (
1930 implicit_value_parameter_type, "value",
1931 Parameter.Modifier.NONE, null);
1933 args [0] = implicit_value_parameter;
1935 current_local_parameters = new Parameters (args, null, lexer.Location);
1936 lexer.EventParsing = false;
1940 $$ = new Accessor ((Block) $4, (Attributes) $1, lexer.Location);
1941 lexer.EventParsing = true;
1943 | opt_attributes REMOVE error {
1944 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1950 : opt_attributes opt_modifiers indexer_declarator
1953 IndexerDeclaration decl = (IndexerDeclaration) $3;
1955 implicit_value_parameter_type = decl.type;
1957 lexer.PropertyParsing = true;
1958 parsing_indexer = true;
1960 indexer_parameters = decl.param_list;
1961 oob_stack.Push (lexer.Location);
1963 accessor_declarations
1965 lexer.PropertyParsing = false;
1966 parsing_indexer = false;
1970 // The signature is computed from the signature of the indexer. Look
1971 // at section 3.6 on the spec
1972 Location loc = (Location) oob_stack.Pop ();
1974 IndexerDeclaration decl = (IndexerDeclaration) $3;
1975 Pair pair = (Pair) $6;
1976 Accessor get_block = (Accessor) pair.First;
1977 Accessor set_block = (Accessor) pair.Second;
1980 if (decl.interface_type != null)
1981 name = new MemberName (decl.interface_type,
1982 TypeContainer.DefaultIndexerName, null);
1984 name = new MemberName (TypeContainer.DefaultIndexerName);
1986 indexer = new Indexer (current_class, decl.type, name,
1987 (int) $2, false, decl.param_list, (Attributes) $1,
1988 get_block, set_block, loc);
1990 current_container.AddIndexer (indexer);
1992 current_local_parameters = null;
1993 implicit_value_parameter_type = null;
1994 indexer_parameters = null;
1999 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2001 Parameters pars = (Parameters) $4;
2002 if (pars.HasArglist) {
2003 // "__arglist is not valid in this context"
2004 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2005 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2006 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2009 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
2011 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2013 Parameters pars = (Parameters) $6;
2015 if (pars.HasArglist) {
2016 // "__arglist is not valid in this context"
2017 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2018 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2019 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2021 MemberName name = (MemberName) $2;
2022 if (name.TypeArguments != null)
2023 syntax_error (lexer.Location, "an indexer can't have type arguments");
2025 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
2037 Location enum_location = lexer.Location;
2039 MemberName full_name = MakeName (new MemberName ((string) $4));
2040 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
2041 full_name, (Attributes) $1, enum_location);
2043 foreach (VariableDeclaration ev in (ArrayList) $6) {
2044 e.AddEnumMember (ev.identifier,
2045 (Expression) ev.expression_or_array_initializer,
2046 ev.Location, ev.OptAttributes);
2049 string name = full_name.GetName ();
2050 current_container.AddEnum (e);
2051 RootContext.Tree.RecordDecl (name, e);
2057 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2058 | COLON type { $$ = $2; }
2062 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
2068 opt_enum_member_declarations
2069 : /* empty */ { $$ = new ArrayList (4); }
2070 | enum_member_declarations opt_comma { $$ = $1; }
2073 enum_member_declarations
2074 : enum_member_declaration
2076 ArrayList l = new ArrayList (4);
2081 | enum_member_declarations COMMA enum_member_declaration
2083 ArrayList l = (ArrayList) $1;
2091 enum_member_declaration
2092 : opt_attributes IDENTIFIER
2094 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
2096 | opt_attributes IDENTIFIER
2098 $$ = lexer.Location;
2102 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
2106 delegate_declaration
2109 DELEGATE type member_name
2110 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2112 Location l = lexer.Location;
2113 MemberName name = MakeName ((MemberName) $5);
2114 Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
2115 (int) $2, name, (Parameters) $7, (Attributes) $1, l);
2117 current_container.AddDelegate (del);
2118 RootContext.Tree.RecordDecl (name.GetName (true), del);
2120 current_delegate = del;
2122 lexer.ConstraintsParsing = true;
2124 opt_type_parameter_constraints_clauses
2126 lexer.ConstraintsParsing = false;
2130 current_delegate.SetParameterInfo ((ArrayList) $9);
2132 current_delegate = null;
2136 DELEGATE VOID member_name
2137 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2139 Location l = lexer.Location;
2140 MemberName name = MakeName ((MemberName) $5);
2141 Delegate del = new Delegate (
2142 current_namespace, current_container,
2143 TypeManager.system_void_expr, (int) $2, name,
2144 (Parameters) $7, (Attributes) $1, l);
2146 current_container.AddDelegate (del);
2147 RootContext.Tree.RecordDecl (name.GetName (true), del);
2149 current_delegate = del;
2151 lexer.ConstraintsParsing = true;
2153 opt_type_parameter_constraints_clauses
2155 lexer.ConstraintsParsing = false;
2159 current_delegate.SetParameterInfo ((ArrayList) $9);
2161 current_delegate = null;
2165 namespace_or_type_name
2167 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2168 $$ = new MemberName ((MemberName) $1, (string) $3, (TypeArguments) $4);
2173 : IDENTIFIER opt_type_argument_list {
2174 $$ = new MemberName ((string) $1, (TypeArguments) $2);
2178 opt_type_argument_list
2179 : /* empty */ { $$ = null; }
2180 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2186 $$ = new TypeArguments ((int) $1, lexer.Location);
2192 TypeArguments type_args = new TypeArguments (lexer.Location);
2193 type_args.Add ((Expression) $1);
2196 | type_arguments COMMA type {
2197 TypeArguments type_args = (TypeArguments) $1;
2198 type_args.Add ((Expression) $3);
2204 * Before you think of adding a return_type, notice that we have been
2205 * using two rules in the places where it matters (one rule using type
2206 * and another identical one that uses VOID as the return type). This
2207 * gets rid of a shift/reduce couple
2210 : namespace_or_type_name
2212 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2224 // Note that here only unmanaged types are allowed but we
2225 // can't perform checks during this phase - we do it during
2226 // semantic analysis.
2228 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2232 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2238 | non_expression_type rank_specifier
2240 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2242 | non_expression_type STAR
2244 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2246 | expression rank_specifiers
2248 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2252 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2256 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2257 // through this different path
2259 | multiplicative_expression STAR
2261 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2268 ArrayList types = new ArrayList (4);
2273 | type_list COMMA type
2275 ArrayList types = (ArrayList) $1;
2283 * replaces all the productions for isolating the various
2284 * simple types, but we need this to reuse it easily in local_variable_type
2287 : OBJECT { $$ = TypeManager.system_object_expr; }
2288 | STRING { $$ = TypeManager.system_string_expr; }
2289 | BOOL { $$ = TypeManager.system_boolean_expr; }
2290 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2291 | FLOAT { $$ = TypeManager.system_single_expr; }
2292 | DOUBLE { $$ = TypeManager.system_double_expr; }
2297 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2298 | BYTE { $$ = TypeManager.system_byte_expr; }
2299 | SHORT { $$ = TypeManager.system_int16_expr; }
2300 | USHORT { $$ = TypeManager.system_uint16_expr; }
2301 | INT { $$ = TypeManager.system_int32_expr; }
2302 | UINT { $$ = TypeManager.system_uint32_expr; }
2303 | LONG { $$ = TypeManager.system_int64_expr; }
2304 | ULONG { $$ = TypeManager.system_uint64_expr; }
2305 | CHAR { $$ = TypeManager.system_char_expr; }
2306 | VOID { $$ = TypeManager.system_void_expr; }
2310 : type rank_specifiers
2312 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2317 // Expressions, section 7.5
2327 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2329 | parenthesized_expression
2330 | default_value_expression
2332 | invocation_expression
2336 | post_increment_expression
2337 | post_decrement_expression
2341 | checked_expression
2342 | unchecked_expression
2343 | pointer_member_access
2344 | anonymous_method_expression
2351 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2352 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2353 | NULL { $$ = NullLiteral.Null; }
2357 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2358 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2359 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2364 object v = lexer.Value;
2370 $$ = IntLiteral.Zero;
2372 $$ = IntLiteral.One;
2374 $$ = new IntLiteral (i);
2375 } else if (v is uint)
2376 $$ = new UIntLiteral ((UInt32) v);
2378 $$ = new LongLiteral ((Int64) v);
2379 else if (v is ulong)
2380 $$ = new ULongLiteral ((UInt64) v);
2382 Console.WriteLine ("OOPS. Unexpected result from scanner");
2387 : TRUE { $$ = new BoolLiteral (true); }
2388 | FALSE { $$ = new BoolLiteral (false); }
2391 parenthesized_expression_0
2392 : OPEN_PARENS expression CLOSE_PARENS
2395 lexer.Deambiguate_CloseParens ();
2396 // After this, the next token returned is one of
2397 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2398 // or CLOSE_PARENS_MINUS.
2402 parenthesized_expression
2403 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2407 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2409 // If a parenthesized expression is followed by a minus, we need to wrap
2410 // the expression inside a ParenthesizedExpression for the CS0075 check
2411 // in Binary.DoResolve().
2412 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2417 : primary_expression DOT IDENTIFIER opt_type_argument_list
2419 $$ = new MemberAccess ((Expression) $1, (string) $3,
2420 (TypeArguments) $4, lexer.Location);
2422 | predefined_type DOT IDENTIFIER opt_type_argument_list
2424 $$ = new MemberAccess ((Expression) $1, (string) $3,
2425 (TypeArguments) $4, lexer.Location);
2433 invocation_expression
2434 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2437 Location l = lexer.Location;
2438 Report.Error (1, l, "Parse error");
2440 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2442 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2444 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2446 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2448 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2453 : /* empty */ { $$ = null; }
2460 ArrayList list = new ArrayList (4);
2464 | argument_list COMMA argument
2466 ArrayList list = (ArrayList) $1;
2470 | argument_list error {
2471 CheckToken (1026, yyToken, ", or ) expected");
2478 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2480 | REF variable_reference
2482 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2484 | OUT variable_reference
2486 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2488 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
2490 ArrayList list = (ArrayList) $3;
2491 Argument[] args = new Argument [list.Count];
2492 list.CopyTo (args, 0);
2494 Expression expr = new Arglist (args, lexer.Location);
2495 $$ = new Argument (expr, Argument.AType.Expression);
2499 $$ = new Argument (new ArglistAccess (lexer.Location), Argument.AType.ArgList);
2504 : expression { note ("section 5.4"); $$ = $1; }
2508 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2510 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2512 | primary_expression rank_specifiers
2514 // So the super-trick is that primary_expression
2515 // can only be either a SimpleName or a MemberAccess.
2516 // The MemberAccess case arises when you have a fully qualified type-name like :
2518 // SimpleName is when you have
2521 Expression expr = (Expression) $1;
2522 if (expr is ComposedCast){
2523 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2524 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2525 Error_ExpectingTypeName (lexer.Location, expr);
2526 $$ = TypeManager.system_object_expr;
2529 // So we extract the string corresponding to the SimpleName
2532 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2540 ArrayList list = new ArrayList (4);
2544 | expression_list COMMA expression
2546 ArrayList list = (ArrayList) $1;
2555 $$ = new This (current_block, lexer.Location);
2560 : BASE DOT IDENTIFIER
2562 $$ = new BaseAccess ((string) $3, lexer.Location);
2564 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2566 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2569 Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
2574 post_increment_expression
2575 : primary_expression OP_INC
2577 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2578 (Expression) $1, lexer.Location);
2582 post_decrement_expression
2583 : primary_expression OP_DEC
2585 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2586 (Expression) $1, lexer.Location);
2591 : object_or_delegate_creation_expression
2592 | array_creation_expression
2595 object_or_delegate_creation_expression
2596 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2598 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2602 array_creation_expression
2603 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2605 opt_array_initializer
2607 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2609 | NEW type rank_specifiers array_initializer
2611 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2615 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2631 : rank_specifier opt_rank_specifier
2633 $$ = (string) $2 + (string) $1;
2638 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2640 $$ = "[" + (string) $2 + "]";
2660 | dim_separators COMMA
2662 $$ = (string) $1 + ",";
2666 opt_array_initializer
2678 : OPEN_BRACE CLOSE_BRACE
2680 ArrayList list = new ArrayList (4);
2683 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2685 $$ = (ArrayList) $2;
2689 variable_initializer_list
2690 : variable_initializer
2692 ArrayList list = new ArrayList (4);
2696 | variable_initializer_list COMMA variable_initializer
2698 ArrayList list = (ArrayList) $1;
2705 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2707 $$ = new TypeOfVoid (lexer.Location);
2709 | TYPEOF OPEN_PARENS
2711 lexer.TypeOfParsing = true;
2715 lexer.TypeOfParsing = false;
2716 $$ = new TypeOf ((Expression) $4, lexer.Location);
2721 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2722 $$ = new SizeOf ((Expression) $3, lexer.Location);
2727 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2729 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2733 unchecked_expression
2734 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2736 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2740 pointer_member_access
2741 : primary_expression OP_PTR IDENTIFIER
2745 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2746 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2750 anonymous_method_expression
2751 : DELEGATE opt_anonymous_method_signature {
2752 oob_stack.Push (current_local_parameters);
2753 current_local_parameters = (Parameters)$2;
2754 create_toplevel_block = true;
2757 Report.Error (-213, lexer.Location, "Anonymous methods are not supported in this branch");
2760 create_toplevel_block = false;
2761 if (RootContext.Version == LanguageVersion.ISO_1){
2762 Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
2765 $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
2766 current_local_parameters = (Parameters) oob_stack.Pop ();
2771 opt_anonymous_method_signature
2772 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
2773 | anonymous_method_signature
2776 anonymous_method_signature
2777 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2780 $$ = Parameters.EmptyReadOnlyParameters;
2782 ArrayList par_list = (ArrayList) $2;
2783 Parameter [] pars = new Parameter [par_list.Count];
2784 par_list.CopyTo (pars);
2785 $$ = new Parameters (pars, null, lexer.Location);
2790 opt_anonymous_method_parameter_list
2791 : /* empty */ { $$ = null; }
2792 | anonymous_method_parameter_list { $$ = $1; }
2795 anonymous_method_parameter_list
2796 : anonymous_method_parameter
2798 ArrayList a = new ArrayList (4);
2802 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2804 ArrayList a = (ArrayList) $1;
2810 anonymous_method_parameter
2811 : opt_parameter_modifier type IDENTIFIER {
2812 $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
2816 default_value_expression
2817 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
2819 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
2824 : primary_expression
2825 | BANG prefixed_unary_expression
2827 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2829 | TILDE prefixed_unary_expression
2831 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2837 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2839 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2841 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2843 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2849 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2851 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2856 // The idea to split this out is from Rhys' grammar
2857 // to solve the problem with casts.
2859 prefixed_unary_expression
2861 | PLUS prefixed_unary_expression
2863 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2865 | MINUS prefixed_unary_expression
2867 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2869 | OP_INC prefixed_unary_expression
2871 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2872 (Expression) $2, lexer.Location);
2874 | OP_DEC prefixed_unary_expression
2876 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2877 (Expression) $2, lexer.Location);
2879 | STAR prefixed_unary_expression
2881 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2883 | BITWISE_AND prefixed_unary_expression
2885 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2889 pre_increment_expression
2890 : OP_INC prefixed_unary_expression
2892 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2893 (Expression) $2, lexer.Location);
2897 pre_decrement_expression
2898 : OP_DEC prefixed_unary_expression
2900 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2901 (Expression) $2, lexer.Location);
2905 multiplicative_expression
2906 : prefixed_unary_expression
2907 | multiplicative_expression STAR prefixed_unary_expression
2909 $$ = new Binary (Binary.Operator.Multiply,
2910 (Expression) $1, (Expression) $3, lexer.Location);
2912 | multiplicative_expression DIV prefixed_unary_expression
2914 $$ = new Binary (Binary.Operator.Division,
2915 (Expression) $1, (Expression) $3, lexer.Location);
2917 | multiplicative_expression PERCENT prefixed_unary_expression
2919 $$ = new Binary (Binary.Operator.Modulus,
2920 (Expression) $1, (Expression) $3, lexer.Location);
2925 : multiplicative_expression
2926 | additive_expression PLUS multiplicative_expression
2928 $$ = new Binary (Binary.Operator.Addition,
2929 (Expression) $1, (Expression) $3, lexer.Location);
2931 | additive_expression MINUS multiplicative_expression
2933 $$ = new Binary (Binary.Operator.Subtraction,
2934 (Expression) $1, (Expression) $3, lexer.Location);
2939 : additive_expression
2940 | shift_expression OP_SHIFT_LEFT additive_expression
2942 $$ = new Binary (Binary.Operator.LeftShift,
2943 (Expression) $1, (Expression) $3, lexer.Location);
2945 | shift_expression OP_SHIFT_RIGHT additive_expression
2947 $$ = new Binary (Binary.Operator.RightShift,
2948 (Expression) $1, (Expression) $3, lexer.Location);
2952 relational_expression
2954 | relational_expression OP_LT shift_expression
2956 $$ = new Binary (Binary.Operator.LessThan,
2957 (Expression) $1, (Expression) $3, lexer.Location);
2959 | relational_expression OP_GT shift_expression
2961 $$ = new Binary (Binary.Operator.GreaterThan,
2962 (Expression) $1, (Expression) $3, lexer.Location);
2964 | relational_expression OP_LE shift_expression
2966 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2967 (Expression) $1, (Expression) $3, lexer.Location);
2969 | relational_expression OP_GE shift_expression
2971 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2972 (Expression) $1, (Expression) $3, lexer.Location);
2974 | relational_expression IS type
2976 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2978 | relational_expression AS type
2980 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2985 : relational_expression
2986 | equality_expression OP_EQ relational_expression
2988 $$ = new Binary (Binary.Operator.Equality,
2989 (Expression) $1, (Expression) $3, lexer.Location);
2991 | equality_expression OP_NE relational_expression
2993 $$ = new Binary (Binary.Operator.Inequality,
2994 (Expression) $1, (Expression) $3, lexer.Location);
2999 : equality_expression
3000 | and_expression BITWISE_AND equality_expression
3002 $$ = new Binary (Binary.Operator.BitwiseAnd,
3003 (Expression) $1, (Expression) $3, lexer.Location);
3007 exclusive_or_expression
3009 | exclusive_or_expression CARRET and_expression
3011 $$ = new Binary (Binary.Operator.ExclusiveOr,
3012 (Expression) $1, (Expression) $3, lexer.Location);
3016 inclusive_or_expression
3017 : exclusive_or_expression
3018 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3020 $$ = new Binary (Binary.Operator.BitwiseOr,
3021 (Expression) $1, (Expression) $3, lexer.Location);
3025 conditional_and_expression
3026 : inclusive_or_expression
3027 | conditional_and_expression OP_AND inclusive_or_expression
3029 $$ = new Binary (Binary.Operator.LogicalAnd,
3030 (Expression) $1, (Expression) $3, lexer.Location);
3034 conditional_or_expression
3035 : conditional_and_expression
3036 | conditional_or_expression OP_OR conditional_and_expression
3038 $$ = new Binary (Binary.Operator.LogicalOr,
3039 (Expression) $1, (Expression) $3, lexer.Location);
3043 conditional_expression
3044 : conditional_or_expression
3045 | conditional_or_expression INTERR expression COLON expression
3047 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
3051 assignment_expression
3052 : prefixed_unary_expression ASSIGN expression
3054 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
3056 | prefixed_unary_expression OP_MULT_ASSIGN expression
3058 Location l = lexer.Location;
3060 $$ = new CompoundAssign (
3061 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
3063 | prefixed_unary_expression OP_DIV_ASSIGN expression
3065 Location l = lexer.Location;
3067 $$ = new CompoundAssign (
3068 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
3070 | prefixed_unary_expression OP_MOD_ASSIGN expression
3072 Location l = lexer.Location;
3074 $$ = new CompoundAssign (
3075 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
3077 | prefixed_unary_expression OP_ADD_ASSIGN expression
3079 Location l = lexer.Location;
3081 $$ = new CompoundAssign (
3082 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
3084 | prefixed_unary_expression OP_SUB_ASSIGN expression
3086 Location l = lexer.Location;
3088 $$ = new CompoundAssign (
3089 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
3091 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3093 Location l = lexer.Location;
3095 $$ = new CompoundAssign (
3096 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
3098 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3100 Location l = lexer.Location;
3102 $$ = new CompoundAssign (
3103 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
3105 | prefixed_unary_expression OP_AND_ASSIGN expression
3107 Location l = lexer.Location;
3109 $$ = new CompoundAssign (
3110 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
3112 | prefixed_unary_expression OP_OR_ASSIGN expression
3114 Location l = lexer.Location;
3116 $$ = new CompoundAssign (
3117 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
3119 | prefixed_unary_expression OP_XOR_ASSIGN expression
3121 Location l = lexer.Location;
3123 $$ = new CompoundAssign (
3124 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
3129 : conditional_expression
3130 | assignment_expression
3150 MemberName name = MakeName ((MemberName) $5);
3151 bool partial = (bool) $3;
3152 int mod_flags = (int) $2;
3155 ClassPart part = PartialContainer.CreatePart (
3156 current_namespace, current_container, name, mod_flags,
3157 (Attributes) $1, Kind.Class, lexer.Location);
3159 current_container = part.PartialContainer;
3160 current_class = part;
3162 if ((mod_flags & Modifiers.STATIC) != 0) {
3163 current_class = new StaticClass (
3164 current_namespace, current_container, name,
3165 mod_flags, (Attributes) $1, lexer.Location);
3167 current_class = new Class (
3168 current_namespace, current_container, name,
3169 mod_flags, (Attributes) $1, lexer.Location);
3172 current_container = current_class;
3173 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
3176 lexer.ConstraintsParsing = true;
3179 opt_type_parameter_constraints_clauses
3181 lexer.ConstraintsParsing = false;
3184 if (current_class.Name == "System.Object") {
3185 Report.Error (537, current_class.Location,
3186 "The class System.Object cannot have a base " +
3187 "class or implement an interface.");
3189 current_class.Bases = (ArrayList) $7;
3192 current_class.SetParameterInfo ((ArrayList) $8);
3194 current_class.Register ();
3201 current_container = current_container.Parent;
3202 current_class = current_container;
3208 { $$ = (bool) false; }
3210 { $$ = (bool) true; }
3214 : /* empty */ { $$ = (int) 0; }
3220 | modifiers modifier
3225 if ((m1 & m2) != 0) {
3226 Location l = lexer.Location;
3227 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3229 $$ = (int) (m1 | m2);
3234 : NEW { $$ = Modifiers.NEW; }
3235 | PUBLIC { $$ = Modifiers.PUBLIC; }
3236 | PROTECTED { $$ = Modifiers.PROTECTED; }
3237 | INTERNAL { $$ = Modifiers.INTERNAL; }
3238 | PRIVATE { $$ = Modifiers.PRIVATE; }
3239 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3240 | SEALED { $$ = Modifiers.SEALED; }
3241 | STATIC { $$ = Modifiers.STATIC; }
3242 | READONLY { $$ = Modifiers.READONLY; }
3243 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3244 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3245 | EXTERN { $$ = Modifiers.EXTERN; }
3246 | VOLATILE { $$ = Modifiers.VOLATILE; }
3247 | UNSAFE { $$ = Modifiers.UNSAFE; }
3251 : /* empty */ { $$ = null; }
3252 | class_base { $$ = $1; }
3256 : COLON type_list { $$ = $2; }
3259 opt_type_parameter_constraints_clauses
3260 : /* empty */ { $$ = null; }
3261 | type_parameter_constraints_clauses
3265 type_parameter_constraints_clauses
3266 : type_parameter_constraints_clause {
3267 ArrayList constraints = new ArrayList (1);
3268 constraints.Add ($1);
3271 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3272 ArrayList constraints = (ArrayList) $1;
3274 constraints.Add ($2);
3279 type_parameter_constraints_clause
3280 : WHERE IDENTIFIER COLON type_parameter_constraints {
3281 $$ = new Constraints ((string) $2, (ArrayList) $4, lexer.Location);
3285 type_parameter_constraints
3286 : type_parameter_constraint {
3287 ArrayList constraints = new ArrayList (1);
3288 constraints.Add ($1);
3291 | type_parameter_constraints COMMA type_parameter_constraint {
3292 ArrayList constraints = (ArrayList) $1;
3294 constraints.Add ($3);
3299 type_parameter_constraint
3301 | NEW OPEN_PARENS CLOSE_PARENS {
3302 $$ = SpecialConstraint.Constructor;
3305 $$ = SpecialConstraint.ReferenceType;
3308 $$ = SpecialConstraint.ValueType;
3317 // A block is "contained" on the following places:
3319 // property_declaration as part of the accessor body (get/set)
3320 // operator_declaration
3321 // constructor_declaration
3322 // destructor_declaration
3323 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3328 if (current_block == null || create_toplevel_block){
3329 current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
3331 current_block = new Block (current_block, current_local_parameters,
3332 lexer.Location, Location.Null);
3335 opt_statement_list CLOSE_BRACE
3337 while (current_block.Implicit)
3338 current_block = current_block.Parent;
3340 current_block.SetEndLocation (lexer.Location);
3341 current_block = current_block.Parent;
3352 | statement_list statement
3356 : declaration_statement
3358 if ($1 != null && (Block) $1 != current_block){
3359 current_block.AddStatement ((Statement) $1);
3360 current_block = (Block) $1;
3363 | valid_declaration_statement
3365 current_block.AddStatement ((Statement) $1);
3370 valid_declaration_statement
3373 | expression_statement
3374 | selection_statement
3375 | iteration_statement
3379 | unchecked_statement
3387 : valid_declaration_statement
3388 | declaration_statement
3390 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
3395 Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
3403 $$ = EmptyStatement.Value;
3410 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3412 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3413 current_block.AddStatement (labeled);
3418 declaration_statement
3419 : local_variable_declaration SEMICOLON
3422 DictionaryEntry de = (DictionaryEntry) $1;
3424 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3428 | local_constant_declaration SEMICOLON
3431 DictionaryEntry de = (DictionaryEntry) $1;
3433 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3439 * The following is from Rhys' grammar:
3440 * > Types in local variable declarations must be recognized as
3441 * > expressions to prevent reduce/reduce errors in the grammar.
3442 * > The expressions are converted into types during semantic analysis.
3445 : primary_expression opt_rank_specifier
3447 // FIXME: Do something smart here regarding the composition of the type.
3449 // Ok, the above "primary_expression" is there to get rid of
3450 // both reduce/reduce and shift/reduces in the grammar, it should
3451 // really just be "type_name". If you use type_name, a reduce/reduce
3452 // creeps up. If you use namespace_or_type_name (which is all we need
3453 // really) two shift/reduces appear.
3456 // So the super-trick is that primary_expression
3457 // can only be either a SimpleName or a MemberAccess.
3458 // The MemberAccess case arises when you have a fully qualified type-name like :
3460 // SimpleName is when you have
3463 Expression expr = (Expression) $1;
3464 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3465 Error_ExpectingTypeName (lexer.Location, expr);
3469 // So we extract the string corresponding to the SimpleName
3473 if ((string) $2 == "")
3476 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3479 | builtin_types opt_rank_specifier
3481 if ((string) $2 == "")
3484 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3488 local_variable_pointer_type
3489 : primary_expression STAR
3491 Expression expr = (Expression) $1;
3492 Location l = lexer.Location;
3494 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3495 Error_ExpectingTypeName (l, expr);
3499 $$ = new ComposedCast ((Expression) $1, "*", l);
3501 | builtin_types STAR
3503 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3507 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3509 | local_variable_pointer_type STAR
3511 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3515 local_variable_declaration
3516 : local_variable_type variable_declarators
3519 $$ = new DictionaryEntry ($1, $2);
3523 | local_variable_pointer_type opt_rank_specifier variable_declarators
3528 if ((string) $2 == "")
3529 t = (Expression) $1;
3531 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3532 $$ = new DictionaryEntry (t, $3);
3538 local_constant_declaration
3539 : CONST local_variable_type constant_declarators
3542 $$ = new DictionaryEntry ($2, $3);
3548 expression_statement
3549 : statement_expression SEMICOLON
3556 // We have to do the wrapping here and not in the case above,
3557 // because statement_expression is used for example in for_statement
3559 statement_expression
3560 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3561 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3562 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3563 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3564 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3565 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3566 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3568 Report.Error (1002, lexer.Location, "Expecting `;'");
3573 object_creation_expression
3574 : object_or_delegate_creation_expression
3575 { note ("complain if this is a delegate maybe?"); }
3584 : if_statement_open if_statement_rest
3593 oob_stack.Push (lexer.Location);
3598 : boolean_expression CLOSE_PARENS
3601 Location l = (Location) oob_stack.Pop ();
3603 $$ = new If ((Expression) $1, (Statement) $3, l);
3605 if (RootContext.WarningLevel >= 3){
3606 if ($3 == EmptyStatement.Value)
3607 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3611 | boolean_expression CLOSE_PARENS
3612 embedded_statement ELSE embedded_statement
3614 Location l = (Location) oob_stack.Pop ();
3616 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3621 : SWITCH OPEN_PARENS
3623 oob_stack.Push (lexer.Location);
3624 switch_stack.Push (current_block);
3626 expression CLOSE_PARENS
3629 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3630 current_block = (Block) switch_stack.Pop ();
3646 Report.Error (1522, lexer.Location, "Empty switch block");
3654 ArrayList sections = new ArrayList (4);
3659 | switch_sections switch_section
3661 ArrayList sections = (ArrayList) $1;
3671 current_block = current_block.CreateSwitchBlock (lexer.Location);
3675 Block topmost = current_block;
3677 while (topmost.Implicit)
3678 topmost = topmost.Parent;
3679 $$ = new SwitchSection ((ArrayList) $1, topmost);
3686 ArrayList labels = new ArrayList (4);
3691 | switch_labels switch_label
3693 ArrayList labels = (ArrayList) ($1);
3701 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3702 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3705 1523, lexer.Location,
3706 "The keyword case or default must precede code in switch block");
3720 oob_stack.Push (lexer.Location);
3722 boolean_expression CLOSE_PARENS embedded_statement
3724 Location l = (Location) oob_stack.Pop ();
3725 $$ = new While ((Expression) $4, (Statement) $6, l);
3727 if (RootContext.WarningLevel >= 3){
3728 if ($6 == EmptyStatement.Value)
3729 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3735 : DO embedded_statement
3737 oob_stack.Push (lexer.Location);
3739 boolean_expression CLOSE_PARENS SEMICOLON
3741 Location l = (Location) oob_stack.Pop ();
3743 $$ = new Do ((Statement) $2, (Expression) $6, l);
3749 opt_for_initializer SEMICOLON
3751 Block assign_block = new Block (current_block);
3752 current_block = assign_block;
3754 if ($3 is DictionaryEntry){
3755 DictionaryEntry de = (DictionaryEntry) $3;
3757 Expression type = (Expression) de.Key;
3758 ArrayList var_declarators = (ArrayList) de.Value;
3760 foreach (VariableDeclaration decl in var_declarators){
3764 vi = current_block.AddVariable (
3765 type, decl.identifier, current_local_parameters, decl.Location);
3769 Location l = lexer.Location;
3771 if (decl.expression_or_array_initializer is Expression){
3772 expr = (Expression) decl.expression_or_array_initializer;
3773 } else if (decl.expression_or_array_initializer == null) {
3776 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3777 expr = new ArrayCreation (type, "", init, decl.Location);
3780 LocalVariableReference var;
3781 var = new LocalVariableReference (assign_block, decl.identifier, l);
3784 Assign a = new Assign (var, expr, decl.Location);
3786 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3792 oob_stack.Push (lexer.Location);
3794 opt_for_condition SEMICOLON
3795 opt_for_iterator CLOSE_PARENS
3798 Location l = (Location) oob_stack.Pop ();
3800 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3802 if (RootContext.WarningLevel >= 3){
3803 if ($10 == EmptyStatement.Value)
3804 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3807 current_block.AddStatement (f);
3808 while (current_block.Implicit)
3809 current_block = current_block.Parent;
3811 current_block = current_block.Parent;
3816 : /* empty */ { $$ = EmptyStatement.Value; }
3821 : local_variable_declaration
3822 | statement_expression_list
3826 : /* empty */ { $$ = null; }
3827 | boolean_expression
3831 : /* empty */ { $$ = EmptyStatement.Value; }
3836 : statement_expression_list
3839 statement_expression_list
3840 : statement_expression
3842 // CHANGE: was `null'
3843 Block b = new Block (current_block, Block.Flags.Implicit);
3845 b.AddStatement ((Statement) $1);
3848 | statement_expression_list COMMA statement_expression
3850 Block b = (Block) $1;
3852 b.AddStatement ((Statement) $3);
3858 : FOREACH OPEN_PARENS type IDENTIFIER IN
3860 oob_stack.Push (lexer.Location);
3862 expression CLOSE_PARENS
3864 oob_stack.Push (current_block);
3866 Block foreach_block = new Block (current_block);
3867 LocalVariableReference v = null;
3868 Location l = lexer.Location;
3871 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3875 // Get a writable reference to this read-only variable.
3876 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3878 current_block = foreach_block;
3881 oob_stack.Push (current_block);
3885 Block foreach_block = (Block) oob_stack.Pop ();
3886 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3887 Block prev_block = (Block) oob_stack.Pop ();
3888 Location l = (Location) oob_stack.Pop ();
3890 current_block = prev_block;
3893 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3894 foreach_block.AddStatement (f);
3903 | continue_statement
3913 $$ = new Break (lexer.Location);
3918 : CONTINUE SEMICOLON
3920 $$ = new Continue (lexer.Location);
3925 : GOTO IDENTIFIER SEMICOLON
3927 $$ = new Goto (current_block, (string) $2, lexer.Location);
3929 | GOTO CASE constant_expression SEMICOLON
3931 $$ = new GotoCase ((Expression) $3, lexer.Location);
3933 | GOTO DEFAULT SEMICOLON
3935 $$ = new GotoDefault (lexer.Location);
3940 : RETURN opt_expression SEMICOLON
3942 $$ = new Return ((Expression) $2, lexer.Location);
3947 : THROW opt_expression SEMICOLON
3949 $$ = new Throw ((Expression) $2, lexer.Location);
3954 : IDENTIFIER RETURN expression SEMICOLON
3956 string s = (string) $1;
3958 Report.Error (1003, lexer.Location, "; expected");
3961 if (RootContext.Version == LanguageVersion.ISO_1){
3962 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
3965 if (iterator_container == null){
3966 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3969 iterator_container.SetYields ();
3970 $$ = new Yield ((Expression) $3, lexer.Location);
3973 | IDENTIFIER BREAK SEMICOLON
3975 string s = (string) $1;
3977 Report.Error (1003, lexer.Location, "; expected");
3980 if (RootContext.Version == LanguageVersion.ISO_1){
3981 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
3984 if (iterator_container == null){
3985 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3988 iterator_container.SetYields ();
3989 $$ = new YieldBreak (lexer.Location);
4000 : TRY block catch_clauses
4004 ArrayList c = (ArrayList)$3;
4005 for (int i = 0; i < c.Count; ++i) {
4006 Catch cc = (Catch) c [i];
4008 if (i != c.Count - 1)
4009 Report.Error (1017, cc.loc, "Empty catch block must be the last in a series of catch blocks");
4016 // Now s contains the list of specific catch clauses
4017 // and g contains the general one.
4019 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4021 | TRY block opt_catch_clauses FINALLY block
4024 ArrayList s = new ArrayList (4);
4025 ArrayList catch_list = (ArrayList) $3;
4027 if (catch_list != null){
4028 foreach (Catch cc in catch_list) {
4036 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4040 Report.Error (1524, lexer.Location, "Expected catch or finally");
4045 : /* empty */ { $$ = null; }
4052 ArrayList l = new ArrayList (4);
4057 | catch_clauses catch_clause
4059 ArrayList l = (ArrayList) $1;
4067 : /* empty */ { $$ = null; }
4072 : CATCH opt_catch_args
4074 Expression type = null;
4078 DictionaryEntry cc = (DictionaryEntry) $2;
4079 type = (Expression) cc.Key;
4080 id = (string) cc.Value;
4083 ArrayList one = new ArrayList (4);
4084 Location loc = lexer.Location;
4086 one.Add (new VariableDeclaration (id, null, loc));
4089 current_block = new Block (current_block);
4090 Block b = declare_local_variables (type, one, loc);
4095 Expression type = null;
4099 DictionaryEntry cc = (DictionaryEntry) $2;
4100 type = (Expression) cc.Key;
4101 id = (string) cc.Value;
4105 // FIXME: I can change this for an assignment.
4107 while (current_block != (Block) $1)
4108 current_block = current_block.Parent;
4113 $$ = new Catch (type, id , (Block) $4, ((Block) $4).loc);
4118 : /* empty */ { $$ = null; }
4123 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4125 $$ = new DictionaryEntry ($2, $3);
4132 $$ = new Checked ((Block) $2);
4139 $$ = new Unchecked ((Block) $2);
4146 if (!RootContext.Unsafe){
4147 Report.Error (227, lexer.Location,
4148 "Unsafe code can only be used if --unsafe is used");
4151 $$ = new Unsafe ((Block) $3);
4157 type fixed_pointer_declarators
4160 ArrayList list = (ArrayList) $4;
4161 Expression type = (Expression) $3;
4162 Location l = lexer.Location;
4163 int top = list.Count;
4165 Block assign_block = new Block (current_block);
4166 current_block = assign_block;
4168 for (int i = 0; i < top; i++){
4169 Pair p = (Pair) list [i];
4172 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4186 Location l = (Location) oob_stack.Pop ();
4188 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4190 if (RootContext.WarningLevel >= 3){
4191 if ($7 == EmptyStatement.Value)
4192 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
4195 current_block.AddStatement (f);
4196 while (current_block.Implicit)
4197 current_block = current_block.Parent;
4199 current_block = current_block.Parent;
4203 fixed_pointer_declarators
4204 : fixed_pointer_declarator {
4205 ArrayList declarators = new ArrayList (4);
4207 declarators.Add ($1);
4210 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4212 ArrayList declarators = (ArrayList) $1;
4214 declarators.Add ($3);
4219 fixed_pointer_declarator
4220 : IDENTIFIER ASSIGN expression
4222 $$ = new Pair ($1, $3);
4226 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
4232 : LOCK OPEN_PARENS expression CLOSE_PARENS
4238 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4243 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4245 Block assign_block = new Block (current_block);
4246 current_block = assign_block;
4248 oob_stack.Push (lexer.Location);
4250 if ($3 is DictionaryEntry){
4251 DictionaryEntry de = (DictionaryEntry) $3;
4252 Location l = lexer.Location;
4254 Expression type = (Expression) de.Key;
4255 ArrayList var_declarators = (ArrayList) de.Value;
4257 ArrayList vars = new ArrayList (4);
4259 foreach (VariableDeclaration decl in var_declarators){
4261 LocalInfo vi = current_block.AddVariable (
4262 type, decl.identifier,
4263 current_local_parameters, decl.Location);
4269 if (decl.expression_or_array_initializer is Expression){
4270 expr = (Expression) decl.expression_or_array_initializer;
4272 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4274 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4277 expr = new ArrayCreation (type, "", init, decl.Location);
4280 LocalVariableReference var;
4282 // Get a writable reference to this read-only variable.
4283 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4285 // This is so that it is not a warning on using variables
4288 vars.Add (new DictionaryEntry (var, expr));
4290 // Assign a = new Assign (var, expr, decl.Location);
4291 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4293 $3 = new DictionaryEntry (type, vars);
4298 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4299 current_block.AddStatement (u);
4300 while (current_block.Implicit)
4301 current_block = current_block.Parent;
4303 current_block = current_block.Parent;
4307 resource_acquisition
4308 : local_variable_declaration
4315 // A class used to pass around variable declarations and constants
4317 public class VariableDeclaration {
4318 public string identifier;
4319 public object expression_or_array_initializer;
4320 public Location Location;
4321 public Attributes OptAttributes;
4323 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4325 this.identifier = id;
4326 this.expression_or_array_initializer = eoai;
4328 this.OptAttributes = opt_attrs;
4331 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4337 /// Used to pass around interface property information
4339 public class InterfaceAccessorInfo {
4341 public readonly Accessor Get, Set;
4343 public InterfaceAccessorInfo (bool has_get, bool has_set,
4344 Attributes get_attrs, Attributes set_attrs, Location get_loc, Location set_loc)
4347 Get = new Accessor (null, get_attrs, get_loc);
4349 Set = new Accessor (null, set_attrs, set_loc);
4355 // A class used to hold info about an indexer declarator
4357 public class IndexerDeclaration {
4358 public Expression type;
4359 public MemberName interface_type;
4360 public Parameters param_list;
4362 public IndexerDeclaration (Expression type, MemberName interface_type,
4363 Parameters param_list)
4366 this.interface_type = interface_type;
4367 this.param_list = param_list;
4372 // We use this when we do not have an object in advance that is an IIteratorContainer
4374 public class SimpleIteratorContainer : IIteratorContainer {
4377 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4382 public static SimpleIteratorContainer GetSimple () {
4383 Simple.Yields = false;
4387 public void SetYields () { Yields = true; }
4391 // A class used to hold info about an operator declarator
4393 public class OperatorDeclaration {
4394 public Operator.OpType optype;
4395 public Expression ret_type, arg1type, arg2type;
4396 public string arg1name, arg2name;
4397 public Location location;
4399 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4400 Expression arg1type, string arg1name,
4401 Expression arg2type, string arg2name, Location location)
4404 this.ret_type = ret_type;
4405 this.arg1type = arg1type;
4406 this.arg1name = arg1name;
4407 this.arg2type = arg2type;
4408 this.arg2name = arg2name;
4409 this.location = location;
4414 void Error_ExpectingTypeName (Location l, Expression expr)
4416 if (expr is Invocation){
4417 Report.Error (1002, l, "; expected");
4419 Report.Error (-1, l, "Invalid Type definition");
4424 // Given the @class_name name, it creates a fully qualified name
4425 // based on the containing declaration space
4428 MakeName (MemberName class_name)
4430 string ns = current_namespace.FullName;
4432 if (current_container.Name == ""){
4434 return new MemberName (new MemberName (ns), class_name);
4438 return new MemberName (current_container.MemberName, class_name);
4442 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4444 Block implicit_block;
4445 ArrayList inits = null;
4448 // We use the `Used' property to check whether statements
4449 // have been added to the current block. If so, we need
4450 // to create another block to contain the new declaration
4451 // otherwise, as an optimization, we use the same block to
4452 // add the declaration.
4454 // FIXME: A further optimization is to check if the statements
4455 // that were added were added as part of the initialization
4456 // below. In which case, no other statements have been executed
4457 // and we might be able to reduce the number of blocks for
4458 // situations like this:
4460 // int j = 1; int k = j + 1;
4462 if (current_block.Used)
4463 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4465 implicit_block = current_block;
4467 foreach (VariableDeclaration decl in variable_declarators){
4469 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4470 if (decl.expression_or_array_initializer != null){
4472 inits = new ArrayList (4);
4479 return implicit_block;
4481 foreach (VariableDeclaration decl in inits){
4485 if (decl.expression_or_array_initializer is Expression){
4486 expr = (Expression) decl.expression_or_array_initializer;
4489 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4491 expr = new ArrayCreation (type, "", init, decl.Location);
4494 LocalVariableReference var;
4495 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4497 assign = new Assign (var, expr, decl.Location);
4499 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4502 return implicit_block;
4505 Block declare_local_constants (Expression type, ArrayList declarators)
4507 Block implicit_block;
4509 if (current_block.Used)
4510 implicit_block = new Block (current_block, Block.Flags.Implicit);
4512 implicit_block = current_block;
4514 foreach (VariableDeclaration decl in declarators){
4515 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4516 current_local_parameters, decl.Location);
4519 return implicit_block;
4522 void CheckAttributeTarget (string a)
4526 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4530 Location l = lexer.Location;
4531 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4537 void CheckUnaryOperator (Operator.OpType op)
4541 case Operator.OpType.LogicalNot:
4542 case Operator.OpType.OnesComplement:
4543 case Operator.OpType.Increment:
4544 case Operator.OpType.Decrement:
4545 case Operator.OpType.True:
4546 case Operator.OpType.False:
4547 case Operator.OpType.Addition:
4548 case Operator.OpType.Subtraction:
4553 Location l = lexer.Location;
4554 Report.Error (1019, l, "Overloadable unary operator expected");
4560 void CheckBinaryOperator (Operator.OpType op)
4564 case Operator.OpType.Addition:
4565 case Operator.OpType.Subtraction:
4566 case Operator.OpType.Multiply:
4567 case Operator.OpType.Division:
4568 case Operator.OpType.Modulus:
4569 case Operator.OpType.BitwiseAnd:
4570 case Operator.OpType.BitwiseOr:
4571 case Operator.OpType.ExclusiveOr:
4572 case Operator.OpType.LeftShift:
4573 case Operator.OpType.RightShift:
4574 case Operator.OpType.Equality:
4575 case Operator.OpType.Inequality:
4576 case Operator.OpType.GreaterThan:
4577 case Operator.OpType.LessThan:
4578 case Operator.OpType.GreaterThanOrEqual:
4579 case Operator.OpType.LessThanOrEqual:
4583 Location l = lexer.Location;
4584 Report.Error (1020, l, "Overloadable binary operator expected");
4590 void syntax_error (Location l, string msg)
4592 Report.Error (1003, l, "Syntax error, " + msg);
4595 void output (string s)
4597 Console.WriteLine (s);
4600 void note (string s)
4602 // Used to put annotations
4607 public Tokenizer Lexer {
4613 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4615 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4616 this.name = file.Name;
4618 current_container = RootContext.Tree.Types;
4619 current_container.NamespaceEntry = current_namespace;
4620 oob_stack = new Stack ();
4621 switch_stack = new Stack ();
4623 lexer = new Tokenizer (reader, file, defines);
4626 public void parse ()
4629 if (yacc_verbose_flag)
4630 yyparse (lexer, new yydebug.yyDebugSimple ());
4633 Tokenizer tokenizer = lexer as Tokenizer;
4634 tokenizer.cleanup ();
4635 } catch (Exception e){
4637 // Removed for production use, use parser verbose to get the output.
4639 // Console.WriteLine (e);
4640 Report.Error (-25, lexer.Location, "Parsing error");
4641 if (Driver.parser_verbose)
4642 Console.WriteLine (e);
4646 void CheckToken (int error, int yyToken, string msg)
4648 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4649 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4652 Report.Error (error, lexer.Location, msg);
4655 void CheckIdentifierToken (int yyToken)
4657 CheckToken (1041, yyToken, "Identifier expected");