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 current_namespace.UsingAlias ((string) $2, (TypeName) $4, lexer.Location);
327 CheckIdentifierToken (yyToken);
331 using_namespace_directive
332 : USING namespace_name SEMICOLON
334 current_namespace.Using ((string) $2, lexer.Location);
339 // Strictly speaking, namespaces don't have attributes but
340 // we parse global attributes along with namespace declarations and then
343 namespace_declaration
344 : opt_attributes NAMESPACE namespace_name
346 Attributes attrs = (Attributes) $1;
349 foreach (AttributeSection asec in attrs.AttributeSections)
350 if (asec.Target == "assembly")
351 CodeGen.Assembly.AddAttribute (current_container, asec);
353 Report.Error(1518, Lexer.Location,
354 "Attributes cannot be applied to namespaces."
355 + " Expected class, delegate, enum, interface, or struct");
358 current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, (string) $3, lexer.Location);
360 namespace_body opt_semicolon
362 current_namespace = current_namespace.Parent;
377 : namespace_or_type_name {
378 TypeName name = (TypeName) $1;
380 if (name.TypeArguments != null)
381 syntax_error (lexer.Location, "namespace name expected");
383 $$ = name.GetName ();
390 opt_namespace_member_declarations
401 opt_namespace_member_declarations
403 | namespace_member_declarations
406 namespace_member_declarations
407 : namespace_member_declaration
408 | namespace_member_declarations namespace_member_declaration
411 namespace_member_declaration
418 Class c = (Class) $1;
419 mod_flags = c.ModFlags;
421 } else if ($1 is Struct){
422 Struct s = (Struct) $1;
423 mod_flags = s.ModFlags;
428 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
430 1527, lexer.Location,
431 "Namespace elements cant be explicitly " +
432 "declared private or protected in `" + name + "'");
434 current_namespace.DeclarationFound = true;
436 | namespace_declaration {
437 current_namespace.DeclarationFound = true;
440 | field_declaration {
441 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
443 | method_declaration {
444 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
451 | interface_declaration
453 | delegate_declaration
455 // Enable this when we have handled all errors, because this acts as a generic fallback
458 // Console.WriteLine ("Token=" + yyToken);
459 // Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
469 | attribute_sections { $$ = $1; }
475 AttributeSection sect = (AttributeSection) $1;
477 if (sect.Target == "assembly") {
478 CodeGen.Assembly.AddAttribute (current_container, sect);
481 else if (sect.Target == "module") {
482 CodeGen.Module.AddAttribute (current_container, sect);
486 $$ = new Attributes (sect);
488 | attribute_sections attribute_section
490 Attributes attrs = $1 as Attributes;
491 AttributeSection sect = (AttributeSection) $2;
493 if (sect.Target == "assembly") {
494 CodeGen.Assembly.AddAttribute (current_container, sect);
496 else if (sect.Target == "module") {
497 CodeGen.Module.AddAttribute (current_container, sect);
501 attrs = new Attributes (sect);
503 attrs.AddAttributeSection (sect);
511 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
513 string target = null;
516 target = (string) $2;
518 $$ = new AttributeSection (target, (ArrayList) $3);
520 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
522 $$ = new AttributeSection (null, (ArrayList) $2);
526 attribute_target_specifier
527 : attribute_target COLON
536 CheckAttributeTarget ((string) $1);
539 | EVENT { $$ = "event"; }
540 | RETURN { $$ = "return"; }
546 ArrayList attrs = new ArrayList (4);
552 | attribute_list COMMA attribute
554 ArrayList attrs = (ArrayList) $1;
566 opt_attribute_arguments
569 // Attributes need a string, not an expression: generic types will fail here.
571 $$ = new Attribute (((Expression) $1).ToString (), (ArrayList) $3, (Location) $2);
576 : type_name { /* reserved attribute name or identifier: 17.4 */ }
579 opt_attribute_arguments
580 : /* empty */ { $$ = null; }
581 | OPEN_PARENS attribute_arguments CLOSE_PARENS
589 : opt_positional_argument_list
594 ArrayList args = new ArrayList (4);
600 | positional_argument_list COMMA named_argument_list
602 ArrayList args = new ArrayList (4);
608 | named_argument_list
610 ArrayList args = new ArrayList (4);
619 opt_positional_argument_list
620 : /* empty */ { $$ = null; }
621 | positional_argument_list
624 positional_argument_list
627 ArrayList args = new ArrayList (4);
628 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
632 | positional_argument_list COMMA expression
634 ArrayList args = (ArrayList) $1;
635 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
644 ArrayList args = new ArrayList (4);
649 | named_argument_list COMMA named_argument
651 ArrayList args = (ArrayList) $1;
659 : IDENTIFIER ASSIGN expression
661 $$ = new DictionaryEntry (
663 new Argument ((Expression) $3, Argument.AType.Expression));
669 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
672 opt_class_member_declarations
674 | class_member_declarations
677 class_member_declarations
678 : class_member_declaration
679 | class_member_declarations
680 class_member_declaration
683 class_member_declaration
684 : constant_declaration // done
685 | field_declaration // done
686 | method_declaration // done
687 | property_declaration // done
688 | event_declaration // done
689 | indexer_declaration // done
690 | operator_declaration // done
691 | constructor_declaration // done
692 | destructor_declaration // done
702 MemberName full_struct_name = MakeName ((MemberName) $4);
704 new_struct = new Struct (current_namespace, current_container, full_struct_name,
705 (int) $2, (Attributes) $1, lexer.Location);
706 current_container = new_struct;
707 RootContext.Tree.RecordDecl (full_struct_name.GetName (true), new_struct);
708 lexer.ConstraintsParsing = true;
711 opt_type_parameter_constraints_clauses
713 lexer.ConstraintsParsing = false;
718 Struct new_struct = (Struct) current_container;
720 CheckDef (new_struct.SetParameterInfo ((ArrayList) $7), new_struct.Name, new_struct.Location);
723 new_struct.Bases = (ArrayList) $6;
725 current_container = current_container.Parent;
726 CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
729 | opt_attributes opt_modifiers STRUCT error {
730 CheckIdentifierToken (yyToken);
735 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
738 opt_struct_member_declarations
740 | struct_member_declarations
743 struct_member_declarations
744 : struct_member_declaration
745 | struct_member_declarations struct_member_declaration
748 struct_member_declaration
749 : constant_declaration
752 | property_declaration
754 | indexer_declaration
755 | operator_declaration
756 | constructor_declaration
760 * This is only included so we can flag error 575:
761 * destructors only allowed on class types
763 | destructor_declaration
774 foreach (VariableDeclaration constant in (ArrayList) $5){
775 Location l = constant.Location;
777 Const c = new Const (
778 (Expression) $4, (string) constant.identifier,
779 (Expression) constant.expression_or_array_initializer, (int) $2,
782 CheckDef (current_container.AddConstant (c), c.Name, l);
788 : constant_declarator
790 ArrayList constants = new ArrayList (4);
794 | constant_declarators COMMA constant_declarator
796 ArrayList constants = (ArrayList) $1;
803 : IDENTIFIER ASSIGN constant_expression
805 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
816 Expression type = (Expression) $3;
819 foreach (VariableDeclaration var in (ArrayList) $4){
820 Location l = var.Location;
822 Field field = new Field (type, mod, var.identifier,
823 var.expression_or_array_initializer,
826 CheckDef (current_container.AddField (field), field.Name, l);
834 Report.Error (670, lexer.Location, "void type is not allowed for fields");
839 : variable_declarator
841 ArrayList decl = new ArrayList (4);
845 | variable_declarators COMMA variable_declarator
847 ArrayList decls = (ArrayList) $1;
854 : IDENTIFIER ASSIGN variable_initializer
856 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
860 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
873 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
875 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
881 iterator_container = (IIteratorContainer) $1;
885 Method method = (Method) $1;
886 Block b = (Block) $3;
887 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
890 if ((method.ModFlags & extern_abstract) == 0){
892 501, lexer.Location, current_container.MakeName (method.Name) +
893 "must declare a body because it is not marked abstract or extern");
896 if ((method.ModFlags & Modifiers.EXTERN) != 0){
898 179, lexer.Location, current_container.MakeName (method.Name) +
899 " is declared extern, but has a body");
903 method.Block = (Block) $3;
904 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
906 current_local_parameters = null;
907 iterator_container = null;
921 1585, lexer.Location, "Member modifier `" +
922 Modifiers.Name (i) + "' must precede member type and name");
933 type namespace_or_type_name
934 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
936 lexer.ConstraintsParsing = true;
938 opt_type_parameter_constraints_clauses
940 lexer.ConstraintsParsing = false;
942 TypeName type_name = (TypeName) $4;
943 MemberName name = type_name.GetMemberName ();
945 if ($9 != null && name.TypeParameters == null)
946 Report.Error (80, lexer.Location,
947 "Contraints are not allowed on non-generic declarations");
951 GenericMethod generic = null;
952 if (name.TypeParameters != null) {
953 generic = new GenericMethod (current_namespace, current_container,
954 name, (Attributes) $1, lexer.Location);
956 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
958 method = new Method (generic, (Expression) $3, (int) $2, false, name,
959 (Parameters) $6, (Attributes) $1, lexer.Location);
961 method = new Method (current_container, (Expression) $3, (int) $2,
962 false, name, (Parameters) $6, (Attributes) $1,
965 current_local_parameters = (Parameters) $6;
971 VOID namespace_or_type_name
972 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
974 lexer.ConstraintsParsing = true;
976 opt_type_parameter_constraints_clauses
978 lexer.ConstraintsParsing = false;
980 TypeName type_name = (TypeName) $4;
981 MemberName name = type_name.GetMemberName ();
983 if ($9 != null && name.TypeParameters == null)
984 Report.Error (80, lexer.Location,
985 "Contraints are not allowed on non-generic declarations");
988 GenericMethod generic = null;
989 if (name.TypeParameters != null) {
990 generic = new GenericMethod (current_namespace, current_container,
991 name, (Attributes) $1, lexer.Location);
994 CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
996 method = new Method (generic, TypeManager.system_void_expr, (int) $2,
997 false, name, (Parameters) $6, (Attributes) $1,
1000 method = new Method (current_container, TypeManager.system_void_expr,
1001 (int) $2, false, name, (Parameters) $6,
1002 (Attributes) $1, lexer.Location);
1004 current_local_parameters = (Parameters) $6;
1011 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1013 Report.Error (1585, lexer.Location,
1014 String.Format ("Modifier {0} should appear before type",
1015 Modifiers.Name ((int) $4)));
1016 TypeName type_name = (TypeName) $4;
1017 MemberName name = type_name.GetMemberName ();
1019 Method method = new Method (current_container, TypeManager.system_void_expr,
1020 0, false, name, (Parameters) $6, (Attributes) $1,
1023 current_local_parameters = (Parameters) $6;
1030 | SEMICOLON { $$ = null; }
1033 opt_formal_parameter_list
1034 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1035 | formal_parameter_list
1038 formal_parameter_list
1041 ArrayList pars_list = (ArrayList) $1;
1043 Parameter [] pars = new Parameter [pars_list.Count];
1044 pars_list.CopyTo (pars);
1046 $$ = new Parameters (pars, null, lexer.Location);
1048 | fixed_parameters COMMA parameter_array
1050 ArrayList pars_list = (ArrayList) $1;
1052 Parameter [] pars = new Parameter [pars_list.Count];
1053 pars_list.CopyTo (pars);
1055 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
1059 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1066 ArrayList pars = new ArrayList (4);
1071 | fixed_parameters COMMA fixed_parameter
1073 ArrayList pars = (ArrayList) $1;
1082 opt_parameter_modifier
1086 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1089 opt_parameter_modifier
1092 CheckIdentifierToken (yyToken);
1097 opt_parameter_modifier
1098 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1099 | parameter_modifier
1103 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1104 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1108 : opt_attributes PARAMS type IDENTIFIER
1110 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1111 note ("type must be a single-dimension array type");
1113 | opt_attributes PARAMS type error {
1114 CheckIdentifierToken (yyToken);
1119 property_declaration
1122 type namespace_or_type_name
1125 implicit_value_parameter_type = (Expression) $3;
1127 lexer.PropertyParsing = true;
1129 $$ = lexer.Location;
1131 iterator_container = SimpleIteratorContainer.GetSimple ();
1133 accessor_declarations
1135 lexer.PropertyParsing = false;
1140 Pair pair = (Pair) $7;
1141 Accessor get_block = (Accessor) pair.First;
1142 Accessor set_block = (Accessor) pair.Second;
1144 TypeName type_name = (TypeName) $4;
1145 if (type_name.TypeArguments != null)
1146 syntax_error (lexer.Location, "a property can't have type arguments");
1148 MemberName name = type_name.GetMemberName ();
1150 Location loc = (Location) $6;
1151 prop = new Property (current_container, (Expression) $3, (int) $2, false,
1152 name, (Attributes) $1, get_block, set_block, loc);
1153 if (SimpleIteratorContainer.Simple.Yields)
1156 CheckDef (current_container.AddProperty (prop), prop.Name, loc);
1157 implicit_value_parameter_type = null;
1158 iterator_container = null;
1162 accessor_declarations
1163 : get_accessor_declaration opt_set_accessor_declaration
1165 $$ = new Pair ($1, $2);
1167 | set_accessor_declaration opt_get_accessor_declaration
1169 $$ = new Pair ($2, $1);
1173 opt_get_accessor_declaration
1174 : /* empty */ { $$ = null; }
1175 | get_accessor_declaration
1178 opt_set_accessor_declaration
1179 : /* empty */ { $$ = null; }
1180 | set_accessor_declaration
1183 get_accessor_declaration
1184 : opt_attributes GET
1186 // If this is not the case, then current_local_parameters has already
1187 // been set in indexer_declaration
1188 if (parsing_indexer == false)
1189 current_local_parameters = null;
1191 current_local_parameters = indexer_parameters;
1192 lexer.PropertyParsing = false;
1196 $$ = new Accessor ((Block) $4, (Attributes) $1);
1197 current_local_parameters = null;
1198 lexer.PropertyParsing = true;
1202 set_accessor_declaration
1203 : opt_attributes SET
1206 Parameter implicit_value_parameter = new Parameter (
1207 implicit_value_parameter_type, "value",
1208 Parameter.Modifier.NONE, null);
1210 if (parsing_indexer == false) {
1211 args = new Parameter [1];
1212 args [0] = implicit_value_parameter;
1213 current_local_parameters = new Parameters (args, null, lexer.Location);
1215 Parameter [] fpars = indexer_parameters.FixedParameters;
1218 int count = fpars.Length;
1220 args = new Parameter [count + 1];
1221 fpars.CopyTo (args, 0);
1222 args [count] = implicit_value_parameter;
1225 current_local_parameters = new Parameters (
1226 args, indexer_parameters.ArrayParameter, lexer.Location);
1229 lexer.PropertyParsing = false;
1233 $$ = new Accessor ((Block) $4, (Attributes) $1);
1234 current_local_parameters = null;
1235 lexer.PropertyParsing = true;
1241 | SEMICOLON { $$ = null; }
1244 interface_declaration
1247 INTERFACE member_name
1249 Interface new_interface;
1250 MemberName full_interface_name = MakeName ((MemberName) $4);
1252 new_interface = new Interface (current_namespace, current_container, full_interface_name,
1253 (int) $2, (Attributes) $1, lexer.Location);
1254 if (current_interface != null) {
1255 Location l = lexer.Location;
1256 Report.Error (-2, l, "Internal compiler error: interface inside interface");
1258 current_interface = new_interface;
1259 current_container = new_interface;
1260 RootContext.Tree.RecordDecl (
1261 full_interface_name.GetName (true), new_interface);
1262 lexer.ConstraintsParsing = true;
1265 opt_type_parameter_constraints_clauses
1267 lexer.ConstraintsParsing = false;
1269 interface_body opt_semicolon
1271 Interface new_interface = (Interface) current_interface;
1273 CheckDef (new_interface.SetParameterInfo ((ArrayList) $7), new_interface.Name, new_interface.Location);
1275 new_interface.Bases = (ArrayList) $6;
1277 current_interface = null;
1278 current_container = current_container.Parent;
1279 CheckDef (current_container.AddInterface (new_interface),
1280 new_interface.Name, new_interface.Location);
1282 | opt_attributes opt_modifiers INTERFACE error {
1283 CheckIdentifierToken (yyToken);
1289 opt_interface_member_declarations
1293 opt_interface_member_declarations
1295 | interface_member_declarations
1298 interface_member_declarations
1299 : interface_member_declaration
1300 | interface_member_declarations interface_member_declaration
1303 interface_member_declaration
1304 : interface_method_declaration
1306 Method m = (Method) $1;
1308 CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
1310 | interface_property_declaration
1312 Property p = (Property) $1;
1314 CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
1316 | interface_event_declaration
1319 Event e = (Event) $1;
1320 CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
1323 | interface_indexer_declaration
1325 Indexer i = (Indexer) $1;
1327 current_interface.AddIndexer (i);
1335 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1340 interface_method_declaration
1341 : opt_attributes opt_new type IDENTIFIER
1342 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1345 $$ = new Method (current_container, (Expression) $3, (int) $2, true,
1346 new MemberName ((string) $4), (Parameters) $6,
1347 (Attributes) $1, lexer.Location);
1349 | opt_attributes opt_new VOID IDENTIFIER
1350 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1353 $$ = new Method (current_container, TypeManager.system_void_expr, (int) $2,
1354 true, new MemberName ((string) $4), (Parameters) $6,
1355 (Attributes) $1, lexer.Location);
1359 interface_property_declaration
1364 { lexer.PropertyParsing = true; }
1366 { lexer.PropertyParsing = false; }
1369 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1371 $$ = new Property (current_container, (Expression) $3, (int) $2, true,
1372 new MemberName ((string) $4), (Attributes) $1,
1373 pinfo.Get, pinfo.Set, lexer.Location);
1378 CheckIdentifierToken (yyToken);
1384 : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null); }
1385 | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1); }
1386 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1387 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3); }
1388 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1389 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1); }
1392 interface_event_declaration
1393 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1395 $$ = new Event ((Expression) $4, (int) $2, true,
1396 new MemberName ((string) $5), null,
1397 (Attributes) $1, null, null, lexer.Location);
1399 | opt_attributes opt_new EVENT type error {
1400 CheckIdentifierToken (yyToken);
1403 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1404 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1407 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1408 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1413 interface_indexer_declaration
1414 : opt_attributes opt_new type THIS
1415 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1417 { lexer.PropertyParsing = true; }
1419 { lexer.PropertyParsing = false; }
1422 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1424 $$ = new Indexer (current_container, (Expression) $3, (int) $2, true,
1425 MemberName.Null, (Parameters) $6, (Attributes) $1,
1426 info.Get, info.Set, lexer.Location);
1430 operator_declaration
1431 : opt_attributes opt_modifiers operator_declarator
1433 iterator_container = SimpleIteratorContainer.GetSimple ();
1437 OperatorDeclaration decl = (OperatorDeclaration) $3;
1439 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1440 decl.arg2type, decl.arg2name, (Block) $5, (Attributes) $1, decl.location);
1442 if (SimpleIteratorContainer.Simple.Yields)
1445 // Note again, checking is done in semantic analysis
1446 current_container.AddOperator (op);
1448 current_local_parameters = null;
1449 iterator_container = null;
1455 | SEMICOLON { $$ = null; }
1458 : type OPERATOR overloadable_operator
1459 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1461 Operator.OpType op = (Operator.OpType) $3;
1462 CheckUnaryOperator (op);
1464 if (op == Operator.OpType.Addition)
1465 op = Operator.OpType.UnaryPlus;
1467 if (op == Operator.OpType.Subtraction)
1468 op = Operator.OpType.UnaryNegation;
1470 Parameter [] pars = new Parameter [1];
1472 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1474 current_local_parameters = new Parameters (pars, null, lexer.Location);
1476 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1477 null, null, lexer.Location);
1479 | type OPERATOR overloadable_operator
1481 type IDENTIFIER COMMA
1485 CheckBinaryOperator ((Operator.OpType) $3);
1487 Parameter [] pars = new Parameter [2];
1489 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1490 pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1492 current_local_parameters = new Parameters (pars, null, lexer.Location);
1494 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1495 (Expression) $5, (string) $6,
1496 (Expression) $8, (string) $9, lexer.Location);
1498 | conversion_operator_declarator
1501 overloadable_operator
1503 : BANG { $$ = Operator.OpType.LogicalNot; }
1504 | TILDE { $$ = Operator.OpType.OnesComplement; }
1505 | OP_INC { $$ = Operator.OpType.Increment; }
1506 | OP_DEC { $$ = Operator.OpType.Decrement; }
1507 | TRUE { $$ = Operator.OpType.True; }
1508 | FALSE { $$ = Operator.OpType.False; }
1509 // Unary and binary:
1510 | PLUS { $$ = Operator.OpType.Addition; }
1511 | MINUS { $$ = Operator.OpType.Subtraction; }
1513 | STAR { $$ = Operator.OpType.Multiply; }
1514 | DIV { $$ = Operator.OpType.Division; }
1515 | PERCENT { $$ = Operator.OpType.Modulus; }
1516 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1517 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1518 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1519 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1520 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1521 | OP_EQ { $$ = Operator.OpType.Equality; }
1522 | OP_NE { $$ = Operator.OpType.Inequality; }
1523 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1524 | OP_LT { $$ = Operator.OpType.LessThan; }
1525 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1526 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1529 conversion_operator_declarator
1530 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1532 Parameter [] pars = new Parameter [1];
1534 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1536 current_local_parameters = new Parameters (pars, null, lexer.Location);
1538 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1539 null, null, lexer.Location);
1541 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1543 Parameter [] pars = new Parameter [1];
1545 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1547 current_local_parameters = new Parameters (pars, null, lexer.Location);
1549 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1550 null, null, lexer.Location);
1554 syntax_error (lexer.Location, "'operator' expected");
1558 syntax_error (lexer.Location, "'operator' expected");
1562 constructor_declaration
1565 constructor_declarator
1568 Constructor c = (Constructor) $3;
1569 c.Block = (Block) $4;
1570 c.OptAttributes = (Attributes) $1;
1571 c.ModFlags = (int) $2;
1573 if (c.Name == current_container.Basename){
1574 if ((c.ModFlags & Modifiers.STATIC) != 0){
1575 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1577 515, c.Location, String.Format (
1578 "`{0}.{1}': static constructor can not have access modifiers",
1579 c.Name, current_container.Name));
1582 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1584 if (c.Initializer != null){
1587 "Static constructors can not have an explicit this or base " +
1588 "constructor invocations");
1591 if (!c.Parameters.Empty){
1593 132, c.Location, "Static constructors should not have parameters");
1596 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1599 // We let another layer check the validity of the constructor.
1600 Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1603 CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
1605 current_local_parameters = null;
1609 constructor_declarator
1611 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1613 oob_stack.Push (lexer.Location);
1615 current_local_parameters = (Parameters) $3;
1617 opt_constructor_initializer
1619 Location l = (Location) oob_stack.Pop ();
1620 $$ = new Constructor (current_container, (string) $1, 0, (Parameters) $3,
1621 (ConstructorInitializer) $6, l);
1627 | SEMICOLON { $$ = null; }
1630 opt_constructor_initializer
1631 : /* empty */ { $$ = null; }
1632 | constructor_initializer
1635 constructor_initializer
1636 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1638 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1640 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1642 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1645 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1651 : /* EMPTY */ { $$ = 0; }
1652 | UNSAFE { $$ = Modifiers.UNSAFE; }
1653 | EXTERN { $$ = Modifiers.EXTERN; }
1656 destructor_declaration
1657 : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1659 if ((string) $4 != current_container.Basename){
1660 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1661 } else if (!(current_container is Class)){
1662 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1664 Location l = lexer.Location;
1667 if (!RootContext.StdLib && current_container.Name == "System.Object")
1668 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1670 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1672 if ((m & Modifiers.UNSAFE) != 0){
1673 if (!RootContext.Unsafe){
1674 Report.Error (227, l,
1675 "Unsafe code requires the --unsafe command " +
1676 "line option to be specified");
1680 Method d = new Destructor (
1681 current_container, TypeManager.system_void_expr, m, "Finalize",
1682 new Parameters (null, null, l), (Attributes) $1, l);
1684 d.Block = (Block) $7;
1685 CheckDef (current_container.AddMethod (d), d.Name, d.Location);
1693 EVENT type variable_declarators SEMICOLON
1695 foreach (VariableDeclaration var in (ArrayList) $5) {
1697 MemberName name = new MemberName (var.identifier);
1699 Event e = new Event ((Expression) $4, (int) $2, false, name,
1700 var.expression_or_array_initializer,
1701 (Attributes) $1, null, null, lexer.Location);
1703 CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1709 EVENT type namespace_or_type_name
1712 implicit_value_parameter_type = (Expression) $4;
1713 lexer.EventParsing = true;
1714 oob_stack.Push (lexer.Location);
1716 event_accessor_declarations
1718 lexer.EventParsing = false;
1722 Location loc = (Location) oob_stack.Pop ();
1725 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1728 Pair pair = (Pair) $8;
1729 Accessor add_accessor = null;
1730 Accessor rem_accessor = null;
1732 if (pair.First != null)
1733 add_accessor = (Accessor) pair.First;
1734 if (pair.Second != null)
1735 rem_accessor = (Accessor) pair.Second;
1737 TypeName type_name = (TypeName) $5;
1738 if (type_name.TypeArguments != null)
1739 syntax_error (lexer.Location, "an event can't have type arguments");
1741 MemberName name = type_name.GetMemberName ();
1743 Event e = new Event ((Expression) $4, (int) $2, false, name, null,
1744 (Attributes) $1, add_accessor, rem_accessor, loc);
1746 CheckDef (current_container.AddEvent (e), e.Name, loc);
1747 implicit_value_parameter_type = null;
1752 event_accessor_declarations
1753 : add_accessor_declaration remove_accessor_declaration
1755 $$ = new Pair ($1, $2);
1757 | remove_accessor_declaration add_accessor_declaration
1759 $$ = new Pair ($2, $1);
1761 | add_accessor_declaration { $$ = null; }
1762 | remove_accessor_declaration { $$ = null; }
1765 add_accessor_declaration
1766 : opt_attributes ADD
1768 Parameter [] args = new Parameter [1];
1769 Parameter implicit_value_parameter = new Parameter (
1770 implicit_value_parameter_type, "value",
1771 Parameter.Modifier.NONE, null);
1773 args [0] = implicit_value_parameter;
1775 current_local_parameters = new Parameters (args, null, lexer.Location);
1776 lexer.EventParsing = false;
1780 $$ = new Accessor ((Block) $4, (Attributes) $1);
1781 lexer.EventParsing = true;
1783 | opt_attributes ADD error {
1784 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1789 remove_accessor_declaration
1790 : opt_attributes REMOVE
1792 Parameter [] args = new Parameter [1];
1793 Parameter implicit_value_parameter = new Parameter (
1794 implicit_value_parameter_type, "value",
1795 Parameter.Modifier.NONE, null);
1797 args [0] = implicit_value_parameter;
1799 current_local_parameters = new Parameters (args, null, lexer.Location);
1800 lexer.EventParsing = false;
1804 $$ = new Accessor ((Block) $4, (Attributes) $1);
1805 lexer.EventParsing = true;
1807 | opt_attributes REMOVE error {
1808 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1814 : opt_attributes opt_modifiers indexer_declarator
1817 IndexerDeclaration decl = (IndexerDeclaration) $3;
1819 implicit_value_parameter_type = decl.type;
1821 lexer.PropertyParsing = true;
1822 parsing_indexer = true;
1824 indexer_parameters = decl.param_list;
1825 oob_stack.Push (lexer.Location);
1827 accessor_declarations
1829 lexer.PropertyParsing = false;
1830 parsing_indexer = false;
1834 // The signature is computed from the signature of the indexer. Look
1835 // at section 3.6 on the spec
1836 Location loc = (Location) oob_stack.Pop ();
1838 IndexerDeclaration decl = (IndexerDeclaration) $3;
1839 Pair pair = (Pair) $6;
1840 Accessor get_block = (Accessor) pair.First;
1841 Accessor set_block = (Accessor) pair.Second;
1844 if (decl.interface_type != null)
1845 name = new MemberName (decl.interface_type, "");
1847 name = MemberName.Null;
1849 indexer = new Indexer (current_container, decl.type, (int) $2, false,
1850 name, decl.param_list, (Attributes) $1,
1851 get_block, set_block, loc);
1853 // Note that there is no equivalent of CheckDef for this case
1854 // We shall handle this in semantic analysis
1856 current_container.AddIndexer (indexer);
1858 current_local_parameters = null;
1859 implicit_value_parameter_type = null;
1860 indexer_parameters = null;
1865 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1867 Parameters pars = (Parameters) $4;
1869 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1870 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1873 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1875 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1877 Parameters pars = (Parameters) $6;
1879 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1880 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1882 TypeName name = (TypeName) $2;
1883 if (name.TypeArguments != null)
1884 syntax_error (lexer.Location, "an indexer can't have type arguments");
1886 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
1898 Location enum_location = lexer.Location;
1900 MemberName full_name = MakeName (new MemberName ((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 string name = full_name.GetName (false);
1914 CheckDef (current_container.AddEnum (e), name, enum_location);
1915 RootContext.Tree.RecordDecl (name, e);
1921 : /* empty */ { $$ = TypeManager.system_int32_expr; }
1922 | COLON type { $$ = $2; }
1926 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1932 opt_enum_member_declarations
1933 : /* empty */ { $$ = new ArrayList (4); }
1934 | enum_member_declarations opt_comma { $$ = $1; }
1937 enum_member_declarations
1938 : enum_member_declaration
1940 ArrayList l = new ArrayList (4);
1945 | enum_member_declarations COMMA enum_member_declaration
1947 ArrayList l = (ArrayList) $1;
1955 enum_member_declaration
1956 : opt_attributes IDENTIFIER
1958 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
1960 | opt_attributes IDENTIFIER
1962 $$ = lexer.Location;
1966 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
1970 delegate_declaration
1973 DELEGATE type member_name
1974 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1976 Location l = lexer.Location;
1977 Delegate del = new Delegate (
1978 current_namespace, current_container, (Expression) $4, (int) $2,
1979 MakeName ((MemberName) $5), (Parameters) $7, (Attributes) $1, l);
1981 CheckDef (current_container.AddDelegate (del), del.Name, l);
1983 current_delegate = del;
1985 lexer.ConstraintsParsing = true;
1987 opt_type_parameter_constraints_clauses
1989 lexer.ConstraintsParsing = false;
1993 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
1995 current_delegate = null;
1999 DELEGATE VOID member_name
2000 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2002 Location l = lexer.Location;
2003 Delegate del = new Delegate (
2004 current_namespace, current_container,
2005 TypeManager.system_void_expr, (int) $2, MakeName ((MemberName) $5),
2006 (Parameters) $7, (Attributes) $1, l);
2008 CheckDef (current_container.AddDelegate (del), del.Name, l);
2010 current_delegate = del;
2012 lexer.ConstraintsParsing = true;
2014 opt_type_parameter_constraints_clauses
2016 lexer.ConstraintsParsing = false;
2020 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
2022 current_delegate = null;
2027 : namespace_or_type_name {
2028 $$ = ((TypeName) $1).GetTypeExpression (lexer.Location);
2032 namespace_or_type_name
2033 : IDENTIFIER opt_type_argument_list {
2034 $$ = new TypeName ((string) $1, (TypeArguments) $2);
2036 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2037 $$ = new TypeName ((TypeName) $1, (string) $3, (TypeArguments) $4);
2042 : IDENTIFIER opt_type_parameter_list {
2043 $$ = new MemberName (null, (string) $1, (ArrayList) $2);
2047 opt_type_argument_list
2048 : /* empty */ { $$ = null; }
2049 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2057 TypeArguments type_args = new TypeArguments (lexer.Location);
2058 type_args.Add ((Expression) $1);
2061 | type_arguments COMMA type {
2062 TypeArguments type_args = (TypeArguments) $1;
2063 type_args.Add ((Expression) $3);
2069 * Before you think of adding a return_type, notice that we have been
2070 * using two rules in the places where it matters (one rule using type
2071 * and another identical one that uses VOID as the return type). This
2072 * gets rid of a shift/reduce couple
2075 : type_name { /* class_type */
2087 // Note that here only unmanaged types are allowed but we
2088 // can't perform checks during this phase - we do it during
2089 // semantic analysis.
2091 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2095 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2101 | non_expression_type rank_specifier
2103 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2105 | non_expression_type STAR
2107 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2109 | expression rank_specifiers
2111 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2115 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2119 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2120 // through this different path
2122 | multiplicative_expression STAR
2124 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2131 ArrayList types = new ArrayList (4);
2136 | type_list COMMA type
2138 ArrayList types = (ArrayList) $1;
2146 * replaces all the productions for isolating the various
2147 * simple types, but we need this to reuse it easily in local_variable_type
2150 : OBJECT { $$ = TypeManager.system_object_expr; }
2151 | STRING { $$ = TypeManager.system_string_expr; }
2152 | BOOL { $$ = TypeManager.system_boolean_expr; }
2153 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2154 | FLOAT { $$ = TypeManager.system_single_expr; }
2155 | DOUBLE { $$ = TypeManager.system_double_expr; }
2160 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2161 | BYTE { $$ = TypeManager.system_byte_expr; }
2162 | SHORT { $$ = TypeManager.system_int16_expr; }
2163 | USHORT { $$ = TypeManager.system_uint16_expr; }
2164 | INT { $$ = TypeManager.system_int32_expr; }
2165 | UINT { $$ = TypeManager.system_uint32_expr; }
2166 | LONG { $$ = TypeManager.system_int64_expr; }
2167 | ULONG { $$ = TypeManager.system_uint64_expr; }
2168 | CHAR { $$ = TypeManager.system_char_expr; }
2169 | VOID { $$ = TypeManager.system_void_expr; }
2177 : type rank_specifiers
2179 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2184 // Expressions, section 7.5
2196 | parenthesized_expression
2197 | default_value_expression
2199 | invocation_expression
2203 | post_increment_expression
2204 | post_decrement_expression
2208 | checked_expression
2209 | unchecked_expression
2210 | pointer_member_access
2211 | anonymous_method_expression
2218 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2219 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2220 | NULL { $$ = NullLiteral.Null; }
2224 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2225 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2226 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2231 object v = lexer.Value;
2237 $$ = IntLiteral.Zero;
2239 $$ = IntLiteral.One;
2241 $$ = new IntLiteral (i);
2242 } else if (v is uint)
2243 $$ = new UIntLiteral ((UInt32) v);
2245 $$ = new LongLiteral ((Int64) v);
2246 else if (v is ulong)
2247 $$ = new ULongLiteral ((UInt64) v);
2249 Console.WriteLine ("OOPS. Unexpected result from scanner");
2254 : TRUE { $$ = new BoolLiteral (true); }
2255 | FALSE { $$ = new BoolLiteral (false); }
2258 parenthesized_expression_0
2259 : OPEN_PARENS expression CLOSE_PARENS
2262 lexer.Deambiguate_CloseParens ();
2263 // After this, the next token returned is one of
2264 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2265 // or CLOSE_PARENS_MINUS.
2269 parenthesized_expression
2270 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2274 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2276 // If a parenthesized expression is followed by a minus, we need to wrap
2277 // the expression inside a ParenthesizedExpression for the CS0075 check
2278 // in Binary.DoResolve().
2279 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2284 : primary_expression DOT IDENTIFIER
2286 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2288 | predefined_type DOT IDENTIFIER
2290 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2298 invocation_expression
2299 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2302 Location l = lexer.Location;
2303 Report.Error (1, l, "Parse error");
2305 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2307 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2309 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2311 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2313 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2318 : /* empty */ { $$ = null; }
2325 ArrayList list = new ArrayList (4);
2329 | argument_list COMMA argument
2331 ArrayList list = (ArrayList) $1;
2335 | argument_list error {
2336 CheckToken (1026, yyToken, ", or ) expected");
2343 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2345 | REF variable_reference
2347 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2349 | OUT variable_reference
2351 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2356 : expression { note ("section 5.4"); $$ = $1; }
2360 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2362 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2364 | primary_expression rank_specifiers
2366 // So the super-trick is that primary_expression
2367 // can only be either a SimpleName or a MemberAccess.
2368 // The MemberAccess case arises when you have a fully qualified type-name like :
2370 // SimpleName is when you have
2373 Expression expr = (Expression) $1;
2374 if (expr is ComposedCast){
2375 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2376 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2377 Error_ExpectingTypeName (lexer.Location, expr);
2378 $$ = TypeManager.system_object_expr;
2381 // So we extract the string corresponding to the SimpleName
2384 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2392 ArrayList list = new ArrayList (4);
2396 | expression_list COMMA expression
2398 ArrayList list = (ArrayList) $1;
2407 $$ = new This (current_block, lexer.Location);
2412 : BASE DOT IDENTIFIER
2414 $$ = new BaseAccess ((string) $3, lexer.Location);
2416 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2418 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2421 Report.Error (175, "Use of keyword `base' is not valid in this context");
2426 post_increment_expression
2427 : primary_expression OP_INC
2429 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2430 (Expression) $1, lexer.Location);
2434 post_decrement_expression
2435 : primary_expression OP_DEC
2437 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2438 (Expression) $1, lexer.Location);
2443 : object_or_delegate_creation_expression
2444 | array_creation_expression
2447 object_or_delegate_creation_expression
2448 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2450 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2454 array_creation_expression
2455 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2457 opt_array_initializer
2459 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2461 | NEW type rank_specifiers array_initializer
2463 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2467 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2483 : rank_specifier opt_rank_specifier
2485 $$ = (string) $2 + (string) $1;
2490 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2492 $$ = "[" + (string) $2 + "]";
2512 | dim_separators COMMA
2514 $$ = (string) $1 + ",";
2518 opt_array_initializer
2530 : OPEN_BRACE CLOSE_BRACE
2532 ArrayList list = new ArrayList (4);
2535 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2537 $$ = (ArrayList) $2;
2541 variable_initializer_list
2542 : variable_initializer
2544 ArrayList list = new ArrayList (4);
2548 | variable_initializer_list COMMA variable_initializer
2550 ArrayList list = (ArrayList) $1;
2557 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2559 $$ = new TypeOfVoid (lexer.Location);
2561 | TYPEOF OPEN_PARENS type CLOSE_PARENS
2563 $$ = new TypeOf ((Expression) $3, lexer.Location);
2568 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2569 $$ = new SizeOf ((Expression) $3, lexer.Location);
2574 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2576 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2580 unchecked_expression
2581 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2583 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2587 pointer_member_access
2588 : primary_expression OP_PTR IDENTIFIER
2592 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2593 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2597 anonymous_method_expression
2598 : DELEGATE opt_anonymous_method_signature {
2599 oob_stack.Push (current_local_parameters);
2600 current_local_parameters = (Parameters)$2;
2601 create_toplevel_block = true;
2603 create_toplevel_block = false;
2604 if (!RootContext.V2){
2605 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2608 $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
2609 current_local_parameters = (Parameters) oob_stack.Pop ();
2613 opt_anonymous_method_signature
2614 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
2615 | anonymous_method_signature
2618 anonymous_method_signature
2619 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2622 $$ = Parameters.EmptyReadOnlyParameters;
2624 ArrayList par_list = (ArrayList) $2;
2625 Parameter [] pars = new Parameter [par_list.Count];
2626 par_list.CopyTo (pars);
2627 $$ = new Parameters (pars, null, lexer.Location);
2632 opt_anonymous_method_parameter_list
2633 : /* empty */ { $$ = null; }
2634 | anonymous_method_parameter_list { $$ = $1; }
2637 anonymous_method_parameter_list
2638 : anonymous_method_parameter
2640 ArrayList a = new ArrayList (4);
2644 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2646 ArrayList a = (ArrayList) $1;
2652 anonymous_method_parameter
2653 : opt_parameter_modifier type IDENTIFIER {
2654 $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
2658 default_value_expression
2659 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
2661 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
2666 : primary_expression
2667 | BANG prefixed_unary_expression
2669 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2671 | TILDE prefixed_unary_expression
2673 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2679 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2681 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2683 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2685 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2691 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2693 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2698 // The idea to split this out is from Rhys' grammar
2699 // to solve the problem with casts.
2701 prefixed_unary_expression
2703 | PLUS prefixed_unary_expression
2705 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2707 | MINUS prefixed_unary_expression
2709 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2711 | OP_INC prefixed_unary_expression
2713 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2714 (Expression) $2, lexer.Location);
2716 | OP_DEC prefixed_unary_expression
2718 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2719 (Expression) $2, lexer.Location);
2721 | STAR prefixed_unary_expression
2723 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2725 | BITWISE_AND prefixed_unary_expression
2727 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2731 pre_increment_expression
2732 : OP_INC prefixed_unary_expression
2734 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2735 (Expression) $2, lexer.Location);
2739 pre_decrement_expression
2740 : OP_DEC prefixed_unary_expression
2742 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2743 (Expression) $2, lexer.Location);
2747 multiplicative_expression
2748 : prefixed_unary_expression
2749 | multiplicative_expression STAR prefixed_unary_expression
2751 $$ = new Binary (Binary.Operator.Multiply,
2752 (Expression) $1, (Expression) $3, lexer.Location);
2754 | multiplicative_expression DIV prefixed_unary_expression
2756 $$ = new Binary (Binary.Operator.Division,
2757 (Expression) $1, (Expression) $3, lexer.Location);
2759 | multiplicative_expression PERCENT prefixed_unary_expression
2761 $$ = new Binary (Binary.Operator.Modulus,
2762 (Expression) $1, (Expression) $3, lexer.Location);
2767 : multiplicative_expression
2768 | additive_expression PLUS multiplicative_expression
2770 $$ = new Binary (Binary.Operator.Addition,
2771 (Expression) $1, (Expression) $3, lexer.Location);
2773 | additive_expression MINUS multiplicative_expression
2775 $$ = new Binary (Binary.Operator.Subtraction,
2776 (Expression) $1, (Expression) $3, lexer.Location);
2781 : additive_expression
2782 | shift_expression OP_SHIFT_LEFT additive_expression
2784 $$ = new Binary (Binary.Operator.LeftShift,
2785 (Expression) $1, (Expression) $3, lexer.Location);
2787 | shift_expression OP_SHIFT_RIGHT additive_expression
2789 $$ = new Binary (Binary.Operator.RightShift,
2790 (Expression) $1, (Expression) $3, lexer.Location);
2794 relational_expression
2796 | relational_expression OP_LT shift_expression
2798 $$ = new Binary (Binary.Operator.LessThan,
2799 (Expression) $1, (Expression) $3, lexer.Location);
2801 | relational_expression OP_GT shift_expression
2803 $$ = new Binary (Binary.Operator.GreaterThan,
2804 (Expression) $1, (Expression) $3, lexer.Location);
2806 | relational_expression OP_LE shift_expression
2808 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2809 (Expression) $1, (Expression) $3, lexer.Location);
2811 | relational_expression OP_GE shift_expression
2813 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2814 (Expression) $1, (Expression) $3, lexer.Location);
2816 | relational_expression IS type
2818 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2820 | relational_expression AS type
2822 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2827 : relational_expression
2828 | equality_expression OP_EQ relational_expression
2830 $$ = new Binary (Binary.Operator.Equality,
2831 (Expression) $1, (Expression) $3, lexer.Location);
2833 | equality_expression OP_NE relational_expression
2835 $$ = new Binary (Binary.Operator.Inequality,
2836 (Expression) $1, (Expression) $3, lexer.Location);
2841 : equality_expression
2842 | and_expression BITWISE_AND equality_expression
2844 $$ = new Binary (Binary.Operator.BitwiseAnd,
2845 (Expression) $1, (Expression) $3, lexer.Location);
2849 exclusive_or_expression
2851 | exclusive_or_expression CARRET and_expression
2853 $$ = new Binary (Binary.Operator.ExclusiveOr,
2854 (Expression) $1, (Expression) $3, lexer.Location);
2858 inclusive_or_expression
2859 : exclusive_or_expression
2860 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2862 $$ = new Binary (Binary.Operator.BitwiseOr,
2863 (Expression) $1, (Expression) $3, lexer.Location);
2867 conditional_and_expression
2868 : inclusive_or_expression
2869 | conditional_and_expression OP_AND inclusive_or_expression
2871 $$ = new Binary (Binary.Operator.LogicalAnd,
2872 (Expression) $1, (Expression) $3, lexer.Location);
2876 conditional_or_expression
2877 : conditional_and_expression
2878 | conditional_or_expression OP_OR conditional_and_expression
2880 $$ = new Binary (Binary.Operator.LogicalOr,
2881 (Expression) $1, (Expression) $3, lexer.Location);
2885 conditional_expression
2886 : conditional_or_expression
2887 | conditional_or_expression INTERR expression COLON expression
2889 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2893 assignment_expression
2894 : prefixed_unary_expression ASSIGN expression
2896 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2898 | prefixed_unary_expression OP_MULT_ASSIGN expression
2900 Location l = lexer.Location;
2902 $$ = new CompoundAssign (
2903 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
2905 | prefixed_unary_expression OP_DIV_ASSIGN expression
2907 Location l = lexer.Location;
2909 $$ = new CompoundAssign (
2910 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
2912 | prefixed_unary_expression OP_MOD_ASSIGN expression
2914 Location l = lexer.Location;
2916 $$ = new CompoundAssign (
2917 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
2919 | prefixed_unary_expression OP_ADD_ASSIGN expression
2921 Location l = lexer.Location;
2923 $$ = new CompoundAssign (
2924 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
2926 | prefixed_unary_expression OP_SUB_ASSIGN expression
2928 Location l = lexer.Location;
2930 $$ = new CompoundAssign (
2931 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
2933 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2935 Location l = lexer.Location;
2937 $$ = new CompoundAssign (
2938 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
2940 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2942 Location l = lexer.Location;
2944 $$ = new CompoundAssign (
2945 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
2947 | prefixed_unary_expression OP_AND_ASSIGN expression
2949 Location l = lexer.Location;
2951 $$ = new CompoundAssign (
2952 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
2954 | prefixed_unary_expression OP_OR_ASSIGN expression
2956 Location l = lexer.Location;
2958 $$ = new CompoundAssign (
2959 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
2961 | prefixed_unary_expression OP_XOR_ASSIGN expression
2963 Location l = lexer.Location;
2965 $$ = new CompoundAssign (
2966 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
2971 : conditional_expression
2972 | assignment_expression
2993 MemberName name = MakeName ((MemberName) $4);
2995 new_class = new Class (current_namespace, current_container, name, (int) $2,
2996 (Attributes) $1, lexer.Location);
2997 current_container = new_class;
2998 RootContext.Tree.RecordDecl (name.GetName (true), new_class);
3000 lexer.ConstraintsParsing = true;
3003 opt_type_parameter_constraints_clauses
3005 lexer.ConstraintsParsing = false;
3010 Class new_class = (Class) current_container;
3012 CheckDef (new_class.SetParameterInfo ((ArrayList) $7), new_class.Name, new_class.Location);
3014 if (new_class.Name == "System.Object") {
3015 Report.Error (537, new_class.Location, "The class System.Object cannot have a base class or implement an interface.");
3018 new_class.Bases = (ArrayList) $6;
3020 current_container = current_container.Parent;
3021 CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
3029 lexer.ConstraintsParsing = true;
3032 Report.Error (80, lexer.Location,
3033 "Contraints are not allowed on non-generic declarations");
3040 : /* empty */ { $$ = (int) 0; }
3046 | modifiers modifier
3051 if ((m1 & m2) != 0) {
3052 Location l = lexer.Location;
3053 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3055 $$ = (int) (m1 | m2);
3060 : NEW { $$ = Modifiers.NEW; }
3061 | PUBLIC { $$ = Modifiers.PUBLIC; }
3062 | PROTECTED { $$ = Modifiers.PROTECTED; }
3063 | INTERNAL { $$ = Modifiers.INTERNAL; }
3064 | PRIVATE { $$ = Modifiers.PRIVATE; }
3065 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3066 | SEALED { $$ = Modifiers.SEALED; }
3067 | STATIC { $$ = Modifiers.STATIC; }
3068 | READONLY { $$ = Modifiers.READONLY; }
3069 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3070 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3071 | EXTERN { $$ = Modifiers.EXTERN; }
3072 | VOLATILE { $$ = Modifiers.VOLATILE; }
3073 | UNSAFE { $$ = Modifiers.UNSAFE; }
3077 : /* empty */ { $$ = null; }
3078 | class_base { $$ = $1; }
3082 : COLON type_list { $$ = $2; }
3085 opt_type_parameter_list
3086 : /* empty */ { $$ = null; }
3087 | type_parameter_list { $$ = $1; }
3091 : OP_GENERICS_LT type_parameters OP_GENERICS_GT { $$ = $2; }
3097 // Do some profiling to find the optimal size, for now we
3098 // assume most people will be generic on one type (saves space
3100 ArrayList type_parameters = new ArrayList (1);
3101 type_parameters.Add ($1);
3102 $$ = type_parameters;
3104 | type_parameters COMMA type_parameter {
3105 ArrayList type_parameters = (ArrayList) $1;
3107 type_parameters.Add ($3);
3108 $$ = type_parameters;
3116 opt_type_parameter_constraints_clauses
3117 : /* empty */ { $$ = null; }
3118 | type_parameter_constraints_clauses
3122 type_parameter_constraints_clauses
3123 : type_parameter_constraints_clause
3124 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3125 ArrayList constraints = (ArrayList) $1;
3127 constraints.Add ($2);
3132 type_parameter_constraints_clause
3133 : WHERE type_parameter COLON type_parameter_constraints {
3134 ArrayList constraints = new ArrayList (1);
3135 constraints.Add (new Constraints ((string) $2, (ArrayList) $4, lexer.Location));
3140 type_parameter_constraints
3141 : type_parameter_constraint {
3142 ArrayList constraints = new ArrayList (1);
3143 constraints.Add ($1);
3146 | type_parameter_constraints COMMA type_parameter_constraint {
3147 ArrayList constraints = (ArrayList) $1;
3149 constraints.Add ($3);
3154 type_parameter_constraint
3156 | NEW OPEN_PARENS CLOSE_PARENS {
3157 $$ = SpecialConstraint.Constructor;
3160 $$ = SpecialConstraint.ReferenceType;
3163 $$ = SpecialConstraint.ValueType;
3172 // A block is "contained" on the following places:
3174 // property_declaration as part of the accessor body (get/set)
3175 // operator_declaration
3176 // constructor_declaration
3177 // destructor_declaration
3178 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3183 if (current_block == null || create_toplevel_block){
3184 current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
3186 current_block = new Block (current_block, current_local_parameters,
3187 lexer.Location, Location.Null);
3190 opt_statement_list CLOSE_BRACE
3192 while (current_block.Implicit)
3193 current_block = current_block.Parent;
3195 current_block.SetEndLocation (lexer.Location);
3196 current_block = current_block.Parent;
3207 | statement_list statement
3211 : declaration_statement
3213 if ($1 != null && (Block) $1 != current_block){
3214 current_block.AddStatement ((Statement) $1);
3215 current_block = (Block) $1;
3218 | embedded_statement
3220 current_block.AddStatement ((Statement) $1);
3228 | expression_statement
3229 | selection_statement
3230 | iteration_statement
3234 | unchecked_statement
3244 $$ = EmptyStatement.Value;
3251 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3253 if (!current_block.AddLabel ((string) $1, labeled)){
3254 Location l = lexer.Location;
3255 Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
3257 current_block.AddStatement (labeled);
3262 declaration_statement
3263 : local_variable_declaration SEMICOLON
3266 DictionaryEntry de = (DictionaryEntry) $1;
3268 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3272 | local_constant_declaration SEMICOLON
3275 DictionaryEntry de = (DictionaryEntry) $1;
3277 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3283 * The following is from Rhys' grammar:
3284 * > Types in local variable declarations must be recognized as
3285 * > expressions to prevent reduce/reduce errors in the grammar.
3286 * > The expressions are converted into types during semantic analysis.
3289 : primary_expression opt_rank_specifier
3291 // FIXME: Do something smart here regarding the composition of the type.
3293 // Ok, the above "primary_expression" is there to get rid of
3294 // both reduce/reduce and shift/reduces in the grammar, it should
3295 // really just be "type_name". If you use type_name, a reduce/reduce
3296 // creeps up. If you use namespace_or_type_name (which is all we need
3297 // really) two shift/reduces appear.
3300 // So the super-trick is that primary_expression
3301 // can only be either a SimpleName or a MemberAccess.
3302 // The MemberAccess case arises when you have a fully qualified type-name like :
3304 // SimpleName is when you have
3307 Expression expr = (Expression) $1;
3308 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3309 Error_ExpectingTypeName (lexer.Location, expr);
3313 // So we extract the string corresponding to the SimpleName
3317 if ((string) $2 == "")
3320 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3323 | builtin_types opt_rank_specifier
3325 if ((string) $2 == "")
3328 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3332 local_variable_pointer_type
3333 : primary_expression STAR
3335 Expression expr = (Expression) $1;
3336 Location l = lexer.Location;
3338 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3339 Error_ExpectingTypeName (l, expr);
3343 $$ = new ComposedCast ((Expression) $1, "*", l);
3345 | builtin_types STAR
3347 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3351 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3353 | local_variable_pointer_type STAR
3355 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3359 local_variable_declaration
3360 : local_variable_type variable_declarators
3363 $$ = new DictionaryEntry ($1, $2);
3367 | local_variable_pointer_type opt_rank_specifier variable_declarators
3372 if ((string) $2 == "")
3373 t = (Expression) $1;
3375 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3376 $$ = new DictionaryEntry (t, $3);
3382 local_constant_declaration
3383 : CONST local_variable_type constant_declarators
3386 $$ = new DictionaryEntry ($2, $3);
3392 expression_statement
3393 : statement_expression SEMICOLON
3400 // We have to do the wrapping here and not in the case above,
3401 // because statement_expression is used for example in for_statement
3403 statement_expression
3404 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3405 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3406 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3407 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3408 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3409 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3410 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3412 Report.Error (1002, lexer.Location, "Expecting `;'");
3417 object_creation_expression
3418 : object_or_delegate_creation_expression
3419 { note ("complain if this is a delegate maybe?"); }
3428 : if_statement_open if_statement_rest
3437 oob_stack.Push (lexer.Location);
3442 : boolean_expression CLOSE_PARENS
3445 Location l = (Location) oob_stack.Pop ();
3447 $$ = new If ((Expression) $1, (Statement) $3, l);
3449 if (RootContext.WarningLevel >= 3){
3450 if ($3 == EmptyStatement.Value)
3451 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3455 | boolean_expression CLOSE_PARENS
3456 embedded_statement ELSE embedded_statement
3458 Location l = (Location) oob_stack.Pop ();
3460 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3465 : SWITCH OPEN_PARENS
3467 oob_stack.Push (lexer.Location);
3468 switch_stack.Push (current_block);
3470 expression CLOSE_PARENS
3473 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3474 current_block = (Block) switch_stack.Pop ();
3490 Report.Error (1522, lexer.Location, "Empty switch block");
3498 ArrayList sections = new ArrayList (4);
3503 | switch_sections switch_section
3505 ArrayList sections = (ArrayList) $1;
3515 current_block = current_block.CreateSwitchBlock (lexer.Location);
3519 Block topmost = current_block;
3521 while (topmost.Implicit)
3522 topmost = topmost.Parent;
3523 $$ = new SwitchSection ((ArrayList) $1, topmost);
3530 ArrayList labels = new ArrayList (4);
3535 | switch_labels switch_label
3537 ArrayList labels = (ArrayList) ($1);
3545 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3546 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3549 1523, lexer.Location,
3550 "The keyword case or default must precede code in switch block");
3564 oob_stack.Push (lexer.Location);
3566 boolean_expression CLOSE_PARENS embedded_statement
3568 Location l = (Location) oob_stack.Pop ();
3569 $$ = new While ((Expression) $4, (Statement) $6, l);
3571 if (RootContext.WarningLevel >= 3){
3572 if ($6 == EmptyStatement.Value)
3573 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3579 : DO embedded_statement
3581 oob_stack.Push (lexer.Location);
3583 boolean_expression CLOSE_PARENS SEMICOLON
3585 Location l = (Location) oob_stack.Pop ();
3587 $$ = new Do ((Statement) $2, (Expression) $6, l);
3593 opt_for_initializer SEMICOLON
3595 Block assign_block = new Block (current_block);
3596 current_block = assign_block;
3598 if ($3 is DictionaryEntry){
3599 DictionaryEntry de = (DictionaryEntry) $3;
3601 Expression type = (Expression) de.Key;
3602 ArrayList var_declarators = (ArrayList) de.Value;
3604 foreach (VariableDeclaration decl in var_declarators){
3608 vi = current_block.AddVariable (
3609 type, decl.identifier, current_local_parameters, decl.Location);
3613 Location l = lexer.Location;
3615 if (decl.expression_or_array_initializer is Expression){
3616 expr = (Expression) decl.expression_or_array_initializer;
3617 } else if (decl.expression_or_array_initializer == null) {
3620 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3621 expr = new ArrayCreation (type, "", init, decl.Location);
3624 LocalVariableReference var;
3625 var = new LocalVariableReference (assign_block, decl.identifier, l);
3628 Assign a = new Assign (var, expr, decl.Location);
3630 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3636 oob_stack.Push (lexer.Location);
3638 opt_for_condition SEMICOLON
3639 opt_for_iterator CLOSE_PARENS
3642 Location l = (Location) oob_stack.Pop ();
3644 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3646 if (RootContext.WarningLevel >= 3){
3647 if ($10 == EmptyStatement.Value)
3648 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3651 current_block.AddStatement (f);
3652 while (current_block.Implicit)
3653 current_block = current_block.Parent;
3655 current_block = current_block.Parent;
3660 : /* empty */ { $$ = EmptyStatement.Value; }
3665 : local_variable_declaration
3666 | statement_expression_list
3670 : /* empty */ { $$ = null; }
3671 | boolean_expression
3675 : /* empty */ { $$ = EmptyStatement.Value; }
3680 : statement_expression_list
3683 statement_expression_list
3684 : statement_expression
3686 // CHANGE: was `null'
3687 Block b = new Block (current_block, Block.Flags.Implicit);
3689 b.AddStatement ((Statement) $1);
3692 | statement_expression_list COMMA statement_expression
3694 Block b = (Block) $1;
3696 b.AddStatement ((Statement) $3);
3702 : FOREACH OPEN_PARENS type IDENTIFIER IN
3704 oob_stack.Push (lexer.Location);
3706 expression CLOSE_PARENS
3708 oob_stack.Push (current_block);
3710 Block foreach_block = new Block (current_block, Block.Flags.Implicit);
3711 LocalVariableReference v = null;
3712 Location l = lexer.Location;
3715 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3719 // Get a writable reference to this read-only variable.
3720 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3722 current_block = foreach_block;
3725 oob_stack.Push (current_block);
3729 Block foreach_block = (Block) oob_stack.Pop ();
3730 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3731 Block prev_block = (Block) oob_stack.Pop ();
3732 Location l = (Location) oob_stack.Pop ();
3734 current_block = prev_block;
3737 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3738 foreach_block.AddStatement (f);
3747 | continue_statement
3757 $$ = new Break (lexer.Location);
3762 : CONTINUE SEMICOLON
3764 $$ = new Continue (lexer.Location);
3769 : GOTO IDENTIFIER SEMICOLON
3771 $$ = new Goto (current_block, (string) $2, lexer.Location);
3773 | GOTO CASE constant_expression SEMICOLON
3775 $$ = new GotoCase ((Expression) $3, lexer.Location);
3777 | GOTO DEFAULT SEMICOLON
3779 $$ = new GotoDefault (lexer.Location);
3784 : RETURN opt_expression SEMICOLON
3786 $$ = new Return ((Expression) $2, lexer.Location);
3791 : THROW opt_expression SEMICOLON
3793 $$ = new Throw ((Expression) $2, lexer.Location);
3798 : IDENTIFIER RETURN expression SEMICOLON
3800 string s = (string) $1;
3802 Report.Error (1003, lexer.Location, "; expected");
3805 if (!RootContext.V2){
3806 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3809 if (iterator_container == null){
3810 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3813 iterator_container.SetYields ();
3814 $$ = new Yield ((Expression) $3, lexer.Location);
3817 | IDENTIFIER BREAK 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 YieldBreak (lexer.Location);
3844 : TRY block catch_clauses
3847 ArrayList s = new ArrayList (4);
3849 foreach (Catch cc in (ArrayList) $3) {
3856 // Now s contains the list of specific catch clauses
3857 // and g contains the general one.
3859 $$ = new Try ((Block) $2, s, g, null, lexer.Location);
3861 | TRY block opt_catch_clauses FINALLY block
3864 ArrayList s = new ArrayList (4);
3865 ArrayList catch_list = (ArrayList) $3;
3867 if (catch_list != null){
3868 foreach (Catch cc in catch_list) {
3876 $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
3880 Report.Error (1524, lexer.Location, "Expected catch or finally");
3885 : /* empty */ { $$ = null; }
3892 ArrayList l = new ArrayList (4);
3897 | catch_clauses catch_clause
3899 ArrayList l = (ArrayList) $1;
3907 : /* empty */ { $$ = null; }
3912 : CATCH opt_catch_args
3914 Expression type = null;
3918 DictionaryEntry cc = (DictionaryEntry) $2;
3919 type = (Expression) cc.Key;
3920 id = (string) cc.Value;
3923 ArrayList one = new ArrayList (4);
3924 Location loc = lexer.Location;
3926 one.Add (new VariableDeclaration (id, null, loc));
3929 current_block = new Block (current_block);
3930 Block b = declare_local_variables (type, one, loc);
3935 Expression type = null;
3939 DictionaryEntry cc = (DictionaryEntry) $2;
3940 type = (Expression) cc.Key;
3941 id = (string) cc.Value;
3945 // FIXME: I can change this for an assignment.
3947 while (current_block != (Block) $1)
3948 current_block = current_block.Parent;
3953 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3958 : /* empty */ { $$ = null; }
3963 : OPEN_PARENS type opt_identifier CLOSE_PARENS
3965 $$ = new DictionaryEntry ($2, $3);
3972 $$ = new Checked ((Block) $2);
3979 $$ = new Unchecked ((Block) $2);
3986 if (!RootContext.Unsafe){
3987 Report.Error (227, lexer.Location,
3988 "Unsafe code can only be used if --unsafe is used");
3991 $$ = new Unsafe ((Block) $3);
3997 type fixed_pointer_declarators
4000 Block assign_block = new Block (current_block, Block.Flags.Implicit);
4001 ArrayList list = (ArrayList) $4;
4002 Expression type = (Expression) $3;
4003 Location l = lexer.Location;
4004 int top = list.Count;
4006 for (int i = 0; i < top; i++){
4007 Pair p = (Pair) list [i];
4010 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4017 current_block.AddStatement (assign_block);
4018 current_block = assign_block;
4019 oob_stack.Push (assign_block);
4024 Location l = (Location) oob_stack.Pop ();
4027 $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4031 fixed_pointer_declarators
4032 : fixed_pointer_declarator {
4033 ArrayList declarators = new ArrayList (4);
4034 declarators.Add ($1);
4037 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4039 ArrayList declarators = (ArrayList) $1;
4040 declarators.Add ($3);
4045 fixed_pointer_declarator
4046 : IDENTIFIER ASSIGN expression
4048 $$ = new Pair ($1, $3);
4053 : LOCK OPEN_PARENS expression CLOSE_PARENS
4059 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4064 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4066 Block assign_block = new Block (current_block);
4067 current_block = assign_block;
4069 oob_stack.Push (lexer.Location);
4071 if ($3 is DictionaryEntry){
4072 DictionaryEntry de = (DictionaryEntry) $3;
4073 Location l = lexer.Location;
4075 Expression type = (Expression) de.Key;
4076 ArrayList var_declarators = (ArrayList) de.Value;
4078 ArrayList vars = new ArrayList (4);
4080 foreach (VariableDeclaration decl in var_declarators){
4082 LocalInfo vi = current_block.AddVariable (
4083 type, decl.identifier,
4084 current_local_parameters, decl.Location);
4090 if (decl.expression_or_array_initializer is Expression){
4091 expr = (Expression) decl.expression_or_array_initializer;
4093 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4095 expr = new ArrayCreation (type, "", init, decl.Location);
4098 LocalVariableReference var;
4100 // Get a writable reference to this read-only variable.
4101 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4103 // This is so that it is not a warning on using variables
4106 vars.Add (new DictionaryEntry (var, expr));
4108 // Assign a = new Assign (var, expr, decl.Location);
4109 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4111 $3 = new DictionaryEntry (type, vars);
4116 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4117 current_block.AddStatement (u);
4118 while (current_block.Implicit)
4119 current_block = current_block.Parent;
4121 current_block = current_block.Parent;
4125 resource_acquisition
4126 : local_variable_declaration
4133 // A class used to pass around variable declarations and constants
4135 public class VariableDeclaration {
4136 public string identifier;
4137 public object expression_or_array_initializer;
4138 public Location Location;
4139 public Attributes OptAttributes;
4141 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4143 this.identifier = id;
4144 this.expression_or_array_initializer = eoai;
4146 this.OptAttributes = opt_attrs;
4149 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4155 /// Used to pass around interface property information
4157 public class InterfaceAccessorInfo {
4159 public readonly Accessor Get, Set;
4161 public InterfaceAccessorInfo (bool has_get, bool has_set,
4162 Attributes get_attrs, Attributes set_attrs)
4165 Get = new Accessor (null, get_attrs);
4167 Set = new Accessor (null, set_attrs);
4173 // A class used to hold info about an indexer declarator
4175 public class IndexerDeclaration {
4176 public Expression type;
4177 public TypeName interface_type;
4178 public Parameters param_list;
4180 public IndexerDeclaration (Expression type, TypeName interface_type,
4181 Parameters param_list)
4184 this.interface_type = interface_type;
4185 this.param_list = param_list;
4190 // We use this when we do not have an object in advance that is an IIteratorContainer
4192 public class SimpleIteratorContainer : IIteratorContainer {
4195 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4200 public static SimpleIteratorContainer GetSimple () {
4201 Simple.Yields = false;
4205 public void SetYields () { Yields = true; }
4209 // A class used to hold info about an operator declarator
4211 public class OperatorDeclaration {
4212 public Operator.OpType optype;
4213 public Expression ret_type, arg1type, arg2type;
4214 public string arg1name, arg2name;
4215 public Location location;
4217 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4218 Expression arg1type, string arg1name,
4219 Expression arg2type, string arg2name, Location location)
4222 this.ret_type = ret_type;
4223 this.arg1type = arg1type;
4224 this.arg1name = arg1name;
4225 this.arg2type = arg2type;
4226 this.arg2name = arg2name;
4227 this.location = location;
4232 void Error_ExpectingTypeName (Location l, Expression expr)
4234 if (expr is Invocation){
4235 Report.Error (1002, l, "; expected");
4237 Report.Error (-1, l, "Invalid Type definition");
4242 // Given the @class_name name, it creates a fully qualified name
4243 // based on the containing declaration space
4246 MakeName (MemberName class_name)
4248 string ns = current_namespace.FullName;
4250 if (current_container.Name == ""){
4252 return new MemberName (new TypeName (ns), class_name);
4256 TypeName type = current_container.MemberName.MakeTypeName (lexer.Location);
4257 return new MemberName (type, class_name);
4262 // Used to report back to the user the result of a declaration
4263 // in the current declaration space
4266 CheckDef (DeclSpace.AdditionResult result, string name, Location l)
4268 if (result == DeclSpace.AdditionResult.Success)
4272 case DeclSpace.AdditionResult.NameExists:
4273 Report.Error (102, l, "The container `" + current_container.Name +
4274 "' already contains a definition for `"+
4280 // This is handled only for static Constructors, because
4281 // in reality we handle these by the semantic analysis later
4283 case DeclSpace.AdditionResult.MethodExists:
4285 111, l, "Class `"+current_container.Name+
4286 "' already defines a member called '" +
4287 name + "' with the same parameter types (more than one default constructor)");
4290 case DeclSpace.AdditionResult.EnclosingClash:
4291 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
4294 case DeclSpace.AdditionResult.NotAConstructor:
4295 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
4298 case DeclSpace.AdditionResult.Error:
4299 // Error has already been reported.
4305 CheckDef (bool result, string name, Location l)
4309 CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
4312 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4314 Block implicit_block;
4315 ArrayList inits = null;
4318 // We use the `Used' property to check whether statements
4319 // have been added to the current block. If so, we need
4320 // to create another block to contain the new declaration
4321 // otherwise, as an optimization, we use the same block to
4322 // add the declaration.
4324 // FIXME: A further optimization is to check if the statements
4325 // that were added were added as part of the initialization
4326 // below. In which case, no other statements have been executed
4327 // and we might be able to reduce the number of blocks for
4328 // situations like this:
4330 // int j = 1; int k = j + 1;
4332 if (current_block.Used) {
4333 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4334 implicit_block.AddChildVariableNames (current_block);
4336 implicit_block = current_block;
4338 foreach (VariableDeclaration decl in variable_declarators){
4340 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4341 if (decl.expression_or_array_initializer != null){
4343 inits = new ArrayList (4);
4350 return implicit_block;
4352 foreach (VariableDeclaration decl in inits){
4356 if (decl.expression_or_array_initializer is Expression){
4357 expr = (Expression) decl.expression_or_array_initializer;
4360 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4362 expr = new ArrayCreation (type, "", init, decl.Location);
4365 LocalVariableReference var;
4366 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4368 assign = new Assign (var, expr, decl.Location);
4370 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4373 return implicit_block;
4376 Block declare_local_constants (Expression type, ArrayList declarators)
4378 Block implicit_block;
4380 if (current_block.Used)
4381 implicit_block = new Block (current_block, Block.Flags.Implicit);
4383 implicit_block = current_block;
4385 foreach (VariableDeclaration decl in declarators){
4386 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4387 current_local_parameters, decl.Location);
4390 return implicit_block;
4393 void CheckAttributeTarget (string a)
4397 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4401 Location l = lexer.Location;
4402 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4408 void CheckUnaryOperator (Operator.OpType op)
4412 case Operator.OpType.LogicalNot:
4413 case Operator.OpType.OnesComplement:
4414 case Operator.OpType.Increment:
4415 case Operator.OpType.Decrement:
4416 case Operator.OpType.True:
4417 case Operator.OpType.False:
4418 case Operator.OpType.Addition:
4419 case Operator.OpType.Subtraction:
4424 Location l = lexer.Location;
4425 Report.Error (1019, l, "Overloadable unary operator expected");
4431 void CheckBinaryOperator (Operator.OpType op)
4435 case Operator.OpType.Addition:
4436 case Operator.OpType.Subtraction:
4437 case Operator.OpType.Multiply:
4438 case Operator.OpType.Division:
4439 case Operator.OpType.Modulus:
4440 case Operator.OpType.BitwiseAnd:
4441 case Operator.OpType.BitwiseOr:
4442 case Operator.OpType.ExclusiveOr:
4443 case Operator.OpType.LeftShift:
4444 case Operator.OpType.RightShift:
4445 case Operator.OpType.Equality:
4446 case Operator.OpType.Inequality:
4447 case Operator.OpType.GreaterThan:
4448 case Operator.OpType.LessThan:
4449 case Operator.OpType.GreaterThanOrEqual:
4450 case Operator.OpType.LessThanOrEqual:
4454 Location l = lexer.Location;
4455 Report.Error (1020, l, "Overloadable binary operator expected");
4461 void syntax_error (Location l, string msg)
4463 Report.Error (1003, l, "Syntax error, " + msg);
4466 void output (string s)
4468 Console.WriteLine (s);
4471 void note (string s)
4473 // Used to put annotations
4478 public Tokenizer Lexer {
4484 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4486 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4487 this.name = file.Name;
4489 current_container = RootContext.Tree.Types;
4490 current_container.NamespaceEntry = current_namespace;
4491 oob_stack = new Stack ();
4492 switch_stack = new Stack ();
4494 lexer = new Tokenizer (reader, file, defines);
4497 public void parse ()
4500 if (yacc_verbose_flag)
4501 yyparse (lexer, new yydebug.yyDebugSimple ());
4504 Tokenizer tokenizer = lexer as Tokenizer;
4505 tokenizer.cleanup ();
4506 } catch (Exception e){
4507 // Please do not remove this, it is used during debugging
4510 Console.WriteLine (e);
4511 Report.Error (-25, lexer.Location, "Parsing error");
4512 if (Driver.parser_verbose)
4513 Console.WriteLine (e);
4517 void CheckToken (int error, int yyToken, string msg)
4519 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4520 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4523 Report.Error (error, lexer.Location, msg);
4526 void CheckIdentifierToken (int yyToken)
4528 CheckToken (1041, yyToken, "Identifier expected");