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 global_attributes opt_EOF
298 | global_attributes 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");
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
594 // Attributes need a string, not an expression: generic types will fail here.
596 if (current_attr_target == "assembly" || current_attr_target == "module")
597 $$ = new GlobalAttribute (current_container, current_attr_target,
598 ((Expression) $1).ToString (),
599 (ArrayList) $3, (Location) $2);
601 $$ = new Attribute (current_attr_target, ((Expression) $1).ToString (),
602 (ArrayList) $3, (Location) $2);
607 : type_name { /* reserved attribute name or identifier: 17.4 */ }
610 opt_attribute_arguments
611 : /* empty */ { $$ = null; }
612 | OPEN_PARENS attribute_arguments CLOSE_PARENS
620 : opt_positional_argument_list
625 ArrayList args = new ArrayList (4);
631 | positional_argument_list COMMA named_argument_list
633 ArrayList args = new ArrayList (4);
639 | named_argument_list
641 ArrayList args = new ArrayList (4);
650 opt_positional_argument_list
651 : /* empty */ { $$ = null; }
652 | positional_argument_list
655 positional_argument_list
658 ArrayList args = new ArrayList (4);
659 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
663 | positional_argument_list COMMA expression
665 ArrayList args = (ArrayList) $1;
666 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
675 ArrayList args = new ArrayList (4);
680 | named_argument_list COMMA named_argument
682 ArrayList args = (ArrayList) $1;
690 : IDENTIFIER ASSIGN expression
692 $$ = new DictionaryEntry (
694 new Argument ((Expression) $3, Argument.AType.Expression));
700 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
703 opt_class_member_declarations
705 | class_member_declarations
708 class_member_declarations
709 : class_member_declaration
710 | class_member_declarations
711 class_member_declaration
714 class_member_declaration
715 : constant_declaration // done
716 | field_declaration // done
717 | method_declaration // done
718 | property_declaration // done
719 | event_declaration // done
720 | indexer_declaration // done
721 | operator_declaration // done
722 | constructor_declaration // done
723 | destructor_declaration // done
733 MemberName full_struct_name = MakeName ((MemberName) $4);
735 new_struct = new Struct (current_namespace, current_container, full_struct_name,
736 (int) $2, (Attributes) $1, lexer.Location);
737 current_container = new_struct;
738 RootContext.Tree.RecordDecl (full_struct_name.GetName (true), new_struct);
739 lexer.ConstraintsParsing = true;
742 opt_type_parameter_constraints_clauses
744 lexer.ConstraintsParsing = false;
749 Struct new_struct = (Struct) current_container;
751 CheckDef (new_struct.SetParameterInfo ((ArrayList) $7), new_struct.Name, new_struct.Location);
754 new_struct.Bases = (ArrayList) $6;
756 current_container = current_container.Parent;
757 CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
760 | opt_attributes opt_modifiers STRUCT error {
761 CheckIdentifierToken (yyToken);
766 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
769 opt_struct_member_declarations
771 | struct_member_declarations
774 struct_member_declarations
775 : struct_member_declaration
776 | struct_member_declarations struct_member_declaration
779 struct_member_declaration
780 : constant_declaration
783 | property_declaration
785 | indexer_declaration
786 | operator_declaration
787 | constructor_declaration
791 * This is only included so we can flag error 575:
792 * destructors only allowed on class types
794 | destructor_declaration
805 foreach (VariableDeclaration constant in (ArrayList) $5){
806 Location l = constant.Location;
808 Const c = new Const (
809 (Expression) $4, (string) constant.identifier,
810 (Expression) constant.expression_or_array_initializer, (int) $2,
813 CheckDef (current_container.AddConstant (c), c.Name, l);
819 : constant_declarator
821 ArrayList constants = new ArrayList (4);
825 | constant_declarators COMMA constant_declarator
827 ArrayList constants = (ArrayList) $1;
834 : IDENTIFIER ASSIGN constant_expression
836 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
847 Expression type = (Expression) $3;
850 foreach (VariableDeclaration var in (ArrayList) $4){
851 Location l = var.Location;
853 Field field = new Field (type, mod, var.identifier,
854 var.expression_or_array_initializer,
857 CheckDef (current_container.AddField (field), field.Name, l);
865 Report.Error (670, lexer.Location, "void type is not allowed for fields");
870 : variable_declarator
872 ArrayList decl = new ArrayList (4);
876 | variable_declarators COMMA variable_declarator
878 ArrayList decls = (ArrayList) $1;
885 : IDENTIFIER ASSIGN variable_initializer
887 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
891 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
904 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
906 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
912 iterator_container = (IIteratorContainer) $1;
916 Method method = (Method) $1;
917 Block b = (Block) $3;
918 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
921 if ((method.ModFlags & extern_abstract) == 0){
923 501, lexer.Location, current_container.MakeName (method.Name) +
924 "must declare a body because it is not marked abstract or extern");
927 if ((method.ModFlags & Modifiers.EXTERN) != 0){
929 179, lexer.Location, current_container.MakeName (method.Name) +
930 " is declared extern, but has a body");
934 method.Block = (Block) $3;
935 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
937 current_local_parameters = null;
938 iterator_container = null;
952 1585, lexer.Location, "Member modifier `" +
953 Modifiers.Name (i) + "' must precede member type and name");
964 type namespace_or_type_name
965 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
967 lexer.ConstraintsParsing = true;
969 opt_type_parameter_constraints_clauses
971 lexer.ConstraintsParsing = false;
973 TypeName type_name = (TypeName) $4;
974 MemberName name = type_name.GetMemberName ();
976 if ($9 != null && name.TypeParameters == null)
977 Report.Error (80, lexer.Location,
978 "Contraints are not allowed on non-generic declarations");
982 GenericMethod generic = null;
983 if (name.TypeParameters != null) {
984 generic = new GenericMethod (current_namespace, current_container,
985 name, (Attributes) $1, lexer.Location);
987 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
989 method = new Method (generic, (Expression) $3, (int) $2, false, name,
990 (Parameters) $6, (Attributes) $1, lexer.Location);
992 method = new Method (current_container, (Expression) $3, (int) $2,
993 false, name, (Parameters) $6, (Attributes) $1,
996 current_local_parameters = (Parameters) $6;
1002 VOID namespace_or_type_name
1003 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1005 lexer.ConstraintsParsing = true;
1007 opt_type_parameter_constraints_clauses
1009 lexer.ConstraintsParsing = false;
1011 TypeName type_name = (TypeName) $4;
1012 MemberName name = type_name.GetMemberName ();
1014 if ($9 != null && name.TypeParameters == null)
1015 Report.Error (80, lexer.Location,
1016 "Contraints are not allowed on non-generic declarations");
1019 GenericMethod generic = null;
1020 if (name.TypeParameters != null) {
1021 generic = new GenericMethod (current_namespace, current_container,
1022 name, (Attributes) $1, lexer.Location);
1025 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
1027 method = new Method (generic, TypeManager.system_void_expr, (int) $2,
1028 false, name, (Parameters) $6, (Attributes) $1,
1031 method = new Method (current_container, TypeManager.system_void_expr,
1032 (int) $2, false, name, (Parameters) $6,
1033 (Attributes) $1, lexer.Location);
1035 current_local_parameters = (Parameters) $6;
1042 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1044 Report.Error (1585, lexer.Location,
1045 String.Format ("Modifier {0} should appear before type",
1046 Modifiers.Name ((int) $4)));
1047 TypeName type_name = (TypeName) $4;
1048 MemberName name = type_name.GetMemberName ();
1050 Method method = new Method (current_container, TypeManager.system_void_expr,
1051 0, false, name, (Parameters) $6, (Attributes) $1,
1054 current_local_parameters = (Parameters) $6;
1061 | SEMICOLON { $$ = null; }
1064 opt_formal_parameter_list
1065 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1066 | formal_parameter_list
1069 formal_parameter_list
1072 ArrayList pars_list = (ArrayList) $1;
1074 Parameter [] pars = new Parameter [pars_list.Count];
1075 pars_list.CopyTo (pars);
1077 $$ = new Parameters (pars, null, lexer.Location);
1079 | fixed_parameters COMMA parameter_array
1081 ArrayList pars_list = (ArrayList) $1;
1083 Parameter [] pars = new Parameter [pars_list.Count];
1084 pars_list.CopyTo (pars);
1086 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
1090 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1097 ArrayList pars = new ArrayList (4);
1102 | fixed_parameters COMMA fixed_parameter
1104 ArrayList pars = (ArrayList) $1;
1113 opt_parameter_modifier
1117 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1120 opt_parameter_modifier
1123 CheckIdentifierToken (yyToken);
1128 opt_parameter_modifier
1129 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1130 | parameter_modifier
1134 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1135 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1139 : opt_attributes PARAMS type IDENTIFIER
1141 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1142 note ("type must be a single-dimension array type");
1144 | opt_attributes PARAMS type error {
1145 CheckIdentifierToken (yyToken);
1150 property_declaration
1153 type namespace_or_type_name
1156 implicit_value_parameter_type = (Expression) $3;
1158 lexer.PropertyParsing = true;
1160 $$ = lexer.Location;
1162 iterator_container = SimpleIteratorContainer.GetSimple ();
1164 accessor_declarations
1166 lexer.PropertyParsing = false;
1171 Pair pair = (Pair) $7;
1172 Accessor get_block = (Accessor) pair.First;
1173 Accessor set_block = (Accessor) pair.Second;
1175 TypeName type_name = (TypeName) $4;
1176 if (type_name.TypeArguments != null)
1177 syntax_error (lexer.Location, "a property can't have type arguments");
1179 MemberName name = type_name.GetMemberName ();
1181 Location loc = (Location) $6;
1182 prop = new Property (current_container, (Expression) $3, (int) $2, false,
1183 name, (Attributes) $1, get_block, set_block, loc);
1184 if (SimpleIteratorContainer.Simple.Yields)
1187 CheckDef (current_container.AddProperty (prop), prop.Name, loc);
1188 implicit_value_parameter_type = null;
1189 iterator_container = null;
1193 accessor_declarations
1194 : get_accessor_declaration opt_set_accessor_declaration
1196 $$ = new Pair ($1, $2);
1198 | set_accessor_declaration opt_get_accessor_declaration
1200 $$ = new Pair ($2, $1);
1204 opt_get_accessor_declaration
1205 : /* empty */ { $$ = null; }
1206 | get_accessor_declaration
1209 opt_set_accessor_declaration
1210 : /* empty */ { $$ = null; }
1211 | set_accessor_declaration
1214 get_accessor_declaration
1215 : opt_attributes GET
1217 // If this is not the case, then current_local_parameters has already
1218 // been set in indexer_declaration
1219 if (parsing_indexer == false)
1220 current_local_parameters = null;
1222 current_local_parameters = indexer_parameters;
1223 lexer.PropertyParsing = false;
1227 $$ = new Accessor ((Block) $4, (Attributes) $1);
1228 current_local_parameters = null;
1229 lexer.PropertyParsing = true;
1233 set_accessor_declaration
1234 : opt_attributes SET
1237 Parameter implicit_value_parameter = new Parameter (
1238 implicit_value_parameter_type, "value",
1239 Parameter.Modifier.NONE, null);
1241 if (parsing_indexer == false) {
1242 args = new Parameter [1];
1243 args [0] = implicit_value_parameter;
1244 current_local_parameters = new Parameters (args, null, lexer.Location);
1246 Parameter [] fpars = indexer_parameters.FixedParameters;
1249 int count = fpars.Length;
1251 args = new Parameter [count + 1];
1252 fpars.CopyTo (args, 0);
1253 args [count] = implicit_value_parameter;
1256 current_local_parameters = new Parameters (
1257 args, indexer_parameters.ArrayParameter, lexer.Location);
1260 lexer.PropertyParsing = false;
1264 $$ = new Accessor ((Block) $4, (Attributes) $1);
1265 current_local_parameters = null;
1266 lexer.PropertyParsing = true;
1272 | SEMICOLON { $$ = null; }
1275 interface_declaration
1278 INTERFACE member_name
1280 Interface new_interface;
1281 MemberName full_interface_name = MakeName ((MemberName) $4);
1283 new_interface = new Interface (current_namespace, current_container, full_interface_name,
1284 (int) $2, (Attributes) $1, lexer.Location);
1285 if (current_interface != null) {
1286 Location l = lexer.Location;
1287 Report.Error (-2, l, "Internal compiler error: interface inside interface");
1289 current_interface = new_interface;
1290 current_container = new_interface;
1291 RootContext.Tree.RecordDecl (
1292 full_interface_name.GetName (true), new_interface);
1293 lexer.ConstraintsParsing = true;
1296 opt_type_parameter_constraints_clauses
1298 lexer.ConstraintsParsing = false;
1300 interface_body opt_semicolon
1302 Interface new_interface = (Interface) current_interface;
1304 CheckDef (new_interface.SetParameterInfo ((ArrayList) $7), new_interface.Name, new_interface.Location);
1306 new_interface.Bases = (ArrayList) $6;
1308 current_interface = null;
1309 current_container = current_container.Parent;
1310 CheckDef (current_container.AddInterface (new_interface),
1311 new_interface.Name, new_interface.Location);
1313 | opt_attributes opt_modifiers INTERFACE error {
1314 CheckIdentifierToken (yyToken);
1320 opt_interface_member_declarations
1324 opt_interface_member_declarations
1326 | interface_member_declarations
1329 interface_member_declarations
1330 : interface_member_declaration
1331 | interface_member_declarations interface_member_declaration
1334 interface_member_declaration
1335 : interface_method_declaration
1337 Method m = (Method) $1;
1339 CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
1341 | interface_property_declaration
1343 Property p = (Property) $1;
1345 CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
1347 | interface_event_declaration
1350 Event e = (Event) $1;
1351 CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
1354 | interface_indexer_declaration
1356 Indexer i = (Indexer) $1;
1358 current_interface.AddIndexer (i);
1366 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1371 interface_method_declaration
1372 : opt_attributes opt_new type IDENTIFIER
1373 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1376 $$ = new Method (current_container, (Expression) $3, (int) $2, true,
1377 new MemberName ((string) $4), (Parameters) $6,
1378 (Attributes) $1, lexer.Location);
1380 | opt_attributes opt_new VOID IDENTIFIER
1381 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1384 $$ = new Method (current_container, TypeManager.system_void_expr, (int) $2,
1385 true, new MemberName ((string) $4), (Parameters) $6,
1386 (Attributes) $1, lexer.Location);
1390 interface_property_declaration
1395 { lexer.PropertyParsing = true; }
1397 { lexer.PropertyParsing = false; }
1400 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1402 $$ = new Property (current_container, (Expression) $3, (int) $2, true,
1403 new MemberName ((string) $4), (Attributes) $1,
1404 pinfo.Get, pinfo.Set, lexer.Location);
1409 CheckIdentifierToken (yyToken);
1415 : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null); }
1416 | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1); }
1417 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1418 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3); }
1419 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1420 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1); }
1423 interface_event_declaration
1424 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1426 $$ = new EventField (current_container, (Expression) $4, (int) $2, true,
1427 new MemberName ((string) $5), null,
1428 (Attributes) $1, lexer.Location);
1430 | opt_attributes opt_new EVENT type error {
1431 CheckIdentifierToken (yyToken);
1434 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1435 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1438 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1439 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1444 interface_indexer_declaration
1445 : opt_attributes opt_new type THIS
1446 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1448 { lexer.PropertyParsing = true; }
1450 { lexer.PropertyParsing = false; }
1453 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1455 $$ = new Indexer (current_container, (Expression) $3, (int) $2, true,
1456 MemberName.Null, (Parameters) $6, (Attributes) $1,
1457 info.Get, info.Set, lexer.Location);
1461 operator_declaration
1462 : opt_attributes opt_modifiers operator_declarator
1464 iterator_container = SimpleIteratorContainer.GetSimple ();
1468 OperatorDeclaration decl = (OperatorDeclaration) $3;
1470 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1471 decl.arg2type, decl.arg2name, (Block) $5, (Attributes) $1, decl.location);
1473 if (SimpleIteratorContainer.Simple.Yields)
1476 // Note again, checking is done in semantic analysis
1477 current_container.AddOperator (op);
1479 current_local_parameters = null;
1480 iterator_container = null;
1486 | SEMICOLON { $$ = null; }
1489 : type OPERATOR overloadable_operator
1490 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1492 Operator.OpType op = (Operator.OpType) $3;
1493 CheckUnaryOperator (op);
1495 if (op == Operator.OpType.Addition)
1496 op = Operator.OpType.UnaryPlus;
1498 if (op == Operator.OpType.Subtraction)
1499 op = Operator.OpType.UnaryNegation;
1501 Parameter [] pars = new Parameter [1];
1503 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1505 current_local_parameters = new Parameters (pars, null, lexer.Location);
1507 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1508 null, null, lexer.Location);
1510 | type OPERATOR overloadable_operator
1512 type IDENTIFIER COMMA
1516 CheckBinaryOperator ((Operator.OpType) $3);
1518 Parameter [] pars = new Parameter [2];
1520 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1521 pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1523 current_local_parameters = new Parameters (pars, null, lexer.Location);
1525 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1526 (Expression) $5, (string) $6,
1527 (Expression) $8, (string) $9, lexer.Location);
1529 | conversion_operator_declarator
1532 overloadable_operator
1534 : BANG { $$ = Operator.OpType.LogicalNot; }
1535 | TILDE { $$ = Operator.OpType.OnesComplement; }
1536 | OP_INC { $$ = Operator.OpType.Increment; }
1537 | OP_DEC { $$ = Operator.OpType.Decrement; }
1538 | TRUE { $$ = Operator.OpType.True; }
1539 | FALSE { $$ = Operator.OpType.False; }
1540 // Unary and binary:
1541 | PLUS { $$ = Operator.OpType.Addition; }
1542 | MINUS { $$ = Operator.OpType.Subtraction; }
1544 | STAR { $$ = Operator.OpType.Multiply; }
1545 | DIV { $$ = Operator.OpType.Division; }
1546 | PERCENT { $$ = Operator.OpType.Modulus; }
1547 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1548 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1549 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1550 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1551 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1552 | OP_EQ { $$ = Operator.OpType.Equality; }
1553 | OP_NE { $$ = Operator.OpType.Inequality; }
1554 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1555 | OP_LT { $$ = Operator.OpType.LessThan; }
1556 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1557 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1560 conversion_operator_declarator
1561 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1563 Parameter [] pars = new Parameter [1];
1565 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1567 current_local_parameters = new Parameters (pars, null, lexer.Location);
1569 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1570 null, null, lexer.Location);
1572 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1574 Parameter [] pars = new Parameter [1];
1576 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1578 current_local_parameters = new Parameters (pars, null, lexer.Location);
1580 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1581 null, null, lexer.Location);
1585 syntax_error (lexer.Location, "'operator' expected");
1589 syntax_error (lexer.Location, "'operator' expected");
1593 constructor_declaration
1596 constructor_declarator
1599 Constructor c = (Constructor) $3;
1600 c.Block = (Block) $4;
1601 c.OptAttributes = (Attributes) $1;
1602 c.ModFlags = (int) $2;
1604 if (c.Name == current_container.Basename){
1605 if ((c.ModFlags & Modifiers.STATIC) != 0){
1606 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1608 515, c.Location, String.Format (
1609 "`{0}.{1}': static constructor can not have access modifiers",
1610 c.Name, current_container.Name));
1613 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1615 if (c.Initializer != null){
1618 "Static constructors can not have an explicit this or base " +
1619 "constructor invocations");
1622 if (!c.Parameters.Empty){
1624 132, c.Location, "Static constructors should not have parameters");
1627 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1630 // We let another layer check the validity of the constructor.
1631 Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1634 CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
1636 current_local_parameters = null;
1640 constructor_declarator
1642 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1644 oob_stack.Push (lexer.Location);
1646 current_local_parameters = (Parameters) $3;
1648 opt_constructor_initializer
1650 Location l = (Location) oob_stack.Pop ();
1651 $$ = new Constructor (current_container, (string) $1, 0, (Parameters) $3,
1652 (ConstructorInitializer) $6, l);
1658 | SEMICOLON { $$ = null; }
1661 opt_constructor_initializer
1662 : /* empty */ { $$ = null; }
1663 | constructor_initializer
1666 constructor_initializer
1667 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1669 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1671 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1673 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1676 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1682 : /* EMPTY */ { $$ = 0; }
1683 | UNSAFE { $$ = Modifiers.UNSAFE; }
1684 | EXTERN { $$ = Modifiers.EXTERN; }
1687 destructor_declaration
1688 : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1690 if ((string) $4 != current_container.Basename){
1691 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1692 } else if (!(current_container is Class)){
1693 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1695 Location l = lexer.Location;
1698 if (!RootContext.StdLib && current_container.Name == "System.Object")
1699 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1701 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1703 if ((m & Modifiers.UNSAFE) != 0){
1704 if (!RootContext.Unsafe){
1705 Report.Error (227, l,
1706 "Unsafe code requires the -unsafe command " +
1707 "line option to be specified");
1711 Method d = new Destructor (
1712 current_container, TypeManager.system_void_expr, m, "Finalize",
1713 new Parameters (null, null, l), (Attributes) $1, l);
1715 d.Block = (Block) $7;
1716 CheckDef (current_container.AddMethod (d), d.Name, d.Location);
1719 | opt_attributes opt_modifiers EVENT type member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
1720 string mn = (string) $5;
1722 if (mn.IndexOf ('.') != -1)
1723 Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
1725 Report.Error (71, lexer.Location, "Event declaration should use property syntax");
1732 EVENT type variable_declarators SEMICOLON
1734 foreach (VariableDeclaration var in (ArrayList) $5) {
1736 MemberName name = new MemberName (var.identifier);
1738 Event e = new EventField (current_container, (Expression) $4, (int) $2,
1740 var.expression_or_array_initializer,
1741 (Attributes) $1, lexer.Location);
1743 CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1749 EVENT type namespace_or_type_name
1752 implicit_value_parameter_type = (Expression) $4;
1753 lexer.EventParsing = true;
1754 oob_stack.Push (lexer.Location);
1756 event_accessor_declarations
1758 lexer.EventParsing = false;
1762 Location loc = (Location) oob_stack.Pop ();
1765 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1768 Pair pair = (Pair) $8;
1770 TypeName type_name = (TypeName) $5;
1771 if (type_name.TypeArguments != null)
1772 syntax_error (lexer.Location, "an event can't have type arguments");
1774 MemberName name = type_name.GetMemberName ();
1776 Event e = new EventProperty (current_container, (Expression) $4, (int) $2,
1777 false, name, null, (Attributes) $1,
1778 (Accessor) pair.First, (Accessor) pair.Second,
1781 CheckDef (current_container.AddEvent (e), e.Name, loc);
1782 implicit_value_parameter_type = null;
1787 event_accessor_declarations
1788 : add_accessor_declaration remove_accessor_declaration
1790 $$ = new Pair ($1, $2);
1792 | remove_accessor_declaration add_accessor_declaration
1794 $$ = new Pair ($2, $1);
1796 | add_accessor_declaration { $$ = null; }
1797 | remove_accessor_declaration { $$ = null; }
1800 add_accessor_declaration
1801 : opt_attributes ADD
1803 Parameter [] args = new Parameter [1];
1804 Parameter implicit_value_parameter = new Parameter (
1805 implicit_value_parameter_type, "value",
1806 Parameter.Modifier.NONE, null);
1808 args [0] = implicit_value_parameter;
1810 current_local_parameters = new Parameters (args, null, lexer.Location);
1811 lexer.EventParsing = false;
1815 $$ = new Accessor ((Block) $4, (Attributes) $1);
1816 lexer.EventParsing = true;
1818 | opt_attributes ADD error {
1819 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1824 remove_accessor_declaration
1825 : opt_attributes REMOVE
1827 Parameter [] args = new Parameter [1];
1828 Parameter implicit_value_parameter = new Parameter (
1829 implicit_value_parameter_type, "value",
1830 Parameter.Modifier.NONE, null);
1832 args [0] = implicit_value_parameter;
1834 current_local_parameters = new Parameters (args, null, lexer.Location);
1835 lexer.EventParsing = false;
1839 $$ = new Accessor ((Block) $4, (Attributes) $1);
1840 lexer.EventParsing = true;
1842 | opt_attributes REMOVE error {
1843 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1849 : opt_attributes opt_modifiers indexer_declarator
1852 IndexerDeclaration decl = (IndexerDeclaration) $3;
1854 implicit_value_parameter_type = decl.type;
1856 lexer.PropertyParsing = true;
1857 parsing_indexer = true;
1859 indexer_parameters = decl.param_list;
1860 oob_stack.Push (lexer.Location);
1862 accessor_declarations
1864 lexer.PropertyParsing = false;
1865 parsing_indexer = false;
1869 // The signature is computed from the signature of the indexer. Look
1870 // at section 3.6 on the spec
1871 Location loc = (Location) oob_stack.Pop ();
1873 IndexerDeclaration decl = (IndexerDeclaration) $3;
1874 Pair pair = (Pair) $6;
1875 Accessor get_block = (Accessor) pair.First;
1876 Accessor set_block = (Accessor) pair.Second;
1879 if (decl.interface_type != null)
1880 name = new MemberName (decl.interface_type, "");
1882 name = MemberName.Null;
1884 indexer = new Indexer (current_container, decl.type, (int) $2, false,
1885 name, decl.param_list, (Attributes) $1,
1886 get_block, set_block, loc);
1888 // Note that there is no equivalent of CheckDef for this case
1889 // We shall handle this in semantic analysis
1891 current_container.AddIndexer (indexer);
1893 current_local_parameters = null;
1894 implicit_value_parameter_type = null;
1895 indexer_parameters = null;
1900 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1902 Parameters pars = (Parameters) $4;
1904 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1905 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1908 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1910 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1912 Parameters pars = (Parameters) $6;
1914 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1915 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1917 TypeName name = (TypeName) $2;
1918 if (name.TypeArguments != null)
1919 syntax_error (lexer.Location, "an indexer can't have type arguments");
1921 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
1933 Location enum_location = lexer.Location;
1935 MemberName full_name = MakeName (new MemberName ((string) $4));
1936 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
1937 full_name, (Attributes) $1, enum_location);
1939 foreach (VariableDeclaration ev in (ArrayList) $6) {
1940 Location loc = (Location) ev.Location;
1942 CheckDef (e.AddEnumMember (ev.identifier,
1943 (Expression) ev.expression_or_array_initializer,
1944 loc, ev.OptAttributes),
1945 ev.identifier, loc);
1948 string name = full_name.GetName (false);
1949 CheckDef (current_container.AddEnum (e), name, enum_location);
1950 RootContext.Tree.RecordDecl (name, e);
1956 : /* empty */ { $$ = TypeManager.system_int32_expr; }
1957 | COLON type { $$ = $2; }
1961 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1967 opt_enum_member_declarations
1968 : /* empty */ { $$ = new ArrayList (4); }
1969 | enum_member_declarations opt_comma { $$ = $1; }
1972 enum_member_declarations
1973 : enum_member_declaration
1975 ArrayList l = new ArrayList (4);
1980 | enum_member_declarations COMMA enum_member_declaration
1982 ArrayList l = (ArrayList) $1;
1990 enum_member_declaration
1991 : opt_attributes IDENTIFIER
1993 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
1995 | opt_attributes IDENTIFIER
1997 $$ = lexer.Location;
2001 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
2005 delegate_declaration
2008 DELEGATE type member_name
2009 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2011 Location l = lexer.Location;
2012 Delegate del = new Delegate (
2013 current_namespace, current_container, (Expression) $4, (int) $2,
2014 MakeName ((MemberName) $5), (Parameters) $7, (Attributes) $1, l);
2016 CheckDef (current_container.AddDelegate (del), del.Name, l);
2018 current_delegate = del;
2020 lexer.ConstraintsParsing = true;
2022 opt_type_parameter_constraints_clauses
2024 lexer.ConstraintsParsing = false;
2028 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
2030 current_delegate = null;
2034 DELEGATE VOID member_name
2035 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2037 Location l = lexer.Location;
2038 Delegate del = new Delegate (
2039 current_namespace, current_container,
2040 TypeManager.system_void_expr, (int) $2, MakeName ((MemberName) $5),
2041 (Parameters) $7, (Attributes) $1, l);
2043 CheckDef (current_container.AddDelegate (del), del.Name, l);
2045 current_delegate = del;
2047 lexer.ConstraintsParsing = true;
2049 opt_type_parameter_constraints_clauses
2051 lexer.ConstraintsParsing = false;
2055 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
2057 current_delegate = null;
2062 : namespace_or_type_name {
2063 $$ = ((TypeName) $1).GetTypeExpression (lexer.Location);
2067 namespace_or_type_name
2068 : IDENTIFIER opt_type_argument_list {
2069 $$ = new TypeName ((string) $1, (TypeArguments) $2);
2071 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2072 $$ = new TypeName ((TypeName) $1, (string) $3, (TypeArguments) $4);
2077 : IDENTIFIER opt_type_parameter_list {
2078 $$ = new MemberName (null, (string) $1, (ArrayList) $2);
2082 opt_type_argument_list
2083 : /* empty */ { $$ = null; }
2084 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2092 TypeArguments type_args = new TypeArguments (lexer.Location);
2093 type_args.Add ((Expression) $1);
2096 | type_arguments COMMA type {
2097 TypeArguments type_args = (TypeArguments) $1;
2098 type_args.Add ((Expression) $3);
2104 * Before you think of adding a return_type, notice that we have been
2105 * using two rules in the places where it matters (one rule using type
2106 * and another identical one that uses VOID as the return type). This
2107 * gets rid of a shift/reduce couple
2110 : type_name { /* class_type */
2122 // Note that here only unmanaged types are allowed but we
2123 // can't perform checks during this phase - we do it during
2124 // semantic analysis.
2126 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2130 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2136 | non_expression_type rank_specifier
2138 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2140 | non_expression_type STAR
2142 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2144 | expression rank_specifiers
2146 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2150 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2154 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2155 // through this different path
2157 | multiplicative_expression STAR
2159 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2166 ArrayList types = new ArrayList (4);
2171 | type_list COMMA type
2173 ArrayList types = (ArrayList) $1;
2181 * replaces all the productions for isolating the various
2182 * simple types, but we need this to reuse it easily in local_variable_type
2185 : OBJECT { $$ = TypeManager.system_object_expr; }
2186 | STRING { $$ = TypeManager.system_string_expr; }
2187 | BOOL { $$ = TypeManager.system_boolean_expr; }
2188 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2189 | FLOAT { $$ = TypeManager.system_single_expr; }
2190 | DOUBLE { $$ = TypeManager.system_double_expr; }
2195 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2196 | BYTE { $$ = TypeManager.system_byte_expr; }
2197 | SHORT { $$ = TypeManager.system_int16_expr; }
2198 | USHORT { $$ = TypeManager.system_uint16_expr; }
2199 | INT { $$ = TypeManager.system_int32_expr; }
2200 | UINT { $$ = TypeManager.system_uint32_expr; }
2201 | LONG { $$ = TypeManager.system_int64_expr; }
2202 | ULONG { $$ = TypeManager.system_uint64_expr; }
2203 | CHAR { $$ = TypeManager.system_char_expr; }
2204 | VOID { $$ = TypeManager.system_void_expr; }
2212 : type rank_specifiers
2214 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2219 // Expressions, section 7.5
2231 | parenthesized_expression
2232 | default_value_expression
2234 | invocation_expression
2238 | post_increment_expression
2239 | post_decrement_expression
2243 | checked_expression
2244 | unchecked_expression
2245 | pointer_member_access
2246 | anonymous_method_expression
2253 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2254 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2255 | NULL { $$ = NullLiteral.Null; }
2259 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2260 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2261 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2266 object v = lexer.Value;
2272 $$ = IntLiteral.Zero;
2274 $$ = IntLiteral.One;
2276 $$ = new IntLiteral (i);
2277 } else if (v is uint)
2278 $$ = new UIntLiteral ((UInt32) v);
2280 $$ = new LongLiteral ((Int64) v);
2281 else if (v is ulong)
2282 $$ = new ULongLiteral ((UInt64) v);
2284 Console.WriteLine ("OOPS. Unexpected result from scanner");
2289 : TRUE { $$ = new BoolLiteral (true); }
2290 | FALSE { $$ = new BoolLiteral (false); }
2293 parenthesized_expression_0
2294 : OPEN_PARENS expression CLOSE_PARENS
2297 lexer.Deambiguate_CloseParens ();
2298 // After this, the next token returned is one of
2299 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2300 // or CLOSE_PARENS_MINUS.
2304 parenthesized_expression
2305 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2309 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2311 // If a parenthesized expression is followed by a minus, we need to wrap
2312 // the expression inside a ParenthesizedExpression for the CS0075 check
2313 // in Binary.DoResolve().
2314 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2319 : primary_expression DOT IDENTIFIER
2321 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2323 | predefined_type DOT IDENTIFIER
2325 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2333 invocation_expression
2334 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2337 Location l = lexer.Location;
2338 Report.Error (1, l, "Parse error");
2340 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2342 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2344 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2346 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2348 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2353 : /* empty */ { $$ = null; }
2360 ArrayList list = new ArrayList (4);
2364 | argument_list COMMA argument
2366 ArrayList list = (ArrayList) $1;
2370 | argument_list error {
2371 CheckToken (1026, yyToken, ", or ) expected");
2378 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2380 | REF variable_reference
2382 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2384 | OUT variable_reference
2386 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2391 : expression { note ("section 5.4"); $$ = $1; }
2395 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2397 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2399 | primary_expression rank_specifiers
2401 // So the super-trick is that primary_expression
2402 // can only be either a SimpleName or a MemberAccess.
2403 // The MemberAccess case arises when you have a fully qualified type-name like :
2405 // SimpleName is when you have
2408 Expression expr = (Expression) $1;
2409 if (expr is ComposedCast){
2410 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2411 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2412 Error_ExpectingTypeName (lexer.Location, expr);
2413 $$ = TypeManager.system_object_expr;
2416 // So we extract the string corresponding to the SimpleName
2419 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2427 ArrayList list = new ArrayList (4);
2431 | expression_list COMMA expression
2433 ArrayList list = (ArrayList) $1;
2442 $$ = new This (current_block, lexer.Location);
2447 : BASE DOT IDENTIFIER
2449 $$ = new BaseAccess ((string) $3, lexer.Location);
2451 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2453 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2456 Report.Error (175, "Use of keyword `base' is not valid in this context");
2461 post_increment_expression
2462 : primary_expression OP_INC
2464 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2465 (Expression) $1, lexer.Location);
2469 post_decrement_expression
2470 : primary_expression OP_DEC
2472 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2473 (Expression) $1, lexer.Location);
2478 : object_or_delegate_creation_expression
2479 | array_creation_expression
2482 object_or_delegate_creation_expression
2483 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2485 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2489 array_creation_expression
2490 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2492 opt_array_initializer
2494 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2496 | NEW type rank_specifiers array_initializer
2498 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2502 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2518 : rank_specifier opt_rank_specifier
2520 $$ = (string) $2 + (string) $1;
2525 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2527 $$ = "[" + (string) $2 + "]";
2547 | dim_separators COMMA
2549 $$ = (string) $1 + ",";
2553 opt_array_initializer
2565 : OPEN_BRACE CLOSE_BRACE
2567 ArrayList list = new ArrayList (4);
2570 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2572 $$ = (ArrayList) $2;
2576 variable_initializer_list
2577 : variable_initializer
2579 ArrayList list = new ArrayList (4);
2583 | variable_initializer_list COMMA variable_initializer
2585 ArrayList list = (ArrayList) $1;
2592 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2594 $$ = new TypeOfVoid (lexer.Location);
2596 | TYPEOF OPEN_PARENS type CLOSE_PARENS
2598 $$ = new TypeOf ((Expression) $3, lexer.Location);
2603 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2604 $$ = new SizeOf ((Expression) $3, lexer.Location);
2609 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2611 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2615 unchecked_expression
2616 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2618 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2622 pointer_member_access
2623 : primary_expression OP_PTR IDENTIFIER
2627 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2628 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2632 anonymous_method_expression
2633 : DELEGATE opt_anonymous_method_signature {
2634 oob_stack.Push (current_local_parameters);
2635 current_local_parameters = (Parameters)$2;
2636 create_toplevel_block = true;
2639 Report.Error (-213, lexer.Location, "Anonymous methods are not supported in this branch");
2642 create_toplevel_block = false;
2643 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2644 if (!RootContext.V2){
2645 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2648 $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
2649 current_local_parameters = (Parameters) oob_stack.Pop ();
2654 opt_anonymous_method_signature
2655 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
2656 | anonymous_method_signature
2659 anonymous_method_signature
2660 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2663 $$ = Parameters.EmptyReadOnlyParameters;
2665 ArrayList par_list = (ArrayList) $2;
2666 Parameter [] pars = new Parameter [par_list.Count];
2667 par_list.CopyTo (pars);
2668 $$ = new Parameters (pars, null, lexer.Location);
2673 opt_anonymous_method_parameter_list
2674 : /* empty */ { $$ = null; }
2675 | anonymous_method_parameter_list { $$ = $1; }
2678 anonymous_method_parameter_list
2679 : anonymous_method_parameter
2681 ArrayList a = new ArrayList (4);
2685 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2687 ArrayList a = (ArrayList) $1;
2693 anonymous_method_parameter
2694 : opt_parameter_modifier type IDENTIFIER {
2695 $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
2699 default_value_expression
2700 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
2702 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
2707 : primary_expression
2708 | BANG prefixed_unary_expression
2710 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2712 | TILDE prefixed_unary_expression
2714 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2720 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2722 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2724 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2726 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2732 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2734 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2739 // The idea to split this out is from Rhys' grammar
2740 // to solve the problem with casts.
2742 prefixed_unary_expression
2744 | PLUS prefixed_unary_expression
2746 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2748 | MINUS prefixed_unary_expression
2750 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2752 | OP_INC prefixed_unary_expression
2754 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2755 (Expression) $2, lexer.Location);
2757 | OP_DEC prefixed_unary_expression
2759 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2760 (Expression) $2, lexer.Location);
2762 | STAR prefixed_unary_expression
2764 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2766 | BITWISE_AND prefixed_unary_expression
2768 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2772 pre_increment_expression
2773 : OP_INC prefixed_unary_expression
2775 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2776 (Expression) $2, lexer.Location);
2780 pre_decrement_expression
2781 : OP_DEC prefixed_unary_expression
2783 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2784 (Expression) $2, lexer.Location);
2788 multiplicative_expression
2789 : prefixed_unary_expression
2790 | multiplicative_expression STAR prefixed_unary_expression
2792 $$ = new Binary (Binary.Operator.Multiply,
2793 (Expression) $1, (Expression) $3, lexer.Location);
2795 | multiplicative_expression DIV prefixed_unary_expression
2797 $$ = new Binary (Binary.Operator.Division,
2798 (Expression) $1, (Expression) $3, lexer.Location);
2800 | multiplicative_expression PERCENT prefixed_unary_expression
2802 $$ = new Binary (Binary.Operator.Modulus,
2803 (Expression) $1, (Expression) $3, lexer.Location);
2808 : multiplicative_expression
2809 | additive_expression PLUS multiplicative_expression
2811 $$ = new Binary (Binary.Operator.Addition,
2812 (Expression) $1, (Expression) $3, lexer.Location);
2814 | additive_expression MINUS multiplicative_expression
2816 $$ = new Binary (Binary.Operator.Subtraction,
2817 (Expression) $1, (Expression) $3, lexer.Location);
2822 : additive_expression
2823 | shift_expression OP_SHIFT_LEFT additive_expression
2825 $$ = new Binary (Binary.Operator.LeftShift,
2826 (Expression) $1, (Expression) $3, lexer.Location);
2828 | shift_expression OP_SHIFT_RIGHT additive_expression
2830 $$ = new Binary (Binary.Operator.RightShift,
2831 (Expression) $1, (Expression) $3, lexer.Location);
2835 relational_expression
2837 | relational_expression OP_LT shift_expression
2839 $$ = new Binary (Binary.Operator.LessThan,
2840 (Expression) $1, (Expression) $3, lexer.Location);
2842 | relational_expression OP_GT shift_expression
2844 $$ = new Binary (Binary.Operator.GreaterThan,
2845 (Expression) $1, (Expression) $3, lexer.Location);
2847 | relational_expression OP_LE shift_expression
2849 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2850 (Expression) $1, (Expression) $3, lexer.Location);
2852 | relational_expression OP_GE shift_expression
2854 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2855 (Expression) $1, (Expression) $3, lexer.Location);
2857 | relational_expression IS type
2859 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2861 | relational_expression AS type
2863 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2868 : relational_expression
2869 | equality_expression OP_EQ relational_expression
2871 $$ = new Binary (Binary.Operator.Equality,
2872 (Expression) $1, (Expression) $3, lexer.Location);
2874 | equality_expression OP_NE relational_expression
2876 $$ = new Binary (Binary.Operator.Inequality,
2877 (Expression) $1, (Expression) $3, lexer.Location);
2882 : equality_expression
2883 | and_expression BITWISE_AND equality_expression
2885 $$ = new Binary (Binary.Operator.BitwiseAnd,
2886 (Expression) $1, (Expression) $3, lexer.Location);
2890 exclusive_or_expression
2892 | exclusive_or_expression CARRET and_expression
2894 $$ = new Binary (Binary.Operator.ExclusiveOr,
2895 (Expression) $1, (Expression) $3, lexer.Location);
2899 inclusive_or_expression
2900 : exclusive_or_expression
2901 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2903 $$ = new Binary (Binary.Operator.BitwiseOr,
2904 (Expression) $1, (Expression) $3, lexer.Location);
2908 conditional_and_expression
2909 : inclusive_or_expression
2910 | conditional_and_expression OP_AND inclusive_or_expression
2912 $$ = new Binary (Binary.Operator.LogicalAnd,
2913 (Expression) $1, (Expression) $3, lexer.Location);
2917 conditional_or_expression
2918 : conditional_and_expression
2919 | conditional_or_expression OP_OR conditional_and_expression
2921 $$ = new Binary (Binary.Operator.LogicalOr,
2922 (Expression) $1, (Expression) $3, lexer.Location);
2926 conditional_expression
2927 : conditional_or_expression
2928 | conditional_or_expression INTERR expression COLON expression
2930 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2934 assignment_expression
2935 : prefixed_unary_expression ASSIGN expression
2937 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2939 | prefixed_unary_expression OP_MULT_ASSIGN expression
2941 Location l = lexer.Location;
2943 $$ = new CompoundAssign (
2944 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
2946 | prefixed_unary_expression OP_DIV_ASSIGN expression
2948 Location l = lexer.Location;
2950 $$ = new CompoundAssign (
2951 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
2953 | prefixed_unary_expression OP_MOD_ASSIGN expression
2955 Location l = lexer.Location;
2957 $$ = new CompoundAssign (
2958 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
2960 | prefixed_unary_expression OP_ADD_ASSIGN expression
2962 Location l = lexer.Location;
2964 $$ = new CompoundAssign (
2965 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
2967 | prefixed_unary_expression OP_SUB_ASSIGN expression
2969 Location l = lexer.Location;
2971 $$ = new CompoundAssign (
2972 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
2974 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2976 Location l = lexer.Location;
2978 $$ = new CompoundAssign (
2979 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
2981 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2983 Location l = lexer.Location;
2985 $$ = new CompoundAssign (
2986 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
2988 | prefixed_unary_expression OP_AND_ASSIGN expression
2990 Location l = lexer.Location;
2992 $$ = new CompoundAssign (
2993 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
2995 | prefixed_unary_expression OP_OR_ASSIGN expression
2997 Location l = lexer.Location;
2999 $$ = new CompoundAssign (
3000 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
3002 | prefixed_unary_expression OP_XOR_ASSIGN expression
3004 Location l = lexer.Location;
3006 $$ = new CompoundAssign (
3007 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
3012 : conditional_expression
3013 | assignment_expression
3034 MemberName name = MakeName ((MemberName) $4);
3036 new_class = new Class (current_namespace, current_container, name, (int) $2,
3037 (Attributes) $1, lexer.Location);
3038 current_container = new_class;
3039 RootContext.Tree.RecordDecl (name.GetName (true), new_class);
3041 lexer.ConstraintsParsing = true;
3044 opt_type_parameter_constraints_clauses
3046 lexer.ConstraintsParsing = false;
3051 Class new_class = (Class) current_container;
3053 CheckDef (new_class.SetParameterInfo ((ArrayList) $7), new_class.Name, new_class.Location);
3055 if (new_class.Name == "System.Object") {
3056 Report.Error (537, new_class.Location, "The class System.Object cannot have a base class or implement an interface.");
3059 new_class.Bases = (ArrayList) $6;
3061 current_container = current_container.Parent;
3062 CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
3070 lexer.ConstraintsParsing = true;
3073 Report.Error (80, lexer.Location,
3074 "Contraints are not allowed on non-generic declarations");
3081 : /* empty */ { $$ = (int) 0; }
3087 | modifiers modifier
3092 if ((m1 & m2) != 0) {
3093 Location l = lexer.Location;
3094 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3096 $$ = (int) (m1 | m2);
3101 : NEW { $$ = Modifiers.NEW; }
3102 | PUBLIC { $$ = Modifiers.PUBLIC; }
3103 | PROTECTED { $$ = Modifiers.PROTECTED; }
3104 | INTERNAL { $$ = Modifiers.INTERNAL; }
3105 | PRIVATE { $$ = Modifiers.PRIVATE; }
3106 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3107 | SEALED { $$ = Modifiers.SEALED; }
3108 | STATIC { $$ = Modifiers.STATIC; }
3109 | READONLY { $$ = Modifiers.READONLY; }
3110 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3111 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3112 | EXTERN { $$ = Modifiers.EXTERN; }
3113 | VOLATILE { $$ = Modifiers.VOLATILE; }
3114 | UNSAFE { $$ = Modifiers.UNSAFE; }
3118 : /* empty */ { $$ = null; }
3119 | class_base { $$ = $1; }
3123 : COLON type_list { $$ = $2; }
3126 opt_type_parameter_list
3127 : /* empty */ { $$ = null; }
3128 | type_parameter_list { $$ = $1; }
3132 : OP_GENERICS_LT type_parameters OP_GENERICS_GT { $$ = $2; }
3138 // Do some profiling to find the optimal size, for now we
3139 // assume most people will be generic on one type (saves space
3141 ArrayList type_parameters = new ArrayList (1);
3142 type_parameters.Add ($1);
3143 $$ = type_parameters;
3145 | type_parameters COMMA type_parameter {
3146 ArrayList type_parameters = (ArrayList) $1;
3148 type_parameters.Add ($3);
3149 $$ = type_parameters;
3157 opt_type_parameter_constraints_clauses
3158 : /* empty */ { $$ = null; }
3159 | type_parameter_constraints_clauses
3163 type_parameter_constraints_clauses
3164 : type_parameter_constraints_clause {
3165 ArrayList constraints = new ArrayList (1);
3166 constraints.Add ($1);
3169 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3170 ArrayList constraints = (ArrayList) $1;
3172 constraints.Add ($2);
3177 type_parameter_constraints_clause
3178 : WHERE type_parameter COLON type_parameter_constraints {
3179 $$ = new Constraints ((string) $2, (ArrayList) $4, lexer.Location);
3183 type_parameter_constraints
3184 : type_parameter_constraint {
3185 ArrayList constraints = new ArrayList (1);
3186 constraints.Add ($1);
3189 | type_parameter_constraints COMMA type_parameter_constraint {
3190 ArrayList constraints = (ArrayList) $1;
3192 constraints.Add ($3);
3197 type_parameter_constraint
3199 | NEW OPEN_PARENS CLOSE_PARENS {
3200 $$ = SpecialConstraint.Constructor;
3203 $$ = SpecialConstraint.ReferenceType;
3206 $$ = SpecialConstraint.ValueType;
3215 // A block is "contained" on the following places:
3217 // property_declaration as part of the accessor body (get/set)
3218 // operator_declaration
3219 // constructor_declaration
3220 // destructor_declaration
3221 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3226 if (current_block == null || create_toplevel_block){
3227 current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
3229 current_block = new Block (current_block, current_local_parameters,
3230 lexer.Location, Location.Null);
3233 opt_statement_list CLOSE_BRACE
3235 while (current_block.Implicit)
3236 current_block = current_block.Parent;
3238 current_block.SetEndLocation (lexer.Location);
3239 current_block = current_block.Parent;
3250 | statement_list statement
3254 : declaration_statement
3256 if ($1 != null && (Block) $1 != current_block){
3257 current_block.AddStatement ((Statement) $1);
3258 current_block = (Block) $1;
3261 | valid_declaration_statement
3263 current_block.AddStatement ((Statement) $1);
3268 valid_declaration_statement
3271 | expression_statement
3272 | selection_statement
3273 | iteration_statement
3277 | unchecked_statement
3285 : valid_declaration_statement
3286 | declaration_statement
3288 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
3293 Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
3301 $$ = EmptyStatement.Value;
3308 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3310 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3311 current_block.AddStatement (labeled);
3316 declaration_statement
3317 : local_variable_declaration SEMICOLON
3320 DictionaryEntry de = (DictionaryEntry) $1;
3322 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3326 | local_constant_declaration SEMICOLON
3329 DictionaryEntry de = (DictionaryEntry) $1;
3331 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3337 * The following is from Rhys' grammar:
3338 * > Types in local variable declarations must be recognized as
3339 * > expressions to prevent reduce/reduce errors in the grammar.
3340 * > The expressions are converted into types during semantic analysis.
3343 : primary_expression opt_rank_specifier
3345 // FIXME: Do something smart here regarding the composition of the type.
3347 // Ok, the above "primary_expression" is there to get rid of
3348 // both reduce/reduce and shift/reduces in the grammar, it should
3349 // really just be "type_name". If you use type_name, a reduce/reduce
3350 // creeps up. If you use namespace_or_type_name (which is all we need
3351 // really) two shift/reduces appear.
3354 // So the super-trick is that primary_expression
3355 // can only be either a SimpleName or a MemberAccess.
3356 // The MemberAccess case arises when you have a fully qualified type-name like :
3358 // SimpleName is when you have
3361 Expression expr = (Expression) $1;
3362 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3363 Error_ExpectingTypeName (lexer.Location, expr);
3367 // So we extract the string corresponding to the SimpleName
3371 if ((string) $2 == "")
3374 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3377 | builtin_types opt_rank_specifier
3379 if ((string) $2 == "")
3382 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3386 local_variable_pointer_type
3387 : primary_expression STAR
3389 Expression expr = (Expression) $1;
3390 Location l = lexer.Location;
3392 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3393 Error_ExpectingTypeName (l, expr);
3397 $$ = new ComposedCast ((Expression) $1, "*", l);
3399 | builtin_types STAR
3401 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3405 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3407 | local_variable_pointer_type STAR
3409 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3413 local_variable_declaration
3414 : local_variable_type variable_declarators
3417 $$ = new DictionaryEntry ($1, $2);
3421 | local_variable_pointer_type opt_rank_specifier variable_declarators
3426 if ((string) $2 == "")
3427 t = (Expression) $1;
3429 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3430 $$ = new DictionaryEntry (t, $3);
3436 local_constant_declaration
3437 : CONST local_variable_type constant_declarators
3440 $$ = new DictionaryEntry ($2, $3);
3446 expression_statement
3447 : statement_expression SEMICOLON
3454 // We have to do the wrapping here and not in the case above,
3455 // because statement_expression is used for example in for_statement
3457 statement_expression
3458 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3459 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3460 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3461 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3462 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3463 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3464 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3466 Report.Error (1002, lexer.Location, "Expecting `;'");
3471 object_creation_expression
3472 : object_or_delegate_creation_expression
3473 { note ("complain if this is a delegate maybe?"); }
3482 : if_statement_open if_statement_rest
3491 oob_stack.Push (lexer.Location);
3496 : boolean_expression CLOSE_PARENS
3499 Location l = (Location) oob_stack.Pop ();
3501 $$ = new If ((Expression) $1, (Statement) $3, l);
3503 if (RootContext.WarningLevel >= 3){
3504 if ($3 == EmptyStatement.Value)
3505 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3509 | boolean_expression CLOSE_PARENS
3510 embedded_statement ELSE embedded_statement
3512 Location l = (Location) oob_stack.Pop ();
3514 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3519 : SWITCH OPEN_PARENS
3521 oob_stack.Push (lexer.Location);
3522 switch_stack.Push (current_block);
3524 expression CLOSE_PARENS
3527 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3528 current_block = (Block) switch_stack.Pop ();
3544 Report.Error (1522, lexer.Location, "Empty switch block");
3552 ArrayList sections = new ArrayList (4);
3557 | switch_sections switch_section
3559 ArrayList sections = (ArrayList) $1;
3569 current_block = current_block.CreateSwitchBlock (lexer.Location);
3573 Block topmost = current_block;
3575 while (topmost.Implicit)
3576 topmost = topmost.Parent;
3577 $$ = new SwitchSection ((ArrayList) $1, topmost);
3584 ArrayList labels = new ArrayList (4);
3589 | switch_labels switch_label
3591 ArrayList labels = (ArrayList) ($1);
3599 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3600 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3603 1523, lexer.Location,
3604 "The keyword case or default must precede code in switch block");
3618 oob_stack.Push (lexer.Location);
3620 boolean_expression CLOSE_PARENS embedded_statement
3622 Location l = (Location) oob_stack.Pop ();
3623 $$ = new While ((Expression) $4, (Statement) $6, l);
3625 if (RootContext.WarningLevel >= 3){
3626 if ($6 == EmptyStatement.Value)
3627 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3633 : DO embedded_statement
3635 oob_stack.Push (lexer.Location);
3637 boolean_expression CLOSE_PARENS SEMICOLON
3639 Location l = (Location) oob_stack.Pop ();
3641 $$ = new Do ((Statement) $2, (Expression) $6, l);
3647 opt_for_initializer SEMICOLON
3649 Block assign_block = new Block (current_block);
3650 current_block = assign_block;
3652 if ($3 is DictionaryEntry){
3653 DictionaryEntry de = (DictionaryEntry) $3;
3655 Expression type = (Expression) de.Key;
3656 ArrayList var_declarators = (ArrayList) de.Value;
3658 foreach (VariableDeclaration decl in var_declarators){
3662 vi = current_block.AddVariable (
3663 type, decl.identifier, current_local_parameters, decl.Location);
3667 Location l = lexer.Location;
3669 if (decl.expression_or_array_initializer is Expression){
3670 expr = (Expression) decl.expression_or_array_initializer;
3671 } else if (decl.expression_or_array_initializer == null) {
3674 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3675 expr = new ArrayCreation (type, "", init, decl.Location);
3678 LocalVariableReference var;
3679 var = new LocalVariableReference (assign_block, decl.identifier, l);
3682 Assign a = new Assign (var, expr, decl.Location);
3684 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3690 oob_stack.Push (lexer.Location);
3692 opt_for_condition SEMICOLON
3693 opt_for_iterator CLOSE_PARENS
3696 Location l = (Location) oob_stack.Pop ();
3698 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3700 if (RootContext.WarningLevel >= 3){
3701 if ($10 == EmptyStatement.Value)
3702 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3705 current_block.AddStatement (f);
3706 while (current_block.Implicit)
3707 current_block = current_block.Parent;
3709 current_block = current_block.Parent;
3714 : /* empty */ { $$ = EmptyStatement.Value; }
3719 : local_variable_declaration
3720 | statement_expression_list
3724 : /* empty */ { $$ = null; }
3725 | boolean_expression
3729 : /* empty */ { $$ = EmptyStatement.Value; }
3734 : statement_expression_list
3737 statement_expression_list
3738 : statement_expression
3740 // CHANGE: was `null'
3741 Block b = new Block (current_block, Block.Flags.Implicit);
3743 b.AddStatement ((Statement) $1);
3746 | statement_expression_list COMMA statement_expression
3748 Block b = (Block) $1;
3750 b.AddStatement ((Statement) $3);
3756 : FOREACH OPEN_PARENS type IDENTIFIER IN
3758 oob_stack.Push (lexer.Location);
3760 expression CLOSE_PARENS
3762 oob_stack.Push (current_block);
3764 Block foreach_block = new Block (current_block);
3765 LocalVariableReference v = null;
3766 Location l = lexer.Location;
3769 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3773 // Get a writable reference to this read-only variable.
3774 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3776 current_block = foreach_block;
3779 oob_stack.Push (current_block);
3783 Block foreach_block = (Block) oob_stack.Pop ();
3784 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3785 Block prev_block = (Block) oob_stack.Pop ();
3786 Location l = (Location) oob_stack.Pop ();
3788 current_block = prev_block;
3791 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3792 foreach_block.AddStatement (f);
3801 | continue_statement
3811 $$ = new Break (lexer.Location);
3816 : CONTINUE SEMICOLON
3818 $$ = new Continue (lexer.Location);
3823 : GOTO IDENTIFIER SEMICOLON
3825 $$ = new Goto (current_block, (string) $2, lexer.Location);
3827 | GOTO CASE constant_expression SEMICOLON
3829 $$ = new GotoCase ((Expression) $3, lexer.Location);
3831 | GOTO DEFAULT SEMICOLON
3833 $$ = new GotoDefault (lexer.Location);
3838 : RETURN opt_expression SEMICOLON
3840 $$ = new Return ((Expression) $2, lexer.Location);
3845 : THROW opt_expression SEMICOLON
3847 $$ = new Throw ((Expression) $2, lexer.Location);
3852 : IDENTIFIER RETURN expression SEMICOLON
3854 string s = (string) $1;
3856 Report.Error (1003, lexer.Location, "; expected");
3859 if (!RootContext.V2){
3860 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3863 if (iterator_container == null){
3864 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3867 iterator_container.SetYields ();
3868 $$ = new Yield ((Expression) $3, lexer.Location);
3871 | IDENTIFIER BREAK SEMICOLON
3873 string s = (string) $1;
3875 Report.Error (1003, lexer.Location, "; expected");
3878 if (!RootContext.V2){
3879 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3882 if (iterator_container == null){
3883 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3886 iterator_container.SetYields ();
3887 $$ = new YieldBreak (lexer.Location);
3898 : TRY block catch_clauses
3901 ArrayList s = new ArrayList (4);
3903 foreach (Catch cc in (ArrayList) $3) {
3910 // Now s contains the list of specific catch clauses
3911 // and g contains the general one.
3913 $$ = new Try ((Block) $2, s, g, null, lexer.Location);
3915 | TRY block opt_catch_clauses FINALLY block
3918 ArrayList s = new ArrayList (4);
3919 ArrayList catch_list = (ArrayList) $3;
3921 if (catch_list != null){
3922 foreach (Catch cc in catch_list) {
3930 $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
3934 Report.Error (1524, lexer.Location, "Expected catch or finally");
3939 : /* empty */ { $$ = null; }
3946 ArrayList l = new ArrayList (4);
3951 | catch_clauses catch_clause
3953 ArrayList l = (ArrayList) $1;
3961 : /* empty */ { $$ = null; }
3966 : CATCH opt_catch_args
3968 Expression type = null;
3972 DictionaryEntry cc = (DictionaryEntry) $2;
3973 type = (Expression) cc.Key;
3974 id = (string) cc.Value;
3977 ArrayList one = new ArrayList (4);
3978 Location loc = lexer.Location;
3980 one.Add (new VariableDeclaration (id, null, loc));
3983 current_block = new Block (current_block);
3984 Block b = declare_local_variables (type, one, loc);
3989 Expression type = null;
3993 DictionaryEntry cc = (DictionaryEntry) $2;
3994 type = (Expression) cc.Key;
3995 id = (string) cc.Value;
3999 // FIXME: I can change this for an assignment.
4001 while (current_block != (Block) $1)
4002 current_block = current_block.Parent;
4007 $$ = new Catch (type, id , (Block) $4, lexer.Location);
4012 : /* empty */ { $$ = null; }
4017 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4019 $$ = new DictionaryEntry ($2, $3);
4026 $$ = new Checked ((Block) $2);
4033 $$ = new Unchecked ((Block) $2);
4040 if (!RootContext.Unsafe){
4041 Report.Error (227, lexer.Location,
4042 "Unsafe code can only be used if --unsafe is used");
4045 $$ = new Unsafe ((Block) $3);
4051 type fixed_pointer_declarators
4054 Block assign_block = new Block (current_block, Block.Flags.Implicit);
4055 ArrayList list = (ArrayList) $4;
4056 Expression type = (Expression) $3;
4057 Location l = lexer.Location;
4058 int top = list.Count;
4060 for (int i = 0; i < top; i++){
4061 Pair p = (Pair) list [i];
4064 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4071 current_block.AddStatement (assign_block);
4072 current_block = assign_block;
4073 oob_stack.Push (assign_block);
4078 Location l = (Location) oob_stack.Pop ();
4081 $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4085 fixed_pointer_declarators
4086 : fixed_pointer_declarator {
4087 ArrayList declarators = new ArrayList (4);
4088 declarators.Add ($1);
4091 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4093 ArrayList declarators = (ArrayList) $1;
4094 declarators.Add ($3);
4099 fixed_pointer_declarator
4100 : IDENTIFIER ASSIGN expression
4102 $$ = new Pair ($1, $3);
4107 : LOCK OPEN_PARENS expression CLOSE_PARENS
4113 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4118 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4120 Block assign_block = new Block (current_block);
4121 current_block = assign_block;
4123 oob_stack.Push (lexer.Location);
4125 if ($3 is DictionaryEntry){
4126 DictionaryEntry de = (DictionaryEntry) $3;
4127 Location l = lexer.Location;
4129 Expression type = (Expression) de.Key;
4130 ArrayList var_declarators = (ArrayList) de.Value;
4132 ArrayList vars = new ArrayList (4);
4134 foreach (VariableDeclaration decl in var_declarators){
4136 LocalInfo vi = current_block.AddVariable (
4137 type, decl.identifier,
4138 current_local_parameters, decl.Location);
4144 if (decl.expression_or_array_initializer is Expression){
4145 expr = (Expression) decl.expression_or_array_initializer;
4147 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4149 expr = new ArrayCreation (type, "", init, decl.Location);
4152 LocalVariableReference var;
4154 // Get a writable reference to this read-only variable.
4155 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4157 // This is so that it is not a warning on using variables
4160 vars.Add (new DictionaryEntry (var, expr));
4162 // Assign a = new Assign (var, expr, decl.Location);
4163 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4165 $3 = new DictionaryEntry (type, vars);
4170 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4171 current_block.AddStatement (u);
4172 while (current_block.Implicit)
4173 current_block = current_block.Parent;
4175 current_block = current_block.Parent;
4179 resource_acquisition
4180 : local_variable_declaration
4187 // A class used to pass around variable declarations and constants
4189 public class VariableDeclaration {
4190 public string identifier;
4191 public object expression_or_array_initializer;
4192 public Location Location;
4193 public Attributes OptAttributes;
4195 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4197 this.identifier = id;
4198 this.expression_or_array_initializer = eoai;
4200 this.OptAttributes = opt_attrs;
4203 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4209 /// Used to pass around interface property information
4211 public class InterfaceAccessorInfo {
4213 public readonly Accessor Get, Set;
4215 public InterfaceAccessorInfo (bool has_get, bool has_set,
4216 Attributes get_attrs, Attributes set_attrs)
4219 Get = new Accessor (null, get_attrs);
4221 Set = new Accessor (null, set_attrs);
4227 // A class used to hold info about an indexer declarator
4229 public class IndexerDeclaration {
4230 public Expression type;
4231 public TypeName interface_type;
4232 public Parameters param_list;
4234 public IndexerDeclaration (Expression type, TypeName interface_type,
4235 Parameters param_list)
4238 this.interface_type = interface_type;
4239 this.param_list = param_list;
4244 // We use this when we do not have an object in advance that is an IIteratorContainer
4246 public class SimpleIteratorContainer : IIteratorContainer {
4249 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4254 public static SimpleIteratorContainer GetSimple () {
4255 Simple.Yields = false;
4259 public void SetYields () { Yields = true; }
4263 // A class used to hold info about an operator declarator
4265 public class OperatorDeclaration {
4266 public Operator.OpType optype;
4267 public Expression ret_type, arg1type, arg2type;
4268 public string arg1name, arg2name;
4269 public Location location;
4271 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4272 Expression arg1type, string arg1name,
4273 Expression arg2type, string arg2name, Location location)
4276 this.ret_type = ret_type;
4277 this.arg1type = arg1type;
4278 this.arg1name = arg1name;
4279 this.arg2type = arg2type;
4280 this.arg2name = arg2name;
4281 this.location = location;
4286 void Error_ExpectingTypeName (Location l, Expression expr)
4288 if (expr is Invocation){
4289 Report.Error (1002, l, "; expected");
4291 Report.Error (-1, l, "Invalid Type definition");
4296 // Given the @class_name name, it creates a fully qualified name
4297 // based on the containing declaration space
4300 MakeName (MemberName class_name)
4302 string ns = current_namespace.FullName;
4304 if (current_container.Name == ""){
4306 return new MemberName (new TypeName (ns), class_name);
4310 TypeName type = current_container.MemberName.MakeTypeName (lexer.Location);
4311 return new MemberName (type, class_name);
4316 // Used to report back to the user the result of a declaration
4317 // in the current declaration space
4320 CheckDef (DeclSpace.AdditionResult result, string name, Location l)
4322 if (result == DeclSpace.AdditionResult.Success)
4326 case DeclSpace.AdditionResult.NameExists:
4327 Report.Error (102, l, "The container `" + current_container.Name +
4328 "' already contains a definition for `"+
4334 // This is handled only for static Constructors, because
4335 // in reality we handle these by the semantic analysis later
4337 case DeclSpace.AdditionResult.MethodExists:
4339 111, l, "Class `"+current_container.Name+
4340 "' already defines a member called '" +
4341 name + "' with the same parameter types (more than one default constructor)");
4344 case DeclSpace.AdditionResult.EnclosingClash:
4345 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
4348 case DeclSpace.AdditionResult.NotAConstructor:
4349 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
4352 case DeclSpace.AdditionResult.Error:
4353 // Error has already been reported.
4359 CheckDef (bool result, string name, Location l)
4363 CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
4366 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4368 Block implicit_block;
4369 ArrayList inits = null;
4372 // We use the `Used' property to check whether statements
4373 // have been added to the current block. If so, we need
4374 // to create another block to contain the new declaration
4375 // otherwise, as an optimization, we use the same block to
4376 // add the declaration.
4378 // FIXME: A further optimization is to check if the statements
4379 // that were added were added as part of the initialization
4380 // below. In which case, no other statements have been executed
4381 // and we might be able to reduce the number of blocks for
4382 // situations like this:
4384 // int j = 1; int k = j + 1;
4386 if (current_block.Used)
4387 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4389 implicit_block = current_block;
4391 foreach (VariableDeclaration decl in variable_declarators){
4393 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4394 if (decl.expression_or_array_initializer != null){
4396 inits = new ArrayList (4);
4403 return implicit_block;
4405 foreach (VariableDeclaration decl in inits){
4409 if (decl.expression_or_array_initializer is Expression){
4410 expr = (Expression) decl.expression_or_array_initializer;
4413 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4415 expr = new ArrayCreation (type, "", init, decl.Location);
4418 LocalVariableReference var;
4419 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4421 assign = new Assign (var, expr, decl.Location);
4423 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4426 return implicit_block;
4429 Block declare_local_constants (Expression type, ArrayList declarators)
4431 Block implicit_block;
4433 if (current_block.Used)
4434 implicit_block = new Block (current_block, Block.Flags.Implicit);
4436 implicit_block = current_block;
4438 foreach (VariableDeclaration decl in declarators){
4439 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4440 current_local_parameters, decl.Location);
4443 return implicit_block;
4446 void CheckAttributeTarget (string a)
4450 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4454 Location l = lexer.Location;
4455 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4461 void CheckUnaryOperator (Operator.OpType op)
4465 case Operator.OpType.LogicalNot:
4466 case Operator.OpType.OnesComplement:
4467 case Operator.OpType.Increment:
4468 case Operator.OpType.Decrement:
4469 case Operator.OpType.True:
4470 case Operator.OpType.False:
4471 case Operator.OpType.Addition:
4472 case Operator.OpType.Subtraction:
4477 Location l = lexer.Location;
4478 Report.Error (1019, l, "Overloadable unary operator expected");
4484 void CheckBinaryOperator (Operator.OpType op)
4488 case Operator.OpType.Addition:
4489 case Operator.OpType.Subtraction:
4490 case Operator.OpType.Multiply:
4491 case Operator.OpType.Division:
4492 case Operator.OpType.Modulus:
4493 case Operator.OpType.BitwiseAnd:
4494 case Operator.OpType.BitwiseOr:
4495 case Operator.OpType.ExclusiveOr:
4496 case Operator.OpType.LeftShift:
4497 case Operator.OpType.RightShift:
4498 case Operator.OpType.Equality:
4499 case Operator.OpType.Inequality:
4500 case Operator.OpType.GreaterThan:
4501 case Operator.OpType.LessThan:
4502 case Operator.OpType.GreaterThanOrEqual:
4503 case Operator.OpType.LessThanOrEqual:
4507 Location l = lexer.Location;
4508 Report.Error (1020, l, "Overloadable binary operator expected");
4514 void syntax_error (Location l, string msg)
4516 Report.Error (1003, l, "Syntax error, " + msg);
4519 void output (string s)
4521 Console.WriteLine (s);
4524 void note (string s)
4526 // Used to put annotations
4531 public Tokenizer Lexer {
4537 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4539 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4540 this.name = file.Name;
4542 current_container = RootContext.Tree.Types;
4543 current_container.NamespaceEntry = current_namespace;
4544 oob_stack = new Stack ();
4545 switch_stack = new Stack ();
4547 lexer = new Tokenizer (reader, file, defines);
4550 public void parse ()
4553 if (yacc_verbose_flag)
4554 yyparse (lexer, new yydebug.yyDebugSimple ());
4557 Tokenizer tokenizer = lexer as Tokenizer;
4558 tokenizer.cleanup ();
4559 } catch (Exception e){
4560 // Please do not remove this, it is used during debugging
4563 Console.WriteLine (e);
4564 Report.Error (-25, lexer.Location, "Parsing error");
4565 if (Driver.parser_verbose)
4566 Console.WriteLine (e);
4570 void CheckToken (int error, int yyToken, string msg)
4572 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4573 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4576 Report.Error (error, lexer.Location, msg);
4579 void CheckIdentifierToken (int yyToken)
4581 CheckToken (1041, yyToken, "Identifier expected");