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;
35 TypeContainer current_class;
37 IIteratorContainer iterator_container;
40 /// Current block is used to add statements as we find
43 Block current_block, top_current_block;
46 /// This is used by the unary_expression code to resolve
47 /// a name against a parameter.
49 Parameters current_local_parameters;
52 /// Using during property parsing to describe the implicit
53 /// value parameter that is passed to the "set" and "get"accesor
54 /// methods (properties and indexers).
56 Expression implicit_value_parameter_type;
57 Parameters indexer_parameters;
60 /// Used to determine if we are parsing the get/set pair
61 /// of an indexer or a property
66 /// An out-of-band stack.
75 public bool yacc_verbose_flag;
77 // Name of the file we are parsing
86 /// Current attribute target
87 string current_attr_target;
89 /// assembly and module attribute definition is enabled
90 bool global_attrs_enabled = true;
94 %token NONE /* This token is never returned by our lexer */
95 %token ERROR // This is used not by the parser, but by the tokenizer.
99 *These are the C# keywords
185 /* C# keywords which are not really keywords */
191 /* C# single character operators/punctuation. */
192 %token OPEN_BRACE "{"
193 %token CLOSE_BRACE "}"
194 %token OPEN_BRACKET "["
195 %token CLOSE_BRACKET "]"
196 %token OPEN_PARENS "("
197 %token CLOSE_PARENS ")"
210 %token BITWISE_AND "&"
211 %token BITWISE_OR "|"
218 /* C# multi-character operators. */
221 %token OP_SHIFT_LEFT "<<"
222 %token OP_SHIFT_RIGHT ">>"
229 %token OP_MULT_ASSIGN "*="
230 %token OP_DIV_ASSIGN "/="
231 %token OP_MOD_ASSIGN "%="
232 %token OP_ADD_ASSIGN "+="
233 %token OP_SUB_ASSIGN "-="
234 %token OP_SHIFT_LEFT_ASSIGN "<<="
235 %token OP_SHIFT_RIGHT_ASSIGN ">>="
236 %token OP_AND_ASSIGN "&="
237 %token OP_XOR_ASSIGN "^="
238 %token OP_OR_ASSIGN "|="
242 %token LITERAL_INTEGER "int literal"
243 %token LITERAL_FLOAT "float literal"
244 %token LITERAL_DOUBLE "double literal"
245 %token LITERAL_DECIMAL "decimal literal"
246 %token LITERAL_CHARACTER "character literal"
247 %token LITERAL_STRING "string literal"
250 %token CLOSE_PARENS_CAST
251 %token CLOSE_PARENS_NO_CAST
252 %token CLOSE_PARENS_OPEN_PARENS
253 %token CLOSE_PARENS_MINUS
255 /* Add precedence rules to solve dangling else s/r conflict */
264 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
266 %left STAR DIV PERCENT
267 %right BANG CARRET UMINUS
268 %nonassoc OP_INC OP_DEC
270 %left OPEN_BRACKET OPEN_BRACE
274 %start compilation_unit
278 : outer_declarations opt_EOF
279 | outer_declarations global_attributes opt_EOF
280 | global_attributes opt_EOF
281 | opt_EOF /* allow empty files */
291 | outer_declarations outer_declaration
296 | namespace_member_declaration
301 | using_directives using_directive
305 : using_alias_directive
306 | using_namespace_directive
309 using_alias_directive
310 : USING IDENTIFIER ASSIGN
311 namespace_or_type_name SEMICOLON
313 current_namespace.UsingAlias ((string) $2, (MemberName) $4, lexer.Location);
316 CheckIdentifierToken (yyToken);
320 using_namespace_directive
321 : USING namespace_name SEMICOLON
323 current_namespace.Using ((string) $2, lexer.Location);
328 // Strictly speaking, namespaces don't have attributes but
329 // we parse global attributes along with namespace declarations and then
332 namespace_declaration
333 : opt_attributes NAMESPACE namespace_or_type_name
336 Report.Error(1518, Lexer.Location, "Attributes cannot be applied to namespaces."
337 + " Expected class, delegate, enum, interface, or struct");
340 MemberName name = (MemberName) $3;
342 if ((current_namespace.Parent != null) && (name.Left != null)) {
343 Report.Error (134, lexer.Location,
344 "Cannot use qualified namespace names in nested " +
345 "namespace declarations");
348 current_namespace = new NamespaceEntry (
349 current_namespace, file, name.GetName (), lexer.Location);
351 namespace_body opt_semicolon
353 current_namespace = current_namespace.Parent;
368 : namespace_or_type_name {
369 MemberName name = (MemberName) $1;
371 $$ = name.GetName ();
378 opt_namespace_member_declarations
389 opt_namespace_member_declarations
391 | namespace_member_declarations
394 namespace_member_declarations
395 : namespace_member_declaration
396 | namespace_member_declarations namespace_member_declaration
399 namespace_member_declaration
406 Class c = (Class) $1;
407 mod_flags = c.ModFlags;
409 } else if ($1 is Struct){
410 Struct s = (Struct) $1;
411 mod_flags = s.ModFlags;
416 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
418 1527, lexer.Location,
419 "Namespace elements cant be explicitly " +
420 "declared private or protected in `" + name + "'");
422 current_namespace.DeclarationFound = true;
424 | namespace_declaration {
425 current_namespace.DeclarationFound = true;
428 | field_declaration {
429 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
431 | method_declaration {
432 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
439 | interface_declaration
441 | delegate_declaration
443 // Enable this when we have handled all errors, because this acts as a generic fallback
446 // Console.WriteLine ("Token=" + yyToken);
447 // Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
459 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
467 global_attrs_enabled = false;
472 global_attrs_enabled = false;
481 ArrayList sect = (ArrayList) $1;
483 if (global_attrs_enabled) {
484 if (current_attr_target == "module") {
485 CodeGen.Module.AddAttributes (sect);
487 } else if (current_attr_target == "assembly") {
488 CodeGen.Assembly.AddAttributes (sect);
491 $$ = new Attributes (sect);
494 $$ = new Attributes (sect);
496 current_attr_target = null;
498 | attribute_sections attribute_section
500 Attributes attrs = $1 as Attributes;
501 ArrayList sect = (ArrayList) $2;
503 if (global_attrs_enabled) {
504 if (current_attr_target == "module") {
505 CodeGen.Module.AddAttributes (sect);
507 } else if (current_attr_target == "assembly") {
508 CodeGen.Assembly.AddAttributes (sect);
512 attrs = new Attributes (sect);
514 attrs.AddAttributes (sect);
518 attrs = new Attributes (sect);
520 attrs.AddAttributes (sect);
523 current_attr_target = null;
528 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
532 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
538 attribute_target_specifier
539 : attribute_target COLON
541 current_attr_target = (string)$1;
549 CheckAttributeTarget ((string) $1);
552 | EVENT { $$ = "event"; }
553 | RETURN { $$ = "return"; }
559 ArrayList attrs = new ArrayList (4);
565 | attribute_list COMMA attribute
567 ArrayList attrs = (ArrayList) $1;
579 opt_attribute_arguments
581 MemberName mname = (MemberName) $1;
582 string name = mname.GetName ();
583 if (current_attr_target == "assembly" || current_attr_target == "module")
584 $$ = new GlobalAttribute (current_container, current_attr_target,
585 name, (ArrayList) $3, (Location) $2);
587 $$ = new Attribute (current_attr_target, name, (ArrayList) $3,
593 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
596 opt_attribute_arguments
597 : /* empty */ { $$ = null; }
598 | OPEN_PARENS attribute_arguments CLOSE_PARENS
606 : opt_positional_argument_list
611 ArrayList args = new ArrayList (4);
617 | positional_argument_list COMMA named_argument_list
619 ArrayList args = new ArrayList (4);
625 | named_argument_list
627 ArrayList args = new ArrayList (4);
636 opt_positional_argument_list
637 : /* empty */ { $$ = null; }
638 | positional_argument_list
641 positional_argument_list
644 ArrayList args = new ArrayList (4);
645 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
649 | positional_argument_list COMMA expression
651 ArrayList args = (ArrayList) $1;
652 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
661 ArrayList args = new ArrayList (4);
666 | named_argument_list COMMA named_argument
668 ArrayList args = (ArrayList) $1;
673 | named_argument_list COMMA expression
675 Report.Error (1016, lexer.Location, "Named attribute argument expected");
681 : IDENTIFIER ASSIGN expression
683 $$ = new DictionaryEntry (
685 new Argument ((Expression) $3, Argument.AType.Expression));
691 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
694 opt_class_member_declarations
696 | class_member_declarations
699 class_member_declarations
700 : class_member_declaration
701 | class_member_declarations
702 class_member_declaration
705 class_member_declaration
706 : constant_declaration // done
707 | field_declaration // done
708 | method_declaration // done
709 | property_declaration // done
710 | event_declaration // done
711 | indexer_declaration // done
712 | operator_declaration // done
713 | constructor_declaration // done
714 | destructor_declaration // done
724 MemberName name = MakeName ((MemberName) $5);
725 bool partial = (bool) $3;
728 ClassPart part = PartialContainer.CreatePart (
729 current_namespace, current_container, name, (int) $2,
730 (Attributes) $1, Kind.Struct, lexer.Location);
732 current_container = part.PartialContainer;
733 current_class = part;
735 current_class = new Struct (
736 current_namespace, current_container, name, (int) $2,
737 (Attributes) $1, lexer.Location);
739 current_container = current_class;
740 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
746 current_class.Bases = (ArrayList) $7;
748 current_class.Register ();
755 current_container = current_container.Parent;
756 current_class = current_container;
758 | opt_attributes opt_modifiers opt_partial STRUCT error {
759 CheckIdentifierToken (yyToken);
764 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
767 opt_struct_member_declarations
769 | struct_member_declarations
772 struct_member_declarations
773 : struct_member_declaration
774 | struct_member_declarations struct_member_declaration
777 struct_member_declaration
778 : constant_declaration
781 | property_declaration
783 | indexer_declaration
784 | operator_declaration
785 | constructor_declaration
789 * This is only included so we can flag error 575:
790 * destructors only allowed on class types
792 | destructor_declaration
803 int modflags = (int) $2;
804 foreach (VariableDeclaration constant in (ArrayList) $5){
805 Location l = constant.Location;
806 if ((modflags & Modifiers.STATIC) != 0) {
807 Report.Error (504, l, "The constant '{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
811 Const c = new Const (
812 current_class, (Expression) $4, (string) constant.identifier,
813 (Expression) constant.expression_or_array_initializer, modflags,
816 current_container.AddConstant (c);
822 : constant_declarator
824 ArrayList constants = new ArrayList (4);
829 | constant_declarators COMMA constant_declarator
832 ArrayList constants = (ArrayList) $1;
839 : IDENTIFIER ASSIGN constant_expression
841 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
845 // A const field requires a value to be provided
846 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
858 Expression type = (Expression) $3;
861 foreach (VariableDeclaration var in (ArrayList) $4){
862 Location l = var.Location;
864 Field field = new Field (current_class, type, mod, var.identifier,
865 var.expression_or_array_initializer,
868 current_container.AddField (field);
876 Report.Error (670, lexer.Location, "void type is not allowed for fields");
881 : variable_declarator
883 ArrayList decl = new ArrayList (4);
887 | variable_declarators COMMA variable_declarator
889 ArrayList decls = (ArrayList) $1;
896 : IDENTIFIER ASSIGN variable_initializer
898 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
902 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
915 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
917 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
921 Report.Error (1575, lexer.Location, "A stackalloc expression requires [] after type");
928 iterator_container = (IIteratorContainer) $1;
932 Method method = (Method) $1;
933 Block b = (Block) $3;
934 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
937 if ((method.ModFlags & extern_abstract) == 0){
939 501, lexer.Location, current_container.MakeName (method.Name) +
940 "must declare a body because it is not marked abstract or extern");
943 if ((method.ModFlags & Modifiers.EXTERN) != 0){
945 179, lexer.Location, current_container.MakeName (method.Name) +
946 " is declared extern, but has a body");
950 method.Block = (ToplevelBlock) $3;
951 current_container.AddMethod (method);
953 current_local_parameters = null;
954 iterator_container = null;
968 1585, lexer.Location, "Member modifier `" +
969 Modifiers.Name (i) + "' must precede member type and name");
980 type namespace_or_type_name
981 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
983 MemberName name = (MemberName) $4;
985 Method method = new Method (current_class, (Expression) $3, (int) $2,
986 false, name, (Parameters) $6, (Attributes) $1,
989 current_local_parameters = (Parameters) $6;
995 VOID namespace_or_type_name
996 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
998 MemberName name = (MemberName) $4;
1000 Method method = new Method (current_class, TypeManager.system_void_expr,
1001 (int) $2, false, name, (Parameters) $6,
1002 (Attributes) $1, lexer.Location);
1004 current_local_parameters = (Parameters) $6;
1010 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1012 Report.Error (1585, lexer.Location,
1013 String.Format ("Modifier {0} should appear before type",
1014 Modifiers.Name ((int) $4)));
1015 MemberName name = (MemberName) $4;
1017 Method method = new Method (current_class, TypeManager.system_void_expr,
1018 0, false, name, (Parameters) $7, (Attributes) $1,
1021 current_local_parameters = (Parameters) $7;
1028 | SEMICOLON { $$ = null; }
1031 opt_formal_parameter_list
1032 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1033 | formal_parameter_list
1036 formal_parameter_list
1039 ArrayList pars_list = (ArrayList) $1;
1041 Parameter [] pars = new Parameter [pars_list.Count];
1042 pars_list.CopyTo (pars);
1044 $$ = new Parameters (pars, null, lexer.Location);
1046 | fixed_parameters COMMA parameter_array
1048 ArrayList pars_list = (ArrayList) $1;
1050 Parameter [] pars = new Parameter [pars_list.Count];
1051 pars_list.CopyTo (pars);
1053 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
1055 | fixed_parameters COMMA ARGLIST
1057 ArrayList pars_list = (ArrayList) $1;
1059 Parameter [] pars = new Parameter [pars_list.Count];
1060 pars_list.CopyTo (pars);
1062 $$ = new Parameters (pars, true, lexer.Location);
1064 | parameter_array COMMA fixed_parameters
1066 Report.Error (231, lexer.Location, "A params parameter must be the last parameter in a formal parameter list");
1069 | ARGLIST COMMA fixed_parameters
1071 Report.Error (257, lexer.Location, "An __arglist parameter must be the last parameter in a formal parameter list");
1076 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1080 $$ = new Parameters (null, true, lexer.Location);
1087 ArrayList pars = new ArrayList (4);
1092 | fixed_parameters COMMA fixed_parameter
1094 ArrayList pars = (ArrayList) $1;
1103 opt_parameter_modifier
1107 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1110 opt_parameter_modifier
1113 Report.Error (1001, lexer.Location, "Identifier expected");
1117 opt_parameter_modifier
1120 CheckIdentifierToken (yyToken);
1124 opt_parameter_modifier
1130 Report.Error (241, lexer.Location, "Default parameter specifiers are not permitted");
1135 opt_parameter_modifier
1136 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1137 | parameter_modifier
1141 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1142 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1146 : opt_attributes PARAMS type IDENTIFIER
1148 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1149 note ("type must be a single-dimension array type");
1151 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1153 Report.Error (1611, lexer.Location, "The params parameter cannot be declared as ref or out");
1156 | opt_attributes PARAMS type error {
1157 CheckIdentifierToken (yyToken);
1162 property_declaration
1165 type namespace_or_type_name
1168 implicit_value_parameter_type = (Expression) $3;
1170 lexer.PropertyParsing = true;
1172 $$ = lexer.Location;
1174 iterator_container = SimpleIteratorContainer.GetSimple ();
1176 accessor_declarations
1178 lexer.PropertyParsing = false;
1183 Pair pair = (Pair) $7;
1184 Accessor get_block = (Accessor) pair.First;
1185 Accessor set_block = (Accessor) pair.Second;
1187 Location loc = (Location) $6;
1188 MemberName name = (MemberName) $4;
1190 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1191 name, (Attributes) $1, get_block, set_block, loc);
1192 if (SimpleIteratorContainer.Simple.Yields)
1195 current_container.AddProperty (prop);
1196 implicit_value_parameter_type = null;
1197 iterator_container = null;
1201 accessor_declarations
1202 : get_accessor_declaration opt_set_accessor_declaration
1204 $$ = new Pair ($1, $2);
1206 | set_accessor_declaration opt_get_accessor_declaration
1208 $$ = new Pair ($2, $1);
1212 opt_get_accessor_declaration
1213 : /* empty */ { $$ = null; }
1214 | get_accessor_declaration
1217 opt_set_accessor_declaration
1218 : /* empty */ { $$ = null; }
1219 | set_accessor_declaration
1222 get_accessor_declaration
1223 : opt_attributes opt_modifiers GET
1225 // If this is not the case, then current_local_parameters has already
1226 // been set in indexer_declaration
1227 if (parsing_indexer == false)
1228 current_local_parameters = null;
1230 current_local_parameters = indexer_parameters;
1231 lexer.PropertyParsing = false;
1235 $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
1236 current_local_parameters = null;
1237 lexer.PropertyParsing = true;
1241 set_accessor_declaration
1242 : opt_attributes opt_modifiers SET
1245 Parameter implicit_value_parameter = new Parameter (
1246 implicit_value_parameter_type, "value",
1247 Parameter.Modifier.NONE, null);
1249 if (parsing_indexer == false) {
1250 args = new Parameter [1];
1251 args [0] = implicit_value_parameter;
1252 current_local_parameters = new Parameters (args, null, lexer.Location);
1254 Parameter [] fpars = indexer_parameters.FixedParameters;
1257 int count = fpars.Length;
1259 args = new Parameter [count + 1];
1260 fpars.CopyTo (args, 0);
1261 args [count] = implicit_value_parameter;
1264 current_local_parameters = new Parameters (
1265 args, indexer_parameters.ArrayParameter, lexer.Location);
1268 lexer.PropertyParsing = false;
1272 $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
1273 current_local_parameters = null;
1274 lexer.PropertyParsing = true;
1280 | SEMICOLON { $$ = null; }
1283 interface_declaration
1287 INTERFACE member_name
1289 MemberName name = MakeName ((MemberName) $5);
1290 bool partial = (bool) $3;
1293 ClassPart part = PartialContainer.CreatePart (
1294 current_namespace, current_container, name, (int) $2,
1295 (Attributes) $1, Kind.Interface, lexer.Location);
1297 current_container = part.PartialContainer;
1298 current_class = part;
1300 current_class = new Interface (
1301 current_namespace, current_container, name, (int) $2,
1302 (Attributes) $1, lexer.Location);
1304 current_container = current_class;
1305 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
1310 current_class.Bases = (ArrayList) $7;
1312 current_class.Register ();
1319 current_container = current_container.Parent;
1320 current_class = current_container;
1322 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1323 CheckIdentifierToken (yyToken);
1329 opt_interface_member_declarations
1333 opt_interface_member_declarations
1335 | interface_member_declarations
1338 interface_member_declarations
1339 : interface_member_declaration
1340 | interface_member_declarations interface_member_declaration
1343 interface_member_declaration
1344 : interface_method_declaration
1346 Method m = (Method) $1;
1348 current_container.AddMethod (m);
1350 | interface_property_declaration
1352 Property p = (Property) $1;
1354 current_container.AddProperty (p);
1356 | interface_event_declaration
1359 Event e = (Event) $1;
1360 current_container.AddEvent (e);
1363 | interface_indexer_declaration
1365 Indexer i = (Indexer) $1;
1367 current_container.AddIndexer (i);
1375 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1380 interface_method_declaration
1381 : opt_attributes opt_new type namespace_or_type_name
1382 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1385 MemberName name = (MemberName) $4;
1387 $$ = new Method (current_class, (Expression) $3, (int) $2, true,
1388 name, (Parameters) $6, (Attributes) $1, lexer.Location);
1390 | opt_attributes opt_new VOID namespace_or_type_name
1391 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1394 MemberName name = (MemberName) $4;
1396 $$ = new Method (current_class, TypeManager.system_void_expr, (int) $2,
1397 true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
1401 interface_property_declaration
1406 { lexer.PropertyParsing = true; }
1408 { lexer.PropertyParsing = false; }
1411 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1413 $$ = new Property (current_class, (Expression) $3, (int) $2, true,
1414 new MemberName ((string) $4), (Attributes) $1,
1415 pinfo.Get, pinfo.Set, lexer.Location);
1420 CheckIdentifierToken (yyToken);
1426 : opt_attributes opt_modifiers GET SEMICOLON
1427 { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, (int) $2, 0, lexer.Location, lexer.Location); }
1428 | opt_attributes opt_modifiers SET SEMICOLON
1429 { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1, 0, (int) $2, lexer.Location, lexer.Location); }
1430 | opt_attributes opt_modifiers GET SEMICOLON opt_attributes opt_modifiers SET SEMICOLON
1431 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $5, (int) $2, (int) $6, lexer.Location, lexer.Location); }
1432 | opt_attributes opt_modifiers SET SEMICOLON opt_attributes opt_modifiers GET SEMICOLON
1433 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $5, (Attributes) $1, (int) $6, (int) $2, lexer.Location, lexer.Location); }
1436 interface_event_declaration
1437 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1439 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1440 new MemberName ((string) $5), null,
1441 (Attributes) $1, lexer.Location);
1443 | opt_attributes opt_new EVENT type error {
1444 CheckIdentifierToken (yyToken);
1447 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1448 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1451 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1452 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1457 interface_indexer_declaration
1458 : opt_attributes opt_new type THIS
1459 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1461 { lexer.PropertyParsing = true; }
1463 { lexer.PropertyParsing = false; }
1466 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1468 $$ = new Indexer (current_class, (Expression) $3,
1469 new MemberName (TypeContainer.DefaultIndexerName),
1470 (int) $2, true, (Parameters) $6, (Attributes) $1,
1471 info.Get, info.Set, lexer.Location);
1475 operator_declaration
1476 : opt_attributes opt_modifiers operator_declarator
1478 iterator_container = SimpleIteratorContainer.GetSimple ();
1482 OperatorDeclaration decl = (OperatorDeclaration) $3;
1484 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
1486 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null);
1487 if (decl.arg2type != null)
1488 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null);
1490 Operator op = new Operator (
1491 current_class, decl.optype, decl.ret_type, (int) $2,
1492 new Parameters (param_list, null, decl.location),
1493 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1495 if (SimpleIteratorContainer.Simple.Yields)
1498 // Note again, checking is done in semantic analysis
1499 current_container.AddOperator (op);
1501 current_local_parameters = null;
1502 iterator_container = null;
1508 | SEMICOLON { $$ = null; }
1511 : type OPERATOR overloadable_operator
1512 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1514 Operator.OpType op = (Operator.OpType) $3;
1515 CheckUnaryOperator (op);
1517 if (op == Operator.OpType.Addition)
1518 op = Operator.OpType.UnaryPlus;
1520 if (op == Operator.OpType.Subtraction)
1521 op = Operator.OpType.UnaryNegation;
1523 Parameter [] pars = new Parameter [1];
1525 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1527 current_local_parameters = new Parameters (pars, null, lexer.Location);
1529 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1530 null, null, lexer.Location);
1532 | type OPERATOR overloadable_operator
1534 type IDENTIFIER COMMA
1538 CheckBinaryOperator ((Operator.OpType) $3);
1540 Parameter [] pars = new Parameter [2];
1542 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1543 pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1545 current_local_parameters = new Parameters (pars, null, lexer.Location);
1547 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1548 (Expression) $5, (string) $6,
1549 (Expression) $8, (string) $9, lexer.Location);
1551 | conversion_operator_declarator
1554 overloadable_operator
1556 : BANG { $$ = Operator.OpType.LogicalNot; }
1557 | TILDE { $$ = Operator.OpType.OnesComplement; }
1558 | OP_INC { $$ = Operator.OpType.Increment; }
1559 | OP_DEC { $$ = Operator.OpType.Decrement; }
1560 | TRUE { $$ = Operator.OpType.True; }
1561 | FALSE { $$ = Operator.OpType.False; }
1562 // Unary and binary:
1563 | PLUS { $$ = Operator.OpType.Addition; }
1564 | MINUS { $$ = Operator.OpType.Subtraction; }
1566 | STAR { $$ = Operator.OpType.Multiply; }
1567 | DIV { $$ = Operator.OpType.Division; }
1568 | PERCENT { $$ = Operator.OpType.Modulus; }
1569 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1570 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1571 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1572 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1573 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1574 | OP_EQ { $$ = Operator.OpType.Equality; }
1575 | OP_NE { $$ = Operator.OpType.Inequality; }
1576 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1577 | OP_LT { $$ = Operator.OpType.LessThan; }
1578 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1579 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1582 conversion_operator_declarator
1583 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1585 Parameter [] pars = new Parameter [1];
1587 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1589 current_local_parameters = new Parameters (pars, null, lexer.Location);
1591 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1592 null, null, lexer.Location);
1594 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1596 Parameter [] pars = new Parameter [1];
1598 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1600 current_local_parameters = new Parameters (pars, null, lexer.Location);
1602 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1603 null, null, lexer.Location);
1607 syntax_error (lexer.Location, "'operator' expected");
1611 syntax_error (lexer.Location, "'operator' expected");
1615 constructor_declaration
1618 constructor_declarator
1621 Constructor c = (Constructor) $3;
1622 c.Block = (ToplevelBlock) $4;
1623 c.OptAttributes = (Attributes) $1;
1624 c.ModFlags = (int) $2;
1626 if (c.Name == current_container.Basename){
1627 if ((c.ModFlags & Modifiers.STATIC) != 0){
1628 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1630 515, c.Location, String.Format (
1631 "`{0}.{1}': static constructor can not have access modifiers",
1632 c.Name, current_container.Name));
1635 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1637 if (c.Initializer != null){
1640 "Static constructors can not have an explicit this or base " +
1641 "constructor invocations");
1644 if (!c.Parameters.Empty){
1646 132, c.Location, "Static constructors should not have parameters");
1649 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1652 // We let another layer check the validity of the constructor.
1653 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1656 current_container.AddConstructor (c);
1658 current_local_parameters = null;
1662 constructor_declarator
1664 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1666 oob_stack.Push (lexer.Location);
1668 current_local_parameters = (Parameters) $3;
1670 opt_constructor_initializer
1672 Location l = (Location) oob_stack.Pop ();
1673 $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $3,
1674 (ConstructorInitializer) $6, l);
1680 | SEMICOLON { $$ = null; }
1683 opt_constructor_initializer
1684 : /* empty */ { $$ = null; }
1685 | constructor_initializer
1688 constructor_initializer
1689 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1691 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1693 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1695 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1698 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1704 : /* EMPTY */ { $$ = 0; }
1705 | UNSAFE { $$ = Modifiers.UNSAFE; }
1706 | EXTERN { $$ = Modifiers.EXTERN; }
1709 destructor_declaration
1710 : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1712 if ((string) $4 != current_container.Basename){
1713 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1714 } else if (!(current_container is Class)){
1715 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1717 Location l = lexer.Location;
1720 if (!RootContext.StdLib && current_container.Name == "System.Object")
1721 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1723 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1725 if ((m & Modifiers.UNSAFE) != 0){
1726 if (!RootContext.Unsafe){
1727 Report.Error (227, l,
1728 "Unsafe code requires the -unsafe command " +
1729 "line option to be specified");
1733 Method d = new Destructor (
1734 current_class, TypeManager.system_void_expr, m, "Finalize",
1735 new Parameters (null, null, l), (Attributes) $1, l);
1737 d.Block = (ToplevelBlock) $7;
1738 current_container.AddMethod (d);
1746 EVENT type variable_declarators SEMICOLON
1748 foreach (VariableDeclaration var in (ArrayList) $5) {
1750 MemberName name = new MemberName (var.identifier);
1752 Event e = new EventField (
1753 current_class, (Expression) $4, (int) $2, false, name,
1754 var.expression_or_array_initializer, (Attributes) $1,
1757 current_container.AddEvent (e);
1763 EVENT type namespace_or_type_name
1766 implicit_value_parameter_type = (Expression) $4;
1767 lexer.EventParsing = true;
1768 oob_stack.Push (lexer.Location);
1770 event_accessor_declarations
1772 lexer.EventParsing = false;
1776 Location loc = (Location) oob_stack.Pop ();
1779 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1782 Pair pair = (Pair) $8;
1784 MemberName name = (MemberName) $5;
1786 Event e = new EventProperty (
1787 current_class, (Expression) $4, (int) $2, false, name, null,
1788 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
1791 current_container.AddEvent (e);
1792 implicit_value_parameter_type = null;
1795 | opt_attributes opt_modifiers EVENT type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
1796 MemberName mn = (MemberName) $5;
1798 if (mn.Left != null)
1799 Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
1801 Report.Error (71, lexer.Location, "Event declaration should use property syntax");
1805 event_accessor_declarations
1806 : add_accessor_declaration remove_accessor_declaration
1808 $$ = new Pair ($1, $2);
1810 | remove_accessor_declaration add_accessor_declaration
1812 $$ = new Pair ($2, $1);
1814 | add_accessor_declaration { $$ = null; }
1815 | remove_accessor_declaration { $$ = null; }
1818 Report.Error (1055, lexer.Location, "An add or remove accessor expected");
1824 add_accessor_declaration
1825 : opt_attributes ADD
1827 Parameter [] args = new Parameter [1];
1828 Parameter implicit_value_parameter = new Parameter (
1829 implicit_value_parameter_type, "value",
1830 Parameter.Modifier.NONE, null);
1832 args [0] = implicit_value_parameter;
1834 current_local_parameters = new Parameters (args, null, lexer.Location);
1835 lexer.EventParsing = false;
1839 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
1840 lexer.EventParsing = true;
1842 | opt_attributes ADD error {
1843 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1848 remove_accessor_declaration
1849 : opt_attributes REMOVE
1851 Parameter [] args = new Parameter [1];
1852 Parameter implicit_value_parameter = new Parameter (
1853 implicit_value_parameter_type, "value",
1854 Parameter.Modifier.NONE, null);
1856 args [0] = implicit_value_parameter;
1858 current_local_parameters = new Parameters (args, null, lexer.Location);
1859 lexer.EventParsing = false;
1863 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
1864 lexer.EventParsing = true;
1866 | opt_attributes REMOVE error {
1867 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1873 : opt_attributes opt_modifiers indexer_declarator
1876 IndexerDeclaration decl = (IndexerDeclaration) $3;
1878 implicit_value_parameter_type = decl.type;
1880 lexer.PropertyParsing = true;
1881 parsing_indexer = true;
1883 indexer_parameters = decl.param_list;
1884 oob_stack.Push (lexer.Location);
1886 accessor_declarations
1888 lexer.PropertyParsing = false;
1889 parsing_indexer = false;
1893 // The signature is computed from the signature of the indexer. Look
1894 // at section 3.6 on the spec
1895 Location loc = (Location) oob_stack.Pop ();
1897 IndexerDeclaration decl = (IndexerDeclaration) $3;
1898 Pair pair = (Pair) $6;
1899 Accessor get_block = (Accessor) pair.First;
1900 Accessor set_block = (Accessor) pair.Second;
1903 if (decl.interface_type != null)
1904 name = new MemberName (decl.interface_type,
1905 TypeContainer.DefaultIndexerName);
1907 name = new MemberName (TypeContainer.DefaultIndexerName);
1909 indexer = new Indexer (current_class, decl.type, name,
1910 (int) $2, false, decl.param_list, (Attributes) $1,
1911 get_block, set_block, loc);
1913 current_container.AddIndexer (indexer);
1915 current_local_parameters = null;
1916 implicit_value_parameter_type = null;
1917 indexer_parameters = null;
1922 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1924 Parameters pars = (Parameters) $4;
1925 if (pars.HasArglist) {
1926 // "__arglist is not valid in this context"
1927 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
1928 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
1929 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1932 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1934 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1936 Parameters pars = (Parameters) $6;
1938 if (pars.HasArglist) {
1939 // "__arglist is not valid in this context"
1940 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
1941 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
1942 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1944 MemberName name = (MemberName) $2;
1945 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
1957 Location enum_location = lexer.Location;
1959 MemberName full_name = MakeName (new MemberName ((string) $4));
1960 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
1961 full_name, (Attributes) $1, enum_location);
1963 foreach (VariableDeclaration ev in (ArrayList) $6) {
1964 e.AddEnumMember (ev.identifier,
1965 (Expression) ev.expression_or_array_initializer,
1966 ev.Location, ev.OptAttributes);
1969 string name = full_name.GetName ();
1970 current_container.AddEnum (e);
1971 RootContext.Tree.RecordDecl (name, e);
1977 : /* empty */ { $$ = TypeManager.system_int32_expr; }
1978 | COLON type { $$ = $2; }
1982 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1988 opt_enum_member_declarations
1989 : /* empty */ { $$ = new ArrayList (4); }
1990 | enum_member_declarations opt_comma { $$ = $1; }
1993 enum_member_declarations
1994 : enum_member_declaration
1996 ArrayList l = new ArrayList (4);
2001 | enum_member_declarations COMMA enum_member_declaration
2003 ArrayList l = (ArrayList) $1;
2011 enum_member_declaration
2012 : opt_attributes IDENTIFIER
2014 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
2016 | opt_attributes IDENTIFIER
2018 $$ = lexer.Location;
2022 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
2026 delegate_declaration
2029 DELEGATE type member_name
2030 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2033 Location l = lexer.Location;
2034 MemberName name = MakeName ((MemberName) $5);
2035 Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
2036 (int) $2, name, (Parameters) $7, (Attributes) $1, l);
2038 current_container.AddDelegate (del);
2039 RootContext.Tree.RecordDecl (name.GetName (true), del);
2043 DELEGATE VOID member_name
2044 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2047 Location l = lexer.Location;
2048 MemberName name = MakeName ((MemberName) $5);
2049 Delegate del = new Delegate (
2050 current_namespace, current_container,
2051 TypeManager.system_void_expr, (int) $2, name,
2052 (Parameters) $7, (Attributes) $1, l);
2054 current_container.AddDelegate (del);
2055 RootContext.Tree.RecordDecl (name.GetName (true), del);
2059 namespace_or_type_name
2061 | namespace_or_type_name DOT IDENTIFIER {
2062 $$ = new MemberName ((MemberName) $1, (string) $3);
2068 $$ = new MemberName ((string) $1);
2073 * Before you think of adding a return_type, notice that we have been
2074 * using two rules in the places where it matters (one rule using type
2075 * and another identical one that uses VOID as the return type). This
2076 * gets rid of a shift/reduce couple
2079 : namespace_or_type_name
2081 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2093 // Note that here only unmanaged types are allowed but we
2094 // can't perform checks during this phase - we do it during
2095 // semantic analysis.
2097 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2101 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2107 | non_expression_type rank_specifier
2109 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2111 | non_expression_type STAR
2113 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2115 | expression rank_specifiers
2117 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2121 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2125 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2126 // through this different path
2128 | multiplicative_expression STAR
2130 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2137 ArrayList types = new ArrayList (4);
2142 | type_list COMMA type
2144 ArrayList types = (ArrayList) $1;
2152 * replaces all the productions for isolating the various
2153 * simple types, but we need this to reuse it easily in local_variable_type
2156 : OBJECT { $$ = TypeManager.system_object_expr; }
2157 | STRING { $$ = TypeManager.system_string_expr; }
2158 | BOOL { $$ = TypeManager.system_boolean_expr; }
2159 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2160 | FLOAT { $$ = TypeManager.system_single_expr; }
2161 | DOUBLE { $$ = TypeManager.system_double_expr; }
2166 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2167 | BYTE { $$ = TypeManager.system_byte_expr; }
2168 | SHORT { $$ = TypeManager.system_int16_expr; }
2169 | USHORT { $$ = TypeManager.system_uint16_expr; }
2170 | INT { $$ = TypeManager.system_int32_expr; }
2171 | UINT { $$ = TypeManager.system_uint32_expr; }
2172 | LONG { $$ = TypeManager.system_int64_expr; }
2173 | ULONG { $$ = TypeManager.system_uint64_expr; }
2174 | CHAR { $$ = TypeManager.system_char_expr; }
2175 | VOID { $$ = TypeManager.system_void_expr; }
2179 : type rank_specifiers
2181 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2186 // Expressions, section 7.5
2196 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2198 | parenthesized_expression
2200 | invocation_expression
2204 | post_increment_expression
2205 | post_decrement_expression
2209 | checked_expression
2210 | unchecked_expression
2211 | pointer_member_access
2212 | anonymous_method_expression
2219 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2220 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2221 | NULL { $$ = NullLiteral.Null; }
2225 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2226 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2227 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2232 object v = lexer.Value;
2238 $$ = IntLiteral.Zero;
2240 $$ = IntLiteral.One;
2242 $$ = new IntLiteral (i);
2243 } else if (v is uint)
2244 $$ = new UIntLiteral ((UInt32) v);
2246 $$ = new LongLiteral ((Int64) v);
2247 else if (v is ulong)
2248 $$ = new ULongLiteral ((UInt64) v);
2250 Console.WriteLine ("OOPS. Unexpected result from scanner");
2255 : TRUE { $$ = new BoolLiteral (true); }
2256 | FALSE { $$ = new BoolLiteral (false); }
2259 parenthesized_expression_0
2260 : OPEN_PARENS expression CLOSE_PARENS
2263 lexer.Deambiguate_CloseParens ();
2264 // After this, the next token returned is one of
2265 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2266 // or CLOSE_PARENS_MINUS.
2270 parenthesized_expression
2271 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2275 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2277 // If a parenthesized expression is followed by a minus, we need to wrap
2278 // the expression inside a ParenthesizedExpression for the CS0075 check
2279 // in Binary.DoResolve().
2280 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2285 : primary_expression DOT IDENTIFIER
2287 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2289 | predefined_type DOT IDENTIFIER
2291 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2299 invocation_expression
2300 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2303 Location l = lexer.Location;
2304 Report.Error (1, l, "Parse error");
2306 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2308 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2310 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2312 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2314 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2319 : /* empty */ { $$ = null; }
2326 ArrayList list = new ArrayList (4);
2330 | argument_list COMMA argument
2332 ArrayList list = (ArrayList) $1;
2336 | argument_list error {
2337 CheckToken (1026, yyToken, ", or ) expected");
2344 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2346 | REF variable_reference
2348 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2350 | OUT variable_reference
2352 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2354 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
2356 ArrayList list = (ArrayList) $3;
2357 Argument[] args = new Argument [list.Count];
2358 list.CopyTo (args, 0);
2360 Expression expr = new Arglist (args, lexer.Location);
2361 $$ = new Argument (expr, Argument.AType.Expression);
2365 $$ = new Argument (new ArglistAccess (lexer.Location), Argument.AType.ArgList);
2370 : expression { note ("section 5.4"); $$ = $1; }
2374 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2376 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2378 | primary_expression rank_specifiers
2380 // So the super-trick is that primary_expression
2381 // can only be either a SimpleName or a MemberAccess.
2382 // The MemberAccess case arises when you have a fully qualified type-name like :
2384 // SimpleName is when you have
2387 Expression expr = (Expression) $1;
2388 if (expr is ComposedCast){
2389 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2390 } else if (!(expr is SimpleName || expr is MemberAccess)){
2391 Error_ExpectingTypeName (lexer.Location, expr);
2392 $$ = TypeManager.system_object_expr;
2395 // So we extract the string corresponding to the SimpleName
2398 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2406 ArrayList list = new ArrayList (4);
2410 | expression_list COMMA expression
2412 ArrayList list = (ArrayList) $1;
2421 $$ = new This (current_block, lexer.Location);
2426 : BASE DOT IDENTIFIER
2428 $$ = new BaseAccess ((string) $3, lexer.Location);
2430 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2432 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2435 Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
2440 post_increment_expression
2441 : primary_expression OP_INC
2443 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2444 (Expression) $1, lexer.Location);
2448 post_decrement_expression
2449 : primary_expression OP_DEC
2451 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2452 (Expression) $1, lexer.Location);
2457 : object_or_delegate_creation_expression
2458 | array_creation_expression
2461 object_or_delegate_creation_expression
2462 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2464 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2468 array_creation_expression
2469 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2471 opt_array_initializer
2473 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2475 | NEW type rank_specifiers array_initializer
2477 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2481 Report.Error (1031, lexer.Location, "Type expected");
2486 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2502 : rank_specifier opt_rank_specifier
2504 $$ = (string) $2 + (string) $1;
2509 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2511 $$ = "[" + (string) $2 + "]";
2531 | dim_separators COMMA
2533 $$ = (string) $1 + ",";
2537 opt_array_initializer
2549 : OPEN_BRACE CLOSE_BRACE
2551 ArrayList list = new ArrayList (4);
2554 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2556 $$ = (ArrayList) $2;
2560 variable_initializer_list
2561 : variable_initializer
2563 ArrayList list = new ArrayList (4);
2567 | variable_initializer_list COMMA variable_initializer
2569 ArrayList list = (ArrayList) $1;
2576 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2578 $$ = new TypeOfVoid (lexer.Location);
2580 | TYPEOF OPEN_PARENS type CLOSE_PARENS
2582 $$ = new TypeOf ((Expression) $3, lexer.Location);
2587 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2588 $$ = new SizeOf ((Expression) $3, lexer.Location);
2593 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2595 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2599 unchecked_expression
2600 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2602 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2606 pointer_member_access
2607 : primary_expression OP_PTR IDENTIFIER
2611 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2612 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2616 anonymous_method_expression
2617 : DELEGATE opt_anonymous_method_signature {
2618 oob_stack.Push (current_local_parameters);
2619 current_local_parameters = (Parameters)$2;
2621 // Force the next block to be created as a ToplevelBlock
2622 oob_stack.Push (current_block);
2623 oob_stack.Push (top_current_block);
2624 oob_stack.Push (lexer.Location);
2625 current_block = null;
2627 Location loc = (Location) oob_stack.Pop ();
2628 top_current_block = (Block) oob_stack.Pop ();
2629 current_block = (Block) oob_stack.Pop ();
2630 if (RootContext.Version == LanguageVersion.ISO_1){
2631 Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
2634 ToplevelBlock anon_block = (ToplevelBlock) $4;
2636 anon_block.Parent = current_block;
2637 $$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block,
2640 current_local_parameters = (Parameters) oob_stack.Pop ();
2644 opt_anonymous_method_signature
2645 : /* empty */ { $$ = null; }
2646 | anonymous_method_signature
2649 anonymous_method_signature
2650 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2653 $$ = Parameters.EmptyReadOnlyParameters;
2655 ArrayList par_list = (ArrayList) $2;
2656 Parameter [] pars = new Parameter [par_list.Count];
2657 par_list.CopyTo (pars);
2658 $$ = new Parameters (pars, null, lexer.Location);
2663 opt_anonymous_method_parameter_list
2664 : /* empty */ { $$ = null; }
2665 | anonymous_method_parameter_list { $$ = $1; }
2668 anonymous_method_parameter_list
2669 : anonymous_method_parameter
2671 ArrayList a = new ArrayList (4);
2675 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2677 ArrayList a = (ArrayList) $1;
2683 anonymous_method_parameter
2684 : opt_parameter_modifier type IDENTIFIER {
2685 $$ = new Parameter ((Expression) $2, (string) $3, (Parameter.Modifier) $1, null);
2687 | PARAMS type IDENTIFIER {
2688 Report.Error (-221, lexer.Location, "params modifier not allowed in anonymous method declaration");
2694 : primary_expression
2695 | BANG prefixed_unary_expression
2697 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2699 | TILDE prefixed_unary_expression
2701 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2707 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2709 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2711 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2713 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2719 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2721 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2726 // The idea to split this out is from Rhys' grammar
2727 // to solve the problem with casts.
2729 prefixed_unary_expression
2731 | PLUS prefixed_unary_expression
2733 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2735 | MINUS prefixed_unary_expression
2737 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2739 | OP_INC prefixed_unary_expression
2741 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2742 (Expression) $2, lexer.Location);
2744 | OP_DEC prefixed_unary_expression
2746 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2747 (Expression) $2, lexer.Location);
2749 | STAR prefixed_unary_expression
2751 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2753 | BITWISE_AND prefixed_unary_expression
2755 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2759 pre_increment_expression
2760 : OP_INC prefixed_unary_expression
2762 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2763 (Expression) $2, lexer.Location);
2767 pre_decrement_expression
2768 : OP_DEC prefixed_unary_expression
2770 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2771 (Expression) $2, lexer.Location);
2775 multiplicative_expression
2776 : prefixed_unary_expression
2777 | multiplicative_expression STAR prefixed_unary_expression
2779 $$ = new Binary (Binary.Operator.Multiply,
2780 (Expression) $1, (Expression) $3, lexer.Location);
2782 | multiplicative_expression DIV prefixed_unary_expression
2784 $$ = new Binary (Binary.Operator.Division,
2785 (Expression) $1, (Expression) $3, lexer.Location);
2787 | multiplicative_expression PERCENT prefixed_unary_expression
2789 $$ = new Binary (Binary.Operator.Modulus,
2790 (Expression) $1, (Expression) $3, lexer.Location);
2795 : multiplicative_expression
2796 | additive_expression PLUS multiplicative_expression
2798 $$ = new Binary (Binary.Operator.Addition,
2799 (Expression) $1, (Expression) $3, lexer.Location);
2801 | additive_expression MINUS multiplicative_expression
2803 $$ = new Binary (Binary.Operator.Subtraction,
2804 (Expression) $1, (Expression) $3, lexer.Location);
2809 : additive_expression
2810 | shift_expression OP_SHIFT_LEFT additive_expression
2812 $$ = new Binary (Binary.Operator.LeftShift,
2813 (Expression) $1, (Expression) $3, lexer.Location);
2815 | shift_expression OP_SHIFT_RIGHT additive_expression
2817 $$ = new Binary (Binary.Operator.RightShift,
2818 (Expression) $1, (Expression) $3, lexer.Location);
2822 relational_expression
2824 | relational_expression OP_LT shift_expression
2826 $$ = new Binary (Binary.Operator.LessThan,
2827 (Expression) $1, (Expression) $3, lexer.Location);
2829 | relational_expression OP_GT shift_expression
2831 $$ = new Binary (Binary.Operator.GreaterThan,
2832 (Expression) $1, (Expression) $3, lexer.Location);
2834 | relational_expression OP_LE shift_expression
2836 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2837 (Expression) $1, (Expression) $3, lexer.Location);
2839 | relational_expression OP_GE shift_expression
2841 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2842 (Expression) $1, (Expression) $3, lexer.Location);
2844 | relational_expression IS type
2846 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2848 | relational_expression AS type
2850 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2855 : relational_expression
2856 | equality_expression OP_EQ relational_expression
2858 $$ = new Binary (Binary.Operator.Equality,
2859 (Expression) $1, (Expression) $3, lexer.Location);
2861 | equality_expression OP_NE relational_expression
2863 $$ = new Binary (Binary.Operator.Inequality,
2864 (Expression) $1, (Expression) $3, lexer.Location);
2869 : equality_expression
2870 | and_expression BITWISE_AND equality_expression
2872 $$ = new Binary (Binary.Operator.BitwiseAnd,
2873 (Expression) $1, (Expression) $3, lexer.Location);
2877 exclusive_or_expression
2879 | exclusive_or_expression CARRET and_expression
2881 $$ = new Binary (Binary.Operator.ExclusiveOr,
2882 (Expression) $1, (Expression) $3, lexer.Location);
2886 inclusive_or_expression
2887 : exclusive_or_expression
2888 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2890 $$ = new Binary (Binary.Operator.BitwiseOr,
2891 (Expression) $1, (Expression) $3, lexer.Location);
2895 conditional_and_expression
2896 : inclusive_or_expression
2897 | conditional_and_expression OP_AND inclusive_or_expression
2899 $$ = new Binary (Binary.Operator.LogicalAnd,
2900 (Expression) $1, (Expression) $3, lexer.Location);
2904 conditional_or_expression
2905 : conditional_and_expression
2906 | conditional_or_expression OP_OR conditional_and_expression
2908 $$ = new Binary (Binary.Operator.LogicalOr,
2909 (Expression) $1, (Expression) $3, lexer.Location);
2913 conditional_expression
2914 : conditional_or_expression
2915 | conditional_or_expression INTERR expression COLON expression
2917 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2921 assignment_expression
2922 : prefixed_unary_expression ASSIGN expression
2924 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2926 | prefixed_unary_expression OP_MULT_ASSIGN expression
2928 Location l = lexer.Location;
2930 $$ = new CompoundAssign (
2931 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
2933 | prefixed_unary_expression OP_DIV_ASSIGN expression
2935 Location l = lexer.Location;
2937 $$ = new CompoundAssign (
2938 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
2940 | prefixed_unary_expression OP_MOD_ASSIGN expression
2942 Location l = lexer.Location;
2944 $$ = new CompoundAssign (
2945 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
2947 | prefixed_unary_expression OP_ADD_ASSIGN expression
2949 Location l = lexer.Location;
2951 $$ = new CompoundAssign (
2952 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
2954 | prefixed_unary_expression OP_SUB_ASSIGN expression
2956 Location l = lexer.Location;
2958 $$ = new CompoundAssign (
2959 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
2961 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2963 Location l = lexer.Location;
2965 $$ = new CompoundAssign (
2966 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
2968 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2970 Location l = lexer.Location;
2972 $$ = new CompoundAssign (
2973 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
2975 | prefixed_unary_expression OP_AND_ASSIGN expression
2977 Location l = lexer.Location;
2979 $$ = new CompoundAssign (
2980 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
2982 | prefixed_unary_expression OP_OR_ASSIGN expression
2984 Location l = lexer.Location;
2986 $$ = new CompoundAssign (
2987 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
2989 | prefixed_unary_expression OP_XOR_ASSIGN expression
2991 Location l = lexer.Location;
2993 $$ = new CompoundAssign (
2994 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
2999 : conditional_expression
3000 | assignment_expression
3020 MemberName name = MakeName ((MemberName) $5);
3021 bool partial = (bool) $3;
3022 int mod_flags = (int) $2;
3025 ClassPart part = PartialContainer.CreatePart (
3026 current_namespace, current_container, name, mod_flags,
3027 (Attributes) $1, Kind.Class, lexer.Location);
3029 current_container = part.PartialContainer;
3030 current_class = part;
3032 if ((mod_flags & Modifiers.STATIC) != 0) {
3033 current_class = new StaticClass (
3034 current_namespace, current_container, name,
3035 mod_flags, (Attributes) $1, lexer.Location);
3037 current_class = new Class (
3038 current_namespace, current_container, name,
3039 mod_flags, (Attributes) $1, lexer.Location);
3042 current_container = current_class;
3043 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
3049 if (current_class.Name == "System.Object") {
3050 Report.Error (537, current_class.Location,
3051 "The class System.Object cannot have a base " +
3052 "class or implement an interface.");
3054 current_class.Bases = (ArrayList) $7;
3057 current_class.Register ();
3064 current_container = current_container.Parent;
3065 current_class = current_container;
3071 { $$ = (bool) false; }
3073 { $$ = (bool) true; }
3077 : /* empty */ { $$ = (int) 0; }
3083 | modifiers modifier
3088 if ((m1 & m2) != 0) {
3089 Location l = lexer.Location;
3090 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3092 $$ = (int) (m1 | m2);
3097 : NEW { $$ = Modifiers.NEW; }
3098 | PUBLIC { $$ = Modifiers.PUBLIC; }
3099 | PROTECTED { $$ = Modifiers.PROTECTED; }
3100 | INTERNAL { $$ = Modifiers.INTERNAL; }
3101 | PRIVATE { $$ = Modifiers.PRIVATE; }
3102 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3103 | SEALED { $$ = Modifiers.SEALED; }
3104 | STATIC { $$ = Modifiers.STATIC; }
3105 | READONLY { $$ = Modifiers.READONLY; }
3106 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3107 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3108 | EXTERN { $$ = Modifiers.EXTERN; }
3109 | VOLATILE { $$ = Modifiers.VOLATILE; }
3110 | UNSAFE { $$ = Modifiers.UNSAFE; }
3114 : /* empty */ { $$ = null; }
3115 | class_base { $$ = $1; }
3119 : COLON type_list { $$ = $2; }
3127 // A block is "contained" on the following places:
3129 // property_declaration as part of the accessor body (get/set)
3130 // operator_declaration
3131 // constructor_declaration
3132 // destructor_declaration
3133 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3138 if (current_block == null){
3139 current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, lexer.Location);
3140 top_current_block = current_block;
3142 current_block = new Block (current_block, current_local_parameters,
3143 lexer.Location, Location.Null);
3146 opt_statement_list CLOSE_BRACE
3148 while (current_block.Implicit)
3149 current_block = current_block.Parent;
3151 current_block.SetEndLocation (lexer.Location);
3152 current_block = current_block.Parent;
3153 if (current_block == null)
3154 top_current_block = null;
3165 | statement_list statement
3169 : declaration_statement
3171 if ($1 != null && (Block) $1 != current_block){
3172 current_block.AddStatement ((Statement) $1);
3173 current_block = (Block) $1;
3176 | valid_declaration_statement
3178 current_block.AddStatement ((Statement) $1);
3183 valid_declaration_statement
3186 | expression_statement
3187 | selection_statement
3188 | iteration_statement
3192 | unchecked_statement
3200 : valid_declaration_statement
3201 | declaration_statement
3203 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
3208 Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
3216 $$ = EmptyStatement.Value;
3223 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3225 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3226 current_block.AddStatement (labeled);
3231 declaration_statement
3232 : local_variable_declaration SEMICOLON
3235 DictionaryEntry de = (DictionaryEntry) $1;
3237 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3241 | local_constant_declaration SEMICOLON
3244 DictionaryEntry de = (DictionaryEntry) $1;
3246 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3252 * The following is from Rhys' grammar:
3253 * > Types in local variable declarations must be recognized as
3254 * > expressions to prevent reduce/reduce errors in the grammar.
3255 * > The expressions are converted into types during semantic analysis.
3258 : primary_expression opt_rank_specifier
3260 // FIXME: Do something smart here regarding the composition of the type.
3262 // Ok, the above "primary_expression" is there to get rid of
3263 // both reduce/reduce and shift/reduces in the grammar, it should
3264 // really just be "type_name". If you use type_name, a reduce/reduce
3265 // creeps up. If you use namespace_or_type_name (which is all we need
3266 // really) two shift/reduces appear.
3269 // So the super-trick is that primary_expression
3270 // can only be either a SimpleName or a MemberAccess.
3271 // The MemberAccess case arises when you have a fully qualified type-name like :
3273 // SimpleName is when you have
3276 Expression expr = (Expression) $1;
3277 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast)) {
3278 Error_ExpectingTypeName (lexer.Location, expr);
3282 // So we extract the string corresponding to the SimpleName
3286 if ((string) $2 == "")
3289 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3292 | builtin_types opt_rank_specifier
3294 if ((string) $2 == "")
3297 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3301 local_variable_pointer_type
3302 : primary_expression STAR
3304 Expression expr = (Expression) $1;
3305 Location l = lexer.Location;
3307 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast)) {
3308 Error_ExpectingTypeName (l, expr);
3312 $$ = new ComposedCast ((Expression) $1, "*", l);
3314 | builtin_types STAR
3316 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3320 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3322 | local_variable_pointer_type STAR
3324 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3328 local_variable_declaration
3329 : local_variable_type variable_declarators
3332 $$ = new DictionaryEntry ($1, $2);
3336 | local_variable_pointer_type opt_rank_specifier variable_declarators
3341 if ((string) $2 == "")
3342 t = (Expression) $1;
3344 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3345 $$ = new DictionaryEntry (t, $3);
3351 local_constant_declaration
3352 : CONST local_variable_type constant_declarators
3355 $$ = new DictionaryEntry ($2, $3);
3361 expression_statement
3362 : statement_expression SEMICOLON
3369 // We have to do the wrapping here and not in the case above,
3370 // because statement_expression is used for example in for_statement
3372 statement_expression
3373 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3374 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3375 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3376 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3377 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3378 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3379 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3381 Report.Error (1002, lexer.Location, "Expecting `;'");
3386 object_creation_expression
3387 : object_or_delegate_creation_expression
3388 { note ("complain if this is a delegate maybe?"); }
3397 : if_statement_open if_statement_rest
3406 oob_stack.Push (lexer.Location);
3411 : boolean_expression CLOSE_PARENS
3414 Location l = (Location) oob_stack.Pop ();
3416 $$ = new If ((Expression) $1, (Statement) $3, l);
3418 if (RootContext.WarningLevel >= 3){
3419 if ($3 == EmptyStatement.Value)
3420 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3424 | boolean_expression CLOSE_PARENS
3425 embedded_statement ELSE embedded_statement
3427 Location l = (Location) oob_stack.Pop ();
3429 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3434 : SWITCH OPEN_PARENS
3436 oob_stack.Push (lexer.Location);
3437 switch_stack.Push (current_block);
3439 expression CLOSE_PARENS
3442 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3443 current_block = (Block) switch_stack.Pop ();
3459 Report.Error (1522, lexer.Location, "Empty switch block");
3467 ArrayList sections = new ArrayList (4);
3472 | switch_sections switch_section
3474 ArrayList sections = (ArrayList) $1;
3484 current_block = current_block.CreateSwitchBlock (lexer.Location);
3488 Block topmost = current_block;
3490 while (topmost.Implicit)
3491 topmost = topmost.Parent;
3492 $$ = new SwitchSection ((ArrayList) $1, topmost);
3499 ArrayList labels = new ArrayList (4);
3504 | switch_labels switch_label
3506 ArrayList labels = (ArrayList) ($1);
3514 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3515 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3518 1523, lexer.Location,
3519 "The keyword case or default must precede code in switch block");
3533 oob_stack.Push (lexer.Location);
3535 boolean_expression CLOSE_PARENS embedded_statement
3537 Location l = (Location) oob_stack.Pop ();
3538 $$ = new While ((Expression) $4, (Statement) $6, l);
3540 if (RootContext.WarningLevel >= 3){
3541 if ($6 == EmptyStatement.Value)
3542 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3548 : DO embedded_statement
3550 oob_stack.Push (lexer.Location);
3552 boolean_expression CLOSE_PARENS SEMICOLON
3554 Location l = (Location) oob_stack.Pop ();
3556 $$ = new Do ((Statement) $2, (Expression) $6, l);
3562 opt_for_initializer SEMICOLON
3564 Block assign_block = new Block (current_block);
3565 current_block = assign_block;
3567 if ($3 is DictionaryEntry){
3568 DictionaryEntry de = (DictionaryEntry) $3;
3570 Expression type = (Expression) de.Key;
3571 ArrayList var_declarators = (ArrayList) de.Value;
3573 foreach (VariableDeclaration decl in var_declarators){
3577 vi = current_block.AddVariable (
3578 type, decl.identifier, current_local_parameters, decl.Location);
3582 Location l = lexer.Location;
3584 if (decl.expression_or_array_initializer is Expression){
3585 expr = (Expression) decl.expression_or_array_initializer;
3586 } else if (decl.expression_or_array_initializer == null) {
3589 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3590 expr = new ArrayCreation (type, "", init, decl.Location);
3593 LocalVariableReference var;
3594 var = new LocalVariableReference (assign_block, decl.identifier, l);
3597 Assign a = new Assign (var, expr, decl.Location);
3599 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3605 oob_stack.Push (lexer.Location);
3607 opt_for_condition SEMICOLON
3608 opt_for_iterator CLOSE_PARENS
3611 Location l = (Location) oob_stack.Pop ();
3613 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3615 if (RootContext.WarningLevel >= 3){
3616 if ($10 == EmptyStatement.Value)
3617 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3620 current_block.AddStatement (f);
3621 while (current_block.Implicit)
3622 current_block = current_block.Parent;
3624 current_block = current_block.Parent;
3629 : /* empty */ { $$ = EmptyStatement.Value; }
3634 : local_variable_declaration
3635 | statement_expression_list
3639 : /* empty */ { $$ = null; }
3640 | boolean_expression
3644 : /* empty */ { $$ = EmptyStatement.Value; }
3649 : statement_expression_list
3652 statement_expression_list
3653 : statement_expression
3655 // CHANGE: was `null'
3656 Block b = new Block (current_block, Block.Flags.Implicit);
3658 b.AddStatement ((Statement) $1);
3661 | statement_expression_list COMMA statement_expression
3663 Block b = (Block) $1;
3665 b.AddStatement ((Statement) $3);
3671 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
3673 Report.Error (230, lexer.Location, "Type and identifier are both required in a foreach statement");
3676 | FOREACH OPEN_PARENS type IDENTIFIER IN
3678 oob_stack.Push (lexer.Location);
3680 expression CLOSE_PARENS
3682 oob_stack.Push (current_block);
3684 Block foreach_block = new Block (current_block);
3685 LocalVariableReference v = null;
3686 Location l = lexer.Location;
3689 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3693 // Get a writable reference to this read-only variable.
3694 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3696 current_block = foreach_block;
3699 oob_stack.Push (current_block);
3703 Block foreach_block = (Block) oob_stack.Pop ();
3704 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3705 Block prev_block = (Block) oob_stack.Pop ();
3706 Location l = (Location) oob_stack.Pop ();
3708 current_block = prev_block;
3711 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3712 foreach_block.AddStatement (f);
3721 | continue_statement
3731 $$ = new Break (lexer.Location);
3736 : CONTINUE SEMICOLON
3738 $$ = new Continue (lexer.Location);
3743 : GOTO IDENTIFIER SEMICOLON
3745 $$ = new Goto (current_block, (string) $2, lexer.Location);
3747 | GOTO CASE constant_expression SEMICOLON
3749 $$ = new GotoCase ((Expression) $3, lexer.Location);
3751 | GOTO DEFAULT SEMICOLON
3753 $$ = new GotoDefault (lexer.Location);
3758 : RETURN opt_expression SEMICOLON
3760 $$ = new Return ((Expression) $2, lexer.Location);
3765 : THROW opt_expression SEMICOLON
3767 $$ = new Throw ((Expression) $2, lexer.Location);
3772 : IDENTIFIER RETURN expression SEMICOLON
3774 string s = (string) $1;
3776 Report.Error (1003, lexer.Location, "; expected");
3779 if (RootContext.Version == LanguageVersion.ISO_1){
3780 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
3783 if (iterator_container == null){
3784 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3787 iterator_container.SetYields ();
3788 $$ = new Yield ((Expression) $3, lexer.Location);
3791 | IDENTIFIER BREAK SEMICOLON
3793 string s = (string) $1;
3795 Report.Error (1003, lexer.Location, "; expected");
3798 if (RootContext.Version == LanguageVersion.ISO_1){
3799 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
3802 if (iterator_container == null){
3803 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3806 iterator_container.SetYields ();
3807 $$ = new YieldBreak (lexer.Location);
3818 : TRY block catch_clauses
3822 ArrayList c = (ArrayList)$3;
3823 for (int i = 0; i < c.Count; ++i) {
3824 Catch cc = (Catch) c [i];
3826 if (i != c.Count - 1)
3827 Report.Error (1017, cc.loc, "Empty catch block must be the last in a series of catch blocks");
3834 // Now s contains the list of specific catch clauses
3835 // and g contains the general one.
3837 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
3839 | TRY block opt_catch_clauses FINALLY block
3842 ArrayList s = new ArrayList (4);
3843 ArrayList catch_list = (ArrayList) $3;
3845 if (catch_list != null){
3846 foreach (Catch cc in catch_list) {
3854 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
3858 Report.Error (1524, lexer.Location, "Expected catch or finally");
3863 : /* empty */ { $$ = null; }
3870 ArrayList l = new ArrayList (4);
3875 | catch_clauses catch_clause
3877 ArrayList l = (ArrayList) $1;
3885 : /* empty */ { $$ = null; }
3890 : CATCH opt_catch_args
3892 Expression type = null;
3896 DictionaryEntry cc = (DictionaryEntry) $2;
3897 type = (Expression) cc.Key;
3898 id = (string) cc.Value;
3901 ArrayList one = new ArrayList (4);
3902 Location loc = lexer.Location;
3904 one.Add (new VariableDeclaration (id, null, loc));
3907 current_block = new Block (current_block);
3908 Block b = declare_local_variables (type, one, loc);
3913 Expression type = null;
3917 DictionaryEntry cc = (DictionaryEntry) $2;
3918 type = (Expression) cc.Key;
3919 id = (string) cc.Value;
3923 // FIXME: I can change this for an assignment.
3925 while (current_block != (Block) $1)
3926 current_block = current_block.Parent;
3931 $$ = new Catch (type, id , (Block) $4, ((Block) $4).loc);
3936 : /* empty */ { $$ = null; }
3941 : OPEN_PARENS type opt_identifier CLOSE_PARENS
3943 $$ = new DictionaryEntry ($2, $3);
3950 $$ = new Checked ((Block) $2);
3957 $$ = new Unchecked ((Block) $2);
3964 if (!RootContext.Unsafe){
3965 Report.Error (227, lexer.Location,
3966 "Unsafe code can only be used if --unsafe is used");
3969 $$ = new Unsafe ((Block) $3);
3975 type fixed_pointer_declarators
3978 ArrayList list = (ArrayList) $4;
3979 Expression type = (Expression) $3;
3980 Location l = lexer.Location;
3981 int top = list.Count;
3983 Block assign_block = new Block (current_block);
3984 current_block = assign_block;
3986 for (int i = 0; i < top; i++){
3987 Pair p = (Pair) list [i];
3990 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4004 Location l = (Location) oob_stack.Pop ();
4006 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4008 if (RootContext.WarningLevel >= 3){
4009 if ($7 == EmptyStatement.Value)
4010 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
4013 current_block.AddStatement (f);
4014 while (current_block.Implicit)
4015 current_block = current_block.Parent;
4017 current_block = current_block.Parent;
4021 fixed_pointer_declarators
4022 : fixed_pointer_declarator {
4023 ArrayList declarators = new ArrayList (4);
4025 declarators.Add ($1);
4028 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4030 ArrayList declarators = (ArrayList) $1;
4032 declarators.Add ($3);
4037 fixed_pointer_declarator
4038 : IDENTIFIER ASSIGN expression
4040 $$ = new Pair ($1, $3);
4044 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
4050 : LOCK OPEN_PARENS expression CLOSE_PARENS
4056 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4061 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4063 Block assign_block = new Block (current_block);
4064 current_block = assign_block;
4066 oob_stack.Push (lexer.Location);
4068 if ($3 is DictionaryEntry){
4069 DictionaryEntry de = (DictionaryEntry) $3;
4070 Location l = lexer.Location;
4072 Expression type = (Expression) de.Key;
4073 ArrayList var_declarators = (ArrayList) de.Value;
4075 ArrayList vars = new ArrayList (4);
4077 foreach (VariableDeclaration decl in var_declarators){
4079 LocalInfo vi = current_block.AddVariable (
4080 type, decl.identifier,
4081 current_local_parameters, decl.Location);
4087 if (decl.expression_or_array_initializer is Expression){
4088 expr = (Expression) decl.expression_or_array_initializer;
4090 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4092 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
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, int get_mod, int set_mod, Location get_loc, Location set_loc)
4165 Report.Error (275, get_loc, "Accessibility modifiers can not be used on accessors in interfaces");
4167 Report.Error (275, set_loc, "Accessibility modifiers can not be used on accessors in interfaces");
4170 Get = new Accessor (null, 0, get_attrs, get_loc);
4172 Set = new Accessor (null, 0, set_attrs, set_loc);
4179 // A class used to hold info about an indexer declarator
4181 public class IndexerDeclaration {
4182 public Expression type;
4183 public MemberName interface_type;
4184 public Parameters param_list;
4186 public IndexerDeclaration (Expression type, MemberName interface_type,
4187 Parameters param_list)
4190 this.interface_type = interface_type;
4191 this.param_list = param_list;
4196 // We use this when we do not have an object in advance that is an IIteratorContainer
4198 public class SimpleIteratorContainer : IIteratorContainer {
4201 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4206 public static SimpleIteratorContainer GetSimple () {
4207 Simple.Yields = false;
4211 public void SetYields () { Yields = true; }
4215 // A class used to hold info about an operator declarator
4217 public class OperatorDeclaration {
4218 public Operator.OpType optype;
4219 public Expression ret_type, arg1type, arg2type;
4220 public string arg1name, arg2name;
4221 public Location location;
4223 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4224 Expression arg1type, string arg1name,
4225 Expression arg2type, string arg2name, Location location)
4228 this.ret_type = ret_type;
4229 this.arg1type = arg1type;
4230 this.arg1name = arg1name;
4231 this.arg2type = arg2type;
4232 this.arg2name = arg2name;
4233 this.location = location;
4238 void Error_ExpectingTypeName (Location l, Expression expr)
4240 if (expr is Invocation){
4241 Report.Error (1002, l, "; expected");
4243 Report.Error (-1, l, "Invalid Type definition");
4248 // Given the @class_name name, it creates a fully qualified name
4249 // based on the containing declaration space
4252 MakeName (MemberName class_name)
4254 string ns = current_namespace.FullName;
4256 if (current_container.Name == ""){
4258 return new MemberName (new MemberName (ns), class_name);
4262 return new MemberName (current_container.MemberName, class_name);
4266 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4268 Block implicit_block;
4269 ArrayList inits = null;
4272 // We use the `Used' property to check whether statements
4273 // have been added to the current block. If so, we need
4274 // to create another block to contain the new declaration
4275 // otherwise, as an optimization, we use the same block to
4276 // add the declaration.
4278 // FIXME: A further optimization is to check if the statements
4279 // that were added were added as part of the initialization
4280 // below. In which case, no other statements have been executed
4281 // and we might be able to reduce the number of blocks for
4282 // situations like this:
4284 // int j = 1; int k = j + 1;
4286 if (current_block.Used)
4287 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4289 implicit_block = current_block;
4291 foreach (VariableDeclaration decl in variable_declarators){
4293 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4294 if (decl.expression_or_array_initializer != null){
4296 inits = new ArrayList (4);
4303 return implicit_block;
4305 foreach (VariableDeclaration decl in inits){
4309 if (decl.expression_or_array_initializer is Expression){
4310 expr = (Expression) decl.expression_or_array_initializer;
4313 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4315 expr = new ArrayCreation (type, "", init, decl.Location);
4318 LocalVariableReference var;
4319 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4321 assign = new Assign (var, expr, decl.Location);
4323 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4326 return implicit_block;
4329 Block declare_local_constants (Expression type, ArrayList declarators)
4331 Block implicit_block;
4333 if (current_block.Used)
4334 implicit_block = new Block (current_block, Block.Flags.Implicit);
4336 implicit_block = current_block;
4338 foreach (VariableDeclaration decl in declarators){
4339 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4340 current_local_parameters, decl.Location);
4343 return implicit_block;
4346 void CheckAttributeTarget (string a)
4350 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4354 Location l = lexer.Location;
4355 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4361 void CheckUnaryOperator (Operator.OpType op)
4365 case Operator.OpType.LogicalNot:
4366 case Operator.OpType.OnesComplement:
4367 case Operator.OpType.Increment:
4368 case Operator.OpType.Decrement:
4369 case Operator.OpType.True:
4370 case Operator.OpType.False:
4371 case Operator.OpType.Addition:
4372 case Operator.OpType.Subtraction:
4377 Location l = lexer.Location;
4378 Report.Error (1019, l, "Overloadable unary operator expected");
4384 void CheckBinaryOperator (Operator.OpType op)
4388 case Operator.OpType.Addition:
4389 case Operator.OpType.Subtraction:
4390 case Operator.OpType.Multiply:
4391 case Operator.OpType.Division:
4392 case Operator.OpType.Modulus:
4393 case Operator.OpType.BitwiseAnd:
4394 case Operator.OpType.BitwiseOr:
4395 case Operator.OpType.ExclusiveOr:
4396 case Operator.OpType.LeftShift:
4397 case Operator.OpType.RightShift:
4398 case Operator.OpType.Equality:
4399 case Operator.OpType.Inequality:
4400 case Operator.OpType.GreaterThan:
4401 case Operator.OpType.LessThan:
4402 case Operator.OpType.GreaterThanOrEqual:
4403 case Operator.OpType.LessThanOrEqual:
4407 Location l = lexer.Location;
4408 Report.Error (1020, l, "Overloadable binary operator expected");
4414 void syntax_error (Location l, string msg)
4416 Report.Error (1003, l, "Syntax error, " + msg);
4419 void output (string s)
4421 Console.WriteLine (s);
4424 void note (string s)
4426 // Used to put annotations
4431 public Tokenizer Lexer {
4437 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4439 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4440 this.name = file.Name;
4442 current_container = RootContext.Tree.Types;
4443 current_container.NamespaceEntry = current_namespace;
4444 oob_stack = new Stack ();
4445 switch_stack = new Stack ();
4447 lexer = new Tokenizer (reader, file, defines);
4450 public void parse ()
4453 if (yacc_verbose_flag)
4454 yyparse (lexer, new yydebug.yyDebugSimple ());
4457 Tokenizer tokenizer = lexer as Tokenizer;
4458 tokenizer.cleanup ();
4459 } catch (Exception e){
4461 // Removed for production use, use parser verbose to get the output.
4463 // Console.WriteLine (e);
4464 Report.Error (-25, lexer.Location, "Parsing error");
4465 if (Driver.parser_verbose)
4466 Console.WriteLine (e);
4470 void CheckToken (int error, int yyToken, string msg)
4472 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4473 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4476 Report.Error (error, lexer.Location, msg);
4479 void CheckIdentifierToken (int yyToken)
4481 CheckToken (1041, yyToken, "Identifier expected");