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
43 Block current_block, top_current_block;
45 Delegate current_delegate;
48 /// This is used by the unary_expression code to resolve
49 /// a name against a parameter.
51 Parameters current_local_parameters;
54 /// Using during property parsing to describe the implicit
55 /// value parameter that is passed to the "set" and "get"accesor
56 /// methods (properties and indexers).
58 Expression implicit_value_parameter_type;
59 Parameters indexer_parameters;
62 /// Used to determine if we are parsing the get/set pair
63 /// of an indexer or a property
68 /// An out-of-band stack.
77 static public int yacc_verbose_flag;
79 // Name of the file we are parsing
88 /// Current attribute target
89 string current_attr_target;
91 /// assembly and module attribute definition is enabled
92 bool global_attrs_enabled = true;
96 %token NONE /* This token is never returned by our lexer */
97 %token ERROR // This is used not by the parser, but by the tokenizer.
101 *These are the C# keywords
188 /* C# keywords which are not really keywords */
194 /* C# single character operators/punctuation. */
195 %token OPEN_BRACE "{"
196 %token CLOSE_BRACE "}"
197 %token OPEN_BRACKET "["
198 %token CLOSE_BRACKET "]"
199 %token OPEN_PARENS "("
200 %token CLOSE_PARENS ")"
212 %token OP_GENERICS_LT "<"
214 %token OP_GENERICS_GT ">"
215 %token BITWISE_AND "&"
216 %token BITWISE_OR "|"
223 /* C# multi-character operators. */
226 %token OP_SHIFT_LEFT "<<"
227 %token OP_SHIFT_RIGHT ">>"
234 %token OP_MULT_ASSIGN "*="
235 %token OP_DIV_ASSIGN "/="
236 %token OP_MOD_ASSIGN "%="
237 %token OP_ADD_ASSIGN "+="
238 %token OP_SUB_ASSIGN "-="
239 %token OP_SHIFT_LEFT_ASSIGN "<<="
240 %token OP_SHIFT_RIGHT_ASSIGN ">>="
241 %token OP_AND_ASSIGN "&="
242 %token OP_XOR_ASSIGN "^="
243 %token OP_OR_ASSIGN "|="
247 %token LITERAL_INTEGER "int literal"
248 %token LITERAL_FLOAT "float literal"
249 %token LITERAL_DOUBLE "double literal"
250 %token LITERAL_DECIMAL "decimal literal"
251 %token LITERAL_CHARACTER "character literal"
252 %token LITERAL_STRING "string literal"
255 %token CLOSE_PARENS_CAST
256 %token CLOSE_PARENS_NO_CAST
257 %token CLOSE_PARENS_OPEN_PARENS
258 %token CLOSE_PARENS_MINUS
259 %token DEFAULT_OPEN_PARENS
260 %token GENERIC_DIMENSION
262 /* Add precedence rules to solve dangling else s/r conflict */
271 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
273 %left STAR DIV PERCENT
274 %right BANG CARRET UMINUS
275 %nonassoc OP_INC OP_DEC
277 %left OPEN_BRACKET OPEN_BRACE
281 %start compilation_unit
285 : outer_declarations opt_EOF
286 | outer_declarations global_attributes opt_EOF
287 | global_attributes opt_EOF
288 | opt_EOF /* allow empty files */
298 | outer_declarations outer_declaration
303 | namespace_member_declaration
308 | using_directives using_directive
312 : using_alias_directive
313 | using_namespace_directive
316 using_alias_directive
317 : USING IDENTIFIER ASSIGN
318 namespace_or_type_name SEMICOLON
320 current_namespace.UsingAlias ((string) $2, (MemberName) $4, lexer.Location);
323 CheckIdentifierToken (yyToken);
327 using_namespace_directive
328 : USING namespace_name SEMICOLON
330 current_namespace.Using ((string) $2, lexer.Location);
335 // Strictly speaking, namespaces don't have attributes but
336 // we parse global attributes along with namespace declarations and then
339 namespace_declaration
340 : opt_attributes NAMESPACE namespace_or_type_name
343 Report.Error(1518, Lexer.Location, "Attributes cannot be applied to namespaces."
344 + " Expected class, delegate, enum, interface, or struct");
347 MemberName name = (MemberName) $3;
349 if (name.TypeArguments != null)
350 syntax_error (lexer.Location, "namespace name expected");
351 else if ((current_namespace.Parent != null) && (name.Left != null)) {
352 Report.Error (134, lexer.Location,
353 "Cannot use qualified namespace names in nested " +
354 "namespace declarations");
357 current_namespace = new NamespaceEntry (
358 current_namespace, file, name.GetName (), lexer.Location);
360 namespace_body opt_semicolon
362 current_namespace = current_namespace.Parent;
377 : namespace_or_type_name {
378 MemberName name = (MemberName) $1;
380 if (name.TypeArguments != null)
381 syntax_error (lexer.Location, "namespace name expected");
383 $$ = name.GetName ();
390 opt_namespace_member_declarations
401 opt_namespace_member_declarations
403 | namespace_member_declarations
406 namespace_member_declarations
407 : namespace_member_declaration
408 | namespace_member_declarations namespace_member_declaration
411 namespace_member_declaration
418 Class c = (Class) $1;
419 mod_flags = c.ModFlags;
421 } else if ($1 is Struct){
422 Struct s = (Struct) $1;
423 mod_flags = s.ModFlags;
428 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
430 1527, lexer.Location,
431 "Namespace elements cant be explicitly " +
432 "declared private or protected in `" + name + "'");
434 current_namespace.DeclarationFound = true;
436 | namespace_declaration {
437 current_namespace.DeclarationFound = true;
440 | field_declaration {
441 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
443 | method_declaration {
444 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
451 | interface_declaration
453 | delegate_declaration
455 // Enable this when we have handled all errors, because this acts as a generic fallback
458 // Console.WriteLine ("Token=" + yyToken);
459 // Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
471 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
479 global_attrs_enabled = false;
484 global_attrs_enabled = false;
493 ArrayList sect = (ArrayList) $1;
495 if (global_attrs_enabled) {
496 if (current_attr_target == "module") {
497 CodeGen.Module.AddAttributes (sect);
499 } else if (current_attr_target == "assembly") {
500 CodeGen.Assembly.AddAttributes (sect);
503 $$ = new Attributes (sect);
506 $$ = new Attributes (sect);
508 current_attr_target = null;
510 | attribute_sections attribute_section
512 Attributes attrs = $1 as Attributes;
513 ArrayList sect = (ArrayList) $2;
515 if (global_attrs_enabled) {
516 if (current_attr_target == "module") {
517 CodeGen.Module.AddAttributes (sect);
519 } else if (current_attr_target == "assembly") {
520 CodeGen.Assembly.AddAttributes (sect);
524 attrs = new Attributes (sect);
526 attrs.AddAttributes (sect);
530 attrs = new Attributes (sect);
532 attrs.AddAttributes (sect);
535 current_attr_target = null;
540 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
544 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
550 attribute_target_specifier
551 : attribute_target COLON
553 current_attr_target = (string)$1;
561 CheckAttributeTarget ((string) $1);
564 | EVENT { $$ = "event"; }
565 | RETURN { $$ = "return"; }
571 ArrayList attrs = new ArrayList (4);
577 | attribute_list COMMA attribute
579 ArrayList attrs = (ArrayList) $1;
591 opt_attribute_arguments
593 MemberName mname = (MemberName) $1;
594 if (mname.IsGeneric) {
595 Report.Error (404, lexer.Location,
596 "'<' unexpected: attributes cannot be generic");
599 string name = mname.GetName ();
600 if (current_attr_target == "assembly" || current_attr_target == "module")
601 $$ = new GlobalAttribute (current_container, current_attr_target,
602 name, (ArrayList) $3, (Location) $2);
604 $$ = new Attribute (current_attr_target, name, (ArrayList) $3,
610 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
613 opt_attribute_arguments
614 : /* empty */ { $$ = null; }
615 | OPEN_PARENS attribute_arguments CLOSE_PARENS
623 : opt_positional_argument_list
628 ArrayList args = new ArrayList (4);
634 | positional_argument_list COMMA named_argument_list
636 ArrayList args = new ArrayList (4);
642 | named_argument_list
644 ArrayList args = new ArrayList (4);
653 opt_positional_argument_list
654 : /* empty */ { $$ = null; }
655 | positional_argument_list
658 positional_argument_list
661 ArrayList args = new ArrayList (4);
662 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
666 | positional_argument_list COMMA expression
668 ArrayList args = (ArrayList) $1;
669 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
678 ArrayList args = new ArrayList (4);
683 | named_argument_list COMMA named_argument
685 ArrayList args = (ArrayList) $1;
690 | named_argument_list COMMA expression
692 Report.Error (1016, lexer.Location, "Named attribute argument expected");
698 : IDENTIFIER ASSIGN expression
700 $$ = new DictionaryEntry (
702 new Argument ((Expression) $3, Argument.AType.Expression));
708 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
711 opt_class_member_declarations
713 | class_member_declarations
716 class_member_declarations
717 : class_member_declaration
718 | class_member_declarations
719 class_member_declaration
722 class_member_declaration
723 : constant_declaration // done
724 | field_declaration // done
725 | method_declaration // done
726 | property_declaration // done
727 | event_declaration // done
728 | indexer_declaration // done
729 | operator_declaration // done
730 | constructor_declaration // done
731 | destructor_declaration // done
741 MemberName name = MakeName ((MemberName) $5);
742 bool partial = (bool) $3;
745 ClassPart part = PartialContainer.CreatePart (
746 current_namespace, current_container, name, (int) $2,
747 (Attributes) $1, Kind.Struct, lexer.Location);
749 current_container = part.PartialContainer;
750 current_class = part;
752 current_class = new Struct (
753 current_namespace, current_container, name, (int) $2,
754 (Attributes) $1, lexer.Location);
756 current_container = current_class;
757 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
760 lexer.ConstraintsParsing = true;
763 opt_type_parameter_constraints_clauses
765 lexer.ConstraintsParsing = false;
768 current_class.Bases = (ArrayList) $7;
770 current_class.SetParameterInfo ((ArrayList) $8);
772 current_class.Register ();
779 current_container = current_container.Parent;
780 current_class = current_container;
782 | opt_attributes opt_modifiers opt_partial STRUCT error {
783 CheckIdentifierToken (yyToken);
788 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
791 opt_struct_member_declarations
793 | struct_member_declarations
796 struct_member_declarations
797 : struct_member_declaration
798 | struct_member_declarations struct_member_declaration
801 struct_member_declaration
802 : constant_declaration
805 | property_declaration
807 | indexer_declaration
808 | operator_declaration
809 | constructor_declaration
813 * This is only included so we can flag error 575:
814 * destructors only allowed on class types
816 | destructor_declaration
827 int modflags = (int) $2;
828 foreach (VariableDeclaration constant in (ArrayList) $5){
829 Location l = constant.Location;
830 if ((modflags & Modifiers.STATIC) != 0) {
831 Report.Error (504, l, "The constant '{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
835 Const c = new Const (
836 current_class, (Expression) $4, (string) constant.identifier,
837 (Expression) constant.expression_or_array_initializer, modflags,
840 current_container.AddConstant (c);
846 : constant_declarator
848 ArrayList constants = new ArrayList (4);
853 | constant_declarators COMMA constant_declarator
856 ArrayList constants = (ArrayList) $1;
863 : IDENTIFIER ASSIGN constant_expression
865 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
869 // A const field requires a value to be provided
870 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
882 Expression type = (Expression) $3;
885 foreach (VariableDeclaration var in (ArrayList) $4){
886 Location l = var.Location;
888 Field field = new Field (current_class, type, mod, var.identifier,
889 var.expression_or_array_initializer,
892 current_container.AddField (field);
900 Report.Error (670, lexer.Location, "void type is not allowed for fields");
905 : variable_declarator
907 ArrayList decl = new ArrayList (4);
911 | variable_declarators COMMA variable_declarator
913 ArrayList decls = (ArrayList) $1;
920 : IDENTIFIER ASSIGN variable_initializer
922 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
926 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
939 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
941 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
945 Report.Error (1575, lexer.Location, "A stackalloc expression requires [] after type");
952 iterator_container = (IIteratorContainer) $1;
956 Method method = (Method) $1;
957 Block b = (Block) $3;
958 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
961 if ((method.ModFlags & extern_abstract) == 0){
963 501, lexer.Location, current_container.MakeName (method.Name) +
964 "must declare a body because it is not marked abstract or extern");
967 if ((method.ModFlags & Modifiers.EXTERN) != 0){
969 179, lexer.Location, current_container.MakeName (method.Name) +
970 " is declared extern, but has a body");
974 method.Block = (ToplevelBlock) $3;
975 current_container.AddMethod (method);
977 current_local_parameters = null;
978 iterator_container = null;
992 1585, lexer.Location, "Member modifier `" +
993 Modifiers.Name (i) + "' must precede member type and name");
1004 type namespace_or_type_name
1005 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1007 lexer.ConstraintsParsing = true;
1009 opt_type_parameter_constraints_clauses
1011 lexer.ConstraintsParsing = false;
1013 MemberName name = (MemberName) $4;
1015 if ($9 != null && name.TypeArguments == null)
1016 Report.Error (80, lexer.Location,
1017 "Contraints are not allowed on non-generic declarations");
1021 GenericMethod generic = null;
1022 if (name.TypeArguments != null) {
1023 generic = new GenericMethod (current_namespace, current_class,
1024 name, lexer.Location);
1026 generic.SetParameterInfo ((ArrayList) $9);
1029 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1030 name, (Parameters) $6, (Attributes) $1, lexer.Location);
1032 current_local_parameters = (Parameters) $6;
1038 VOID namespace_or_type_name
1039 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1041 lexer.ConstraintsParsing = true;
1043 opt_type_parameter_constraints_clauses
1045 lexer.ConstraintsParsing = false;
1047 MemberName name = (MemberName) $4;
1049 if ($9 != null && name.TypeArguments == null)
1050 Report.Error (80, lexer.Location,
1051 "Contraints are not allowed on non-generic declarations");
1054 GenericMethod generic = null;
1055 if (name.TypeArguments != null) {
1056 generic = new GenericMethod (current_namespace, current_class,
1057 name, lexer.Location);
1059 generic.SetParameterInfo ((ArrayList) $9);
1062 method = new Method (current_class, generic, TypeManager.system_void_expr,
1063 (int) $2, false, name, (Parameters) $6, (Attributes) $1,
1066 current_local_parameters = (Parameters) $6;
1072 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1074 Report.Error (1585, lexer.Location,
1075 String.Format ("Modifier {0} should appear before type",
1076 Modifiers.Name ((int) $4)));
1077 MemberName name = (MemberName) $4;
1079 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1080 0, false, name, (Parameters) $6, (Attributes) $1,
1083 current_local_parameters = (Parameters) $6;
1090 | SEMICOLON { $$ = null; }
1093 opt_formal_parameter_list
1094 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1095 | formal_parameter_list
1098 formal_parameter_list
1101 ArrayList pars_list = (ArrayList) $1;
1103 Parameter [] pars = new Parameter [pars_list.Count];
1104 pars_list.CopyTo (pars);
1106 $$ = new Parameters (pars, null, lexer.Location);
1108 | fixed_parameters COMMA parameter_array
1110 ArrayList pars_list = (ArrayList) $1;
1112 Parameter [] pars = new Parameter [pars_list.Count];
1113 pars_list.CopyTo (pars);
1115 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
1117 | fixed_parameters COMMA ARGLIST
1119 ArrayList pars_list = (ArrayList) $1;
1121 Parameter [] pars = new Parameter [pars_list.Count];
1122 pars_list.CopyTo (pars);
1124 $$ = new Parameters (pars, true, lexer.Location);
1128 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1132 $$ = new Parameters (null, true, lexer.Location);
1139 ArrayList pars = new ArrayList (4);
1144 | fixed_parameters COMMA fixed_parameter
1146 ArrayList pars = (ArrayList) $1;
1155 opt_parameter_modifier
1159 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1162 opt_parameter_modifier
1165 Report.Error (1001, lexer.Location, "Identifier expected");
1169 opt_parameter_modifier
1172 CheckIdentifierToken (yyToken);
1176 opt_parameter_modifier
1182 Report.Error (241, lexer.Location, "Default parameter specifiers are not permitted");
1187 opt_parameter_modifier
1188 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1189 | parameter_modifier
1193 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1194 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1198 : opt_attributes PARAMS type IDENTIFIER
1200 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1201 note ("type must be a single-dimension array type");
1203 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1205 Report.Error (1611, lexer.Location, "The params parameter cannot be declared as ref or out");
1208 | opt_attributes PARAMS type error {
1209 CheckIdentifierToken (yyToken);
1214 property_declaration
1217 type namespace_or_type_name
1220 implicit_value_parameter_type = (Expression) $3;
1222 lexer.PropertyParsing = true;
1224 $$ = lexer.Location;
1226 iterator_container = SimpleIteratorContainer.GetSimple ();
1228 accessor_declarations
1230 lexer.PropertyParsing = false;
1235 Pair pair = (Pair) $7;
1236 Accessor get_block = (Accessor) pair.First;
1237 Accessor set_block = (Accessor) pair.Second;
1239 Location loc = (Location) $6;
1240 MemberName name = (MemberName) $4;
1242 if (name.TypeArguments != null)
1243 syntax_error (lexer.Location, "a property can't have type arguments");
1245 prop = new Property (current_container, (Expression) $3, (int) $2, false,
1246 name, (Attributes) $1, get_block, set_block, loc);
1247 if (SimpleIteratorContainer.Simple.Yields)
1250 current_container.AddProperty (prop);
1251 implicit_value_parameter_type = null;
1252 iterator_container = null;
1256 accessor_declarations
1257 : get_accessor_declaration opt_set_accessor_declaration
1259 $$ = new Pair ($1, $2);
1261 | set_accessor_declaration opt_get_accessor_declaration
1263 $$ = new Pair ($2, $1);
1267 opt_get_accessor_declaration
1268 : /* empty */ { $$ = null; }
1269 | get_accessor_declaration
1272 opt_set_accessor_declaration
1273 : /* empty */ { $$ = null; }
1274 | set_accessor_declaration
1277 get_accessor_declaration
1278 : opt_attributes opt_modifiers GET
1280 // If this is not the case, then current_local_parameters has already
1281 // been set in indexer_declaration
1282 if (parsing_indexer == false)
1283 current_local_parameters = null;
1285 current_local_parameters = indexer_parameters;
1286 lexer.PropertyParsing = false;
1290 $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
1291 current_local_parameters = null;
1292 lexer.PropertyParsing = true;
1296 set_accessor_declaration
1297 : opt_attributes opt_modifiers SET
1300 Parameter implicit_value_parameter = new Parameter (
1301 implicit_value_parameter_type, "value",
1302 Parameter.Modifier.NONE, null);
1304 if (parsing_indexer == false) {
1305 args = new Parameter [1];
1306 args [0] = implicit_value_parameter;
1307 current_local_parameters = new Parameters (args, null, lexer.Location);
1309 Parameter [] fpars = indexer_parameters.FixedParameters;
1312 int count = fpars.Length;
1314 args = new Parameter [count + 1];
1315 fpars.CopyTo (args, 0);
1316 args [count] = implicit_value_parameter;
1319 current_local_parameters = new Parameters (
1320 args, indexer_parameters.ArrayParameter, lexer.Location);
1323 lexer.PropertyParsing = false;
1327 $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
1328 current_local_parameters = null;
1329 lexer.PropertyParsing = true;
1335 | SEMICOLON { $$ = null; }
1338 interface_declaration
1342 INTERFACE member_name
1344 MemberName name = MakeName ((MemberName) $5);
1345 bool partial = (bool) $3;
1348 ClassPart part = PartialContainer.CreatePart (
1349 current_namespace, current_container, name, (int) $2,
1350 (Attributes) $1, Kind.Interface, lexer.Location);
1352 current_container = part.PartialContainer;
1353 current_class = part;
1355 current_class = new Interface (
1356 current_namespace, current_container, name, (int) $2,
1357 (Attributes) $1, lexer.Location);
1359 current_container = current_class;
1360 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
1363 lexer.ConstraintsParsing = true;
1366 opt_type_parameter_constraints_clauses
1368 lexer.ConstraintsParsing = false;
1371 current_class.Bases = (ArrayList) $7;
1373 current_class.SetParameterInfo ((ArrayList) $8);
1375 current_class.Register ();
1377 interface_body opt_semicolon
1381 current_container = current_container.Parent;
1382 current_class = current_container;
1384 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1385 CheckIdentifierToken (yyToken);
1391 opt_interface_member_declarations
1395 opt_interface_member_declarations
1397 | interface_member_declarations
1400 interface_member_declarations
1401 : interface_member_declaration
1402 | interface_member_declarations interface_member_declaration
1405 interface_member_declaration
1406 : interface_method_declaration
1408 Method m = (Method) $1;
1410 current_container.AddMethod (m);
1412 | interface_property_declaration
1414 Property p = (Property) $1;
1416 current_container.AddProperty (p);
1418 | interface_event_declaration
1421 Event e = (Event) $1;
1422 current_container.AddEvent (e);
1425 | interface_indexer_declaration
1427 Indexer i = (Indexer) $1;
1429 current_container.AddIndexer (i);
1437 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1442 interface_method_declaration
1443 : opt_attributes opt_new type namespace_or_type_name
1444 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1446 lexer.ConstraintsParsing = true;
1448 opt_type_parameter_constraints_clauses
1451 lexer.ConstraintsParsing = false;
1453 MemberName name = (MemberName) $4;
1455 if ($9 != null && name.TypeArguments == null)
1456 Report.Error (80, lexer.Location,
1457 "Contraints are not allowed on non-generic declarations");
1459 GenericMethod generic = null;
1460 if (name.TypeArguments != null) {
1461 generic = new GenericMethod (current_namespace, current_class,
1462 name, lexer.Location);
1464 generic.SetParameterInfo ((ArrayList) $9);
1467 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1468 (Parameters) $6, (Attributes) $1, lexer.Location);
1470 | opt_attributes opt_new VOID namespace_or_type_name
1471 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1473 lexer.ConstraintsParsing = true;
1475 opt_type_parameter_constraints_clauses
1478 lexer.ConstraintsParsing = false;
1480 MemberName name = (MemberName) $4;
1482 if ($9 != null && name.TypeArguments == null)
1483 Report.Error (80, lexer.Location,
1484 "Contraints are not allowed on non-generic declarations");
1486 GenericMethod generic = null;
1487 if (name.TypeArguments != null) {
1488 generic = new GenericMethod (current_namespace, current_class,
1489 name, lexer.Location);
1491 generic.SetParameterInfo ((ArrayList) $9);
1494 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1495 true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
1499 interface_property_declaration
1504 { lexer.PropertyParsing = true; }
1506 { lexer.PropertyParsing = false; }
1509 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1511 $$ = new Property (current_class, (Expression) $3, (int) $2, true,
1512 new MemberName ((string) $4), (Attributes) $1,
1513 pinfo.Get, pinfo.Set, lexer.Location);
1518 CheckIdentifierToken (yyToken);
1524 : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, lexer.Location, lexer.Location); }
1525 | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1, lexer.Location, lexer.Location); }
1526 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1527 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3, lexer.Location, lexer.Location); }
1528 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1529 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1, lexer.Location, lexer.Location); }
1532 interface_event_declaration
1533 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1535 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1536 new MemberName ((string) $5), null,
1537 (Attributes) $1, lexer.Location);
1539 | opt_attributes opt_new EVENT type error {
1540 CheckIdentifierToken (yyToken);
1543 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1544 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1547 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1548 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1553 interface_indexer_declaration
1554 : opt_attributes opt_new type THIS
1555 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1557 { lexer.PropertyParsing = true; }
1559 { lexer.PropertyParsing = false; }
1562 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1564 $$ = new Indexer (current_class, (Expression) $3,
1565 new MemberName (TypeContainer.DefaultIndexerName),
1566 (int) $2, true, (Parameters) $6, (Attributes) $1,
1567 info.Get, info.Set, lexer.Location);
1571 operator_declaration
1572 : opt_attributes opt_modifiers operator_declarator
1574 iterator_container = SimpleIteratorContainer.GetSimple ();
1578 OperatorDeclaration decl = (OperatorDeclaration) $3;
1580 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
1582 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null);
1583 if (decl.arg2type != null)
1584 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null);
1586 Operator op = new Operator (
1587 current_class, decl.optype, decl.ret_type, (int) $2,
1588 new Parameters (param_list, null, decl.location),
1589 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1591 if (SimpleIteratorContainer.Simple.Yields)
1594 // Note again, checking is done in semantic analysis
1595 current_container.AddOperator (op);
1597 current_local_parameters = null;
1598 iterator_container = null;
1604 | SEMICOLON { $$ = null; }
1607 : type OPERATOR overloadable_operator
1608 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1610 Operator.OpType op = (Operator.OpType) $3;
1611 CheckUnaryOperator (op);
1613 if (op == Operator.OpType.Addition)
1614 op = Operator.OpType.UnaryPlus;
1616 if (op == Operator.OpType.Subtraction)
1617 op = Operator.OpType.UnaryNegation;
1619 Parameter [] pars = new Parameter [1];
1621 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1623 current_local_parameters = new Parameters (pars, null, lexer.Location);
1625 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1626 null, null, lexer.Location);
1628 | type OPERATOR overloadable_operator
1630 type IDENTIFIER COMMA
1634 CheckBinaryOperator ((Operator.OpType) $3);
1636 Parameter [] pars = new Parameter [2];
1638 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1639 pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1641 current_local_parameters = new Parameters (pars, null, lexer.Location);
1643 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1644 (Expression) $5, (string) $6,
1645 (Expression) $8, (string) $9, lexer.Location);
1647 | conversion_operator_declarator
1650 overloadable_operator
1652 : BANG { $$ = Operator.OpType.LogicalNot; }
1653 | TILDE { $$ = Operator.OpType.OnesComplement; }
1654 | OP_INC { $$ = Operator.OpType.Increment; }
1655 | OP_DEC { $$ = Operator.OpType.Decrement; }
1656 | TRUE { $$ = Operator.OpType.True; }
1657 | FALSE { $$ = Operator.OpType.False; }
1658 // Unary and binary:
1659 | PLUS { $$ = Operator.OpType.Addition; }
1660 | MINUS { $$ = Operator.OpType.Subtraction; }
1662 | STAR { $$ = Operator.OpType.Multiply; }
1663 | DIV { $$ = Operator.OpType.Division; }
1664 | PERCENT { $$ = Operator.OpType.Modulus; }
1665 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1666 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1667 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1668 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1669 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1670 | OP_EQ { $$ = Operator.OpType.Equality; }
1671 | OP_NE { $$ = Operator.OpType.Inequality; }
1672 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1673 | OP_LT { $$ = Operator.OpType.LessThan; }
1674 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1675 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1678 conversion_operator_declarator
1679 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1681 Parameter [] pars = new Parameter [1];
1683 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1685 current_local_parameters = new Parameters (pars, null, lexer.Location);
1687 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1688 null, null, lexer.Location);
1690 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1692 Parameter [] pars = new Parameter [1];
1694 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1696 current_local_parameters = new Parameters (pars, null, lexer.Location);
1698 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1699 null, null, lexer.Location);
1703 syntax_error (lexer.Location, "'operator' expected");
1707 syntax_error (lexer.Location, "'operator' expected");
1711 constructor_declaration
1714 constructor_declarator
1717 Constructor c = (Constructor) $3;
1718 c.Block = (ToplevelBlock) $4;
1719 c.OptAttributes = (Attributes) $1;
1720 c.ModFlags = (int) $2;
1722 if (c.Name == current_container.Basename){
1723 if ((c.ModFlags & Modifiers.STATIC) != 0){
1724 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1726 515, c.Location, String.Format (
1727 "`{0}.{1}': static constructor can not have access modifiers",
1728 c.Name, current_container.Name));
1731 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1733 if (c.Initializer != null){
1736 "Static constructors can not have an explicit this or base " +
1737 "constructor invocations");
1740 if (!c.Parameters.Empty){
1742 132, c.Location, "Static constructors should not have parameters");
1745 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1748 // We let another layer check the validity of the constructor.
1749 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1752 current_container.AddConstructor (c);
1754 current_local_parameters = null;
1758 constructor_declarator
1760 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1762 oob_stack.Push (lexer.Location);
1764 current_local_parameters = (Parameters) $3;
1766 opt_constructor_initializer
1768 Location l = (Location) oob_stack.Pop ();
1769 $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $3,
1770 (ConstructorInitializer) $6, l);
1776 | SEMICOLON { $$ = null; }
1779 opt_constructor_initializer
1780 : /* empty */ { $$ = null; }
1781 | constructor_initializer
1784 constructor_initializer
1785 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1787 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1789 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1791 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1794 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1800 : /* EMPTY */ { $$ = 0; }
1801 | UNSAFE { $$ = Modifiers.UNSAFE; }
1802 | EXTERN { $$ = Modifiers.EXTERN; }
1805 destructor_declaration
1806 : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1808 if ((string) $4 != current_container.Basename){
1809 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1810 } else if (!(current_container is Class)){
1811 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1813 Location l = lexer.Location;
1816 if (!RootContext.StdLib && current_container.Name == "System.Object")
1817 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1819 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1821 if ((m & Modifiers.UNSAFE) != 0){
1822 if (!RootContext.Unsafe){
1823 Report.Error (227, l,
1824 "Unsafe code requires the -unsafe command " +
1825 "line option to be specified");
1829 Method d = new Destructor (
1830 current_class, TypeManager.system_void_expr, m, "Finalize",
1831 new Parameters (null, null, l), (Attributes) $1, l);
1833 d.Block = (ToplevelBlock) $7;
1834 current_container.AddMethod (d);
1842 EVENT type variable_declarators SEMICOLON
1844 foreach (VariableDeclaration var in (ArrayList) $5) {
1846 MemberName name = new MemberName (var.identifier);
1848 Event e = new EventField (
1849 current_class, (Expression) $4, (int) $2, false, name,
1850 var.expression_or_array_initializer, (Attributes) $1,
1853 current_container.AddEvent (e);
1859 EVENT type namespace_or_type_name
1862 implicit_value_parameter_type = (Expression) $4;
1863 lexer.EventParsing = true;
1864 oob_stack.Push (lexer.Location);
1866 event_accessor_declarations
1868 lexer.EventParsing = false;
1872 Location loc = (Location) oob_stack.Pop ();
1875 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1878 Pair pair = (Pair) $8;
1880 MemberName name = (MemberName) $5;
1882 if (name.TypeArguments != null)
1883 syntax_error (lexer.Location, "an event can't have type arguments");
1885 Event e = new EventProperty (
1886 current_class, (Expression) $4, (int) $2, false, name, null,
1887 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
1890 current_container.AddEvent (e);
1891 implicit_value_parameter_type = null;
1894 | opt_attributes opt_modifiers EVENT type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
1895 MemberName mn = (MemberName) $5;
1897 if (mn.Left != null)
1898 Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
1900 Report.Error (71, lexer.Location, "Event declaration should use property syntax");
1904 event_accessor_declarations
1905 : add_accessor_declaration remove_accessor_declaration
1907 $$ = new Pair ($1, $2);
1909 | remove_accessor_declaration add_accessor_declaration
1911 $$ = new Pair ($2, $1);
1913 | add_accessor_declaration { $$ = null; }
1914 | remove_accessor_declaration { $$ = null; }
1917 Report.Error (1055, lexer.Location, "An add or remove accessor expected");
1923 add_accessor_declaration
1924 : opt_attributes ADD
1926 Parameter [] args = new Parameter [1];
1927 Parameter implicit_value_parameter = new Parameter (
1928 implicit_value_parameter_type, "value",
1929 Parameter.Modifier.NONE, null);
1931 args [0] = implicit_value_parameter;
1933 current_local_parameters = new Parameters (args, null, lexer.Location);
1934 lexer.EventParsing = false;
1938 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
1939 lexer.EventParsing = true;
1941 | opt_attributes ADD error {
1942 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1947 remove_accessor_declaration
1948 : opt_attributes REMOVE
1950 Parameter [] args = new Parameter [1];
1951 Parameter implicit_value_parameter = new Parameter (
1952 implicit_value_parameter_type, "value",
1953 Parameter.Modifier.NONE, null);
1955 args [0] = implicit_value_parameter;
1957 current_local_parameters = new Parameters (args, null, lexer.Location);
1958 lexer.EventParsing = false;
1962 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
1963 lexer.EventParsing = true;
1965 | opt_attributes REMOVE error {
1966 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1972 : opt_attributes opt_modifiers indexer_declarator
1975 IndexerDeclaration decl = (IndexerDeclaration) $3;
1977 implicit_value_parameter_type = decl.type;
1979 lexer.PropertyParsing = true;
1980 parsing_indexer = true;
1982 indexer_parameters = decl.param_list;
1983 oob_stack.Push (lexer.Location);
1985 accessor_declarations
1987 lexer.PropertyParsing = false;
1988 parsing_indexer = false;
1992 // The signature is computed from the signature of the indexer. Look
1993 // at section 3.6 on the spec
1994 Location loc = (Location) oob_stack.Pop ();
1996 IndexerDeclaration decl = (IndexerDeclaration) $3;
1997 Pair pair = (Pair) $6;
1998 Accessor get_block = (Accessor) pair.First;
1999 Accessor set_block = (Accessor) pair.Second;
2002 if (decl.interface_type != null)
2003 name = new MemberName (decl.interface_type,
2004 TypeContainer.DefaultIndexerName, null);
2006 name = new MemberName (TypeContainer.DefaultIndexerName);
2008 indexer = new Indexer (current_class, decl.type, name,
2009 (int) $2, false, decl.param_list, (Attributes) $1,
2010 get_block, set_block, loc);
2012 current_container.AddIndexer (indexer);
2014 current_local_parameters = null;
2015 implicit_value_parameter_type = null;
2016 indexer_parameters = null;
2021 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2023 Parameters pars = (Parameters) $4;
2024 if (pars.HasArglist) {
2025 // "__arglist is not valid in this context"
2026 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2027 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2028 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2031 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
2033 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2035 Parameters pars = (Parameters) $6;
2037 if (pars.HasArglist) {
2038 // "__arglist is not valid in this context"
2039 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2040 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2041 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2043 MemberName name = (MemberName) $2;
2044 if (name.TypeArguments != null)
2045 syntax_error (lexer.Location, "an indexer can't have type arguments");
2047 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
2059 Location enum_location = lexer.Location;
2061 MemberName full_name = MakeName (new MemberName ((string) $4));
2062 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
2063 full_name, (Attributes) $1, enum_location);
2065 foreach (VariableDeclaration ev in (ArrayList) $6) {
2066 e.AddEnumMember (ev.identifier,
2067 (Expression) ev.expression_or_array_initializer,
2068 ev.Location, ev.OptAttributes);
2071 string name = full_name.GetName ();
2072 current_container.AddEnum (e);
2073 RootContext.Tree.RecordDecl (name, e);
2079 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2080 | COLON type { $$ = $2; }
2084 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
2090 opt_enum_member_declarations
2091 : /* empty */ { $$ = new ArrayList (4); }
2092 | enum_member_declarations opt_comma { $$ = $1; }
2095 enum_member_declarations
2096 : enum_member_declaration
2098 ArrayList l = new ArrayList (4);
2103 | enum_member_declarations COMMA enum_member_declaration
2105 ArrayList l = (ArrayList) $1;
2113 enum_member_declaration
2114 : opt_attributes IDENTIFIER
2116 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
2118 | opt_attributes IDENTIFIER
2120 $$ = lexer.Location;
2124 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
2128 delegate_declaration
2131 DELEGATE type member_name
2132 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2134 Location l = lexer.Location;
2135 MemberName name = MakeName ((MemberName) $5);
2136 Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
2137 (int) $2, name, (Parameters) $7, (Attributes) $1, l);
2139 current_container.AddDelegate (del);
2140 RootContext.Tree.RecordDecl (name.GetName (true), del);
2142 current_delegate = del;
2144 lexer.ConstraintsParsing = true;
2146 opt_type_parameter_constraints_clauses
2148 lexer.ConstraintsParsing = false;
2152 current_delegate.SetParameterInfo ((ArrayList) $9);
2154 current_delegate = null;
2158 DELEGATE VOID member_name
2159 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2161 Location l = lexer.Location;
2162 MemberName name = MakeName ((MemberName) $5);
2163 Delegate del = new Delegate (
2164 current_namespace, current_container,
2165 TypeManager.system_void_expr, (int) $2, name,
2166 (Parameters) $7, (Attributes) $1, l);
2168 current_container.AddDelegate (del);
2169 RootContext.Tree.RecordDecl (name.GetName (true), del);
2171 current_delegate = del;
2173 lexer.ConstraintsParsing = true;
2175 opt_type_parameter_constraints_clauses
2177 lexer.ConstraintsParsing = false;
2181 current_delegate.SetParameterInfo ((ArrayList) $9);
2183 current_delegate = null;
2187 namespace_or_type_name
2189 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2190 $$ = new MemberName ((MemberName) $1, (string) $3, (TypeArguments) $4);
2195 : IDENTIFIER opt_type_argument_list {
2196 $$ = new MemberName ((string) $1, (TypeArguments) $2);
2200 opt_type_argument_list
2201 : /* empty */ { $$ = null; }
2202 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2208 $$ = new TypeArguments ((int) $1, lexer.Location);
2214 TypeArguments type_args = new TypeArguments (lexer.Location);
2215 type_args.Add ((Expression) $1);
2218 | type_arguments COMMA type {
2219 TypeArguments type_args = (TypeArguments) $1;
2220 type_args.Add ((Expression) $3);
2226 * Before you think of adding a return_type, notice that we have been
2227 * using two rules in the places where it matters (one rule using type
2228 * and another identical one that uses VOID as the return type). This
2229 * gets rid of a shift/reduce couple
2232 : namespace_or_type_name
2234 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2246 // Note that here only unmanaged types are allowed but we
2247 // can't perform checks during this phase - we do it during
2248 // semantic analysis.
2250 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2254 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2260 | non_expression_type rank_specifier
2262 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2264 | non_expression_type STAR
2266 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2268 | expression rank_specifiers
2270 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2274 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2278 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2279 // through this different path
2281 | multiplicative_expression STAR
2283 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2290 ArrayList types = new ArrayList (4);
2295 | type_list COMMA type
2297 ArrayList types = (ArrayList) $1;
2305 * replaces all the productions for isolating the various
2306 * simple types, but we need this to reuse it easily in local_variable_type
2309 : OBJECT { $$ = TypeManager.system_object_expr; }
2310 | STRING { $$ = TypeManager.system_string_expr; }
2311 | BOOL { $$ = TypeManager.system_boolean_expr; }
2312 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2313 | FLOAT { $$ = TypeManager.system_single_expr; }
2314 | DOUBLE { $$ = TypeManager.system_double_expr; }
2319 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2320 | BYTE { $$ = TypeManager.system_byte_expr; }
2321 | SHORT { $$ = TypeManager.system_int16_expr; }
2322 | USHORT { $$ = TypeManager.system_uint16_expr; }
2323 | INT { $$ = TypeManager.system_int32_expr; }
2324 | UINT { $$ = TypeManager.system_uint32_expr; }
2325 | LONG { $$ = TypeManager.system_int64_expr; }
2326 | ULONG { $$ = TypeManager.system_uint64_expr; }
2327 | CHAR { $$ = TypeManager.system_char_expr; }
2328 | VOID { $$ = TypeManager.system_void_expr; }
2332 : type rank_specifiers
2334 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2339 // Expressions, section 7.5
2349 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2351 | parenthesized_expression
2352 | default_value_expression
2354 | invocation_expression
2358 | post_increment_expression
2359 | post_decrement_expression
2363 | checked_expression
2364 | unchecked_expression
2365 | pointer_member_access
2366 | anonymous_method_expression
2373 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2374 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2375 | NULL { $$ = NullLiteral.Null; }
2379 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2380 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2381 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2386 object v = lexer.Value;
2392 $$ = IntLiteral.Zero;
2394 $$ = IntLiteral.One;
2396 $$ = new IntLiteral (i);
2397 } else if (v is uint)
2398 $$ = new UIntLiteral ((UInt32) v);
2400 $$ = new LongLiteral ((Int64) v);
2401 else if (v is ulong)
2402 $$ = new ULongLiteral ((UInt64) v);
2404 Console.WriteLine ("OOPS. Unexpected result from scanner");
2409 : TRUE { $$ = new BoolLiteral (true); }
2410 | FALSE { $$ = new BoolLiteral (false); }
2413 parenthesized_expression_0
2414 : OPEN_PARENS expression CLOSE_PARENS
2417 lexer.Deambiguate_CloseParens ();
2418 // After this, the next token returned is one of
2419 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2420 // or CLOSE_PARENS_MINUS.
2424 parenthesized_expression
2425 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2429 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2431 // If a parenthesized expression is followed by a minus, we need to wrap
2432 // the expression inside a ParenthesizedExpression for the CS0075 check
2433 // in Binary.DoResolve().
2434 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2439 : primary_expression DOT IDENTIFIER opt_type_argument_list
2441 $$ = new MemberAccess ((Expression) $1, (string) $3,
2442 (TypeArguments) $4, lexer.Location);
2444 | predefined_type DOT IDENTIFIER opt_type_argument_list
2446 $$ = new MemberAccess ((Expression) $1, (string) $3,
2447 (TypeArguments) $4, lexer.Location);
2455 invocation_expression
2456 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2459 Location l = lexer.Location;
2460 Report.Error (1, l, "Parse error");
2462 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2464 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2466 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2468 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2470 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2475 : /* empty */ { $$ = null; }
2482 ArrayList list = new ArrayList (4);
2486 | argument_list COMMA argument
2488 ArrayList list = (ArrayList) $1;
2492 | argument_list error {
2493 CheckToken (1026, yyToken, ", or ) expected");
2500 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2502 | REF variable_reference
2504 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2506 | OUT variable_reference
2508 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2510 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
2512 ArrayList list = (ArrayList) $3;
2513 Argument[] args = new Argument [list.Count];
2514 list.CopyTo (args, 0);
2516 Expression expr = new Arglist (args, lexer.Location);
2517 $$ = new Argument (expr, Argument.AType.Expression);
2521 $$ = new Argument (new ArglistAccess (lexer.Location), Argument.AType.ArgList);
2526 : expression { note ("section 5.4"); $$ = $1; }
2530 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2532 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2534 | primary_expression rank_specifiers
2536 // So the super-trick is that primary_expression
2537 // can only be either a SimpleName or a MemberAccess.
2538 // The MemberAccess case arises when you have a fully qualified type-name like :
2540 // SimpleName is when you have
2543 Expression expr = (Expression) $1;
2544 if (expr is ComposedCast){
2545 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2546 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2547 Error_ExpectingTypeName (lexer.Location, expr);
2548 $$ = TypeManager.system_object_expr;
2551 // So we extract the string corresponding to the SimpleName
2554 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2562 ArrayList list = new ArrayList (4);
2566 | expression_list COMMA expression
2568 ArrayList list = (ArrayList) $1;
2577 $$ = new This (current_block, lexer.Location);
2582 : BASE DOT IDENTIFIER
2584 $$ = new BaseAccess ((string) $3, lexer.Location);
2586 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2588 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2591 Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
2596 post_increment_expression
2597 : primary_expression OP_INC
2599 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2600 (Expression) $1, lexer.Location);
2604 post_decrement_expression
2605 : primary_expression OP_DEC
2607 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2608 (Expression) $1, lexer.Location);
2613 : object_or_delegate_creation_expression
2614 | array_creation_expression
2617 object_or_delegate_creation_expression
2618 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2620 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2624 array_creation_expression
2625 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2627 opt_array_initializer
2629 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2631 | NEW type rank_specifiers array_initializer
2633 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2637 Report.Error (1031, lexer.Location, "Type expected");
2642 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2658 : rank_specifier opt_rank_specifier
2660 $$ = (string) $2 + (string) $1;
2665 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2667 $$ = "[" + (string) $2 + "]";
2687 | dim_separators COMMA
2689 $$ = (string) $1 + ",";
2693 opt_array_initializer
2705 : OPEN_BRACE CLOSE_BRACE
2707 ArrayList list = new ArrayList (4);
2710 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2712 $$ = (ArrayList) $2;
2716 variable_initializer_list
2717 : variable_initializer
2719 ArrayList list = new ArrayList (4);
2723 | variable_initializer_list COMMA variable_initializer
2725 ArrayList list = (ArrayList) $1;
2732 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2734 $$ = new TypeOfVoid (lexer.Location);
2736 | TYPEOF OPEN_PARENS
2738 lexer.TypeOfParsing = true;
2742 lexer.TypeOfParsing = false;
2743 $$ = new TypeOf ((Expression) $4, lexer.Location);
2748 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2749 $$ = new SizeOf ((Expression) $3, lexer.Location);
2754 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2756 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2760 unchecked_expression
2761 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2763 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2767 pointer_member_access
2768 : primary_expression OP_PTR IDENTIFIER
2772 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2773 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2777 anonymous_method_expression
2778 : DELEGATE opt_anonymous_method_signature {
2779 oob_stack.Push (current_local_parameters);
2780 current_local_parameters = (Parameters)$2;
2782 // Force the next block to be created as a ToplevelBlock
2783 oob_stack.Push (current_block);
2784 oob_stack.Push (top_current_block);
2785 oob_stack.Push (lexer.Location);
2786 current_block = null;
2788 Location loc = (Location) oob_stack.Pop ();
2789 top_current_block = (Block) oob_stack.Pop ();
2790 current_block = (Block) oob_stack.Pop ();
2791 if (RootContext.Version == LanguageVersion.ISO_1){
2792 Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
2795 ToplevelBlock anon_block = (ToplevelBlock) $4;
2797 anon_block.Parent = current_block;
2798 $$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block,
2801 current_local_parameters = (Parameters) oob_stack.Pop ();
2805 opt_anonymous_method_signature
2806 : /* empty */ { $$ = null; }
2807 | anonymous_method_signature
2810 anonymous_method_signature
2811 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2814 $$ = Parameters.EmptyReadOnlyParameters;
2816 ArrayList par_list = (ArrayList) $2;
2817 Parameter [] pars = new Parameter [par_list.Count];
2818 par_list.CopyTo (pars);
2819 $$ = new Parameters (pars, null, lexer.Location);
2824 opt_anonymous_method_parameter_list
2825 : /* empty */ { $$ = null; }
2826 | anonymous_method_parameter_list { $$ = $1; }
2829 anonymous_method_parameter_list
2830 : anonymous_method_parameter
2832 ArrayList a = new ArrayList (4);
2836 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2838 ArrayList a = (ArrayList) $1;
2844 anonymous_method_parameter
2845 : opt_parameter_modifier type IDENTIFIER {
2846 $$ = new Parameter ((Expression) $2, (string) $3, (Parameter.Modifier) $1, null);
2848 | PARAMS type IDENTIFIER {
2849 Report.Error (-221, lexer.Location, "params modifier not allowed in anonymous method declaration");
2854 default_value_expression
2855 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
2857 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
2862 : primary_expression
2863 | BANG prefixed_unary_expression
2865 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2867 | TILDE prefixed_unary_expression
2869 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2875 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2877 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2879 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2881 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2887 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2889 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2894 // The idea to split this out is from Rhys' grammar
2895 // to solve the problem with casts.
2897 prefixed_unary_expression
2899 | PLUS prefixed_unary_expression
2901 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2903 | MINUS prefixed_unary_expression
2905 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2907 | OP_INC prefixed_unary_expression
2909 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2910 (Expression) $2, lexer.Location);
2912 | OP_DEC prefixed_unary_expression
2914 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2915 (Expression) $2, lexer.Location);
2917 | STAR prefixed_unary_expression
2919 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2921 | BITWISE_AND prefixed_unary_expression
2923 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2927 pre_increment_expression
2928 : OP_INC prefixed_unary_expression
2930 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2931 (Expression) $2, lexer.Location);
2935 pre_decrement_expression
2936 : OP_DEC prefixed_unary_expression
2938 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2939 (Expression) $2, lexer.Location);
2943 multiplicative_expression
2944 : prefixed_unary_expression
2945 | multiplicative_expression STAR prefixed_unary_expression
2947 $$ = new Binary (Binary.Operator.Multiply,
2948 (Expression) $1, (Expression) $3, lexer.Location);
2950 | multiplicative_expression DIV prefixed_unary_expression
2952 $$ = new Binary (Binary.Operator.Division,
2953 (Expression) $1, (Expression) $3, lexer.Location);
2955 | multiplicative_expression PERCENT prefixed_unary_expression
2957 $$ = new Binary (Binary.Operator.Modulus,
2958 (Expression) $1, (Expression) $3, lexer.Location);
2963 : multiplicative_expression
2964 | additive_expression PLUS multiplicative_expression
2966 $$ = new Binary (Binary.Operator.Addition,
2967 (Expression) $1, (Expression) $3, lexer.Location);
2969 | additive_expression MINUS multiplicative_expression
2971 $$ = new Binary (Binary.Operator.Subtraction,
2972 (Expression) $1, (Expression) $3, lexer.Location);
2977 : additive_expression
2978 | shift_expression OP_SHIFT_LEFT additive_expression
2980 $$ = new Binary (Binary.Operator.LeftShift,
2981 (Expression) $1, (Expression) $3, lexer.Location);
2983 | shift_expression OP_SHIFT_RIGHT additive_expression
2985 $$ = new Binary (Binary.Operator.RightShift,
2986 (Expression) $1, (Expression) $3, lexer.Location);
2990 relational_expression
2992 | relational_expression OP_LT shift_expression
2994 $$ = new Binary (Binary.Operator.LessThan,
2995 (Expression) $1, (Expression) $3, lexer.Location);
2997 | relational_expression OP_GT shift_expression
2999 $$ = new Binary (Binary.Operator.GreaterThan,
3000 (Expression) $1, (Expression) $3, lexer.Location);
3002 | relational_expression OP_LE shift_expression
3004 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3005 (Expression) $1, (Expression) $3, lexer.Location);
3007 | relational_expression OP_GE shift_expression
3009 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3010 (Expression) $1, (Expression) $3, lexer.Location);
3012 | relational_expression IS type
3014 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
3016 | relational_expression AS type
3018 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
3023 : relational_expression
3024 | equality_expression OP_EQ relational_expression
3026 $$ = new Binary (Binary.Operator.Equality,
3027 (Expression) $1, (Expression) $3, lexer.Location);
3029 | equality_expression OP_NE relational_expression
3031 $$ = new Binary (Binary.Operator.Inequality,
3032 (Expression) $1, (Expression) $3, lexer.Location);
3037 : equality_expression
3038 | and_expression BITWISE_AND equality_expression
3040 $$ = new Binary (Binary.Operator.BitwiseAnd,
3041 (Expression) $1, (Expression) $3, lexer.Location);
3045 exclusive_or_expression
3047 | exclusive_or_expression CARRET and_expression
3049 $$ = new Binary (Binary.Operator.ExclusiveOr,
3050 (Expression) $1, (Expression) $3, lexer.Location);
3054 inclusive_or_expression
3055 : exclusive_or_expression
3056 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3058 $$ = new Binary (Binary.Operator.BitwiseOr,
3059 (Expression) $1, (Expression) $3, lexer.Location);
3063 conditional_and_expression
3064 : inclusive_or_expression
3065 | conditional_and_expression OP_AND inclusive_or_expression
3067 $$ = new Binary (Binary.Operator.LogicalAnd,
3068 (Expression) $1, (Expression) $3, lexer.Location);
3072 conditional_or_expression
3073 : conditional_and_expression
3074 | conditional_or_expression OP_OR conditional_and_expression
3076 $$ = new Binary (Binary.Operator.LogicalOr,
3077 (Expression) $1, (Expression) $3, lexer.Location);
3081 conditional_expression
3082 : conditional_or_expression
3083 | conditional_or_expression INTERR expression COLON expression
3085 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
3089 assignment_expression
3090 : prefixed_unary_expression ASSIGN expression
3092 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
3094 | prefixed_unary_expression OP_MULT_ASSIGN expression
3096 Location l = lexer.Location;
3098 $$ = new CompoundAssign (
3099 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
3101 | prefixed_unary_expression OP_DIV_ASSIGN expression
3103 Location l = lexer.Location;
3105 $$ = new CompoundAssign (
3106 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
3108 | prefixed_unary_expression OP_MOD_ASSIGN expression
3110 Location l = lexer.Location;
3112 $$ = new CompoundAssign (
3113 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
3115 | prefixed_unary_expression OP_ADD_ASSIGN expression
3117 Location l = lexer.Location;
3119 $$ = new CompoundAssign (
3120 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
3122 | prefixed_unary_expression OP_SUB_ASSIGN expression
3124 Location l = lexer.Location;
3126 $$ = new CompoundAssign (
3127 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
3129 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3131 Location l = lexer.Location;
3133 $$ = new CompoundAssign (
3134 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
3136 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3138 Location l = lexer.Location;
3140 $$ = new CompoundAssign (
3141 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
3143 | prefixed_unary_expression OP_AND_ASSIGN expression
3145 Location l = lexer.Location;
3147 $$ = new CompoundAssign (
3148 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
3150 | prefixed_unary_expression OP_OR_ASSIGN expression
3152 Location l = lexer.Location;
3154 $$ = new CompoundAssign (
3155 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
3157 | prefixed_unary_expression OP_XOR_ASSIGN expression
3159 Location l = lexer.Location;
3161 $$ = new CompoundAssign (
3162 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
3167 : conditional_expression
3168 | assignment_expression
3188 MemberName name = MakeName ((MemberName) $5);
3189 bool partial = (bool) $3;
3190 int mod_flags = (int) $2;
3193 ClassPart part = PartialContainer.CreatePart (
3194 current_namespace, current_container, name, mod_flags,
3195 (Attributes) $1, Kind.Class, lexer.Location);
3197 current_container = part.PartialContainer;
3198 current_class = part;
3200 if ((mod_flags & Modifiers.STATIC) != 0) {
3201 current_class = new StaticClass (
3202 current_namespace, current_container, name,
3203 mod_flags, (Attributes) $1, lexer.Location);
3205 current_class = new Class (
3206 current_namespace, current_container, name,
3207 mod_flags, (Attributes) $1, lexer.Location);
3210 current_container = current_class;
3211 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
3214 lexer.ConstraintsParsing = true;
3217 opt_type_parameter_constraints_clauses
3219 lexer.ConstraintsParsing = false;
3222 if (current_class.Name == "System.Object") {
3223 Report.Error (537, current_class.Location,
3224 "The class System.Object cannot have a base " +
3225 "class or implement an interface.");
3227 current_class.Bases = (ArrayList) $7;
3230 current_class.SetParameterInfo ((ArrayList) $8);
3232 current_class.Register ();
3239 current_container = current_container.Parent;
3240 current_class = current_container;
3246 { $$ = (bool) false; }
3248 { $$ = (bool) true; }
3252 : /* empty */ { $$ = (int) 0; }
3258 | modifiers modifier
3263 if ((m1 & m2) != 0) {
3264 Location l = lexer.Location;
3265 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3267 $$ = (int) (m1 | m2);
3272 : NEW { $$ = Modifiers.NEW; }
3273 | PUBLIC { $$ = Modifiers.PUBLIC; }
3274 | PROTECTED { $$ = Modifiers.PROTECTED; }
3275 | INTERNAL { $$ = Modifiers.INTERNAL; }
3276 | PRIVATE { $$ = Modifiers.PRIVATE; }
3277 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3278 | SEALED { $$ = Modifiers.SEALED; }
3279 | STATIC { $$ = Modifiers.STATIC; }
3280 | READONLY { $$ = Modifiers.READONLY; }
3281 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3282 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3283 | EXTERN { $$ = Modifiers.EXTERN; }
3284 | VOLATILE { $$ = Modifiers.VOLATILE; }
3285 | UNSAFE { $$ = Modifiers.UNSAFE; }
3289 : /* empty */ { $$ = null; }
3290 | class_base { $$ = $1; }
3294 : COLON type_list { $$ = $2; }
3297 opt_type_parameter_constraints_clauses
3298 : /* empty */ { $$ = null; }
3299 | type_parameter_constraints_clauses
3303 type_parameter_constraints_clauses
3304 : type_parameter_constraints_clause {
3305 ArrayList constraints = new ArrayList (1);
3306 constraints.Add ($1);
3309 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3310 ArrayList constraints = (ArrayList) $1;
3312 constraints.Add ($2);
3317 type_parameter_constraints_clause
3318 : WHERE IDENTIFIER COLON type_parameter_constraints {
3319 $$ = new Constraints ((string) $2, (ArrayList) $4, lexer.Location);
3323 type_parameter_constraints
3324 : type_parameter_constraint {
3325 ArrayList constraints = new ArrayList (1);
3326 constraints.Add ($1);
3329 | type_parameter_constraints COMMA type_parameter_constraint {
3330 ArrayList constraints = (ArrayList) $1;
3332 constraints.Add ($3);
3337 type_parameter_constraint
3339 | NEW OPEN_PARENS CLOSE_PARENS {
3340 $$ = SpecialConstraint.Constructor;
3343 $$ = SpecialConstraint.ReferenceType;
3346 $$ = SpecialConstraint.ValueType;
3355 // A block is "contained" on the following places:
3357 // property_declaration as part of the accessor body (get/set)
3358 // operator_declaration
3359 // constructor_declaration
3360 // destructor_declaration
3361 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3366 if (current_block == null){
3367 current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, lexer.Location);
3368 top_current_block = current_block;
3370 current_block = new Block (current_block, current_local_parameters,
3371 lexer.Location, Location.Null);
3374 opt_statement_list CLOSE_BRACE
3376 while (current_block.Implicit)
3377 current_block = current_block.Parent;
3379 current_block.SetEndLocation (lexer.Location);
3380 current_block = current_block.Parent;
3381 if (current_block == null)
3382 top_current_block = null;
3393 | statement_list statement
3397 : declaration_statement
3399 if ($1 != null && (Block) $1 != current_block){
3400 current_block.AddStatement ((Statement) $1);
3401 current_block = (Block) $1;
3404 | valid_declaration_statement
3406 current_block.AddStatement ((Statement) $1);
3411 valid_declaration_statement
3414 | expression_statement
3415 | selection_statement
3416 | iteration_statement
3420 | unchecked_statement
3428 : valid_declaration_statement
3429 | declaration_statement
3431 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
3436 Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
3444 $$ = EmptyStatement.Value;
3451 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3453 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3454 current_block.AddStatement (labeled);
3459 declaration_statement
3460 : local_variable_declaration SEMICOLON
3463 DictionaryEntry de = (DictionaryEntry) $1;
3465 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3469 | local_constant_declaration SEMICOLON
3472 DictionaryEntry de = (DictionaryEntry) $1;
3474 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3480 * The following is from Rhys' grammar:
3481 * > Types in local variable declarations must be recognized as
3482 * > expressions to prevent reduce/reduce errors in the grammar.
3483 * > The expressions are converted into types during semantic analysis.
3486 : primary_expression opt_rank_specifier
3488 // FIXME: Do something smart here regarding the composition of the type.
3490 // Ok, the above "primary_expression" is there to get rid of
3491 // both reduce/reduce and shift/reduces in the grammar, it should
3492 // really just be "type_name". If you use type_name, a reduce/reduce
3493 // creeps up. If you use namespace_or_type_name (which is all we need
3494 // really) two shift/reduces appear.
3497 // So the super-trick is that primary_expression
3498 // can only be either a SimpleName or a MemberAccess.
3499 // The MemberAccess case arises when you have a fully qualified type-name like :
3501 // SimpleName is when you have
3504 Expression expr = (Expression) $1;
3505 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3506 Error_ExpectingTypeName (lexer.Location, expr);
3510 // So we extract the string corresponding to the SimpleName
3514 if ((string) $2 == "")
3517 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3520 | builtin_types opt_rank_specifier
3522 if ((string) $2 == "")
3525 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3529 local_variable_pointer_type
3530 : primary_expression STAR
3532 Expression expr = (Expression) $1;
3533 Location l = lexer.Location;
3535 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3536 Error_ExpectingTypeName (l, expr);
3540 $$ = new ComposedCast ((Expression) $1, "*", l);
3542 | builtin_types STAR
3544 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3548 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3550 | local_variable_pointer_type STAR
3552 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3556 local_variable_declaration
3557 : local_variable_type variable_declarators
3560 $$ = new DictionaryEntry ($1, $2);
3564 | local_variable_pointer_type opt_rank_specifier variable_declarators
3569 if ((string) $2 == "")
3570 t = (Expression) $1;
3572 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3573 $$ = new DictionaryEntry (t, $3);
3579 local_constant_declaration
3580 : CONST local_variable_type constant_declarators
3583 $$ = new DictionaryEntry ($2, $3);
3589 expression_statement
3590 : statement_expression SEMICOLON
3597 // We have to do the wrapping here and not in the case above,
3598 // because statement_expression is used for example in for_statement
3600 statement_expression
3601 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3602 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3603 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3604 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3605 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3606 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3607 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3609 Report.Error (1002, lexer.Location, "Expecting `;'");
3614 object_creation_expression
3615 : object_or_delegate_creation_expression
3616 { note ("complain if this is a delegate maybe?"); }
3625 : if_statement_open if_statement_rest
3634 oob_stack.Push (lexer.Location);
3639 : boolean_expression CLOSE_PARENS
3642 Location l = (Location) oob_stack.Pop ();
3644 $$ = new If ((Expression) $1, (Statement) $3, l);
3646 if (RootContext.WarningLevel >= 3){
3647 if ($3 == EmptyStatement.Value)
3648 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3652 | boolean_expression CLOSE_PARENS
3653 embedded_statement ELSE embedded_statement
3655 Location l = (Location) oob_stack.Pop ();
3657 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3662 : SWITCH OPEN_PARENS
3664 oob_stack.Push (lexer.Location);
3665 switch_stack.Push (current_block);
3667 expression CLOSE_PARENS
3670 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3671 current_block = (Block) switch_stack.Pop ();
3687 Report.Error (1522, lexer.Location, "Empty switch block");
3695 ArrayList sections = new ArrayList (4);
3700 | switch_sections switch_section
3702 ArrayList sections = (ArrayList) $1;
3712 current_block = current_block.CreateSwitchBlock (lexer.Location);
3716 Block topmost = current_block;
3718 while (topmost.Implicit)
3719 topmost = topmost.Parent;
3720 $$ = new SwitchSection ((ArrayList) $1, topmost);
3727 ArrayList labels = new ArrayList (4);
3732 | switch_labels switch_label
3734 ArrayList labels = (ArrayList) ($1);
3742 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3743 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3746 1523, lexer.Location,
3747 "The keyword case or default must precede code in switch block");
3761 oob_stack.Push (lexer.Location);
3763 boolean_expression CLOSE_PARENS embedded_statement
3765 Location l = (Location) oob_stack.Pop ();
3766 $$ = new While ((Expression) $4, (Statement) $6, l);
3768 if (RootContext.WarningLevel >= 3){
3769 if ($6 == EmptyStatement.Value)
3770 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3776 : DO embedded_statement
3778 oob_stack.Push (lexer.Location);
3780 boolean_expression CLOSE_PARENS SEMICOLON
3782 Location l = (Location) oob_stack.Pop ();
3784 $$ = new Do ((Statement) $2, (Expression) $6, l);
3790 opt_for_initializer SEMICOLON
3792 Block assign_block = new Block (current_block);
3793 current_block = assign_block;
3795 if ($3 is DictionaryEntry){
3796 DictionaryEntry de = (DictionaryEntry) $3;
3798 Expression type = (Expression) de.Key;
3799 ArrayList var_declarators = (ArrayList) de.Value;
3801 foreach (VariableDeclaration decl in var_declarators){
3805 vi = current_block.AddVariable (
3806 type, decl.identifier, current_local_parameters, decl.Location);
3810 Location l = lexer.Location;
3812 if (decl.expression_or_array_initializer is Expression){
3813 expr = (Expression) decl.expression_or_array_initializer;
3814 } else if (decl.expression_or_array_initializer == null) {
3817 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3818 expr = new ArrayCreation (type, "", init, decl.Location);
3821 LocalVariableReference var;
3822 var = new LocalVariableReference (assign_block, decl.identifier, l);
3825 Assign a = new Assign (var, expr, decl.Location);
3827 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3833 oob_stack.Push (lexer.Location);
3835 opt_for_condition SEMICOLON
3836 opt_for_iterator CLOSE_PARENS
3839 Location l = (Location) oob_stack.Pop ();
3841 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3843 if (RootContext.WarningLevel >= 3){
3844 if ($10 == EmptyStatement.Value)
3845 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3848 current_block.AddStatement (f);
3849 while (current_block.Implicit)
3850 current_block = current_block.Parent;
3852 current_block = current_block.Parent;
3857 : /* empty */ { $$ = EmptyStatement.Value; }
3862 : local_variable_declaration
3863 | statement_expression_list
3867 : /* empty */ { $$ = null; }
3868 | boolean_expression
3872 : /* empty */ { $$ = EmptyStatement.Value; }
3877 : statement_expression_list
3880 statement_expression_list
3881 : statement_expression
3883 // CHANGE: was `null'
3884 Block b = new Block (current_block, Block.Flags.Implicit);
3886 b.AddStatement ((Statement) $1);
3889 | statement_expression_list COMMA statement_expression
3891 Block b = (Block) $1;
3893 b.AddStatement ((Statement) $3);
3899 : FOREACH OPEN_PARENS type IDENTIFIER IN
3901 oob_stack.Push (lexer.Location);
3903 expression CLOSE_PARENS
3905 oob_stack.Push (current_block);
3907 Block foreach_block = new Block (current_block);
3908 LocalVariableReference v = null;
3909 Location l = lexer.Location;
3912 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3916 // Get a writable reference to this read-only variable.
3917 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3919 current_block = foreach_block;
3922 oob_stack.Push (current_block);
3926 Block foreach_block = (Block) oob_stack.Pop ();
3927 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3928 Block prev_block = (Block) oob_stack.Pop ();
3929 Location l = (Location) oob_stack.Pop ();
3931 current_block = prev_block;
3934 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3935 foreach_block.AddStatement (f);
3944 | continue_statement
3954 $$ = new Break (lexer.Location);
3959 : CONTINUE SEMICOLON
3961 $$ = new Continue (lexer.Location);
3966 : GOTO IDENTIFIER SEMICOLON
3968 $$ = new Goto (current_block, (string) $2, lexer.Location);
3970 | GOTO CASE constant_expression SEMICOLON
3972 $$ = new GotoCase ((Expression) $3, lexer.Location);
3974 | GOTO DEFAULT SEMICOLON
3976 $$ = new GotoDefault (lexer.Location);
3981 : RETURN opt_expression SEMICOLON
3983 $$ = new Return ((Expression) $2, lexer.Location);
3988 : THROW opt_expression SEMICOLON
3990 $$ = new Throw ((Expression) $2, lexer.Location);
3995 : IDENTIFIER RETURN expression SEMICOLON
3997 string s = (string) $1;
3999 Report.Error (1003, lexer.Location, "; expected");
4002 if (RootContext.Version == LanguageVersion.ISO_1){
4003 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
4006 if (iterator_container == null){
4007 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
4010 iterator_container.SetYields ();
4011 $$ = new Yield ((Expression) $3, lexer.Location);
4014 | IDENTIFIER BREAK SEMICOLON
4016 string s = (string) $1;
4018 Report.Error (1003, lexer.Location, "; expected");
4021 if (RootContext.Version == LanguageVersion.ISO_1){
4022 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
4025 if (iterator_container == null){
4026 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
4029 iterator_container.SetYields ();
4030 $$ = new YieldBreak (lexer.Location);
4041 : TRY block catch_clauses
4045 ArrayList c = (ArrayList)$3;
4046 for (int i = 0; i < c.Count; ++i) {
4047 Catch cc = (Catch) c [i];
4049 if (i != c.Count - 1)
4050 Report.Error (1017, cc.loc, "Empty catch block must be the last in a series of catch blocks");
4057 // Now s contains the list of specific catch clauses
4058 // and g contains the general one.
4060 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4062 | TRY block opt_catch_clauses FINALLY block
4065 ArrayList s = new ArrayList (4);
4066 ArrayList catch_list = (ArrayList) $3;
4068 if (catch_list != null){
4069 foreach (Catch cc in catch_list) {
4077 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4081 Report.Error (1524, lexer.Location, "Expected catch or finally");
4086 : /* empty */ { $$ = null; }
4093 ArrayList l = new ArrayList (4);
4098 | catch_clauses catch_clause
4100 ArrayList l = (ArrayList) $1;
4108 : /* empty */ { $$ = null; }
4113 : CATCH opt_catch_args
4115 Expression type = null;
4119 DictionaryEntry cc = (DictionaryEntry) $2;
4120 type = (Expression) cc.Key;
4121 id = (string) cc.Value;
4124 ArrayList one = new ArrayList (4);
4125 Location loc = lexer.Location;
4127 one.Add (new VariableDeclaration (id, null, loc));
4130 current_block = new Block (current_block);
4131 Block b = declare_local_variables (type, one, loc);
4136 Expression type = null;
4140 DictionaryEntry cc = (DictionaryEntry) $2;
4141 type = (Expression) cc.Key;
4142 id = (string) cc.Value;
4146 // FIXME: I can change this for an assignment.
4148 while (current_block != (Block) $1)
4149 current_block = current_block.Parent;
4154 $$ = new Catch (type, id , (Block) $4, ((Block) $4).loc);
4159 : /* empty */ { $$ = null; }
4164 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4166 $$ = new DictionaryEntry ($2, $3);
4173 $$ = new Checked ((Block) $2);
4180 $$ = new Unchecked ((Block) $2);
4187 if (!RootContext.Unsafe){
4188 Report.Error (227, lexer.Location,
4189 "Unsafe code can only be used if --unsafe is used");
4192 $$ = new Unsafe ((Block) $3);
4198 type fixed_pointer_declarators
4201 ArrayList list = (ArrayList) $4;
4202 Expression type = (Expression) $3;
4203 Location l = lexer.Location;
4204 int top = list.Count;
4206 Block assign_block = new Block (current_block);
4207 current_block = assign_block;
4209 for (int i = 0; i < top; i++){
4210 Pair p = (Pair) list [i];
4213 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4227 Location l = (Location) oob_stack.Pop ();
4229 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4231 if (RootContext.WarningLevel >= 3){
4232 if ($7 == EmptyStatement.Value)
4233 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
4236 current_block.AddStatement (f);
4237 while (current_block.Implicit)
4238 current_block = current_block.Parent;
4240 current_block = current_block.Parent;
4244 fixed_pointer_declarators
4245 : fixed_pointer_declarator {
4246 ArrayList declarators = new ArrayList (4);
4248 declarators.Add ($1);
4251 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4253 ArrayList declarators = (ArrayList) $1;
4255 declarators.Add ($3);
4260 fixed_pointer_declarator
4261 : IDENTIFIER ASSIGN expression
4263 $$ = new Pair ($1, $3);
4267 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
4273 : LOCK OPEN_PARENS expression CLOSE_PARENS
4279 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4284 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4286 Block assign_block = new Block (current_block);
4287 current_block = assign_block;
4289 oob_stack.Push (lexer.Location);
4291 if ($3 is DictionaryEntry){
4292 DictionaryEntry de = (DictionaryEntry) $3;
4293 Location l = lexer.Location;
4295 Expression type = (Expression) de.Key;
4296 ArrayList var_declarators = (ArrayList) de.Value;
4298 ArrayList vars = new ArrayList (4);
4300 foreach (VariableDeclaration decl in var_declarators){
4302 LocalInfo vi = current_block.AddVariable (
4303 type, decl.identifier,
4304 current_local_parameters, decl.Location);
4310 if (decl.expression_or_array_initializer is Expression){
4311 expr = (Expression) decl.expression_or_array_initializer;
4313 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4315 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4318 expr = new ArrayCreation (type, "", init, decl.Location);
4321 LocalVariableReference var;
4323 // Get a writable reference to this read-only variable.
4324 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4326 // This is so that it is not a warning on using variables
4329 vars.Add (new DictionaryEntry (var, expr));
4331 // Assign a = new Assign (var, expr, decl.Location);
4332 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4334 $3 = new DictionaryEntry (type, vars);
4339 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4340 current_block.AddStatement (u);
4341 while (current_block.Implicit)
4342 current_block = current_block.Parent;
4344 current_block = current_block.Parent;
4348 resource_acquisition
4349 : local_variable_declaration
4356 // A class used to pass around variable declarations and constants
4358 public class VariableDeclaration {
4359 public string identifier;
4360 public object expression_or_array_initializer;
4361 public Location Location;
4362 public Attributes OptAttributes;
4364 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4366 this.identifier = id;
4367 this.expression_or_array_initializer = eoai;
4369 this.OptAttributes = opt_attrs;
4372 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4378 /// Used to pass around interface property information
4380 public class InterfaceAccessorInfo {
4382 public readonly Accessor Get, Set;
4384 public InterfaceAccessorInfo (bool has_get, bool has_set,
4385 Attributes get_attrs, Attributes set_attrs, Location get_loc, Location set_loc)
4388 Get = new Accessor (null, 0, get_attrs, get_loc);
4390 Set = new Accessor (null, 0, set_attrs, set_loc);
4396 // A class used to hold info about an indexer declarator
4398 public class IndexerDeclaration {
4399 public Expression type;
4400 public MemberName interface_type;
4401 public Parameters param_list;
4403 public IndexerDeclaration (Expression type, MemberName interface_type,
4404 Parameters param_list)
4407 this.interface_type = interface_type;
4408 this.param_list = param_list;
4413 // We use this when we do not have an object in advance that is an IIteratorContainer
4415 public class SimpleIteratorContainer : IIteratorContainer {
4418 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4423 public static SimpleIteratorContainer GetSimple () {
4424 Simple.Yields = false;
4428 public void SetYields () { Yields = true; }
4432 // A class used to hold info about an operator declarator
4434 public class OperatorDeclaration {
4435 public Operator.OpType optype;
4436 public Expression ret_type, arg1type, arg2type;
4437 public string arg1name, arg2name;
4438 public Location location;
4440 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4441 Expression arg1type, string arg1name,
4442 Expression arg2type, string arg2name, Location location)
4445 this.ret_type = ret_type;
4446 this.arg1type = arg1type;
4447 this.arg1name = arg1name;
4448 this.arg2type = arg2type;
4449 this.arg2name = arg2name;
4450 this.location = location;
4455 void Error_ExpectingTypeName (Location l, Expression expr)
4457 if (expr is Invocation){
4458 Report.Error (1002, l, "; expected");
4460 Report.Error (-1, l, "Invalid Type definition");
4465 // Given the @class_name name, it creates a fully qualified name
4466 // based on the containing declaration space
4469 MakeName (MemberName class_name)
4471 string ns = current_namespace.FullName;
4473 if (current_container.Name == ""){
4475 return new MemberName (new MemberName (ns), class_name);
4479 return new MemberName (current_container.MemberName, class_name);
4483 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4485 Block implicit_block;
4486 ArrayList inits = null;
4489 // We use the `Used' property to check whether statements
4490 // have been added to the current block. If so, we need
4491 // to create another block to contain the new declaration
4492 // otherwise, as an optimization, we use the same block to
4493 // add the declaration.
4495 // FIXME: A further optimization is to check if the statements
4496 // that were added were added as part of the initialization
4497 // below. In which case, no other statements have been executed
4498 // and we might be able to reduce the number of blocks for
4499 // situations like this:
4501 // int j = 1; int k = j + 1;
4503 if (current_block.Used)
4504 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4506 implicit_block = current_block;
4508 foreach (VariableDeclaration decl in variable_declarators){
4510 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4511 if (decl.expression_or_array_initializer != null){
4513 inits = new ArrayList (4);
4520 return implicit_block;
4522 foreach (VariableDeclaration decl in inits){
4526 if (decl.expression_or_array_initializer is Expression){
4527 expr = (Expression) decl.expression_or_array_initializer;
4530 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4532 expr = new ArrayCreation (type, "", init, decl.Location);
4535 LocalVariableReference var;
4536 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4538 assign = new Assign (var, expr, decl.Location);
4540 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4543 return implicit_block;
4546 Block declare_local_constants (Expression type, ArrayList declarators)
4548 Block implicit_block;
4550 if (current_block.Used)
4551 implicit_block = new Block (current_block, Block.Flags.Implicit);
4553 implicit_block = current_block;
4555 foreach (VariableDeclaration decl in declarators){
4556 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4557 current_local_parameters, decl.Location);
4560 return implicit_block;
4563 void CheckAttributeTarget (string a)
4567 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4571 Location l = lexer.Location;
4572 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4578 void CheckUnaryOperator (Operator.OpType op)
4582 case Operator.OpType.LogicalNot:
4583 case Operator.OpType.OnesComplement:
4584 case Operator.OpType.Increment:
4585 case Operator.OpType.Decrement:
4586 case Operator.OpType.True:
4587 case Operator.OpType.False:
4588 case Operator.OpType.Addition:
4589 case Operator.OpType.Subtraction:
4594 Location l = lexer.Location;
4595 Report.Error (1019, l, "Overloadable unary operator expected");
4601 void CheckBinaryOperator (Operator.OpType op)
4605 case Operator.OpType.Addition:
4606 case Operator.OpType.Subtraction:
4607 case Operator.OpType.Multiply:
4608 case Operator.OpType.Division:
4609 case Operator.OpType.Modulus:
4610 case Operator.OpType.BitwiseAnd:
4611 case Operator.OpType.BitwiseOr:
4612 case Operator.OpType.ExclusiveOr:
4613 case Operator.OpType.LeftShift:
4614 case Operator.OpType.RightShift:
4615 case Operator.OpType.Equality:
4616 case Operator.OpType.Inequality:
4617 case Operator.OpType.GreaterThan:
4618 case Operator.OpType.LessThan:
4619 case Operator.OpType.GreaterThanOrEqual:
4620 case Operator.OpType.LessThanOrEqual:
4624 Location l = lexer.Location;
4625 Report.Error (1020, l, "Overloadable binary operator expected");
4631 void syntax_error (Location l, string msg)
4633 Report.Error (1003, l, "Syntax error, " + msg);
4636 void output (string s)
4638 Console.WriteLine (s);
4641 void note (string s)
4643 // Used to put annotations
4648 public Tokenizer Lexer {
4654 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4656 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4657 this.name = file.Name;
4659 current_container = RootContext.Tree.Types;
4660 current_container.NamespaceEntry = current_namespace;
4661 oob_stack = new Stack ();
4662 switch_stack = new Stack ();
4664 lexer = new Tokenizer (reader, file, defines);
4667 public void parse ()
4670 if (yacc_verbose_flag > 1)
4671 yyparse (lexer, new yydebug.yyDebugSimple ());
4674 Tokenizer tokenizer = lexer as Tokenizer;
4675 tokenizer.cleanup ();
4676 } catch (Exception e){
4678 // Removed for production use, use parser verbose to get the output.
4680 // Console.WriteLine (e);
4681 Report.Error (-25, lexer.Location, "Parsing error");
4682 if (yacc_verbose_flag > 0)
4683 Console.WriteLine (e);
4687 void CheckToken (int error, int yyToken, string msg)
4689 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4690 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4693 Report.Error (error, lexer.Location, msg);
4696 void CheckIdentifierToken (int yyToken)
4698 CheckToken (1041, yyToken, "Identifier expected");