3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnu.org)
6 // Ravi Pratap (ravi@ximian.com)
8 // Licensed under the terms of the GNU GPL
10 // (C) 2001 Ximian, Inc (http://www.ximian.com)
13 // (1) Figure out why error productions dont work. `type-declaration' is a
14 // great spot to put an `error' because you can reproduce it with this input:
17 // Possible optimization:
18 // Run memory profiler with parsing only, and consider dropping
19 // arraylists where not needed. Some pieces can use linked lists.
27 using System.Collections;
32 public class CSharpParser {
33 NamespaceEntry current_namespace;
34 TypeContainer current_container;
35 TypeContainer current_class;
37 IIteratorContainer iterator_container;
40 /// Current block is used to add statements as we find
47 /// If true, creates a toplevel block in the block production
48 /// This is flagged by the delegate creation
50 bool create_toplevel_block;
52 Delegate current_delegate;
55 /// This is used by the unary_expression code to resolve
56 /// a name against a parameter.
58 Parameters current_local_parameters;
61 /// Using during property parsing to describe the implicit
62 /// value parameter that is passed to the "set" and "get"accesor
63 /// methods (properties and indexers).
65 Expression implicit_value_parameter_type;
66 Parameters indexer_parameters;
69 /// Used to determine if we are parsing the get/set pair
70 /// of an indexer or a property
75 /// An out-of-band stack.
84 public bool yacc_verbose_flag;
86 // Name of the file we are parsing
95 /// Current attribute target
96 string current_attr_target;
98 /// assembly and module attribute definition is enabled
99 bool global_attrs_enabled = true;
103 %token NONE /* This token is never returned by our lexer */
104 %token ERROR // This is used not by the parser, but by the tokenizer.
108 *These are the C# keywords
195 /* C# keywords which are not really keywords */
201 /* C# single character operators/punctuation. */
202 %token OPEN_BRACE "{"
203 %token CLOSE_BRACE "}"
204 %token OPEN_BRACKET "["
205 %token CLOSE_BRACKET "]"
206 %token OPEN_PARENS "("
207 %token CLOSE_PARENS ")"
219 %token OP_GENERICS_LT "<"
221 %token OP_GENERICS_GT ">"
222 %token BITWISE_AND "&"
223 %token BITWISE_OR "|"
230 /* C# multi-character operators. */
233 %token OP_SHIFT_LEFT "<<"
234 %token OP_SHIFT_RIGHT ">>"
241 %token OP_MULT_ASSIGN "*="
242 %token OP_DIV_ASSIGN "/="
243 %token OP_MOD_ASSIGN "%="
244 %token OP_ADD_ASSIGN "+="
245 %token OP_SUB_ASSIGN "-="
246 %token OP_SHIFT_LEFT_ASSIGN "<<="
247 %token OP_SHIFT_RIGHT_ASSIGN ">>="
248 %token OP_AND_ASSIGN "&="
249 %token OP_XOR_ASSIGN "^="
250 %token OP_OR_ASSIGN "|="
254 %token LITERAL_INTEGER "int literal"
255 %token LITERAL_FLOAT "float literal"
256 %token LITERAL_DOUBLE "double literal"
257 %token LITERAL_DECIMAL "decimal literal"
258 %token LITERAL_CHARACTER "character literal"
259 %token LITERAL_STRING "string literal"
262 %token CLOSE_PARENS_CAST
263 %token CLOSE_PARENS_NO_CAST
264 %token CLOSE_PARENS_OPEN_PARENS
265 %token CLOSE_PARENS_MINUS
266 %token DEFAULT_OPEN_PARENS
267 %token GENERIC_DIMENSION
269 /* Add precedence rules to solve dangling else s/r conflict */
278 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
280 %left STAR DIV PERCENT
281 %right BANG CARRET UMINUS
282 %nonassoc OP_INC OP_DEC
284 %left OPEN_BRACKET OPEN_BRACE
288 %start compilation_unit
292 : outer_declarations opt_EOF
293 | outer_declarations global_attributes opt_EOF
294 | global_attributes opt_EOF
295 | opt_EOF /* allow empty files */
305 | outer_declarations outer_declaration
310 | namespace_member_declaration
315 | using_directives using_directive
319 : using_alias_directive
320 | using_namespace_directive
323 using_alias_directive
324 : USING IDENTIFIER ASSIGN
325 namespace_or_type_name SEMICOLON
327 current_namespace.UsingAlias ((string) $2, (MemberName) $4, lexer.Location);
330 CheckIdentifierToken (yyToken);
334 using_namespace_directive
335 : USING namespace_name SEMICOLON
337 current_namespace.Using ((string) $2, lexer.Location);
342 // Strictly speaking, namespaces don't have attributes but
343 // we parse global attributes along with namespace declarations and then
346 namespace_declaration
347 : opt_attributes NAMESPACE namespace_name
350 Report.Error(1518, Lexer.Location, "Attributes cannot be applied to namespaces."
351 + " Expected class, delegate, enum, interface, or struct");
354 if (current_namespace.Parent != null && $3 is MemberAccess) {
355 // Cannot use qualified namespace names in nested namespace declarations
356 Report.Error (134, lexer.Location, "Cannot use qualified namespace names in nested namespace declarations");
359 current_namespace = new NamespaceEntry (
360 current_namespace, file, (string) $3, lexer.Location);
362 namespace_body opt_semicolon
364 current_namespace = current_namespace.Parent;
379 : namespace_or_type_name {
380 MemberName name = (MemberName) $1;
382 if (name.TypeArguments != null)
383 syntax_error (lexer.Location, "namespace name expected");
385 $$ = name.GetName ();
392 opt_namespace_member_declarations
403 opt_namespace_member_declarations
405 | namespace_member_declarations
408 namespace_member_declarations
409 : namespace_member_declaration
410 | namespace_member_declarations namespace_member_declaration
413 namespace_member_declaration
420 Class c = (Class) $1;
421 mod_flags = c.ModFlags;
423 } else if ($1 is Struct){
424 Struct s = (Struct) $1;
425 mod_flags = s.ModFlags;
430 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
432 1527, lexer.Location,
433 "Namespace elements cant be explicitly " +
434 "declared private or protected in `" + name + "'");
436 current_namespace.DeclarationFound = true;
438 | namespace_declaration {
439 current_namespace.DeclarationFound = true;
442 | field_declaration {
443 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
445 | method_declaration {
446 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
453 | interface_declaration
455 | delegate_declaration
457 // Enable this when we have handled all errors, because this acts as a generic fallback
460 // Console.WriteLine ("Token=" + yyToken);
461 // Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
473 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
481 global_attrs_enabled = false;
486 global_attrs_enabled = false;
495 ArrayList sect = (ArrayList) $1;
497 if (global_attrs_enabled) {
498 if (current_attr_target == "module") {
499 CodeGen.Module.AddAttributes (sect);
501 } else if (current_attr_target == "assembly") {
502 CodeGen.Assembly.AddAttributes (sect);
505 $$ = new Attributes (sect);
508 $$ = new Attributes (sect);
510 current_attr_target = null;
512 | attribute_sections attribute_section
514 Attributes attrs = $1 as Attributes;
515 ArrayList sect = (ArrayList) $2;
517 if (global_attrs_enabled) {
518 if (current_attr_target == "module") {
519 CodeGen.Module.AddAttributes (sect);
521 } else if (current_attr_target == "assembly") {
522 CodeGen.Assembly.AddAttributes (sect);
526 attrs = new Attributes (sect);
528 attrs.AddAttributes (sect);
532 attrs = new Attributes (sect);
534 attrs.AddAttributes (sect);
537 current_attr_target = null;
542 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
546 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
552 attribute_target_specifier
553 : attribute_target COLON
555 current_attr_target = (string)$1;
563 CheckAttributeTarget ((string) $1);
566 | EVENT { $$ = "event"; }
567 | RETURN { $$ = "return"; }
573 ArrayList attrs = new ArrayList (4);
579 | attribute_list COMMA attribute
581 ArrayList attrs = (ArrayList) $1;
593 opt_attribute_arguments
595 MemberName mname = (MemberName) $1;
596 if (mname.IsGeneric) {
597 Report.Error (404, lexer.Location,
598 "'<' unexpected: attributes cannot be generic");
601 string name = mname.GetName ();
602 if (current_attr_target == "assembly" || current_attr_target == "module")
603 $$ = new GlobalAttribute (current_container, current_attr_target,
604 name, (ArrayList) $3, (Location) $2);
606 $$ = new Attribute (current_attr_target, name, (ArrayList) $3,
612 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
615 opt_attribute_arguments
616 : /* empty */ { $$ = null; }
617 | OPEN_PARENS attribute_arguments CLOSE_PARENS
625 : opt_positional_argument_list
630 ArrayList args = new ArrayList (4);
636 | positional_argument_list COMMA named_argument_list
638 ArrayList args = new ArrayList (4);
644 | named_argument_list
646 ArrayList args = new ArrayList (4);
655 opt_positional_argument_list
656 : /* empty */ { $$ = null; }
657 | positional_argument_list
660 positional_argument_list
663 ArrayList args = new ArrayList (4);
664 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
668 | positional_argument_list COMMA expression
670 ArrayList args = (ArrayList) $1;
671 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
680 ArrayList args = new ArrayList (4);
685 | named_argument_list COMMA named_argument
687 ArrayList args = (ArrayList) $1;
695 : IDENTIFIER ASSIGN expression
697 $$ = new DictionaryEntry (
699 new Argument ((Expression) $3, Argument.AType.Expression));
705 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
708 opt_class_member_declarations
710 | class_member_declarations
713 class_member_declarations
714 : class_member_declaration
715 | class_member_declarations
716 class_member_declaration
719 class_member_declaration
720 : constant_declaration // done
721 | field_declaration // done
722 | method_declaration // done
723 | property_declaration // done
724 | event_declaration // done
725 | indexer_declaration // done
726 | operator_declaration // done
727 | constructor_declaration // done
728 | destructor_declaration // done
738 MemberName name = MakeName ((MemberName) $5);
739 bool partial = (bool) $3;
742 ClassPart part = PartialContainer.CreatePart (
743 current_namespace, current_container, name, (int) $2,
744 (Attributes) $1, Kind.Struct, lexer.Location);
746 current_container = part.PartialContainer;
747 current_class = part;
749 current_class = new Struct (
750 current_namespace, current_container, name, (int) $2,
751 (Attributes) $1, lexer.Location);
753 current_container = current_class;
754 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
757 lexer.ConstraintsParsing = true;
760 opt_type_parameter_constraints_clauses
762 lexer.ConstraintsParsing = false;
765 current_class.Bases = (ArrayList) $7;
767 CheckDef (current_class.SetParameterInfo ((ArrayList) $8), current_class.Name,
768 current_class.Location);
770 current_class.Register ();
777 current_container = current_container.Parent;
778 current_class = current_container;
780 | opt_attributes opt_modifiers opt_partial STRUCT error {
781 CheckIdentifierToken (yyToken);
786 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
789 opt_struct_member_declarations
791 | struct_member_declarations
794 struct_member_declarations
795 : struct_member_declaration
796 | struct_member_declarations struct_member_declaration
799 struct_member_declaration
800 : constant_declaration
803 | property_declaration
805 | indexer_declaration
806 | operator_declaration
807 | constructor_declaration
811 * This is only included so we can flag error 575:
812 * destructors only allowed on class types
814 | destructor_declaration
825 foreach (VariableDeclaration constant in (ArrayList) $5){
826 Location l = constant.Location;
828 Const c = new Const (
829 current_class, (Expression) $4, (string) constant.identifier,
830 (Expression) constant.expression_or_array_initializer, (int) $2,
833 CheckDef (current_container.AddConstant (c), c.Name, l);
839 : constant_declarator
841 ArrayList constants = new ArrayList (4);
846 | constant_declarators COMMA constant_declarator
849 ArrayList constants = (ArrayList) $1;
856 : IDENTIFIER ASSIGN constant_expression
858 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
862 // A const field requires a value to be provided
863 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
875 Expression type = (Expression) $3;
878 foreach (VariableDeclaration var in (ArrayList) $4){
879 Location l = var.Location;
881 Field field = new Field (current_class, type, mod, var.identifier,
882 var.expression_or_array_initializer,
885 CheckDef (current_container.AddField (field), field.Name, l);
893 Report.Error (670, lexer.Location, "void type is not allowed for fields");
898 : variable_declarator
900 ArrayList decl = new ArrayList (4);
904 | variable_declarators COMMA variable_declarator
906 ArrayList decls = (ArrayList) $1;
913 : IDENTIFIER ASSIGN variable_initializer
915 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
919 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
932 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
934 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
940 iterator_container = (IIteratorContainer) $1;
944 Method method = (Method) $1;
945 Block b = (Block) $3;
946 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
949 if ((method.ModFlags & extern_abstract) == 0){
951 501, lexer.Location, current_container.MakeName (method.Name) +
952 "must declare a body because it is not marked abstract or extern");
955 if ((method.ModFlags & Modifiers.EXTERN) != 0){
957 179, lexer.Location, current_container.MakeName (method.Name) +
958 " is declared extern, but has a body");
962 method.Block = (Block) $3;
963 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
965 current_local_parameters = null;
966 iterator_container = null;
980 1585, lexer.Location, "Member modifier `" +
981 Modifiers.Name (i) + "' must precede member type and name");
992 type namespace_or_type_name
993 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
995 lexer.ConstraintsParsing = true;
997 opt_type_parameter_constraints_clauses
999 lexer.ConstraintsParsing = false;
1001 MemberName name = (MemberName) $4;
1003 if ($9 != null && name.TypeArguments == null)
1004 Report.Error (80, lexer.Location,
1005 "Contraints are not allowed on non-generic declarations");
1009 GenericMethod generic = null;
1010 if (name.TypeArguments != null) {
1011 generic = new GenericMethod (current_namespace, current_class,
1012 name, lexer.Location);
1014 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
1017 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1018 name, (Parameters) $6, (Attributes) $1, lexer.Location);
1020 current_local_parameters = (Parameters) $6;
1026 VOID namespace_or_type_name
1027 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1029 lexer.ConstraintsParsing = true;
1031 opt_type_parameter_constraints_clauses
1033 lexer.ConstraintsParsing = false;
1035 MemberName name = (MemberName) $4;
1037 if ($9 != null && name.TypeArguments == null)
1038 Report.Error (80, lexer.Location,
1039 "Contraints are not allowed on non-generic declarations");
1042 GenericMethod generic = null;
1043 if (name.TypeArguments != null) {
1044 generic = new GenericMethod (current_namespace, current_class,
1045 name, lexer.Location);
1048 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
1051 method = new Method (current_class, generic, TypeManager.system_void_expr,
1052 (int) $2, false, name, (Parameters) $6, (Attributes) $1,
1055 current_local_parameters = (Parameters) $6;
1062 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1064 Report.Error (1585, lexer.Location,
1065 String.Format ("Modifier {0} should appear before type",
1066 Modifiers.Name ((int) $4)));
1067 MemberName name = (MemberName) $4;
1069 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1070 0, false, name, (Parameters) $6, (Attributes) $1,
1073 current_local_parameters = (Parameters) $6;
1080 | SEMICOLON { $$ = null; }
1083 opt_formal_parameter_list
1084 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1085 | formal_parameter_list
1088 formal_parameter_list
1091 ArrayList pars_list = (ArrayList) $1;
1093 Parameter [] pars = new Parameter [pars_list.Count];
1094 pars_list.CopyTo (pars);
1096 $$ = new Parameters (pars, null, lexer.Location);
1098 | fixed_parameters COMMA parameter_array
1100 ArrayList pars_list = (ArrayList) $1;
1102 Parameter [] pars = new Parameter [pars_list.Count];
1103 pars_list.CopyTo (pars);
1105 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
1107 | fixed_parameters COMMA ARGLIST
1109 ArrayList pars_list = (ArrayList) $1;
1111 Parameter [] pars = new Parameter [pars_list.Count];
1112 pars_list.CopyTo (pars);
1114 $$ = new Parameters (pars, true, lexer.Location);
1118 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1122 $$ = new Parameters (null, true, lexer.Location);
1129 ArrayList pars = new ArrayList (4);
1134 | fixed_parameters COMMA fixed_parameter
1136 ArrayList pars = (ArrayList) $1;
1145 opt_parameter_modifier
1149 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1152 opt_parameter_modifier
1155 CheckIdentifierToken (yyToken);
1160 opt_parameter_modifier
1161 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1162 | parameter_modifier
1166 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1167 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1171 : opt_attributes PARAMS type IDENTIFIER
1173 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1174 note ("type must be a single-dimension array type");
1176 | opt_attributes PARAMS type error {
1177 CheckIdentifierToken (yyToken);
1182 property_declaration
1185 type namespace_or_type_name
1188 implicit_value_parameter_type = (Expression) $3;
1190 lexer.PropertyParsing = true;
1192 $$ = lexer.Location;
1194 iterator_container = SimpleIteratorContainer.GetSimple ();
1196 accessor_declarations
1198 lexer.PropertyParsing = false;
1203 Pair pair = (Pair) $7;
1204 Accessor get_block = (Accessor) pair.First;
1205 Accessor set_block = (Accessor) pair.Second;
1207 MemberName name = (MemberName) $4;
1208 if (name.TypeArguments != null)
1209 syntax_error (lexer.Location, "a property can't have type arguments");
1211 Location loc = (Location) $6;
1212 prop = new Property (current_container, (Expression) $3, (int) $2, false,
1213 name, (Attributes) $1, get_block, set_block, loc);
1214 if (SimpleIteratorContainer.Simple.Yields)
1217 CheckDef (current_container.AddProperty (prop), prop.Name, loc);
1218 implicit_value_parameter_type = null;
1219 iterator_container = null;
1223 accessor_declarations
1224 : get_accessor_declaration opt_set_accessor_declaration
1226 $$ = new Pair ($1, $2);
1228 | set_accessor_declaration opt_get_accessor_declaration
1230 $$ = new Pair ($2, $1);
1234 opt_get_accessor_declaration
1235 : /* empty */ { $$ = null; }
1236 | get_accessor_declaration
1239 opt_set_accessor_declaration
1240 : /* empty */ { $$ = null; }
1241 | set_accessor_declaration
1244 get_accessor_declaration
1245 : opt_attributes GET
1247 // If this is not the case, then current_local_parameters has already
1248 // been set in indexer_declaration
1249 if (parsing_indexer == false)
1250 current_local_parameters = null;
1252 current_local_parameters = indexer_parameters;
1253 lexer.PropertyParsing = false;
1257 $$ = new Accessor ((Block) $4, (Attributes) $1);
1258 current_local_parameters = null;
1259 lexer.PropertyParsing = true;
1263 set_accessor_declaration
1264 : opt_attributes SET
1267 Parameter implicit_value_parameter = new Parameter (
1268 implicit_value_parameter_type, "value",
1269 Parameter.Modifier.NONE, null);
1271 if (parsing_indexer == false) {
1272 args = new Parameter [1];
1273 args [0] = implicit_value_parameter;
1274 current_local_parameters = new Parameters (args, null, lexer.Location);
1276 Parameter [] fpars = indexer_parameters.FixedParameters;
1279 int count = fpars.Length;
1281 args = new Parameter [count + 1];
1282 fpars.CopyTo (args, 0);
1283 args [count] = implicit_value_parameter;
1286 current_local_parameters = new Parameters (
1287 args, indexer_parameters.ArrayParameter, lexer.Location);
1290 lexer.PropertyParsing = false;
1294 $$ = new Accessor ((Block) $4, (Attributes) $1);
1295 current_local_parameters = null;
1296 lexer.PropertyParsing = true;
1302 | SEMICOLON { $$ = null; }
1305 interface_declaration
1309 INTERFACE member_name
1311 MemberName name = MakeName ((MemberName) $5);
1312 bool partial = (bool) $3;
1315 ClassPart part = PartialContainer.CreatePart (
1316 current_namespace, current_container, name, (int) $2,
1317 (Attributes) $1, Kind.Interface, lexer.Location);
1319 current_container = part.PartialContainer;
1320 current_class = part;
1322 current_class = new Interface (
1323 current_namespace, current_container, name, (int) $2,
1324 (Attributes) $1, lexer.Location);
1326 current_container = current_class;
1327 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
1330 lexer.ConstraintsParsing = true;
1333 opt_type_parameter_constraints_clauses
1335 lexer.ConstraintsParsing = false;
1338 current_class.Bases = (ArrayList) $7;
1340 CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
1341 current_class.Name, current_class.Location);
1343 current_class.Register ();
1345 interface_body opt_semicolon
1349 current_container = current_container.Parent;
1350 current_class = current_container;
1352 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1353 CheckIdentifierToken (yyToken);
1359 opt_interface_member_declarations
1363 opt_interface_member_declarations
1365 | interface_member_declarations
1368 interface_member_declarations
1369 : interface_member_declaration
1370 | interface_member_declarations interface_member_declaration
1373 interface_member_declaration
1374 : interface_method_declaration
1376 Method m = (Method) $1;
1378 CheckDef (current_container.AddMethod (m), m.Name, m.Location);
1380 | interface_property_declaration
1382 Property p = (Property) $1;
1384 CheckDef (current_container.AddProperty (p), p.Name, p.Location);
1386 | interface_event_declaration
1389 Event e = (Event) $1;
1390 CheckDef (current_container.AddEvent (e), e.Name, lexer.Location);
1393 | interface_indexer_declaration
1395 Indexer i = (Indexer) $1;
1397 current_container.AddIndexer (i);
1405 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1410 interface_method_declaration
1411 : opt_attributes opt_new type namespace_or_type_name
1412 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1414 lexer.ConstraintsParsing = true;
1416 opt_type_parameter_constraints_clauses
1419 lexer.ConstraintsParsing = false;
1421 MemberName name = (MemberName) $4;
1423 if ($9 != null && name.TypeArguments == null)
1424 Report.Error (80, lexer.Location,
1425 "Contraints are not allowed on non-generic declarations");
1427 GenericMethod generic = null;
1428 if (name.TypeArguments != null) {
1429 generic = new GenericMethod (current_namespace, current_class,
1430 name, lexer.Location);
1432 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
1435 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1436 (Parameters) $6, (Attributes) $1, lexer.Location);
1438 | opt_attributes opt_new VOID namespace_or_type_name
1439 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1441 lexer.ConstraintsParsing = true;
1443 opt_type_parameter_constraints_clauses
1446 lexer.ConstraintsParsing = false;
1448 MemberName name = (MemberName) $4;
1450 if ($9 != null && name.TypeArguments == null)
1451 Report.Error (80, lexer.Location,
1452 "Contraints are not allowed on non-generic declarations");
1454 GenericMethod generic = null;
1455 if (name.TypeArguments != null) {
1456 generic = new GenericMethod (current_namespace, current_class,
1457 name, lexer.Location);
1459 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
1462 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1463 true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
1467 interface_property_declaration
1472 { lexer.PropertyParsing = true; }
1474 { lexer.PropertyParsing = false; }
1477 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1479 $$ = new Property (current_class, (Expression) $3, (int) $2, true,
1480 new MemberName ((string) $4), (Attributes) $1,
1481 pinfo.Get, pinfo.Set, lexer.Location);
1486 CheckIdentifierToken (yyToken);
1492 : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null); }
1493 | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1); }
1494 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1495 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3); }
1496 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1497 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1); }
1500 interface_event_declaration
1501 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1503 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1504 new MemberName ((string) $5), null,
1505 (Attributes) $1, lexer.Location);
1507 | opt_attributes opt_new EVENT type error {
1508 CheckIdentifierToken (yyToken);
1511 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1512 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1515 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1516 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1521 interface_indexer_declaration
1522 : opt_attributes opt_new type THIS
1523 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1525 { lexer.PropertyParsing = true; }
1527 { lexer.PropertyParsing = false; }
1530 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1532 $$ = new Indexer (current_class, (Expression) $3, (int) $2, true,
1533 MemberName.Null, (Parameters) $6, (Attributes) $1,
1534 info.Get, info.Set, lexer.Location);
1538 operator_declaration
1539 : opt_attributes opt_modifiers operator_declarator
1541 iterator_container = SimpleIteratorContainer.GetSimple ();
1545 OperatorDeclaration decl = (OperatorDeclaration) $3;
1547 Operator op = new Operator (
1548 current_class, decl.optype, decl.ret_type, (int) $2, decl.arg1type,
1549 decl.arg1name, decl.arg2type, decl.arg2name, (Block) $5,
1550 (Attributes) $1, decl.location);
1552 if (SimpleIteratorContainer.Simple.Yields)
1555 // Note again, checking is done in semantic analysis
1556 current_container.AddOperator (op);
1558 current_local_parameters = null;
1559 iterator_container = null;
1565 | SEMICOLON { $$ = null; }
1568 : type OPERATOR overloadable_operator
1569 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1571 Operator.OpType op = (Operator.OpType) $3;
1572 CheckUnaryOperator (op);
1574 if (op == Operator.OpType.Addition)
1575 op = Operator.OpType.UnaryPlus;
1577 if (op == Operator.OpType.Subtraction)
1578 op = Operator.OpType.UnaryNegation;
1580 Parameter [] pars = new Parameter [1];
1582 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1584 current_local_parameters = new Parameters (pars, null, lexer.Location);
1586 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1587 null, null, lexer.Location);
1589 | type OPERATOR overloadable_operator
1591 type IDENTIFIER COMMA
1595 CheckBinaryOperator ((Operator.OpType) $3);
1597 Parameter [] pars = new Parameter [2];
1599 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1600 pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1602 current_local_parameters = new Parameters (pars, null, lexer.Location);
1604 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1605 (Expression) $5, (string) $6,
1606 (Expression) $8, (string) $9, lexer.Location);
1608 | conversion_operator_declarator
1611 overloadable_operator
1613 : BANG { $$ = Operator.OpType.LogicalNot; }
1614 | TILDE { $$ = Operator.OpType.OnesComplement; }
1615 | OP_INC { $$ = Operator.OpType.Increment; }
1616 | OP_DEC { $$ = Operator.OpType.Decrement; }
1617 | TRUE { $$ = Operator.OpType.True; }
1618 | FALSE { $$ = Operator.OpType.False; }
1619 // Unary and binary:
1620 | PLUS { $$ = Operator.OpType.Addition; }
1621 | MINUS { $$ = Operator.OpType.Subtraction; }
1623 | STAR { $$ = Operator.OpType.Multiply; }
1624 | DIV { $$ = Operator.OpType.Division; }
1625 | PERCENT { $$ = Operator.OpType.Modulus; }
1626 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1627 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1628 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1629 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1630 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1631 | OP_EQ { $$ = Operator.OpType.Equality; }
1632 | OP_NE { $$ = Operator.OpType.Inequality; }
1633 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1634 | OP_LT { $$ = Operator.OpType.LessThan; }
1635 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1636 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1639 conversion_operator_declarator
1640 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1642 Parameter [] pars = new Parameter [1];
1644 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1646 current_local_parameters = new Parameters (pars, null, lexer.Location);
1648 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1649 null, null, lexer.Location);
1651 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1653 Parameter [] pars = new Parameter [1];
1655 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1657 current_local_parameters = new Parameters (pars, null, lexer.Location);
1659 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1660 null, null, lexer.Location);
1664 syntax_error (lexer.Location, "'operator' expected");
1668 syntax_error (lexer.Location, "'operator' expected");
1672 constructor_declaration
1675 constructor_declarator
1678 Constructor c = (Constructor) $3;
1679 c.Block = (Block) $4;
1680 c.OptAttributes = (Attributes) $1;
1681 c.ModFlags = (int) $2;
1683 if (c.Name == current_container.Basename){
1684 if ((c.ModFlags & Modifiers.STATIC) != 0){
1685 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1687 515, c.Location, String.Format (
1688 "`{0}.{1}': static constructor can not have access modifiers",
1689 c.Name, current_container.Name));
1692 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1694 if (c.Initializer != null){
1697 "Static constructors can not have an explicit this or base " +
1698 "constructor invocations");
1701 if (!c.Parameters.Empty){
1703 132, c.Location, "Static constructors should not have parameters");
1706 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1709 // We let another layer check the validity of the constructor.
1710 Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1713 CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
1715 current_local_parameters = null;
1719 constructor_declarator
1721 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1723 oob_stack.Push (lexer.Location);
1725 current_local_parameters = (Parameters) $3;
1727 opt_constructor_initializer
1729 Location l = (Location) oob_stack.Pop ();
1730 $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $3,
1731 (ConstructorInitializer) $6, l);
1737 | SEMICOLON { $$ = null; }
1740 opt_constructor_initializer
1741 : /* empty */ { $$ = null; }
1742 | constructor_initializer
1745 constructor_initializer
1746 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1748 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1750 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1752 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1755 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1761 : /* EMPTY */ { $$ = 0; }
1762 | UNSAFE { $$ = Modifiers.UNSAFE; }
1763 | EXTERN { $$ = Modifiers.EXTERN; }
1766 destructor_declaration
1767 : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1769 if ((string) $4 != current_container.Basename){
1770 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1771 } else if (!(current_container is Class)){
1772 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1774 Location l = lexer.Location;
1777 if (!RootContext.StdLib && current_container.Name == "System.Object")
1778 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1780 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1782 if ((m & Modifiers.UNSAFE) != 0){
1783 if (!RootContext.Unsafe){
1784 Report.Error (227, l,
1785 "Unsafe code requires the -unsafe command " +
1786 "line option to be specified");
1790 Method d = new Destructor (
1791 current_class, TypeManager.system_void_expr, m, "Finalize",
1792 new Parameters (null, null, l), (Attributes) $1, l);
1794 d.Block = (Block) $7;
1795 CheckDef (current_container.AddMethod (d), d.Name, d.Location);
1798 | opt_attributes opt_modifiers EVENT type member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
1799 string mn = (string) $5;
1801 if (mn.IndexOf ('.') != -1)
1802 Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
1804 Report.Error (71, lexer.Location, "Event declaration should use property syntax");
1811 EVENT type variable_declarators SEMICOLON
1813 foreach (VariableDeclaration var in (ArrayList) $5) {
1815 MemberName name = new MemberName (var.identifier);
1817 Event e = new EventField (current_class, (Expression) $4, (int) $2,
1819 var.expression_or_array_initializer,
1820 (Attributes) $1, lexer.Location);
1822 CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1828 EVENT type namespace_or_type_name
1831 implicit_value_parameter_type = (Expression) $4;
1832 lexer.EventParsing = true;
1833 oob_stack.Push (lexer.Location);
1835 event_accessor_declarations
1837 lexer.EventParsing = false;
1841 Location loc = (Location) oob_stack.Pop ();
1844 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1847 Pair pair = (Pair) $8;
1849 MemberName name = (MemberName) $5;
1850 if (name.TypeArguments != null)
1851 syntax_error (lexer.Location, "an event can't have type arguments");
1853 Event e = new EventProperty (current_class, (Expression) $4, (int) $2,
1854 false, name, null, (Attributes) $1,
1855 (Accessor) pair.First, (Accessor) pair.Second,
1858 CheckDef (current_container.AddEvent (e), e.Name, loc);
1859 implicit_value_parameter_type = null;
1864 event_accessor_declarations
1865 : add_accessor_declaration remove_accessor_declaration
1867 $$ = new Pair ($1, $2);
1869 | remove_accessor_declaration add_accessor_declaration
1871 $$ = new Pair ($2, $1);
1873 | add_accessor_declaration { $$ = null; }
1874 | remove_accessor_declaration { $$ = null; }
1877 add_accessor_declaration
1878 : opt_attributes ADD
1880 Parameter [] args = new Parameter [1];
1881 Parameter implicit_value_parameter = new Parameter (
1882 implicit_value_parameter_type, "value",
1883 Parameter.Modifier.NONE, null);
1885 args [0] = implicit_value_parameter;
1887 current_local_parameters = new Parameters (args, null, lexer.Location);
1888 lexer.EventParsing = false;
1892 $$ = new Accessor ((Block) $4, (Attributes) $1);
1893 lexer.EventParsing = true;
1895 | opt_attributes ADD error {
1896 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1901 remove_accessor_declaration
1902 : opt_attributes REMOVE
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);
1917 lexer.EventParsing = true;
1919 | opt_attributes REMOVE error {
1920 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1926 : opt_attributes opt_modifiers indexer_declarator
1929 IndexerDeclaration decl = (IndexerDeclaration) $3;
1931 implicit_value_parameter_type = decl.type;
1933 lexer.PropertyParsing = true;
1934 parsing_indexer = true;
1936 indexer_parameters = decl.param_list;
1937 oob_stack.Push (lexer.Location);
1939 accessor_declarations
1941 lexer.PropertyParsing = false;
1942 parsing_indexer = false;
1946 // The signature is computed from the signature of the indexer. Look
1947 // at section 3.6 on the spec
1948 Location loc = (Location) oob_stack.Pop ();
1950 IndexerDeclaration decl = (IndexerDeclaration) $3;
1951 Pair pair = (Pair) $6;
1952 Accessor get_block = (Accessor) pair.First;
1953 Accessor set_block = (Accessor) pair.Second;
1956 if (decl.interface_type != null)
1957 name = new MemberName (decl.interface_type, "", null);
1959 name = MemberName.Null;
1961 indexer = new Indexer (current_class, decl.type, (int) $2, false,
1962 name, decl.param_list, (Attributes) $1,
1963 get_block, set_block, loc);
1965 // Note that there is no equivalent of CheckDef for this case
1966 // We shall handle this in semantic analysis
1968 current_container.AddIndexer (indexer);
1970 current_local_parameters = null;
1971 implicit_value_parameter_type = null;
1972 indexer_parameters = null;
1977 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1979 Parameters pars = (Parameters) $4;
1980 if (pars.HasArglist) {
1981 // "__arglist is not valid in this context"
1982 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
1983 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
1984 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1987 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1989 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1991 Parameters pars = (Parameters) $6;
1993 if (pars.HasArglist) {
1994 // "__arglist is not valid in this context"
1995 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
1996 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
1997 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1999 MemberName name = (MemberName) $2;
2000 if (name.TypeArguments != null)
2001 syntax_error (lexer.Location, "an indexer can't have type arguments");
2003 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
2015 Location enum_location = lexer.Location;
2017 MemberName full_name = MakeName (new MemberName ((string) $4));
2018 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
2019 full_name, (Attributes) $1, enum_location);
2021 foreach (VariableDeclaration ev in (ArrayList) $6) {
2022 Location loc = (Location) ev.Location;
2024 CheckDef (e.AddEnumMember (ev.identifier,
2025 (Expression) ev.expression_or_array_initializer,
2026 loc, ev.OptAttributes),
2027 ev.identifier, loc);
2030 string name = full_name.GetName (false);
2031 CheckDef (current_container.AddEnum (e), name, enum_location);
2032 RootContext.Tree.RecordDecl (name, e);
2038 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2039 | COLON type { $$ = $2; }
2043 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
2049 opt_enum_member_declarations
2050 : /* empty */ { $$ = new ArrayList (4); }
2051 | enum_member_declarations opt_comma { $$ = $1; }
2054 enum_member_declarations
2055 : enum_member_declaration
2057 ArrayList l = new ArrayList (4);
2062 | enum_member_declarations COMMA enum_member_declaration
2064 ArrayList l = (ArrayList) $1;
2072 enum_member_declaration
2073 : opt_attributes IDENTIFIER
2075 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
2077 | opt_attributes IDENTIFIER
2079 $$ = lexer.Location;
2083 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
2087 delegate_declaration
2090 DELEGATE type member_name
2091 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2093 Location l = lexer.Location;
2094 Delegate del = new Delegate (
2095 current_namespace, current_container, (Expression) $4, (int) $2,
2096 MakeName ((MemberName) $5), (Parameters) $7, (Attributes) $1, l);
2098 CheckDef (current_container.AddDelegate (del), del.Name, l);
2100 current_delegate = del;
2102 lexer.ConstraintsParsing = true;
2104 opt_type_parameter_constraints_clauses
2106 lexer.ConstraintsParsing = false;
2110 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
2112 current_delegate = null;
2116 DELEGATE VOID member_name
2117 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2119 Location l = lexer.Location;
2120 Delegate del = new Delegate (
2121 current_namespace, current_container,
2122 TypeManager.system_void_expr, (int) $2, MakeName ((MemberName) $5),
2123 (Parameters) $7, (Attributes) $1, l);
2125 CheckDef (current_container.AddDelegate (del), del.Name, l);
2127 current_delegate = del;
2129 lexer.ConstraintsParsing = true;
2131 opt_type_parameter_constraints_clauses
2133 lexer.ConstraintsParsing = false;
2137 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
2139 current_delegate = null;
2143 namespace_or_type_name
2145 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2146 $$ = new MemberName ((MemberName) $1, (string) $3, (TypeArguments) $4);
2151 : IDENTIFIER opt_type_argument_list {
2152 $$ = new MemberName ((string) $1, (TypeArguments) $2);
2156 opt_type_argument_list
2157 : /* empty */ { $$ = null; }
2158 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2164 $$ = new TypeArguments ((int) $1, lexer.Location);
2170 TypeArguments type_args = new TypeArguments (lexer.Location);
2171 type_args.Add ((Expression) $1);
2174 | type_arguments COMMA type {
2175 TypeArguments type_args = (TypeArguments) $1;
2176 type_args.Add ((Expression) $3);
2182 * Before you think of adding a return_type, notice that we have been
2183 * using two rules in the places where it matters (one rule using type
2184 * and another identical one that uses VOID as the return type). This
2185 * gets rid of a shift/reduce couple
2188 : namespace_or_type_name
2190 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2201 // Note that here only unmanaged types are allowed but we
2202 // can't perform checks during this phase - we do it during
2203 // semantic analysis.
2205 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2209 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2215 | non_expression_type rank_specifier
2217 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2219 | non_expression_type STAR
2221 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2223 | expression rank_specifiers
2225 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2229 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2233 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2234 // through this different path
2236 | multiplicative_expression STAR
2238 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2245 ArrayList types = new ArrayList (4);
2250 | type_list COMMA type
2252 ArrayList types = (ArrayList) $1;
2260 * replaces all the productions for isolating the various
2261 * simple types, but we need this to reuse it easily in local_variable_type
2264 : OBJECT { $$ = TypeManager.system_object_expr; }
2265 | STRING { $$ = TypeManager.system_string_expr; }
2266 | BOOL { $$ = TypeManager.system_boolean_expr; }
2267 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2268 | FLOAT { $$ = TypeManager.system_single_expr; }
2269 | DOUBLE { $$ = TypeManager.system_double_expr; }
2274 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2275 | BYTE { $$ = TypeManager.system_byte_expr; }
2276 | SHORT { $$ = TypeManager.system_int16_expr; }
2277 | USHORT { $$ = TypeManager.system_uint16_expr; }
2278 | INT { $$ = TypeManager.system_int32_expr; }
2279 | UINT { $$ = TypeManager.system_uint32_expr; }
2280 | LONG { $$ = TypeManager.system_int64_expr; }
2281 | ULONG { $$ = TypeManager.system_uint64_expr; }
2282 | CHAR { $$ = TypeManager.system_char_expr; }
2283 | VOID { $$ = TypeManager.system_void_expr; }
2287 : type rank_specifiers
2289 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2294 // Expressions, section 7.5
2304 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2306 | parenthesized_expression
2307 | default_value_expression
2309 | invocation_expression
2313 | post_increment_expression
2314 | post_decrement_expression
2318 | checked_expression
2319 | unchecked_expression
2320 | pointer_member_access
2321 | anonymous_method_expression
2328 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2329 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2330 | NULL { $$ = NullLiteral.Null; }
2334 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2335 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2336 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2341 object v = lexer.Value;
2347 $$ = IntLiteral.Zero;
2349 $$ = IntLiteral.One;
2351 $$ = new IntLiteral (i);
2352 } else if (v is uint)
2353 $$ = new UIntLiteral ((UInt32) v);
2355 $$ = new LongLiteral ((Int64) v);
2356 else if (v is ulong)
2357 $$ = new ULongLiteral ((UInt64) v);
2359 Console.WriteLine ("OOPS. Unexpected result from scanner");
2364 : TRUE { $$ = new BoolLiteral (true); }
2365 | FALSE { $$ = new BoolLiteral (false); }
2368 parenthesized_expression_0
2369 : OPEN_PARENS expression CLOSE_PARENS
2372 lexer.Deambiguate_CloseParens ();
2373 // After this, the next token returned is one of
2374 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2375 // or CLOSE_PARENS_MINUS.
2379 parenthesized_expression
2380 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2384 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2386 // If a parenthesized expression is followed by a minus, we need to wrap
2387 // the expression inside a ParenthesizedExpression for the CS0075 check
2388 // in Binary.DoResolve().
2389 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2394 : primary_expression DOT IDENTIFIER opt_type_argument_list
2396 $$ = new MemberAccess ((Expression) $1, (string) $3,
2397 (TypeArguments) $4, lexer.Location);
2399 | predefined_type DOT IDENTIFIER opt_type_argument_list
2401 $$ = new MemberAccess ((Expression) $1, (string) $3,
2402 (TypeArguments) $4, lexer.Location);
2410 invocation_expression
2411 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2414 Location l = lexer.Location;
2415 Report.Error (1, l, "Parse error");
2417 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2419 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2421 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2423 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2425 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2430 : /* empty */ { $$ = null; }
2437 ArrayList list = new ArrayList (4);
2441 | argument_list COMMA argument
2443 ArrayList list = (ArrayList) $1;
2447 | argument_list error {
2448 CheckToken (1026, yyToken, ", or ) expected");
2455 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2457 | REF variable_reference
2459 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2461 | OUT variable_reference
2463 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2465 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
2467 ArrayList list = (ArrayList) $3;
2468 Argument[] args = new Argument [list.Count];
2469 list.CopyTo (args, 0);
2471 Expression expr = new Arglist (args, lexer.Location);
2472 $$ = new Argument (expr, Argument.AType.Expression);
2476 $$ = new Argument (new ArglistAccess (lexer.Location), Argument.AType.ArgList);
2481 : expression { note ("section 5.4"); $$ = $1; }
2485 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2487 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2489 | primary_expression rank_specifiers
2491 // So the super-trick is that primary_expression
2492 // can only be either a SimpleName or a MemberAccess.
2493 // The MemberAccess case arises when you have a fully qualified type-name like :
2495 // SimpleName is when you have
2498 Expression expr = (Expression) $1;
2499 if (expr is ComposedCast){
2500 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2501 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2502 Error_ExpectingTypeName (lexer.Location, expr);
2503 $$ = TypeManager.system_object_expr;
2506 // So we extract the string corresponding to the SimpleName
2509 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2517 ArrayList list = new ArrayList (4);
2521 | expression_list COMMA expression
2523 ArrayList list = (ArrayList) $1;
2532 $$ = new This (current_block, lexer.Location);
2537 : BASE DOT IDENTIFIER
2539 $$ = new BaseAccess ((string) $3, lexer.Location);
2541 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2543 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2546 Report.Error (175, "Use of keyword `base' is not valid in this context");
2551 post_increment_expression
2552 : primary_expression OP_INC
2554 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2555 (Expression) $1, lexer.Location);
2559 post_decrement_expression
2560 : primary_expression OP_DEC
2562 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2563 (Expression) $1, lexer.Location);
2568 : object_or_delegate_creation_expression
2569 | array_creation_expression
2572 object_or_delegate_creation_expression
2573 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2575 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2579 array_creation_expression
2580 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2582 opt_array_initializer
2584 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2586 | NEW type rank_specifiers array_initializer
2588 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2592 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2608 : rank_specifier opt_rank_specifier
2610 $$ = (string) $2 + (string) $1;
2615 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2617 $$ = "[" + (string) $2 + "]";
2637 | dim_separators COMMA
2639 $$ = (string) $1 + ",";
2643 opt_array_initializer
2655 : OPEN_BRACE CLOSE_BRACE
2657 ArrayList list = new ArrayList (4);
2660 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2662 $$ = (ArrayList) $2;
2666 variable_initializer_list
2667 : variable_initializer
2669 ArrayList list = new ArrayList (4);
2673 | variable_initializer_list COMMA variable_initializer
2675 ArrayList list = (ArrayList) $1;
2682 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2684 $$ = new TypeOfVoid (lexer.Location);
2686 | TYPEOF OPEN_PARENS
2688 lexer.TypeOfParsing = true;
2692 lexer.TypeOfParsing = false;
2693 $$ = new TypeOf ((Expression) $4, lexer.Location);
2698 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2699 $$ = new SizeOf ((Expression) $3, lexer.Location);
2704 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2706 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2710 unchecked_expression
2711 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2713 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2717 pointer_member_access
2718 : primary_expression OP_PTR IDENTIFIER
2722 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2723 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2727 anonymous_method_expression
2728 : DELEGATE opt_anonymous_method_signature {
2729 oob_stack.Push (current_local_parameters);
2730 current_local_parameters = (Parameters)$2;
2731 create_toplevel_block = true;
2734 Report.Error (-213, lexer.Location, "Anonymous methods are not supported in this branch");
2737 create_toplevel_block = false;
2738 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2739 if (!RootContext.V2){
2740 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2743 $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
2744 current_local_parameters = (Parameters) oob_stack.Pop ();
2749 opt_anonymous_method_signature
2750 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
2751 | anonymous_method_signature
2754 anonymous_method_signature
2755 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2758 $$ = Parameters.EmptyReadOnlyParameters;
2760 ArrayList par_list = (ArrayList) $2;
2761 Parameter [] pars = new Parameter [par_list.Count];
2762 par_list.CopyTo (pars);
2763 $$ = new Parameters (pars, null, lexer.Location);
2768 opt_anonymous_method_parameter_list
2769 : /* empty */ { $$ = null; }
2770 | anonymous_method_parameter_list { $$ = $1; }
2773 anonymous_method_parameter_list
2774 : anonymous_method_parameter
2776 ArrayList a = new ArrayList (4);
2780 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2782 ArrayList a = (ArrayList) $1;
2788 anonymous_method_parameter
2789 : opt_parameter_modifier type IDENTIFIER {
2790 $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
2794 default_value_expression
2795 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
2797 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
2802 : primary_expression
2803 | BANG prefixed_unary_expression
2805 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2807 | TILDE prefixed_unary_expression
2809 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2815 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2817 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2819 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2821 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2827 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2829 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2834 // The idea to split this out is from Rhys' grammar
2835 // to solve the problem with casts.
2837 prefixed_unary_expression
2839 | PLUS prefixed_unary_expression
2841 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2843 | MINUS prefixed_unary_expression
2845 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2847 | OP_INC prefixed_unary_expression
2849 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2850 (Expression) $2, lexer.Location);
2852 | OP_DEC prefixed_unary_expression
2854 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2855 (Expression) $2, lexer.Location);
2857 | STAR prefixed_unary_expression
2859 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2861 | BITWISE_AND prefixed_unary_expression
2863 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2867 pre_increment_expression
2868 : OP_INC prefixed_unary_expression
2870 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2871 (Expression) $2, lexer.Location);
2875 pre_decrement_expression
2876 : OP_DEC prefixed_unary_expression
2878 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2879 (Expression) $2, lexer.Location);
2883 multiplicative_expression
2884 : prefixed_unary_expression
2885 | multiplicative_expression STAR prefixed_unary_expression
2887 $$ = new Binary (Binary.Operator.Multiply,
2888 (Expression) $1, (Expression) $3, lexer.Location);
2890 | multiplicative_expression DIV prefixed_unary_expression
2892 $$ = new Binary (Binary.Operator.Division,
2893 (Expression) $1, (Expression) $3, lexer.Location);
2895 | multiplicative_expression PERCENT prefixed_unary_expression
2897 $$ = new Binary (Binary.Operator.Modulus,
2898 (Expression) $1, (Expression) $3, lexer.Location);
2903 : multiplicative_expression
2904 | additive_expression PLUS multiplicative_expression
2906 $$ = new Binary (Binary.Operator.Addition,
2907 (Expression) $1, (Expression) $3, lexer.Location);
2909 | additive_expression MINUS multiplicative_expression
2911 $$ = new Binary (Binary.Operator.Subtraction,
2912 (Expression) $1, (Expression) $3, lexer.Location);
2917 : additive_expression
2918 | shift_expression OP_SHIFT_LEFT additive_expression
2920 $$ = new Binary (Binary.Operator.LeftShift,
2921 (Expression) $1, (Expression) $3, lexer.Location);
2923 | shift_expression OP_SHIFT_RIGHT additive_expression
2925 $$ = new Binary (Binary.Operator.RightShift,
2926 (Expression) $1, (Expression) $3, lexer.Location);
2930 relational_expression
2932 | relational_expression OP_LT shift_expression
2934 $$ = new Binary (Binary.Operator.LessThan,
2935 (Expression) $1, (Expression) $3, lexer.Location);
2937 | relational_expression OP_GT shift_expression
2939 $$ = new Binary (Binary.Operator.GreaterThan,
2940 (Expression) $1, (Expression) $3, lexer.Location);
2942 | relational_expression OP_LE shift_expression
2944 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2945 (Expression) $1, (Expression) $3, lexer.Location);
2947 | relational_expression OP_GE shift_expression
2949 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2950 (Expression) $1, (Expression) $3, lexer.Location);
2952 | relational_expression IS type
2954 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2956 | relational_expression AS type
2958 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2963 : relational_expression
2964 | equality_expression OP_EQ relational_expression
2966 $$ = new Binary (Binary.Operator.Equality,
2967 (Expression) $1, (Expression) $3, lexer.Location);
2969 | equality_expression OP_NE relational_expression
2971 $$ = new Binary (Binary.Operator.Inequality,
2972 (Expression) $1, (Expression) $3, lexer.Location);
2977 : equality_expression
2978 | and_expression BITWISE_AND equality_expression
2980 $$ = new Binary (Binary.Operator.BitwiseAnd,
2981 (Expression) $1, (Expression) $3, lexer.Location);
2985 exclusive_or_expression
2987 | exclusive_or_expression CARRET and_expression
2989 $$ = new Binary (Binary.Operator.ExclusiveOr,
2990 (Expression) $1, (Expression) $3, lexer.Location);
2994 inclusive_or_expression
2995 : exclusive_or_expression
2996 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2998 $$ = new Binary (Binary.Operator.BitwiseOr,
2999 (Expression) $1, (Expression) $3, lexer.Location);
3003 conditional_and_expression
3004 : inclusive_or_expression
3005 | conditional_and_expression OP_AND inclusive_or_expression
3007 $$ = new Binary (Binary.Operator.LogicalAnd,
3008 (Expression) $1, (Expression) $3, lexer.Location);
3012 conditional_or_expression
3013 : conditional_and_expression
3014 | conditional_or_expression OP_OR conditional_and_expression
3016 $$ = new Binary (Binary.Operator.LogicalOr,
3017 (Expression) $1, (Expression) $3, lexer.Location);
3021 conditional_expression
3022 : conditional_or_expression
3023 | conditional_or_expression INTERR expression COLON expression
3025 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
3029 assignment_expression
3030 : prefixed_unary_expression ASSIGN expression
3032 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
3034 | prefixed_unary_expression OP_MULT_ASSIGN expression
3036 Location l = lexer.Location;
3038 $$ = new CompoundAssign (
3039 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
3041 | prefixed_unary_expression OP_DIV_ASSIGN expression
3043 Location l = lexer.Location;
3045 $$ = new CompoundAssign (
3046 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
3048 | prefixed_unary_expression OP_MOD_ASSIGN expression
3050 Location l = lexer.Location;
3052 $$ = new CompoundAssign (
3053 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
3055 | prefixed_unary_expression OP_ADD_ASSIGN expression
3057 Location l = lexer.Location;
3059 $$ = new CompoundAssign (
3060 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
3062 | prefixed_unary_expression OP_SUB_ASSIGN expression
3064 Location l = lexer.Location;
3066 $$ = new CompoundAssign (
3067 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
3069 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3071 Location l = lexer.Location;
3073 $$ = new CompoundAssign (
3074 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
3076 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3078 Location l = lexer.Location;
3080 $$ = new CompoundAssign (
3081 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
3083 | prefixed_unary_expression OP_AND_ASSIGN expression
3085 Location l = lexer.Location;
3087 $$ = new CompoundAssign (
3088 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
3090 | prefixed_unary_expression OP_OR_ASSIGN expression
3092 Location l = lexer.Location;
3094 $$ = new CompoundAssign (
3095 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
3097 | prefixed_unary_expression OP_XOR_ASSIGN expression
3099 Location l = lexer.Location;
3101 $$ = new CompoundAssign (
3102 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
3107 : conditional_expression
3108 | assignment_expression
3128 MemberName name = MakeName ((MemberName) $5);
3129 bool partial = (bool) $3;
3132 ClassPart part = PartialContainer.CreatePart (
3133 current_namespace, current_container, name, (int) $2,
3134 (Attributes) $1, Kind.Class, lexer.Location);
3136 current_container = part.PartialContainer;
3137 current_class = part;
3139 current_class = new Class (
3140 current_namespace, current_container, name, (int) $2,
3141 (Attributes) $1, lexer.Location);
3143 current_container = current_class;
3144 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
3147 lexer.ConstraintsParsing = true;
3150 opt_type_parameter_constraints_clauses
3152 lexer.ConstraintsParsing = false;
3155 if (current_class.Name == "System.Object") {
3156 Report.Error (537, current_class.Location,
3157 "The class System.Object cannot have a base " +
3158 "class or implement an interface.");
3160 current_class.Bases = (ArrayList) $7;
3163 CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
3164 current_class.Name, current_class.Location);
3166 current_class.Register ();
3173 current_container = current_container.Parent;
3174 current_class = current_container;
3180 { $$ = (bool) false; }
3182 { $$ = (bool) true; }
3186 : /* empty */ { $$ = (int) 0; }
3192 | modifiers modifier
3197 if ((m1 & m2) != 0) {
3198 Location l = lexer.Location;
3199 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3201 $$ = (int) (m1 | m2);
3206 : NEW { $$ = Modifiers.NEW; }
3207 | PUBLIC { $$ = Modifiers.PUBLIC; }
3208 | PROTECTED { $$ = Modifiers.PROTECTED; }
3209 | INTERNAL { $$ = Modifiers.INTERNAL; }
3210 | PRIVATE { $$ = Modifiers.PRIVATE; }
3211 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3212 | SEALED { $$ = Modifiers.SEALED; }
3213 | STATIC { $$ = Modifiers.STATIC; }
3214 | READONLY { $$ = Modifiers.READONLY; }
3215 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3216 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3217 | EXTERN { $$ = Modifiers.EXTERN; }
3218 | VOLATILE { $$ = Modifiers.VOLATILE; }
3219 | UNSAFE { $$ = Modifiers.UNSAFE; }
3223 : /* empty */ { $$ = null; }
3224 | class_base { $$ = $1; }
3228 : COLON type_list { $$ = $2; }
3231 opt_type_parameter_constraints_clauses
3232 : /* empty */ { $$ = null; }
3233 | type_parameter_constraints_clauses
3237 type_parameter_constraints_clauses
3238 : type_parameter_constraints_clause {
3239 ArrayList constraints = new ArrayList (1);
3240 constraints.Add ($1);
3243 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3244 ArrayList constraints = (ArrayList) $1;
3246 constraints.Add ($2);
3251 type_parameter_constraints_clause
3252 : WHERE IDENTIFIER COLON type_parameter_constraints {
3253 $$ = new Constraints ((string) $2, (ArrayList) $4, lexer.Location);
3257 type_parameter_constraints
3258 : type_parameter_constraint {
3259 ArrayList constraints = new ArrayList (1);
3260 constraints.Add ($1);
3263 | type_parameter_constraints COMMA type_parameter_constraint {
3264 ArrayList constraints = (ArrayList) $1;
3266 constraints.Add ($3);
3271 type_parameter_constraint
3273 | NEW OPEN_PARENS CLOSE_PARENS {
3274 $$ = SpecialConstraint.Constructor;
3277 $$ = SpecialConstraint.ReferenceType;
3280 $$ = SpecialConstraint.ValueType;
3289 // A block is "contained" on the following places:
3291 // property_declaration as part of the accessor body (get/set)
3292 // operator_declaration
3293 // constructor_declaration
3294 // destructor_declaration
3295 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3300 if (current_block == null || create_toplevel_block){
3301 current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
3303 current_block = new Block (current_block, current_local_parameters,
3304 lexer.Location, Location.Null);
3307 opt_statement_list CLOSE_BRACE
3309 while (current_block.Implicit)
3310 current_block = current_block.Parent;
3312 current_block.SetEndLocation (lexer.Location);
3313 current_block = current_block.Parent;
3324 | statement_list statement
3328 : declaration_statement
3330 if ($1 != null && (Block) $1 != current_block){
3331 current_block.AddStatement ((Statement) $1);
3332 current_block = (Block) $1;
3335 | valid_declaration_statement
3337 current_block.AddStatement ((Statement) $1);
3342 valid_declaration_statement
3345 | expression_statement
3346 | selection_statement
3347 | iteration_statement
3351 | unchecked_statement
3359 : valid_declaration_statement
3360 | declaration_statement
3362 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
3367 Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
3375 $$ = EmptyStatement.Value;
3382 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3384 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3385 current_block.AddStatement (labeled);
3390 declaration_statement
3391 : local_variable_declaration SEMICOLON
3394 DictionaryEntry de = (DictionaryEntry) $1;
3396 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3400 | local_constant_declaration SEMICOLON
3403 DictionaryEntry de = (DictionaryEntry) $1;
3405 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3411 * The following is from Rhys' grammar:
3412 * > Types in local variable declarations must be recognized as
3413 * > expressions to prevent reduce/reduce errors in the grammar.
3414 * > The expressions are converted into types during semantic analysis.
3417 : primary_expression opt_rank_specifier
3419 // FIXME: Do something smart here regarding the composition of the type.
3421 // Ok, the above "primary_expression" is there to get rid of
3422 // both reduce/reduce and shift/reduces in the grammar, it should
3423 // really just be "type_name". If you use type_name, a reduce/reduce
3424 // creeps up. If you use namespace_or_type_name (which is all we need
3425 // really) two shift/reduces appear.
3428 // So the super-trick is that primary_expression
3429 // can only be either a SimpleName or a MemberAccess.
3430 // The MemberAccess case arises when you have a fully qualified type-name like :
3432 // SimpleName is when you have
3435 Expression expr = (Expression) $1;
3436 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3437 Error_ExpectingTypeName (lexer.Location, expr);
3441 // So we extract the string corresponding to the SimpleName
3445 if ((string) $2 == "")
3448 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3451 | builtin_types opt_rank_specifier
3453 if ((string) $2 == "")
3456 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3460 local_variable_pointer_type
3461 : primary_expression STAR
3463 Expression expr = (Expression) $1;
3464 Location l = lexer.Location;
3466 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3467 Error_ExpectingTypeName (l, expr);
3471 $$ = new ComposedCast ((Expression) $1, "*", l);
3473 | builtin_types STAR
3475 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3479 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3481 | local_variable_pointer_type STAR
3483 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3487 local_variable_declaration
3488 : local_variable_type variable_declarators
3491 $$ = new DictionaryEntry ($1, $2);
3495 | local_variable_pointer_type opt_rank_specifier variable_declarators
3500 if ((string) $2 == "")
3501 t = (Expression) $1;
3503 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3504 $$ = new DictionaryEntry (t, $3);
3510 local_constant_declaration
3511 : CONST local_variable_type constant_declarators
3514 $$ = new DictionaryEntry ($2, $3);
3520 expression_statement
3521 : statement_expression SEMICOLON
3528 // We have to do the wrapping here and not in the case above,
3529 // because statement_expression is used for example in for_statement
3531 statement_expression
3532 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3533 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3534 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3535 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3536 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3537 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3538 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3540 Report.Error (1002, lexer.Location, "Expecting `;'");
3545 object_creation_expression
3546 : object_or_delegate_creation_expression
3547 { note ("complain if this is a delegate maybe?"); }
3556 : if_statement_open if_statement_rest
3565 oob_stack.Push (lexer.Location);
3570 : boolean_expression CLOSE_PARENS
3573 Location l = (Location) oob_stack.Pop ();
3575 $$ = new If ((Expression) $1, (Statement) $3, l);
3577 if (RootContext.WarningLevel >= 3){
3578 if ($3 == EmptyStatement.Value)
3579 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3583 | boolean_expression CLOSE_PARENS
3584 embedded_statement ELSE embedded_statement
3586 Location l = (Location) oob_stack.Pop ();
3588 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3593 : SWITCH OPEN_PARENS
3595 oob_stack.Push (lexer.Location);
3596 switch_stack.Push (current_block);
3598 expression CLOSE_PARENS
3601 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3602 current_block = (Block) switch_stack.Pop ();
3618 Report.Error (1522, lexer.Location, "Empty switch block");
3626 ArrayList sections = new ArrayList (4);
3631 | switch_sections switch_section
3633 ArrayList sections = (ArrayList) $1;
3643 current_block = current_block.CreateSwitchBlock (lexer.Location);
3647 Block topmost = current_block;
3649 while (topmost.Implicit)
3650 topmost = topmost.Parent;
3651 $$ = new SwitchSection ((ArrayList) $1, topmost);
3658 ArrayList labels = new ArrayList (4);
3663 | switch_labels switch_label
3665 ArrayList labels = (ArrayList) ($1);
3673 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3674 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3677 1523, lexer.Location,
3678 "The keyword case or default must precede code in switch block");
3692 oob_stack.Push (lexer.Location);
3694 boolean_expression CLOSE_PARENS embedded_statement
3696 Location l = (Location) oob_stack.Pop ();
3697 $$ = new While ((Expression) $4, (Statement) $6, l);
3699 if (RootContext.WarningLevel >= 3){
3700 if ($6 == EmptyStatement.Value)
3701 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3707 : DO embedded_statement
3709 oob_stack.Push (lexer.Location);
3711 boolean_expression CLOSE_PARENS SEMICOLON
3713 Location l = (Location) oob_stack.Pop ();
3715 $$ = new Do ((Statement) $2, (Expression) $6, l);
3721 opt_for_initializer SEMICOLON
3723 Block assign_block = new Block (current_block);
3724 current_block = assign_block;
3726 if ($3 is DictionaryEntry){
3727 DictionaryEntry de = (DictionaryEntry) $3;
3729 Expression type = (Expression) de.Key;
3730 ArrayList var_declarators = (ArrayList) de.Value;
3732 foreach (VariableDeclaration decl in var_declarators){
3736 vi = current_block.AddVariable (
3737 type, decl.identifier, current_local_parameters, decl.Location);
3741 Location l = lexer.Location;
3743 if (decl.expression_or_array_initializer is Expression){
3744 expr = (Expression) decl.expression_or_array_initializer;
3745 } else if (decl.expression_or_array_initializer == null) {
3748 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3749 expr = new ArrayCreation (type, "", init, decl.Location);
3752 LocalVariableReference var;
3753 var = new LocalVariableReference (assign_block, decl.identifier, l);
3756 Assign a = new Assign (var, expr, decl.Location);
3758 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3764 oob_stack.Push (lexer.Location);
3766 opt_for_condition SEMICOLON
3767 opt_for_iterator CLOSE_PARENS
3770 Location l = (Location) oob_stack.Pop ();
3772 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3774 if (RootContext.WarningLevel >= 3){
3775 if ($10 == EmptyStatement.Value)
3776 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3779 current_block.AddStatement (f);
3780 while (current_block.Implicit)
3781 current_block = current_block.Parent;
3783 current_block = current_block.Parent;
3788 : /* empty */ { $$ = EmptyStatement.Value; }
3793 : local_variable_declaration
3794 | statement_expression_list
3798 : /* empty */ { $$ = null; }
3799 | boolean_expression
3803 : /* empty */ { $$ = EmptyStatement.Value; }
3808 : statement_expression_list
3811 statement_expression_list
3812 : statement_expression
3814 // CHANGE: was `null'
3815 Block b = new Block (current_block, Block.Flags.Implicit);
3817 b.AddStatement ((Statement) $1);
3820 | statement_expression_list COMMA statement_expression
3822 Block b = (Block) $1;
3824 b.AddStatement ((Statement) $3);
3830 : FOREACH OPEN_PARENS type IDENTIFIER IN
3832 oob_stack.Push (lexer.Location);
3834 expression CLOSE_PARENS
3836 oob_stack.Push (current_block);
3838 Block foreach_block = new Block (current_block);
3839 LocalVariableReference v = null;
3840 Location l = lexer.Location;
3843 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3847 // Get a writable reference to this read-only variable.
3848 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3850 current_block = foreach_block;
3853 oob_stack.Push (current_block);
3857 Block foreach_block = (Block) oob_stack.Pop ();
3858 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3859 Block prev_block = (Block) oob_stack.Pop ();
3860 Location l = (Location) oob_stack.Pop ();
3862 current_block = prev_block;
3865 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3866 foreach_block.AddStatement (f);
3875 | continue_statement
3885 $$ = new Break (lexer.Location);
3890 : CONTINUE SEMICOLON
3892 $$ = new Continue (lexer.Location);
3897 : GOTO IDENTIFIER SEMICOLON
3899 $$ = new Goto (current_block, (string) $2, lexer.Location);
3901 | GOTO CASE constant_expression SEMICOLON
3903 $$ = new GotoCase ((Expression) $3, lexer.Location);
3905 | GOTO DEFAULT SEMICOLON
3907 $$ = new GotoDefault (lexer.Location);
3912 : RETURN opt_expression SEMICOLON
3914 $$ = new Return ((Expression) $2, lexer.Location);
3919 : THROW opt_expression SEMICOLON
3921 $$ = new Throw ((Expression) $2, lexer.Location);
3926 : IDENTIFIER RETURN expression SEMICOLON
3928 string s = (string) $1;
3930 Report.Error (1003, lexer.Location, "; expected");
3933 if (!RootContext.V2){
3934 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3937 if (iterator_container == null){
3938 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3941 iterator_container.SetYields ();
3942 $$ = new Yield ((Expression) $3, lexer.Location);
3945 | IDENTIFIER BREAK SEMICOLON
3947 string s = (string) $1;
3949 Report.Error (1003, lexer.Location, "; expected");
3952 if (!RootContext.V2){
3953 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3956 if (iterator_container == null){
3957 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3960 iterator_container.SetYields ();
3961 $$ = new YieldBreak (lexer.Location);
3972 : TRY block catch_clauses
3975 ArrayList s = new ArrayList (4);
3977 foreach (Catch cc in (ArrayList) $3) {
3984 // Now s contains the list of specific catch clauses
3985 // and g contains the general one.
3987 $$ = new Try ((Block) $2, s, g, null, lexer.Location);
3989 | TRY block opt_catch_clauses FINALLY block
3992 ArrayList s = new ArrayList (4);
3993 ArrayList catch_list = (ArrayList) $3;
3995 if (catch_list != null){
3996 foreach (Catch cc in catch_list) {
4004 $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
4008 Report.Error (1524, lexer.Location, "Expected catch or finally");
4013 : /* empty */ { $$ = null; }
4020 ArrayList l = new ArrayList (4);
4025 | catch_clauses catch_clause
4027 ArrayList l = (ArrayList) $1;
4035 : /* empty */ { $$ = null; }
4040 : CATCH opt_catch_args
4042 Expression type = null;
4046 DictionaryEntry cc = (DictionaryEntry) $2;
4047 type = (Expression) cc.Key;
4048 id = (string) cc.Value;
4051 ArrayList one = new ArrayList (4);
4052 Location loc = lexer.Location;
4054 one.Add (new VariableDeclaration (id, null, loc));
4057 current_block = new Block (current_block);
4058 Block b = declare_local_variables (type, one, loc);
4063 Expression type = null;
4067 DictionaryEntry cc = (DictionaryEntry) $2;
4068 type = (Expression) cc.Key;
4069 id = (string) cc.Value;
4073 // FIXME: I can change this for an assignment.
4075 while (current_block != (Block) $1)
4076 current_block = current_block.Parent;
4081 $$ = new Catch (type, id , (Block) $4, lexer.Location);
4086 : /* empty */ { $$ = null; }
4091 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4093 $$ = new DictionaryEntry ($2, $3);
4100 $$ = new Checked ((Block) $2);
4107 $$ = new Unchecked ((Block) $2);
4114 if (!RootContext.Unsafe){
4115 Report.Error (227, lexer.Location,
4116 "Unsafe code can only be used if --unsafe is used");
4119 $$ = new Unsafe ((Block) $3);
4125 type fixed_pointer_declarators
4128 Block assign_block = new Block (current_block, Block.Flags.Implicit);
4129 ArrayList list = (ArrayList) $4;
4130 Expression type = (Expression) $3;
4131 Location l = lexer.Location;
4132 int top = list.Count;
4134 for (int i = 0; i < top; i++){
4135 Pair p = (Pair) list [i];
4138 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4147 current_block.AddStatement (assign_block);
4148 current_block = assign_block;
4149 oob_stack.Push (assign_block);
4154 Location l = (Location) oob_stack.Pop ();
4157 $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4161 fixed_pointer_declarators
4162 : fixed_pointer_declarator {
4163 ArrayList declarators = new ArrayList (4);
4165 declarators.Add ($1);
4168 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4170 ArrayList declarators = (ArrayList) $1;
4172 declarators.Add ($3);
4177 fixed_pointer_declarator
4178 : IDENTIFIER ASSIGN expression
4180 $$ = new Pair ($1, $3);
4184 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
4190 : LOCK OPEN_PARENS expression CLOSE_PARENS
4196 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4201 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4203 Block assign_block = new Block (current_block);
4204 current_block = assign_block;
4206 oob_stack.Push (lexer.Location);
4208 if ($3 is DictionaryEntry){
4209 DictionaryEntry de = (DictionaryEntry) $3;
4210 Location l = lexer.Location;
4212 Expression type = (Expression) de.Key;
4213 ArrayList var_declarators = (ArrayList) de.Value;
4215 ArrayList vars = new ArrayList (4);
4217 foreach (VariableDeclaration decl in var_declarators){
4219 LocalInfo vi = current_block.AddVariable (
4220 type, decl.identifier,
4221 current_local_parameters, decl.Location);
4227 if (decl.expression_or_array_initializer is Expression){
4228 expr = (Expression) decl.expression_or_array_initializer;
4230 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4232 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4235 expr = new ArrayCreation (type, "", init, decl.Location);
4238 LocalVariableReference var;
4240 // Get a writable reference to this read-only variable.
4241 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4243 // This is so that it is not a warning on using variables
4246 vars.Add (new DictionaryEntry (var, expr));
4248 // Assign a = new Assign (var, expr, decl.Location);
4249 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4251 $3 = new DictionaryEntry (type, vars);
4256 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4257 current_block.AddStatement (u);
4258 while (current_block.Implicit)
4259 current_block = current_block.Parent;
4261 current_block = current_block.Parent;
4265 resource_acquisition
4266 : local_variable_declaration
4273 // A class used to pass around variable declarations and constants
4275 public class VariableDeclaration {
4276 public string identifier;
4277 public object expression_or_array_initializer;
4278 public Location Location;
4279 public Attributes OptAttributes;
4281 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4283 this.identifier = id;
4284 this.expression_or_array_initializer = eoai;
4286 this.OptAttributes = opt_attrs;
4289 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4295 /// Used to pass around interface property information
4297 public class InterfaceAccessorInfo {
4299 public readonly Accessor Get, Set;
4301 public InterfaceAccessorInfo (bool has_get, bool has_set,
4302 Attributes get_attrs, Attributes set_attrs)
4305 Get = new Accessor (null, get_attrs);
4307 Set = new Accessor (null, set_attrs);
4313 // A class used to hold info about an indexer declarator
4315 public class IndexerDeclaration {
4316 public Expression type;
4317 public MemberName interface_type;
4318 public Parameters param_list;
4320 public IndexerDeclaration (Expression type, MemberName interface_type,
4321 Parameters param_list)
4324 this.interface_type = interface_type;
4325 this.param_list = param_list;
4330 // We use this when we do not have an object in advance that is an IIteratorContainer
4332 public class SimpleIteratorContainer : IIteratorContainer {
4335 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4340 public static SimpleIteratorContainer GetSimple () {
4341 Simple.Yields = false;
4345 public void SetYields () { Yields = true; }
4349 // A class used to hold info about an operator declarator
4351 public class OperatorDeclaration {
4352 public Operator.OpType optype;
4353 public Expression ret_type, arg1type, arg2type;
4354 public string arg1name, arg2name;
4355 public Location location;
4357 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4358 Expression arg1type, string arg1name,
4359 Expression arg2type, string arg2name, Location location)
4362 this.ret_type = ret_type;
4363 this.arg1type = arg1type;
4364 this.arg1name = arg1name;
4365 this.arg2type = arg2type;
4366 this.arg2name = arg2name;
4367 this.location = location;
4372 void Error_ExpectingTypeName (Location l, Expression expr)
4374 if (expr is Invocation){
4375 Report.Error (1002, l, "; expected");
4377 Report.Error (-1, l, "Invalid Type definition");
4382 // Given the @class_name name, it creates a fully qualified name
4383 // based on the containing declaration space
4386 MakeName (MemberName class_name)
4388 string ns = current_namespace.FullName;
4390 if (current_container.Name == ""){
4392 return new MemberName (new MemberName (ns), class_name);
4396 return new MemberName (current_container.MemberName, class_name);
4401 // Used to report back to the user the result of a declaration
4402 // in the current declaration space
4405 CheckDef (DeclSpace.AdditionResult result, string name, Location l)
4407 current_container.CheckDef (result, name, l);
4411 CheckDef (bool result, string name, Location l)
4415 CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
4418 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4420 Block implicit_block;
4421 ArrayList inits = null;
4424 // We use the `Used' property to check whether statements
4425 // have been added to the current block. If so, we need
4426 // to create another block to contain the new declaration
4427 // otherwise, as an optimization, we use the same block to
4428 // add the declaration.
4430 // FIXME: A further optimization is to check if the statements
4431 // that were added were added as part of the initialization
4432 // below. In which case, no other statements have been executed
4433 // and we might be able to reduce the number of blocks for
4434 // situations like this:
4436 // int j = 1; int k = j + 1;
4438 if (current_block.Used)
4439 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4441 implicit_block = current_block;
4443 foreach (VariableDeclaration decl in variable_declarators){
4445 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4446 if (decl.expression_or_array_initializer != null){
4448 inits = new ArrayList (4);
4455 return implicit_block;
4457 foreach (VariableDeclaration decl in inits){
4461 if (decl.expression_or_array_initializer is Expression){
4462 expr = (Expression) decl.expression_or_array_initializer;
4465 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4467 expr = new ArrayCreation (type, "", init, decl.Location);
4470 LocalVariableReference var;
4471 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4473 assign = new Assign (var, expr, decl.Location);
4475 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4478 return implicit_block;
4481 Block declare_local_constants (Expression type, ArrayList declarators)
4483 Block implicit_block;
4485 if (current_block.Used)
4486 implicit_block = new Block (current_block, Block.Flags.Implicit);
4488 implicit_block = current_block;
4490 foreach (VariableDeclaration decl in declarators){
4491 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4492 current_local_parameters, decl.Location);
4495 return implicit_block;
4498 void CheckAttributeTarget (string a)
4502 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4506 Location l = lexer.Location;
4507 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4513 void CheckUnaryOperator (Operator.OpType op)
4517 case Operator.OpType.LogicalNot:
4518 case Operator.OpType.OnesComplement:
4519 case Operator.OpType.Increment:
4520 case Operator.OpType.Decrement:
4521 case Operator.OpType.True:
4522 case Operator.OpType.False:
4523 case Operator.OpType.Addition:
4524 case Operator.OpType.Subtraction:
4529 Location l = lexer.Location;
4530 Report.Error (1019, l, "Overloadable unary operator expected");
4536 void CheckBinaryOperator (Operator.OpType op)
4540 case Operator.OpType.Addition:
4541 case Operator.OpType.Subtraction:
4542 case Operator.OpType.Multiply:
4543 case Operator.OpType.Division:
4544 case Operator.OpType.Modulus:
4545 case Operator.OpType.BitwiseAnd:
4546 case Operator.OpType.BitwiseOr:
4547 case Operator.OpType.ExclusiveOr:
4548 case Operator.OpType.LeftShift:
4549 case Operator.OpType.RightShift:
4550 case Operator.OpType.Equality:
4551 case Operator.OpType.Inequality:
4552 case Operator.OpType.GreaterThan:
4553 case Operator.OpType.LessThan:
4554 case Operator.OpType.GreaterThanOrEqual:
4555 case Operator.OpType.LessThanOrEqual:
4559 Location l = lexer.Location;
4560 Report.Error (1020, l, "Overloadable binary operator expected");
4566 void syntax_error (Location l, string msg)
4568 Report.Error (1003, l, "Syntax error, " + msg);
4571 void output (string s)
4573 Console.WriteLine (s);
4576 void note (string s)
4578 // Used to put annotations
4583 public Tokenizer Lexer {
4589 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4591 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4592 this.name = file.Name;
4594 current_container = RootContext.Tree.Types;
4595 current_container.NamespaceEntry = current_namespace;
4596 oob_stack = new Stack ();
4597 switch_stack = new Stack ();
4599 lexer = new Tokenizer (reader, file, defines);
4602 public void parse ()
4605 if (yacc_verbose_flag)
4606 yyparse (lexer, new yydebug.yyDebugSimple ());
4609 Tokenizer tokenizer = lexer as Tokenizer;
4610 tokenizer.cleanup ();
4611 } catch (Exception e){
4612 // Please do not remove this, it is used during debugging
4615 Console.WriteLine (e);
4616 Report.Error (-25, lexer.Location, "Parsing error");
4617 if (Driver.parser_verbose)
4618 Console.WriteLine (e);
4622 void CheckToken (int error, int yyToken, string msg)
4624 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4625 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4628 Report.Error (error, lexer.Location, msg);
4631 void CheckIdentifierToken (int yyToken)
4633 CheckToken (1041, yyToken, "Identifier expected");