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
103 %token NONE /* This token is never returned by our lexer */
104 %token ERROR // This is used not by the parser, but by the tokenizer.
108 *These are the C# keywords
193 /* C# keywords which are not really keywords */
199 /* C# single character operators/punctuation. */
200 %token OPEN_BRACE "{"
201 %token CLOSE_BRACE "}"
202 %token OPEN_BRACKET "["
203 %token CLOSE_BRACKET "]"
204 %token OPEN_PARENS "("
205 %token CLOSE_PARENS ")"
217 %token OP_GENERICS_LT "<"
219 %token OP_GENERICS_GT ">"
220 %token BITWISE_AND "&"
221 %token BITWISE_OR "|"
228 /* C# multi-character operators. */
231 %token OP_SHIFT_LEFT "<<"
232 %token OP_SHIFT_RIGHT ">>"
239 %token OP_MULT_ASSIGN "*="
240 %token OP_DIV_ASSIGN "/="
241 %token OP_MOD_ASSIGN "%="
242 %token OP_ADD_ASSIGN "+="
243 %token OP_SUB_ASSIGN "-="
244 %token OP_SHIFT_LEFT_ASSIGN "<<="
245 %token OP_SHIFT_RIGHT_ASSIGN ">>="
246 %token OP_AND_ASSIGN "&="
247 %token OP_XOR_ASSIGN "^="
248 %token OP_OR_ASSIGN "|="
252 %token LITERAL_INTEGER "int literal"
253 %token LITERAL_FLOAT "float literal"
254 %token LITERAL_DOUBLE "double literal"
255 %token LITERAL_DECIMAL "decimal literal"
256 %token LITERAL_CHARACTER "character literal"
257 %token LITERAL_STRING "string literal"
260 %token CLOSE_PARENS_CAST
261 %token CLOSE_PARENS_NO_CAST
262 %token CLOSE_PARENS_OPEN_PARENS
263 %token CLOSE_PARENS_MINUS
264 %token DEFAULT_OPEN_PARENS
266 /* Add precedence rules to solve dangling else s/r conflict */
275 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
277 %left STAR DIV PERCENT
278 %right BANG CARRET UMINUS
279 %nonassoc OP_INC OP_DEC
281 %left OPEN_BRACKET OPEN_BRACE
285 %start compilation_unit
289 : outer_declarations opt_EOF
290 | outer_declarations attribute_sections opt_EOF
291 | attribute_sections opt_EOF
292 | opt_EOF /* allow empty files */
302 | outer_declarations outer_declaration
307 | namespace_member_declaration
312 | using_directives using_directive
316 : using_alias_directive
317 | using_namespace_directive
320 using_alias_directive
321 : USING IDENTIFIER ASSIGN
322 namespace_or_type_name SEMICOLON
324 Expression expr = ((MemberName) $4).GetTypeExpression (lexer.Location);
325 current_namespace.UsingAlias ((string) $2, expr, lexer.Location);
328 CheckIdentifierToken (yyToken);
332 using_namespace_directive
333 : USING namespace_name SEMICOLON
335 current_namespace.Using ((string) $2, lexer.Location);
340 // Strictly speaking, namespaces don't have attributes but
341 // we parse global attributes along with namespace declarations and then
344 namespace_declaration
345 : opt_attributes NAMESPACE namespace_name
347 Attributes attrs = (Attributes) $1;
350 foreach (AttributeSection asec in attrs.AttributeSections)
351 if (asec.Target == "assembly")
352 CodeGen.Assembly.AddAttribute (current_container, asec);
354 Report.Error(1518, Lexer.Location,
355 "Attributes cannot be applied to namespaces."
356 + " Expected class, delegate, enum, interface, or struct");
359 current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, (string) $3, lexer.Location);
361 namespace_body opt_semicolon
363 current_namespace = current_namespace.Parent;
378 : namespace_or_type_name {
379 MemberName name = (MemberName) $1;
381 if (name.TypeArguments != null)
382 syntax_error (lexer.Location, "namespace name expected");
384 $$ = name.GetName ();
391 opt_namespace_member_declarations
402 opt_namespace_member_declarations
404 | namespace_member_declarations
407 namespace_member_declarations
408 : namespace_member_declaration
409 | namespace_member_declarations namespace_member_declaration
412 namespace_member_declaration
419 Class c = (Class) $1;
420 mod_flags = c.ModFlags;
422 } else if ($1 is Struct){
423 Struct s = (Struct) $1;
424 mod_flags = s.ModFlags;
429 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
431 1527, lexer.Location,
432 "Namespace elements cant be explicitly " +
433 "declared private or protected in `" + name + "'");
435 current_namespace.DeclarationFound = true;
437 | namespace_declaration {
438 current_namespace.DeclarationFound = true;
441 | field_declaration {
442 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
444 | method_declaration {
445 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
452 | interface_declaration
454 | delegate_declaration
456 // Enable this when we have handled all errors, because this acts as a generic fallback
459 // Console.WriteLine ("Token=" + yyToken);
460 // Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
470 | attribute_sections { $$ = $1; }
476 AttributeSection sect = (AttributeSection) $1;
478 if (sect.Target == "assembly") {
479 CodeGen.Assembly.AddAttribute (current_container, sect);
482 else if (sect.Target == "module") {
483 CodeGen.Module.AddAttribute (current_container, sect);
487 $$ = new Attributes (sect);
489 | attribute_sections attribute_section
491 Attributes attrs = $1 as Attributes;
492 AttributeSection sect = (AttributeSection) $2;
494 if (sect.Target == "assembly") {
495 CodeGen.Assembly.AddAttribute (current_container, sect);
497 else if (sect.Target == "module") {
498 CodeGen.Module.AddAttribute (current_container, sect);
502 attrs = new Attributes (sect);
504 attrs.AddAttributeSection (sect);
512 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
514 string target = null;
517 target = (string) $2;
519 $$ = new AttributeSection (target, (ArrayList) $3);
521 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
523 $$ = new AttributeSection (null, (ArrayList) $2);
527 attribute_target_specifier
528 : attribute_target COLON
537 CheckAttributeTarget ((string) $1);
540 | EVENT { $$ = "event"; }
541 | RETURN { $$ = "return"; }
547 ArrayList attrs = new ArrayList (4);
553 | attribute_list COMMA attribute
555 ArrayList attrs = (ArrayList) $1;
567 opt_attribute_arguments
570 // Attributes need a string, not an expression: generic types will fail here.
572 $$ = new Attribute (((Expression) $1).ToString (), (ArrayList) $3, (Location) $2);
577 : type_name { /* reserved attribute name or identifier: 17.4 */ }
580 opt_attribute_arguments
581 : /* empty */ { $$ = null; }
582 | OPEN_PARENS attribute_arguments CLOSE_PARENS
590 : opt_positional_argument_list
595 ArrayList args = new ArrayList (4);
601 | positional_argument_list COMMA named_argument_list
603 ArrayList args = new ArrayList (4);
609 | named_argument_list
611 ArrayList args = new ArrayList (4);
620 opt_positional_argument_list
621 : /* empty */ { $$ = null; }
622 | positional_argument_list
625 positional_argument_list
628 ArrayList args = new ArrayList (4);
629 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
633 | positional_argument_list COMMA expression
635 ArrayList args = (ArrayList) $1;
636 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
645 ArrayList args = new ArrayList (4);
650 | named_argument_list COMMA named_argument
652 ArrayList args = (ArrayList) $1;
660 : IDENTIFIER ASSIGN expression
662 $$ = new DictionaryEntry (
664 new Argument ((Expression) $3, Argument.AType.Expression));
670 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
673 opt_class_member_declarations
675 | class_member_declarations
678 class_member_declarations
679 : class_member_declaration
680 | class_member_declarations
681 class_member_declaration
684 class_member_declaration
685 : constant_declaration // done
686 | field_declaration // done
687 | method_declaration // done
688 | property_declaration // done
689 | event_declaration // done
690 | indexer_declaration // done
691 | operator_declaration // done
692 | constructor_declaration // done
693 | destructor_declaration // done
703 string full_struct_name = MakeName ((string) $4);
705 new_struct = new Struct (current_namespace, current_container, full_struct_name,
706 (int) $2, (Attributes) $1, lexer.Location);
707 current_container = new_struct;
708 RootContext.Tree.RecordDecl (full_struct_name, new_struct);
709 lexer.ConstraintsParsing = true;
711 opt_type_parameter_list
713 opt_type_parameter_constraints_clauses
715 lexer.ConstraintsParsing = false;
720 Struct new_struct = (Struct) current_container;
722 if ($8 != null && $6 == null)
723 Report.Error (80, lexer.Location,
724 "Contraints are not allowed on non-generic declarations");
726 CheckDef (new_struct.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_struct.Name, new_struct.Location);
729 new_struct.Bases = (ArrayList) $7;
731 current_container = current_container.Parent;
732 CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
735 | opt_attributes opt_modifiers STRUCT error {
736 CheckIdentifierToken (yyToken);
741 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
744 opt_struct_member_declarations
746 | struct_member_declarations
749 struct_member_declarations
750 : struct_member_declaration
751 | struct_member_declarations struct_member_declaration
754 struct_member_declaration
755 : constant_declaration
758 | property_declaration
760 | indexer_declaration
761 | operator_declaration
762 | constructor_declaration
766 * This is only included so we can flag error 575:
767 * destructors only allowed on class types
769 | destructor_declaration
780 foreach (VariableDeclaration constant in (ArrayList) $5){
781 Location l = constant.Location;
783 Const c = new Const (
784 (Expression) $4, (string) constant.identifier,
785 (Expression) constant.expression_or_array_initializer, (int) $2,
788 CheckDef (current_container.AddConstant (c), c.Name, l);
794 : constant_declarator
796 ArrayList constants = new ArrayList (4);
800 | constant_declarators COMMA constant_declarator
802 ArrayList constants = (ArrayList) $1;
809 : IDENTIFIER ASSIGN constant_expression
811 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
822 Expression type = (Expression) $3;
825 foreach (VariableDeclaration var in (ArrayList) $4){
826 Location l = var.Location;
828 Field field = new Field (type, mod, var.identifier,
829 var.expression_or_array_initializer,
832 CheckDef (current_container.AddField (field), field.Name, l);
840 Report.Error (670, lexer.Location, "void type is not allowed for fields");
845 : variable_declarator
847 ArrayList decl = new ArrayList (4);
851 | variable_declarators COMMA variable_declarator
853 ArrayList decls = (ArrayList) $1;
860 : IDENTIFIER ASSIGN variable_initializer
862 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
866 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
879 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
881 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
887 iterator_container = (IIteratorContainer) $1;
891 Method method = (Method) $1;
892 Block b = (Block) $3;
893 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
896 if ((method.ModFlags & extern_abstract) == 0){
898 501, lexer.Location, current_container.MakeName (method.Name) +
899 "must declare a body because it is not marked abstract or extern");
902 if ((method.ModFlags & Modifiers.EXTERN) != 0){
904 179, lexer.Location, current_container.MakeName (method.Name) +
905 " is declared extern, but has a body");
909 method.Block = (Block) $3;
910 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
912 current_local_parameters = null;
913 iterator_container = null;
927 1585, lexer.Location, "Member modifier `" +
928 Modifiers.Name (i) + "' must precede member type and name");
940 namespace_or_type_name
941 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
943 lexer.ConstraintsParsing = true;
945 opt_type_parameter_constraints_clauses
947 lexer.ConstraintsParsing = false;
949 MemberName name = (MemberName) $4;
951 if ($9 != null && name.TypeArguments == null)
952 Report.Error (80, lexer.Location,
953 "Contraints are not allowed on non-generic declarations");
957 GenericMethod generic = null;
958 if (name.TypeArguments != null) {
959 generic = new GenericMethod (current_namespace, current_container,
960 name.Name, (Attributes) $1,
963 CheckDef (generic.SetParameterInfo (name.TypeArguments, (ArrayList) $9), name.Name, lexer.Location);
965 method = new Method (generic, (Expression) $3, (int) $2, false, name,
966 (Parameters) $6, (Attributes) $1, lexer.Location);
968 method = new Method (current_container, (Expression) $3, (int) $2,
969 false, name, (Parameters) $6, (Attributes) $1,
972 current_local_parameters = (Parameters) $6;
979 namespace_or_type_name
980 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
982 lexer.ConstraintsParsing = true;
984 opt_type_parameter_constraints_clauses
986 lexer.ConstraintsParsing = false;
988 MemberName name = (MemberName) $4;
990 if ($9 != null && name.TypeArguments == null)
991 Report.Error (80, lexer.Location,
992 "Contraints are not allowed on non-generic declarations");
995 GenericMethod generic = null;
996 if (name.TypeArguments != null) {
997 generic = new GenericMethod (current_namespace, current_container,
998 name.Name, (Attributes) $1,
1002 CheckDef (generic.SetParameterInfo (name.TypeArguments, (ArrayList) $9), name.Name, lexer.Location);
1004 method = new Method (generic, TypeManager.system_void_expr, (int) $2,
1005 false, name, (Parameters) $6, (Attributes) $1,
1008 method = new Method (current_container, TypeManager.system_void_expr,
1009 (int) $2, false, name, (Parameters) $6,
1010 (Attributes) $1, lexer.Location);
1012 current_local_parameters = (Parameters) $6;
1019 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1021 Report.Error (1585, lexer.Location,
1022 String.Format ("Modifier {0} should appear before type",
1023 Modifiers.Name ((int) $4)));
1024 Method method = new Method (current_container, TypeManager.system_void_expr,
1025 0, false, (MemberName) $5, (Parameters) $6,
1026 (Attributes) $1, lexer.Location);
1028 current_local_parameters = (Parameters) $6;
1035 | SEMICOLON { $$ = null; }
1038 opt_formal_parameter_list
1039 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1040 | formal_parameter_list
1043 formal_parameter_list
1046 ArrayList pars_list = (ArrayList) $1;
1048 Parameter [] pars = new Parameter [pars_list.Count];
1049 pars_list.CopyTo (pars);
1051 $$ = new Parameters (pars, null, lexer.Location);
1053 | fixed_parameters COMMA parameter_array
1055 ArrayList pars_list = (ArrayList) $1;
1057 Parameter [] pars = new Parameter [pars_list.Count];
1058 pars_list.CopyTo (pars);
1060 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
1064 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1071 ArrayList pars = new ArrayList (4);
1076 | fixed_parameters COMMA fixed_parameter
1078 ArrayList pars = (ArrayList) $1;
1087 opt_parameter_modifier
1091 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1094 opt_parameter_modifier
1097 CheckIdentifierToken (yyToken);
1102 opt_parameter_modifier
1103 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1104 | parameter_modifier
1108 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1109 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1113 : opt_attributes PARAMS type IDENTIFIER
1115 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1116 note ("type must be a single-dimension array type");
1118 | opt_attributes PARAMS type error {
1119 CheckIdentifierToken (yyToken);
1124 property_declaration
1127 type namespace_or_type_name
1130 implicit_value_parameter_type = (Expression) $3;
1132 lexer.PropertyParsing = true;
1134 $$ = lexer.Location;
1136 iterator_container = SimpleIteratorContainer.GetSimple ();
1138 accessor_declarations
1140 lexer.PropertyParsing = false;
1145 Pair pair = (Pair) $7;
1146 Accessor get_block = (Accessor) pair.First;
1147 Accessor set_block = (Accessor) pair.Second;
1149 MemberName name = (MemberName) $4;
1150 if (name.TypeArguments != null)
1151 syntax_error (lexer.Location, "a property can't have type arguments");
1153 Location loc = (Location) $6;
1154 prop = new Property (current_container, (Expression) $3, (int) $2, false,
1155 name, (Attributes) $1, get_block, set_block, loc);
1156 if (SimpleIteratorContainer.Simple.Yields)
1159 CheckDef (current_container.AddProperty (prop), prop.Name, loc);
1160 implicit_value_parameter_type = null;
1161 iterator_container = null;
1165 accessor_declarations
1166 : get_accessor_declaration opt_set_accessor_declaration
1168 $$ = new Pair ($1, $2);
1170 | set_accessor_declaration opt_get_accessor_declaration
1172 $$ = new Pair ($2, $1);
1176 opt_get_accessor_declaration
1177 : /* empty */ { $$ = null; }
1178 | get_accessor_declaration
1181 opt_set_accessor_declaration
1182 : /* empty */ { $$ = null; }
1183 | set_accessor_declaration
1186 get_accessor_declaration
1187 : opt_attributes GET
1189 // If this is not the case, then current_local_parameters has already
1190 // been set in indexer_declaration
1191 if (parsing_indexer == false)
1192 current_local_parameters = null;
1194 current_local_parameters = indexer_parameters;
1195 lexer.PropertyParsing = false;
1199 $$ = new Accessor ((Block) $4, (Attributes) $1);
1200 current_local_parameters = null;
1201 lexer.PropertyParsing = true;
1205 set_accessor_declaration
1206 : opt_attributes SET
1209 Parameter implicit_value_parameter = new Parameter (
1210 implicit_value_parameter_type, "value",
1211 Parameter.Modifier.NONE, null);
1213 if (parsing_indexer == false) {
1214 args = new Parameter [1];
1215 args [0] = implicit_value_parameter;
1216 current_local_parameters = new Parameters (args, null, lexer.Location);
1218 Parameter [] fpars = indexer_parameters.FixedParameters;
1221 int count = fpars.Length;
1223 args = new Parameter [count + 1];
1224 fpars.CopyTo (args, 0);
1225 args [count] = implicit_value_parameter;
1228 current_local_parameters = new Parameters (
1229 args, indexer_parameters.ArrayParameter, lexer.Location);
1232 lexer.PropertyParsing = false;
1236 $$ = new Accessor ((Block) $4, (Attributes) $1);
1237 current_local_parameters = null;
1238 lexer.PropertyParsing = true;
1244 | SEMICOLON { $$ = null; }
1247 interface_declaration
1250 INTERFACE IDENTIFIER
1252 Interface new_interface;
1253 string full_interface_name = MakeName ((string) $4);
1255 new_interface = new Interface (current_namespace, current_container, full_interface_name,
1256 (int) $2, (Attributes) $1, lexer.Location);
1257 if (current_interface != null) {
1258 Location l = lexer.Location;
1259 Report.Error (-2, l, "Internal compiler error: interface inside interface");
1261 current_interface = new_interface;
1262 current_container = new_interface;
1263 RootContext.Tree.RecordDecl (full_interface_name, new_interface);
1264 lexer.ConstraintsParsing = true;
1266 opt_type_parameter_list
1268 opt_type_parameter_constraints_clauses
1270 lexer.ConstraintsParsing = false;
1272 interface_body opt_semicolon
1274 Interface new_interface = (Interface) current_interface;
1276 if ($8 != null && $6 == null)
1277 Report.Error (80, lexer.Location,
1278 "Contraints are not allowed on non-generic declarations");
1280 CheckDef (new_interface.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_interface.Name, new_interface.Location);
1282 new_interface.Bases = (ArrayList) $7;
1284 current_interface = null;
1285 current_container = current_container.Parent;
1286 CheckDef (current_container.AddInterface (new_interface),
1287 new_interface.Name, new_interface.Location);
1289 | opt_attributes opt_modifiers INTERFACE error {
1290 CheckIdentifierToken (yyToken);
1296 opt_interface_member_declarations
1300 opt_interface_member_declarations
1302 | interface_member_declarations
1305 interface_member_declarations
1306 : interface_member_declaration
1307 | interface_member_declarations interface_member_declaration
1310 interface_member_declaration
1311 : interface_method_declaration
1313 Method m = (Method) $1;
1315 CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
1317 | interface_property_declaration
1319 Property p = (Property) $1;
1321 CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
1323 | interface_event_declaration
1326 Event e = (Event) $1;
1327 CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
1330 | interface_indexer_declaration
1332 Indexer i = (Indexer) $1;
1334 current_interface.AddIndexer (i);
1342 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1347 interface_method_declaration
1348 : opt_attributes opt_new type IDENTIFIER
1349 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1352 $$ = new Method (current_container, (Expression) $3, (int) $2, true,
1353 new MemberName ((string) $4), (Parameters) $6,
1354 (Attributes) $1, lexer.Location);
1356 | opt_attributes opt_new VOID IDENTIFIER
1357 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1360 $$ = new Method (current_container, TypeManager.system_void_expr, (int) $2,
1361 true, new MemberName ((string) $4), (Parameters) $6,
1362 (Attributes) $1, lexer.Location);
1366 interface_property_declaration
1371 { lexer.PropertyParsing = true; }
1373 { lexer.PropertyParsing = false; }
1376 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1378 $$ = new Property (current_container, (Expression) $3, (int) $2, true,
1379 new MemberName ((string) $4), (Attributes) $1,
1380 pinfo.Get, pinfo.Set, lexer.Location);
1385 CheckIdentifierToken (yyToken);
1391 : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null); }
1392 | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1); }
1393 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1394 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3); }
1395 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1396 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1); }
1399 interface_event_declaration
1400 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1402 $$ = new Event ((Expression) $4, (int) $2, true,
1403 new MemberName ((string) $5), null,
1404 (Attributes) $1, null, null, lexer.Location);
1406 | opt_attributes opt_new EVENT type error {
1407 CheckIdentifierToken (yyToken);
1410 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1411 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1414 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1415 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1420 interface_indexer_declaration
1421 : opt_attributes opt_new type THIS
1422 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1424 { lexer.PropertyParsing = true; }
1426 { lexer.PropertyParsing = false; }
1429 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1431 $$ = new Indexer (current_container, (Expression) $3, (int) $2, true,
1432 MemberName.Null, (Parameters) $6, (Attributes) $1,
1433 info.Get, info.Set, lexer.Location);
1437 operator_declaration
1438 : opt_attributes opt_modifiers operator_declarator
1440 iterator_container = SimpleIteratorContainer.GetSimple ();
1444 OperatorDeclaration decl = (OperatorDeclaration) $3;
1446 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1447 decl.arg2type, decl.arg2name, (Block) $5, (Attributes) $1, decl.location);
1449 if (SimpleIteratorContainer.Simple.Yields)
1452 // Note again, checking is done in semantic analysis
1453 current_container.AddOperator (op);
1455 current_local_parameters = null;
1456 iterator_container = null;
1462 | SEMICOLON { $$ = null; }
1465 : type OPERATOR overloadable_operator
1466 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1468 Operator.OpType op = (Operator.OpType) $3;
1469 CheckUnaryOperator (op);
1471 if (op == Operator.OpType.Addition)
1472 op = Operator.OpType.UnaryPlus;
1474 if (op == Operator.OpType.Subtraction)
1475 op = Operator.OpType.UnaryNegation;
1477 Parameter [] pars = new Parameter [1];
1479 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1481 current_local_parameters = new Parameters (pars, null, lexer.Location);
1483 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1484 null, null, lexer.Location);
1486 | type OPERATOR overloadable_operator
1488 type IDENTIFIER COMMA
1492 CheckBinaryOperator ((Operator.OpType) $3);
1494 Parameter [] pars = new Parameter [2];
1496 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1497 pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1499 current_local_parameters = new Parameters (pars, null, lexer.Location);
1501 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1502 (Expression) $5, (string) $6,
1503 (Expression) $8, (string) $9, lexer.Location);
1505 | conversion_operator_declarator
1508 overloadable_operator
1510 : BANG { $$ = Operator.OpType.LogicalNot; }
1511 | TILDE { $$ = Operator.OpType.OnesComplement; }
1512 | OP_INC { $$ = Operator.OpType.Increment; }
1513 | OP_DEC { $$ = Operator.OpType.Decrement; }
1514 | TRUE { $$ = Operator.OpType.True; }
1515 | FALSE { $$ = Operator.OpType.False; }
1516 // Unary and binary:
1517 | PLUS { $$ = Operator.OpType.Addition; }
1518 | MINUS { $$ = Operator.OpType.Subtraction; }
1520 | STAR { $$ = Operator.OpType.Multiply; }
1521 | DIV { $$ = Operator.OpType.Division; }
1522 | PERCENT { $$ = Operator.OpType.Modulus; }
1523 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1524 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1525 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1526 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1527 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1528 | OP_EQ { $$ = Operator.OpType.Equality; }
1529 | OP_NE { $$ = Operator.OpType.Inequality; }
1530 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1531 | OP_LT { $$ = Operator.OpType.LessThan; }
1532 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1533 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1536 conversion_operator_declarator
1537 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1539 Parameter [] pars = new Parameter [1];
1541 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1543 current_local_parameters = new Parameters (pars, null, lexer.Location);
1545 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1546 null, null, lexer.Location);
1548 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1550 Parameter [] pars = new Parameter [1];
1552 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1554 current_local_parameters = new Parameters (pars, null, lexer.Location);
1556 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1557 null, null, lexer.Location);
1561 syntax_error (lexer.Location, "'operator' expected");
1565 syntax_error (lexer.Location, "'operator' expected");
1569 constructor_declaration
1572 constructor_declarator
1575 Constructor c = (Constructor) $3;
1576 c.Block = (Block) $4;
1577 c.OptAttributes = (Attributes) $1;
1578 c.ModFlags = (int) $2;
1580 if (c.Name == current_container.Basename){
1581 if ((c.ModFlags & Modifiers.STATIC) != 0){
1582 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1584 515, c.Location, String.Format (
1585 "`{0}.{1}': static constructor can not have access modifiers",
1586 c.Name, current_container.Name));
1589 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1591 if (c.Initializer != null){
1594 "Static constructors can not have an explicit this or base " +
1595 "constructor invocations");
1598 if (!c.Parameters.Empty){
1600 132, c.Location, "Static constructors should not have parameters");
1603 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1606 // We let another layer check the validity of the constructor.
1607 Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1610 CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
1612 current_local_parameters = null;
1616 constructor_declarator
1618 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1620 oob_stack.Push (lexer.Location);
1622 current_local_parameters = (Parameters) $3;
1624 opt_constructor_initializer
1626 Location l = (Location) oob_stack.Pop ();
1627 $$ = new Constructor (current_container, (string) $1, 0, (Parameters) $3,
1628 (ConstructorInitializer) $6, l);
1634 | SEMICOLON { $$ = null; }
1637 opt_constructor_initializer
1638 : /* empty */ { $$ = null; }
1639 | constructor_initializer
1642 constructor_initializer
1643 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1645 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1647 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1649 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1652 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1658 : /* EMPTY */ { $$ = 0; }
1659 | UNSAFE { $$ = Modifiers.UNSAFE; }
1660 | EXTERN { $$ = Modifiers.EXTERN; }
1663 destructor_declaration
1664 : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1666 if ((string) $4 != current_container.Basename){
1667 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1668 } else if (!(current_container is Class)){
1669 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1671 Location l = lexer.Location;
1674 if (!RootContext.StdLib && current_container.Name == "System.Object")
1675 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1677 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1679 if ((m & Modifiers.UNSAFE) != 0){
1680 if (!RootContext.Unsafe){
1681 Report.Error (227, l,
1682 "Unsafe code requires the --unsafe command " +
1683 "line option to be specified");
1687 Method d = new Destructor (
1688 current_container, TypeManager.system_void_expr, m, "Finalize",
1689 new Parameters (null, null, l), (Attributes) $1, l);
1691 d.Block = (Block) $7;
1692 CheckDef (current_container.AddMethod (d), d.Name, d.Location);
1700 EVENT type variable_declarators SEMICOLON
1702 foreach (VariableDeclaration var in (ArrayList) $5) {
1704 MemberName name = new MemberName (var.identifier);
1706 Event e = new Event ((Expression) $4, (int) $2, false, name,
1707 var.expression_or_array_initializer,
1708 (Attributes) $1, null, null, lexer.Location);
1710 CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1716 EVENT type namespace_or_type_name
1719 implicit_value_parameter_type = (Expression) $4;
1720 lexer.EventParsing = true;
1721 oob_stack.Push (lexer.Location);
1723 event_accessor_declarations
1725 lexer.EventParsing = false;
1729 Location loc = (Location) oob_stack.Pop ();
1732 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1735 Pair pair = (Pair) $8;
1736 Accessor add_accessor = null;
1737 Accessor rem_accessor = null;
1739 if (pair.First != null)
1740 add_accessor = (Accessor) pair.First;
1741 if (pair.Second != null)
1742 rem_accessor = (Accessor) pair.Second;
1744 MemberName name = (MemberName) $5;
1745 if (name.TypeArguments != null)
1746 syntax_error (lexer.Location, "an event can't have type arguments");
1748 Event e = new Event ((Expression) $4, (int) $2, false, name, null,
1749 (Attributes) $1, add_accessor, rem_accessor, loc);
1751 CheckDef (current_container.AddEvent (e), e.Name, loc);
1752 implicit_value_parameter_type = null;
1757 event_accessor_declarations
1758 : add_accessor_declaration remove_accessor_declaration
1760 $$ = new Pair ($1, $2);
1762 | remove_accessor_declaration add_accessor_declaration
1764 $$ = new Pair ($2, $1);
1766 | add_accessor_declaration { $$ = null; }
1767 | remove_accessor_declaration { $$ = null; }
1770 add_accessor_declaration
1771 : opt_attributes ADD
1773 Parameter [] args = new Parameter [1];
1774 Parameter implicit_value_parameter = new Parameter (
1775 implicit_value_parameter_type, "value",
1776 Parameter.Modifier.NONE, null);
1778 args [0] = implicit_value_parameter;
1780 current_local_parameters = new Parameters (args, null, lexer.Location);
1781 lexer.EventParsing = false;
1785 $$ = new Accessor ((Block) $4, (Attributes) $1);
1786 lexer.EventParsing = true;
1788 | opt_attributes ADD error {
1789 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1794 remove_accessor_declaration
1795 : opt_attributes REMOVE
1797 Parameter [] args = new Parameter [1];
1798 Parameter implicit_value_parameter = new Parameter (
1799 implicit_value_parameter_type, "value",
1800 Parameter.Modifier.NONE, null);
1802 args [0] = implicit_value_parameter;
1804 current_local_parameters = new Parameters (args, null, lexer.Location);
1805 lexer.EventParsing = false;
1809 $$ = new Accessor ((Block) $4, (Attributes) $1);
1810 lexer.EventParsing = true;
1812 | opt_attributes REMOVE error {
1813 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1819 : opt_attributes opt_modifiers indexer_declarator
1822 IndexerDeclaration decl = (IndexerDeclaration) $3;
1824 implicit_value_parameter_type = decl.type;
1826 lexer.PropertyParsing = true;
1827 parsing_indexer = true;
1829 indexer_parameters = decl.param_list;
1830 oob_stack.Push (lexer.Location);
1832 accessor_declarations
1834 lexer.PropertyParsing = false;
1835 parsing_indexer = false;
1839 // The signature is computed from the signature of the indexer. Look
1840 // at section 3.6 on the spec
1841 Location loc = (Location) oob_stack.Pop ();
1843 IndexerDeclaration decl = (IndexerDeclaration) $3;
1844 Pair pair = (Pair) $6;
1845 Accessor get_block = (Accessor) pair.First;
1846 Accessor set_block = (Accessor) pair.Second;
1849 if (decl.interface_type != null)
1850 name = new MemberName (decl.interface_type, "", null);
1852 name = MemberName.Null;
1854 indexer = new Indexer (current_container, decl.type, (int) $2, false,
1855 name, decl.param_list, (Attributes) $1,
1856 get_block, set_block, loc);
1858 // Note that there is no equivalent of CheckDef for this case
1859 // We shall handle this in semantic analysis
1861 current_container.AddIndexer (indexer);
1863 current_local_parameters = null;
1864 implicit_value_parameter_type = null;
1865 indexer_parameters = null;
1870 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1872 Parameters pars = (Parameters) $4;
1874 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1875 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1878 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1880 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1882 Parameters pars = (Parameters) $6;
1884 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1885 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1887 MemberName name = (MemberName) $2;
1888 if (name.TypeArguments != null)
1889 syntax_error (lexer.Location, "an indexer can't have type arguments");
1891 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
1903 Location enum_location = lexer.Location;
1905 string full_name = MakeName ((string) $4);
1906 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
1907 full_name, (Attributes) $1, enum_location);
1909 foreach (VariableDeclaration ev in (ArrayList) $6) {
1910 Location loc = (Location) ev.Location;
1912 CheckDef (e.AddEnumMember (ev.identifier,
1913 (Expression) ev.expression_or_array_initializer,
1914 loc, ev.OptAttributes),
1915 ev.identifier, loc);
1918 CheckDef (current_container.AddEnum (e), full_name, enum_location);
1919 RootContext.Tree.RecordDecl (full_name, e);
1925 : /* empty */ { $$ = TypeManager.system_int32_expr; }
1926 | COLON type { $$ = $2; }
1930 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1936 opt_enum_member_declarations
1937 : /* empty */ { $$ = new ArrayList (4); }
1938 | enum_member_declarations opt_comma { $$ = $1; }
1941 enum_member_declarations
1942 : enum_member_declaration
1944 ArrayList l = new ArrayList (4);
1949 | enum_member_declarations COMMA enum_member_declaration
1951 ArrayList l = (ArrayList) $1;
1959 enum_member_declaration
1960 : opt_attributes IDENTIFIER
1962 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
1964 | opt_attributes IDENTIFIER
1966 $$ = lexer.Location;
1970 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
1974 delegate_declaration
1977 DELEGATE type IDENTIFIER
1978 opt_type_parameter_list
1979 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1981 Location l = lexer.Location;
1982 Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
1983 (int) $2, MakeName ((string) $5), (Parameters) $8,
1984 (Attributes) $1, l);
1986 CheckDef (current_container.AddDelegate (del), del.Name, l);
1988 current_delegate = del;
1990 lexer.ConstraintsParsing = true;
1992 opt_type_parameter_constraints_clauses
1994 lexer.ConstraintsParsing = false;
1998 if ($11 != null && $6 == null)
1999 Report.Error (80, lexer.Location,
2000 "Contraints are not allowed on non-generic declarations");
2003 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $6, (ArrayList) $11), current_delegate.Name, current_delegate.Location);
2005 current_delegate = null;
2009 DELEGATE VOID IDENTIFIER
2010 opt_type_parameter_list
2011 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2013 Location l = lexer.Location;
2014 Delegate del = new Delegate (
2015 current_namespace, current_container,
2016 TypeManager.system_void_expr, (int) $2, MakeName ((string) $5),
2017 (Parameters) $8, (Attributes) $1, l);
2019 CheckDef (current_container.AddDelegate (del), del.Name, l);
2021 current_delegate = del;
2023 lexer.ConstraintsParsing = true;
2025 opt_type_parameter_constraints_clauses
2027 lexer.ConstraintsParsing = false;
2031 if ($11 != null && $6 == null)
2032 Report.Error (80, lexer.Location,
2033 "Contraints are not allowed on non-generic declarations");
2036 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $6, (ArrayList) $11), current_delegate.Name, current_delegate.Location);
2038 current_delegate = null;
2043 : namespace_or_type_name {
2044 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2048 namespace_or_type_name
2049 : IDENTIFIER opt_type_argument_list {
2050 $$ = new MemberName ((string) $1, (TypeArguments) $2);
2052 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2053 $$ = new MemberName ((MemberName) $1, (string) $3, (TypeArguments) $4);
2055 // | namespace_or_type_name DOT DEFAULT
2057 // $$ = new DefaultValueExpression ((Expression) $1, lexer.Location);
2063 // Figure out what to do with the list
2065 opt_type_argument_list
2066 : /* empty */ { $$ = null; }
2067 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2075 TypeArguments type_args = new TypeArguments (lexer.Location);
2076 type_args.Add ((Expression) $1);
2079 | type_arguments COMMA type {
2080 TypeArguments type_args = (TypeArguments) $1;
2081 type_args.Add ((Expression) $3);
2087 * Before you think of adding a return_type, notice that we have been
2088 * using two rules in the places where it matters (one rule using type
2089 * and another identical one that uses VOID as the return type). This
2090 * gets rid of a shift/reduce couple
2093 : type_name { /* class_type */
2105 // Note that here only unmanaged types are allowed but we
2106 // can't perform checks during this phase - we do it during
2107 // semantic analysis.
2109 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2113 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2119 | non_expression_type rank_specifier
2121 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2123 | non_expression_type STAR
2125 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2127 | expression rank_specifiers
2129 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2133 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2137 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2138 // through this different path
2140 | multiplicative_expression STAR
2142 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2149 ArrayList types = new ArrayList (4);
2154 | type_list COMMA type
2156 ArrayList types = (ArrayList) $1;
2164 * replaces all the productions for isolating the various
2165 * simple types, but we need this to reuse it easily in local_variable_type
2168 : OBJECT { $$ = TypeManager.system_object_expr; }
2169 | STRING { $$ = TypeManager.system_string_expr; }
2170 | BOOL { $$ = TypeManager.system_boolean_expr; }
2171 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2172 | FLOAT { $$ = TypeManager.system_single_expr; }
2173 | DOUBLE { $$ = TypeManager.system_double_expr; }
2178 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2179 | BYTE { $$ = TypeManager.system_byte_expr; }
2180 | SHORT { $$ = TypeManager.system_int16_expr; }
2181 | USHORT { $$ = TypeManager.system_uint16_expr; }
2182 | INT { $$ = TypeManager.system_int32_expr; }
2183 | UINT { $$ = TypeManager.system_uint32_expr; }
2184 | LONG { $$ = TypeManager.system_int64_expr; }
2185 | ULONG { $$ = TypeManager.system_uint64_expr; }
2186 | CHAR { $$ = TypeManager.system_char_expr; }
2187 | VOID { $$ = TypeManager.system_void_expr; }
2195 : type rank_specifiers
2197 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2202 // Expressions, section 7.5
2214 | parenthesized_expression
2215 | default_value_expression
2217 | invocation_expression
2221 | post_increment_expression
2222 | post_decrement_expression
2226 | checked_expression
2227 | unchecked_expression
2228 | pointer_member_access
2229 | anonymous_method_expression
2236 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2237 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2238 | NULL { $$ = NullLiteral.Null; }
2242 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2243 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2244 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2249 object v = lexer.Value;
2255 $$ = IntLiteral.Zero;
2257 $$ = IntLiteral.One;
2259 $$ = new IntLiteral (i);
2260 } else if (v is uint)
2261 $$ = new UIntLiteral ((UInt32) v);
2263 $$ = new LongLiteral ((Int64) v);
2264 else if (v is ulong)
2265 $$ = new ULongLiteral ((UInt64) v);
2267 Console.WriteLine ("OOPS. Unexpected result from scanner");
2272 : TRUE { $$ = new BoolLiteral (true); }
2273 | FALSE { $$ = new BoolLiteral (false); }
2276 parenthesized_expression_0
2277 : OPEN_PARENS expression CLOSE_PARENS
2280 lexer.Deambiguate_CloseParens ();
2281 // After this, the next token returned is one of
2282 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2283 // or CLOSE_PARENS_MINUS.
2287 parenthesized_expression
2288 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2292 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2294 // If a parenthesized expression is followed by a minus, we need to wrap
2295 // the expression inside a ParenthesizedExpression for the CS0075 check
2296 // in Binary.DoResolve().
2297 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2302 : primary_expression DOT IDENTIFIER
2304 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2306 | predefined_type DOT IDENTIFIER
2308 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2316 invocation_expression
2317 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2320 Location l = lexer.Location;
2321 Report.Error (1, l, "Parse error");
2323 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2325 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2327 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2329 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2331 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2336 : /* empty */ { $$ = null; }
2343 ArrayList list = new ArrayList (4);
2347 | argument_list COMMA argument
2349 ArrayList list = (ArrayList) $1;
2353 | argument_list error {
2354 CheckToken (1026, yyToken, ", or ) expected");
2361 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2363 | REF variable_reference
2365 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2367 | OUT variable_reference
2369 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2374 : expression { note ("section 5.4"); $$ = $1; }
2378 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2380 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2382 | primary_expression rank_specifiers
2384 // So the super-trick is that primary_expression
2385 // can only be either a SimpleName or a MemberAccess.
2386 // The MemberAccess case arises when you have a fully qualified type-name like :
2388 // SimpleName is when you have
2391 Expression expr = (Expression) $1;
2392 if (expr is ComposedCast){
2393 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2394 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2395 Error_ExpectingTypeName (lexer.Location, expr);
2396 $$ = TypeManager.system_object_expr;
2399 // So we extract the string corresponding to the SimpleName
2402 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2410 ArrayList list = new ArrayList (4);
2414 | expression_list COMMA expression
2416 ArrayList list = (ArrayList) $1;
2425 $$ = new This (current_block, lexer.Location);
2430 : BASE DOT IDENTIFIER
2432 $$ = new BaseAccess ((string) $3, lexer.Location);
2434 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2436 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2439 Report.Error (175, "Use of keyword `base' is not valid in this context");
2444 post_increment_expression
2445 : primary_expression OP_INC
2447 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2448 (Expression) $1, lexer.Location);
2452 post_decrement_expression
2453 : primary_expression OP_DEC
2455 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2456 (Expression) $1, lexer.Location);
2461 : object_or_delegate_creation_expression
2462 | array_creation_expression
2465 object_or_delegate_creation_expression
2466 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2468 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2472 array_creation_expression
2473 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2475 opt_array_initializer
2477 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2479 | NEW type rank_specifiers array_initializer
2481 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2485 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2501 : rank_specifier opt_rank_specifier
2503 $$ = (string) $2 + (string) $1;
2508 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2510 $$ = "[" + (string) $2 + "]";
2530 | dim_separators COMMA
2532 $$ = (string) $1 + ",";
2536 opt_array_initializer
2548 : OPEN_BRACE CLOSE_BRACE
2550 ArrayList list = new ArrayList (4);
2553 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2555 $$ = (ArrayList) $2;
2559 variable_initializer_list
2560 : variable_initializer
2562 ArrayList list = new ArrayList (4);
2566 | variable_initializer_list COMMA variable_initializer
2568 ArrayList list = (ArrayList) $1;
2575 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2577 $$ = new TypeOfVoid (lexer.Location);
2579 | TYPEOF OPEN_PARENS type CLOSE_PARENS
2581 $$ = new TypeOf ((Expression) $3, lexer.Location);
2586 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2587 $$ = new SizeOf ((Expression) $3, lexer.Location);
2592 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2594 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2598 unchecked_expression
2599 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2601 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2605 pointer_member_access
2606 : primary_expression OP_PTR IDENTIFIER
2610 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2611 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2615 anonymous_method_expression
2616 : DELEGATE opt_anonymous_method_signature {
2617 oob_stack.Push (current_local_parameters);
2618 current_local_parameters = (Parameters)$2;
2619 create_toplevel_block = true;
2621 create_toplevel_block = false;
2622 if (!RootContext.V2){
2623 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2626 $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
2627 current_local_parameters = (Parameters) oob_stack.Pop ();
2631 opt_anonymous_method_signature
2632 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
2633 | anonymous_method_signature
2636 anonymous_method_signature
2637 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2640 $$ = Parameters.EmptyReadOnlyParameters;
2642 ArrayList par_list = (ArrayList) $2;
2643 Parameter [] pars = new Parameter [par_list.Count];
2644 par_list.CopyTo (pars);
2645 $$ = new Parameters (pars, null, lexer.Location);
2650 opt_anonymous_method_parameter_list
2651 : /* empty */ { $$ = null; }
2652 | anonymous_method_parameter_list { $$ = $1; }
2655 anonymous_method_parameter_list
2656 : anonymous_method_parameter
2658 ArrayList a = new ArrayList (4);
2662 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2664 ArrayList a = (ArrayList) $1;
2670 anonymous_method_parameter
2671 : opt_parameter_modifier type IDENTIFIER {
2672 $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
2676 default_value_expression
2677 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
2679 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
2684 : primary_expression
2685 | BANG prefixed_unary_expression
2687 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2689 | TILDE prefixed_unary_expression
2691 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2697 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2699 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2701 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2703 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2709 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2711 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2716 // The idea to split this out is from Rhys' grammar
2717 // to solve the problem with casts.
2719 prefixed_unary_expression
2721 | PLUS prefixed_unary_expression
2723 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2725 | MINUS prefixed_unary_expression
2727 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2729 | OP_INC prefixed_unary_expression
2731 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2732 (Expression) $2, lexer.Location);
2734 | OP_DEC prefixed_unary_expression
2736 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2737 (Expression) $2, lexer.Location);
2739 | STAR prefixed_unary_expression
2741 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2743 | BITWISE_AND prefixed_unary_expression
2745 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2749 pre_increment_expression
2750 : OP_INC prefixed_unary_expression
2752 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2753 (Expression) $2, lexer.Location);
2757 pre_decrement_expression
2758 : OP_DEC prefixed_unary_expression
2760 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2761 (Expression) $2, lexer.Location);
2765 multiplicative_expression
2766 : prefixed_unary_expression
2767 | multiplicative_expression STAR prefixed_unary_expression
2769 $$ = new Binary (Binary.Operator.Multiply,
2770 (Expression) $1, (Expression) $3, lexer.Location);
2772 | multiplicative_expression DIV prefixed_unary_expression
2774 $$ = new Binary (Binary.Operator.Division,
2775 (Expression) $1, (Expression) $3, lexer.Location);
2777 | multiplicative_expression PERCENT prefixed_unary_expression
2779 $$ = new Binary (Binary.Operator.Modulus,
2780 (Expression) $1, (Expression) $3, lexer.Location);
2785 : multiplicative_expression
2786 | additive_expression PLUS multiplicative_expression
2788 $$ = new Binary (Binary.Operator.Addition,
2789 (Expression) $1, (Expression) $3, lexer.Location);
2791 | additive_expression MINUS multiplicative_expression
2793 $$ = new Binary (Binary.Operator.Subtraction,
2794 (Expression) $1, (Expression) $3, lexer.Location);
2799 : additive_expression
2800 | shift_expression OP_SHIFT_LEFT additive_expression
2802 $$ = new Binary (Binary.Operator.LeftShift,
2803 (Expression) $1, (Expression) $3, lexer.Location);
2805 | shift_expression OP_SHIFT_RIGHT additive_expression
2807 $$ = new Binary (Binary.Operator.RightShift,
2808 (Expression) $1, (Expression) $3, lexer.Location);
2812 relational_expression
2814 | relational_expression OP_LT shift_expression
2816 $$ = new Binary (Binary.Operator.LessThan,
2817 (Expression) $1, (Expression) $3, lexer.Location);
2819 | relational_expression OP_GT shift_expression
2821 $$ = new Binary (Binary.Operator.GreaterThan,
2822 (Expression) $1, (Expression) $3, lexer.Location);
2824 | relational_expression OP_LE shift_expression
2826 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2827 (Expression) $1, (Expression) $3, lexer.Location);
2829 | relational_expression OP_GE shift_expression
2831 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2832 (Expression) $1, (Expression) $3, lexer.Location);
2834 | relational_expression IS type
2836 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2838 | relational_expression AS type
2840 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2845 : relational_expression
2846 | equality_expression OP_EQ relational_expression
2848 $$ = new Binary (Binary.Operator.Equality,
2849 (Expression) $1, (Expression) $3, lexer.Location);
2851 | equality_expression OP_NE relational_expression
2853 $$ = new Binary (Binary.Operator.Inequality,
2854 (Expression) $1, (Expression) $3, lexer.Location);
2859 : equality_expression
2860 | and_expression BITWISE_AND equality_expression
2862 $$ = new Binary (Binary.Operator.BitwiseAnd,
2863 (Expression) $1, (Expression) $3, lexer.Location);
2867 exclusive_or_expression
2869 | exclusive_or_expression CARRET and_expression
2871 $$ = new Binary (Binary.Operator.ExclusiveOr,
2872 (Expression) $1, (Expression) $3, lexer.Location);
2876 inclusive_or_expression
2877 : exclusive_or_expression
2878 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2880 $$ = new Binary (Binary.Operator.BitwiseOr,
2881 (Expression) $1, (Expression) $3, lexer.Location);
2885 conditional_and_expression
2886 : inclusive_or_expression
2887 | conditional_and_expression OP_AND inclusive_or_expression
2889 $$ = new Binary (Binary.Operator.LogicalAnd,
2890 (Expression) $1, (Expression) $3, lexer.Location);
2894 conditional_or_expression
2895 : conditional_and_expression
2896 | conditional_or_expression OP_OR conditional_and_expression
2898 $$ = new Binary (Binary.Operator.LogicalOr,
2899 (Expression) $1, (Expression) $3, lexer.Location);
2903 conditional_expression
2904 : conditional_or_expression
2905 | conditional_or_expression INTERR expression COLON expression
2907 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2911 assignment_expression
2912 : prefixed_unary_expression ASSIGN expression
2914 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2916 | prefixed_unary_expression OP_MULT_ASSIGN expression
2918 Location l = lexer.Location;
2920 $$ = new CompoundAssign (
2921 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
2923 | prefixed_unary_expression OP_DIV_ASSIGN expression
2925 Location l = lexer.Location;
2927 $$ = new CompoundAssign (
2928 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
2930 | prefixed_unary_expression OP_MOD_ASSIGN expression
2932 Location l = lexer.Location;
2934 $$ = new CompoundAssign (
2935 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
2937 | prefixed_unary_expression OP_ADD_ASSIGN expression
2939 Location l = lexer.Location;
2941 $$ = new CompoundAssign (
2942 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
2944 | prefixed_unary_expression OP_SUB_ASSIGN expression
2946 Location l = lexer.Location;
2948 $$ = new CompoundAssign (
2949 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
2951 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2953 Location l = lexer.Location;
2955 $$ = new CompoundAssign (
2956 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
2958 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2960 Location l = lexer.Location;
2962 $$ = new CompoundAssign (
2963 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
2965 | prefixed_unary_expression OP_AND_ASSIGN expression
2967 Location l = lexer.Location;
2969 $$ = new CompoundAssign (
2970 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
2972 | prefixed_unary_expression OP_OR_ASSIGN expression
2974 Location l = lexer.Location;
2976 $$ = new CompoundAssign (
2977 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
2979 | prefixed_unary_expression OP_XOR_ASSIGN expression
2981 Location l = lexer.Location;
2983 $$ = new CompoundAssign (
2984 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
2989 : conditional_expression
2990 | assignment_expression
3012 name = MakeName ((string) $4);
3014 new_class = new Class (current_namespace, current_container, name, (int) $2,
3015 (Attributes) $1, lexer.Location);
3016 current_container = new_class;
3017 RootContext.Tree.RecordDecl (name, new_class);
3019 lexer.ConstraintsParsing = true;
3021 opt_type_parameter_list
3023 opt_type_parameter_constraints_clauses
3025 lexer.ConstraintsParsing = false;
3030 Class new_class = (Class) current_container;
3032 if ($8 != null && $6 == null)
3033 Report.Error (80, lexer.Location,
3034 "Contraints are not allowed on non-generic declarations");
3037 CheckDef (new_class.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_class.Name, new_class.Location);
3039 if (new_class.Name == "System.Object") {
3040 Report.Error (537, new_class.Location, "The class System.Object cannot have a base class or implement an interface.");
3043 new_class.Bases = (ArrayList) $7;
3045 current_container = current_container.Parent;
3046 CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
3054 lexer.ConstraintsParsing = true;
3057 Report.Error (80, lexer.Location,
3058 "Contraints are not allowed on non-generic declarations");
3065 : /* empty */ { $$ = (int) 0; }
3071 | modifiers modifier
3076 if ((m1 & m2) != 0) {
3077 Location l = lexer.Location;
3078 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3080 $$ = (int) (m1 | m2);
3085 : NEW { $$ = Modifiers.NEW; }
3086 | PUBLIC { $$ = Modifiers.PUBLIC; }
3087 | PROTECTED { $$ = Modifiers.PROTECTED; }
3088 | INTERNAL { $$ = Modifiers.INTERNAL; }
3089 | PRIVATE { $$ = Modifiers.PRIVATE; }
3090 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3091 | SEALED { $$ = Modifiers.SEALED; }
3092 | STATIC { $$ = Modifiers.STATIC; }
3093 | READONLY { $$ = Modifiers.READONLY; }
3094 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3095 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3096 | EXTERN { $$ = Modifiers.EXTERN; }
3097 | VOLATILE { $$ = Modifiers.VOLATILE; }
3098 | UNSAFE { $$ = Modifiers.UNSAFE; }
3102 : /* empty */ { $$ = null; }
3103 | class_base { $$ = $1; }
3107 : COLON type_list { $$ = $2; }
3110 opt_type_parameter_list
3111 : /* empty */ { $$ = null; }
3112 | type_parameter_list { $$ = $1; }
3116 : OP_GENERICS_LT type_parameters OP_GENERICS_GT { $$ = $2; }
3122 // Do some profiling to find the optimal size, for now we
3123 // assume most people will be generic on one type (saves space
3125 ArrayList type_parameters = new ArrayList (1);
3126 type_parameters.Add ($1);
3127 $$ = type_parameters;
3129 | type_parameters COMMA type_parameter {
3130 ArrayList type_parameters = (ArrayList) $1;
3132 type_parameters.Add ($3);
3133 $$ = type_parameters;
3141 opt_type_parameter_constraints_clauses
3142 : /* empty */ { $$ = null; }
3143 | type_parameter_constraints_clauses
3147 type_parameter_constraints_clauses
3148 : type_parameter_constraints_clause
3149 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3150 ArrayList constraints = (ArrayList) $1;
3152 constraints.Add ($2);
3157 type_parameter_constraints_clause
3158 : WHERE type_parameter COLON type_parameter_constraints {
3159 ArrayList constraints = new ArrayList (1);
3160 constraints.Add (new Constraints ((string) $2, (ArrayList) $4, lexer.Location));
3165 type_parameter_constraints
3166 : type_parameter_constraint {
3167 ArrayList constraints = new ArrayList (1);
3168 constraints.Add ($1);
3171 | type_parameter_constraints COMMA type_parameter_constraint {
3172 ArrayList constraints = (ArrayList) $1;
3174 constraints.Add ($3);
3179 type_parameter_constraint
3181 | NEW OPEN_PARENS CLOSE_PARENS {
3191 // A block is "contained" on the following places:
3193 // property_declaration as part of the accessor body (get/set)
3194 // operator_declaration
3195 // constructor_declaration
3196 // destructor_declaration
3197 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3202 if (current_block == null || create_toplevel_block){
3203 current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
3205 current_block = new Block (current_block, current_local_parameters,
3206 lexer.Location, Location.Null);
3209 opt_statement_list CLOSE_BRACE
3211 while (current_block.Implicit)
3212 current_block = current_block.Parent;
3214 current_block.SetEndLocation (lexer.Location);
3215 current_block = current_block.Parent;
3226 | statement_list statement
3230 : declaration_statement
3232 if ($1 != null && (Block) $1 != current_block){
3233 current_block.AddStatement ((Statement) $1);
3234 current_block = (Block) $1;
3237 | embedded_statement
3239 current_block.AddStatement ((Statement) $1);
3247 | expression_statement
3248 | selection_statement
3249 | iteration_statement
3253 | unchecked_statement
3263 $$ = EmptyStatement.Value;
3270 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3272 if (!current_block.AddLabel ((string) $1, labeled)){
3273 Location l = lexer.Location;
3274 Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
3276 current_block.AddStatement (labeled);
3281 declaration_statement
3282 : local_variable_declaration SEMICOLON
3285 DictionaryEntry de = (DictionaryEntry) $1;
3287 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3291 | local_constant_declaration SEMICOLON
3294 DictionaryEntry de = (DictionaryEntry) $1;
3296 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3302 * The following is from Rhys' grammar:
3303 * > Types in local variable declarations must be recognized as
3304 * > expressions to prevent reduce/reduce errors in the grammar.
3305 * > The expressions are converted into types during semantic analysis.
3308 : primary_expression opt_rank_specifier
3310 // FIXME: Do something smart here regarding the composition of the type.
3312 // Ok, the above "primary_expression" is there to get rid of
3313 // both reduce/reduce and shift/reduces in the grammar, it should
3314 // really just be "type_name". If you use type_name, a reduce/reduce
3315 // creeps up. If you use namespace_or_type_name (which is all we need
3316 // really) two shift/reduces appear.
3319 // So the super-trick is that primary_expression
3320 // can only be either a SimpleName or a MemberAccess.
3321 // The MemberAccess case arises when you have a fully qualified type-name like :
3323 // SimpleName is when you have
3326 Expression expr = (Expression) $1;
3327 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3328 Error_ExpectingTypeName (lexer.Location, expr);
3332 // So we extract the string corresponding to the SimpleName
3336 if ((string) $2 == "")
3339 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3342 | builtin_types opt_rank_specifier
3344 if ((string) $2 == "")
3347 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3351 local_variable_pointer_type
3352 : primary_expression STAR
3354 Expression expr = (Expression) $1;
3355 Location l = lexer.Location;
3357 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3358 Error_ExpectingTypeName (l, expr);
3362 $$ = new ComposedCast ((Expression) $1, "*", l);
3364 | builtin_types STAR
3366 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3370 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3372 | local_variable_pointer_type STAR
3374 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3378 local_variable_declaration
3379 : local_variable_type variable_declarators
3382 $$ = new DictionaryEntry ($1, $2);
3386 | local_variable_pointer_type opt_rank_specifier variable_declarators
3391 if ((string) $2 == "")
3392 t = (Expression) $1;
3394 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3395 $$ = new DictionaryEntry (t, $3);
3401 local_constant_declaration
3402 : CONST local_variable_type constant_declarators
3405 $$ = new DictionaryEntry ($2, $3);
3411 expression_statement
3412 : statement_expression SEMICOLON
3419 // We have to do the wrapping here and not in the case above,
3420 // because statement_expression is used for example in for_statement
3422 statement_expression
3423 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3424 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3425 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3426 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3427 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3428 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3429 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3431 Report.Error (1002, lexer.Location, "Expecting `;'");
3436 object_creation_expression
3437 : object_or_delegate_creation_expression
3438 { note ("complain if this is a delegate maybe?"); }
3447 : if_statement_open if_statement_rest
3456 oob_stack.Push (lexer.Location);
3461 : boolean_expression CLOSE_PARENS
3464 Location l = (Location) oob_stack.Pop ();
3466 $$ = new If ((Expression) $1, (Statement) $3, l);
3468 if (RootContext.WarningLevel >= 3){
3469 if ($3 == EmptyStatement.Value)
3470 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3474 | boolean_expression CLOSE_PARENS
3475 embedded_statement ELSE embedded_statement
3477 Location l = (Location) oob_stack.Pop ();
3479 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3484 : SWITCH OPEN_PARENS
3486 oob_stack.Push (lexer.Location);
3487 switch_stack.Push (current_block);
3489 expression CLOSE_PARENS
3492 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3493 current_block = (Block) switch_stack.Pop ();
3509 Report.Error (1522, lexer.Location, "Empty switch block");
3517 ArrayList sections = new ArrayList (4);
3522 | switch_sections switch_section
3524 ArrayList sections = (ArrayList) $1;
3534 current_block = current_block.CreateSwitchBlock (lexer.Location);
3538 Block topmost = current_block;
3540 while (topmost.Implicit)
3541 topmost = topmost.Parent;
3542 $$ = new SwitchSection ((ArrayList) $1, topmost);
3549 ArrayList labels = new ArrayList (4);
3554 | switch_labels switch_label
3556 ArrayList labels = (ArrayList) ($1);
3564 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3565 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3568 1523, lexer.Location,
3569 "The keyword case or default must precede code in switch block");
3583 oob_stack.Push (lexer.Location);
3585 boolean_expression CLOSE_PARENS embedded_statement
3587 Location l = (Location) oob_stack.Pop ();
3588 $$ = new While ((Expression) $4, (Statement) $6, l);
3590 if (RootContext.WarningLevel >= 3){
3591 if ($6 == EmptyStatement.Value)
3592 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3598 : DO embedded_statement
3600 oob_stack.Push (lexer.Location);
3602 boolean_expression CLOSE_PARENS SEMICOLON
3604 Location l = (Location) oob_stack.Pop ();
3606 $$ = new Do ((Statement) $2, (Expression) $6, l);
3612 opt_for_initializer SEMICOLON
3614 Block assign_block = new Block (current_block);
3615 current_block = assign_block;
3617 if ($3 is DictionaryEntry){
3618 DictionaryEntry de = (DictionaryEntry) $3;
3620 Expression type = (Expression) de.Key;
3621 ArrayList var_declarators = (ArrayList) de.Value;
3623 foreach (VariableDeclaration decl in var_declarators){
3627 vi = current_block.AddVariable (
3628 type, decl.identifier, current_local_parameters, decl.Location);
3632 Location l = lexer.Location;
3634 if (decl.expression_or_array_initializer is Expression){
3635 expr = (Expression) decl.expression_or_array_initializer;
3636 } else if (decl.expression_or_array_initializer == null) {
3639 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3640 expr = new ArrayCreation (type, "", init, decl.Location);
3643 LocalVariableReference var;
3644 var = new LocalVariableReference (assign_block, decl.identifier, l);
3647 Assign a = new Assign (var, expr, decl.Location);
3649 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3655 oob_stack.Push (lexer.Location);
3657 opt_for_condition SEMICOLON
3658 opt_for_iterator CLOSE_PARENS
3661 Location l = (Location) oob_stack.Pop ();
3663 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3665 if (RootContext.WarningLevel >= 3){
3666 if ($10 == EmptyStatement.Value)
3667 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3670 current_block.AddStatement (f);
3671 while (current_block.Implicit)
3672 current_block = current_block.Parent;
3674 current_block = current_block.Parent;
3679 : /* empty */ { $$ = EmptyStatement.Value; }
3684 : local_variable_declaration
3685 | statement_expression_list
3689 : /* empty */ { $$ = null; }
3690 | boolean_expression
3694 : /* empty */ { $$ = EmptyStatement.Value; }
3699 : statement_expression_list
3702 statement_expression_list
3703 : statement_expression
3705 // CHANGE: was `null'
3706 Block b = new Block (current_block, Block.Flags.Implicit);
3708 b.AddStatement ((Statement) $1);
3711 | statement_expression_list COMMA statement_expression
3713 Block b = (Block) $1;
3715 b.AddStatement ((Statement) $3);
3721 : FOREACH OPEN_PARENS type IDENTIFIER IN
3723 oob_stack.Push (lexer.Location);
3725 expression CLOSE_PARENS
3727 oob_stack.Push (current_block);
3729 Block foreach_block = new Block (current_block, Block.Flags.Implicit);
3730 LocalVariableReference v = null;
3731 Location l = lexer.Location;
3734 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3738 // Get a writable reference to this read-only variable.
3739 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3741 current_block = foreach_block;
3744 oob_stack.Push (current_block);
3748 Block foreach_block = (Block) oob_stack.Pop ();
3749 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3750 Block prev_block = (Block) oob_stack.Pop ();
3751 Location l = (Location) oob_stack.Pop ();
3753 current_block = prev_block;
3756 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3757 foreach_block.AddStatement (f);
3766 | continue_statement
3776 $$ = new Break (lexer.Location);
3781 : CONTINUE SEMICOLON
3783 $$ = new Continue (lexer.Location);
3788 : GOTO IDENTIFIER SEMICOLON
3790 $$ = new Goto (current_block, (string) $2, lexer.Location);
3792 | GOTO CASE constant_expression SEMICOLON
3794 $$ = new GotoCase ((Expression) $3, lexer.Location);
3796 | GOTO DEFAULT SEMICOLON
3798 $$ = new GotoDefault (lexer.Location);
3803 : RETURN opt_expression SEMICOLON
3805 $$ = new Return ((Expression) $2, lexer.Location);
3810 : THROW opt_expression SEMICOLON
3812 $$ = new Throw ((Expression) $2, lexer.Location);
3817 : IDENTIFIER RETURN expression SEMICOLON
3819 string s = (string) $1;
3821 Report.Error (1003, lexer.Location, "; expected");
3824 if (!RootContext.V2){
3825 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3828 if (iterator_container == null){
3829 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3832 iterator_container.SetYields ();
3833 $$ = new Yield ((Expression) $3, lexer.Location);
3836 | IDENTIFIER BREAK SEMICOLON
3838 string s = (string) $1;
3840 Report.Error (1003, lexer.Location, "; expected");
3843 if (!RootContext.V2){
3844 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3847 if (iterator_container == null){
3848 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3851 iterator_container.SetYields ();
3852 $$ = new YieldBreak (lexer.Location);
3863 : TRY block catch_clauses
3866 ArrayList s = new ArrayList (4);
3868 foreach (Catch cc in (ArrayList) $3) {
3875 // Now s contains the list of specific catch clauses
3876 // and g contains the general one.
3878 $$ = new Try ((Block) $2, s, g, null, lexer.Location);
3880 | TRY block opt_catch_clauses FINALLY block
3883 ArrayList s = new ArrayList (4);
3884 ArrayList catch_list = (ArrayList) $3;
3886 if (catch_list != null){
3887 foreach (Catch cc in catch_list) {
3895 $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
3899 Report.Error (1524, lexer.Location, "Expected catch or finally");
3904 : /* empty */ { $$ = null; }
3911 ArrayList l = new ArrayList (4);
3916 | catch_clauses catch_clause
3918 ArrayList l = (ArrayList) $1;
3926 : /* empty */ { $$ = null; }
3931 : CATCH opt_catch_args
3933 Expression type = null;
3937 DictionaryEntry cc = (DictionaryEntry) $2;
3938 type = (Expression) cc.Key;
3939 id = (string) cc.Value;
3942 ArrayList one = new ArrayList (4);
3943 Location loc = lexer.Location;
3945 one.Add (new VariableDeclaration (id, null, loc));
3948 current_block = new Block (current_block);
3949 Block b = declare_local_variables (type, one, loc);
3954 Expression type = null;
3958 DictionaryEntry cc = (DictionaryEntry) $2;
3959 type = (Expression) cc.Key;
3960 id = (string) cc.Value;
3964 // FIXME: I can change this for an assignment.
3966 while (current_block != (Block) $1)
3967 current_block = current_block.Parent;
3972 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3977 : /* empty */ { $$ = null; }
3982 : OPEN_PARENS type opt_identifier CLOSE_PARENS
3984 $$ = new DictionaryEntry ($2, $3);
3991 $$ = new Checked ((Block) $2);
3998 $$ = new Unchecked ((Block) $2);
4005 if (!RootContext.Unsafe){
4006 Report.Error (227, lexer.Location,
4007 "Unsafe code can only be used if --unsafe is used");
4010 $$ = new Unsafe ((Block) $3);
4016 type fixed_pointer_declarators
4019 Block assign_block = new Block (current_block, Block.Flags.Implicit);
4020 ArrayList list = (ArrayList) $4;
4021 Expression type = (Expression) $3;
4022 Location l = lexer.Location;
4023 int top = list.Count;
4025 for (int i = 0; i < top; i++){
4026 Pair p = (Pair) list [i];
4029 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4036 current_block.AddStatement (assign_block);
4037 current_block = assign_block;
4038 oob_stack.Push (assign_block);
4043 Location l = (Location) oob_stack.Pop ();
4046 $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4050 fixed_pointer_declarators
4051 : fixed_pointer_declarator {
4052 ArrayList declarators = new ArrayList (4);
4053 declarators.Add ($1);
4056 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4058 ArrayList declarators = (ArrayList) $1;
4059 declarators.Add ($3);
4064 fixed_pointer_declarator
4065 : IDENTIFIER ASSIGN expression
4067 $$ = new Pair ($1, $3);
4072 : LOCK OPEN_PARENS expression CLOSE_PARENS
4078 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4083 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4085 Block assign_block = new Block (current_block);
4086 current_block = assign_block;
4088 oob_stack.Push (lexer.Location);
4090 if ($3 is DictionaryEntry){
4091 DictionaryEntry de = (DictionaryEntry) $3;
4092 Location l = lexer.Location;
4094 Expression type = (Expression) de.Key;
4095 ArrayList var_declarators = (ArrayList) de.Value;
4097 ArrayList vars = new ArrayList (4);
4099 foreach (VariableDeclaration decl in var_declarators){
4101 LocalInfo vi = current_block.AddVariable (
4102 type, decl.identifier,
4103 current_local_parameters, decl.Location);
4109 if (decl.expression_or_array_initializer is Expression){
4110 expr = (Expression) decl.expression_or_array_initializer;
4112 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4114 expr = new ArrayCreation (type, "", init, decl.Location);
4117 LocalVariableReference var;
4119 // Get a writable reference to this read-only variable.
4120 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4122 // This is so that it is not a warning on using variables
4125 vars.Add (new DictionaryEntry (var, expr));
4127 // Assign a = new Assign (var, expr, decl.Location);
4128 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4130 $3 = new DictionaryEntry (type, vars);
4135 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4136 current_block.AddStatement (u);
4137 while (current_block.Implicit)
4138 current_block = current_block.Parent;
4140 current_block = current_block.Parent;
4144 resource_acquisition
4145 : local_variable_declaration
4152 // A class used to pass around variable declarations and constants
4154 public class VariableDeclaration {
4155 public string identifier;
4156 public object expression_or_array_initializer;
4157 public Location Location;
4158 public Attributes OptAttributes;
4160 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4162 this.identifier = id;
4163 this.expression_or_array_initializer = eoai;
4165 this.OptAttributes = opt_attrs;
4168 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4174 /// Used to pass around interface property information
4176 public class InterfaceAccessorInfo {
4178 public readonly Accessor Get, Set;
4180 public InterfaceAccessorInfo (bool has_get, bool has_set,
4181 Attributes get_attrs, Attributes set_attrs)
4184 Get = new Accessor (null, get_attrs);
4186 Set = new Accessor (null, set_attrs);
4192 // A class used to hold info about an indexer declarator
4194 public class IndexerDeclaration {
4195 public Expression type;
4196 public MemberName interface_type;
4197 public Parameters param_list;
4199 public IndexerDeclaration (Expression type, MemberName interface_type,
4200 Parameters param_list)
4203 this.interface_type = interface_type;
4204 this.param_list = param_list;
4209 // We use this when we do not have an object in advance that is an IIteratorContainer
4211 public class SimpleIteratorContainer : IIteratorContainer {
4214 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4219 public static SimpleIteratorContainer GetSimple () {
4220 Simple.Yields = false;
4224 public void SetYields () { Yields = true; }
4228 // A class used to hold info about an operator declarator
4230 public class OperatorDeclaration {
4231 public Operator.OpType optype;
4232 public Expression ret_type, arg1type, arg2type;
4233 public string arg1name, arg2name;
4234 public Location location;
4236 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4237 Expression arg1type, string arg1name,
4238 Expression arg2type, string arg2name, Location location)
4241 this.ret_type = ret_type;
4242 this.arg1type = arg1type;
4243 this.arg1name = arg1name;
4244 this.arg2type = arg2type;
4245 this.arg2name = arg2name;
4246 this.location = location;
4251 void Error_ExpectingTypeName (Location l, Expression expr)
4253 if (expr is Invocation){
4254 Report.Error (1002, l, "; expected");
4256 Report.Error (-1, l, "Invalid Type definition");
4261 // Given the @class_name name, it creates a fully qualified name
4262 // based on the containing declaration space
4265 MakeName (string class_name)
4267 string ns = current_namespace.FullName;
4268 string container_name = current_container.Name;
4270 if (container_name == ""){
4272 return ns + "." + class_name;
4276 return container_name + "." + class_name;
4280 // Used to report back to the user the result of a declaration
4281 // in the current declaration space
4284 CheckDef (DeclSpace.AdditionResult result, string name, Location l)
4286 if (result == DeclSpace.AdditionResult.Success)
4290 case DeclSpace.AdditionResult.NameExists:
4291 Report.Error (102, l, "The container `" + current_container.Name +
4292 "' already contains a definition for `"+
4298 // This is handled only for static Constructors, because
4299 // in reality we handle these by the semantic analysis later
4301 case DeclSpace.AdditionResult.MethodExists:
4303 111, l, "Class `"+current_container.Name+
4304 "' already defines a member called '" +
4305 name + "' with the same parameter types (more than one default constructor)");
4308 case DeclSpace.AdditionResult.EnclosingClash:
4309 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
4312 case DeclSpace.AdditionResult.NotAConstructor:
4313 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
4316 case DeclSpace.AdditionResult.Error:
4317 // Error has already been reported.
4323 CheckDef (bool result, string name, Location l)
4327 CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
4330 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4332 Block implicit_block;
4333 ArrayList inits = null;
4336 // We use the `Used' property to check whether statements
4337 // have been added to the current block. If so, we need
4338 // to create another block to contain the new declaration
4339 // otherwise, as an optimization, we use the same block to
4340 // add the declaration.
4342 // FIXME: A further optimization is to check if the statements
4343 // that were added were added as part of the initialization
4344 // below. In which case, no other statements have been executed
4345 // and we might be able to reduce the number of blocks for
4346 // situations like this:
4348 // int j = 1; int k = j + 1;
4350 if (current_block.Used) {
4351 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4352 implicit_block.AddChildVariableNames (current_block);
4354 implicit_block = current_block;
4356 foreach (VariableDeclaration decl in variable_declarators){
4358 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4359 if (decl.expression_or_array_initializer != null){
4361 inits = new ArrayList (4);
4368 return implicit_block;
4370 foreach (VariableDeclaration decl in inits){
4374 if (decl.expression_or_array_initializer is Expression){
4375 expr = (Expression) decl.expression_or_array_initializer;
4378 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4380 expr = new ArrayCreation (type, "", init, decl.Location);
4383 LocalVariableReference var;
4384 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4386 assign = new Assign (var, expr, decl.Location);
4388 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4391 return implicit_block;
4394 Block declare_local_constants (Expression type, ArrayList declarators)
4396 Block implicit_block;
4398 if (current_block.Used)
4399 implicit_block = new Block (current_block, Block.Flags.Implicit);
4401 implicit_block = current_block;
4403 foreach (VariableDeclaration decl in declarators){
4404 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4405 current_local_parameters, decl.Location);
4408 return implicit_block;
4411 void CheckAttributeTarget (string a)
4415 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4419 Location l = lexer.Location;
4420 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4426 void CheckUnaryOperator (Operator.OpType op)
4430 case Operator.OpType.LogicalNot:
4431 case Operator.OpType.OnesComplement:
4432 case Operator.OpType.Increment:
4433 case Operator.OpType.Decrement:
4434 case Operator.OpType.True:
4435 case Operator.OpType.False:
4436 case Operator.OpType.Addition:
4437 case Operator.OpType.Subtraction:
4442 Location l = lexer.Location;
4443 Report.Error (1019, l, "Overloadable unary operator expected");
4449 void CheckBinaryOperator (Operator.OpType op)
4453 case Operator.OpType.Addition:
4454 case Operator.OpType.Subtraction:
4455 case Operator.OpType.Multiply:
4456 case Operator.OpType.Division:
4457 case Operator.OpType.Modulus:
4458 case Operator.OpType.BitwiseAnd:
4459 case Operator.OpType.BitwiseOr:
4460 case Operator.OpType.ExclusiveOr:
4461 case Operator.OpType.LeftShift:
4462 case Operator.OpType.RightShift:
4463 case Operator.OpType.Equality:
4464 case Operator.OpType.Inequality:
4465 case Operator.OpType.GreaterThan:
4466 case Operator.OpType.LessThan:
4467 case Operator.OpType.GreaterThanOrEqual:
4468 case Operator.OpType.LessThanOrEqual:
4472 Location l = lexer.Location;
4473 Report.Error (1020, l, "Overloadable binary operator expected");
4479 void syntax_error (Location l, string msg)
4481 Report.Error (1003, l, "Syntax error, " + msg);
4484 void output (string s)
4486 Console.WriteLine (s);
4489 void note (string s)
4491 // Used to put annotations
4496 public Tokenizer Lexer {
4502 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4504 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4505 this.name = file.Name;
4507 current_container = RootContext.Tree.Types;
4508 current_container.NamespaceEntry = current_namespace;
4509 oob_stack = new Stack ();
4510 switch_stack = new Stack ();
4512 lexer = new Tokenizer (reader, file, defines);
4515 public void parse ()
4518 if (yacc_verbose_flag)
4519 yyparse (lexer, new yydebug.yyDebugSimple ());
4522 Tokenizer tokenizer = lexer as Tokenizer;
4523 tokenizer.cleanup ();
4524 } catch (Exception e){
4525 // Please do not remove this, it is used during debugging
4528 Console.WriteLine (e);
4529 Report.Error (-25, lexer.Location, "Parsing error");
4530 if (Driver.parser_verbose)
4531 Console.WriteLine (e);
4535 void CheckToken (int error, int yyToken, string msg)
4537 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4538 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4541 Report.Error (error, lexer.Location, msg);
4544 void CheckIdentifierToken (int yyToken)
4546 CheckToken (1041, yyToken, "Identifier expected");