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 (current_container, (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);
1688 | opt_attributes opt_modifiers EVENT type member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
1689 string mn = (string) $5;
1691 if (mn.IndexOf ('.') != -1)
1692 Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
1694 Report.Error (71, lexer.Location, "Event declaration should use property syntax");
1701 EVENT type variable_declarators SEMICOLON
1703 foreach (VariableDeclaration var in (ArrayList) $5) {
1705 MemberName name = new MemberName (var.identifier);
1707 Event e = new Event (current_container, (Expression) $4, (int) $2,
1708 false, name, var.expression_or_array_initializer,
1709 (Attributes) $1, null, null, lexer.Location);
1711 CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1717 EVENT type namespace_or_type_name
1720 implicit_value_parameter_type = (Expression) $4;
1721 lexer.EventParsing = true;
1722 oob_stack.Push (lexer.Location);
1724 event_accessor_declarations
1726 lexer.EventParsing = false;
1730 Location loc = (Location) oob_stack.Pop ();
1733 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1736 Pair pair = (Pair) $8;
1737 Accessor add_accessor = null;
1738 Accessor rem_accessor = null;
1740 if (pair.First != null)
1741 add_accessor = (Accessor) pair.First;
1742 if (pair.Second != null)
1743 rem_accessor = (Accessor) pair.Second;
1745 TypeName type_name = (TypeName) $5;
1746 if (type_name.TypeArguments != null)
1747 syntax_error (lexer.Location, "an event can't have type arguments");
1749 MemberName name = type_name.GetMemberName ();
1751 Event e = new Event (current_container, (Expression) $4, (int) $2, false,
1752 name, null, (Attributes) $1, add_accessor, rem_accessor,
1755 CheckDef (current_container.AddEvent (e), e.Name, loc);
1756 implicit_value_parameter_type = null;
1761 event_accessor_declarations
1762 : add_accessor_declaration remove_accessor_declaration
1764 $$ = new Pair ($1, $2);
1766 | remove_accessor_declaration add_accessor_declaration
1768 $$ = new Pair ($2, $1);
1770 | add_accessor_declaration { $$ = null; }
1771 | remove_accessor_declaration { $$ = null; }
1774 add_accessor_declaration
1775 : opt_attributes ADD
1777 Parameter [] args = new Parameter [1];
1778 Parameter implicit_value_parameter = new Parameter (
1779 implicit_value_parameter_type, "value",
1780 Parameter.Modifier.NONE, null);
1782 args [0] = implicit_value_parameter;
1784 current_local_parameters = new Parameters (args, null, lexer.Location);
1785 lexer.EventParsing = false;
1789 $$ = new Accessor ((Block) $4, (Attributes) $1);
1790 lexer.EventParsing = true;
1792 | opt_attributes ADD error {
1793 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1798 remove_accessor_declaration
1799 : opt_attributes REMOVE
1801 Parameter [] args = new Parameter [1];
1802 Parameter implicit_value_parameter = new Parameter (
1803 implicit_value_parameter_type, "value",
1804 Parameter.Modifier.NONE, null);
1806 args [0] = implicit_value_parameter;
1808 current_local_parameters = new Parameters (args, null, lexer.Location);
1809 lexer.EventParsing = false;
1813 $$ = new Accessor ((Block) $4, (Attributes) $1);
1814 lexer.EventParsing = true;
1816 | opt_attributes REMOVE error {
1817 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1823 : opt_attributes opt_modifiers indexer_declarator
1826 IndexerDeclaration decl = (IndexerDeclaration) $3;
1828 implicit_value_parameter_type = decl.type;
1830 lexer.PropertyParsing = true;
1831 parsing_indexer = true;
1833 indexer_parameters = decl.param_list;
1834 oob_stack.Push (lexer.Location);
1836 accessor_declarations
1838 lexer.PropertyParsing = false;
1839 parsing_indexer = false;
1843 // The signature is computed from the signature of the indexer. Look
1844 // at section 3.6 on the spec
1845 Location loc = (Location) oob_stack.Pop ();
1847 IndexerDeclaration decl = (IndexerDeclaration) $3;
1848 Pair pair = (Pair) $6;
1849 Accessor get_block = (Accessor) pair.First;
1850 Accessor set_block = (Accessor) pair.Second;
1853 if (decl.interface_type != null)
1854 name = new MemberName (decl.interface_type, "");
1856 name = MemberName.Null;
1858 indexer = new Indexer (current_container, decl.type, (int) $2, false,
1859 name, decl.param_list, (Attributes) $1,
1860 get_block, set_block, loc);
1862 // Note that there is no equivalent of CheckDef for this case
1863 // We shall handle this in semantic analysis
1865 current_container.AddIndexer (indexer);
1867 current_local_parameters = null;
1868 implicit_value_parameter_type = null;
1869 indexer_parameters = null;
1874 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1876 Parameters pars = (Parameters) $4;
1878 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1879 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1882 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1884 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1886 Parameters pars = (Parameters) $6;
1888 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1889 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1891 TypeName name = (TypeName) $2;
1892 if (name.TypeArguments != null)
1893 syntax_error (lexer.Location, "an indexer can't have type arguments");
1895 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
1907 Location enum_location = lexer.Location;
1909 MemberName full_name = MakeName (new MemberName ((string) $4));
1910 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
1911 full_name, (Attributes) $1, enum_location);
1913 foreach (VariableDeclaration ev in (ArrayList) $6) {
1914 Location loc = (Location) ev.Location;
1916 CheckDef (e.AddEnumMember (ev.identifier,
1917 (Expression) ev.expression_or_array_initializer,
1918 loc, ev.OptAttributes),
1919 ev.identifier, loc);
1922 string name = full_name.GetName (false);
1923 CheckDef (current_container.AddEnum (e), name, enum_location);
1924 RootContext.Tree.RecordDecl (name, e);
1930 : /* empty */ { $$ = TypeManager.system_int32_expr; }
1931 | COLON type { $$ = $2; }
1935 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1941 opt_enum_member_declarations
1942 : /* empty */ { $$ = new ArrayList (4); }
1943 | enum_member_declarations opt_comma { $$ = $1; }
1946 enum_member_declarations
1947 : enum_member_declaration
1949 ArrayList l = new ArrayList (4);
1954 | enum_member_declarations COMMA enum_member_declaration
1956 ArrayList l = (ArrayList) $1;
1964 enum_member_declaration
1965 : opt_attributes IDENTIFIER
1967 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
1969 | opt_attributes IDENTIFIER
1971 $$ = lexer.Location;
1975 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
1979 delegate_declaration
1982 DELEGATE type member_name
1983 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1985 Location l = lexer.Location;
1986 Delegate del = new Delegate (
1987 current_namespace, current_container, (Expression) $4, (int) $2,
1988 MakeName ((MemberName) $5), (Parameters) $7, (Attributes) $1, l);
1990 CheckDef (current_container.AddDelegate (del), del.Name, l);
1992 current_delegate = del;
1994 lexer.ConstraintsParsing = true;
1996 opt_type_parameter_constraints_clauses
1998 lexer.ConstraintsParsing = false;
2002 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
2004 current_delegate = null;
2008 DELEGATE VOID member_name
2009 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2011 Location l = lexer.Location;
2012 Delegate del = new Delegate (
2013 current_namespace, current_container,
2014 TypeManager.system_void_expr, (int) $2, MakeName ((MemberName) $5),
2015 (Parameters) $7, (Attributes) $1, l);
2017 CheckDef (current_container.AddDelegate (del), del.Name, l);
2019 current_delegate = del;
2021 lexer.ConstraintsParsing = true;
2023 opt_type_parameter_constraints_clauses
2025 lexer.ConstraintsParsing = false;
2029 CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
2031 current_delegate = null;
2036 : namespace_or_type_name {
2037 $$ = ((TypeName) $1).GetTypeExpression (lexer.Location);
2041 namespace_or_type_name
2042 : IDENTIFIER opt_type_argument_list {
2043 $$ = new TypeName ((string) $1, (TypeArguments) $2);
2045 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2046 $$ = new TypeName ((TypeName) $1, (string) $3, (TypeArguments) $4);
2051 : IDENTIFIER opt_type_parameter_list {
2052 $$ = new MemberName (null, (string) $1, (ArrayList) $2);
2056 opt_type_argument_list
2057 : /* empty */ { $$ = null; }
2058 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2066 TypeArguments type_args = new TypeArguments (lexer.Location);
2067 type_args.Add ((Expression) $1);
2070 | type_arguments COMMA type {
2071 TypeArguments type_args = (TypeArguments) $1;
2072 type_args.Add ((Expression) $3);
2078 * Before you think of adding a return_type, notice that we have been
2079 * using two rules in the places where it matters (one rule using type
2080 * and another identical one that uses VOID as the return type). This
2081 * gets rid of a shift/reduce couple
2084 : type_name { /* class_type */
2096 // Note that here only unmanaged types are allowed but we
2097 // can't perform checks during this phase - we do it during
2098 // semantic analysis.
2100 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2104 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2110 | non_expression_type rank_specifier
2112 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2114 | non_expression_type STAR
2116 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2118 | expression rank_specifiers
2120 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2124 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2128 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2129 // through this different path
2131 | multiplicative_expression STAR
2133 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2140 ArrayList types = new ArrayList (4);
2145 | type_list COMMA type
2147 ArrayList types = (ArrayList) $1;
2155 * replaces all the productions for isolating the various
2156 * simple types, but we need this to reuse it easily in local_variable_type
2159 : OBJECT { $$ = TypeManager.system_object_expr; }
2160 | STRING { $$ = TypeManager.system_string_expr; }
2161 | BOOL { $$ = TypeManager.system_boolean_expr; }
2162 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2163 | FLOAT { $$ = TypeManager.system_single_expr; }
2164 | DOUBLE { $$ = TypeManager.system_double_expr; }
2169 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2170 | BYTE { $$ = TypeManager.system_byte_expr; }
2171 | SHORT { $$ = TypeManager.system_int16_expr; }
2172 | USHORT { $$ = TypeManager.system_uint16_expr; }
2173 | INT { $$ = TypeManager.system_int32_expr; }
2174 | UINT { $$ = TypeManager.system_uint32_expr; }
2175 | LONG { $$ = TypeManager.system_int64_expr; }
2176 | ULONG { $$ = TypeManager.system_uint64_expr; }
2177 | CHAR { $$ = TypeManager.system_char_expr; }
2178 | VOID { $$ = TypeManager.system_void_expr; }
2186 : type rank_specifiers
2188 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2193 // Expressions, section 7.5
2205 | parenthesized_expression
2206 | default_value_expression
2208 | invocation_expression
2212 | post_increment_expression
2213 | post_decrement_expression
2217 | checked_expression
2218 | unchecked_expression
2219 | pointer_member_access
2220 | anonymous_method_expression
2227 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2228 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2229 | NULL { $$ = NullLiteral.Null; }
2233 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2234 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2235 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2240 object v = lexer.Value;
2246 $$ = IntLiteral.Zero;
2248 $$ = IntLiteral.One;
2250 $$ = new IntLiteral (i);
2251 } else if (v is uint)
2252 $$ = new UIntLiteral ((UInt32) v);
2254 $$ = new LongLiteral ((Int64) v);
2255 else if (v is ulong)
2256 $$ = new ULongLiteral ((UInt64) v);
2258 Console.WriteLine ("OOPS. Unexpected result from scanner");
2263 : TRUE { $$ = new BoolLiteral (true); }
2264 | FALSE { $$ = new BoolLiteral (false); }
2267 parenthesized_expression_0
2268 : OPEN_PARENS expression CLOSE_PARENS
2271 lexer.Deambiguate_CloseParens ();
2272 // After this, the next token returned is one of
2273 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2274 // or CLOSE_PARENS_MINUS.
2278 parenthesized_expression
2279 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2283 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2285 // If a parenthesized expression is followed by a minus, we need to wrap
2286 // the expression inside a ParenthesizedExpression for the CS0075 check
2287 // in Binary.DoResolve().
2288 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2293 : primary_expression DOT IDENTIFIER
2295 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2297 | predefined_type DOT IDENTIFIER
2299 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2307 invocation_expression
2308 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2311 Location l = lexer.Location;
2312 Report.Error (1, l, "Parse error");
2314 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2316 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2318 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2320 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2322 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2327 : /* empty */ { $$ = null; }
2334 ArrayList list = new ArrayList (4);
2338 | argument_list COMMA argument
2340 ArrayList list = (ArrayList) $1;
2344 | argument_list error {
2345 CheckToken (1026, yyToken, ", or ) expected");
2352 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2354 | REF variable_reference
2356 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2358 | OUT variable_reference
2360 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2365 : expression { note ("section 5.4"); $$ = $1; }
2369 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2371 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2373 | primary_expression rank_specifiers
2375 // So the super-trick is that primary_expression
2376 // can only be either a SimpleName or a MemberAccess.
2377 // The MemberAccess case arises when you have a fully qualified type-name like :
2379 // SimpleName is when you have
2382 Expression expr = (Expression) $1;
2383 if (expr is ComposedCast){
2384 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2385 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2386 Error_ExpectingTypeName (lexer.Location, expr);
2387 $$ = TypeManager.system_object_expr;
2390 // So we extract the string corresponding to the SimpleName
2393 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2401 ArrayList list = new ArrayList (4);
2405 | expression_list COMMA expression
2407 ArrayList list = (ArrayList) $1;
2416 $$ = new This (current_block, lexer.Location);
2421 : BASE DOT IDENTIFIER
2423 $$ = new BaseAccess ((string) $3, lexer.Location);
2425 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2427 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2430 Report.Error (175, "Use of keyword `base' is not valid in this context");
2435 post_increment_expression
2436 : primary_expression OP_INC
2438 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2439 (Expression) $1, lexer.Location);
2443 post_decrement_expression
2444 : primary_expression OP_DEC
2446 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2447 (Expression) $1, lexer.Location);
2452 : object_or_delegate_creation_expression
2453 | array_creation_expression
2456 object_or_delegate_creation_expression
2457 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2459 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2463 array_creation_expression
2464 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2466 opt_array_initializer
2468 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2470 | NEW type rank_specifiers array_initializer
2472 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2476 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2492 : rank_specifier opt_rank_specifier
2494 $$ = (string) $2 + (string) $1;
2499 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2501 $$ = "[" + (string) $2 + "]";
2521 | dim_separators COMMA
2523 $$ = (string) $1 + ",";
2527 opt_array_initializer
2539 : OPEN_BRACE CLOSE_BRACE
2541 ArrayList list = new ArrayList (4);
2544 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2546 $$ = (ArrayList) $2;
2550 variable_initializer_list
2551 : variable_initializer
2553 ArrayList list = new ArrayList (4);
2557 | variable_initializer_list COMMA variable_initializer
2559 ArrayList list = (ArrayList) $1;
2566 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2568 $$ = new TypeOfVoid (lexer.Location);
2570 | TYPEOF OPEN_PARENS type CLOSE_PARENS
2572 $$ = new TypeOf ((Expression) $3, lexer.Location);
2577 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2578 $$ = new SizeOf ((Expression) $3, lexer.Location);
2583 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2585 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2589 unchecked_expression
2590 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2592 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2596 pointer_member_access
2597 : primary_expression OP_PTR IDENTIFIER
2601 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2602 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2606 anonymous_method_expression
2607 : DELEGATE opt_anonymous_method_signature {
2608 oob_stack.Push (current_local_parameters);
2609 current_local_parameters = (Parameters)$2;
2610 create_toplevel_block = true;
2613 Report.Error (-213, lexer.Location, "Anonymous methods are not supported in this branch");
2616 create_toplevel_block = false;
2617 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2618 if (!RootContext.V2){
2619 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2622 $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
2623 current_local_parameters = (Parameters) oob_stack.Pop ();
2628 opt_anonymous_method_signature
2629 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
2630 | anonymous_method_signature
2633 anonymous_method_signature
2634 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2637 $$ = Parameters.EmptyReadOnlyParameters;
2639 ArrayList par_list = (ArrayList) $2;
2640 Parameter [] pars = new Parameter [par_list.Count];
2641 par_list.CopyTo (pars);
2642 $$ = new Parameters (pars, null, lexer.Location);
2647 opt_anonymous_method_parameter_list
2648 : /* empty */ { $$ = null; }
2649 | anonymous_method_parameter_list { $$ = $1; }
2652 anonymous_method_parameter_list
2653 : anonymous_method_parameter
2655 ArrayList a = new ArrayList (4);
2659 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2661 ArrayList a = (ArrayList) $1;
2667 anonymous_method_parameter
2668 : opt_parameter_modifier type IDENTIFIER {
2669 $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
2673 default_value_expression
2674 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
2676 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
2681 : primary_expression
2682 | BANG prefixed_unary_expression
2684 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2686 | TILDE prefixed_unary_expression
2688 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2694 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2696 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2698 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2700 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2706 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2708 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2713 // The idea to split this out is from Rhys' grammar
2714 // to solve the problem with casts.
2716 prefixed_unary_expression
2718 | PLUS prefixed_unary_expression
2720 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2722 | MINUS prefixed_unary_expression
2724 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2726 | OP_INC prefixed_unary_expression
2728 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2729 (Expression) $2, lexer.Location);
2731 | OP_DEC prefixed_unary_expression
2733 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2734 (Expression) $2, lexer.Location);
2736 | STAR prefixed_unary_expression
2738 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2740 | BITWISE_AND prefixed_unary_expression
2742 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2746 pre_increment_expression
2747 : OP_INC prefixed_unary_expression
2749 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2750 (Expression) $2, lexer.Location);
2754 pre_decrement_expression
2755 : OP_DEC prefixed_unary_expression
2757 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2758 (Expression) $2, lexer.Location);
2762 multiplicative_expression
2763 : prefixed_unary_expression
2764 | multiplicative_expression STAR prefixed_unary_expression
2766 $$ = new Binary (Binary.Operator.Multiply,
2767 (Expression) $1, (Expression) $3, lexer.Location);
2769 | multiplicative_expression DIV prefixed_unary_expression
2771 $$ = new Binary (Binary.Operator.Division,
2772 (Expression) $1, (Expression) $3, lexer.Location);
2774 | multiplicative_expression PERCENT prefixed_unary_expression
2776 $$ = new Binary (Binary.Operator.Modulus,
2777 (Expression) $1, (Expression) $3, lexer.Location);
2782 : multiplicative_expression
2783 | additive_expression PLUS multiplicative_expression
2785 $$ = new Binary (Binary.Operator.Addition,
2786 (Expression) $1, (Expression) $3, lexer.Location);
2788 | additive_expression MINUS multiplicative_expression
2790 $$ = new Binary (Binary.Operator.Subtraction,
2791 (Expression) $1, (Expression) $3, lexer.Location);
2796 : additive_expression
2797 | shift_expression OP_SHIFT_LEFT additive_expression
2799 $$ = new Binary (Binary.Operator.LeftShift,
2800 (Expression) $1, (Expression) $3, lexer.Location);
2802 | shift_expression OP_SHIFT_RIGHT additive_expression
2804 $$ = new Binary (Binary.Operator.RightShift,
2805 (Expression) $1, (Expression) $3, lexer.Location);
2809 relational_expression
2811 | relational_expression OP_LT shift_expression
2813 $$ = new Binary (Binary.Operator.LessThan,
2814 (Expression) $1, (Expression) $3, lexer.Location);
2816 | relational_expression OP_GT shift_expression
2818 $$ = new Binary (Binary.Operator.GreaterThan,
2819 (Expression) $1, (Expression) $3, lexer.Location);
2821 | relational_expression OP_LE shift_expression
2823 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2824 (Expression) $1, (Expression) $3, lexer.Location);
2826 | relational_expression OP_GE shift_expression
2828 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2829 (Expression) $1, (Expression) $3, lexer.Location);
2831 | relational_expression IS type
2833 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2835 | relational_expression AS type
2837 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2842 : relational_expression
2843 | equality_expression OP_EQ relational_expression
2845 $$ = new Binary (Binary.Operator.Equality,
2846 (Expression) $1, (Expression) $3, lexer.Location);
2848 | equality_expression OP_NE relational_expression
2850 $$ = new Binary (Binary.Operator.Inequality,
2851 (Expression) $1, (Expression) $3, lexer.Location);
2856 : equality_expression
2857 | and_expression BITWISE_AND equality_expression
2859 $$ = new Binary (Binary.Operator.BitwiseAnd,
2860 (Expression) $1, (Expression) $3, lexer.Location);
2864 exclusive_or_expression
2866 | exclusive_or_expression CARRET and_expression
2868 $$ = new Binary (Binary.Operator.ExclusiveOr,
2869 (Expression) $1, (Expression) $3, lexer.Location);
2873 inclusive_or_expression
2874 : exclusive_or_expression
2875 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2877 $$ = new Binary (Binary.Operator.BitwiseOr,
2878 (Expression) $1, (Expression) $3, lexer.Location);
2882 conditional_and_expression
2883 : inclusive_or_expression
2884 | conditional_and_expression OP_AND inclusive_or_expression
2886 $$ = new Binary (Binary.Operator.LogicalAnd,
2887 (Expression) $1, (Expression) $3, lexer.Location);
2891 conditional_or_expression
2892 : conditional_and_expression
2893 | conditional_or_expression OP_OR conditional_and_expression
2895 $$ = new Binary (Binary.Operator.LogicalOr,
2896 (Expression) $1, (Expression) $3, lexer.Location);
2900 conditional_expression
2901 : conditional_or_expression
2902 | conditional_or_expression INTERR expression COLON expression
2904 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2908 assignment_expression
2909 : prefixed_unary_expression ASSIGN expression
2911 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2913 | prefixed_unary_expression OP_MULT_ASSIGN expression
2915 Location l = lexer.Location;
2917 $$ = new CompoundAssign (
2918 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
2920 | prefixed_unary_expression OP_DIV_ASSIGN expression
2922 Location l = lexer.Location;
2924 $$ = new CompoundAssign (
2925 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
2927 | prefixed_unary_expression OP_MOD_ASSIGN expression
2929 Location l = lexer.Location;
2931 $$ = new CompoundAssign (
2932 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
2934 | prefixed_unary_expression OP_ADD_ASSIGN expression
2936 Location l = lexer.Location;
2938 $$ = new CompoundAssign (
2939 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
2941 | prefixed_unary_expression OP_SUB_ASSIGN expression
2943 Location l = lexer.Location;
2945 $$ = new CompoundAssign (
2946 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
2948 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2950 Location l = lexer.Location;
2952 $$ = new CompoundAssign (
2953 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
2955 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2957 Location l = lexer.Location;
2959 $$ = new CompoundAssign (
2960 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
2962 | prefixed_unary_expression OP_AND_ASSIGN expression
2964 Location l = lexer.Location;
2966 $$ = new CompoundAssign (
2967 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
2969 | prefixed_unary_expression OP_OR_ASSIGN expression
2971 Location l = lexer.Location;
2973 $$ = new CompoundAssign (
2974 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
2976 | prefixed_unary_expression OP_XOR_ASSIGN expression
2978 Location l = lexer.Location;
2980 $$ = new CompoundAssign (
2981 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
2986 : conditional_expression
2987 | assignment_expression
3008 MemberName name = MakeName ((MemberName) $4);
3010 new_class = new Class (current_namespace, current_container, name, (int) $2,
3011 (Attributes) $1, lexer.Location);
3012 current_container = new_class;
3013 RootContext.Tree.RecordDecl (name.GetName (true), new_class);
3015 lexer.ConstraintsParsing = true;
3018 opt_type_parameter_constraints_clauses
3020 lexer.ConstraintsParsing = false;
3025 Class new_class = (Class) current_container;
3027 CheckDef (new_class.SetParameterInfo ((ArrayList) $7), new_class.Name, new_class.Location);
3029 if (new_class.Name == "System.Object") {
3030 Report.Error (537, new_class.Location, "The class System.Object cannot have a base class or implement an interface.");
3033 new_class.Bases = (ArrayList) $6;
3035 current_container = current_container.Parent;
3036 CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
3044 lexer.ConstraintsParsing = true;
3047 Report.Error (80, lexer.Location,
3048 "Contraints are not allowed on non-generic declarations");
3055 : /* empty */ { $$ = (int) 0; }
3061 | modifiers modifier
3066 if ((m1 & m2) != 0) {
3067 Location l = lexer.Location;
3068 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3070 $$ = (int) (m1 | m2);
3075 : NEW { $$ = Modifiers.NEW; }
3076 | PUBLIC { $$ = Modifiers.PUBLIC; }
3077 | PROTECTED { $$ = Modifiers.PROTECTED; }
3078 | INTERNAL { $$ = Modifiers.INTERNAL; }
3079 | PRIVATE { $$ = Modifiers.PRIVATE; }
3080 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3081 | SEALED { $$ = Modifiers.SEALED; }
3082 | STATIC { $$ = Modifiers.STATIC; }
3083 | READONLY { $$ = Modifiers.READONLY; }
3084 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3085 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3086 | EXTERN { $$ = Modifiers.EXTERN; }
3087 | VOLATILE { $$ = Modifiers.VOLATILE; }
3088 | UNSAFE { $$ = Modifiers.UNSAFE; }
3092 : /* empty */ { $$ = null; }
3093 | class_base { $$ = $1; }
3097 : COLON type_list { $$ = $2; }
3100 opt_type_parameter_list
3101 : /* empty */ { $$ = null; }
3102 | type_parameter_list { $$ = $1; }
3106 : OP_GENERICS_LT type_parameters OP_GENERICS_GT { $$ = $2; }
3112 // Do some profiling to find the optimal size, for now we
3113 // assume most people will be generic on one type (saves space
3115 ArrayList type_parameters = new ArrayList (1);
3116 type_parameters.Add ($1);
3117 $$ = type_parameters;
3119 | type_parameters COMMA type_parameter {
3120 ArrayList type_parameters = (ArrayList) $1;
3122 type_parameters.Add ($3);
3123 $$ = type_parameters;
3131 opt_type_parameter_constraints_clauses
3132 : /* empty */ { $$ = null; }
3133 | type_parameter_constraints_clauses
3137 type_parameter_constraints_clauses
3138 : type_parameter_constraints_clause {
3139 ArrayList constraints = new ArrayList (1);
3140 constraints.Add ($1);
3143 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3144 ArrayList constraints = (ArrayList) $1;
3146 constraints.Add ($2);
3151 type_parameter_constraints_clause
3152 : WHERE type_parameter COLON type_parameter_constraints {
3153 $$ = new Constraints ((string) $2, (ArrayList) $4, lexer.Location);
3157 type_parameter_constraints
3158 : type_parameter_constraint {
3159 ArrayList constraints = new ArrayList (1);
3160 constraints.Add ($1);
3163 | type_parameter_constraints COMMA type_parameter_constraint {
3164 ArrayList constraints = (ArrayList) $1;
3166 constraints.Add ($3);
3171 type_parameter_constraint
3173 | NEW OPEN_PARENS CLOSE_PARENS {
3174 $$ = SpecialConstraint.Constructor;
3177 $$ = SpecialConstraint.ReferenceType;
3180 $$ = SpecialConstraint.ValueType;
3189 // A block is "contained" on the following places:
3191 // property_declaration as part of the accessor body (get/set)
3192 // operator_declaration
3193 // constructor_declaration
3194 // destructor_declaration
3195 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3200 if (current_block == null || create_toplevel_block){
3201 current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
3203 current_block = new Block (current_block, current_local_parameters,
3204 lexer.Location, Location.Null);
3207 opt_statement_list CLOSE_BRACE
3209 while (current_block.Implicit)
3210 current_block = current_block.Parent;
3212 current_block.SetEndLocation (lexer.Location);
3213 current_block = current_block.Parent;
3224 | statement_list statement
3228 : declaration_statement
3230 if ($1 != null && (Block) $1 != current_block){
3231 current_block.AddStatement ((Statement) $1);
3232 current_block = (Block) $1;
3235 | valid_declaration_statement
3237 current_block.AddStatement ((Statement) $1);
3242 valid_declaration_statement
3245 | expression_statement
3246 | selection_statement
3247 | iteration_statement
3251 | unchecked_statement
3259 : valid_declaration_statement
3260 | declaration_statement
3262 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
3267 Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
3275 $$ = EmptyStatement.Value;
3282 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3284 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3285 current_block.AddStatement (labeled);
3290 declaration_statement
3291 : local_variable_declaration SEMICOLON
3294 DictionaryEntry de = (DictionaryEntry) $1;
3296 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3300 | local_constant_declaration SEMICOLON
3303 DictionaryEntry de = (DictionaryEntry) $1;
3305 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3311 * The following is from Rhys' grammar:
3312 * > Types in local variable declarations must be recognized as
3313 * > expressions to prevent reduce/reduce errors in the grammar.
3314 * > The expressions are converted into types during semantic analysis.
3317 : primary_expression opt_rank_specifier
3319 // FIXME: Do something smart here regarding the composition of the type.
3321 // Ok, the above "primary_expression" is there to get rid of
3322 // both reduce/reduce and shift/reduces in the grammar, it should
3323 // really just be "type_name". If you use type_name, a reduce/reduce
3324 // creeps up. If you use namespace_or_type_name (which is all we need
3325 // really) two shift/reduces appear.
3328 // So the super-trick is that primary_expression
3329 // can only be either a SimpleName or a MemberAccess.
3330 // The MemberAccess case arises when you have a fully qualified type-name like :
3332 // SimpleName is when you have
3335 Expression expr = (Expression) $1;
3336 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3337 Error_ExpectingTypeName (lexer.Location, expr);
3341 // So we extract the string corresponding to the SimpleName
3345 if ((string) $2 == "")
3348 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3351 | builtin_types opt_rank_specifier
3353 if ((string) $2 == "")
3356 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3360 local_variable_pointer_type
3361 : primary_expression STAR
3363 Expression expr = (Expression) $1;
3364 Location l = lexer.Location;
3366 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3367 Error_ExpectingTypeName (l, expr);
3371 $$ = new ComposedCast ((Expression) $1, "*", l);
3373 | builtin_types STAR
3375 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3379 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3381 | local_variable_pointer_type STAR
3383 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3387 local_variable_declaration
3388 : local_variable_type variable_declarators
3391 $$ = new DictionaryEntry ($1, $2);
3395 | local_variable_pointer_type opt_rank_specifier variable_declarators
3400 if ((string) $2 == "")
3401 t = (Expression) $1;
3403 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3404 $$ = new DictionaryEntry (t, $3);
3410 local_constant_declaration
3411 : CONST local_variable_type constant_declarators
3414 $$ = new DictionaryEntry ($2, $3);
3420 expression_statement
3421 : statement_expression SEMICOLON
3428 // We have to do the wrapping here and not in the case above,
3429 // because statement_expression is used for example in for_statement
3431 statement_expression
3432 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3433 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3434 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3435 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3436 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3437 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3438 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3440 Report.Error (1002, lexer.Location, "Expecting `;'");
3445 object_creation_expression
3446 : object_or_delegate_creation_expression
3447 { note ("complain if this is a delegate maybe?"); }
3456 : if_statement_open if_statement_rest
3465 oob_stack.Push (lexer.Location);
3470 : boolean_expression CLOSE_PARENS
3473 Location l = (Location) oob_stack.Pop ();
3475 $$ = new If ((Expression) $1, (Statement) $3, l);
3477 if (RootContext.WarningLevel >= 3){
3478 if ($3 == EmptyStatement.Value)
3479 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3483 | boolean_expression CLOSE_PARENS
3484 embedded_statement ELSE embedded_statement
3486 Location l = (Location) oob_stack.Pop ();
3488 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3493 : SWITCH OPEN_PARENS
3495 oob_stack.Push (lexer.Location);
3496 switch_stack.Push (current_block);
3498 expression CLOSE_PARENS
3501 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3502 current_block = (Block) switch_stack.Pop ();
3518 Report.Error (1522, lexer.Location, "Empty switch block");
3526 ArrayList sections = new ArrayList (4);
3531 | switch_sections switch_section
3533 ArrayList sections = (ArrayList) $1;
3543 current_block = current_block.CreateSwitchBlock (lexer.Location);
3547 Block topmost = current_block;
3549 while (topmost.Implicit)
3550 topmost = topmost.Parent;
3551 $$ = new SwitchSection ((ArrayList) $1, topmost);
3558 ArrayList labels = new ArrayList (4);
3563 | switch_labels switch_label
3565 ArrayList labels = (ArrayList) ($1);
3573 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3574 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3577 1523, lexer.Location,
3578 "The keyword case or default must precede code in switch block");
3592 oob_stack.Push (lexer.Location);
3594 boolean_expression CLOSE_PARENS embedded_statement
3596 Location l = (Location) oob_stack.Pop ();
3597 $$ = new While ((Expression) $4, (Statement) $6, l);
3599 if (RootContext.WarningLevel >= 3){
3600 if ($6 == EmptyStatement.Value)
3601 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3607 : DO embedded_statement
3609 oob_stack.Push (lexer.Location);
3611 boolean_expression CLOSE_PARENS SEMICOLON
3613 Location l = (Location) oob_stack.Pop ();
3615 $$ = new Do ((Statement) $2, (Expression) $6, l);
3621 opt_for_initializer SEMICOLON
3623 Block assign_block = new Block (current_block);
3624 current_block = assign_block;
3626 if ($3 is DictionaryEntry){
3627 DictionaryEntry de = (DictionaryEntry) $3;
3629 Expression type = (Expression) de.Key;
3630 ArrayList var_declarators = (ArrayList) de.Value;
3632 foreach (VariableDeclaration decl in var_declarators){
3636 vi = current_block.AddVariable (
3637 type, decl.identifier, current_local_parameters, decl.Location);
3641 Location l = lexer.Location;
3643 if (decl.expression_or_array_initializer is Expression){
3644 expr = (Expression) decl.expression_or_array_initializer;
3645 } else if (decl.expression_or_array_initializer == null) {
3648 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3649 expr = new ArrayCreation (type, "", init, decl.Location);
3652 LocalVariableReference var;
3653 var = new LocalVariableReference (assign_block, decl.identifier, l);
3656 Assign a = new Assign (var, expr, decl.Location);
3658 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3664 oob_stack.Push (lexer.Location);
3666 opt_for_condition SEMICOLON
3667 opt_for_iterator CLOSE_PARENS
3670 Location l = (Location) oob_stack.Pop ();
3672 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3674 if (RootContext.WarningLevel >= 3){
3675 if ($10 == EmptyStatement.Value)
3676 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3679 current_block.AddStatement (f);
3680 while (current_block.Implicit)
3681 current_block = current_block.Parent;
3683 current_block = current_block.Parent;
3688 : /* empty */ { $$ = EmptyStatement.Value; }
3693 : local_variable_declaration
3694 | statement_expression_list
3698 : /* empty */ { $$ = null; }
3699 | boolean_expression
3703 : /* empty */ { $$ = EmptyStatement.Value; }
3708 : statement_expression_list
3711 statement_expression_list
3712 : statement_expression
3714 // CHANGE: was `null'
3715 Block b = new Block (current_block, Block.Flags.Implicit);
3717 b.AddStatement ((Statement) $1);
3720 | statement_expression_list COMMA statement_expression
3722 Block b = (Block) $1;
3724 b.AddStatement ((Statement) $3);
3730 : FOREACH OPEN_PARENS type IDENTIFIER IN
3732 oob_stack.Push (lexer.Location);
3734 expression CLOSE_PARENS
3736 oob_stack.Push (current_block);
3738 Block foreach_block = new Block (current_block);
3739 LocalVariableReference v = null;
3740 Location l = lexer.Location;
3743 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3747 // Get a writable reference to this read-only variable.
3748 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3750 current_block = foreach_block;
3753 oob_stack.Push (current_block);
3757 Block foreach_block = (Block) oob_stack.Pop ();
3758 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3759 Block prev_block = (Block) oob_stack.Pop ();
3760 Location l = (Location) oob_stack.Pop ();
3762 current_block = prev_block;
3765 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3766 foreach_block.AddStatement (f);
3775 | continue_statement
3785 $$ = new Break (lexer.Location);
3790 : CONTINUE SEMICOLON
3792 $$ = new Continue (lexer.Location);
3797 : GOTO IDENTIFIER SEMICOLON
3799 $$ = new Goto (current_block, (string) $2, lexer.Location);
3801 | GOTO CASE constant_expression SEMICOLON
3803 $$ = new GotoCase ((Expression) $3, lexer.Location);
3805 | GOTO DEFAULT SEMICOLON
3807 $$ = new GotoDefault (lexer.Location);
3812 : RETURN opt_expression SEMICOLON
3814 $$ = new Return ((Expression) $2, lexer.Location);
3819 : THROW opt_expression SEMICOLON
3821 $$ = new Throw ((Expression) $2, lexer.Location);
3826 : IDENTIFIER RETURN expression SEMICOLON
3828 string s = (string) $1;
3830 Report.Error (1003, lexer.Location, "; expected");
3833 if (!RootContext.V2){
3834 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3837 if (iterator_container == null){
3838 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3841 iterator_container.SetYields ();
3842 $$ = new Yield ((Expression) $3, lexer.Location);
3845 | IDENTIFIER BREAK SEMICOLON
3847 string s = (string) $1;
3849 Report.Error (1003, lexer.Location, "; expected");
3852 if (!RootContext.V2){
3853 Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
3856 if (iterator_container == null){
3857 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3860 iterator_container.SetYields ();
3861 $$ = new YieldBreak (lexer.Location);
3872 : TRY block catch_clauses
3875 ArrayList s = new ArrayList (4);
3877 foreach (Catch cc in (ArrayList) $3) {
3884 // Now s contains the list of specific catch clauses
3885 // and g contains the general one.
3887 $$ = new Try ((Block) $2, s, g, null, lexer.Location);
3889 | TRY block opt_catch_clauses FINALLY block
3892 ArrayList s = new ArrayList (4);
3893 ArrayList catch_list = (ArrayList) $3;
3895 if (catch_list != null){
3896 foreach (Catch cc in catch_list) {
3904 $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
3908 Report.Error (1524, lexer.Location, "Expected catch or finally");
3913 : /* empty */ { $$ = null; }
3920 ArrayList l = new ArrayList (4);
3925 | catch_clauses catch_clause
3927 ArrayList l = (ArrayList) $1;
3935 : /* empty */ { $$ = null; }
3940 : CATCH opt_catch_args
3942 Expression type = null;
3946 DictionaryEntry cc = (DictionaryEntry) $2;
3947 type = (Expression) cc.Key;
3948 id = (string) cc.Value;
3951 ArrayList one = new ArrayList (4);
3952 Location loc = lexer.Location;
3954 one.Add (new VariableDeclaration (id, null, loc));
3957 current_block = new Block (current_block);
3958 Block b = declare_local_variables (type, one, loc);
3963 Expression type = null;
3967 DictionaryEntry cc = (DictionaryEntry) $2;
3968 type = (Expression) cc.Key;
3969 id = (string) cc.Value;
3973 // FIXME: I can change this for an assignment.
3975 while (current_block != (Block) $1)
3976 current_block = current_block.Parent;
3981 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3986 : /* empty */ { $$ = null; }
3991 : OPEN_PARENS type opt_identifier CLOSE_PARENS
3993 $$ = new DictionaryEntry ($2, $3);
4000 $$ = new Checked ((Block) $2);
4007 $$ = new Unchecked ((Block) $2);
4014 if (!RootContext.Unsafe){
4015 Report.Error (227, lexer.Location,
4016 "Unsafe code can only be used if --unsafe is used");
4019 $$ = new Unsafe ((Block) $3);
4025 type fixed_pointer_declarators
4028 Block assign_block = new Block (current_block, Block.Flags.Implicit);
4029 ArrayList list = (ArrayList) $4;
4030 Expression type = (Expression) $3;
4031 Location l = lexer.Location;
4032 int top = list.Count;
4034 for (int i = 0; i < top; i++){
4035 Pair p = (Pair) list [i];
4038 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4045 current_block.AddStatement (assign_block);
4046 current_block = assign_block;
4047 oob_stack.Push (assign_block);
4052 Location l = (Location) oob_stack.Pop ();
4055 $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4059 fixed_pointer_declarators
4060 : fixed_pointer_declarator {
4061 ArrayList declarators = new ArrayList (4);
4062 declarators.Add ($1);
4065 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4067 ArrayList declarators = (ArrayList) $1;
4068 declarators.Add ($3);
4073 fixed_pointer_declarator
4074 : IDENTIFIER ASSIGN expression
4076 $$ = new Pair ($1, $3);
4081 : LOCK OPEN_PARENS expression CLOSE_PARENS
4087 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4092 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4094 Block assign_block = new Block (current_block);
4095 current_block = assign_block;
4097 oob_stack.Push (lexer.Location);
4099 if ($3 is DictionaryEntry){
4100 DictionaryEntry de = (DictionaryEntry) $3;
4101 Location l = lexer.Location;
4103 Expression type = (Expression) de.Key;
4104 ArrayList var_declarators = (ArrayList) de.Value;
4106 ArrayList vars = new ArrayList (4);
4108 foreach (VariableDeclaration decl in var_declarators){
4110 LocalInfo vi = current_block.AddVariable (
4111 type, decl.identifier,
4112 current_local_parameters, decl.Location);
4118 if (decl.expression_or_array_initializer is Expression){
4119 expr = (Expression) decl.expression_or_array_initializer;
4121 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4123 expr = new ArrayCreation (type, "", init, decl.Location);
4126 LocalVariableReference var;
4128 // Get a writable reference to this read-only variable.
4129 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4131 // This is so that it is not a warning on using variables
4134 vars.Add (new DictionaryEntry (var, expr));
4136 // Assign a = new Assign (var, expr, decl.Location);
4137 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4139 $3 = new DictionaryEntry (type, vars);
4144 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4145 current_block.AddStatement (u);
4146 while (current_block.Implicit)
4147 current_block = current_block.Parent;
4149 current_block = current_block.Parent;
4153 resource_acquisition
4154 : local_variable_declaration
4161 // A class used to pass around variable declarations and constants
4163 public class VariableDeclaration {
4164 public string identifier;
4165 public object expression_or_array_initializer;
4166 public Location Location;
4167 public Attributes OptAttributes;
4169 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4171 this.identifier = id;
4172 this.expression_or_array_initializer = eoai;
4174 this.OptAttributes = opt_attrs;
4177 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4183 /// Used to pass around interface property information
4185 public class InterfaceAccessorInfo {
4187 public readonly Accessor Get, Set;
4189 public InterfaceAccessorInfo (bool has_get, bool has_set,
4190 Attributes get_attrs, Attributes set_attrs)
4193 Get = new Accessor (null, get_attrs);
4195 Set = new Accessor (null, set_attrs);
4201 // A class used to hold info about an indexer declarator
4203 public class IndexerDeclaration {
4204 public Expression type;
4205 public TypeName interface_type;
4206 public Parameters param_list;
4208 public IndexerDeclaration (Expression type, TypeName interface_type,
4209 Parameters param_list)
4212 this.interface_type = interface_type;
4213 this.param_list = param_list;
4218 // We use this when we do not have an object in advance that is an IIteratorContainer
4220 public class SimpleIteratorContainer : IIteratorContainer {
4223 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4228 public static SimpleIteratorContainer GetSimple () {
4229 Simple.Yields = false;
4233 public void SetYields () { Yields = true; }
4237 // A class used to hold info about an operator declarator
4239 public class OperatorDeclaration {
4240 public Operator.OpType optype;
4241 public Expression ret_type, arg1type, arg2type;
4242 public string arg1name, arg2name;
4243 public Location location;
4245 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4246 Expression arg1type, string arg1name,
4247 Expression arg2type, string arg2name, Location location)
4250 this.ret_type = ret_type;
4251 this.arg1type = arg1type;
4252 this.arg1name = arg1name;
4253 this.arg2type = arg2type;
4254 this.arg2name = arg2name;
4255 this.location = location;
4260 void Error_ExpectingTypeName (Location l, Expression expr)
4262 if (expr is Invocation){
4263 Report.Error (1002, l, "; expected");
4265 Report.Error (-1, l, "Invalid Type definition");
4270 // Given the @class_name name, it creates a fully qualified name
4271 // based on the containing declaration space
4274 MakeName (MemberName class_name)
4276 string ns = current_namespace.FullName;
4278 if (current_container.Name == ""){
4280 return new MemberName (new TypeName (ns), class_name);
4284 TypeName type = current_container.MemberName.MakeTypeName (lexer.Location);
4285 return new MemberName (type, class_name);
4290 // Used to report back to the user the result of a declaration
4291 // in the current declaration space
4294 CheckDef (DeclSpace.AdditionResult result, string name, Location l)
4296 if (result == DeclSpace.AdditionResult.Success)
4300 case DeclSpace.AdditionResult.NameExists:
4301 Report.Error (102, l, "The container `" + current_container.Name +
4302 "' already contains a definition for `"+
4308 // This is handled only for static Constructors, because
4309 // in reality we handle these by the semantic analysis later
4311 case DeclSpace.AdditionResult.MethodExists:
4313 111, l, "Class `"+current_container.Name+
4314 "' already defines a member called '" +
4315 name + "' with the same parameter types (more than one default constructor)");
4318 case DeclSpace.AdditionResult.EnclosingClash:
4319 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
4322 case DeclSpace.AdditionResult.NotAConstructor:
4323 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
4326 case DeclSpace.AdditionResult.Error:
4327 // Error has already been reported.
4333 CheckDef (bool result, string name, Location l)
4337 CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
4340 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4342 Block implicit_block;
4343 ArrayList inits = null;
4346 // We use the `Used' property to check whether statements
4347 // have been added to the current block. If so, we need
4348 // to create another block to contain the new declaration
4349 // otherwise, as an optimization, we use the same block to
4350 // add the declaration.
4352 // FIXME: A further optimization is to check if the statements
4353 // that were added were added as part of the initialization
4354 // below. In which case, no other statements have been executed
4355 // and we might be able to reduce the number of blocks for
4356 // situations like this:
4358 // int j = 1; int k = j + 1;
4360 if (current_block.Used)
4361 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4363 implicit_block = current_block;
4365 foreach (VariableDeclaration decl in variable_declarators){
4367 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4368 if (decl.expression_or_array_initializer != null){
4370 inits = new ArrayList (4);
4377 return implicit_block;
4379 foreach (VariableDeclaration decl in inits){
4383 if (decl.expression_or_array_initializer is Expression){
4384 expr = (Expression) decl.expression_or_array_initializer;
4387 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4389 expr = new ArrayCreation (type, "", init, decl.Location);
4392 LocalVariableReference var;
4393 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4395 assign = new Assign (var, expr, decl.Location);
4397 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4400 return implicit_block;
4403 Block declare_local_constants (Expression type, ArrayList declarators)
4405 Block implicit_block;
4407 if (current_block.Used)
4408 implicit_block = new Block (current_block, Block.Flags.Implicit);
4410 implicit_block = current_block;
4412 foreach (VariableDeclaration decl in declarators){
4413 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4414 current_local_parameters, decl.Location);
4417 return implicit_block;
4420 void CheckAttributeTarget (string a)
4424 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4428 Location l = lexer.Location;
4429 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4435 void CheckUnaryOperator (Operator.OpType op)
4439 case Operator.OpType.LogicalNot:
4440 case Operator.OpType.OnesComplement:
4441 case Operator.OpType.Increment:
4442 case Operator.OpType.Decrement:
4443 case Operator.OpType.True:
4444 case Operator.OpType.False:
4445 case Operator.OpType.Addition:
4446 case Operator.OpType.Subtraction:
4451 Location l = lexer.Location;
4452 Report.Error (1019, l, "Overloadable unary operator expected");
4458 void CheckBinaryOperator (Operator.OpType op)
4462 case Operator.OpType.Addition:
4463 case Operator.OpType.Subtraction:
4464 case Operator.OpType.Multiply:
4465 case Operator.OpType.Division:
4466 case Operator.OpType.Modulus:
4467 case Operator.OpType.BitwiseAnd:
4468 case Operator.OpType.BitwiseOr:
4469 case Operator.OpType.ExclusiveOr:
4470 case Operator.OpType.LeftShift:
4471 case Operator.OpType.RightShift:
4472 case Operator.OpType.Equality:
4473 case Operator.OpType.Inequality:
4474 case Operator.OpType.GreaterThan:
4475 case Operator.OpType.LessThan:
4476 case Operator.OpType.GreaterThanOrEqual:
4477 case Operator.OpType.LessThanOrEqual:
4481 Location l = lexer.Location;
4482 Report.Error (1020, l, "Overloadable binary operator expected");
4488 void syntax_error (Location l, string msg)
4490 Report.Error (1003, l, "Syntax error, " + msg);
4493 void output (string s)
4495 Console.WriteLine (s);
4498 void note (string s)
4500 // Used to put annotations
4505 public Tokenizer Lexer {
4511 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4513 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4514 this.name = file.Name;
4516 current_container = RootContext.Tree.Types;
4517 current_container.NamespaceEntry = current_namespace;
4518 oob_stack = new Stack ();
4519 switch_stack = new Stack ();
4521 lexer = new Tokenizer (reader, file, defines);
4524 public void parse ()
4527 if (yacc_verbose_flag)
4528 yyparse (lexer, new yydebug.yyDebugSimple ());
4531 Tokenizer tokenizer = lexer as Tokenizer;
4532 tokenizer.cleanup ();
4533 } catch (Exception e){
4534 // Please do not remove this, it is used during debugging
4537 Console.WriteLine (e);
4538 Report.Error (-25, lexer.Location, "Parsing error");
4539 if (Driver.parser_verbose)
4540 Console.WriteLine (e);
4544 void CheckToken (int error, int yyToken, string msg)
4546 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4547 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4550 Report.Error (error, lexer.Location, msg);
4553 void CheckIdentifierToken (int yyToken)
4555 CheckToken (1041, yyToken, "Identifier expected");