3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnu.org)
6 // Ravi Pratap (ravi@ximian.com)
8 // Licensed under the terms of the GNU GPL
10 // (C) 2001 Ximian, Inc (http://www.ximian.com)
13 // (1) Figure out why error productions dont work. `type-declaration' is a
14 // great spot to put an `error' because you can reproduce it with this input:
17 // Possible optimization:
18 // Run memory profiler with parsing only, and consider dropping
19 // arraylists where not needed. Some pieces can use linked lists.
27 using System.Collections;
32 public class CSharpParser {
33 NamespaceEntry current_namespace;
34 TypeContainer current_container;
36 IIteratorContainer iterator_container;
39 /// Current block is used to add statements as we find
46 /// If true, creates a toplevel block in the block production
47 /// This is flagged by the delegate creation
49 bool create_toplevel_block;
53 /// Current interface is used by the various declaration
54 /// productions in the interface declaration to "add"
55 /// the interfaces as we find them.
57 Interface current_interface;
60 /// This is used by the unary_expression code to resolve
61 /// a name against a parameter.
63 Parameters current_local_parameters;
66 /// Using during property parsing to describe the implicit
67 /// value parameter that is passed to the "set" and "get"accesor
68 /// methods (properties and indexers).
70 Expression implicit_value_parameter_type;
71 Parameters indexer_parameters;
74 /// Used to determine if we are parsing the get/set pair
75 /// of an indexer or a property
80 /// An out-of-band stack.
89 public bool yacc_verbose_flag;
91 // Name of the file we are parsing
101 %token NONE /* This token is never returned by our lexer */
102 %token ERROR // This is used not by the parser, but by the tokenizer.
106 *These are the C# keywords
194 /* C# keywords which are not really keywords */
200 /* C# single character operators/punctuation. */
201 %token OPEN_BRACE "{"
202 %token CLOSE_BRACE "}"
203 %token OPEN_BRACKET "["
204 %token CLOSE_BRACKET "]"
205 %token OPEN_PARENS "("
206 %token CLOSE_PARENS ")"
218 %token OP_GENERICS_LT "<"
220 %token OP_GENERICS_GT ">"
221 %token BITWISE_AND "&"
222 %token BITWISE_OR "|"
229 /* C# multi-character operators. */
232 %token OP_SHIFT_LEFT "<<"
233 %token OP_SHIFT_RIGHT ">>"
240 %token OP_MULT_ASSIGN "*="
241 %token OP_DIV_ASSIGN "/="
242 %token OP_MOD_ASSIGN "%="
243 %token OP_ADD_ASSIGN "+="
244 %token OP_SUB_ASSIGN "-="
245 %token OP_SHIFT_LEFT_ASSIGN "<<="
246 %token OP_SHIFT_RIGHT_ASSIGN ">>="
247 %token OP_AND_ASSIGN "&="
248 %token OP_XOR_ASSIGN "^="
249 %token OP_OR_ASSIGN "|="
253 %token LITERAL_INTEGER "int literal"
254 %token LITERAL_FLOAT "float literal"
255 %token LITERAL_DOUBLE "double literal"
256 %token LITERAL_DECIMAL "decimal literal"
257 %token LITERAL_CHARACTER "character literal"
258 %token LITERAL_STRING "string literal"
261 %token CLOSE_PARENS_CAST
262 %token CLOSE_PARENS_NO_CAST
263 %token CLOSE_PARENS_OPEN_PARENS
264 %token CLOSE_PARENS_MINUS
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, (Expression) $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 qualified_identifier
346 Attributes attrs = (Attributes) $1;
349 foreach (AttributeSection asec in attrs.AttributeSections)
350 if (asec.Target == "assembly")
351 RootContext.AddGlobalAttributeSection (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, $3.ToString (), lexer.Location);
360 namespace_body opt_semicolon
362 current_namespace = current_namespace.Parent;
377 : IDENTIFIER { $$ = new QualifiedIdentifier ((string) $1); }
378 | qualified_identifier DOT IDENTIFIER {
379 $$ = new QualifiedIdentifier ((QualifiedIdentifier) $1, (string) $3);
384 : qualified_identifier { $$ = ($1).ToString (); }
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 RootContext.AddGlobalAttributeSection (current_container, sect);
482 $$ = new Attributes (sect);
484 | attribute_sections attribute_section
486 Attributes attrs = $1 as Attributes;
487 AttributeSection sect = (AttributeSection) $2;
489 if (sect.Target == "assembly") {
490 RootContext.AddGlobalAttributeSection (current_container, sect);
493 attrs = new Attributes (sect);
495 attrs.AddAttributeSection (sect);
503 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
505 string target = null;
508 target = (string) $2;
510 $$ = new AttributeSection (target, (ArrayList) $3);
512 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
514 $$ = new AttributeSection (null, (ArrayList) $2);
518 attribute_target_specifier
519 : attribute_target COLON
528 CheckAttributeTarget ((string) $1);
531 | EVENT { $$ = "event"; }
532 | RETURN { $$ = "return"; }
538 ArrayList attrs = new ArrayList (4);
544 | attribute_list COMMA attribute
546 ArrayList attrs = (ArrayList) $1;
558 opt_attribute_arguments
561 // Attributes need a string, not an expression: generic types will fail here.
563 $$ = new Attribute (((Expression) $1).ToString (), (ArrayList) $3, (Location) $2);
568 : type_name { /* reserved attribute name or identifier: 17.4 */ }
571 opt_attribute_arguments
572 : /* empty */ { $$ = null; }
573 | OPEN_PARENS attribute_arguments CLOSE_PARENS
581 : opt_positional_argument_list
586 ArrayList args = new ArrayList (4);
592 | positional_argument_list COMMA named_argument_list
594 ArrayList args = new ArrayList (4);
600 | named_argument_list
602 ArrayList args = new ArrayList (4);
611 opt_positional_argument_list
612 : /* empty */ { $$ = null; }
613 | positional_argument_list
616 positional_argument_list
619 ArrayList args = new ArrayList (4);
620 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
624 | positional_argument_list COMMA expression
626 ArrayList args = (ArrayList) $1;
627 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
636 ArrayList args = new ArrayList (4);
641 | named_argument_list COMMA named_argument
643 ArrayList args = (ArrayList) $1;
651 : IDENTIFIER ASSIGN expression
653 $$ = new DictionaryEntry (
655 new Argument ((Expression) $3, Argument.AType.Expression));
661 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
664 opt_class_member_declarations
666 | class_member_declarations
669 class_member_declarations
670 : class_member_declaration
671 | class_member_declarations
672 class_member_declaration
675 class_member_declaration
676 : constant_declaration // done
677 | field_declaration // done
678 | method_declaration // done
679 | property_declaration // done
680 | event_declaration // done
681 | indexer_declaration // done
682 | operator_declaration // done
683 | constructor_declaration // done
684 | destructor_declaration // done
694 string full_struct_name = MakeName ((string) $4);
696 new_struct = new Struct (current_namespace, current_container, full_struct_name,
697 (int) $2, (Attributes) $1, lexer.Location);
698 current_container = new_struct;
699 RootContext.Tree.RecordDecl (full_struct_name, new_struct);
700 lexer.ConstraintsParsing = true;
702 opt_type_parameter_list
704 opt_type_parameter_constraints_clauses
706 lexer.ConstraintsParsing = false;
711 Struct new_struct = (Struct) current_container;
713 if ($8 != null && $6 == null)
714 Report.Error (-200, new_struct.Location,
715 "Type parameter constraints only valid if there is a type parameter list");
717 CheckDef (new_struct.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_struct.Name, new_struct.Location);
720 new_struct.Bases = (ArrayList) $7;
722 current_container = current_container.Parent;
723 CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
726 | opt_attributes opt_modifiers STRUCT error {
727 CheckIdentifierToken (yyToken);
732 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
735 opt_struct_member_declarations
737 | struct_member_declarations
740 struct_member_declarations
741 : struct_member_declaration
742 | struct_member_declarations struct_member_declaration
745 struct_member_declaration
746 : constant_declaration
749 | property_declaration
751 | indexer_declaration
752 | operator_declaration
753 | constructor_declaration
757 * This is only included so we can flag error 575:
758 * destructors only allowed on class types
760 | destructor_declaration
771 foreach (VariableDeclaration constant in (ArrayList) $5){
772 Location l = constant.Location;
774 Const c = new Const (
775 (Expression) $4, (string) constant.identifier,
776 (Expression) constant.expression_or_array_initializer, (int) $2,
779 CheckDef (current_container.AddConstant (c), c.Name, l);
785 : constant_declarator
787 ArrayList constants = new ArrayList (4);
791 | constant_declarators COMMA constant_declarator
793 ArrayList constants = (ArrayList) $1;
800 : IDENTIFIER ASSIGN constant_expression
802 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
813 Expression type = (Expression) $3;
816 foreach (VariableDeclaration var in (ArrayList) $4){
817 Location l = var.Location;
819 Field field = new Field (type, mod, var.identifier,
820 var.expression_or_array_initializer,
823 CheckDef (current_container.AddField (field), field.Name, l);
831 Report.Error (670, lexer.Location, "void type is not allowed for fields");
836 : variable_declarator
838 ArrayList decl = new ArrayList (4);
842 | variable_declarators COMMA variable_declarator
844 ArrayList decls = (ArrayList) $1;
851 : IDENTIFIER ASSIGN variable_initializer
853 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
857 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
870 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
872 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
878 iterator_container = (IIteratorContainer) $1;
882 Method method = (Method) $1;
883 Block b = (Block) $3;
884 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
887 if ((method.ModFlags & extern_abstract) == 0){
889 501, lexer.Location, current_container.MakeName (method.Name) +
890 "must declare a body because it is not marked abstract or extern");
893 if ((method.ModFlags & Modifiers.EXTERN) != 0){
895 179, lexer.Location, current_container.MakeName (method.Name) +
896 " is declared extern, but has a body");
900 method.Block = (Block) $3;
901 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
903 current_local_parameters = null;
904 iterator_container = null;
918 1585, lexer.Location, "Member modifier `" +
919 Modifiers.Name (i) + "' must precede member type and name");
932 opt_type_parameter_list
933 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
935 lexer.ConstraintsParsing = true;
937 opt_type_parameter_constraints_clauses
939 lexer.ConstraintsParsing = false;
940 if ($10 != null && $5 == null)
941 Report.Error (-200, lexer.Location,
942 "Type parameter constraints only valid if there is a type parameter list");
945 GenericMethod generic = null;
947 generic = new GenericMethod (current_namespace, current_container,
948 (string) $4, (Attributes) $1,
951 CheckDef (generic.SetParameterInfo ((ArrayList) $5, (ArrayList) $10), generic.Name, generic.Location);
952 method = new Method (generic, (Expression) $3, (int) $2, (string) $4,
953 (Parameters) $7, (Attributes) $1, lexer.Location);
955 method = new Method (current_container, (Expression) $3, (int) $2, (string) $4,
956 (Parameters) $7, (Attributes) $1, lexer.Location);
958 current_local_parameters = (Parameters) $7;
966 opt_type_parameter_list
967 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
969 lexer.ConstraintsParsing = true;
971 opt_type_parameter_constraints_clauses
973 lexer.ConstraintsParsing = false;
974 if ($10 != null && $5 == null)
975 Report.Error (-200, lexer.Location,
976 "Type parameter constraints only valid if there is a type parameter list");
979 GenericMethod generic = null;
981 generic = new GenericMethod (current_namespace, current_container,
982 (string) $4, (Attributes) $1,
985 CheckDef (generic.SetParameterInfo ((ArrayList) $5, (ArrayList) $10), generic.Name, generic.Location);
987 method = new Method (generic, TypeManager.system_void_expr, (int) $2,
988 (string) $4, (Parameters) $7, (Attributes) $1,
991 method = new Method (current_container, TypeManager.system_void_expr, (int) $2,
992 (string) $4, (Parameters) $7, (Attributes) $1,
995 current_local_parameters = (Parameters) $7;
1002 modifiers member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1004 Report.Error (1585, lexer.Location,
1005 String.Format ("Modifier {0} should appear before type",
1006 Modifiers.Name ((int) $4)));
1007 Method method = new Method (current_container, TypeManager.system_void_expr, 0,
1008 (string) $5, (Parameters) $7, (Attributes) $1,
1011 current_local_parameters = (Parameters) $7;
1018 | SEMICOLON { $$ = null; }
1021 opt_formal_parameter_list
1022 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1023 | formal_parameter_list
1026 formal_parameter_list
1029 ArrayList pars_list = (ArrayList) $1;
1031 Parameter [] pars = new Parameter [pars_list.Count];
1032 pars_list.CopyTo (pars);
1034 $$ = new Parameters (pars, null, lexer.Location);
1036 | fixed_parameters COMMA parameter_array
1038 ArrayList pars_list = (ArrayList) $1;
1040 Parameter [] pars = new Parameter [pars_list.Count];
1041 pars_list.CopyTo (pars);
1043 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
1047 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1054 ArrayList pars = new ArrayList (4);
1059 | fixed_parameters COMMA fixed_parameter
1061 ArrayList pars = (ArrayList) $1;
1070 opt_parameter_modifier
1074 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1077 opt_parameter_modifier
1080 CheckIdentifierToken (yyToken);
1085 opt_parameter_modifier
1086 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1087 | parameter_modifier
1091 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1092 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1096 : opt_attributes PARAMS type IDENTIFIER
1098 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1099 note ("type must be a single-dimension array type");
1101 | opt_attributes PARAMS type error {
1102 CheckIdentifierToken (yyToken);
1108 : qualified_identifier { $$ = ($1).ToString (); }
1111 property_declaration
1117 implicit_value_parameter_type = (Expression) $3;
1119 lexer.PropertyParsing = true;
1121 $$ = lexer.Location;
1123 accessor_declarations
1125 lexer.PropertyParsing = false;
1130 Pair pair = (Pair) $7;
1131 Accessor get_block = (Accessor) pair.First;
1132 Accessor set_block = (Accessor) pair.Second;
1134 Location loc = (Location) $6;
1135 prop = new Property (current_container, (Expression) $3, (string) $4, (int) $2,
1136 get_block, set_block, (Attributes) $1, loc);
1138 CheckDef (current_container.AddProperty (prop), prop.Name, loc);
1139 implicit_value_parameter_type = null;
1143 accessor_declarations
1144 : get_accessor_declaration opt_set_accessor_declaration
1146 $$ = new Pair ($1, $2);
1148 | set_accessor_declaration opt_get_accessor_declaration
1150 $$ = new Pair ($2, $1);
1154 opt_get_accessor_declaration
1155 : /* empty */ { $$ = null; }
1156 | get_accessor_declaration
1159 opt_set_accessor_declaration
1160 : /* empty */ { $$ = null; }
1161 | set_accessor_declaration
1164 get_accessor_declaration
1165 : opt_attributes GET
1167 // If this is not the case, then current_local_parameters has already
1168 // been set in indexer_declaration
1169 if (parsing_indexer == false)
1170 current_local_parameters = null;
1172 current_local_parameters = indexer_parameters;
1173 lexer.PropertyParsing = false;
1177 $$ = new Accessor ((Block) $4, (Attributes) $1);
1178 current_local_parameters = null;
1179 lexer.PropertyParsing = true;
1183 set_accessor_declaration
1184 : opt_attributes SET
1187 Parameter implicit_value_parameter = new Parameter (
1188 implicit_value_parameter_type, "value",
1189 Parameter.Modifier.NONE, null);
1191 if (parsing_indexer == false) {
1192 args = new Parameter [1];
1193 args [0] = implicit_value_parameter;
1194 current_local_parameters = new Parameters (args, null, lexer.Location);
1196 Parameter [] fpars = indexer_parameters.FixedParameters;
1199 int count = fpars.Length;
1201 args = new Parameter [count + 1];
1202 fpars.CopyTo (args, 0);
1203 args [count] = implicit_value_parameter;
1206 current_local_parameters = new Parameters (
1207 args, indexer_parameters.ArrayParameter, lexer.Location);
1210 lexer.PropertyParsing = false;
1214 $$ = new Accessor ((Block) $4, (Attributes) $1);
1215 current_local_parameters = null;
1216 lexer.PropertyParsing = true;
1222 | SEMICOLON { $$ = null; }
1225 interface_declaration
1228 INTERFACE IDENTIFIER
1230 Interface new_interface;
1231 string full_interface_name = MakeName ((string) $4);
1233 new_interface = new Interface (current_namespace, current_container, full_interface_name,
1234 (int) $2, (Attributes) $1, lexer.Location);
1235 if (current_interface != null) {
1236 Location l = lexer.Location;
1237 Report.Error (-2, l, "Internal compiler error: interface inside interface");
1239 current_interface = new_interface;
1240 RootContext.Tree.RecordDecl (full_interface_name, new_interface);
1241 lexer.ConstraintsParsing = true;
1243 opt_type_parameter_list
1245 opt_type_parameter_constraints_clauses
1247 lexer.ConstraintsParsing = false;
1249 interface_body opt_semicolon
1251 Interface new_interface = (Interface) current_interface;
1253 if ($8 != null && $6 == null)
1254 Report.Error (-200, new_interface.Location,
1255 "Type parameter constraints only valid if there is a type parameter list");
1258 CheckDef (new_interface.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_interface.Name, new_interface.Location);
1260 new_interface.Bases = (ArrayList) $7;
1262 current_interface = null;
1263 CheckDef (current_container.AddInterface (new_interface),
1264 new_interface.Name, new_interface.Location);
1266 | opt_attributes opt_modifiers INTERFACE error {
1267 CheckIdentifierToken (yyToken);
1272 : /* empty */ { $$ = null; }
1277 : COLON interface_type_list { $$ = $2; }
1283 ArrayList interfaces = new ArrayList (4);
1285 interfaces.Add ($1);
1288 | interface_type_list COMMA interface_type
1290 ArrayList interfaces = (ArrayList) $1;
1291 interfaces.Add ($3);
1298 opt_interface_member_declarations
1302 opt_interface_member_declarations
1304 | interface_member_declarations
1307 interface_member_declarations
1308 : interface_member_declaration
1309 | interface_member_declarations interface_member_declaration
1312 interface_member_declaration
1313 : interface_method_declaration
1315 InterfaceMethod m = (InterfaceMethod) $1;
1317 CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
1319 | interface_property_declaration
1321 InterfaceProperty p = (InterfaceProperty) $1;
1323 CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
1325 | interface_event_declaration
1328 InterfaceEvent e = (InterfaceEvent) $1;
1329 CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
1332 | interface_indexer_declaration
1334 InterfaceIndexer i = (InterfaceIndexer) $1;
1336 CheckDef (current_interface.AddIndexer (i), "indexer", i.Location);
1345 val = Modifiers.Check (Modifiers.NEW, val, 0, lexer.Location);
1346 $$ = (bool) (val != 0);
1350 interface_method_declaration
1351 : opt_attributes opt_new type IDENTIFIER
1352 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1355 $$ = new InterfaceMethod ((Expression) $3, (string) $4, (bool) $2,
1356 (Parameters) $6, (Attributes) $1, lexer.Location);
1358 | opt_attributes opt_new VOID IDENTIFIER
1359 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1362 $$ = new InterfaceMethod (
1363 TypeManager.system_void_expr, (string) $4, (bool) $2, (Parameters) $6,
1364 (Attributes) $1, lexer.Location);
1368 interface_property_declaration
1373 { lexer.PropertyParsing = true; }
1375 { lexer.PropertyParsing = false; }
1380 $$ = new InterfaceProperty ((Expression) $3, (string) $4, (bool) $2,
1381 (gs & 1) == 1, (gs & 2) == 2, (Attributes) $1,
1387 CheckIdentifierToken (yyToken);
1393 : opt_attributes GET SEMICOLON { $$ = 1; }
1394 | opt_attributes SET SEMICOLON { $$ = 2; }
1395 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1397 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1401 interface_event_declaration
1402 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1404 $$ = new InterfaceEvent ((Expression) $4, (string) $5, (bool) $2, (Attributes) $1,
1407 | opt_attributes opt_new EVENT type error {
1408 CheckIdentifierToken (yyToken);
1411 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1412 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1415 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1416 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1421 interface_indexer_declaration
1422 : opt_attributes opt_new type THIS
1423 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1425 { lexer.PropertyParsing = true; }
1427 { lexer.PropertyParsing = false; }
1430 int a_flags = (int) $10;
1432 bool do_get = (a_flags & 1) == 1;
1433 bool do_set = (a_flags & 2) == 2;
1435 $$ = new InterfaceIndexer ((Expression) $3, (Parameters) $6, do_get, do_set,
1436 (bool) $2, (Attributes) $1, lexer.Location);
1440 operator_declaration
1441 : opt_attributes opt_modifiers operator_declarator operator_body
1443 OperatorDeclaration decl = (OperatorDeclaration) $3;
1445 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1446 decl.arg2type, decl.arg2name, (Block) $4, (Attributes) $1, decl.location);
1448 // Note again, checking is done in semantic analysis
1449 current_container.AddOperator (op);
1451 current_local_parameters = null;
1457 | SEMICOLON { $$ = null; }
1460 : type OPERATOR overloadable_operator
1461 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1463 Operator.OpType op = (Operator.OpType) $3;
1464 CheckUnaryOperator (op);
1466 if (op == Operator.OpType.Addition)
1467 op = Operator.OpType.UnaryPlus;
1469 if (op == Operator.OpType.Subtraction)
1470 op = Operator.OpType.UnaryNegation;
1472 Parameter [] pars = new Parameter [1];
1474 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1476 current_local_parameters = new Parameters (pars, null, lexer.Location);
1478 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1479 null, null, lexer.Location);
1481 | type OPERATOR overloadable_operator
1483 type IDENTIFIER COMMA
1487 CheckBinaryOperator ((Operator.OpType) $3);
1489 Parameter [] pars = new Parameter [2];
1491 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1492 pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1494 current_local_parameters = new Parameters (pars, null, lexer.Location);
1496 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1497 (Expression) $5, (string) $6,
1498 (Expression) $8, (string) $9, lexer.Location);
1500 | conversion_operator_declarator
1503 overloadable_operator
1505 : BANG { $$ = Operator.OpType.LogicalNot; }
1506 | TILDE { $$ = Operator.OpType.OnesComplement; }
1507 | OP_INC { $$ = Operator.OpType.Increment; }
1508 | OP_DEC { $$ = Operator.OpType.Decrement; }
1509 | TRUE { $$ = Operator.OpType.True; }
1510 | FALSE { $$ = Operator.OpType.False; }
1511 // Unary and binary:
1512 | PLUS { $$ = Operator.OpType.Addition; }
1513 | MINUS { $$ = Operator.OpType.Subtraction; }
1515 | STAR { $$ = Operator.OpType.Multiply; }
1516 | DIV { $$ = Operator.OpType.Division; }
1517 | PERCENT { $$ = Operator.OpType.Modulus; }
1518 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1519 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1520 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1521 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1522 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1523 | OP_EQ { $$ = Operator.OpType.Equality; }
1524 | OP_NE { $$ = Operator.OpType.Inequality; }
1525 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1526 | OP_LT { $$ = Operator.OpType.LessThan; }
1527 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1528 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1531 conversion_operator_declarator
1532 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1534 Parameter [] pars = new Parameter [1];
1536 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1538 current_local_parameters = new Parameters (pars, null, lexer.Location);
1540 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1541 null, null, lexer.Location);
1543 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1545 Parameter [] pars = new Parameter [1];
1547 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1549 current_local_parameters = new Parameters (pars, null, lexer.Location);
1551 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1552 null, null, lexer.Location);
1556 syntax_error (lexer.Location, "'operator' expected");
1560 syntax_error (lexer.Location, "'operator' expected");
1564 constructor_declaration
1567 constructor_declarator
1570 Constructor c = (Constructor) $3;
1571 c.Block = (Block) $4;
1572 c.OptAttributes = (Attributes) $1;
1573 c.ModFlags = (int) $2;
1575 if (c.Name == current_container.Basename){
1576 if ((c.ModFlags & Modifiers.STATIC) != 0){
1577 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1579 515, c.Location, String.Format (
1580 "`{0}.{1}': static constructor can not have access modifiers",
1581 c.Name, current_container.Name));
1584 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1586 if (c.Initializer != null){
1589 "Static constructors can not have an explicit this or base " +
1590 "constructor invocations");
1593 if (!c.Parameters.Empty){
1595 132, c.Location, "Static constructors should not have parameters");
1598 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1601 // We let another layer check the validity of the constructor.
1602 Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1605 CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
1607 current_local_parameters = null;
1611 constructor_declarator
1613 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1615 oob_stack.Push (lexer.Location);
1617 current_local_parameters = (Parameters) $3;
1619 opt_constructor_initializer
1621 Location l = (Location) oob_stack.Pop ();
1622 $$ = new Constructor (current_container, (string) $1, (Parameters) $3,
1623 (ConstructorInitializer) $6, l);
1629 | SEMICOLON { $$ = null; }
1632 opt_constructor_initializer
1633 : /* empty */ { $$ = null; }
1634 | constructor_initializer
1637 constructor_initializer
1638 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1640 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1642 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1644 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1647 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1653 : /* EMPTY */ { $$ = 0; }
1654 | UNSAFE { $$ = Modifiers.UNSAFE; }
1655 | EXTERN { $$ = Modifiers.EXTERN; }
1658 destructor_declaration
1659 : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1661 if ((string) $4 != current_container.Basename){
1662 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1663 } else if (!(current_container is Class)){
1664 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1666 Location l = lexer.Location;
1669 if (!RootContext.StdLib && current_container.Name == "System.Object")
1670 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1672 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1674 if ((m & Modifiers.UNSAFE) != 0){
1675 if (!RootContext.Unsafe){
1676 Report.Error (227, l,
1677 "Unsafe code requires the --unsafe command " +
1678 "line option to be specified");
1682 Method d = new Destructor (
1683 current_container, TypeManager.system_void_expr, m, "Finalize",
1684 new Parameters (null, null, l), (Attributes) $1, l);
1686 d.Block = (Block) $7;
1687 CheckDef (current_container.AddMethod (d), d.Name, d.Location);
1695 EVENT type variable_declarators SEMICOLON
1697 foreach (VariableDeclaration var in (ArrayList) $5) {
1699 Event e = new Event ((Expression) $4, var.identifier,
1700 var.expression_or_array_initializer,
1701 (int) $2, null, null, (Attributes) $1, lexer.Location);
1703 CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1709 EVENT type member_name
1712 implicit_value_parameter_type = (Expression) $4;
1713 lexer.EventParsing = true;
1714 oob_stack.Push (lexer.Location);
1716 event_accessor_declarations
1718 lexer.EventParsing = false;
1722 Location loc = (Location) oob_stack.Pop ();
1725 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1728 Pair pair = (Pair) $8;
1729 Accessor add_accessor = null;
1730 Accessor rem_accessor = null;
1732 if (pair.First != null)
1733 add_accessor = (Accessor) pair.First;
1734 if (pair.Second != null)
1735 rem_accessor = (Accessor) pair.Second;
1737 Event e = new Event ((Expression) $4, (string) $5, null, (int) $2, add_accessor, rem_accessor,
1738 (Attributes) $1, loc);
1740 CheckDef (current_container.AddEvent (e), e.Name, loc);
1741 implicit_value_parameter_type = null;
1746 event_accessor_declarations
1747 : add_accessor_declaration remove_accessor_declaration
1749 $$ = new Pair ($1, $2);
1751 | remove_accessor_declaration add_accessor_declaration
1753 $$ = new Pair ($2, $1);
1755 | add_accessor_declaration { $$ = null; }
1756 | remove_accessor_declaration { $$ = null; }
1759 add_accessor_declaration
1760 : opt_attributes ADD
1762 Parameter [] args = new Parameter [1];
1763 Parameter implicit_value_parameter = new Parameter (
1764 implicit_value_parameter_type, "value",
1765 Parameter.Modifier.NONE, null);
1767 args [0] = implicit_value_parameter;
1769 current_local_parameters = new Parameters (args, null, lexer.Location);
1770 lexer.EventParsing = false;
1774 $$ = new Accessor ((Block) $4, (Attributes) $1);
1775 lexer.EventParsing = true;
1777 | opt_attributes ADD error {
1778 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1783 remove_accessor_declaration
1784 : opt_attributes REMOVE
1786 Parameter [] args = new Parameter [1];
1787 Parameter implicit_value_parameter = new Parameter (
1788 implicit_value_parameter_type, "value",
1789 Parameter.Modifier.NONE, null);
1791 args [0] = implicit_value_parameter;
1793 current_local_parameters = new Parameters (args, null, lexer.Location);
1794 lexer.EventParsing = false;
1798 $$ = new Accessor ((Block) $4, (Attributes) $1);
1799 lexer.EventParsing = true;
1801 | opt_attributes REMOVE error {
1802 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1808 : opt_attributes opt_modifiers indexer_declarator
1811 IndexerDeclaration decl = (IndexerDeclaration) $3;
1813 implicit_value_parameter_type = decl.type;
1815 lexer.PropertyParsing = true;
1816 parsing_indexer = true;
1818 indexer_parameters = decl.param_list;
1819 oob_stack.Push (lexer.Location);
1821 accessor_declarations
1823 lexer.PropertyParsing = false;
1824 parsing_indexer = false;
1828 // The signature is computed from the signature of the indexer. Look
1829 // at section 3.6 on the spec
1830 Location loc = (Location) oob_stack.Pop ();
1832 IndexerDeclaration decl = (IndexerDeclaration) $3;
1833 Pair pair = (Pair) $6;
1834 Accessor get_block = (Accessor) pair.First;
1835 Accessor set_block = (Accessor) pair.Second;
1837 indexer = new Indexer (current_container, decl.type, decl.interface_type, (int) $2,
1838 decl.param_list, get_block, set_block, (Attributes) $1, loc);
1840 // Note that there is no equivalent of CheckDef for this case
1841 // We shall handle this in semantic analysis
1843 current_container.AddIndexer (indexer);
1845 current_local_parameters = null;
1846 implicit_value_parameter_type = null;
1847 indexer_parameters = null;
1852 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1854 Parameters pars = (Parameters) $4;
1856 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1857 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1860 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1862 | type qualified_identifier DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1864 Parameters pars = (Parameters) $6;
1866 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1867 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1869 $$ = new IndexerDeclaration ((Expression) $1, $2.ToString (), pars);
1881 Location enum_location = lexer.Location;
1883 string full_name = MakeName ((string) $4);
1884 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
1885 full_name, (Attributes) $1, enum_location);
1887 foreach (VariableDeclaration ev in (ArrayList) $6) {
1888 Location loc = (Location) ev.Location;
1890 CheckDef (e.AddEnumMember (ev.identifier,
1891 (Expression) ev.expression_or_array_initializer,
1892 loc, ev.OptAttributes),
1893 ev.identifier, loc);
1896 CheckDef (current_container.AddEnum (e), full_name, enum_location);
1897 RootContext.Tree.RecordDecl (full_name, e);
1903 : /* empty */ { $$ = TypeManager.system_int32_expr; }
1904 | COLON type { $$ = $2; }
1908 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1914 opt_enum_member_declarations
1915 : /* empty */ { $$ = new ArrayList (4); }
1916 | enum_member_declarations opt_comma { $$ = $1; }
1919 enum_member_declarations
1920 : enum_member_declaration
1922 ArrayList l = new ArrayList (4);
1927 | enum_member_declarations COMMA enum_member_declaration
1929 ArrayList l = (ArrayList) $1;
1937 enum_member_declaration
1938 : opt_attributes IDENTIFIER
1940 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
1942 | opt_attributes IDENTIFIER
1944 $$ = lexer.Location;
1948 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
1952 delegate_declaration
1956 IDENTIFIER OPEN_PARENS
1957 opt_formal_parameter_list
1961 Location l = lexer.Location;
1962 Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
1963 (int) $2, MakeName ((string) $5), (Parameters) $7,
1964 (Attributes) $1, l);
1966 CheckDef (current_container.AddDelegate (del), del.Name, l);
1971 IDENTIFIER OPEN_PARENS
1972 opt_formal_parameter_list
1976 Location l = lexer.Location;
1977 Delegate del = new Delegate (
1978 current_namespace, current_container,
1979 TypeManager.system_void_expr, (int) $2, MakeName ((string) $5),
1980 (Parameters) $7, (Attributes) $1, l);
1982 CheckDef (current_container.AddDelegate (del), del.Name, l);
1987 : namespace_or_type_name
1990 namespace_or_type_name
1991 : IDENTIFIER opt_type_argument_list {
1993 $$ = new SimpleName ((string) $1, lexer.Location);
1995 $$ = new ConstructedType ((string) $1, (TypeArguments) $2, lexer.Location);
1997 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2002 // Third argument will become an Expression, when we have sorted out
2003 // the issues with SimpleName first
2007 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2009 $$ = new GenericMemberAccess ((Expression) $1, (string) $3,
2010 (TypeArguments) $4, lexer.Location);
2012 | namespace_or_type_name DOT DEFAULT
2014 $$ = new DefaultValueExpression ((Expression) $1, lexer.Location);
2020 // Figure out what to do with the list
2022 opt_type_argument_list
2023 : /* empty */ { $$ = null; }
2024 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2032 TypeArguments type_args = new TypeArguments ();
2033 type_args.Add ((Expression) $1);
2036 | type_arguments COMMA type {
2037 TypeArguments type_args = (TypeArguments) $1;
2038 type_args.Add ((Expression) $3);
2043 type_name_expression
2044 : IDENTIFIER { $$ = new SimpleName ((string) $1, lexer.Location);}
2045 | type_name_expression DOT IDENTIFIER {
2046 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2051 * Before you think of adding a return_type, notice that we have been
2052 * using two rules in the places where it matters (one rule using type
2053 * and another identical one that uses VOID as the return type). This
2054 * gets rid of a shift/reduce couple
2057 : type_name { /* class_type */
2069 // Note that here only unmanaged types are allowed but we
2070 // can't perform checks during this phase - we do it during
2071 // semantic analysis.
2073 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2077 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2083 | non_expression_type rank_specifier
2085 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2087 | non_expression_type STAR
2089 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2091 | expression rank_specifiers
2093 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2097 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2101 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2102 // through this different path
2104 | multiplicative_expression STAR
2106 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2113 ArrayList types = new ArrayList (4);
2118 | type_list COMMA type
2120 ArrayList types = (ArrayList) $1;
2128 * replaces all the productions for isolating the various
2129 * simple types, but we need this to reuse it easily in local_variable_type
2132 : OBJECT { $$ = TypeManager.system_object_expr; }
2133 | STRING { $$ = TypeManager.system_string_expr; }
2134 | BOOL { $$ = TypeManager.system_boolean_expr; }
2135 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2136 | FLOAT { $$ = TypeManager.system_single_expr; }
2137 | DOUBLE { $$ = TypeManager.system_double_expr; }
2142 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2143 | BYTE { $$ = TypeManager.system_byte_expr; }
2144 | SHORT { $$ = TypeManager.system_int16_expr; }
2145 | USHORT { $$ = TypeManager.system_uint16_expr; }
2146 | INT { $$ = TypeManager.system_int32_expr; }
2147 | UINT { $$ = TypeManager.system_uint32_expr; }
2148 | LONG { $$ = TypeManager.system_int64_expr; }
2149 | ULONG { $$ = TypeManager.system_uint64_expr; }
2150 | CHAR { $$ = TypeManager.system_char_expr; }
2151 | VOID { $$ = TypeManager.system_void_expr; }
2159 : type rank_specifiers
2161 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2166 // Expressions, section 7.5
2178 | parenthesized_expression
2179 | default_value_expression
2181 | invocation_expression
2185 | post_increment_expression
2186 | post_decrement_expression
2190 | checked_expression
2191 | unchecked_expression
2192 | pointer_member_access
2193 | anonymous_method_expression
2200 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2201 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2202 | NULL { $$ = NullLiteral.Null; }
2206 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2207 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2208 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2213 object v = lexer.Value;
2219 $$ = IntLiteral.Zero;
2221 $$ = IntLiteral.One;
2223 $$ = new IntLiteral (i);
2224 } else if (v is uint)
2225 $$ = new UIntLiteral ((UInt32) v);
2227 $$ = new LongLiteral ((Int64) v);
2228 else if (v is ulong)
2229 $$ = new ULongLiteral ((UInt64) v);
2231 Console.WriteLine ("OOPS. Unexpected result from scanner");
2236 : TRUE { $$ = new BoolLiteral (true); }
2237 | FALSE { $$ = new BoolLiteral (false); }
2240 parenthesized_expression_0
2241 : OPEN_PARENS expression CLOSE_PARENS
2244 lexer.Deambiguate_CloseParens ();
2245 // After this, the next token returned is one of
2246 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2247 // or CLOSE_PARENS_MINUS.
2251 parenthesized_expression
2252 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2256 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2258 // If a parenthesized expression is followed by a minus, we need to wrap
2259 // the expression inside a ParenthesizedExpression for the CS0075 check
2260 // in Binary.DoResolve().
2261 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2266 : primary_expression DOT IDENTIFIER
2268 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2270 | predefined_type DOT IDENTIFIER
2272 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2280 invocation_expression
2281 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2284 Location l = lexer.Location;
2285 Report.Error (1, l, "Parse error");
2287 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2289 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2291 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2293 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2295 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2300 : /* empty */ { $$ = null; }
2307 ArrayList list = new ArrayList (4);
2311 | argument_list COMMA argument
2313 ArrayList list = (ArrayList) $1;
2317 | argument_list error {
2318 CheckToken (1026, yyToken, ", or ) expected");
2325 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2327 | REF variable_reference
2329 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2331 | OUT variable_reference
2333 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2338 : expression { note ("section 5.4"); $$ = $1; }
2342 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2344 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2346 | primary_expression rank_specifiers
2348 // So the super-trick is that primary_expression
2349 // can only be either a SimpleName or a MemberAccess.
2350 // The MemberAccess case arises when you have a fully qualified type-name like :
2352 // SimpleName is when you have
2355 Expression expr = (Expression) $1;
2356 if (expr is ComposedCast){
2357 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2358 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2359 Error_ExpectingTypeName (lexer.Location, expr);
2360 $$ = TypeManager.system_object_expr;
2363 // So we extract the string corresponding to the SimpleName
2366 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2374 ArrayList list = new ArrayList (4);
2378 | expression_list COMMA expression
2380 ArrayList list = (ArrayList) $1;
2389 $$ = new This (current_block, lexer.Location);
2394 : BASE DOT IDENTIFIER
2396 $$ = new BaseAccess ((string) $3, lexer.Location);
2398 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2400 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2403 Report.Error (175, "Use of keyword `base' is not valid in this context");
2408 post_increment_expression
2409 : primary_expression OP_INC
2411 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2412 (Expression) $1, lexer.Location);
2416 post_decrement_expression
2417 : primary_expression OP_DEC
2419 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2420 (Expression) $1, lexer.Location);
2425 : object_or_delegate_creation_expression
2426 | array_creation_expression
2429 object_or_delegate_creation_expression
2430 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2432 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2436 array_creation_expression
2437 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2439 opt_array_initializer
2441 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2443 | NEW type rank_specifiers array_initializer
2445 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2449 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2465 : rank_specifier opt_rank_specifier
2467 $$ = (string) $2 + (string) $1;
2472 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2474 $$ = "[" + (string) $2 + "]";
2494 | dim_separators COMMA
2496 $$ = (string) $1 + ",";
2500 opt_array_initializer
2512 : OPEN_BRACE CLOSE_BRACE
2514 ArrayList list = new ArrayList (4);
2517 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2519 $$ = (ArrayList) $2;
2523 variable_initializer_list
2524 : variable_initializer
2526 ArrayList list = new ArrayList (4);
2530 | variable_initializer_list COMMA variable_initializer
2532 ArrayList list = (ArrayList) $1;
2539 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2541 $$ = new TypeOfVoid (lexer.Location);
2543 | TYPEOF OPEN_PARENS type CLOSE_PARENS
2545 $$ = new TypeOf ((Expression) $3, lexer.Location);
2550 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2551 $$ = new SizeOf ((Expression) $3, lexer.Location);
2556 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2558 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2562 unchecked_expression
2563 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2565 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2569 pointer_member_access
2570 : primary_expression OP_PTR IDENTIFIER
2574 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2575 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2579 anonymous_method_expression
2580 : DELEGATE opt_anonymous_method_signature {
2581 oob_stack.Push (current_local_parameters);
2582 current_local_parameters = (Parameters)$2;
2583 create_toplevel_block = true;
2585 create_toplevel_block = false;
2586 if (!RootContext.V2){
2587 Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
2590 $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
2591 current_local_parameters = (Parameters) oob_stack.Pop ();
2595 opt_anonymous_method_signature
2596 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
2597 | anonymous_method_signature
2600 anonymous_method_signature
2601 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2604 $$ = Parameters.EmptyReadOnlyParameters;
2606 ArrayList par_list = (ArrayList) $2;
2607 Parameter [] pars = new Parameter [par_list.Count];
2608 par_list.CopyTo (pars);
2609 $$ = new Parameters (pars, null, lexer.Location);
2614 opt_anonymous_method_parameter_list
2615 : /* empty */ { $$ = null; }
2616 | anonymous_method_parameter_list { $$ = $1; }
2619 anonymous_method_parameter_list
2620 : anonymous_method_parameter
2622 ArrayList a = new ArrayList (4);
2626 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2628 ArrayList a = (ArrayList) $1;
2634 anonymous_method_parameter
2635 : opt_parameter_modifier type IDENTIFIER {
2636 $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
2640 default_value_expression
2641 : primary_expression DOT DEFAULT
2643 $$ = new DefaultValueExpression ((Expression) $1, lexer.Location);
2645 | predefined_type DOT DEFAULT
2647 $$ = new DefaultValueExpression ((Expression) $1, lexer.Location);
2652 : primary_expression
2653 | BANG prefixed_unary_expression
2655 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2657 | TILDE prefixed_unary_expression
2659 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2665 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2667 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2669 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2671 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2677 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2679 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2684 // The idea to split this out is from Rhys' grammar
2685 // to solve the problem with casts.
2687 prefixed_unary_expression
2689 | PLUS prefixed_unary_expression
2691 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2693 | MINUS prefixed_unary_expression
2695 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2697 | OP_INC prefixed_unary_expression
2699 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2700 (Expression) $2, lexer.Location);
2702 | OP_DEC prefixed_unary_expression
2704 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2705 (Expression) $2, lexer.Location);
2707 | STAR prefixed_unary_expression
2709 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2711 | BITWISE_AND prefixed_unary_expression
2713 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2717 pre_increment_expression
2718 : OP_INC prefixed_unary_expression
2720 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2721 (Expression) $2, lexer.Location);
2725 pre_decrement_expression
2726 : OP_DEC prefixed_unary_expression
2728 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2729 (Expression) $2, lexer.Location);
2733 multiplicative_expression
2734 : prefixed_unary_expression
2735 | multiplicative_expression STAR prefixed_unary_expression
2737 $$ = new Binary (Binary.Operator.Multiply,
2738 (Expression) $1, (Expression) $3, lexer.Location);
2740 | multiplicative_expression DIV prefixed_unary_expression
2742 $$ = new Binary (Binary.Operator.Division,
2743 (Expression) $1, (Expression) $3, lexer.Location);
2745 | multiplicative_expression PERCENT prefixed_unary_expression
2747 $$ = new Binary (Binary.Operator.Modulus,
2748 (Expression) $1, (Expression) $3, lexer.Location);
2753 : multiplicative_expression
2754 | additive_expression PLUS multiplicative_expression
2756 $$ = new Binary (Binary.Operator.Addition,
2757 (Expression) $1, (Expression) $3, lexer.Location);
2759 | additive_expression MINUS multiplicative_expression
2761 $$ = new Binary (Binary.Operator.Subtraction,
2762 (Expression) $1, (Expression) $3, lexer.Location);
2767 : additive_expression
2768 | shift_expression OP_SHIFT_LEFT additive_expression
2770 $$ = new Binary (Binary.Operator.LeftShift,
2771 (Expression) $1, (Expression) $3, lexer.Location);
2773 | shift_expression OP_SHIFT_RIGHT additive_expression
2775 $$ = new Binary (Binary.Operator.RightShift,
2776 (Expression) $1, (Expression) $3, lexer.Location);
2780 relational_expression
2782 | relational_expression OP_LT shift_expression
2784 $$ = new Binary (Binary.Operator.LessThan,
2785 (Expression) $1, (Expression) $3, lexer.Location);
2787 | relational_expression OP_GT shift_expression
2789 $$ = new Binary (Binary.Operator.GreaterThan,
2790 (Expression) $1, (Expression) $3, lexer.Location);
2792 | relational_expression OP_LE shift_expression
2794 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2795 (Expression) $1, (Expression) $3, lexer.Location);
2797 | relational_expression OP_GE shift_expression
2799 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2800 (Expression) $1, (Expression) $3, lexer.Location);
2802 | relational_expression IS type
2804 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2806 | relational_expression AS type
2808 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2813 : relational_expression
2814 | equality_expression OP_EQ relational_expression
2816 $$ = new Binary (Binary.Operator.Equality,
2817 (Expression) $1, (Expression) $3, lexer.Location);
2819 | equality_expression OP_NE relational_expression
2821 $$ = new Binary (Binary.Operator.Inequality,
2822 (Expression) $1, (Expression) $3, lexer.Location);
2827 : equality_expression
2828 | and_expression BITWISE_AND equality_expression
2830 $$ = new Binary (Binary.Operator.BitwiseAnd,
2831 (Expression) $1, (Expression) $3, lexer.Location);
2835 exclusive_or_expression
2837 | exclusive_or_expression CARRET and_expression
2839 $$ = new Binary (Binary.Operator.ExclusiveOr,
2840 (Expression) $1, (Expression) $3, lexer.Location);
2844 inclusive_or_expression
2845 : exclusive_or_expression
2846 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2848 $$ = new Binary (Binary.Operator.BitwiseOr,
2849 (Expression) $1, (Expression) $3, lexer.Location);
2853 conditional_and_expression
2854 : inclusive_or_expression
2855 | conditional_and_expression OP_AND inclusive_or_expression
2857 $$ = new Binary (Binary.Operator.LogicalAnd,
2858 (Expression) $1, (Expression) $3, lexer.Location);
2862 conditional_or_expression
2863 : conditional_and_expression
2864 | conditional_or_expression OP_OR conditional_and_expression
2866 $$ = new Binary (Binary.Operator.LogicalOr,
2867 (Expression) $1, (Expression) $3, lexer.Location);
2871 conditional_expression
2872 : conditional_or_expression
2873 | conditional_or_expression INTERR expression COLON expression
2875 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2879 assignment_expression
2880 : prefixed_unary_expression ASSIGN expression
2882 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2884 | prefixed_unary_expression OP_MULT_ASSIGN expression
2886 Location l = lexer.Location;
2888 $$ = new CompoundAssign (
2889 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
2891 | prefixed_unary_expression OP_DIV_ASSIGN expression
2893 Location l = lexer.Location;
2895 $$ = new CompoundAssign (
2896 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
2898 | prefixed_unary_expression OP_MOD_ASSIGN expression
2900 Location l = lexer.Location;
2902 $$ = new CompoundAssign (
2903 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
2905 | prefixed_unary_expression OP_ADD_ASSIGN expression
2907 Location l = lexer.Location;
2909 $$ = new CompoundAssign (
2910 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
2912 | prefixed_unary_expression OP_SUB_ASSIGN expression
2914 Location l = lexer.Location;
2916 $$ = new CompoundAssign (
2917 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
2919 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2921 Location l = lexer.Location;
2923 $$ = new CompoundAssign (
2924 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
2926 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2928 Location l = lexer.Location;
2930 $$ = new CompoundAssign (
2931 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
2933 | prefixed_unary_expression OP_AND_ASSIGN expression
2935 Location l = lexer.Location;
2937 $$ = new CompoundAssign (
2938 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
2940 | prefixed_unary_expression OP_OR_ASSIGN expression
2942 Location l = lexer.Location;
2944 $$ = new CompoundAssign (
2945 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
2947 | prefixed_unary_expression OP_XOR_ASSIGN expression
2949 Location l = lexer.Location;
2951 $$ = new CompoundAssign (
2952 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
2957 : conditional_expression
2958 | assignment_expression
2980 name = MakeName ((string) $4);
2982 new_class = new Class (current_namespace, current_container, name, (int) $2,
2983 (Attributes) $1, lexer.Location);
2984 current_container = new_class;
2985 RootContext.Tree.RecordDecl (name, new_class);
2987 lexer.ConstraintsParsing = true;
2989 opt_type_parameter_list
2991 opt_type_parameter_constraints_clauses
2993 lexer.ConstraintsParsing = false;
2998 Class new_class = (Class) current_container;
3000 if ($8 != null && $6 == null)
3001 Report.Error (-200, new_class.Location,
3002 "Type parameter constraints only valid if there is a type parameter list");
3005 CheckDef (new_class.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_class.Name, new_class.Location);
3007 if (new_class.Name == "System.Object") {
3008 Report.Error (537, new_class.Location, "The class System.Object cannot have a base class or implement an interface.");
3011 new_class.Bases = (ArrayList) $7;
3013 current_container = current_container.Parent;
3014 CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
3022 lexer.ConstraintsParsing = true;
3025 Report.Error (-200, lexer.Location,
3026 "Type parameter constraints only valid if there is a type parameter list");
3033 : /* empty */ { $$ = (int) 0; }
3039 | modifiers modifier
3044 if ((m1 & m2) != 0) {
3045 Location l = lexer.Location;
3046 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3048 $$ = (int) (m1 | m2);
3053 : NEW { $$ = Modifiers.NEW; }
3054 | PUBLIC { $$ = Modifiers.PUBLIC; }
3055 | PROTECTED { $$ = Modifiers.PROTECTED; }
3056 | INTERNAL { $$ = Modifiers.INTERNAL; }
3057 | PRIVATE { $$ = Modifiers.PRIVATE; }
3058 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3059 | SEALED { $$ = Modifiers.SEALED; }
3060 | STATIC { $$ = Modifiers.STATIC; }
3061 | READONLY { $$ = Modifiers.READONLY; }
3062 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3063 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3064 | EXTERN { $$ = Modifiers.EXTERN; }
3065 | VOLATILE { $$ = Modifiers.VOLATILE; }
3066 | UNSAFE { $$ = Modifiers.UNSAFE; }
3070 : /* empty */ { $$ = null; }
3071 | class_base { $$ = $1; }
3075 : COLON type_list { $$ = $2; }
3078 opt_type_parameter_list
3079 : /* empty */ { $$ = null; }
3080 | type_parameter_list { $$ = $1; }
3084 : OP_GENERICS_LT type_parameters OP_GENERICS_GT { $$ = $2; }
3090 // Do some profiling to find the optimal size, for now we
3091 // assume most people will be generic on one type (saves space
3093 ArrayList type_parameters = new ArrayList (1);
3094 type_parameters.Add ($1);
3095 $$ = type_parameters;
3097 | type_parameters COMMA type_parameter {
3098 ArrayList type_parameters = (ArrayList) $1;
3100 type_parameters.Add ($3);
3101 $$ = type_parameters;
3109 opt_type_parameter_constraints_clauses
3110 : /* empty */ { $$ = null; }
3111 | type_parameter_constraints_clauses
3115 type_parameter_constraints_clauses
3116 : type_parameter_constraints_clause
3117 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3118 ArrayList constraints = (ArrayList) $1;
3120 constraints.Add ($2);
3125 type_parameter_constraints_clause
3126 : WHERE type_parameter COLON type_parameter_constraints {
3127 ArrayList constraints = new ArrayList (1);
3128 constraints.Add (new Constraints ((string) $2, (ArrayList) $4, lexer.Location));
3133 type_parameter_constraints
3134 : type_parameter_constraint {
3135 ArrayList constraints = new ArrayList (1);
3136 constraints.Add ($1);
3139 | type_parameter_constraints COMMA type_parameter_constraint {
3140 ArrayList constraints = (ArrayList) $1;
3142 constraints.Add ($3);
3147 type_parameter_constraint
3149 | NEW OPEN_PARENS CLOSE_PARENS {
3159 // A block is "contained" on the following places:
3161 // property_declaration as part of the accessor body (get/set)
3162 // operator_declaration
3163 // constructor_declaration
3164 // destructor_declaration
3165 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3170 if (current_block == null || create_toplevel_block){
3171 current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
3173 current_block = new Block (current_block, current_local_parameters,
3174 lexer.Location, Location.Null);
3177 opt_statement_list CLOSE_BRACE
3179 while (current_block.Implicit)
3180 current_block = current_block.Parent;
3182 current_block.SetEndLocation (lexer.Location);
3183 current_block = current_block.Parent;
3194 | statement_list statement
3198 : declaration_statement
3200 if ($1 != null && (Block) $1 != current_block){
3201 current_block.AddStatement ((Statement) $1);
3202 current_block = (Block) $1;
3205 | embedded_statement
3207 current_block.AddStatement ((Statement) $1);
3215 | expression_statement
3216 | selection_statement
3217 | iteration_statement
3221 | unchecked_statement
3231 $$ = EmptyStatement.Value;
3238 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3240 if (!current_block.AddLabel ((string) $1, labeled)){
3241 Location l = lexer.Location;
3242 Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
3244 current_block.AddStatement (labeled);
3249 declaration_statement
3250 : local_variable_declaration SEMICOLON
3253 DictionaryEntry de = (DictionaryEntry) $1;
3255 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3259 | local_constant_declaration SEMICOLON
3262 DictionaryEntry de = (DictionaryEntry) $1;
3264 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3270 * The following is from Rhys' grammar:
3271 * > Types in local variable declarations must be recognized as
3272 * > expressions to prevent reduce/reduce errors in the grammar.
3273 * > The expressions are converted into types during semantic analysis.
3276 : primary_expression opt_rank_specifier
3278 // FIXME: Do something smart here regarding the composition of the type.
3280 // Ok, the above "primary_expression" is there to get rid of
3281 // both reduce/reduce and shift/reduces in the grammar, it should
3282 // really just be "type_name". If you use type_name, a reduce/reduce
3283 // creeps up. If you use qualified_identifier (which is all we need
3284 // really) two shift/reduces appear.
3287 // So the super-trick is that primary_expression
3288 // can only be either a SimpleName or a MemberAccess.
3289 // The MemberAccess case arises when you have a fully qualified type-name like :
3291 // SimpleName is when you have
3294 Expression expr = (Expression) $1;
3295 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3296 Error_ExpectingTypeName (lexer.Location, expr);
3300 // So we extract the string corresponding to the SimpleName
3304 if ((string) $2 == "")
3307 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3310 | builtin_types opt_rank_specifier
3312 if ((string) $2 == "")
3315 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3319 local_variable_pointer_type
3320 : primary_expression STAR
3322 Expression expr = (Expression) $1;
3323 Location l = lexer.Location;
3325 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
3326 Error_ExpectingTypeName (l, expr);
3330 $$ = new ComposedCast ((Expression) $1, "*", l);
3332 | builtin_types STAR
3334 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3338 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3340 | local_variable_pointer_type STAR
3342 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3346 local_variable_declaration
3347 : local_variable_type variable_declarators
3350 $$ = new DictionaryEntry ($1, $2);
3354 | local_variable_pointer_type opt_rank_specifier variable_declarators
3359 if ((string) $2 == "")
3360 t = (Expression) $1;
3362 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3363 $$ = new DictionaryEntry (t, $3);
3369 local_constant_declaration
3370 : CONST local_variable_type constant_declarators
3373 $$ = new DictionaryEntry ($2, $3);
3379 expression_statement
3380 : statement_expression SEMICOLON
3387 // We have to do the wrapping here and not in the case above,
3388 // because statement_expression is used for example in for_statement
3390 statement_expression
3391 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3392 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3393 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3394 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3395 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3396 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3397 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3399 Report.Error (1002, lexer.Location, "Expecting `;'");
3404 object_creation_expression
3405 : object_or_delegate_creation_expression
3406 { note ("complain if this is a delegate maybe?"); }
3415 : if_statement_open if_statement_rest
3424 oob_stack.Push (lexer.Location);
3429 : boolean_expression CLOSE_PARENS
3432 Location l = (Location) oob_stack.Pop ();
3434 $$ = new If ((Expression) $1, (Statement) $3, l);
3436 if (RootContext.WarningLevel >= 3){
3437 if ($3 == EmptyStatement.Value)
3438 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3442 | boolean_expression CLOSE_PARENS
3443 embedded_statement ELSE embedded_statement
3445 Location l = (Location) oob_stack.Pop ();
3447 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3452 : SWITCH OPEN_PARENS
3454 oob_stack.Push (lexer.Location);
3455 switch_stack.Push (current_block);
3457 expression CLOSE_PARENS
3460 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3461 current_block = (Block) switch_stack.Pop ();
3477 Report.Error (1522, lexer.Location, "Empty switch block");
3485 ArrayList sections = new ArrayList (4);
3490 | switch_sections switch_section
3492 ArrayList sections = (ArrayList) $1;
3502 current_block = current_block.CreateSwitchBlock (lexer.Location);
3506 Block topmost = current_block;
3508 while (topmost.Implicit)
3509 topmost = topmost.Parent;
3510 $$ = new SwitchSection ((ArrayList) $1, topmost);
3517 ArrayList labels = new ArrayList (4);
3522 | switch_labels switch_label
3524 ArrayList labels = (ArrayList) ($1);
3532 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3533 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3536 1523, lexer.Location,
3537 "The keyword case or default must precede code in switch block");
3551 oob_stack.Push (lexer.Location);
3553 boolean_expression CLOSE_PARENS embedded_statement
3555 Location l = (Location) oob_stack.Pop ();
3556 $$ = new While ((Expression) $4, (Statement) $6, l);
3558 if (RootContext.WarningLevel >= 3){
3559 if ($6 == EmptyStatement.Value)
3560 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3566 : DO embedded_statement
3568 oob_stack.Push (lexer.Location);
3570 boolean_expression CLOSE_PARENS SEMICOLON
3572 Location l = (Location) oob_stack.Pop ();
3574 $$ = new Do ((Statement) $2, (Expression) $6, l);
3580 opt_for_initializer SEMICOLON
3582 Block assign_block = new Block (current_block);
3583 current_block = assign_block;
3585 if ($3 is DictionaryEntry){
3586 DictionaryEntry de = (DictionaryEntry) $3;
3588 Expression type = (Expression) de.Key;
3589 ArrayList var_declarators = (ArrayList) de.Value;
3591 foreach (VariableDeclaration decl in var_declarators){
3595 vi = current_block.AddVariable (
3596 type, decl.identifier, current_local_parameters, decl.Location);
3600 Location l = lexer.Location;
3602 if (decl.expression_or_array_initializer is Expression){
3603 expr = (Expression) decl.expression_or_array_initializer;
3604 } else if (decl.expression_or_array_initializer == null) {
3607 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3608 expr = new ArrayCreation (type, "", init, decl.Location);
3611 LocalVariableReference var;
3612 var = new LocalVariableReference (assign_block, decl.identifier, l);
3615 Assign a = new Assign (var, expr, decl.Location);
3617 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3623 oob_stack.Push (lexer.Location);
3625 opt_for_condition SEMICOLON
3626 opt_for_iterator CLOSE_PARENS
3629 Location l = (Location) oob_stack.Pop ();
3631 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3633 if (RootContext.WarningLevel >= 3){
3634 if ($10 == EmptyStatement.Value)
3635 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3638 current_block.AddStatement (f);
3639 while (current_block.Implicit)
3640 current_block = current_block.Parent;
3642 current_block = current_block.Parent;
3647 : /* empty */ { $$ = EmptyStatement.Value; }
3652 : local_variable_declaration
3653 | statement_expression_list
3657 : /* empty */ { $$ = null; }
3658 | boolean_expression
3662 : /* empty */ { $$ = EmptyStatement.Value; }
3667 : statement_expression_list
3670 statement_expression_list
3671 : statement_expression
3673 // CHANGE: was `null'
3674 Block b = new Block (current_block, Block.Flags.Implicit);
3676 b.AddStatement ((Statement) $1);
3679 | statement_expression_list COMMA statement_expression
3681 Block b = (Block) $1;
3683 b.AddStatement ((Statement) $3);
3689 : FOREACH OPEN_PARENS type IDENTIFIER IN
3691 oob_stack.Push (lexer.Location);
3693 expression CLOSE_PARENS
3695 oob_stack.Push (current_block);
3697 Block foreach_block = new Block (current_block, Block.Flags.Implicit);
3698 LocalVariableReference v = null;
3699 Location l = lexer.Location;
3702 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3706 // Get a writable reference to this read-only variable.
3707 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3709 current_block = foreach_block;
3712 oob_stack.Push (current_block);
3716 Block foreach_block = (Block) oob_stack.Pop ();
3717 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3718 Block prev_block = (Block) oob_stack.Pop ();
3719 Location l = (Location) oob_stack.Pop ();
3721 current_block = prev_block;
3724 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3725 foreach_block.AddStatement (f);
3734 | continue_statement
3744 $$ = new Break (lexer.Location);
3749 : CONTINUE SEMICOLON
3751 $$ = new Continue (lexer.Location);
3756 : GOTO IDENTIFIER SEMICOLON
3758 $$ = new Goto (current_block, (string) $2, lexer.Location);
3760 | GOTO CASE constant_expression SEMICOLON
3762 $$ = new GotoCase ((Expression) $3, lexer.Location);
3764 | GOTO DEFAULT SEMICOLON
3766 $$ = new GotoDefault (lexer.Location);
3771 : RETURN opt_expression SEMICOLON
3773 $$ = new Return ((Expression) $2, lexer.Location);
3778 : THROW opt_expression SEMICOLON
3780 $$ = new Throw ((Expression) $2, lexer.Location);
3785 : YIELD RETURN expression SEMICOLON
3787 if (iterator_container == null){
3788 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3791 iterator_container.SetYields ();
3792 $$ = new Yield ((Expression) $3, lexer.Location);
3795 | YIELD expression SEMICOLON
3797 if (iterator_container == null){
3798 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3801 iterator_container.SetYields ();
3802 $$ = new Yield ((Expression) $2, lexer.Location);
3805 | YIELD BREAK SEMICOLON
3807 if (iterator_container == null){
3808 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
3811 iterator_container.SetYields ();
3812 $$ = new YieldBreak (lexer.Location);
3823 : TRY block catch_clauses
3826 ArrayList s = new ArrayList (4);
3828 foreach (Catch cc in (ArrayList) $3) {
3835 // Now s contains the list of specific catch clauses
3836 // and g contains the general one.
3838 $$ = new Try ((Block) $2, s, g, null, lexer.Location);
3840 | TRY block opt_catch_clauses FINALLY block
3843 ArrayList s = new ArrayList (4);
3844 ArrayList catch_list = (ArrayList) $3;
3846 if (catch_list != null){
3847 foreach (Catch cc in catch_list) {
3855 $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
3859 Report.Error (1524, lexer.Location, "Expected catch or finally");
3864 : /* empty */ { $$ = null; }
3871 ArrayList l = new ArrayList (4);
3876 | catch_clauses catch_clause
3878 ArrayList l = (ArrayList) $1;
3886 : /* empty */ { $$ = null; }
3891 : CATCH opt_catch_args
3893 Expression type = null;
3897 DictionaryEntry cc = (DictionaryEntry) $2;
3898 type = (Expression) cc.Key;
3899 id = (string) cc.Value;
3902 ArrayList one = new ArrayList (4);
3903 Location loc = lexer.Location;
3905 one.Add (new VariableDeclaration (id, null, loc));
3908 current_block = new Block (current_block);
3909 Block b = declare_local_variables (type, one, loc);
3914 Expression type = null;
3918 DictionaryEntry cc = (DictionaryEntry) $2;
3919 type = (Expression) cc.Key;
3920 id = (string) cc.Value;
3924 // FIXME: I can change this for an assignment.
3926 while (current_block != (Block) $1)
3927 current_block = current_block.Parent;
3932 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3937 : /* empty */ { $$ = null; }
3942 : OPEN_PARENS type opt_identifier CLOSE_PARENS
3944 $$ = new DictionaryEntry ($2, $3);
3951 $$ = new Checked ((Block) $2);
3958 $$ = new Unchecked ((Block) $2);
3965 if (!RootContext.Unsafe){
3966 Report.Error (227, lexer.Location,
3967 "Unsafe code can only be used if --unsafe is used");
3970 $$ = new Unsafe ((Block) $3);
3976 type fixed_pointer_declarators
3979 Block assign_block = new Block (current_block, Block.Flags.Implicit);
3980 ArrayList list = (ArrayList) $4;
3981 Expression type = (Expression) $3;
3982 Location l = lexer.Location;
3983 int top = list.Count;
3985 for (int i = 0; i < top; i++){
3986 Pair p = (Pair) list [i];
3989 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
3996 current_block.AddStatement (assign_block);
3997 current_block = assign_block;
3998 oob_stack.Push (assign_block);
4003 Location l = (Location) oob_stack.Pop ();
4006 $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4010 fixed_pointer_declarators
4011 : fixed_pointer_declarator {
4012 ArrayList declarators = new ArrayList (4);
4013 declarators.Add ($1);
4016 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4018 ArrayList declarators = (ArrayList) $1;
4019 declarators.Add ($3);
4024 fixed_pointer_declarator
4025 : IDENTIFIER ASSIGN expression
4027 $$ = new Pair ($1, $3);
4032 : LOCK OPEN_PARENS expression CLOSE_PARENS
4038 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4043 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4045 Block assign_block = new Block (current_block);
4046 current_block = assign_block;
4048 oob_stack.Push (lexer.Location);
4050 if ($3 is DictionaryEntry){
4051 DictionaryEntry de = (DictionaryEntry) $3;
4052 Location l = lexer.Location;
4054 Expression type = (Expression) de.Key;
4055 ArrayList var_declarators = (ArrayList) de.Value;
4057 ArrayList vars = new ArrayList (4);
4059 foreach (VariableDeclaration decl in var_declarators){
4061 LocalInfo vi = current_block.AddVariable (
4062 type, decl.identifier,
4063 current_local_parameters, decl.Location);
4069 if (decl.expression_or_array_initializer is Expression){
4070 expr = (Expression) decl.expression_or_array_initializer;
4072 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4074 expr = new ArrayCreation (type, "", init, decl.Location);
4077 LocalVariableReference var;
4079 // Get a writable reference to this read-only variable.
4080 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4082 // This is so that it is not a warning on using variables
4085 vars.Add (new DictionaryEntry (var, expr));
4087 // Assign a = new Assign (var, expr, decl.Location);
4088 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4090 $3 = new DictionaryEntry (type, vars);
4095 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4096 current_block.AddStatement (u);
4097 while (current_block.Implicit)
4098 current_block = current_block.Parent;
4100 current_block = current_block.Parent;
4104 resource_acquisition
4105 : local_variable_declaration
4112 // A class used to pass around variable declarations and constants
4114 public class VariableDeclaration {
4115 public string identifier;
4116 public object expression_or_array_initializer;
4117 public Location Location;
4118 public Attributes OptAttributes;
4120 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4122 this.identifier = id;
4123 this.expression_or_array_initializer = eoai;
4125 this.OptAttributes = opt_attrs;
4128 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4134 // A class used to hold info about an indexer declarator
4136 public class IndexerDeclaration {
4137 public Expression type;
4138 public string interface_type;
4139 public Parameters param_list;
4141 public IndexerDeclaration (Expression type, string interface_type, Parameters param_list)
4144 this.interface_type = interface_type;
4145 this.param_list = param_list;
4150 // A class used to hold info about an operator declarator
4152 public class OperatorDeclaration {
4153 public Operator.OpType optype;
4154 public Expression ret_type, arg1type, arg2type;
4155 public string arg1name, arg2name;
4156 public Location location;
4158 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4159 Expression arg1type, string arg1name,
4160 Expression arg2type, string arg2name, Location location)
4163 this.ret_type = ret_type;
4164 this.arg1type = arg1type;
4165 this.arg1name = arg1name;
4166 this.arg2type = arg2type;
4167 this.arg2name = arg2name;
4168 this.location = location;
4173 public class QualifiedIdentifier {
4175 public QualifiedIdentifier prev;
4177 public QualifiedIdentifier (string s)
4183 public QualifiedIdentifier (QualifiedIdentifier prev, string s)
4189 public override string ToString ()
4196 if (prev.prev == null)
4197 return prev.s + "." + s;
4198 if (prev.prev.prev == null)
4199 return prev.prev.s + "." + prev.s + "." + s;
4202 QualifiedIdentifier ptr = this.prev;
4204 while (ptr != null){
4208 string [] ss = new string [count];
4210 for (int i = count; i-- > 0;){
4214 return String.Join (".", ss, 0, ss.Length);
4218 void Error_ExpectingTypeName (Location l, Expression expr)
4220 if (expr is Invocation){
4221 Report.Error (1002, l, "; expected");
4223 Report.Error (-1, l, "Invalid Type definition");
4228 // Given the @class_name name, it creates a fully qualified name
4229 // based on the containing declaration space
4232 MakeName (string class_name)
4234 string ns = current_namespace.FullName;
4235 string container_name = current_container.Name;
4237 if (container_name == ""){
4239 return ns + "." + class_name;
4243 return container_name + "." + class_name;
4247 // Used to report back to the user the result of a declaration
4248 // in the current declaration space
4251 CheckDef (DeclSpace.AdditionResult result, string name, Location l)
4253 if (result == DeclSpace.AdditionResult.Success)
4257 case DeclSpace.AdditionResult.NameExists:
4258 Report.Error (102, l, "The container `" + current_container.Name +
4259 "' already contains a definition for `"+
4265 // This is handled only for static Constructors, because
4266 // in reality we handle these by the semantic analysis later
4268 case DeclSpace.AdditionResult.MethodExists:
4270 111, l, "Class `"+current_container.Name+
4271 "' already defines a member called '" +
4272 name + "' with the same parameter types (more than one default constructor)");
4275 case DeclSpace.AdditionResult.EnclosingClash:
4276 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
4279 case DeclSpace.AdditionResult.NotAConstructor:
4280 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
4283 case DeclSpace.AdditionResult.Error:
4284 // Error has already been reported.
4290 CheckDef (bool result, string name, Location l)
4294 CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
4297 Expression DecomposeQI (QualifiedIdentifier qi, Location loc)
4301 if (qi.prev == null)
4302 return new SimpleName (qi.s, loc);
4304 o = DecomposeQI (qi.prev, loc);
4305 return new MemberAccess (o, qi.s, loc);
4309 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4311 Block implicit_block;
4312 ArrayList inits = null;
4315 // We use the `Used' property to check whether statements
4316 // have been added to the current block. If so, we need
4317 // to create another block to contain the new declaration
4318 // otherwise, as an optimization, we use the same block to
4319 // add the declaration.
4321 // FIXME: A further optimization is to check if the statements
4322 // that were added were added as part of the initialization
4323 // below. In which case, no other statements have been executed
4324 // and we might be able to reduce the number of blocks for
4325 // situations like this:
4327 // int j = 1; int k = j + 1;
4329 if (current_block.Used) {
4330 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4331 implicit_block.AddChildVariableNames (current_block);
4333 implicit_block = current_block;
4335 foreach (VariableDeclaration decl in variable_declarators){
4337 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4338 if (decl.expression_or_array_initializer != null){
4340 inits = new ArrayList (4);
4347 return implicit_block;
4349 foreach (VariableDeclaration decl in inits){
4353 if (decl.expression_or_array_initializer is Expression){
4354 expr = (Expression) decl.expression_or_array_initializer;
4357 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4359 expr = new ArrayCreation (type, "", init, decl.Location);
4362 LocalVariableReference var;
4363 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4365 assign = new Assign (var, expr, decl.Location);
4367 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4370 return implicit_block;
4373 Block declare_local_constants (Expression type, ArrayList declarators)
4375 Block implicit_block;
4377 if (current_block.Used)
4378 implicit_block = new Block (current_block, Block.Flags.Implicit);
4380 implicit_block = current_block;
4382 foreach (VariableDeclaration decl in declarators){
4383 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4384 current_local_parameters, decl.Location);
4387 return implicit_block;
4390 void CheckAttributeTarget (string a)
4394 case "assembly" : case "field" : case "method" : case "param" : case "property" : case "type" :
4398 Location l = lexer.Location;
4399 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4405 void CheckUnaryOperator (Operator.OpType op)
4409 case Operator.OpType.LogicalNot:
4410 case Operator.OpType.OnesComplement:
4411 case Operator.OpType.Increment:
4412 case Operator.OpType.Decrement:
4413 case Operator.OpType.True:
4414 case Operator.OpType.False:
4415 case Operator.OpType.Addition:
4416 case Operator.OpType.Subtraction:
4421 Location l = lexer.Location;
4422 Report.Error (1019, l, "Overloadable unary operator expected");
4428 void CheckBinaryOperator (Operator.OpType op)
4432 case Operator.OpType.Addition:
4433 case Operator.OpType.Subtraction:
4434 case Operator.OpType.Multiply:
4435 case Operator.OpType.Division:
4436 case Operator.OpType.Modulus:
4437 case Operator.OpType.BitwiseAnd:
4438 case Operator.OpType.BitwiseOr:
4439 case Operator.OpType.ExclusiveOr:
4440 case Operator.OpType.LeftShift:
4441 case Operator.OpType.RightShift:
4442 case Operator.OpType.Equality:
4443 case Operator.OpType.Inequality:
4444 case Operator.OpType.GreaterThan:
4445 case Operator.OpType.LessThan:
4446 case Operator.OpType.GreaterThanOrEqual:
4447 case Operator.OpType.LessThanOrEqual:
4451 Location l = lexer.Location;
4452 Report.Error (1020, l, "Overloadable binary operator expected");
4458 void syntax_error (Location l, string msg)
4460 Report.Error (1003, l, "Syntax error, " + msg);
4463 void output (string s)
4465 Console.WriteLine (s);
4468 void note (string s)
4470 // Used to put annotations
4475 public Tokenizer Lexer {
4481 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4483 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4484 this.name = file.Name;
4486 current_container = RootContext.Tree.Types;
4487 current_container.NamespaceEntry = current_namespace;
4488 oob_stack = new Stack ();
4489 switch_stack = new Stack ();
4491 lexer = new Tokenizer (reader, file, defines);
4494 public void parse ()
4497 if (yacc_verbose_flag)
4498 yyparse (lexer, new yydebug.yyDebugSimple ());
4501 Tokenizer tokenizer = lexer as Tokenizer;
4502 tokenizer.cleanup ();
4503 } catch (Exception e){
4504 // Please do not remove this, it is used during debugging
4507 Console.WriteLine (e);
4508 Report.Error (-25, lexer.Location, "Parsing error");
4509 if (Driver.parser_verbose)
4510 Console.WriteLine (e);
4514 void CheckToken (int error, int yyToken, string msg)
4516 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4517 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4520 Report.Error (error, lexer.Location, msg);
4523 void CheckIdentifierToken (int yyToken)
4525 CheckToken (1041, yyToken, "Identifier expected");