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;
36 IIteratorContainer iterator_container;
39 /// Current block is used to add statements as we find
46 /// If true, creates a toplevel block in the block production
47 /// This is flagged by the delegate creation
49 bool create_toplevel_block;
53 /// Current interface is used by the various declaration
54 /// productions in the interface declaration to "add"
55 /// the interfaces as we find them.
57 Interface current_interface;
59 Delegate current_delegate;
62 /// This is used by the unary_expression code to resolve
63 /// a name against a parameter.
65 Parameters current_local_parameters;
68 /// Using during property parsing to describe the implicit
69 /// value parameter that is passed to the "set" and "get"accesor
70 /// methods (properties and indexers).
72 Expression implicit_value_parameter_type;
73 Parameters indexer_parameters;
76 /// Used to determine if we are parsing the get/set pair
77 /// of an indexer or a property
82 /// An out-of-band stack.
91 public bool yacc_verbose_flag;
93 // Name of the file we are parsing
102 /// Current attribute target
103 string current_attr_target;
105 /// assembly and module attribute definition is enabled
106 bool global_attrs_enabled = true;
110 %token NONE /* This token is never returned by our lexer */
111 %token ERROR // This is used not by the parser, but by the tokenizer.
115 *These are the C# keywords
200 /* C# keywords which are not really keywords */
206 /* C# single character operators/punctuation. */
207 %token OPEN_BRACE "{"
208 %token CLOSE_BRACE "}"
209 %token OPEN_BRACKET "["
210 %token CLOSE_BRACKET "]"
211 %token OPEN_PARENS "("
212 %token CLOSE_PARENS ")"
224 %token OP_GENERICS_LT "<"
226 %token OP_GENERICS_GT ">"
227 %token BITWISE_AND "&"
228 %token BITWISE_OR "|"
235 /* C# multi-character operators. */
238 %token OP_SHIFT_LEFT "<<"
239 %token OP_SHIFT_RIGHT ">>"
246 %token OP_MULT_ASSIGN "*="
247 %token OP_DIV_ASSIGN "/="
248 %token OP_MOD_ASSIGN "%="
249 %token OP_ADD_ASSIGN "+="
250 %token OP_SUB_ASSIGN "-="
251 %token OP_SHIFT_LEFT_ASSIGN "<<="
252 %token OP_SHIFT_RIGHT_ASSIGN ">>="
253 %token OP_AND_ASSIGN "&="
254 %token OP_XOR_ASSIGN "^="
255 %token OP_OR_ASSIGN "|="
259 %token LITERAL_INTEGER "int literal"
260 %token LITERAL_FLOAT "float literal"
261 %token LITERAL_DOUBLE "double literal"
262 %token LITERAL_DECIMAL "decimal literal"
263 %token LITERAL_CHARACTER "character literal"
264 %token LITERAL_STRING "string literal"
267 %token CLOSE_PARENS_CAST
268 %token CLOSE_PARENS_NO_CAST
269 %token CLOSE_PARENS_OPEN_PARENS
270 %token CLOSE_PARENS_MINUS
271 %token DEFAULT_OPEN_PARENS
273 /* Add precedence rules to solve dangling else s/r conflict */
282 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
284 %left STAR DIV PERCENT
285 %right BANG CARRET UMINUS
286 %nonassoc OP_INC OP_DEC
288 %left OPEN_BRACKET OPEN_BRACE
292 %start compilation_unit
296 : outer_declarations opt_EOF
297 | outer_declarations attribute_sections opt_EOF
298 | attribute_sections opt_EOF
299 | opt_EOF /* allow empty files */
309 | outer_declarations outer_declaration
314 | namespace_member_declaration
319 | using_directives using_directive
323 : using_alias_directive
324 | using_namespace_directive
327 using_alias_directive
328 : USING IDENTIFIER ASSIGN
329 namespace_or_type_name SEMICOLON
331 current_namespace.UsingAlias ((string) $2, (TypeName) $4, lexer.Location);
334 CheckIdentifierToken (yyToken);
338 using_namespace_directive
339 : USING namespace_name SEMICOLON
341 current_namespace.Using ((string) $2, lexer.Location);
346 // Strictly speaking, namespaces don't have attributes but
347 // we parse global attributes along with namespace declarations and then
350 namespace_declaration
351 : opt_attributes NAMESPACE namespace_name
354 Report.Error(1518, Lexer.Location, "Attributes cannot be applied to namespaces."
355 + " Expected class, delegate, enum, interface, or struct");
358 current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, (string) $3, lexer.Location);
360 namespace_body opt_semicolon
362 current_namespace = current_namespace.Parent;
377 : namespace_or_type_name {
378 TypeName name = (TypeName) $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");
470 global_attrs_enabled = false;
475 global_attrs_enabled = false;
484 ArrayList sect = (ArrayList) $1;
486 if (global_attrs_enabled) {
487 if (current_attr_target == "module") {
488 CodeGen.Module.AddAttributes (sect);
490 } else if (current_attr_target == "assembly") {
491 CodeGen.Assembly.AddAttributes (sect);
495 // Because we don't know if target should be on assembly or type
496 // we add it to both. This leads error CS0657 is reported twice
497 // for this case but it is better than mistification.
498 CodeGen.Assembly.AddAttributes (sect);
499 $$ = new Attributes (sect);
502 $$ = new Attributes (sect);
504 current_attr_target = null;
506 | attribute_sections attribute_section
508 Attributes attrs = $1 as Attributes;
509 ArrayList sect = (ArrayList) $2;
511 if (global_attrs_enabled) {
512 if (current_attr_target == "module") {
513 CodeGen.Module.AddAttributes (sect);
515 } else if (current_attr_target == "assembly") {
516 CodeGen.Assembly.AddAttributes (sect);
520 attrs = new Attributes (sect);
522 attrs.AddAttributes (sect);
526 attrs = new Attributes (sect);
528 attrs.AddAttributes (sect);
531 current_attr_target = null;
536 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
540 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
546 attribute_target_specifier
547 : attribute_target COLON
549 current_attr_target = (string)$1;
557 CheckAttributeTarget ((string) $1);
560 | EVENT { $$ = "event"; }
561 | RETURN { $$ = "return"; }
567 ArrayList attrs = new ArrayList (4);
573 | attribute_list COMMA attribute
575 ArrayList attrs = (ArrayList) $1;
587 opt_attribute_arguments
590 // Attributes need a string, not an expression: generic types will fail here.
592 if (current_attr_target == "assembly" || current_attr_target == "module"
593 || (global_attrs_enabled && current_attr_target == null))
594 $$ = new GlobalAttribute (current_container, current_attr_target,
595 ((Expression) $1).ToString (),
596 (ArrayList) $3, (Location) $2);
598 $$ = new Attribute (current_attr_target, ((Expression) $1).ToString (),
599 (ArrayList) $3, (Location) $2);
604 : type_name { /* reserved attribute name or identifier: 17.4 */ }
607 opt_attribute_arguments
608 : /* empty */ { $$ = null; }
609 | OPEN_PARENS attribute_arguments CLOSE_PARENS
617 : opt_positional_argument_list
622 ArrayList args = new ArrayList (4);
628 | positional_argument_list COMMA named_argument_list
630 ArrayList args = new ArrayList (4);
636 | named_argument_list
638 ArrayList args = new ArrayList (4);
647 opt_positional_argument_list
648 : /* empty */ { $$ = null; }
649 | positional_argument_list
652 positional_argument_list
655 ArrayList args = new ArrayList (4);
656 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
660 | positional_argument_list COMMA expression
662 ArrayList args = (ArrayList) $1;
663 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
672 ArrayList args = new ArrayList (4);
677 | named_argument_list COMMA named_argument
679 ArrayList args = (ArrayList) $1;
687 : IDENTIFIER ASSIGN expression
689 $$ = new DictionaryEntry (
691 new Argument ((Expression) $3, Argument.AType.Expression));
697 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
700 opt_class_member_declarations
702 | class_member_declarations
705 class_member_declarations
706 : class_member_declaration
707 | class_member_declarations
708 class_member_declaration
711 class_member_declaration
712 : constant_declaration // done
713 | field_declaration // done
714 | method_declaration // done
715 | property_declaration // done
716 | event_declaration // done
717 | indexer_declaration // done
718 | operator_declaration // done
719 | constructor_declaration // done
720 | destructor_declaration // done
730 MemberName full_struct_name = MakeName ((MemberName) $4);
732 new_struct = new Struct (current_namespace, current_container, full_struct_name,
733 (int) $2, (Attributes) $1, lexer.Location);
734 current_container = new_struct;
735 RootContext.Tree.RecordDecl (full_struct_name.GetName (true), new_struct);
736 lexer.ConstraintsParsing = true;
739 opt_type_parameter_constraints_clauses
741 lexer.ConstraintsParsing = false;
746 Struct new_struct = (Struct) current_container;
748 CheckDef (new_struct.SetParameterInfo ((ArrayList) $7), new_struct.Name, new_struct.Location);
751 new_struct.Bases = (ArrayList) $6;
753 current_container = current_container.Parent;
754 CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
757 | opt_attributes opt_modifiers STRUCT error {
758 CheckIdentifierToken (yyToken);
763 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
766 opt_struct_member_declarations
768 | struct_member_declarations
771 struct_member_declarations
772 : struct_member_declaration
773 | struct_member_declarations struct_member_declaration
776 struct_member_declaration
777 : constant_declaration
780 | property_declaration
782 | indexer_declaration
783 | operator_declaration
784 | constructor_declaration
788 * This is only included so we can flag error 575:
789 * destructors only allowed on class types
791 | destructor_declaration
802 foreach (VariableDeclaration constant in (ArrayList) $5){
803 Location l = constant.Location;
805 Const c = new Const (
806 (Expression) $4, (string) constant.identifier,
807 (Expression) constant.expression_or_array_initializer, (int) $2,
810 CheckDef (current_container.AddConstant (c), c.Name, l);
816 : constant_declarator
818 ArrayList constants = new ArrayList (4);
822 | constant_declarators COMMA constant_declarator
824 ArrayList constants = (ArrayList) $1;
831 : IDENTIFIER ASSIGN constant_expression
833 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
844 Expression type = (Expression) $3;
847 foreach (VariableDeclaration var in (ArrayList) $4){
848 Location l = var.Location;
850 Field field = new Field (type, mod, var.identifier,
851 var.expression_or_array_initializer,
854 CheckDef (current_container.AddField (field), field.Name, l);
862 Report.Error (670, lexer.Location, "void type is not allowed for fields");
867 : variable_declarator
869 ArrayList decl = new ArrayList (4);
873 | variable_declarators COMMA variable_declarator
875 ArrayList decls = (ArrayList) $1;
882 : IDENTIFIER ASSIGN variable_initializer
884 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
888 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
901 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
903 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
909 iterator_container = (IIteratorContainer) $1;
913 Method method = (Method) $1;
914 Block b = (Block) $3;
915 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
918 if ((method.ModFlags & extern_abstract) == 0){
920 501, lexer.Location, current_container.MakeName (method.Name) +
921 "must declare a body because it is not marked abstract or extern");
924 if ((method.ModFlags & Modifiers.EXTERN) != 0){
926 179, lexer.Location, current_container.MakeName (method.Name) +
927 " is declared extern, but has a body");
931 method.Block = (Block) $3;
932 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
934 current_local_parameters = null;
935 iterator_container = null;
949 1585, lexer.Location, "Member modifier `" +
950 Modifiers.Name (i) + "' must precede member type and name");
961 type namespace_or_type_name
962 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
964 lexer.ConstraintsParsing = true;
966 opt_type_parameter_constraints_clauses
968 lexer.ConstraintsParsing = false;
970 TypeName type_name = (TypeName) $4;
971 MemberName name = type_name.GetMemberName ();
973 if ($9 != null && name.TypeParameters == null)
974 Report.Error (80, lexer.Location,
975 "Contraints are not allowed on non-generic declarations");
979 GenericMethod generic = null;
980 if (name.TypeParameters != null) {
981 generic = new GenericMethod (current_namespace, current_container,
982 name, (Attributes) $1, lexer.Location);
984 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
986 method = new Method (generic, (Expression) $3, (int) $2, false, name,
987 (Parameters) $6, (Attributes) $1, lexer.Location);
989 method = new Method (current_container, (Expression) $3, (int) $2,
990 false, name, (Parameters) $6, (Attributes) $1,
993 current_local_parameters = (Parameters) $6;
999 VOID namespace_or_type_name
1000 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1002 lexer.ConstraintsParsing = true;
1004 opt_type_parameter_constraints_clauses
1006 lexer.ConstraintsParsing = false;
1008 TypeName type_name = (TypeName) $4;
1009 MemberName name = type_name.GetMemberName ();
1011 if ($9 != null && name.TypeParameters == null)
1012 Report.Error (80, lexer.Location,
1013 "Contraints are not allowed on non-generic declarations");
1016 GenericMethod generic = null;
1017 if (name.TypeParameters != null) {
1018 generic = new GenericMethod (current_namespace, current_container,
1019 name, (Attributes) $1, lexer.Location);
1022 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
1024 method = new Method (generic, TypeManager.system_void_expr, (int) $2,
1025 false, name, (Parameters) $6, (Attributes) $1,
1028 method = new Method (current_container, TypeManager.system_void_expr,
1029 (int) $2, false, name, (Parameters) $6,
1030 (Attributes) $1, lexer.Location);
1032 current_local_parameters = (Parameters) $6;
1039 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1041 Report.Error (1585, lexer.Location,
1042 String.Format ("Modifier {0} should appear before type",
1043 Modifiers.Name ((int) $4)));
1044 TypeName type_name = (TypeName) $4;
1045 MemberName name = type_name.GetMemberName ();
1047 Method method = new Method (current_container, TypeManager.system_void_expr,
1048 0, false, name, (Parameters) $6, (Attributes) $1,
1051 current_local_parameters = (Parameters) $6;
1058 | SEMICOLON { $$ = null; }
1061 opt_formal_parameter_list
1062 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1063 | formal_parameter_list
1066 formal_parameter_list
1069 ArrayList pars_list = (ArrayList) $1;
1071 Parameter [] pars = new Parameter [pars_list.Count];
1072 pars_list.CopyTo (pars);
1074 $$ = new Parameters (pars, null, lexer.Location);
1076 | fixed_parameters COMMA parameter_array
1078 ArrayList pars_list = (ArrayList) $1;
1080 Parameter [] pars = new Parameter [pars_list.Count];
1081 pars_list.CopyTo (pars);
1083 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
1087 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1094 ArrayList pars = new ArrayList (4);
1099 | fixed_parameters COMMA fixed_parameter
1101 ArrayList pars = (ArrayList) $1;
1110 opt_parameter_modifier
1114 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1117 opt_parameter_modifier
1120 CheckIdentifierToken (yyToken);
1125 opt_parameter_modifier
1126 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1127 | parameter_modifier
1131 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1132 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1136 : opt_attributes PARAMS type IDENTIFIER
1138 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1139 note ("type must be a single-dimension array type");
1141 | opt_attributes PARAMS type error {
1142 CheckIdentifierToken (yyToken);
1147 property_declaration
1150 type namespace_or_type_name
1153 implicit_value_parameter_type = (Expression) $3;
1155 lexer.PropertyParsing = true;
1157 $$ = lexer.Location;
1159 iterator_container = SimpleIteratorContainer.GetSimple ();
1161 accessor_declarations
1163 lexer.PropertyParsing = false;
1168 Pair pair = (Pair) $7;
1169 Accessor get_block = (Accessor) pair.First;
1170 Accessor set_block = (Accessor) pair.Second;
1172 TypeName type_name = (TypeName) $4;
1173 if (type_name.TypeArguments != null)
1174 syntax_error (lexer.Location, "a property can't have type arguments");
1176 MemberName name = type_name.GetMemberName ();
1178 Location loc = (Location) $6;
1179 prop = new Property (current_container, (Expression) $3, (int) $2, false,
1180 name, (Attributes) $1, get_block, set_block, loc);
1181 if (SimpleIteratorContainer.Simple.Yields)
1184 CheckDef (current_container.AddProperty (prop), prop.Name, loc);
1185 implicit_value_parameter_type = null;
1186 iterator_container = null;
1190 accessor_declarations
1191 : get_accessor_declaration opt_set_accessor_declaration
1193 $$ = new Pair ($1, $2);
1195 | set_accessor_declaration opt_get_accessor_declaration
1197 $$ = new Pair ($2, $1);
1201 opt_get_accessor_declaration
1202 : /* empty */ { $$ = null; }
1203 | get_accessor_declaration
1206 opt_set_accessor_declaration
1207 : /* empty */ { $$ = null; }
1208 | set_accessor_declaration
1211 get_accessor_declaration
1212 : opt_attributes GET
1214 // If this is not the case, then current_local_parameters has already
1215 // been set in indexer_declaration
1216 if (parsing_indexer == false)
1217 current_local_parameters = null;
1219 current_local_parameters = indexer_parameters;
1220 lexer.PropertyParsing = false;
1224 $$ = new Accessor ((Block) $4, (Attributes) $1);
1225 current_local_parameters = null;
1226 lexer.PropertyParsing = true;
1230 set_accessor_declaration
1231 : opt_attributes SET
1234 Parameter implicit_value_parameter = new Parameter (
1235 implicit_value_parameter_type, "value",
1236 Parameter.Modifier.NONE, null);
1238 if (parsing_indexer == false) {
1239 args = new Parameter [1];
1240 args [0] = implicit_value_parameter;
1241 current_local_parameters = new Parameters (args, null, lexer.Location);
1243 Parameter [] fpars = indexer_parameters.FixedParameters;
1246 int count = fpars.Length;
1248 args = new Parameter [count + 1];
1249 fpars.CopyTo (args, 0);
1250 args [count] = implicit_value_parameter;
1253 current_local_parameters = new Parameters (
1254 args, indexer_parameters.ArrayParameter, lexer.Location);
1257 lexer.PropertyParsing = false;
1261 $$ = new Accessor ((Block) $4, (Attributes) $1);
1262 current_local_parameters = null;
1263 lexer.PropertyParsing = true;
1269 | SEMICOLON { $$ = null; }
1272 interface_declaration
1275 INTERFACE member_name
1277 Interface new_interface;
1278 MemberName full_interface_name = MakeName ((MemberName) $4);
1280 new_interface = new Interface (current_namespace, current_container, full_interface_name,
1281 (int) $2, (Attributes) $1, lexer.Location);
1282 if (current_interface != null) {
1283 Location l = lexer.Location;
1284 Report.Error (-2, l, "Internal compiler error: interface inside interface");
1286 current_interface = new_interface;
1287 current_container = new_interface;
1288 RootContext.Tree.RecordDecl (
1289 full_interface_name.GetName (true), new_interface);
1290 lexer.ConstraintsParsing = true;
1293 opt_type_parameter_constraints_clauses
1295 lexer.ConstraintsParsing = false;
1297 interface_body opt_semicolon
1299 Interface new_interface = (Interface) current_interface;
1301 CheckDef (new_interface.SetParameterInfo ((ArrayList) $7), new_interface.Name, new_interface.Location);
1303 new_interface.Bases = (ArrayList) $6;
1305 current_interface = null;
1306 current_container = current_container.Parent;
1307 CheckDef (current_container.AddInterface (new_interface),
1308 new_interface.Name, new_interface.Location);
1310 | opt_attributes opt_modifiers INTERFACE error {
1311 CheckIdentifierToken (yyToken);
1317 opt_interface_member_declarations
1321 opt_interface_member_declarations
1323 | interface_member_declarations
1326 interface_member_declarations
1327 : interface_member_declaration
1328 | interface_member_declarations interface_member_declaration
1331 interface_member_declaration
1332 : interface_method_declaration
1334 Method m = (Method) $1;
1336 CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
1338 | interface_property_declaration
1340 Property p = (Property) $1;
1342 CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
1344 | interface_event_declaration
1347 Event e = (Event) $1;
1348 CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
1351 | interface_indexer_declaration
1353 Indexer i = (Indexer) $1;
1355 current_interface.AddIndexer (i);
1363 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1368 interface_method_declaration
1369 : opt_attributes opt_new type IDENTIFIER
1370 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1373 $$ = new Method (current_container, (Expression) $3, (int) $2, true,
1374 new MemberName ((string) $4), (Parameters) $6,
1375 (Attributes) $1, lexer.Location);
1377 | opt_attributes opt_new VOID IDENTIFIER
1378 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1381 $$ = new Method (current_container, TypeManager.system_void_expr, (int) $2,
1382 true, new MemberName ((string) $4), (Parameters) $6,
1383 (Attributes) $1, lexer.Location);
1387 interface_property_declaration
1392 { lexer.PropertyParsing = true; }
1394 { lexer.PropertyParsing = false; }
1397 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1399 $$ = new Property (current_container, (Expression) $3, (int) $2, true,
1400 new MemberName ((string) $4), (Attributes) $1,
1401 pinfo.Get, pinfo.Set, lexer.Location);
1406 CheckIdentifierToken (yyToken);
1412 : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null); }
1413 | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1); }
1414 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1415 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3); }
1416 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1417 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1); }
1420 interface_event_declaration
1421 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1423 $$ = new EventField (current_container, (Expression) $4, (int) $2, true,
1424 new MemberName ((string) $5), null,
1425 (Attributes) $1, lexer.Location);
1427 | opt_attributes opt_new EVENT type error {
1428 CheckIdentifierToken (yyToken);
1431 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1432 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1435 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1436 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1441 interface_indexer_declaration
1442 : opt_attributes opt_new type THIS
1443 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1445 { lexer.PropertyParsing = true; }
1447 { lexer.PropertyParsing = false; }
1450 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1452 $$ = new Indexer (current_container, (Expression) $3, (int) $2, true,
1453 MemberName.Null, (Parameters) $6, (Attributes) $1,
1454 info.Get, info.Set, lexer.Location);
1458 operator_declaration
1459 : opt_attributes opt_modifiers operator_declarator
1461 iterator_container = SimpleIteratorContainer.GetSimple ();
1465 OperatorDeclaration decl = (OperatorDeclaration) $3;
1467 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1468 decl.arg2type, decl.arg2name, (Block) $5, (Attributes) $1, decl.location);
1470 if (SimpleIteratorContainer.Simple.Yields)
1473 // Note again, checking is done in semantic analysis
1474 current_container.AddOperator (op);
1476 current_local_parameters = null;
1477 iterator_container = null;
1483 | SEMICOLON { $$ = null; }
1486 : type OPERATOR overloadable_operator
1487 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1489 Operator.OpType op = (Operator.OpType) $3;
1490 CheckUnaryOperator (op);
1492 if (op == Operator.OpType.Addition)
1493 op = Operator.OpType.UnaryPlus;
1495 if (op == Operator.OpType.Subtraction)
1496 op = Operator.OpType.UnaryNegation;
1498 Parameter [] pars = new Parameter [1];
1500 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1502 current_local_parameters = new Parameters (pars, null, lexer.Location);
1504 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1505 null, null, lexer.Location);
1507 | type OPERATOR overloadable_operator
1509 type IDENTIFIER COMMA
1513 CheckBinaryOperator ((Operator.OpType) $3);
1515 Parameter [] pars = new Parameter [2];
1517 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1518 pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1520 current_local_parameters = new Parameters (pars, null, lexer.Location);
1522 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1523 (Expression) $5, (string) $6,
1524 (Expression) $8, (string) $9, lexer.Location);
1526 | conversion_operator_declarator
1529 overloadable_operator
1531 : BANG { $$ = Operator.OpType.LogicalNot; }
1532 | TILDE { $$ = Operator.OpType.OnesComplement; }
1533 | OP_INC { $$ = Operator.OpType.Increment; }
1534 | OP_DEC { $$ = Operator.OpType.Decrement; }
1535 | TRUE { $$ = Operator.OpType.True; }
1536 | FALSE { $$ = Operator.OpType.False; }
1537 // Unary and binary:
1538 | PLUS { $$ = Operator.OpType.Addition; }
1539 | MINUS { $$ = Operator.OpType.Subtraction; }
1541 | STAR { $$ = Operator.OpType.Multiply; }
1542 | DIV { $$ = Operator.OpType.Division; }
1543 | PERCENT { $$ = Operator.OpType.Modulus; }
1544 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1545 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1546 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1547 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1548 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1549 | OP_EQ { $$ = Operator.OpType.Equality; }
1550 | OP_NE { $$ = Operator.OpType.Inequality; }
1551 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1552 | OP_LT { $$ = Operator.OpType.LessThan; }
1553 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1554 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1557 conversion_operator_declarator
1558 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1560 Parameter [] pars = new Parameter [1];
1562 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1564 current_local_parameters = new Parameters (pars, null, lexer.Location);
1566 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1567 null, null, lexer.Location);
1569 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1571 Parameter [] pars = new Parameter [1];
1573 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1575 current_local_parameters = new Parameters (pars, null, lexer.Location);
1577 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1578 null, null, lexer.Location);
1582 syntax_error (lexer.Location, "'operator' expected");
1586 syntax_error (lexer.Location, "'operator' expected");
1590 constructor_declaration
1593 constructor_declarator
1596 Constructor c = (Constructor) $3;
1597 c.Block = (Block) $4;
1598 c.OptAttributes = (Attributes) $1;
1599 c.ModFlags = (int) $2;
1601 if (c.Name == current_container.Basename){
1602 if ((c.ModFlags & Modifiers.STATIC) != 0){
1603 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1605 515, c.Location, String.Format (
1606 "`{0}.{1}': static constructor can not have access modifiers",
1607 c.Name, current_container.Name));
1610 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1612 if (c.Initializer != null){
1615 "Static constructors can not have an explicit this or base " +
1616 "constructor invocations");
1619 if (!c.Parameters.Empty){
1621 132, c.Location, "Static constructors should not have parameters");
1624 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1627 // We let another layer check the validity of the constructor.
1628 Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1631 CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
1633 current_local_parameters = null;
1637 constructor_declarator
1639 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1641 oob_stack.Push (lexer.Location);
1643 current_local_parameters = (Parameters) $3;
1645 opt_constructor_initializer
1647 Location l = (Location) oob_stack.Pop ();
1648 $$ = new Constructor (current_container, (string) $1, 0, (Parameters) $3,
1649 (ConstructorInitializer) $6, l);
1655 | SEMICOLON { $$ = null; }
1658 opt_constructor_initializer
1659 : /* empty */ { $$ = null; }
1660 | constructor_initializer
1663 constructor_initializer
1664 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1666 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1668 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1670 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1673 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1679 : /* EMPTY */ { $$ = 0; }
1680 | UNSAFE { $$ = Modifiers.UNSAFE; }
1681 | EXTERN { $$ = Modifiers.EXTERN; }
1684 destructor_declaration
1685 : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1687 if ((string) $4 != current_container.Basename){
1688 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1689 } else if (!(current_container is Class)){
1690 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1692 Location l = lexer.Location;
1695 if (!RootContext.StdLib && current_container.Name == "System.Object")
1696 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1698 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1700 if ((m & Modifiers.UNSAFE) != 0){
1701 if (!RootContext.Unsafe){
1702 Report.Error (227, l,
1703 "Unsafe code requires the -unsafe command " +
1704 "line option to be specified");
1708 Method d = new Destructor (
1709 current_container, TypeManager.system_void_expr, m, "Finalize",
1710 new Parameters (null, null, l), (Attributes) $1, l);
1712 d.Block = (Block) $7;
1713 CheckDef (current_container.AddMethod (d), d.Name, d.Location);
1716 | opt_attributes opt_modifiers EVENT type member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
1717 string mn = (string) $5;
1719 if (mn.IndexOf ('.') != -1)
1720 Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
1722 Report.Error (71, lexer.Location, "Event declaration should use property syntax");
1729 EVENT type variable_declarators SEMICOLON
1731 foreach (VariableDeclaration var in (ArrayList) $5) {
1733 MemberName name = new MemberName (var.identifier);
1735 Event e = new EventField (current_container, (Expression) $4, (int) $2,
1737 var.expression_or_array_initializer,
1738 (Attributes) $1, lexer.Location);
1740 CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1746 EVENT type namespace_or_type_name
1749 implicit_value_parameter_type = (Expression) $4;
1750 lexer.EventParsing = true;
1751 oob_stack.Push (lexer.Location);
1753 event_accessor_declarations
1755 lexer.EventParsing = false;
1759 Location loc = (Location) oob_stack.Pop ();
1762 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1765 Pair pair = (Pair) $8;
1767 TypeName type_name = (TypeName) $5;
1768 if (type_name.TypeArguments != null)
1769 syntax_error (lexer.Location, "an event can't have type arguments");
1771 MemberName name = type_name.GetMemberName ();
1773 Event e = new EventProperty (current_container, (Expression) $4, (int) $2,
1774 false, name, null, (Attributes) $1,
1775 (Accessor) pair.First, (Accessor) pair.Second,
1778 CheckDef (current_container.AddEvent (e), e.Name, loc);
1779 implicit_value_parameter_type = null;
1784 event_accessor_declarations
1785 : add_accessor_declaration remove_accessor_declaration
1787 $$ = new Pair ($1, $2);
1789 | remove_accessor_declaration add_accessor_declaration
1791 $$ = new Pair ($2, $1);
1793 | add_accessor_declaration { $$ = null; }
1794 | remove_accessor_declaration { $$ = null; }
1797 add_accessor_declaration
1798 : opt_attributes ADD
1800 Parameter [] args = new Parameter [1];
1801 Parameter implicit_value_parameter = new Parameter (
1802 implicit_value_parameter_type, "value",
1803 Parameter.Modifier.NONE, null);
1805 args [0] = implicit_value_parameter;
1807 current_local_parameters = new Parameters (args, null, lexer.Location);
1808 lexer.EventParsing = false;
1812 $$ = new Accessor ((Block) $4, (Attributes) $1);
1813 lexer.EventParsing = true;
1815 | opt_attributes ADD error {
1816 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1821 remove_accessor_declaration
1822 : opt_attributes REMOVE
1824 Parameter [] args = new Parameter [1];
1825 Parameter implicit_value_parameter = new Parameter (
1826 implicit_value_parameter_type, "value",
1827 Parameter.Modifier.NONE, null);
1829 args [0] = implicit_value_parameter;
1831 current_local_parameters = new Parameters (args, null, lexer.Location);
1832 lexer.EventParsing = false;
1836 $$ = new Accessor ((Block) $4, (Attributes) $1);
1837 lexer.EventParsing = true;
1839 | opt_attributes REMOVE error {
1840 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1846 : opt_attributes opt_modifiers indexer_declarator
1849 IndexerDeclaration decl = (IndexerDeclaration) $3;
1851 implicit_value_parameter_type = decl.type;
1853 lexer.PropertyParsing = true;
1854 parsing_indexer = true;
1856 indexer_parameters = decl.param_list;
1857 oob_stack.Push (lexer.Location);
1859 accessor_declarations
1861 lexer.PropertyParsing = false;
1862 parsing_indexer = false;
1866 // The signature is computed from the signature of the indexer. Look
1867 // at section 3.6 on the spec
1868 Location loc = (Location) oob_stack.Pop ();
1870 IndexerDeclaration decl = (IndexerDeclaration) $3;
1871 Pair pair = (Pair) $6;
1872 Accessor get_block = (Accessor) pair.First;
1873 Accessor set_block = (Accessor) pair.Second;
1876 if (decl.interface_type != null)
1877 name = new MemberName (decl.interface_type, "");
1879 name = MemberName.Null;
1881 indexer = new Indexer (current_container, decl.type, (int) $2, false,
1882 name, decl.param_list, (Attributes) $1,
1883 get_block, set_block, loc);
1885 // Note that there is no equivalent of CheckDef for this case
1886 // We shall handle this in semantic analysis
1888 current_container.AddIndexer (indexer);
1890 current_local_parameters = null;
1891 implicit_value_parameter_type = null;
1892 indexer_parameters = null;
1897 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1899 Parameters pars = (Parameters) $4;
1901 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1902 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1905 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1907 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1909 Parameters pars = (Parameters) $6;
1911 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1912 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1914 TypeName name = (TypeName) $2;
1915 if (name.TypeArguments != null)
1916 syntax_error (lexer.Location, "an indexer can't have type arguments");
1918 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
1930 Location enum_location = lexer.Location;
1932 MemberName full_name = MakeName (new MemberName ((string) $4));
1933 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
1934 full_name, (Attributes) $1, enum_location);
1936 foreach (VariableDeclaration ev in (ArrayList) $6) {
1937 Location loc = (Location) ev.Location;
1939 CheckDef (e.AddEnumMember (ev.identifier,
1940 (Expression) ev.expression_or_array_initializer,
1941 loc, ev.OptAttributes),
1942 ev.identifier, loc);
1945 string name = full_name.GetName (false);
1946 CheckDef (current_container.AddEnum (e), name, enum_location);
1947 RootContext.Tree.RecordDecl (name, e);
1953 : /* empty */ { $$ = TypeManager.system_int32_expr; }
1954 | COLON type { $$ = $2; }
1958 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1964 opt_enum_member_declarations
1965 : /* empty */ { $$ = new ArrayList (4); }
1966 | enum_member_declarations opt_comma { $$ = $1; }
1969 enum_member_declarations
1970 : enum_member_declaration
1972 ArrayList l = new ArrayList (4);
1977 | enum_member_declarations COMMA enum_member_declaration
1979 ArrayList l = (ArrayList) $1;
1987 enum_member_declaration
1988 : opt_attributes IDENTIFIER
1990 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
1992 | opt_attributes IDENTIFIER
1994 $$ = lexer.Location;
1998 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
2002 delegate_declaration
2005 DELEGATE type member_name
2006 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2008 Location l = lexer.Location;
2009 Delegate del = new Delegate (
2010 current_namespace, current_container, (Expression) $4, (int) $2,
2011 MakeName ((MemberName) $5), (Parameters) $7, (Attributes) $1, l);
2013 CheckDef (current_container.AddDelegate (del), del.Name, l);
2015 current_delegate = del;
2017 lexer.ConstraintsParsing = true;
2019 opt_type_parameter_constraints_clauses
2021 lexer.ConstraintsParsing = false;
2025 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
2027 current_delegate = null;
2031 DELEGATE VOID member_name
2032 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2034 Location l = lexer.Location;
2035 Delegate del = new Delegate (
2036 current_namespace, current_container,
2037 TypeManager.system_void_expr, (int) $2, MakeName ((MemberName) $5),
2038 (Parameters) $7, (Attributes) $1, l);
2040 CheckDef (current_container.AddDelegate (del), del.Name, l);
2042 current_delegate = del;
2044 lexer.ConstraintsParsing = true;
2046 opt_type_parameter_constraints_clauses
2048 lexer.ConstraintsParsing = false;
2052 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
2054 current_delegate = null;
2059 : namespace_or_type_name {
2060 $$ = ((TypeName) $1).GetTypeExpression (lexer.Location);
2064 namespace_or_type_name
2065 : IDENTIFIER opt_type_argument_list {
2066 $$ = new TypeName ((string) $1, (TypeArguments) $2);
2068 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2069 $$ = new TypeName ((TypeName) $1, (string) $3, (TypeArguments) $4);
2074 : IDENTIFIER opt_type_parameter_list {
2075 $$ = new MemberName (null, (string) $1, (ArrayList) $2);
2079 opt_type_argument_list
2080 : /* empty */ { $$ = null; }
2081 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2089 TypeArguments type_args = new TypeArguments (lexer.Location);
2090 type_args.Add ((Expression) $1);
2093 | type_arguments COMMA type {
2094 TypeArguments type_args = (TypeArguments) $1;
2095 type_args.Add ((Expression) $3);
2101 * Before you think of adding a return_type, notice that we have been
2102 * using two rules in the places where it matters (one rule using type
2103 * and another identical one that uses VOID as the return type). This
2104 * gets rid of a shift/reduce couple
2107 : type_name { /* class_type */
2119 // Note that here only unmanaged types are allowed but we
2120 // can't perform checks during this phase - we do it during
2121 // semantic analysis.
2123 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2127 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2133 | non_expression_type rank_specifier
2135 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2137 | non_expression_type STAR
2139 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2141 | expression rank_specifiers
2143 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2147 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2151 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2152 // through this different path
2154 | multiplicative_expression STAR
2156 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2163 ArrayList types = new ArrayList (4);
2168 | type_list COMMA type
2170 ArrayList types = (ArrayList) $1;
2178 * replaces all the productions for isolating the various
2179 * simple types, but we need this to reuse it easily in local_variable_type
2182 : OBJECT { $$ = TypeManager.system_object_expr; }
2183 | STRING { $$ = TypeManager.system_string_expr; }
2184 | BOOL { $$ = TypeManager.system_boolean_expr; }
2185 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2186 | FLOAT { $$ = TypeManager.system_single_expr; }
2187 | DOUBLE { $$ = TypeManager.system_double_expr; }
2192 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2193 | BYTE { $$ = TypeManager.system_byte_expr; }
2194 | SHORT { $$ = TypeManager.system_int16_expr; }
2195 | USHORT { $$ = TypeManager.system_uint16_expr; }
2196 | INT { $$ = TypeManager.system_int32_expr; }
2197 | UINT { $$ = TypeManager.system_uint32_expr; }
2198 | LONG { $$ = TypeManager.system_int64_expr; }
2199 | ULONG { $$ = TypeManager.system_uint64_expr; }
2200 | CHAR { $$ = TypeManager.system_char_expr; }
2201 | VOID { $$ = TypeManager.system_void_expr; }
2209 : type rank_specifiers
2211 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2216 // Expressions, section 7.5
2228 | parenthesized_expression
2229 | default_value_expression
2231 | invocation_expression
2235 | post_increment_expression
2236 | post_decrement_expression
2240 | checked_expression
2241 | unchecked_expression
2242 | pointer_member_access
2243 | anonymous_method_expression
2250 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2251 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2252 | NULL { $$ = NullLiteral.Null; }
2256 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2257 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2258 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2263 object v = lexer.Value;
2269 $$ = IntLiteral.Zero;
2271 $$ = IntLiteral.One;
2273 $$ = new IntLiteral (i);
2274 } else if (v is uint)
2275 $$ = new UIntLiteral ((UInt32) v);
2277 $$ = new LongLiteral ((Int64) v);
2278 else if (v is ulong)
2279 $$ = new ULongLiteral ((UInt64) v);
2281 Console.WriteLine ("OOPS. Unexpected result from scanner");
2286 : TRUE { $$ = new BoolLiteral (true); }
2287 | FALSE { $$ = new BoolLiteral (false); }
2290 parenthesized_expression_0
2291 : OPEN_PARENS expression CLOSE_PARENS
2294 lexer.Deambiguate_CloseParens ();
2295 // After this, the next token returned is one of
2296 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2297 // or CLOSE_PARENS_MINUS.
2301 parenthesized_expression
2302 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2306 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2308 // If a parenthesized expression is followed by a minus, we need to wrap
2309 // the expression inside a ParenthesizedExpression for the CS0075 check
2310 // in Binary.DoResolve().
2311 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2316 : primary_expression DOT IDENTIFIER
2318 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2320 | predefined_type DOT IDENTIFIER
2322 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2330 invocation_expression
2331 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2334 Location l = lexer.Location;
2335 Report.Error (1, l, "Parse error");
2337 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2339 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2341 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2343 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2345 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2350 : /* empty */ { $$ = null; }
2357 ArrayList list = new ArrayList (4);
2361 | argument_list COMMA argument
2363 ArrayList list = (ArrayList) $1;
2367 | argument_list error {
2368 CheckToken (1026, yyToken, ", or ) expected");
2375 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2377 | REF variable_reference
2379 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2381 | OUT variable_reference
2383 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2388 : expression { note ("section 5.4"); $$ = $1; }
2392 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2394 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2396 | primary_expression rank_specifiers
2398 // So the super-trick is that primary_expression
2399 // can only be either a SimpleName or a MemberAccess.
2400 // The MemberAccess case arises when you have a fully qualified type-name like :
2402 // SimpleName is when you have
2405 Expression expr = (Expression) $1;
2406 if (expr is ComposedCast){
2407 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2408 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2409 Error_ExpectingTypeName (lexer.Location, expr);
2410 $$ = TypeManager.system_object_expr;
2413 // So we extract the string corresponding to the SimpleName
2416 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2424 ArrayList list = new ArrayList (4);
2428 | expression_list COMMA expression
2430 ArrayList list = (ArrayList) $1;
2439 $$ = new This (current_block, lexer.Location);
2444 : BASE DOT IDENTIFIER
2446 $$ = new BaseAccess ((string) $3, lexer.Location);
2448 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2450 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2453 Report.Error (175, "Use of keyword `base' is not valid in this context");
2458 post_increment_expression
2459 : primary_expression OP_INC
2461 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2462 (Expression) $1, lexer.Location);
2466 post_decrement_expression
2467 : primary_expression OP_DEC
2469 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2470 (Expression) $1, lexer.Location);
2475 : object_or_delegate_creation_expression
2476 | array_creation_expression
2479 object_or_delegate_creation_expression
2480 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2482 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2486 array_creation_expression
2487 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2489 opt_array_initializer
2491 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2493 | NEW type rank_specifiers array_initializer
2495 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2499 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2515 : rank_specifier opt_rank_specifier
2517 $$ = (string) $2 + (string) $1;
2522 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2524 $$ = "[" + (string) $2 + "]";
2544 | dim_separators COMMA
2546 $$ = (string) $1 + ",";
2550 opt_array_initializer
2562 : OPEN_BRACE CLOSE_BRACE
2564 ArrayList list = new ArrayList (4);
2567 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2569 $$ = (ArrayList) $2;
2573 variable_initializer_list
2574 : variable_initializer
2576 ArrayList list = new ArrayList (4);
2580 | variable_initializer_list COMMA variable_initializer
2582 ArrayList list = (ArrayList) $1;
2589 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2591 $$ = new TypeOfVoid (lexer.Location);
2593 | TYPEOF OPEN_PARENS type CLOSE_PARENS
2595 $$ = new TypeOf ((Expression) $3, lexer.Location);
2600 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2601 $$ = new SizeOf ((Expression) $3, lexer.Location);
2606 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2608 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2612 unchecked_expression
2613 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2615 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2619 pointer_member_access
2620 : primary_expression OP_PTR IDENTIFIER
2624 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2625 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2629 anonymous_method_expression
2630 : DELEGATE opt_anonymous_method_signature {
2631 oob_stack.Push (current_local_parameters);
2632 current_local_parameters = (Parameters)$2;
2633 create_toplevel_block = true;
2636 Report.Error (-213, lexer.Location, "Anonymous methods are not supported in this branch");
2639 create_toplevel_block = false;
2640 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2641 if (!RootContext.V2){
2642 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2645 $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
2646 current_local_parameters = (Parameters) oob_stack.Pop ();
2651 opt_anonymous_method_signature
2652 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
2653 | anonymous_method_signature
2656 anonymous_method_signature
2657 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2660 $$ = Parameters.EmptyReadOnlyParameters;
2662 ArrayList par_list = (ArrayList) $2;
2663 Parameter [] pars = new Parameter [par_list.Count];
2664 par_list.CopyTo (pars);
2665 $$ = new Parameters (pars, null, lexer.Location);
2670 opt_anonymous_method_parameter_list
2671 : /* empty */ { $$ = null; }
2672 | anonymous_method_parameter_list { $$ = $1; }
2675 anonymous_method_parameter_list
2676 : anonymous_method_parameter
2678 ArrayList a = new ArrayList (4);
2682 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2684 ArrayList a = (ArrayList) $1;
2690 anonymous_method_parameter
2691 : opt_parameter_modifier type IDENTIFIER {
2692 $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
2696 default_value_expression
2697 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
2699 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
2704 : primary_expression
2705 | BANG prefixed_unary_expression
2707 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2709 | TILDE prefixed_unary_expression
2711 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2717 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2719 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2721 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2723 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2729 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2731 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2736 // The idea to split this out is from Rhys' grammar
2737 // to solve the problem with casts.
2739 prefixed_unary_expression
2741 | PLUS prefixed_unary_expression
2743 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2745 | MINUS prefixed_unary_expression
2747 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2749 | OP_INC prefixed_unary_expression
2751 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2752 (Expression) $2, lexer.Location);
2754 | OP_DEC prefixed_unary_expression
2756 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2757 (Expression) $2, lexer.Location);
2759 | STAR prefixed_unary_expression
2761 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2763 | BITWISE_AND prefixed_unary_expression
2765 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2769 pre_increment_expression
2770 : OP_INC prefixed_unary_expression
2772 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2773 (Expression) $2, lexer.Location);
2777 pre_decrement_expression
2778 : OP_DEC prefixed_unary_expression
2780 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2781 (Expression) $2, lexer.Location);
2785 multiplicative_expression
2786 : prefixed_unary_expression
2787 | multiplicative_expression STAR prefixed_unary_expression
2789 $$ = new Binary (Binary.Operator.Multiply,
2790 (Expression) $1, (Expression) $3, lexer.Location);
2792 | multiplicative_expression DIV prefixed_unary_expression
2794 $$ = new Binary (Binary.Operator.Division,
2795 (Expression) $1, (Expression) $3, lexer.Location);
2797 | multiplicative_expression PERCENT prefixed_unary_expression
2799 $$ = new Binary (Binary.Operator.Modulus,
2800 (Expression) $1, (Expression) $3, lexer.Location);
2805 : multiplicative_expression
2806 | additive_expression PLUS multiplicative_expression
2808 $$ = new Binary (Binary.Operator.Addition,
2809 (Expression) $1, (Expression) $3, lexer.Location);
2811 | additive_expression MINUS multiplicative_expression
2813 $$ = new Binary (Binary.Operator.Subtraction,
2814 (Expression) $1, (Expression) $3, lexer.Location);
2819 : additive_expression
2820 | shift_expression OP_SHIFT_LEFT additive_expression
2822 $$ = new Binary (Binary.Operator.LeftShift,
2823 (Expression) $1, (Expression) $3, lexer.Location);
2825 | shift_expression OP_SHIFT_RIGHT additive_expression
2827 $$ = new Binary (Binary.Operator.RightShift,
2828 (Expression) $1, (Expression) $3, lexer.Location);
2832 relational_expression
2834 | relational_expression OP_LT shift_expression
2836 $$ = new Binary (Binary.Operator.LessThan,
2837 (Expression) $1, (Expression) $3, lexer.Location);
2839 | relational_expression OP_GT shift_expression
2841 $$ = new Binary (Binary.Operator.GreaterThan,
2842 (Expression) $1, (Expression) $3, lexer.Location);
2844 | relational_expression OP_LE shift_expression
2846 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2847 (Expression) $1, (Expression) $3, lexer.Location);
2849 | relational_expression OP_GE shift_expression
2851 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2852 (Expression) $1, (Expression) $3, lexer.Location);
2854 | relational_expression IS type
2856 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2858 | relational_expression AS type
2860 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2865 : relational_expression
2866 | equality_expression OP_EQ relational_expression
2868 $$ = new Binary (Binary.Operator.Equality,
2869 (Expression) $1, (Expression) $3, lexer.Location);
2871 | equality_expression OP_NE relational_expression
2873 $$ = new Binary (Binary.Operator.Inequality,
2874 (Expression) $1, (Expression) $3, lexer.Location);
2879 : equality_expression
2880 | and_expression BITWISE_AND equality_expression
2882 $$ = new Binary (Binary.Operator.BitwiseAnd,
2883 (Expression) $1, (Expression) $3, lexer.Location);
2887 exclusive_or_expression
2889 | exclusive_or_expression CARRET and_expression
2891 $$ = new Binary (Binary.Operator.ExclusiveOr,
2892 (Expression) $1, (Expression) $3, lexer.Location);
2896 inclusive_or_expression
2897 : exclusive_or_expression
2898 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2900 $$ = new Binary (Binary.Operator.BitwiseOr,
2901 (Expression) $1, (Expression) $3, lexer.Location);
2905 conditional_and_expression
2906 : inclusive_or_expression
2907 | conditional_and_expression OP_AND inclusive_or_expression
2909 $$ = new Binary (Binary.Operator.LogicalAnd,
2910 (Expression) $1, (Expression) $3, lexer.Location);
2914 conditional_or_expression
2915 : conditional_and_expression
2916 | conditional_or_expression OP_OR conditional_and_expression
2918 $$ = new Binary (Binary.Operator.LogicalOr,
2919 (Expression) $1, (Expression) $3, lexer.Location);
2923 conditional_expression
2924 : conditional_or_expression
2925 | conditional_or_expression INTERR expression COLON expression
2927 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2931 assignment_expression
2932 : prefixed_unary_expression ASSIGN expression
2934 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2936 | prefixed_unary_expression OP_MULT_ASSIGN expression
2938 Location l = lexer.Location;
2940 $$ = new CompoundAssign (
2941 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
2943 | prefixed_unary_expression OP_DIV_ASSIGN expression
2945 Location l = lexer.Location;
2947 $$ = new CompoundAssign (
2948 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
2950 | prefixed_unary_expression OP_MOD_ASSIGN expression
2952 Location l = lexer.Location;
2954 $$ = new CompoundAssign (
2955 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
2957 | prefixed_unary_expression OP_ADD_ASSIGN expression
2959 Location l = lexer.Location;
2961 $$ = new CompoundAssign (
2962 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
2964 | prefixed_unary_expression OP_SUB_ASSIGN expression
2966 Location l = lexer.Location;
2968 $$ = new CompoundAssign (
2969 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
2971 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2973 Location l = lexer.Location;
2975 $$ = new CompoundAssign (
2976 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
2978 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2980 Location l = lexer.Location;
2982 $$ = new CompoundAssign (
2983 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
2985 | prefixed_unary_expression OP_AND_ASSIGN expression
2987 Location l = lexer.Location;
2989 $$ = new CompoundAssign (
2990 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
2992 | prefixed_unary_expression OP_OR_ASSIGN expression
2994 Location l = lexer.Location;
2996 $$ = new CompoundAssign (
2997 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
2999 | prefixed_unary_expression OP_XOR_ASSIGN expression
3001 Location l = lexer.Location;
3003 $$ = new CompoundAssign (
3004 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
3009 : conditional_expression
3010 | assignment_expression
3031 MemberName name = MakeName ((MemberName) $4);
3033 new_class = new Class (current_namespace, current_container, name, (int) $2,
3034 (Attributes) $1, lexer.Location);
3035 current_container = new_class;
3036 RootContext.Tree.RecordDecl (name.GetName (true), new_class);
3038 lexer.ConstraintsParsing = true;
3041 opt_type_parameter_constraints_clauses
3043 lexer.ConstraintsParsing = false;
3048 Class new_class = (Class) current_container;
3050 CheckDef (new_class.SetParameterInfo ((ArrayList) $7), new_class.Name, new_class.Location);
3052 if (new_class.Name == "System.Object") {
3053 Report.Error (537, new_class.Location, "The class System.Object cannot have a base class or implement an interface.");
3056 new_class.Bases = (ArrayList) $6;
3058 current_container = current_container.Parent;
3059 CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
3067 lexer.ConstraintsParsing = true;
3070 Report.Error (80, lexer.Location,
3071 "Contraints are not allowed on non-generic declarations");
3078 : /* empty */ { $$ = (int) 0; }
3084 | modifiers modifier
3089 if ((m1 & m2) != 0) {
3090 Location l = lexer.Location;
3091 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3093 $$ = (int) (m1 | m2);
3098 : NEW { $$ = Modifiers.NEW; }
3099 | PUBLIC { $$ = Modifiers.PUBLIC; }
3100 | PROTECTED { $$ = Modifiers.PROTECTED; }
3101 | INTERNAL { $$ = Modifiers.INTERNAL; }
3102 | PRIVATE { $$ = Modifiers.PRIVATE; }
3103 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3104 | SEALED { $$ = Modifiers.SEALED; }
3105 | STATIC { $$ = Modifiers.STATIC; }
3106 | READONLY { $$ = Modifiers.READONLY; }
3107 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3108 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3109 | EXTERN { $$ = Modifiers.EXTERN; }
3110 | VOLATILE { $$ = Modifiers.VOLATILE; }
3111 | UNSAFE { $$ = Modifiers.UNSAFE; }
3115 : /* empty */ { $$ = null; }
3116 | class_base { $$ = $1; }
3120 : COLON type_list { $$ = $2; }
3123 opt_type_parameter_list
3124 : /* empty */ { $$ = null; }
3125 | type_parameter_list { $$ = $1; }
3129 : OP_GENERICS_LT type_parameters OP_GENERICS_GT { $$ = $2; }
3135 // Do some profiling to find the optimal size, for now we
3136 // assume most people will be generic on one type (saves space
3138 ArrayList type_parameters = new ArrayList (1);
3139 type_parameters.Add ($1);
3140 $$ = type_parameters;
3142 | type_parameters COMMA type_parameter {
3143 ArrayList type_parameters = (ArrayList) $1;
3145 type_parameters.Add ($3);
3146 $$ = type_parameters;
3154 opt_type_parameter_constraints_clauses
3155 : /* empty */ { $$ = null; }
3156 | type_parameter_constraints_clauses
3160 type_parameter_constraints_clauses
3161 : type_parameter_constraints_clause {
3162 ArrayList constraints = new ArrayList (1);
3163 constraints.Add ($1);
3166 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3167 ArrayList constraints = (ArrayList) $1;
3169 constraints.Add ($2);
3174 type_parameter_constraints_clause
3175 : WHERE type_parameter COLON type_parameter_constraints {
3176 $$ = new Constraints ((string) $2, (ArrayList) $4, lexer.Location);
3180 type_parameter_constraints
3181 : type_parameter_constraint {
3182 ArrayList constraints = new ArrayList (1);
3183 constraints.Add ($1);
3186 | type_parameter_constraints COMMA type_parameter_constraint {
3187 ArrayList constraints = (ArrayList) $1;
3189 constraints.Add ($3);
3194 type_parameter_constraint
3196 | NEW OPEN_PARENS CLOSE_PARENS {
3197 $$ = SpecialConstraint.Constructor;
3200 $$ = SpecialConstraint.ReferenceType;
3203 $$ = SpecialConstraint.ValueType;
3212 // A block is "contained" on the following places:
3214 // property_declaration as part of the accessor body (get/set)
3215 // operator_declaration
3216 // constructor_declaration
3217 // destructor_declaration
3218 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3223 if (current_block == null || create_toplevel_block){
3224 current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
3226 current_block = new Block (current_block, current_local_parameters,
3227 lexer.Location, Location.Null);
3230 opt_statement_list CLOSE_BRACE
3232 while (current_block.Implicit)
3233 current_block = current_block.Parent;
3235 current_block.SetEndLocation (lexer.Location);
3236 current_block = current_block.Parent;
3247 | statement_list statement
3251 : declaration_statement
3253 if ($1 != null && (Block) $1 != current_block){
3254 current_block.AddStatement ((Statement) $1);
3255 current_block = (Block) $1;
3258 | valid_declaration_statement
3260 current_block.AddStatement ((Statement) $1);
3265 valid_declaration_statement
3268 | expression_statement
3269 | selection_statement
3270 | iteration_statement
3274 | unchecked_statement
3282 : valid_declaration_statement
3283 | declaration_statement
3285 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
3290 Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
3298 $$ = EmptyStatement.Value;
3305 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3307 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3308 current_block.AddStatement (labeled);
3313 declaration_statement
3314 : local_variable_declaration SEMICOLON
3317 DictionaryEntry de = (DictionaryEntry) $1;
3319 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3323 | local_constant_declaration SEMICOLON
3326 DictionaryEntry de = (DictionaryEntry) $1;
3328 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3334 * The following is from Rhys' grammar:
3335 * > Types in local variable declarations must be recognized as
3336 * > expressions to prevent reduce/reduce errors in the grammar.
3337 * > The expressions are converted into types during semantic analysis.
3340 : primary_expression opt_rank_specifier
3342 // FIXME: Do something smart here regarding the composition of the type.
3344 // Ok, the above "primary_expression" is there to get rid of
3345 // both reduce/reduce and shift/reduces in the grammar, it should
3346 // really just be "type_name". If you use type_name, a reduce/reduce
3347 // creeps up. If you use namespace_or_type_name (which is all we need
3348 // really) two shift/reduces appear.
3351 // So the super-trick is that primary_expression
3352 // can only be either a SimpleName or a MemberAccess.
3353 // The MemberAccess case arises when you have a fully qualified type-name like :
3355 // SimpleName is when you have
3358 Expression expr = (Expression) $1;
3359 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3360 Error_ExpectingTypeName (lexer.Location, expr);
3364 // So we extract the string corresponding to the SimpleName
3368 if ((string) $2 == "")
3371 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3374 | builtin_types opt_rank_specifier
3376 if ((string) $2 == "")
3379 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3383 local_variable_pointer_type
3384 : primary_expression STAR
3386 Expression expr = (Expression) $1;
3387 Location l = lexer.Location;
3389 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3390 Error_ExpectingTypeName (l, expr);
3394 $$ = new ComposedCast ((Expression) $1, "*", l);
3396 | builtin_types STAR
3398 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3402 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3404 | local_variable_pointer_type STAR
3406 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3410 local_variable_declaration
3411 : local_variable_type variable_declarators
3414 $$ = new DictionaryEntry ($1, $2);
3418 | local_variable_pointer_type opt_rank_specifier variable_declarators
3423 if ((string) $2 == "")
3424 t = (Expression) $1;
3426 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3427 $$ = new DictionaryEntry (t, $3);
3433 local_constant_declaration
3434 : CONST local_variable_type constant_declarators
3437 $$ = new DictionaryEntry ($2, $3);
3443 expression_statement
3444 : statement_expression SEMICOLON
3451 // We have to do the wrapping here and not in the case above,
3452 // because statement_expression is used for example in for_statement
3454 statement_expression
3455 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3456 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3457 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3458 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3459 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3460 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3461 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3463 Report.Error (1002, lexer.Location, "Expecting `;'");
3468 object_creation_expression
3469 : object_or_delegate_creation_expression
3470 { note ("complain if this is a delegate maybe?"); }
3479 : if_statement_open if_statement_rest
3488 oob_stack.Push (lexer.Location);
3493 : boolean_expression CLOSE_PARENS
3496 Location l = (Location) oob_stack.Pop ();
3498 $$ = new If ((Expression) $1, (Statement) $3, l);
3500 if (RootContext.WarningLevel >= 3){
3501 if ($3 == EmptyStatement.Value)
3502 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3506 | boolean_expression CLOSE_PARENS
3507 embedded_statement ELSE embedded_statement
3509 Location l = (Location) oob_stack.Pop ();
3511 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3516 : SWITCH OPEN_PARENS
3518 oob_stack.Push (lexer.Location);
3519 switch_stack.Push (current_block);
3521 expression CLOSE_PARENS
3524 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3525 current_block = (Block) switch_stack.Pop ();
3541 Report.Error (1522, lexer.Location, "Empty switch block");
3549 ArrayList sections = new ArrayList (4);
3554 | switch_sections switch_section
3556 ArrayList sections = (ArrayList) $1;
3566 current_block = current_block.CreateSwitchBlock (lexer.Location);
3570 Block topmost = current_block;
3572 while (topmost.Implicit)
3573 topmost = topmost.Parent;
3574 $$ = new SwitchSection ((ArrayList) $1, topmost);
3581 ArrayList labels = new ArrayList (4);
3586 | switch_labels switch_label
3588 ArrayList labels = (ArrayList) ($1);
3596 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3597 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3600 1523, lexer.Location,
3601 "The keyword case or default must precede code in switch block");
3615 oob_stack.Push (lexer.Location);
3617 boolean_expression CLOSE_PARENS embedded_statement
3619 Location l = (Location) oob_stack.Pop ();
3620 $$ = new While ((Expression) $4, (Statement) $6, l);
3622 if (RootContext.WarningLevel >= 3){
3623 if ($6 == EmptyStatement.Value)
3624 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3630 : DO embedded_statement
3632 oob_stack.Push (lexer.Location);
3634 boolean_expression CLOSE_PARENS SEMICOLON
3636 Location l = (Location) oob_stack.Pop ();
3638 $$ = new Do ((Statement) $2, (Expression) $6, l);
3644 opt_for_initializer SEMICOLON
3646 Block assign_block = new Block (current_block);
3647 current_block = assign_block;
3649 if ($3 is DictionaryEntry){
3650 DictionaryEntry de = (DictionaryEntry) $3;
3652 Expression type = (Expression) de.Key;
3653 ArrayList var_declarators = (ArrayList) de.Value;
3655 foreach (VariableDeclaration decl in var_declarators){
3659 vi = current_block.AddVariable (
3660 type, decl.identifier, current_local_parameters, decl.Location);
3664 Location l = lexer.Location;
3666 if (decl.expression_or_array_initializer is Expression){
3667 expr = (Expression) decl.expression_or_array_initializer;
3668 } else if (decl.expression_or_array_initializer == null) {
3671 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3672 expr = new ArrayCreation (type, "", init, decl.Location);
3675 LocalVariableReference var;
3676 var = new LocalVariableReference (assign_block, decl.identifier, l);
3679 Assign a = new Assign (var, expr, decl.Location);
3681 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3687 oob_stack.Push (lexer.Location);
3689 opt_for_condition SEMICOLON
3690 opt_for_iterator CLOSE_PARENS
3693 Location l = (Location) oob_stack.Pop ();
3695 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3697 if (RootContext.WarningLevel >= 3){
3698 if ($10 == EmptyStatement.Value)
3699 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3702 current_block.AddStatement (f);
3703 while (current_block.Implicit)
3704 current_block = current_block.Parent;
3706 current_block = current_block.Parent;
3711 : /* empty */ { $$ = EmptyStatement.Value; }
3716 : local_variable_declaration
3717 | statement_expression_list
3721 : /* empty */ { $$ = null; }
3722 | boolean_expression
3726 : /* empty */ { $$ = EmptyStatement.Value; }
3731 : statement_expression_list
3734 statement_expression_list
3735 : statement_expression
3737 // CHANGE: was `null'
3738 Block b = new Block (current_block, Block.Flags.Implicit);
3740 b.AddStatement ((Statement) $1);
3743 | statement_expression_list COMMA statement_expression
3745 Block b = (Block) $1;
3747 b.AddStatement ((Statement) $3);
3753 : FOREACH OPEN_PARENS type IDENTIFIER IN
3755 oob_stack.Push (lexer.Location);
3757 expression CLOSE_PARENS
3759 oob_stack.Push (current_block);
3761 Block foreach_block = new Block (current_block);
3762 LocalVariableReference v = null;
3763 Location l = lexer.Location;
3766 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3770 // Get a writable reference to this read-only variable.
3771 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3773 current_block = foreach_block;
3776 oob_stack.Push (current_block);
3780 Block foreach_block = (Block) oob_stack.Pop ();
3781 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3782 Block prev_block = (Block) oob_stack.Pop ();
3783 Location l = (Location) oob_stack.Pop ();
3785 current_block = prev_block;
3788 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3789 foreach_block.AddStatement (f);
3798 | continue_statement
3808 $$ = new Break (lexer.Location);
3813 : CONTINUE SEMICOLON
3815 $$ = new Continue (lexer.Location);
3820 : GOTO IDENTIFIER SEMICOLON
3822 $$ = new Goto (current_block, (string) $2, lexer.Location);
3824 | GOTO CASE constant_expression SEMICOLON
3826 $$ = new GotoCase ((Expression) $3, lexer.Location);
3828 | GOTO DEFAULT SEMICOLON
3830 $$ = new GotoDefault (lexer.Location);
3835 : RETURN opt_expression SEMICOLON
3837 $$ = new Return ((Expression) $2, lexer.Location);
3842 : THROW opt_expression SEMICOLON
3844 $$ = new Throw ((Expression) $2, lexer.Location);
3849 : IDENTIFIER RETURN expression SEMICOLON
3851 string s = (string) $1;
3853 Report.Error (1003, lexer.Location, "; expected");
3856 if (!RootContext.V2){
3857 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3860 if (iterator_container == null){
3861 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3864 iterator_container.SetYields ();
3865 $$ = new Yield ((Expression) $3, lexer.Location);
3868 | IDENTIFIER BREAK SEMICOLON
3870 string s = (string) $1;
3872 Report.Error (1003, lexer.Location, "; expected");
3875 if (!RootContext.V2){
3876 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3879 if (iterator_container == null){
3880 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3883 iterator_container.SetYields ();
3884 $$ = new YieldBreak (lexer.Location);
3895 : TRY block catch_clauses
3898 ArrayList s = new ArrayList (4);
3900 foreach (Catch cc in (ArrayList) $3) {
3907 // Now s contains the list of specific catch clauses
3908 // and g contains the general one.
3910 $$ = new Try ((Block) $2, s, g, null, lexer.Location);
3912 | TRY block opt_catch_clauses FINALLY block
3915 ArrayList s = new ArrayList (4);
3916 ArrayList catch_list = (ArrayList) $3;
3918 if (catch_list != null){
3919 foreach (Catch cc in catch_list) {
3927 $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
3931 Report.Error (1524, lexer.Location, "Expected catch or finally");
3936 : /* empty */ { $$ = null; }
3943 ArrayList l = new ArrayList (4);
3948 | catch_clauses catch_clause
3950 ArrayList l = (ArrayList) $1;
3958 : /* empty */ { $$ = null; }
3963 : CATCH opt_catch_args
3965 Expression type = null;
3969 DictionaryEntry cc = (DictionaryEntry) $2;
3970 type = (Expression) cc.Key;
3971 id = (string) cc.Value;
3974 ArrayList one = new ArrayList (4);
3975 Location loc = lexer.Location;
3977 one.Add (new VariableDeclaration (id, null, loc));
3980 current_block = new Block (current_block);
3981 Block b = declare_local_variables (type, one, loc);
3986 Expression type = null;
3990 DictionaryEntry cc = (DictionaryEntry) $2;
3991 type = (Expression) cc.Key;
3992 id = (string) cc.Value;
3996 // FIXME: I can change this for an assignment.
3998 while (current_block != (Block) $1)
3999 current_block = current_block.Parent;
4004 $$ = new Catch (type, id , (Block) $4, lexer.Location);
4009 : /* empty */ { $$ = null; }
4014 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4016 $$ = new DictionaryEntry ($2, $3);
4023 $$ = new Checked ((Block) $2);
4030 $$ = new Unchecked ((Block) $2);
4037 if (!RootContext.Unsafe){
4038 Report.Error (227, lexer.Location,
4039 "Unsafe code can only be used if --unsafe is used");
4042 $$ = new Unsafe ((Block) $3);
4048 type fixed_pointer_declarators
4051 Block assign_block = new Block (current_block, Block.Flags.Implicit);
4052 ArrayList list = (ArrayList) $4;
4053 Expression type = (Expression) $3;
4054 Location l = lexer.Location;
4055 int top = list.Count;
4057 for (int i = 0; i < top; i++){
4058 Pair p = (Pair) list [i];
4061 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4068 current_block.AddStatement (assign_block);
4069 current_block = assign_block;
4070 oob_stack.Push (assign_block);
4075 Location l = (Location) oob_stack.Pop ();
4078 $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4082 fixed_pointer_declarators
4083 : fixed_pointer_declarator {
4084 ArrayList declarators = new ArrayList (4);
4085 declarators.Add ($1);
4088 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4090 ArrayList declarators = (ArrayList) $1;
4091 declarators.Add ($3);
4096 fixed_pointer_declarator
4097 : IDENTIFIER ASSIGN expression
4099 $$ = new Pair ($1, $3);
4104 : LOCK OPEN_PARENS expression CLOSE_PARENS
4110 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4115 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4117 Block assign_block = new Block (current_block);
4118 current_block = assign_block;
4120 oob_stack.Push (lexer.Location);
4122 if ($3 is DictionaryEntry){
4123 DictionaryEntry de = (DictionaryEntry) $3;
4124 Location l = lexer.Location;
4126 Expression type = (Expression) de.Key;
4127 ArrayList var_declarators = (ArrayList) de.Value;
4129 ArrayList vars = new ArrayList (4);
4131 foreach (VariableDeclaration decl in var_declarators){
4133 LocalInfo vi = current_block.AddVariable (
4134 type, decl.identifier,
4135 current_local_parameters, decl.Location);
4141 if (decl.expression_or_array_initializer is Expression){
4142 expr = (Expression) decl.expression_or_array_initializer;
4144 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4146 expr = new ArrayCreation (type, "", init, decl.Location);
4149 LocalVariableReference var;
4151 // Get a writable reference to this read-only variable.
4152 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4154 // This is so that it is not a warning on using variables
4157 vars.Add (new DictionaryEntry (var, expr));
4159 // Assign a = new Assign (var, expr, decl.Location);
4160 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4162 $3 = new DictionaryEntry (type, vars);
4167 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4168 current_block.AddStatement (u);
4169 while (current_block.Implicit)
4170 current_block = current_block.Parent;
4172 current_block = current_block.Parent;
4176 resource_acquisition
4177 : local_variable_declaration
4184 // A class used to pass around variable declarations and constants
4186 public class VariableDeclaration {
4187 public string identifier;
4188 public object expression_or_array_initializer;
4189 public Location Location;
4190 public Attributes OptAttributes;
4192 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4194 this.identifier = id;
4195 this.expression_or_array_initializer = eoai;
4197 this.OptAttributes = opt_attrs;
4200 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4206 /// Used to pass around interface property information
4208 public class InterfaceAccessorInfo {
4210 public readonly Accessor Get, Set;
4212 public InterfaceAccessorInfo (bool has_get, bool has_set,
4213 Attributes get_attrs, Attributes set_attrs)
4216 Get = new Accessor (null, get_attrs);
4218 Set = new Accessor (null, set_attrs);
4224 // A class used to hold info about an indexer declarator
4226 public class IndexerDeclaration {
4227 public Expression type;
4228 public TypeName interface_type;
4229 public Parameters param_list;
4231 public IndexerDeclaration (Expression type, TypeName interface_type,
4232 Parameters param_list)
4235 this.interface_type = interface_type;
4236 this.param_list = param_list;
4241 // We use this when we do not have an object in advance that is an IIteratorContainer
4243 public class SimpleIteratorContainer : IIteratorContainer {
4246 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4251 public static SimpleIteratorContainer GetSimple () {
4252 Simple.Yields = false;
4256 public void SetYields () { Yields = true; }
4260 // A class used to hold info about an operator declarator
4262 public class OperatorDeclaration {
4263 public Operator.OpType optype;
4264 public Expression ret_type, arg1type, arg2type;
4265 public string arg1name, arg2name;
4266 public Location location;
4268 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4269 Expression arg1type, string arg1name,
4270 Expression arg2type, string arg2name, Location location)
4273 this.ret_type = ret_type;
4274 this.arg1type = arg1type;
4275 this.arg1name = arg1name;
4276 this.arg2type = arg2type;
4277 this.arg2name = arg2name;
4278 this.location = location;
4283 void Error_ExpectingTypeName (Location l, Expression expr)
4285 if (expr is Invocation){
4286 Report.Error (1002, l, "; expected");
4288 Report.Error (-1, l, "Invalid Type definition");
4293 // Given the @class_name name, it creates a fully qualified name
4294 // based on the containing declaration space
4297 MakeName (MemberName class_name)
4299 string ns = current_namespace.FullName;
4301 if (current_container.Name == ""){
4303 return new MemberName (new TypeName (ns), class_name);
4307 TypeName type = current_container.MemberName.MakeTypeName (lexer.Location);
4308 return new MemberName (type, class_name);
4313 // Used to report back to the user the result of a declaration
4314 // in the current declaration space
4317 CheckDef (DeclSpace.AdditionResult result, string name, Location l)
4319 if (result == DeclSpace.AdditionResult.Success)
4323 case DeclSpace.AdditionResult.NameExists:
4324 Report.Error (102, l, "The container `" + current_container.Name +
4325 "' already contains a definition for `"+
4331 // This is handled only for static Constructors, because
4332 // in reality we handle these by the semantic analysis later
4334 case DeclSpace.AdditionResult.MethodExists:
4336 111, l, "Class `"+current_container.Name+
4337 "' already defines a member called '" +
4338 name + "' with the same parameter types (more than one default constructor)");
4341 case DeclSpace.AdditionResult.EnclosingClash:
4342 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
4345 case DeclSpace.AdditionResult.NotAConstructor:
4346 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
4349 case DeclSpace.AdditionResult.Error:
4350 // Error has already been reported.
4356 CheckDef (bool result, string name, Location l)
4360 CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
4363 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4365 Block implicit_block;
4366 ArrayList inits = null;
4369 // We use the `Used' property to check whether statements
4370 // have been added to the current block. If so, we need
4371 // to create another block to contain the new declaration
4372 // otherwise, as an optimization, we use the same block to
4373 // add the declaration.
4375 // FIXME: A further optimization is to check if the statements
4376 // that were added were added as part of the initialization
4377 // below. In which case, no other statements have been executed
4378 // and we might be able to reduce the number of blocks for
4379 // situations like this:
4381 // int j = 1; int k = j + 1;
4383 if (current_block.Used)
4384 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4386 implicit_block = current_block;
4388 foreach (VariableDeclaration decl in variable_declarators){
4390 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4391 if (decl.expression_or_array_initializer != null){
4393 inits = new ArrayList (4);
4400 return implicit_block;
4402 foreach (VariableDeclaration decl in inits){
4406 if (decl.expression_or_array_initializer is Expression){
4407 expr = (Expression) decl.expression_or_array_initializer;
4410 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4412 expr = new ArrayCreation (type, "", init, decl.Location);
4415 LocalVariableReference var;
4416 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4418 assign = new Assign (var, expr, decl.Location);
4420 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4423 return implicit_block;
4426 Block declare_local_constants (Expression type, ArrayList declarators)
4428 Block implicit_block;
4430 if (current_block.Used)
4431 implicit_block = new Block (current_block, Block.Flags.Implicit);
4433 implicit_block = current_block;
4435 foreach (VariableDeclaration decl in declarators){
4436 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4437 current_local_parameters, decl.Location);
4440 return implicit_block;
4443 void CheckAttributeTarget (string a)
4447 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4451 Location l = lexer.Location;
4452 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4458 void CheckUnaryOperator (Operator.OpType op)
4462 case Operator.OpType.LogicalNot:
4463 case Operator.OpType.OnesComplement:
4464 case Operator.OpType.Increment:
4465 case Operator.OpType.Decrement:
4466 case Operator.OpType.True:
4467 case Operator.OpType.False:
4468 case Operator.OpType.Addition:
4469 case Operator.OpType.Subtraction:
4474 Location l = lexer.Location;
4475 Report.Error (1019, l, "Overloadable unary operator expected");
4481 void CheckBinaryOperator (Operator.OpType op)
4485 case Operator.OpType.Addition:
4486 case Operator.OpType.Subtraction:
4487 case Operator.OpType.Multiply:
4488 case Operator.OpType.Division:
4489 case Operator.OpType.Modulus:
4490 case Operator.OpType.BitwiseAnd:
4491 case Operator.OpType.BitwiseOr:
4492 case Operator.OpType.ExclusiveOr:
4493 case Operator.OpType.LeftShift:
4494 case Operator.OpType.RightShift:
4495 case Operator.OpType.Equality:
4496 case Operator.OpType.Inequality:
4497 case Operator.OpType.GreaterThan:
4498 case Operator.OpType.LessThan:
4499 case Operator.OpType.GreaterThanOrEqual:
4500 case Operator.OpType.LessThanOrEqual:
4504 Location l = lexer.Location;
4505 Report.Error (1020, l, "Overloadable binary operator expected");
4511 void syntax_error (Location l, string msg)
4513 Report.Error (1003, l, "Syntax error, " + msg);
4516 void output (string s)
4518 Console.WriteLine (s);
4521 void note (string s)
4523 // Used to put annotations
4528 public Tokenizer Lexer {
4534 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4536 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4537 this.name = file.Name;
4539 current_container = RootContext.Tree.Types;
4540 current_container.NamespaceEntry = current_namespace;
4541 oob_stack = new Stack ();
4542 switch_stack = new Stack ();
4544 lexer = new Tokenizer (reader, file, defines);
4547 public void parse ()
4550 if (yacc_verbose_flag)
4551 yyparse (lexer, new yydebug.yyDebugSimple ());
4554 Tokenizer tokenizer = lexer as Tokenizer;
4555 tokenizer.cleanup ();
4556 } catch (Exception e){
4557 // Please do not remove this, it is used during debugging
4560 Console.WriteLine (e);
4561 Report.Error (-25, lexer.Location, "Parsing error");
4562 if (Driver.parser_verbose)
4563 Console.WriteLine (e);
4567 void CheckToken (int error, int yyToken, string msg)
4569 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4570 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4573 Report.Error (error, lexer.Location, msg);
4576 void CheckIdentifierToken (int yyToken)
4578 CheckToken (1041, yyToken, "Identifier expected");