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;
60 /// This is used by the unary_expression code to resolve
61 /// a name against a parameter.
63 Parameters current_local_parameters;
66 /// Using during property parsing to describe the implicit
67 /// value parameter that is passed to the "set" and "get"accesor
68 /// methods (properties and indexers).
70 Expression implicit_value_parameter_type;
71 Parameters indexer_parameters;
74 /// Used to determine if we are parsing the get/set pair
75 /// of an indexer or a property
80 /// An out-of-band stack.
89 public bool yacc_verbose_flag;
91 // Name of the file we are parsing
101 %token NONE /* This token is never returned by our lexer */
102 %token ERROR // This is used not by the parser, but by the tokenizer.
106 *These are the C# keywords
191 /* C# keywords which are not really keywords */
197 /* C# single character operators/punctuation. */
198 %token OPEN_BRACE "{"
199 %token CLOSE_BRACE "}"
200 %token OPEN_BRACKET "["
201 %token CLOSE_BRACKET "]"
202 %token OPEN_PARENS "("
203 %token CLOSE_PARENS ")"
215 %token OP_GENERICS_LT "<"
217 %token OP_GENERICS_GT ">"
218 %token BITWISE_AND "&"
219 %token BITWISE_OR "|"
226 /* C# multi-character operators. */
229 %token OP_SHIFT_LEFT "<<"
230 %token OP_SHIFT_RIGHT ">>"
237 %token OP_MULT_ASSIGN "*="
238 %token OP_DIV_ASSIGN "/="
239 %token OP_MOD_ASSIGN "%="
240 %token OP_ADD_ASSIGN "+="
241 %token OP_SUB_ASSIGN "-="
242 %token OP_SHIFT_LEFT_ASSIGN "<<="
243 %token OP_SHIFT_RIGHT_ASSIGN ">>="
244 %token OP_AND_ASSIGN "&="
245 %token OP_XOR_ASSIGN "^="
246 %token OP_OR_ASSIGN "|="
250 %token LITERAL_INTEGER "int literal"
251 %token LITERAL_FLOAT "float literal"
252 %token LITERAL_DOUBLE "double literal"
253 %token LITERAL_DECIMAL "decimal literal"
254 %token LITERAL_CHARACTER "character literal"
255 %token LITERAL_STRING "string literal"
258 %token CLOSE_PARENS_CAST
259 %token CLOSE_PARENS_NO_CAST
260 %token CLOSE_PARENS_OPEN_PARENS
261 %token CLOSE_PARENS_MINUS
263 /* Add precedence rules to solve dangling else s/r conflict */
272 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
274 %left STAR DIV PERCENT
275 %right BANG CARRET UMINUS
276 %nonassoc OP_INC OP_DEC
278 %left OPEN_BRACKET OPEN_BRACE
282 %start compilation_unit
286 : outer_declarations opt_EOF
287 | outer_declarations attribute_sections opt_EOF
288 | attribute_sections opt_EOF
289 | opt_EOF /* allow empty files */
299 | outer_declarations outer_declaration
304 | namespace_member_declaration
309 | using_directives using_directive
313 : using_alias_directive
314 | using_namespace_directive
317 using_alias_directive
318 : USING IDENTIFIER ASSIGN
319 namespace_or_type_name SEMICOLON
321 current_namespace.UsingAlias ((string) $2, (Expression) $4, lexer.Location);
324 CheckIdentifierToken (yyToken);
328 using_namespace_directive
329 : USING namespace_name SEMICOLON
331 current_namespace.Using ((string) $2, lexer.Location);
336 // Strictly speaking, namespaces don't have attributes but
337 // we parse global attributes along with namespace declarations and then
340 namespace_declaration
341 : opt_attributes NAMESPACE namespace_or_type_name
343 Attributes attrs = (Attributes) $1;
346 foreach (AttributeSection asec in attrs.AttributeSections)
347 if (asec.Target == "assembly")
348 CodeGen.Assembly.AddAttribute (current_container, asec);
350 Report.Error(1518, Lexer.Location,
351 "Attributes cannot be applied to namespaces."
352 + " Expected class, delegate, enum, interface, or struct");
355 current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, $3.ToString (), lexer.Location);
357 namespace_body opt_semicolon
359 current_namespace = current_namespace.Parent;
374 : namespace_or_type_name { $$ = ($1).ToString (); }
380 opt_namespace_member_declarations
391 opt_namespace_member_declarations
393 | namespace_member_declarations
396 namespace_member_declarations
397 : namespace_member_declaration
398 | namespace_member_declarations namespace_member_declaration
401 namespace_member_declaration
408 Class c = (Class) $1;
409 mod_flags = c.ModFlags;
411 } else if ($1 is Struct){
412 Struct s = (Struct) $1;
413 mod_flags = s.ModFlags;
418 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
420 1527, lexer.Location,
421 "Namespace elements cant be explicitly " +
422 "declared private or protected in `" + name + "'");
424 current_namespace.DeclarationFound = true;
426 | namespace_declaration {
427 current_namespace.DeclarationFound = true;
430 | field_declaration {
431 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
433 | method_declaration {
434 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
441 | interface_declaration
443 | delegate_declaration
445 // Enable this when we have handled all errors, because this acts as a generic fallback
448 // Console.WriteLine ("Token=" + yyToken);
449 // Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
459 | attribute_sections { $$ = $1; }
465 AttributeSection sect = (AttributeSection) $1;
467 if (sect.Target == "assembly") {
468 CodeGen.Assembly.AddAttribute (current_container, sect);
471 else if (sect.Target == "module") {
472 CodeGen.Module.AddAttribute (current_container, sect);
476 $$ = new Attributes (sect);
478 | attribute_sections attribute_section
480 Attributes attrs = $1 as Attributes;
481 AttributeSection sect = (AttributeSection) $2;
483 if (sect.Target == "assembly") {
484 CodeGen.Assembly.AddAttribute (current_container, sect);
486 else if (sect.Target == "module") {
487 CodeGen.Module.AddAttribute (current_container, sect);
491 attrs = new Attributes (sect);
493 attrs.AddAttributeSection (sect);
501 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
503 string target = null;
506 target = (string) $2;
508 $$ = new AttributeSection (target, (ArrayList) $3);
510 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
512 $$ = new AttributeSection (null, (ArrayList) $2);
516 attribute_target_specifier
517 : attribute_target COLON
526 CheckAttributeTarget ((string) $1);
529 | EVENT { $$ = "event"; }
530 | RETURN { $$ = "return"; }
536 ArrayList attrs = new ArrayList (4);
542 | attribute_list COMMA attribute
544 ArrayList attrs = (ArrayList) $1;
556 opt_attribute_arguments
559 // Attributes need a string, not an expression: generic types will fail here.
561 $$ = new Attribute (((Expression) $1).ToString (), (ArrayList) $3, (Location) $2);
566 : type_name { /* reserved attribute name or identifier: 17.4 */ }
569 opt_attribute_arguments
570 : /* empty */ { $$ = null; }
571 | OPEN_PARENS attribute_arguments CLOSE_PARENS
579 : opt_positional_argument_list
584 ArrayList args = new ArrayList (4);
590 | positional_argument_list COMMA named_argument_list
592 ArrayList args = new ArrayList (4);
598 | named_argument_list
600 ArrayList args = new ArrayList (4);
609 opt_positional_argument_list
610 : /* empty */ { $$ = null; }
611 | positional_argument_list
614 positional_argument_list
617 ArrayList args = new ArrayList (4);
618 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
622 | positional_argument_list COMMA expression
624 ArrayList args = (ArrayList) $1;
625 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
634 ArrayList args = new ArrayList (4);
639 | named_argument_list COMMA named_argument
641 ArrayList args = (ArrayList) $1;
649 : IDENTIFIER ASSIGN expression
651 $$ = new DictionaryEntry (
653 new Argument ((Expression) $3, Argument.AType.Expression));
659 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
662 opt_class_member_declarations
664 | class_member_declarations
667 class_member_declarations
668 : class_member_declaration
669 | class_member_declarations
670 class_member_declaration
673 class_member_declaration
674 : constant_declaration // done
675 | field_declaration // done
676 | method_declaration // done
677 | property_declaration // done
678 | event_declaration // done
679 | indexer_declaration // done
680 | operator_declaration // done
681 | constructor_declaration // done
682 | destructor_declaration // done
692 string full_struct_name = MakeName ((string) $4);
694 new_struct = new Struct (current_namespace, current_container, full_struct_name,
695 (int) $2, (Attributes) $1, lexer.Location);
696 current_container = new_struct;
697 RootContext.Tree.RecordDecl (full_struct_name, new_struct);
698 lexer.ConstraintsParsing = true;
700 opt_type_parameter_list
702 opt_type_parameter_constraints_clauses
704 lexer.ConstraintsParsing = false;
709 Struct new_struct = (Struct) current_container;
711 if ($8 != null && $6 == null)
712 Report.Error (-200, new_struct.Location,
713 "Type parameter constraints only valid if there is a type parameter list");
715 CheckDef (new_struct.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_struct.Name, new_struct.Location);
718 new_struct.Bases = (ArrayList) $7;
720 current_container = current_container.Parent;
721 CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
724 | opt_attributes opt_modifiers STRUCT error {
725 CheckIdentifierToken (yyToken);
730 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
733 opt_struct_member_declarations
735 | struct_member_declarations
738 struct_member_declarations
739 : struct_member_declaration
740 | struct_member_declarations struct_member_declaration
743 struct_member_declaration
744 : constant_declaration
747 | property_declaration
749 | indexer_declaration
750 | operator_declaration
751 | constructor_declaration
755 * This is only included so we can flag error 575:
756 * destructors only allowed on class types
758 | destructor_declaration
769 foreach (VariableDeclaration constant in (ArrayList) $5){
770 Location l = constant.Location;
772 Const c = new Const (
773 (Expression) $4, (string) constant.identifier,
774 (Expression) constant.expression_or_array_initializer, (int) $2,
777 CheckDef (current_container.AddConstant (c), c.Name, l);
783 : constant_declarator
785 ArrayList constants = new ArrayList (4);
789 | constant_declarators COMMA constant_declarator
791 ArrayList constants = (ArrayList) $1;
798 : IDENTIFIER ASSIGN constant_expression
800 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
811 Expression type = (Expression) $3;
814 foreach (VariableDeclaration var in (ArrayList) $4){
815 Location l = var.Location;
817 Field field = new Field (type, mod, var.identifier,
818 var.expression_or_array_initializer,
821 CheckDef (current_container.AddField (field), field.Name, l);
829 Report.Error (670, lexer.Location, "void type is not allowed for fields");
834 : variable_declarator
836 ArrayList decl = new ArrayList (4);
840 | variable_declarators COMMA variable_declarator
842 ArrayList decls = (ArrayList) $1;
849 : IDENTIFIER ASSIGN variable_initializer
851 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
855 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
868 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
870 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
876 iterator_container = (IIteratorContainer) $1;
880 Method method = (Method) $1;
881 Block b = (Block) $3;
882 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
885 if ((method.ModFlags & extern_abstract) == 0){
887 501, lexer.Location, current_container.MakeName (method.Name) +
888 "must declare a body because it is not marked abstract or extern");
891 if ((method.ModFlags & Modifiers.EXTERN) != 0){
893 179, lexer.Location, current_container.MakeName (method.Name) +
894 " is declared extern, but has a body");
898 method.Block = (Block) $3;
899 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
901 current_local_parameters = null;
902 iterator_container = null;
916 1585, lexer.Location, "Member modifier `" +
917 Modifiers.Name (i) + "' must precede member type and name");
930 opt_type_parameter_list
931 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
933 lexer.ConstraintsParsing = true;
935 opt_type_parameter_constraints_clauses
937 lexer.ConstraintsParsing = false;
938 if ($10 != null && $5 == null)
939 Report.Error (-200, lexer.Location,
940 "Type parameter constraints only valid if there is a type parameter list");
944 GenericMethod generic = null;
946 generic = new GenericMethod (current_namespace, current_container,
947 (string) $4, (Attributes) $1,
950 CheckDef (generic.SetParameterInfo ((ArrayList) $5, (ArrayList) $10), generic.Name, generic.Location);
951 method = new Method (generic, (Expression) $3, (int) $2, (string) $4,
952 (Parameters) $7, (Attributes) $1, lexer.Location);
954 method = new Method (current_container, (Expression) $3, (int) $2, (string) $4,
955 (Parameters) $7, (Attributes) $1, lexer.Location);
957 current_local_parameters = (Parameters) $7;
965 opt_type_parameter_list
966 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
968 lexer.ConstraintsParsing = true;
970 opt_type_parameter_constraints_clauses
972 lexer.ConstraintsParsing = false;
973 if ($10 != null && $5 == null)
974 Report.Error (-200, lexer.Location,
975 "Type parameter constraints only valid if there is a type parameter list");
978 GenericMethod generic = null;
980 generic = new GenericMethod (current_namespace, current_container,
981 (string) $4, (Attributes) $1,
984 CheckDef (generic.SetParameterInfo ((ArrayList) $5, (ArrayList) $10), generic.Name, generic.Location);
986 method = new Method (generic, TypeManager.system_void_expr, (int) $2,
987 (string) $4, (Parameters) $7, (Attributes) $1,
990 method = new Method (current_container, TypeManager.system_void_expr, (int) $2,
991 (string) $4, (Parameters) $7, (Attributes) $1,
994 current_local_parameters = (Parameters) $7;
1001 modifiers member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1003 Report.Error (1585, lexer.Location,
1004 String.Format ("Modifier {0} should appear before type",
1005 Modifiers.Name ((int) $4)));
1006 Method method = new Method (current_container, TypeManager.system_void_expr, 0,
1007 (string) $5, (Parameters) $7, (Attributes) $1,
1010 current_local_parameters = (Parameters) $7;
1017 | SEMICOLON { $$ = null; }
1020 opt_formal_parameter_list
1021 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1022 | formal_parameter_list
1025 formal_parameter_list
1028 ArrayList pars_list = (ArrayList) $1;
1030 Parameter [] pars = new Parameter [pars_list.Count];
1031 pars_list.CopyTo (pars);
1033 $$ = new Parameters (pars, null, lexer.Location);
1035 | fixed_parameters COMMA parameter_array
1037 ArrayList pars_list = (ArrayList) $1;
1039 Parameter [] pars = new Parameter [pars_list.Count];
1040 pars_list.CopyTo (pars);
1042 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
1046 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1053 ArrayList pars = new ArrayList (4);
1058 | fixed_parameters COMMA fixed_parameter
1060 ArrayList pars = (ArrayList) $1;
1069 opt_parameter_modifier
1073 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1076 opt_parameter_modifier
1079 CheckIdentifierToken (yyToken);
1084 opt_parameter_modifier
1085 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1086 | parameter_modifier
1090 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1091 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1095 : opt_attributes PARAMS type IDENTIFIER
1097 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1098 note ("type must be a single-dimension array type");
1100 | opt_attributes PARAMS type error {
1101 CheckIdentifierToken (yyToken);
1108 | member_name DOT IDENTIFIER {
1109 $$ = String.Concat ((string) $1, ".", $3);
1113 property_declaration
1119 implicit_value_parameter_type = (Expression) $3;
1121 lexer.PropertyParsing = true;
1123 $$ = lexer.Location;
1125 iterator_container = SimpleIteratorContainer.GetSimple ();
1127 accessor_declarations
1129 lexer.PropertyParsing = false;
1134 Pair pair = (Pair) $7;
1135 Accessor get_block = (Accessor) pair.First;
1136 Accessor set_block = (Accessor) pair.Second;
1138 Location loc = (Location) $6;
1139 prop = new Property (current_container, (Expression) $3, (string) $4, (int) $2,
1140 get_block, set_block, (Attributes) $1, loc);
1141 if (SimpleIteratorContainer.Simple.Yields)
1144 CheckDef (current_container.AddProperty (prop), prop.Name, loc);
1145 implicit_value_parameter_type = null;
1146 iterator_container = null;
1150 accessor_declarations
1151 : get_accessor_declaration opt_set_accessor_declaration
1153 $$ = new Pair ($1, $2);
1155 | set_accessor_declaration opt_get_accessor_declaration
1157 $$ = new Pair ($2, $1);
1161 opt_get_accessor_declaration
1162 : /* empty */ { $$ = null; }
1163 | get_accessor_declaration
1166 opt_set_accessor_declaration
1167 : /* empty */ { $$ = null; }
1168 | set_accessor_declaration
1171 get_accessor_declaration
1172 : opt_attributes GET
1174 // If this is not the case, then current_local_parameters has already
1175 // been set in indexer_declaration
1176 if (parsing_indexer == false)
1177 current_local_parameters = null;
1179 current_local_parameters = indexer_parameters;
1180 lexer.PropertyParsing = false;
1184 $$ = new Accessor ((Block) $4, (Attributes) $1);
1185 current_local_parameters = null;
1186 lexer.PropertyParsing = true;
1190 set_accessor_declaration
1191 : opt_attributes SET
1194 Parameter implicit_value_parameter = new Parameter (
1195 implicit_value_parameter_type, "value",
1196 Parameter.Modifier.NONE, null);
1198 if (parsing_indexer == false) {
1199 args = new Parameter [1];
1200 args [0] = implicit_value_parameter;
1201 current_local_parameters = new Parameters (args, null, lexer.Location);
1203 Parameter [] fpars = indexer_parameters.FixedParameters;
1206 int count = fpars.Length;
1208 args = new Parameter [count + 1];
1209 fpars.CopyTo (args, 0);
1210 args [count] = implicit_value_parameter;
1213 current_local_parameters = new Parameters (
1214 args, indexer_parameters.ArrayParameter, lexer.Location);
1217 lexer.PropertyParsing = false;
1221 $$ = new Accessor ((Block) $4, (Attributes) $1);
1222 current_local_parameters = null;
1223 lexer.PropertyParsing = true;
1229 | SEMICOLON { $$ = null; }
1232 interface_declaration
1235 INTERFACE IDENTIFIER
1237 Interface new_interface;
1238 string full_interface_name = MakeName ((string) $4);
1240 new_interface = new Interface (current_namespace, current_container, full_interface_name,
1241 (int) $2, (Attributes) $1, lexer.Location);
1242 if (current_interface != null) {
1243 Location l = lexer.Location;
1244 Report.Error (-2, l, "Internal compiler error: interface inside interface");
1246 current_interface = new_interface;
1247 RootContext.Tree.RecordDecl (full_interface_name, new_interface);
1248 lexer.ConstraintsParsing = true;
1250 opt_type_parameter_list
1252 opt_type_parameter_constraints_clauses
1254 lexer.ConstraintsParsing = false;
1256 interface_body opt_semicolon
1258 Interface new_interface = (Interface) current_interface;
1260 if ($8 != null && $6 == null)
1261 Report.Error (-200, new_interface.Location,
1262 "Type parameter constraints only valid if there is a type parameter list");
1265 CheckDef (new_interface.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_interface.Name, new_interface.Location);
1267 new_interface.Bases = (ArrayList) $7;
1269 current_interface = null;
1270 CheckDef (current_container.AddInterface (new_interface),
1271 new_interface.Name, new_interface.Location);
1273 | opt_attributes opt_modifiers INTERFACE error {
1274 CheckIdentifierToken (yyToken);
1279 : /* empty */ { $$ = null; }
1284 : COLON interface_type_list { $$ = $2; }
1290 ArrayList interfaces = new ArrayList (4);
1292 interfaces.Add ($1);
1295 | interface_type_list COMMA interface_type
1297 ArrayList interfaces = (ArrayList) $1;
1298 interfaces.Add ($3);
1305 opt_interface_member_declarations
1309 opt_interface_member_declarations
1311 | interface_member_declarations
1314 interface_member_declarations
1315 : interface_member_declaration
1316 | interface_member_declarations interface_member_declaration
1319 interface_member_declaration
1320 : interface_method_declaration
1322 InterfaceMethod m = (InterfaceMethod) $1;
1324 CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
1326 | interface_property_declaration
1328 InterfaceProperty p = (InterfaceProperty) $1;
1330 CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
1332 | interface_event_declaration
1335 InterfaceEvent e = (InterfaceEvent) $1;
1336 CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
1339 | interface_indexer_declaration
1341 InterfaceIndexer i = (InterfaceIndexer) $1;
1343 CheckDef (current_interface.AddIndexer (i), "indexer", i.Location);
1352 val = Modifiers.Check (Modifiers.NEW, val, 0, lexer.Location);
1353 $$ = (bool) (val != 0);
1357 interface_method_declaration
1358 : opt_attributes opt_new type IDENTIFIER
1359 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1362 $$ = new InterfaceMethod ((Expression) $3, (string) $4, (bool) $2,
1363 (Parameters) $6, (Attributes) $1, lexer.Location);
1365 | opt_attributes opt_new VOID IDENTIFIER
1366 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1369 $$ = new InterfaceMethod (
1370 TypeManager.system_void_expr, (string) $4, (bool) $2, (Parameters) $6,
1371 (Attributes) $1, lexer.Location);
1375 interface_property_declaration
1380 { lexer.PropertyParsing = true; }
1382 { lexer.PropertyParsing = false; }
1385 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1387 $$ = new InterfaceProperty ((Expression) $3, (string) $4, (bool) $2,
1388 pinfo.has_get, pinfo.has_set, (Attributes) $1,
1389 pinfo.get_attrs, pinfo.set_attrs,
1395 CheckIdentifierToken (yyToken);
1401 : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null); }
1402 | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1); }
1403 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1404 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3); }
1405 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1406 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1); }
1409 interface_event_declaration
1410 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1412 $$ = new InterfaceEvent ((Expression) $4, (string) $5, (bool) $2, (Attributes) $1,
1415 | opt_attributes opt_new EVENT type error {
1416 CheckIdentifierToken (yyToken);
1419 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1420 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1423 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1424 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1429 interface_indexer_declaration
1430 : opt_attributes opt_new type THIS
1431 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1433 { lexer.PropertyParsing = true; }
1435 { lexer.PropertyParsing = false; }
1438 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1440 bool do_get = info.has_get;
1441 bool do_set = info.has_set;
1443 $$ = new InterfaceIndexer ((Expression) $3, (Parameters) $6, do_get, do_set,
1444 (bool) $2, (Attributes) $1, (Attributes) info.get_attrs,
1445 (Attributes) info.set_attrs, lexer.Location);
1449 operator_declaration
1450 : opt_attributes opt_modifiers operator_declarator
1452 iterator_container = SimpleIteratorContainer.GetSimple ();
1456 OperatorDeclaration decl = (OperatorDeclaration) $3;
1458 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1459 decl.arg2type, decl.arg2name, (Block) $5, (Attributes) $1, decl.location);
1461 if (SimpleIteratorContainer.Simple.Yields)
1464 // Note again, checking is done in semantic analysis
1465 current_container.AddOperator (op);
1467 current_local_parameters = null;
1468 iterator_container = null;
1474 | SEMICOLON { $$ = null; }
1477 : type OPERATOR overloadable_operator
1478 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1480 Operator.OpType op = (Operator.OpType) $3;
1481 CheckUnaryOperator (op);
1483 if (op == Operator.OpType.Addition)
1484 op = Operator.OpType.UnaryPlus;
1486 if (op == Operator.OpType.Subtraction)
1487 op = Operator.OpType.UnaryNegation;
1489 Parameter [] pars = new Parameter [1];
1491 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1493 current_local_parameters = new Parameters (pars, null, lexer.Location);
1495 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1496 null, null, lexer.Location);
1498 | type OPERATOR overloadable_operator
1500 type IDENTIFIER COMMA
1504 CheckBinaryOperator ((Operator.OpType) $3);
1506 Parameter [] pars = new Parameter [2];
1508 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1509 pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1511 current_local_parameters = new Parameters (pars, null, lexer.Location);
1513 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1514 (Expression) $5, (string) $6,
1515 (Expression) $8, (string) $9, lexer.Location);
1517 | conversion_operator_declarator
1520 overloadable_operator
1522 : BANG { $$ = Operator.OpType.LogicalNot; }
1523 | TILDE { $$ = Operator.OpType.OnesComplement; }
1524 | OP_INC { $$ = Operator.OpType.Increment; }
1525 | OP_DEC { $$ = Operator.OpType.Decrement; }
1526 | TRUE { $$ = Operator.OpType.True; }
1527 | FALSE { $$ = Operator.OpType.False; }
1528 // Unary and binary:
1529 | PLUS { $$ = Operator.OpType.Addition; }
1530 | MINUS { $$ = Operator.OpType.Subtraction; }
1532 | STAR { $$ = Operator.OpType.Multiply; }
1533 | DIV { $$ = Operator.OpType.Division; }
1534 | PERCENT { $$ = Operator.OpType.Modulus; }
1535 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1536 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1537 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1538 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1539 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1540 | OP_EQ { $$ = Operator.OpType.Equality; }
1541 | OP_NE { $$ = Operator.OpType.Inequality; }
1542 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1543 | OP_LT { $$ = Operator.OpType.LessThan; }
1544 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1545 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1548 conversion_operator_declarator
1549 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1551 Parameter [] pars = new Parameter [1];
1553 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1555 current_local_parameters = new Parameters (pars, null, lexer.Location);
1557 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1558 null, null, lexer.Location);
1560 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1562 Parameter [] pars = new Parameter [1];
1564 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1566 current_local_parameters = new Parameters (pars, null, lexer.Location);
1568 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1569 null, null, lexer.Location);
1573 syntax_error (lexer.Location, "'operator' expected");
1577 syntax_error (lexer.Location, "'operator' expected");
1581 constructor_declaration
1584 constructor_declarator
1587 Constructor c = (Constructor) $3;
1588 c.Block = (Block) $4;
1589 c.OptAttributes = (Attributes) $1;
1590 c.ModFlags = (int) $2;
1592 if (c.Name == current_container.Basename){
1593 if ((c.ModFlags & Modifiers.STATIC) != 0){
1594 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1596 515, c.Location, String.Format (
1597 "`{0}.{1}': static constructor can not have access modifiers",
1598 c.Name, current_container.Name));
1601 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1603 if (c.Initializer != null){
1606 "Static constructors can not have an explicit this or base " +
1607 "constructor invocations");
1610 if (!c.Parameters.Empty){
1612 132, c.Location, "Static constructors should not have parameters");
1615 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1618 // We let another layer check the validity of the constructor.
1619 Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1622 CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
1624 current_local_parameters = null;
1628 constructor_declarator
1630 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1632 oob_stack.Push (lexer.Location);
1634 current_local_parameters = (Parameters) $3;
1636 opt_constructor_initializer
1638 Location l = (Location) oob_stack.Pop ();
1639 $$ = new Constructor (current_container, (string) $1, 0, (Parameters) $3,
1640 (ConstructorInitializer) $6, l);
1646 | SEMICOLON { $$ = null; }
1649 opt_constructor_initializer
1650 : /* empty */ { $$ = null; }
1651 | constructor_initializer
1654 constructor_initializer
1655 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1657 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1659 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1661 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1664 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1670 : /* EMPTY */ { $$ = 0; }
1671 | UNSAFE { $$ = Modifiers.UNSAFE; }
1672 | EXTERN { $$ = Modifiers.EXTERN; }
1675 destructor_declaration
1676 : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1678 if ((string) $4 != current_container.Basename){
1679 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1680 } else if (!(current_container is Class)){
1681 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1683 Location l = lexer.Location;
1686 if (!RootContext.StdLib && current_container.Name == "System.Object")
1687 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1689 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1691 if ((m & Modifiers.UNSAFE) != 0){
1692 if (!RootContext.Unsafe){
1693 Report.Error (227, l,
1694 "Unsafe code requires the --unsafe command " +
1695 "line option to be specified");
1699 Method d = new Destructor (
1700 current_container, TypeManager.system_void_expr, m, "Finalize",
1701 new Parameters (null, null, l), (Attributes) $1, l);
1703 d.Block = (Block) $7;
1704 CheckDef (current_container.AddMethod (d), d.Name, d.Location);
1712 EVENT type variable_declarators SEMICOLON
1714 foreach (VariableDeclaration var in (ArrayList) $5) {
1716 Event e = new Event ((Expression) $4, var.identifier,
1717 var.expression_or_array_initializer,
1718 (int) $2, null, null, (Attributes) $1, lexer.Location);
1720 CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1726 EVENT type member_name
1729 implicit_value_parameter_type = (Expression) $4;
1730 lexer.EventParsing = true;
1731 oob_stack.Push (lexer.Location);
1733 event_accessor_declarations
1735 lexer.EventParsing = false;
1739 Location loc = (Location) oob_stack.Pop ();
1742 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1745 Pair pair = (Pair) $8;
1746 Accessor add_accessor = null;
1747 Accessor rem_accessor = null;
1749 if (pair.First != null)
1750 add_accessor = (Accessor) pair.First;
1751 if (pair.Second != null)
1752 rem_accessor = (Accessor) pair.Second;
1754 Event e = new Event ((Expression) $4, (string) $5, null, (int) $2, add_accessor, rem_accessor,
1755 (Attributes) $1, loc);
1757 CheckDef (current_container.AddEvent (e), e.Name, loc);
1758 implicit_value_parameter_type = null;
1763 event_accessor_declarations
1764 : add_accessor_declaration remove_accessor_declaration
1766 $$ = new Pair ($1, $2);
1768 | remove_accessor_declaration add_accessor_declaration
1770 $$ = new Pair ($2, $1);
1772 | add_accessor_declaration { $$ = null; }
1773 | remove_accessor_declaration { $$ = null; }
1776 add_accessor_declaration
1777 : opt_attributes ADD
1779 Parameter [] args = new Parameter [1];
1780 Parameter implicit_value_parameter = new Parameter (
1781 implicit_value_parameter_type, "value",
1782 Parameter.Modifier.NONE, null);
1784 args [0] = implicit_value_parameter;
1786 current_local_parameters = new Parameters (args, null, lexer.Location);
1787 lexer.EventParsing = false;
1791 $$ = new Accessor ((Block) $4, (Attributes) $1);
1792 lexer.EventParsing = true;
1794 | opt_attributes ADD error {
1795 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1800 remove_accessor_declaration
1801 : opt_attributes REMOVE
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 REMOVE error {
1819 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1825 : opt_attributes opt_modifiers indexer_declarator
1828 IndexerDeclaration decl = (IndexerDeclaration) $3;
1830 implicit_value_parameter_type = decl.type;
1832 lexer.PropertyParsing = true;
1833 parsing_indexer = true;
1835 indexer_parameters = decl.param_list;
1836 oob_stack.Push (lexer.Location);
1838 accessor_declarations
1840 lexer.PropertyParsing = false;
1841 parsing_indexer = false;
1845 // The signature is computed from the signature of the indexer. Look
1846 // at section 3.6 on the spec
1847 Location loc = (Location) oob_stack.Pop ();
1849 IndexerDeclaration decl = (IndexerDeclaration) $3;
1850 Pair pair = (Pair) $6;
1851 Accessor get_block = (Accessor) pair.First;
1852 Accessor set_block = (Accessor) pair.Second;
1854 indexer = new Indexer (current_container, decl.type, decl.interface_type, (int) $2,
1855 decl.param_list, get_block, set_block, (Attributes) $1, loc);
1857 // Note that there is no equivalent of CheckDef for this case
1858 // We shall handle this in semantic analysis
1860 current_container.AddIndexer (indexer);
1862 current_local_parameters = null;
1863 implicit_value_parameter_type = null;
1864 indexer_parameters = null;
1869 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1871 Parameters pars = (Parameters) $4;
1873 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1874 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1877 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1879 | type member_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1881 Parameters pars = (Parameters) $6;
1883 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1884 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1886 $$ = new IndexerDeclaration ((Expression) $1, $2.ToString (), pars);
1898 Location enum_location = lexer.Location;
1900 string full_name = MakeName ((string) $4);
1901 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
1902 full_name, (Attributes) $1, enum_location);
1904 foreach (VariableDeclaration ev in (ArrayList) $6) {
1905 Location loc = (Location) ev.Location;
1907 CheckDef (e.AddEnumMember (ev.identifier,
1908 (Expression) ev.expression_or_array_initializer,
1909 loc, ev.OptAttributes),
1910 ev.identifier, loc);
1913 CheckDef (current_container.AddEnum (e), full_name, enum_location);
1914 RootContext.Tree.RecordDecl (full_name, e);
1920 : /* empty */ { $$ = TypeManager.system_int32_expr; }
1921 | COLON type { $$ = $2; }
1925 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1931 opt_enum_member_declarations
1932 : /* empty */ { $$ = new ArrayList (4); }
1933 | enum_member_declarations opt_comma { $$ = $1; }
1936 enum_member_declarations
1937 : enum_member_declaration
1939 ArrayList l = new ArrayList (4);
1944 | enum_member_declarations COMMA enum_member_declaration
1946 ArrayList l = (ArrayList) $1;
1954 enum_member_declaration
1955 : opt_attributes IDENTIFIER
1957 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
1959 | opt_attributes IDENTIFIER
1961 $$ = lexer.Location;
1965 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
1969 delegate_declaration
1973 IDENTIFIER OPEN_PARENS
1974 opt_formal_parameter_list
1978 Location l = lexer.Location;
1979 Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
1980 (int) $2, MakeName ((string) $5), (Parameters) $7,
1981 (Attributes) $1, l);
1983 CheckDef (current_container.AddDelegate (del), del.Name, l);
1988 IDENTIFIER OPEN_PARENS
1989 opt_formal_parameter_list
1993 Location l = lexer.Location;
1994 Delegate del = new Delegate (
1995 current_namespace, current_container,
1996 TypeManager.system_void_expr, (int) $2, MakeName ((string) $5),
1997 (Parameters) $7, (Attributes) $1, l);
1999 CheckDef (current_container.AddDelegate (del), del.Name, l);
2004 : namespace_or_type_name
2007 namespace_or_type_name
2008 : IDENTIFIER opt_type_argument_list {
2010 $$ = new SimpleName ((string) $1, lexer.Location);
2012 $$ = new ConstructedType ((string) $1, (TypeArguments) $2, lexer.Location);
2014 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2019 // Third argument will become an Expression, when we have sorted out
2020 // the issues with SimpleName first
2024 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2026 $$ = new GenericMemberAccess ((Expression) $1, (string) $3,
2027 (TypeArguments) $4, lexer.Location);
2029 | namespace_or_type_name DOT DEFAULT
2031 $$ = new DefaultValueExpression ((Expression) $1, lexer.Location);
2037 // Figure out what to do with the list
2039 opt_type_argument_list
2040 : /* empty */ { $$ = null; }
2041 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2049 TypeArguments type_args = new TypeArguments ();
2050 type_args.Add ((Expression) $1);
2053 | type_arguments COMMA type {
2054 TypeArguments type_args = (TypeArguments) $1;
2055 type_args.Add ((Expression) $3);
2061 * Before you think of adding a return_type, notice that we have been
2062 * using two rules in the places where it matters (one rule using type
2063 * and another identical one that uses VOID as the return type). This
2064 * gets rid of a shift/reduce couple
2067 : type_name { /* class_type */
2079 // Note that here only unmanaged types are allowed but we
2080 // can't perform checks during this phase - we do it during
2081 // semantic analysis.
2083 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2087 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2093 | non_expression_type rank_specifier
2095 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2097 | non_expression_type STAR
2099 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2101 | expression rank_specifiers
2103 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2107 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2111 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2112 // through this different path
2114 | multiplicative_expression STAR
2116 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2123 ArrayList types = new ArrayList (4);
2128 | type_list COMMA type
2130 ArrayList types = (ArrayList) $1;
2138 * replaces all the productions for isolating the various
2139 * simple types, but we need this to reuse it easily in local_variable_type
2142 : OBJECT { $$ = TypeManager.system_object_expr; }
2143 | STRING { $$ = TypeManager.system_string_expr; }
2144 | BOOL { $$ = TypeManager.system_boolean_expr; }
2145 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2146 | FLOAT { $$ = TypeManager.system_single_expr; }
2147 | DOUBLE { $$ = TypeManager.system_double_expr; }
2152 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2153 | BYTE { $$ = TypeManager.system_byte_expr; }
2154 | SHORT { $$ = TypeManager.system_int16_expr; }
2155 | USHORT { $$ = TypeManager.system_uint16_expr; }
2156 | INT { $$ = TypeManager.system_int32_expr; }
2157 | UINT { $$ = TypeManager.system_uint32_expr; }
2158 | LONG { $$ = TypeManager.system_int64_expr; }
2159 | ULONG { $$ = TypeManager.system_uint64_expr; }
2160 | CHAR { $$ = TypeManager.system_char_expr; }
2161 | VOID { $$ = TypeManager.system_void_expr; }
2169 : type rank_specifiers
2171 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2176 // Expressions, section 7.5
2188 | parenthesized_expression
2189 | default_value_expression
2191 | invocation_expression
2195 | post_increment_expression
2196 | post_decrement_expression
2200 | checked_expression
2201 | unchecked_expression
2202 | pointer_member_access
2203 | anonymous_method_expression
2210 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2211 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2212 | NULL { $$ = NullLiteral.Null; }
2216 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2217 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2218 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2223 object v = lexer.Value;
2229 $$ = IntLiteral.Zero;
2231 $$ = IntLiteral.One;
2233 $$ = new IntLiteral (i);
2234 } else if (v is uint)
2235 $$ = new UIntLiteral ((UInt32) v);
2237 $$ = new LongLiteral ((Int64) v);
2238 else if (v is ulong)
2239 $$ = new ULongLiteral ((UInt64) v);
2241 Console.WriteLine ("OOPS. Unexpected result from scanner");
2246 : TRUE { $$ = new BoolLiteral (true); }
2247 | FALSE { $$ = new BoolLiteral (false); }
2250 parenthesized_expression_0
2251 : OPEN_PARENS expression CLOSE_PARENS
2254 lexer.Deambiguate_CloseParens ();
2255 // After this, the next token returned is one of
2256 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2257 // or CLOSE_PARENS_MINUS.
2261 parenthesized_expression
2262 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2266 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2268 // If a parenthesized expression is followed by a minus, we need to wrap
2269 // the expression inside a ParenthesizedExpression for the CS0075 check
2270 // in Binary.DoResolve().
2271 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2276 : primary_expression DOT IDENTIFIER
2278 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2280 | predefined_type DOT IDENTIFIER
2282 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2290 invocation_expression
2291 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2294 Location l = lexer.Location;
2295 Report.Error (1, l, "Parse error");
2297 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2299 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2301 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2303 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2305 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2310 : /* empty */ { $$ = null; }
2317 ArrayList list = new ArrayList (4);
2321 | argument_list COMMA argument
2323 ArrayList list = (ArrayList) $1;
2327 | argument_list error {
2328 CheckToken (1026, yyToken, ", or ) expected");
2335 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2337 | REF variable_reference
2339 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2341 | OUT variable_reference
2343 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2348 : expression { note ("section 5.4"); $$ = $1; }
2352 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2354 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2356 | primary_expression rank_specifiers
2358 // So the super-trick is that primary_expression
2359 // can only be either a SimpleName or a MemberAccess.
2360 // The MemberAccess case arises when you have a fully qualified type-name like :
2362 // SimpleName is when you have
2365 Expression expr = (Expression) $1;
2366 if (expr is ComposedCast){
2367 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2368 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2369 Error_ExpectingTypeName (lexer.Location, expr);
2370 $$ = TypeManager.system_object_expr;
2373 // So we extract the string corresponding to the SimpleName
2376 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2384 ArrayList list = new ArrayList (4);
2388 | expression_list COMMA expression
2390 ArrayList list = (ArrayList) $1;
2399 $$ = new This (current_block, lexer.Location);
2404 : BASE DOT IDENTIFIER
2406 $$ = new BaseAccess ((string) $3, lexer.Location);
2408 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2410 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2413 Report.Error (175, "Use of keyword `base' is not valid in this context");
2418 post_increment_expression
2419 : primary_expression OP_INC
2421 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2422 (Expression) $1, lexer.Location);
2426 post_decrement_expression
2427 : primary_expression OP_DEC
2429 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2430 (Expression) $1, lexer.Location);
2435 : object_or_delegate_creation_expression
2436 | array_creation_expression
2439 object_or_delegate_creation_expression
2440 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2442 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2446 array_creation_expression
2447 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2449 opt_array_initializer
2451 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2453 | NEW type rank_specifiers array_initializer
2455 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2459 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2475 : rank_specifier opt_rank_specifier
2477 $$ = (string) $2 + (string) $1;
2482 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2484 $$ = "[" + (string) $2 + "]";
2504 | dim_separators COMMA
2506 $$ = (string) $1 + ",";
2510 opt_array_initializer
2522 : OPEN_BRACE CLOSE_BRACE
2524 ArrayList list = new ArrayList (4);
2527 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2529 $$ = (ArrayList) $2;
2533 variable_initializer_list
2534 : variable_initializer
2536 ArrayList list = new ArrayList (4);
2540 | variable_initializer_list COMMA variable_initializer
2542 ArrayList list = (ArrayList) $1;
2549 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2551 $$ = new TypeOfVoid (lexer.Location);
2553 | TYPEOF OPEN_PARENS type CLOSE_PARENS
2555 $$ = new TypeOf ((Expression) $3, lexer.Location);
2560 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2561 $$ = new SizeOf ((Expression) $3, lexer.Location);
2566 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2568 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2572 unchecked_expression
2573 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2575 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2579 pointer_member_access
2580 : primary_expression OP_PTR IDENTIFIER
2584 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2585 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2589 anonymous_method_expression
2590 : DELEGATE opt_anonymous_method_signature {
2591 oob_stack.Push (current_local_parameters);
2592 current_local_parameters = (Parameters)$2;
2593 create_toplevel_block = true;
2595 create_toplevel_block = false;
2596 if (!RootContext.V2){
2597 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2600 $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
2601 current_local_parameters = (Parameters) oob_stack.Pop ();
2605 opt_anonymous_method_signature
2606 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
2607 | anonymous_method_signature
2610 anonymous_method_signature
2611 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2614 $$ = Parameters.EmptyReadOnlyParameters;
2616 ArrayList par_list = (ArrayList) $2;
2617 Parameter [] pars = new Parameter [par_list.Count];
2618 par_list.CopyTo (pars);
2619 $$ = new Parameters (pars, null, lexer.Location);
2624 opt_anonymous_method_parameter_list
2625 : /* empty */ { $$ = null; }
2626 | anonymous_method_parameter_list { $$ = $1; }
2629 anonymous_method_parameter_list
2630 : anonymous_method_parameter
2632 ArrayList a = new ArrayList (4);
2636 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2638 ArrayList a = (ArrayList) $1;
2644 anonymous_method_parameter
2645 : opt_parameter_modifier type IDENTIFIER {
2646 $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
2650 default_value_expression
2651 : primary_expression DOT DEFAULT
2653 $$ = new DefaultValueExpression ((Expression) $1, lexer.Location);
2655 | predefined_type DOT DEFAULT
2657 $$ = new DefaultValueExpression ((Expression) $1, lexer.Location);
2662 : primary_expression
2663 | BANG prefixed_unary_expression
2665 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2667 | TILDE prefixed_unary_expression
2669 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2675 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2677 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2679 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2681 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2687 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2689 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2694 // The idea to split this out is from Rhys' grammar
2695 // to solve the problem with casts.
2697 prefixed_unary_expression
2699 | PLUS prefixed_unary_expression
2701 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2703 | MINUS prefixed_unary_expression
2705 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2707 | OP_INC prefixed_unary_expression
2709 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2710 (Expression) $2, lexer.Location);
2712 | OP_DEC prefixed_unary_expression
2714 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2715 (Expression) $2, lexer.Location);
2717 | STAR prefixed_unary_expression
2719 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2721 | BITWISE_AND prefixed_unary_expression
2723 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2727 pre_increment_expression
2728 : OP_INC prefixed_unary_expression
2730 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2731 (Expression) $2, lexer.Location);
2735 pre_decrement_expression
2736 : OP_DEC prefixed_unary_expression
2738 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2739 (Expression) $2, lexer.Location);
2743 multiplicative_expression
2744 : prefixed_unary_expression
2745 | multiplicative_expression STAR prefixed_unary_expression
2747 $$ = new Binary (Binary.Operator.Multiply,
2748 (Expression) $1, (Expression) $3, lexer.Location);
2750 | multiplicative_expression DIV prefixed_unary_expression
2752 $$ = new Binary (Binary.Operator.Division,
2753 (Expression) $1, (Expression) $3, lexer.Location);
2755 | multiplicative_expression PERCENT prefixed_unary_expression
2757 $$ = new Binary (Binary.Operator.Modulus,
2758 (Expression) $1, (Expression) $3, lexer.Location);
2763 : multiplicative_expression
2764 | additive_expression PLUS multiplicative_expression
2766 $$ = new Binary (Binary.Operator.Addition,
2767 (Expression) $1, (Expression) $3, lexer.Location);
2769 | additive_expression MINUS multiplicative_expression
2771 $$ = new Binary (Binary.Operator.Subtraction,
2772 (Expression) $1, (Expression) $3, lexer.Location);
2777 : additive_expression
2778 | shift_expression OP_SHIFT_LEFT additive_expression
2780 $$ = new Binary (Binary.Operator.LeftShift,
2781 (Expression) $1, (Expression) $3, lexer.Location);
2783 | shift_expression OP_SHIFT_RIGHT additive_expression
2785 $$ = new Binary (Binary.Operator.RightShift,
2786 (Expression) $1, (Expression) $3, lexer.Location);
2790 relational_expression
2792 | relational_expression OP_LT shift_expression
2794 $$ = new Binary (Binary.Operator.LessThan,
2795 (Expression) $1, (Expression) $3, lexer.Location);
2797 | relational_expression OP_GT shift_expression
2799 $$ = new Binary (Binary.Operator.GreaterThan,
2800 (Expression) $1, (Expression) $3, lexer.Location);
2802 | relational_expression OP_LE shift_expression
2804 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2805 (Expression) $1, (Expression) $3, lexer.Location);
2807 | relational_expression OP_GE shift_expression
2809 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2810 (Expression) $1, (Expression) $3, lexer.Location);
2812 | relational_expression IS type
2814 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2816 | relational_expression AS type
2818 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2823 : relational_expression
2824 | equality_expression OP_EQ relational_expression
2826 $$ = new Binary (Binary.Operator.Equality,
2827 (Expression) $1, (Expression) $3, lexer.Location);
2829 | equality_expression OP_NE relational_expression
2831 $$ = new Binary (Binary.Operator.Inequality,
2832 (Expression) $1, (Expression) $3, lexer.Location);
2837 : equality_expression
2838 | and_expression BITWISE_AND equality_expression
2840 $$ = new Binary (Binary.Operator.BitwiseAnd,
2841 (Expression) $1, (Expression) $3, lexer.Location);
2845 exclusive_or_expression
2847 | exclusive_or_expression CARRET and_expression
2849 $$ = new Binary (Binary.Operator.ExclusiveOr,
2850 (Expression) $1, (Expression) $3, lexer.Location);
2854 inclusive_or_expression
2855 : exclusive_or_expression
2856 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2858 $$ = new Binary (Binary.Operator.BitwiseOr,
2859 (Expression) $1, (Expression) $3, lexer.Location);
2863 conditional_and_expression
2864 : inclusive_or_expression
2865 | conditional_and_expression OP_AND inclusive_or_expression
2867 $$ = new Binary (Binary.Operator.LogicalAnd,
2868 (Expression) $1, (Expression) $3, lexer.Location);
2872 conditional_or_expression
2873 : conditional_and_expression
2874 | conditional_or_expression OP_OR conditional_and_expression
2876 $$ = new Binary (Binary.Operator.LogicalOr,
2877 (Expression) $1, (Expression) $3, lexer.Location);
2881 conditional_expression
2882 : conditional_or_expression
2883 | conditional_or_expression INTERR expression COLON expression
2885 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2889 assignment_expression
2890 : prefixed_unary_expression ASSIGN expression
2892 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2894 | prefixed_unary_expression OP_MULT_ASSIGN expression
2896 Location l = lexer.Location;
2898 $$ = new CompoundAssign (
2899 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
2901 | prefixed_unary_expression OP_DIV_ASSIGN expression
2903 Location l = lexer.Location;
2905 $$ = new CompoundAssign (
2906 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
2908 | prefixed_unary_expression OP_MOD_ASSIGN expression
2910 Location l = lexer.Location;
2912 $$ = new CompoundAssign (
2913 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
2915 | prefixed_unary_expression OP_ADD_ASSIGN expression
2917 Location l = lexer.Location;
2919 $$ = new CompoundAssign (
2920 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
2922 | prefixed_unary_expression OP_SUB_ASSIGN expression
2924 Location l = lexer.Location;
2926 $$ = new CompoundAssign (
2927 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
2929 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2931 Location l = lexer.Location;
2933 $$ = new CompoundAssign (
2934 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
2936 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2938 Location l = lexer.Location;
2940 $$ = new CompoundAssign (
2941 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
2943 | prefixed_unary_expression OP_AND_ASSIGN expression
2945 Location l = lexer.Location;
2947 $$ = new CompoundAssign (
2948 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
2950 | prefixed_unary_expression OP_OR_ASSIGN expression
2952 Location l = lexer.Location;
2954 $$ = new CompoundAssign (
2955 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
2957 | prefixed_unary_expression OP_XOR_ASSIGN expression
2959 Location l = lexer.Location;
2961 $$ = new CompoundAssign (
2962 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
2967 : conditional_expression
2968 | assignment_expression
2990 name = MakeName ((string) $4);
2992 new_class = new Class (current_namespace, current_container, name, (int) $2,
2993 (Attributes) $1, lexer.Location);
2994 current_container = new_class;
2995 RootContext.Tree.RecordDecl (name, new_class);
2997 lexer.ConstraintsParsing = true;
2999 opt_type_parameter_list
3001 opt_type_parameter_constraints_clauses
3003 lexer.ConstraintsParsing = false;
3008 Class new_class = (Class) current_container;
3010 if ($8 != null && $6 == null)
3011 Report.Error (-200, new_class.Location,
3012 "Type parameter constraints only valid if there is a type parameter list");
3015 CheckDef (new_class.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_class.Name, new_class.Location);
3017 if (new_class.Name == "System.Object") {
3018 Report.Error (537, new_class.Location, "The class System.Object cannot have a base class or implement an interface.");
3021 new_class.Bases = (ArrayList) $7;
3023 current_container = current_container.Parent;
3024 CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
3032 lexer.ConstraintsParsing = true;
3035 Report.Error (-200, lexer.Location,
3036 "Type parameter constraints only valid if there is a type parameter list");
3043 : /* empty */ { $$ = (int) 0; }
3049 | modifiers modifier
3054 if ((m1 & m2) != 0) {
3055 Location l = lexer.Location;
3056 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3058 $$ = (int) (m1 | m2);
3063 : NEW { $$ = Modifiers.NEW; }
3064 | PUBLIC { $$ = Modifiers.PUBLIC; }
3065 | PROTECTED { $$ = Modifiers.PROTECTED; }
3066 | INTERNAL { $$ = Modifiers.INTERNAL; }
3067 | PRIVATE { $$ = Modifiers.PRIVATE; }
3068 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3069 | SEALED { $$ = Modifiers.SEALED; }
3070 | STATIC { $$ = Modifiers.STATIC; }
3071 | READONLY { $$ = Modifiers.READONLY; }
3072 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3073 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3074 | EXTERN { $$ = Modifiers.EXTERN; }
3075 | VOLATILE { $$ = Modifiers.VOLATILE; }
3076 | UNSAFE { $$ = Modifiers.UNSAFE; }
3080 : /* empty */ { $$ = null; }
3081 | class_base { $$ = $1; }
3085 : COLON type_list { $$ = $2; }
3088 opt_type_parameter_list
3089 : /* empty */ { $$ = null; }
3090 | type_parameter_list { $$ = $1; }
3094 : OP_GENERICS_LT type_parameters OP_GENERICS_GT { $$ = $2; }
3100 // Do some profiling to find the optimal size, for now we
3101 // assume most people will be generic on one type (saves space
3103 ArrayList type_parameters = new ArrayList (1);
3104 type_parameters.Add ($1);
3105 $$ = type_parameters;
3107 | type_parameters COMMA type_parameter {
3108 ArrayList type_parameters = (ArrayList) $1;
3110 type_parameters.Add ($3);
3111 $$ = type_parameters;
3119 opt_type_parameter_constraints_clauses
3120 : /* empty */ { $$ = null; }
3121 | type_parameter_constraints_clauses
3125 type_parameter_constraints_clauses
3126 : type_parameter_constraints_clause
3127 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3128 ArrayList constraints = (ArrayList) $1;
3130 constraints.Add ($2);
3135 type_parameter_constraints_clause
3136 : WHERE type_parameter COLON type_parameter_constraints {
3137 ArrayList constraints = new ArrayList (1);
3138 constraints.Add (new Constraints ((string) $2, (ArrayList) $4, lexer.Location));
3143 type_parameter_constraints
3144 : type_parameter_constraint {
3145 ArrayList constraints = new ArrayList (1);
3146 constraints.Add ($1);
3149 | type_parameter_constraints COMMA type_parameter_constraint {
3150 ArrayList constraints = (ArrayList) $1;
3152 constraints.Add ($3);
3157 type_parameter_constraint
3159 | NEW OPEN_PARENS CLOSE_PARENS {
3169 // A block is "contained" on the following places:
3171 // property_declaration as part of the accessor body (get/set)
3172 // operator_declaration
3173 // constructor_declaration
3174 // destructor_declaration
3175 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3180 if (current_block == null || create_toplevel_block){
3181 current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
3183 current_block = new Block (current_block, current_local_parameters,
3184 lexer.Location, Location.Null);
3187 opt_statement_list CLOSE_BRACE
3189 while (current_block.Implicit)
3190 current_block = current_block.Parent;
3192 current_block.SetEndLocation (lexer.Location);
3193 current_block = current_block.Parent;
3204 | statement_list statement
3208 : declaration_statement
3210 if ($1 != null && (Block) $1 != current_block){
3211 current_block.AddStatement ((Statement) $1);
3212 current_block = (Block) $1;
3215 | embedded_statement
3217 current_block.AddStatement ((Statement) $1);
3225 | expression_statement
3226 | selection_statement
3227 | iteration_statement
3231 | unchecked_statement
3241 $$ = EmptyStatement.Value;
3248 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3250 if (!current_block.AddLabel ((string) $1, labeled)){
3251 Location l = lexer.Location;
3252 Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
3254 current_block.AddStatement (labeled);
3259 declaration_statement
3260 : local_variable_declaration SEMICOLON
3263 DictionaryEntry de = (DictionaryEntry) $1;
3265 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3269 | local_constant_declaration SEMICOLON
3272 DictionaryEntry de = (DictionaryEntry) $1;
3274 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3280 * The following is from Rhys' grammar:
3281 * > Types in local variable declarations must be recognized as
3282 * > expressions to prevent reduce/reduce errors in the grammar.
3283 * > The expressions are converted into types during semantic analysis.
3286 : primary_expression opt_rank_specifier
3288 // FIXME: Do something smart here regarding the composition of the type.
3290 // Ok, the above "primary_expression" is there to get rid of
3291 // both reduce/reduce and shift/reduces in the grammar, it should
3292 // really just be "type_name". If you use type_name, a reduce/reduce
3293 // creeps up. If you use namespace_or_type_name (which is all we need
3294 // really) two shift/reduces appear.
3297 // So the super-trick is that primary_expression
3298 // can only be either a SimpleName or a MemberAccess.
3299 // The MemberAccess case arises when you have a fully qualified type-name like :
3301 // SimpleName is when you have
3304 Expression expr = (Expression) $1;
3305 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3306 Error_ExpectingTypeName (lexer.Location, expr);
3310 // So we extract the string corresponding to the SimpleName
3314 if ((string) $2 == "")
3317 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3320 | builtin_types opt_rank_specifier
3322 if ((string) $2 == "")
3325 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3329 local_variable_pointer_type
3330 : primary_expression STAR
3332 Expression expr = (Expression) $1;
3333 Location l = lexer.Location;
3335 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3336 Error_ExpectingTypeName (l, expr);
3340 $$ = new ComposedCast ((Expression) $1, "*", l);
3342 | builtin_types STAR
3344 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3348 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3350 | local_variable_pointer_type STAR
3352 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3356 local_variable_declaration
3357 : local_variable_type variable_declarators
3360 $$ = new DictionaryEntry ($1, $2);
3364 | local_variable_pointer_type opt_rank_specifier variable_declarators
3369 if ((string) $2 == "")
3370 t = (Expression) $1;
3372 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3373 $$ = new DictionaryEntry (t, $3);
3379 local_constant_declaration
3380 : CONST local_variable_type constant_declarators
3383 $$ = new DictionaryEntry ($2, $3);
3389 expression_statement
3390 : statement_expression SEMICOLON
3397 // We have to do the wrapping here and not in the case above,
3398 // because statement_expression is used for example in for_statement
3400 statement_expression
3401 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3402 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3403 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3404 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3405 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3406 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3407 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3409 Report.Error (1002, lexer.Location, "Expecting `;'");
3414 object_creation_expression
3415 : object_or_delegate_creation_expression
3416 { note ("complain if this is a delegate maybe?"); }
3425 : if_statement_open if_statement_rest
3434 oob_stack.Push (lexer.Location);
3439 : boolean_expression CLOSE_PARENS
3442 Location l = (Location) oob_stack.Pop ();
3444 $$ = new If ((Expression) $1, (Statement) $3, l);
3446 if (RootContext.WarningLevel >= 3){
3447 if ($3 == EmptyStatement.Value)
3448 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3452 | boolean_expression CLOSE_PARENS
3453 embedded_statement ELSE embedded_statement
3455 Location l = (Location) oob_stack.Pop ();
3457 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3462 : SWITCH OPEN_PARENS
3464 oob_stack.Push (lexer.Location);
3465 switch_stack.Push (current_block);
3467 expression CLOSE_PARENS
3470 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3471 current_block = (Block) switch_stack.Pop ();
3487 Report.Error (1522, lexer.Location, "Empty switch block");
3495 ArrayList sections = new ArrayList (4);
3500 | switch_sections switch_section
3502 ArrayList sections = (ArrayList) $1;
3512 current_block = current_block.CreateSwitchBlock (lexer.Location);
3516 Block topmost = current_block;
3518 while (topmost.Implicit)
3519 topmost = topmost.Parent;
3520 $$ = new SwitchSection ((ArrayList) $1, topmost);
3527 ArrayList labels = new ArrayList (4);
3532 | switch_labels switch_label
3534 ArrayList labels = (ArrayList) ($1);
3542 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3543 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3546 1523, lexer.Location,
3547 "The keyword case or default must precede code in switch block");
3561 oob_stack.Push (lexer.Location);
3563 boolean_expression CLOSE_PARENS embedded_statement
3565 Location l = (Location) oob_stack.Pop ();
3566 $$ = new While ((Expression) $4, (Statement) $6, l);
3568 if (RootContext.WarningLevel >= 3){
3569 if ($6 == EmptyStatement.Value)
3570 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3576 : DO embedded_statement
3578 oob_stack.Push (lexer.Location);
3580 boolean_expression CLOSE_PARENS SEMICOLON
3582 Location l = (Location) oob_stack.Pop ();
3584 $$ = new Do ((Statement) $2, (Expression) $6, l);
3590 opt_for_initializer SEMICOLON
3592 Block assign_block = new Block (current_block);
3593 current_block = assign_block;
3595 if ($3 is DictionaryEntry){
3596 DictionaryEntry de = (DictionaryEntry) $3;
3598 Expression type = (Expression) de.Key;
3599 ArrayList var_declarators = (ArrayList) de.Value;
3601 foreach (VariableDeclaration decl in var_declarators){
3605 vi = current_block.AddVariable (
3606 type, decl.identifier, current_local_parameters, decl.Location);
3610 Location l = lexer.Location;
3612 if (decl.expression_or_array_initializer is Expression){
3613 expr = (Expression) decl.expression_or_array_initializer;
3614 } else if (decl.expression_or_array_initializer == null) {
3617 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3618 expr = new ArrayCreation (type, "", init, decl.Location);
3621 LocalVariableReference var;
3622 var = new LocalVariableReference (assign_block, decl.identifier, l);
3625 Assign a = new Assign (var, expr, decl.Location);
3627 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3633 oob_stack.Push (lexer.Location);
3635 opt_for_condition SEMICOLON
3636 opt_for_iterator CLOSE_PARENS
3639 Location l = (Location) oob_stack.Pop ();
3641 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3643 if (RootContext.WarningLevel >= 3){
3644 if ($10 == EmptyStatement.Value)
3645 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3648 current_block.AddStatement (f);
3649 while (current_block.Implicit)
3650 current_block = current_block.Parent;
3652 current_block = current_block.Parent;
3657 : /* empty */ { $$ = EmptyStatement.Value; }
3662 : local_variable_declaration
3663 | statement_expression_list
3667 : /* empty */ { $$ = null; }
3668 | boolean_expression
3672 : /* empty */ { $$ = EmptyStatement.Value; }
3677 : statement_expression_list
3680 statement_expression_list
3681 : statement_expression
3683 // CHANGE: was `null'
3684 Block b = new Block (current_block, Block.Flags.Implicit);
3686 b.AddStatement ((Statement) $1);
3689 | statement_expression_list COMMA statement_expression
3691 Block b = (Block) $1;
3693 b.AddStatement ((Statement) $3);
3699 : FOREACH OPEN_PARENS type IDENTIFIER IN
3701 oob_stack.Push (lexer.Location);
3703 expression CLOSE_PARENS
3705 oob_stack.Push (current_block);
3707 Block foreach_block = new Block (current_block, Block.Flags.Implicit);
3708 LocalVariableReference v = null;
3709 Location l = lexer.Location;
3712 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3716 // Get a writable reference to this read-only variable.
3717 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3719 current_block = foreach_block;
3722 oob_stack.Push (current_block);
3726 Block foreach_block = (Block) oob_stack.Pop ();
3727 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3728 Block prev_block = (Block) oob_stack.Pop ();
3729 Location l = (Location) oob_stack.Pop ();
3731 current_block = prev_block;
3734 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3735 foreach_block.AddStatement (f);
3744 | continue_statement
3754 $$ = new Break (lexer.Location);
3759 : CONTINUE SEMICOLON
3761 $$ = new Continue (lexer.Location);
3766 : GOTO IDENTIFIER SEMICOLON
3768 $$ = new Goto (current_block, (string) $2, lexer.Location);
3770 | GOTO CASE constant_expression SEMICOLON
3772 $$ = new GotoCase ((Expression) $3, lexer.Location);
3774 | GOTO DEFAULT SEMICOLON
3776 $$ = new GotoDefault (lexer.Location);
3781 : RETURN opt_expression SEMICOLON
3783 $$ = new Return ((Expression) $2, lexer.Location);
3788 : THROW opt_expression SEMICOLON
3790 $$ = new Throw ((Expression) $2, lexer.Location);
3795 : IDENTIFIER RETURN expression SEMICOLON
3797 string s = (string) $1;
3799 Report.Error (1003, lexer.Location, "; expected");
3802 if (!RootContext.V2){
3803 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3806 if (iterator_container == null){
3807 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3810 iterator_container.SetYields ();
3811 $$ = new Yield ((Expression) $3, lexer.Location);
3814 | IDENTIFIER BREAK SEMICOLON
3816 string s = (string) $1;
3818 Report.Error (1003, lexer.Location, "; expected");
3821 if (!RootContext.V2){
3822 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3825 if (iterator_container == null){
3826 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3829 iterator_container.SetYields ();
3830 $$ = new YieldBreak (lexer.Location);
3841 : TRY block catch_clauses
3844 ArrayList s = new ArrayList (4);
3846 foreach (Catch cc in (ArrayList) $3) {
3853 // Now s contains the list of specific catch clauses
3854 // and g contains the general one.
3856 $$ = new Try ((Block) $2, s, g, null, lexer.Location);
3858 | TRY block opt_catch_clauses FINALLY block
3861 ArrayList s = new ArrayList (4);
3862 ArrayList catch_list = (ArrayList) $3;
3864 if (catch_list != null){
3865 foreach (Catch cc in catch_list) {
3873 $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
3877 Report.Error (1524, lexer.Location, "Expected catch or finally");
3882 : /* empty */ { $$ = null; }
3889 ArrayList l = new ArrayList (4);
3894 | catch_clauses catch_clause
3896 ArrayList l = (ArrayList) $1;
3904 : /* empty */ { $$ = null; }
3909 : CATCH opt_catch_args
3911 Expression type = null;
3915 DictionaryEntry cc = (DictionaryEntry) $2;
3916 type = (Expression) cc.Key;
3917 id = (string) cc.Value;
3920 ArrayList one = new ArrayList (4);
3921 Location loc = lexer.Location;
3923 one.Add (new VariableDeclaration (id, null, loc));
3926 current_block = new Block (current_block);
3927 Block b = declare_local_variables (type, one, loc);
3932 Expression type = null;
3936 DictionaryEntry cc = (DictionaryEntry) $2;
3937 type = (Expression) cc.Key;
3938 id = (string) cc.Value;
3942 // FIXME: I can change this for an assignment.
3944 while (current_block != (Block) $1)
3945 current_block = current_block.Parent;
3950 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3955 : /* empty */ { $$ = null; }
3960 : OPEN_PARENS type opt_identifier CLOSE_PARENS
3962 $$ = new DictionaryEntry ($2, $3);
3969 $$ = new Checked ((Block) $2);
3976 $$ = new Unchecked ((Block) $2);
3983 if (!RootContext.Unsafe){
3984 Report.Error (227, lexer.Location,
3985 "Unsafe code can only be used if --unsafe is used");
3988 $$ = new Unsafe ((Block) $3);
3994 type fixed_pointer_declarators
3997 Block assign_block = new Block (current_block, Block.Flags.Implicit);
3998 ArrayList list = (ArrayList) $4;
3999 Expression type = (Expression) $3;
4000 Location l = lexer.Location;
4001 int top = list.Count;
4003 for (int i = 0; i < top; i++){
4004 Pair p = (Pair) list [i];
4007 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4014 current_block.AddStatement (assign_block);
4015 current_block = assign_block;
4016 oob_stack.Push (assign_block);
4021 Location l = (Location) oob_stack.Pop ();
4024 $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4028 fixed_pointer_declarators
4029 : fixed_pointer_declarator {
4030 ArrayList declarators = new ArrayList (4);
4031 declarators.Add ($1);
4034 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4036 ArrayList declarators = (ArrayList) $1;
4037 declarators.Add ($3);
4042 fixed_pointer_declarator
4043 : IDENTIFIER ASSIGN expression
4045 $$ = new Pair ($1, $3);
4050 : LOCK OPEN_PARENS expression CLOSE_PARENS
4056 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4061 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4063 Block assign_block = new Block (current_block);
4064 current_block = assign_block;
4066 oob_stack.Push (lexer.Location);
4068 if ($3 is DictionaryEntry){
4069 DictionaryEntry de = (DictionaryEntry) $3;
4070 Location l = lexer.Location;
4072 Expression type = (Expression) de.Key;
4073 ArrayList var_declarators = (ArrayList) de.Value;
4075 ArrayList vars = new ArrayList (4);
4077 foreach (VariableDeclaration decl in var_declarators){
4079 LocalInfo vi = current_block.AddVariable (
4080 type, decl.identifier,
4081 current_local_parameters, decl.Location);
4087 if (decl.expression_or_array_initializer is Expression){
4088 expr = (Expression) decl.expression_or_array_initializer;
4090 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4092 expr = new ArrayCreation (type, "", init, decl.Location);
4095 LocalVariableReference var;
4097 // Get a writable reference to this read-only variable.
4098 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4100 // This is so that it is not a warning on using variables
4103 vars.Add (new DictionaryEntry (var, expr));
4105 // Assign a = new Assign (var, expr, decl.Location);
4106 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4108 $3 = new DictionaryEntry (type, vars);
4113 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4114 current_block.AddStatement (u);
4115 while (current_block.Implicit)
4116 current_block = current_block.Parent;
4118 current_block = current_block.Parent;
4122 resource_acquisition
4123 : local_variable_declaration
4130 // A class used to pass around variable declarations and constants
4132 public class VariableDeclaration {
4133 public string identifier;
4134 public object expression_or_array_initializer;
4135 public Location Location;
4136 public Attributes OptAttributes;
4138 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4140 this.identifier = id;
4141 this.expression_or_array_initializer = eoai;
4143 this.OptAttributes = opt_attrs;
4146 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4152 /// Used to pass around interface property information
4154 public class InterfaceAccessorInfo {
4156 public bool has_get;
4157 public bool has_set;
4158 public Attributes get_attrs;
4159 public Attributes set_attrs;
4161 public InterfaceAccessorInfo (bool has_get, bool has_set,
4162 Attributes get_attrs, Attributes set_attrs)
4164 this.has_get = has_get;
4165 this.has_set = has_set;
4166 this.get_attrs = get_attrs;
4167 this.set_attrs = set_attrs;
4173 // A class used to hold info about an indexer declarator
4175 public class IndexerDeclaration {
4176 public Expression type;
4177 public string interface_type;
4178 public Parameters param_list;
4180 public IndexerDeclaration (Expression type, string interface_type, Parameters param_list)
4183 this.interface_type = interface_type;
4184 this.param_list = param_list;
4189 // We use this when we do not have an object in advance that is an IIteratorContainer
4191 public class SimpleIteratorContainer : IIteratorContainer {
4194 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4199 public static SimpleIteratorContainer GetSimple () {
4200 Simple.Yields = false;
4204 public void SetYields () { Yields = true; }
4208 // A class used to hold info about an operator declarator
4210 public class OperatorDeclaration {
4211 public Operator.OpType optype;
4212 public Expression ret_type, arg1type, arg2type;
4213 public string arg1name, arg2name;
4214 public Location location;
4216 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4217 Expression arg1type, string arg1name,
4218 Expression arg2type, string arg2name, Location location)
4221 this.ret_type = ret_type;
4222 this.arg1type = arg1type;
4223 this.arg1name = arg1name;
4224 this.arg2type = arg2type;
4225 this.arg2name = arg2name;
4226 this.location = location;
4231 void Error_ExpectingTypeName (Location l, Expression expr)
4233 if (expr is Invocation){
4234 Report.Error (1002, l, "; expected");
4236 Report.Error (-1, l, "Invalid Type definition");
4241 // Given the @class_name name, it creates a fully qualified name
4242 // based on the containing declaration space
4245 MakeName (string class_name)
4247 string ns = current_namespace.FullName;
4248 string container_name = current_container.Name;
4250 if (container_name == ""){
4252 return ns + "." + class_name;
4256 return container_name + "." + class_name;
4260 // Used to report back to the user the result of a declaration
4261 // in the current declaration space
4264 CheckDef (DeclSpace.AdditionResult result, string name, Location l)
4266 if (result == DeclSpace.AdditionResult.Success)
4270 case DeclSpace.AdditionResult.NameExists:
4271 Report.Error (102, l, "The container `" + current_container.Name +
4272 "' already contains a definition for `"+
4278 // This is handled only for static Constructors, because
4279 // in reality we handle these by the semantic analysis later
4281 case DeclSpace.AdditionResult.MethodExists:
4283 111, l, "Class `"+current_container.Name+
4284 "' already defines a member called '" +
4285 name + "' with the same parameter types (more than one default constructor)");
4288 case DeclSpace.AdditionResult.EnclosingClash:
4289 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
4292 case DeclSpace.AdditionResult.NotAConstructor:
4293 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
4296 case DeclSpace.AdditionResult.Error:
4297 // Error has already been reported.
4303 CheckDef (bool result, string name, Location l)
4307 CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
4310 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4312 Block implicit_block;
4313 ArrayList inits = null;
4316 // We use the `Used' property to check whether statements
4317 // have been added to the current block. If so, we need
4318 // to create another block to contain the new declaration
4319 // otherwise, as an optimization, we use the same block to
4320 // add the declaration.
4322 // FIXME: A further optimization is to check if the statements
4323 // that were added were added as part of the initialization
4324 // below. In which case, no other statements have been executed
4325 // and we might be able to reduce the number of blocks for
4326 // situations like this:
4328 // int j = 1; int k = j + 1;
4330 if (current_block.Used) {
4331 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4332 implicit_block.AddChildVariableNames (current_block);
4334 implicit_block = current_block;
4336 foreach (VariableDeclaration decl in variable_declarators){
4338 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4339 if (decl.expression_or_array_initializer != null){
4341 inits = new ArrayList (4);
4348 return implicit_block;
4350 foreach (VariableDeclaration decl in inits){
4354 if (decl.expression_or_array_initializer is Expression){
4355 expr = (Expression) decl.expression_or_array_initializer;
4358 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4360 expr = new ArrayCreation (type, "", init, decl.Location);
4363 LocalVariableReference var;
4364 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4366 assign = new Assign (var, expr, decl.Location);
4368 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4371 return implicit_block;
4374 Block declare_local_constants (Expression type, ArrayList declarators)
4376 Block implicit_block;
4378 if (current_block.Used)
4379 implicit_block = new Block (current_block, Block.Flags.Implicit);
4381 implicit_block = current_block;
4383 foreach (VariableDeclaration decl in declarators){
4384 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4385 current_local_parameters, decl.Location);
4388 return implicit_block;
4391 void CheckAttributeTarget (string a)
4395 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4399 Location l = lexer.Location;
4400 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4406 void CheckUnaryOperator (Operator.OpType op)
4410 case Operator.OpType.LogicalNot:
4411 case Operator.OpType.OnesComplement:
4412 case Operator.OpType.Increment:
4413 case Operator.OpType.Decrement:
4414 case Operator.OpType.True:
4415 case Operator.OpType.False:
4416 case Operator.OpType.Addition:
4417 case Operator.OpType.Subtraction:
4422 Location l = lexer.Location;
4423 Report.Error (1019, l, "Overloadable unary operator expected");
4429 void CheckBinaryOperator (Operator.OpType op)
4433 case Operator.OpType.Addition:
4434 case Operator.OpType.Subtraction:
4435 case Operator.OpType.Multiply:
4436 case Operator.OpType.Division:
4437 case Operator.OpType.Modulus:
4438 case Operator.OpType.BitwiseAnd:
4439 case Operator.OpType.BitwiseOr:
4440 case Operator.OpType.ExclusiveOr:
4441 case Operator.OpType.LeftShift:
4442 case Operator.OpType.RightShift:
4443 case Operator.OpType.Equality:
4444 case Operator.OpType.Inequality:
4445 case Operator.OpType.GreaterThan:
4446 case Operator.OpType.LessThan:
4447 case Operator.OpType.GreaterThanOrEqual:
4448 case Operator.OpType.LessThanOrEqual:
4452 Location l = lexer.Location;
4453 Report.Error (1020, l, "Overloadable binary operator expected");
4459 void syntax_error (Location l, string msg)
4461 Report.Error (1003, l, "Syntax error, " + msg);
4464 void output (string s)
4466 Console.WriteLine (s);
4469 void note (string s)
4471 // Used to put annotations
4476 public Tokenizer Lexer {
4482 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4484 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4485 this.name = file.Name;
4487 current_container = RootContext.Tree.Types;
4488 current_container.NamespaceEntry = current_namespace;
4489 oob_stack = new Stack ();
4490 switch_stack = new Stack ();
4492 lexer = new Tokenizer (reader, file, defines);
4495 public void parse ()
4498 if (yacc_verbose_flag)
4499 yyparse (lexer, new yydebug.yyDebugSimple ());
4502 Tokenizer tokenizer = lexer as Tokenizer;
4503 tokenizer.cleanup ();
4504 } catch (Exception e){
4505 // Please do not remove this, it is used during debugging
4508 Console.WriteLine (e);
4509 Report.Error (-25, lexer.Location, "Parsing error");
4510 if (Driver.parser_verbose)
4511 Console.WriteLine (e);
4515 void CheckToken (int error, int yyToken, string msg)
4517 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4518 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4521 Report.Error (error, lexer.Location, msg);
4524 void CheckIdentifierToken (int yyToken)
4526 CheckToken (1041, yyToken, "Identifier expected");