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)
11 // (C) 2004 Novell, Inc
14 // (1) Figure out why error productions dont work. `type-declaration' is a
15 // great spot to put an `error' because you can reproduce it with this input:
18 // Possible optimization:
19 // Run memory profiler with parsing only, and consider dropping
20 // arraylists where not needed. Some pieces can use linked lists.
28 using System.Collections;
33 public class CSharpParser {
34 NamespaceEntry current_namespace;
35 TypeContainer current_container;
36 TypeContainer current_class;
38 IIteratorContainer iterator_container;
41 /// Current block is used to add statements as we find
44 Block current_block, top_current_block;
47 /// This is used by the unary_expression code to resolve
48 /// a name against a parameter.
50 Parameters current_local_parameters;
53 /// Using during property parsing to describe the implicit
54 /// value parameter that is passed to the "set" and "get"accesor
55 /// methods (properties and indexers).
57 Expression implicit_value_parameter_type;
58 Parameters indexer_parameters;
61 /// Used to determine if we are parsing the get/set pair
62 /// of an indexer or a property
67 /// An out-of-band stack.
76 static public int yacc_verbose_flag;
78 // Name of the file we are parsing
87 /// Temporary Xml documentation cache.
88 /// For enum types, we need one more temporary store.
91 string enumTypeComment;
93 /// Current attribute target
94 string current_attr_target;
96 /// assembly and module attribute definitions are enabled
97 bool global_attrs_enabled = true;
99 bool has_get, has_set;
104 %token NONE /* This token is never returned by our lexer */
105 %token ERROR // This is used not by the parser, but by the tokenizer.
109 *These are the C# keywords
195 /* C# keywords which are not really keywords */
201 /* C# single character operators/punctuation. */
202 %token OPEN_BRACE "{"
203 %token CLOSE_BRACE "}"
204 %token OPEN_BRACKET "["
205 %token CLOSE_BRACKET "]"
206 %token OPEN_PARENS "("
207 %token CLOSE_PARENS ")"
220 %token BITWISE_AND "&"
221 %token BITWISE_OR "|"
228 /* C# multi-character operators. */
231 %token OP_SHIFT_LEFT "<<"
232 %token OP_SHIFT_RIGHT ">>"
239 %token OP_MULT_ASSIGN "*="
240 %token OP_DIV_ASSIGN "/="
241 %token OP_MOD_ASSIGN "%="
242 %token OP_ADD_ASSIGN "+="
243 %token OP_SUB_ASSIGN "-="
244 %token OP_SHIFT_LEFT_ASSIGN "<<="
245 %token OP_SHIFT_RIGHT_ASSIGN ">>="
246 %token OP_AND_ASSIGN "&="
247 %token OP_XOR_ASSIGN "^="
248 %token OP_OR_ASSIGN "|="
252 %token LITERAL_INTEGER "int literal"
253 %token LITERAL_FLOAT "float literal"
254 %token LITERAL_DOUBLE "double literal"
255 %token LITERAL_DECIMAL "decimal literal"
256 %token LITERAL_CHARACTER "character literal"
257 %token LITERAL_STRING "string literal"
260 %token CLOSE_PARENS_CAST
261 %token CLOSE_PARENS_NO_CAST
262 %token CLOSE_PARENS_OPEN_PARENS
263 %token CLOSE_PARENS_MINUS
265 /* Add precedence rules to solve dangling else s/r conflict */
274 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
276 %left STAR DIV PERCENT
277 %right BANG CARRET UMINUS
278 %nonassoc OP_INC OP_DEC
280 %left OPEN_BRACKET OPEN_BRACE
284 %start compilation_unit
288 : outer_declarations opt_EOF
289 | outer_declarations global_attributes opt_EOF
290 | global_attributes opt_EOF
291 | opt_EOF /* allow empty files */
297 Lexer.check_incorrect_doc_comment ();
301 Lexer.check_incorrect_doc_comment ();
307 | outer_declarations outer_declaration
312 | namespace_member_declaration
317 | using_directives using_directive
321 : using_alias_directive
323 if (RootContext.Documentation != null)
324 Lexer.doc_state = XmlCommentState.Allowed;
326 | using_namespace_directive
328 if (RootContext.Documentation != null)
329 Lexer.doc_state = XmlCommentState.Allowed;
333 using_alias_directive
334 : USING IDENTIFIER ASSIGN
335 namespace_or_type_name SEMICOLON
337 current_namespace.UsingAlias ((string) $2, (MemberName) $4, lexer.Location);
340 CheckIdentifierToken (yyToken);
344 using_namespace_directive
345 : USING namespace_name SEMICOLON
347 current_namespace.Using ((MemberName) $2, lexer.Location);
352 // Strictly speaking, namespaces don't have attributes but
353 // we parse global attributes along with namespace declarations and then
356 namespace_declaration
357 : opt_attributes NAMESPACE namespace_or_type_name
360 Report.Error(1671, Lexer.Location, "A namespace declaration cannot have modifiers or attributes");
363 MemberName name = (MemberName) $3;
365 current_namespace = new NamespaceEntry (
366 current_namespace, file, name.GetName (), lexer.Location);
368 namespace_body opt_semicolon
370 current_namespace = current_namespace.Parent;
385 : namespace_or_type_name
391 if (RootContext.Documentation != null)
392 Lexer.doc_state = XmlCommentState.Allowed;
395 opt_namespace_member_declarations
404 opt_namespace_member_declarations
406 | namespace_member_declarations
409 namespace_member_declarations
410 : namespace_member_declaration
411 | namespace_member_declarations namespace_member_declaration
414 namespace_member_declaration
418 DeclSpace ds = (DeclSpace)$1;
420 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
421 Report.Error (1527, lexer.Location,
422 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
425 current_namespace.DeclarationFound = true;
427 | namespace_declaration {
428 current_namespace.DeclarationFound = true;
431 | field_declaration {
432 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
434 | method_declaration {
435 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
442 | interface_declaration
444 | delegate_declaration
446 // Enable this when we have handled all errors, because this acts as a generic fallback
449 // Console.WriteLine ("Token=" + yyToken);
450 // Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
462 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
470 global_attrs_enabled = false;
475 global_attrs_enabled = false;
484 ArrayList sect = (ArrayList) $1;
486 if (global_attrs_enabled) {
487 if (current_attr_target == "module") {
488 CodeGen.Module.AddAttributes (sect);
490 } else if (current_attr_target != null && current_attr_target.Length > 0) {
491 CodeGen.Assembly.AddAttributes (sect);
494 $$ = new Attributes (sect);
497 if (RootContext.Documentation != null) {
498 Lexer.check_incorrect_doc_comment ();
500 XmlCommentState.Allowed;
504 $$ = new Attributes (sect);
506 current_attr_target = null;
508 | attribute_sections attribute_section
510 Attributes attrs = $1 as Attributes;
511 ArrayList sect = (ArrayList) $2;
513 if (global_attrs_enabled) {
514 if (current_attr_target == "module") {
515 CodeGen.Module.AddAttributes (sect);
517 } else if (current_attr_target == "assembly") {
518 CodeGen.Assembly.AddAttributes (sect);
522 attrs = new Attributes (sect);
524 attrs.AddAttributes (sect);
528 attrs = new Attributes (sect);
530 attrs.AddAttributes (sect);
533 current_attr_target = null;
538 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
542 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
548 attribute_target_specifier
549 : attribute_target COLON
551 current_attr_target = (string)$1;
559 CheckAttributeTarget ((string) $1);
562 | EVENT { $$ = "event"; }
563 | RETURN { $$ = "return"; }
569 ArrayList attrs = new ArrayList (4);
575 | attribute_list COMMA attribute
577 ArrayList attrs = (ArrayList) $1;
589 opt_attribute_arguments
591 Location loc = (Location) $2;
592 MemberName mname = (MemberName) $1;
593 MemberName left = mname.Left;
594 string identifier = mname.Name;
596 Expression left_expr = left == null ? null : left.GetTypeExpression (loc);
598 if (current_attr_target == "assembly" || current_attr_target == "module")
599 $$ = new GlobalAttribute (current_class, current_attr_target,
600 left_expr, identifier, (ArrayList) $3, loc);
602 $$ = new Attribute (current_attr_target, left_expr, identifier, (ArrayList) $3, loc);
607 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
610 opt_attribute_arguments
611 : /* empty */ { $$ = null; }
612 | OPEN_PARENS attribute_arguments CLOSE_PARENS
620 : opt_positional_argument_list
625 ArrayList args = new ArrayList (4);
631 | positional_argument_list COMMA named_argument_list
633 ArrayList args = new ArrayList (4);
639 | named_argument_list
641 ArrayList args = new ArrayList (4);
650 opt_positional_argument_list
651 : /* empty */ { $$ = null; }
652 | positional_argument_list
655 positional_argument_list
658 ArrayList args = new ArrayList (4);
659 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
663 | positional_argument_list COMMA expression
665 ArrayList args = (ArrayList) $1;
666 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
675 ArrayList args = new ArrayList (4);
680 | named_argument_list COMMA named_argument
682 ArrayList args = (ArrayList) $1;
687 | named_argument_list COMMA expression
689 Report.Error (1016, lexer.Location, "Named attribute argument expected");
695 : IDENTIFIER ASSIGN expression
697 $$ = new DictionaryEntry (
699 new Argument ((Expression) $3, Argument.AType.Expression));
705 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
708 opt_class_member_declarations
710 | class_member_declarations
713 class_member_declarations
714 : class_member_declaration
715 | class_member_declarations
716 class_member_declaration
719 class_member_declaration
720 : constant_declaration // done
721 | field_declaration // done
722 | method_declaration // done
723 | property_declaration // done
724 | event_declaration // done
725 | indexer_declaration // done
726 | operator_declaration // done
727 | constructor_declaration // done
728 | destructor_declaration // done
738 MemberName name = MakeName ((MemberName) $5);
739 bool partial = (bool) $3;
742 ClassPart part = PartialContainer.CreatePart (
743 current_namespace, current_class, name, (int) $2,
744 (Attributes) $1, Kind.Struct, lexer.Location);
746 current_container = part.PartialContainer;
747 current_class = part;
749 current_class = new Struct (
750 current_namespace, current_class, name, (int) $2,
751 (Attributes) $1, lexer.Location);
753 current_container.AddClassOrStruct (current_class);
754 current_container = current_class;
755 RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
761 current_class.Bases = (ArrayList) $7;
763 if (RootContext.Documentation != null)
764 current_class.DocComment = Lexer.consume_doc_comment ();
768 if (RootContext.Documentation != null)
769 Lexer.doc_state = XmlCommentState.Allowed;
773 $$ = pop_current_class ();
775 | opt_attributes opt_modifiers opt_partial STRUCT error {
776 CheckIdentifierToken (yyToken);
783 if (RootContext.Documentation != null)
784 Lexer.doc_state = XmlCommentState.Allowed;
786 opt_struct_member_declarations CLOSE_BRACE
789 opt_struct_member_declarations
791 | struct_member_declarations
794 struct_member_declarations
795 : struct_member_declaration
796 | struct_member_declarations struct_member_declaration
799 struct_member_declaration
800 : constant_declaration
803 | property_declaration
805 | indexer_declaration
806 | operator_declaration
807 | constructor_declaration
811 * This is only included so we can flag error 575:
812 * destructors only allowed on class types
814 | destructor_declaration
825 int modflags = (int) $2;
826 foreach (VariableDeclaration constant in (ArrayList) $5){
827 Location l = constant.Location;
828 if ((modflags & Modifiers.STATIC) != 0) {
829 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
833 Const c = new Const (
834 current_class, (Expression) $4, (string) constant.identifier,
835 (Expression) constant.expression_or_array_initializer, modflags,
838 if (RootContext.Documentation != null) {
839 c.DocComment = Lexer.consume_doc_comment ();
840 Lexer.doc_state = XmlCommentState.Allowed;
842 current_container.AddConstant (c);
848 : constant_declarator
850 ArrayList constants = new ArrayList (4);
855 | constant_declarators COMMA constant_declarator
858 ArrayList constants = (ArrayList) $1;
865 : IDENTIFIER ASSIGN constant_expression
867 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
871 // A const field requires a value to be provided
872 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
884 Expression type = (Expression) $3;
887 foreach (VariableDeclaration var in (ArrayList) $4){
888 Field field = new Field (current_class, type, mod, var.identifier,
889 var.expression_or_array_initializer,
890 (Attributes) $1, var.Location);
892 if (RootContext.Documentation != null) {
893 field.DocComment = Lexer.consume_doc_comment ();
894 Lexer.doc_state = XmlCommentState.Allowed;
896 current_container.AddField (field);
903 fixed_variable_declarators
906 Expression type = (Expression) $4;
909 foreach (VariableDeclaration var in (ArrayList) $5) {
910 FixedField field = new FixedField (current_class, type, mod, var.identifier,
911 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
913 if (RootContext.Documentation != null) {
914 field.DocComment = Lexer.consume_doc_comment ();
915 Lexer.doc_state = XmlCommentState.Allowed;
917 current_container.AddField (field);
925 Report.Error (670, lexer.Location, "Fields cannot have void type");
929 fixed_variable_declarators
930 : fixed_variable_declarator
932 ArrayList decl = new ArrayList (2);
936 | fixed_variable_declarators COMMA fixed_variable_declarator
938 ArrayList decls = (ArrayList) $1;
944 fixed_variable_declarator
945 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
947 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
952 : variable_declarator
954 ArrayList decl = new ArrayList (4);
959 | variable_declarators COMMA variable_declarator
961 ArrayList decls = (ArrayList) $1;
968 : IDENTIFIER ASSIGN variable_initializer
970 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
974 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
976 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
978 Report.Error (650, lexer.Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
979 "To declare a fixed size buffer field, use the fixed keyword before the field type");
993 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
995 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
999 Report.Error (1575, lexer.Location, "A stackalloc expression requires [] after type");
1006 iterator_container = (IIteratorContainer) $1;
1007 if (RootContext.Documentation != null)
1008 Lexer.doc_state = XmlCommentState.NotAllowed;
1012 Method method = (Method) $1;
1013 Block b = (Block) $3;
1014 method.Block = (ToplevelBlock) $3;
1015 current_container.AddMethod (method);
1017 current_local_parameters = null;
1018 iterator_container = null;
1020 if (RootContext.Documentation != null)
1021 Lexer.doc_state = XmlCommentState.Allowed;
1034 Report.Error (1585, lexer.Location,
1035 "Member modifier `{0}' must precede the member type and name",
1036 Modifiers.Name (i));
1047 type namespace_or_type_name
1048 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1050 MemberName name = (MemberName) $4;
1052 Method method = new Method (current_class, (Expression) $3, (int) $2,
1053 false, name, (Parameters) $6, (Attributes) $1,
1056 current_local_parameters = (Parameters) $6;
1058 if (RootContext.Documentation != null)
1059 method.DocComment = Lexer.consume_doc_comment ();
1065 VOID namespace_or_type_name
1066 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1068 MemberName name = (MemberName) $4;
1070 Method method = new Method (current_class, TypeManager.system_void_expr,
1071 (int) $2, false, name, (Parameters) $6,
1072 (Attributes) $1, lexer.Location);
1074 current_local_parameters = (Parameters) $6;
1076 if (RootContext.Documentation != null)
1077 method.DocComment = Lexer.consume_doc_comment ();
1084 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1086 Report.Error (1585, lexer.Location,
1087 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1088 MemberName name = (MemberName) $4;
1090 Method method = new Method (current_class, TypeManager.system_void_expr,
1091 0, false, name, (Parameters) $7, (Attributes) $1,
1094 current_local_parameters = (Parameters) $7;
1096 if (RootContext.Documentation != null)
1097 method.DocComment = Lexer.consume_doc_comment ();
1105 | SEMICOLON { $$ = null; }
1108 opt_formal_parameter_list
1109 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1110 | formal_parameter_list
1113 formal_parameter_list
1116 ArrayList pars_list = (ArrayList) $1;
1118 Parameter [] pars = new Parameter [pars_list.Count];
1119 pars_list.CopyTo (pars);
1121 $$ = new Parameters (pars, null);
1123 | fixed_parameters COMMA parameter_array
1125 ArrayList pars_list = (ArrayList) $1;
1127 Parameter [] pars = new Parameter [pars_list.Count];
1128 pars_list.CopyTo (pars);
1130 $$ = new Parameters (pars, (Parameter) $3);
1132 | fixed_parameters COMMA ARGLIST
1134 ArrayList pars_list = (ArrayList) $1;
1136 Parameter [] pars = new Parameter [pars_list.Count];
1137 pars_list.CopyTo (pars);
1139 $$ = new Parameters (pars, true);
1141 | parameter_array COMMA fixed_parameters
1143 Report.Error (231, lexer.Location, "A params parameter must be the last parameter in a formal parameter list");
1146 | ARGLIST COMMA fixed_parameters
1148 Report.Error (257, lexer.Location, "An __arglist parameter must be the last parameter in a formal parameter list");
1153 $$ = new Parameters (null, (Parameter) $1);
1157 $$ = new Parameters (null, true);
1164 ArrayList pars = new ArrayList (4);
1169 | fixed_parameters COMMA fixed_parameter
1171 ArrayList pars = (ArrayList) $1;
1180 opt_parameter_modifier
1184 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1, lexer.Location);
1187 opt_parameter_modifier
1189 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1191 Report.Error (1552, lexer.Location, "Array type specifier, [], must appear before parameter name");
1195 opt_parameter_modifier
1198 Report.Error (1001, lexer.Location, "Identifier expected");
1202 opt_parameter_modifier
1205 CheckIdentifierToken (yyToken);
1209 opt_parameter_modifier
1215 Report.Error (241, lexer.Location, "Default parameter specifiers are not permitted");
1220 opt_parameter_modifier
1221 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1222 | parameter_modifier
1226 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1227 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1231 : opt_attributes PARAMS type IDENTIFIER
1233 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1, lexer.Location);
1234 note ("type must be a single-dimension array type");
1236 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1238 Report.Error (1611, lexer.Location, "The params parameter cannot be declared as ref or out");
1241 | opt_attributes PARAMS type error {
1242 CheckIdentifierToken (yyToken);
1247 property_declaration
1251 namespace_or_type_name
1253 if (RootContext.Documentation != null)
1254 tmpComment = Lexer.consume_doc_comment ();
1258 implicit_value_parameter_type = (Expression) $3;
1260 lexer.PropertyParsing = true;
1262 $$ = lexer.Location;
1264 iterator_container = SimpleIteratorContainer.GetSimple ();
1266 accessor_declarations
1268 lexer.PropertyParsing = false;
1269 has_get = has_set = false;
1277 Pair pair = (Pair) $8;
1278 Accessor get_block = (Accessor) pair.First;
1279 Accessor set_block = (Accessor) pair.Second;
1281 Location loc = (Location) $7;
1282 MemberName name = (MemberName) $4;
1284 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1285 name, (Attributes) $1, get_block, set_block, loc);
1286 if (SimpleIteratorContainer.Simple.Yields)
1289 current_container.AddProperty (prop);
1290 implicit_value_parameter_type = null;
1291 iterator_container = null;
1293 if (RootContext.Documentation != null)
1294 prop.DocComment = ConsumeStoredComment ();
1299 accessor_declarations
1300 : get_accessor_declaration
1302 $$ = new Pair ($1, null);
1304 | get_accessor_declaration accessor_declarations
1306 Pair pair = (Pair) $2;
1310 | set_accessor_declaration
1312 $$ = new Pair (null, $1);
1314 | set_accessor_declaration accessor_declarations
1316 Pair pair = (Pair) $2;
1322 Report.Error (1014, lexer.Location, "A get or set accessor expected");
1327 get_accessor_declaration
1328 : opt_attributes opt_modifiers GET
1330 // If this is not the case, then current_local_parameters has already
1331 // been set in indexer_declaration
1332 if (parsing_indexer == false)
1333 current_local_parameters = null;
1335 current_local_parameters = indexer_parameters;
1336 lexer.PropertyParsing = false;
1341 Report.Error (1007, lexer.Location, "Property accessor already defined");
1344 $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
1346 current_local_parameters = null;
1347 lexer.PropertyParsing = true;
1349 if (RootContext.Documentation != null)
1350 if (Lexer.doc_state == XmlCommentState.Error)
1351 Lexer.doc_state = XmlCommentState.NotAllowed;
1355 set_accessor_declaration
1356 : opt_attributes opt_modifiers SET
1359 Parameter implicit_value_parameter = new Parameter (
1360 implicit_value_parameter_type, "value",
1361 Parameter.Modifier.NONE, null, lexer.Location);
1363 if (parsing_indexer == false) {
1364 args = new Parameter [1];
1365 args [0] = implicit_value_parameter;
1366 current_local_parameters = new Parameters (args, null);
1368 Parameter [] fpars = indexer_parameters.FixedParameters;
1371 int count = fpars.Length;
1373 args = new Parameter [count + 1];
1374 fpars.CopyTo (args, 0);
1375 args [count] = implicit_value_parameter;
1378 current_local_parameters = new Parameters (
1379 args, indexer_parameters.ArrayParameter);
1382 lexer.PropertyParsing = false;
1387 Report.Error (1007, lexer.Location, "Property accessor already defined");
1390 $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
1392 current_local_parameters = null;
1393 lexer.PropertyParsing = true;
1395 if (RootContext.Documentation != null
1396 && Lexer.doc_state == XmlCommentState.Error)
1397 Lexer.doc_state = XmlCommentState.NotAllowed;
1403 | SEMICOLON { $$ = null; }
1406 interface_declaration
1410 INTERFACE member_name
1412 MemberName name = MakeName ((MemberName) $5);
1413 bool partial = (bool) $3;
1416 ClassPart part = PartialContainer.CreatePart (
1417 current_namespace, current_class, name, (int) $2,
1418 (Attributes) $1, Kind.Interface, lexer.Location);
1420 current_container = part.PartialContainer;
1421 current_class = part;
1423 current_class = new Interface (
1424 current_namespace, current_class, name, (int) $2,
1425 (Attributes) $1, lexer.Location);
1427 current_container.AddInterface (current_class);
1428 current_container = current_class;
1429 RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
1434 current_class.Bases = (ArrayList) $7;
1436 if (RootContext.Documentation != null) {
1437 current_class.DocComment = Lexer.consume_doc_comment ();
1438 Lexer.doc_state = XmlCommentState.Allowed;
1443 if (RootContext.Documentation != null)
1444 Lexer.doc_state = XmlCommentState.Allowed;
1448 $$ = pop_current_class ();
1450 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1451 CheckIdentifierToken (yyToken);
1457 opt_interface_member_declarations
1461 opt_interface_member_declarations
1463 | interface_member_declarations
1466 interface_member_declarations
1467 : interface_member_declaration
1468 | interface_member_declarations interface_member_declaration
1471 interface_member_declaration
1472 : interface_method_declaration
1477 Method m = (Method) $1;
1479 if (m.IsExplicitImpl)
1480 Report.Error (541, lexer.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1481 m.GetSignatureForError ());
1483 current_container.AddMethod (m);
1485 if (RootContext.Documentation != null)
1486 Lexer.doc_state = XmlCommentState.Allowed;
1488 | interface_property_declaration
1493 Property p = (Property) $1;
1495 if (p.IsExplicitImpl)
1496 Report.Error (541, lexer.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1497 p.GetSignatureForError ());
1499 current_container.AddProperty (p);
1501 if (RootContext.Documentation != null)
1502 Lexer.doc_state = XmlCommentState.Allowed;
1504 | interface_event_declaration
1507 Event e = (Event) $1;
1509 if (e.IsExplicitImpl)
1510 Report.Error (541, lexer.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1511 e.GetSignatureForError ());
1513 current_container.AddEvent (e);
1516 if (RootContext.Documentation != null)
1517 Lexer.doc_state = XmlCommentState.Allowed;
1519 | interface_indexer_declaration
1524 Indexer i = (Indexer) $1;
1526 if (i.IsExplicitImpl)
1527 Report.Error (541, lexer.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1528 i.GetSignatureForError ());
1530 current_container.AddIndexer (i);
1532 if (RootContext.Documentation != null)
1533 Lexer.doc_state = XmlCommentState.Allowed;
1535 | delegate_declaration
1538 Report.Error (524, lexer.Location, "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1539 ((MemberCore)$1).GetSignatureForError ());
1545 Report.Error (524, lexer.Location, "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1546 ((MemberCore)$1).GetSignatureForError ());
1549 | struct_declaration
1552 Report.Error (524, lexer.Location, "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1553 ((MemberCore)$1).GetSignatureForError ());
1559 Report.Error (524, lexer.Location, "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1560 ((MemberCore)$1).GetSignatureForError ());
1563 | interface_declaration
1566 Report.Error (524, lexer.Location, "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1567 ((MemberCore)$1).GetSignatureForError ());
1570 | constant_declaration
1572 Report.Error (525, lexer.Location, "Interfaces cannot contain fields or constants");
1580 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1585 interface_method_declaration
1586 : opt_attributes opt_new type namespace_or_type_name
1587 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1590 $$ = new Method (current_class, (Expression) $3, (int) $2, true,
1591 (MemberName) $4, (Parameters) $6, (Attributes) $1, lexer.Location);
1592 if (RootContext.Documentation != null)
1593 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1595 | opt_attributes opt_new type namespace_or_type_name
1596 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1597 OPEN_BRACE opt_statement_list CLOSE_BRACE
1599 $$ = new Method (current_class, (Expression) $3, (int) $2, true,
1600 (MemberName) $4, (Parameters) $6, (Attributes) $1, lexer.Location);
1602 Report.Error (531, lexer.Location, "`{0}': interface members cannot have a definition",
1603 ((Method)$$).GetSignatureForError ());
1607 interface_property_declaration
1612 { lexer.PropertyParsing = true; }
1614 { lexer.PropertyParsing = false; }
1617 if ($3 == TypeManager.system_void_expr) {
1618 Report.Error (547, lexer.Location, "`{0}': property or indexer cannot have void type", $4);
1623 Property p = new Property (current_class, (Expression) $3, (int) $2, true,
1624 new MemberName ((string) $4), (Attributes) $1,
1625 null, null, lexer.Location);
1627 Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
1631 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1633 $$ = new Property (current_class, (Expression) $3, (int) $2, true,
1634 new MemberName ((string) $4), (Attributes) $1,
1635 pinfo.Get, pinfo.Set, lexer.Location);
1636 if (RootContext.Documentation != null)
1637 ((Property) $$).DocComment = Lexer.consume_doc_comment ();
1642 CheckIdentifierToken (yyToken);
1648 : opt_attributes opt_modifiers GET SEMICOLON
1649 { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, (int) $2, 0, lexer.Location, lexer.Location); }
1650 | opt_attributes opt_modifiers GET OPEN_BRACE
1652 Report.Error (531, lexer.Location, "`{0}': interface members cannot have a definition", ".get");
1653 $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, (int) $2, 0, lexer.Location, lexer.Location);
1655 | opt_attributes opt_modifiers SET SEMICOLON
1656 { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1, 0, (int) $2, lexer.Location, lexer.Location); }
1657 | opt_attributes opt_modifiers GET SEMICOLON opt_attributes opt_modifiers SET SEMICOLON
1658 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $5, (int) $2, (int) $6, lexer.Location, lexer.Location); }
1659 | opt_attributes opt_modifiers SET SEMICOLON opt_attributes opt_modifiers GET SEMICOLON
1660 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $5, (Attributes) $1, (int) $6, (int) $2, lexer.Location, lexer.Location); }
1667 interface_event_declaration
1668 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1670 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1671 new MemberName ((string) $5), null,
1672 (Attributes) $1, lexer.Location);
1673 if (RootContext.Documentation != null)
1674 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1676 | opt_attributes opt_new EVENT type error {
1677 CheckIdentifierToken (yyToken);
1680 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1681 Report.Error (68, lexer.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, $5);
1684 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1686 lexer.EventParsing = true;
1688 event_accessor_declarations
1690 lexer.EventParsing = false;
1693 Report.Error (69, lexer.Location, "Event in interface cannot have add or remove accessors");
1698 interface_indexer_declaration
1699 : opt_attributes opt_new type THIS
1700 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1702 { lexer.PropertyParsing = true; }
1704 { lexer.PropertyParsing = false; }
1708 Indexer i = new Indexer (current_class, (Expression) $3,
1709 new MemberName (TypeContainer.DefaultIndexerName),
1710 (int) $2, true, (Parameters) $6, (Attributes) $1,
1711 null, null, lexer.Location);
1713 Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
1717 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1719 $$ = new Indexer (current_class, (Expression) $3,
1720 new MemberName (TypeContainer.DefaultIndexerName),
1721 (int) $2, true, (Parameters) $6, (Attributes) $1,
1722 info.Get, info.Set, lexer.Location);
1723 if (RootContext.Documentation != null)
1724 ((Indexer) $$).DocComment = ConsumeStoredComment ();
1728 operator_declaration
1729 : opt_attributes opt_modifiers operator_declarator
1731 iterator_container = SimpleIteratorContainer.GetSimple ();
1738 OperatorDeclaration decl = (OperatorDeclaration) $3;
1740 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
1742 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
1743 if (decl.arg2type != null)
1744 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
1746 Operator op = new Operator (
1747 current_class, decl.optype, decl.ret_type, (int) $2,
1748 new Parameters (param_list, null),
1749 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1751 if (RootContext.Documentation != null) {
1752 op.DocComment = tmpComment;
1753 Lexer.doc_state = XmlCommentState.Allowed;
1756 if (SimpleIteratorContainer.Simple.Yields)
1759 // Note again, checking is done in semantic analysis
1760 current_container.AddOperator (op);
1762 current_local_parameters = null;
1763 iterator_container = null;
1769 | SEMICOLON { $$ = null; }
1772 : type OPERATOR overloadable_operator
1773 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1775 Operator.OpType op = (Operator.OpType) $3;
1776 CheckUnaryOperator (op);
1778 if (op == Operator.OpType.Addition)
1779 op = Operator.OpType.UnaryPlus;
1781 if (op == Operator.OpType.Subtraction)
1782 op = Operator.OpType.UnaryNegation;
1784 Parameter [] pars = new Parameter [1];
1785 Expression type = (Expression) $5;
1787 pars [0] = new Parameter (type, (string) $6, Parameter.Modifier.NONE, null, lexer.Location);
1789 current_local_parameters = new Parameters (pars, null);
1791 if (RootContext.Documentation != null) {
1792 tmpComment = Lexer.consume_doc_comment ();
1793 Lexer.doc_state = XmlCommentState.NotAllowed;
1796 $$ = new OperatorDeclaration (op, (Expression) $1, type, (string) $6,
1797 null, null, lexer.Location);
1799 | type OPERATOR overloadable_operator
1801 type IDENTIFIER COMMA
1805 CheckBinaryOperator ((Operator.OpType) $3);
1807 Parameter [] pars = new Parameter [2];
1809 Expression typeL = (Expression) $5;
1810 Expression typeR = (Expression) $8;
1812 pars [0] = new Parameter (typeL, (string) $6, Parameter.Modifier.NONE, null, lexer.Location);
1813 pars [1] = new Parameter (typeR, (string) $9, Parameter.Modifier.NONE, null, lexer.Location);
1815 current_local_parameters = new Parameters (pars, null);
1817 if (RootContext.Documentation != null) {
1818 tmpComment = Lexer.consume_doc_comment ();
1819 Lexer.doc_state = XmlCommentState.NotAllowed;
1822 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1824 typeR, (string) $9, lexer.Location);
1826 | conversion_operator_declarator
1827 | type OPERATOR overloadable_operator
1829 type IDENTIFIER COMMA
1830 type IDENTIFIER COMMA
1834 Report.Error (1534, lexer.Location, "Overloaded binary operator `{0}' takes two parameters",
1835 Operator.GetName ((Operator.OpType) $3));
1838 | type OPERATOR overloadable_operator
1839 OPEN_PARENS CLOSE_PARENS
1841 Report.Error (1535, lexer.Location, "Overloaded unary operator `{0}' takes one parameter",
1842 Operator.GetName ((Operator.OpType) $3));
1847 overloadable_operator
1849 : BANG { $$ = Operator.OpType.LogicalNot; }
1850 | TILDE { $$ = Operator.OpType.OnesComplement; }
1851 | OP_INC { $$ = Operator.OpType.Increment; }
1852 | OP_DEC { $$ = Operator.OpType.Decrement; }
1853 | TRUE { $$ = Operator.OpType.True; }
1854 | FALSE { $$ = Operator.OpType.False; }
1855 // Unary and binary:
1856 | PLUS { $$ = Operator.OpType.Addition; }
1857 | MINUS { $$ = Operator.OpType.Subtraction; }
1859 | STAR { $$ = Operator.OpType.Multiply; }
1860 | DIV { $$ = Operator.OpType.Division; }
1861 | PERCENT { $$ = Operator.OpType.Modulus; }
1862 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1863 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1864 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1865 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1866 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1867 | OP_EQ { $$ = Operator.OpType.Equality; }
1868 | OP_NE { $$ = Operator.OpType.Inequality; }
1869 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1870 | OP_LT { $$ = Operator.OpType.LessThan; }
1871 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1872 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1875 conversion_operator_declarator
1876 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1878 Parameter [] pars = new Parameter [1];
1880 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null, lexer.Location);
1882 current_local_parameters = new Parameters (pars, null);
1884 if (RootContext.Documentation != null) {
1885 tmpComment = Lexer.consume_doc_comment ();
1886 Lexer.doc_state = XmlCommentState.NotAllowed;
1889 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1890 null, null, lexer.Location);
1892 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1894 Parameter [] pars = new Parameter [1];
1896 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null, lexer.Location);
1898 current_local_parameters = new Parameters (pars, null);
1900 if (RootContext.Documentation != null) {
1901 tmpComment = Lexer.consume_doc_comment ();
1902 Lexer.doc_state = XmlCommentState.NotAllowed;
1905 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1906 null, null, lexer.Location);
1910 syntax_error (lexer.Location, "'operator' expected");
1914 syntax_error (lexer.Location, "'operator' expected");
1918 constructor_declaration
1921 constructor_declarator
1924 Constructor c = (Constructor) $3;
1925 c.Block = (ToplevelBlock) $4;
1926 c.OptAttributes = (Attributes) $1;
1927 c.ModFlags = (int) $2;
1929 if (RootContext.Documentation != null)
1930 c.DocComment = ConsumeStoredComment ();
1932 if (c.Name == current_container.Basename){
1933 if ((c.ModFlags & Modifiers.STATIC) != 0){
1934 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1935 Report.Error (515, c.Location,
1936 "`{0}': access modifiers are not allowed on static constructors",
1937 c.GetSignatureForError ());
1940 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1942 if (c.Initializer != null){
1943 Report.Error (514, c.Location,
1944 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
1945 c.GetSignatureForError ());
1948 if (!c.Parameters.Empty){
1949 Report.Error (132, c.Location,
1950 "`{0}': The static constructor must be parameterless", c.GetSignatureForError ());
1953 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1956 // We let another layer check the validity of the constructor.
1957 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1960 current_container.AddConstructor (c);
1962 current_local_parameters = null;
1963 if (RootContext.Documentation != null)
1964 Lexer.doc_state = XmlCommentState.Allowed;
1968 constructor_declarator
1971 if (RootContext.Documentation != null) {
1972 tmpComment = Lexer.consume_doc_comment ();
1973 Lexer.doc_state = XmlCommentState.Allowed;
1976 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS _mark_
1978 current_local_parameters = (Parameters) $4;
1980 opt_constructor_initializer
1982 $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $4,
1983 (ConstructorInitializer) $8, (Location) $6);
1989 | SEMICOLON { $$ = null; }
1992 opt_constructor_initializer
1993 : /* empty */ { $$ = null; }
1994 | constructor_initializer
1997 constructor_initializer
1998 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
2000 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
2002 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
2004 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
2007 Report.Error (1018, lexer.Location, "Keyword this or base expected");
2013 : /* EMPTY */ { $$ = 0; }
2014 | UNSAFE { $$ = Modifiers.UNSAFE; }
2015 | EXTERN { $$ = Modifiers.EXTERN; }
2018 destructor_declaration
2019 : opt_attributes opt_finalizer TILDE
2021 if (RootContext.Documentation != null) {
2022 tmpComment = Lexer.consume_doc_comment ();
2023 Lexer.doc_state = XmlCommentState.NotAllowed;
2026 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2028 if ((string) $5 != current_container.Basename){
2029 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
2030 } else if (current_container.Kind != Kind.Class){
2031 Report.Error (575, lexer.Location, "Only class types can contain destructor");
2033 Location l = lexer.Location;
2036 if (!RootContext.StdLib && current_container.Name == "System.Object")
2037 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2039 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2041 Method d = new Destructor (
2042 current_class, TypeManager.system_void_expr, m, "Finalize",
2043 new Parameters (null, null), (Attributes) $1, l);
2044 if (RootContext.Documentation != null)
2045 d.DocComment = ConsumeStoredComment ();
2047 d.Block = (ToplevelBlock) $8;
2048 current_container.AddMethod (d);
2056 EVENT type variable_declarators SEMICOLON
2058 foreach (VariableDeclaration var in (ArrayList) $5) {
2060 MemberName name = new MemberName (var.identifier);
2062 Event e = new EventField (
2063 current_class, (Expression) $4, (int) $2, false, name,
2064 var.expression_or_array_initializer, (Attributes) $1,
2067 current_container.AddEvent (e);
2069 if (RootContext.Documentation != null) {
2070 e.DocComment = Lexer.consume_doc_comment ();
2071 Lexer.doc_state = XmlCommentState.Allowed;
2077 EVENT type namespace_or_type_name
2080 implicit_value_parameter_type = (Expression) $4;
2081 lexer.EventParsing = true;
2083 event_accessor_declarations
2085 lexer.EventParsing = false;
2089 Location loc = (Location) $7;
2090 MemberName name = (MemberName) $5;
2093 Report.Error (65, lexer.Location, "`{0}.{1}': event property must have both add and remove accessors",
2094 current_container.Name, name);
2097 Pair pair = (Pair) $9;
2099 Event e = new EventProperty (
2100 current_class, (Expression) $4, (int) $2, false, name, null,
2101 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
2103 if (RootContext.Documentation != null) {
2104 e.DocComment = Lexer.consume_doc_comment ();
2105 Lexer.doc_state = XmlCommentState.Allowed;
2108 current_container.AddEvent (e);
2109 implicit_value_parameter_type = null;
2112 | opt_attributes opt_modifiers EVENT type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
2113 MemberName mn = (MemberName) $5;
2115 if (mn.Left != null)
2116 Report.Error (71, lexer.Location, "An explicit interface implementation of an event must use property syntax");
2118 Report.Error (71, lexer.Location, "Event declaration should use property syntax");
2120 if (RootContext.Documentation != null)
2121 Lexer.doc_state = XmlCommentState.Allowed;
2125 event_accessor_declarations
2126 : add_accessor_declaration remove_accessor_declaration
2128 $$ = new Pair ($1, $2);
2130 | remove_accessor_declaration add_accessor_declaration
2132 $$ = new Pair ($2, $1);
2134 | add_accessor_declaration { $$ = null; }
2135 | remove_accessor_declaration { $$ = null; }
2138 Report.Error (1055, lexer.Location, "An add or remove accessor expected");
2144 add_accessor_declaration
2145 : opt_attributes ADD
2147 Parameter [] args = new Parameter [1];
2148 Parameter implicit_value_parameter = new Parameter (
2149 implicit_value_parameter_type, "value",
2150 Parameter.Modifier.NONE, null, lexer.Location);
2152 args [0] = implicit_value_parameter;
2154 current_local_parameters = new Parameters (args, null);
2155 lexer.EventParsing = false;
2159 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
2160 lexer.EventParsing = true;
2162 | opt_attributes ADD error {
2163 Report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2166 | opt_attributes modifiers ADD {
2167 Report.Error (1609, lexer.Location, "Modifiers cannot be placed on event accessor declarations");
2172 remove_accessor_declaration
2173 : opt_attributes REMOVE
2175 Parameter [] args = new Parameter [1];
2176 Parameter implicit_value_parameter = new Parameter (
2177 implicit_value_parameter_type, "value",
2178 Parameter.Modifier.NONE, null, lexer.Location);
2180 args [0] = implicit_value_parameter;
2182 current_local_parameters = new Parameters (args, null);
2183 lexer.EventParsing = false;
2187 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
2188 lexer.EventParsing = true;
2190 | opt_attributes REMOVE error {
2191 Report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2194 | opt_attributes modifiers REMOVE {
2195 Report.Error (1609, lexer.Location, "Modifiers cannot be placed on event accessor declarations");
2201 : opt_attributes opt_modifiers indexer_declarator
2204 IndexerDeclaration decl = (IndexerDeclaration) $3;
2206 implicit_value_parameter_type = decl.type;
2208 lexer.PropertyParsing = true;
2209 parsing_indexer = true;
2210 iterator_container = SimpleIteratorContainer.GetSimple ();
2212 indexer_parameters = decl.param_list;
2214 accessor_declarations
2216 lexer.PropertyParsing = false;
2217 has_get = has_set = false;
2218 parsing_indexer = false;
2225 // The signature is computed from the signature of the indexer. Look
2226 // at section 3.6 on the spec
2227 Location loc = (Location) $5;
2229 IndexerDeclaration decl = (IndexerDeclaration) $3;
2230 Pair pair = (Pair) $7;
2231 Accessor get_block = (Accessor) pair.First;
2232 Accessor set_block = (Accessor) pair.Second;
2235 if (decl.interface_type != null)
2236 name = new MemberName (decl.interface_type,
2237 TypeContainer.DefaultIndexerName);
2239 name = new MemberName (TypeContainer.DefaultIndexerName);
2241 indexer = new Indexer (current_class, decl.type, name,
2242 (int) $2, false, decl.param_list, (Attributes) $1,
2243 get_block, set_block, loc);
2244 if (SimpleIteratorContainer.Simple.Yields)
2245 indexer.SetYields ();
2247 if (RootContext.Documentation != null)
2248 indexer.DocComment = ConsumeStoredComment ();
2250 current_container.AddIndexer (indexer);
2252 current_local_parameters = null;
2253 implicit_value_parameter_type = null;
2254 indexer_parameters = null;
2255 iterator_container = null;
2260 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2262 Parameters pars = (Parameters) $4;
2263 if (pars.HasArglist) {
2264 // "__arglist is not valid in this context"
2265 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2266 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2267 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2269 if (RootContext.Documentation != null) {
2270 tmpComment = Lexer.consume_doc_comment ();
2271 Lexer.doc_state = XmlCommentState.Allowed;
2274 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
2276 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2278 Parameters pars = (Parameters) $6;
2280 if (pars.HasArglist) {
2281 // "__arglist is not valid in this context"
2282 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2283 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2284 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2287 MemberName name = (MemberName) $2;
2288 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
2290 if (RootContext.Documentation != null) {
2291 tmpComment = Lexer.consume_doc_comment ();
2292 Lexer.doc_state = XmlCommentState.Allowed;
2303 if (RootContext.Documentation != null)
2304 enumTypeComment = Lexer.consume_doc_comment ();
2309 bool partial = (bool) $3;
2312 Report.Error (267, lexer.Location, "The partial modifier can only appear immediately before `class', `struct' or `interface'");
2313 break; // assumes that the parser put us in a switch
2316 Location enum_location = lexer.Location;
2318 MemberName name = MakeName (new MemberName ((string) $5));
2319 Enum e = new Enum (current_namespace, current_class, (Expression) $6, (int) $2,
2320 name, (Attributes) $1, enum_location);
2322 if (RootContext.Documentation != null)
2323 e.DocComment = enumTypeComment;
2325 foreach (VariableDeclaration ev in (ArrayList) $8) {
2326 e.AddEnumMember (ev.identifier,
2327 (Expression) ev.expression_or_array_initializer,
2328 ev.Location, ev.OptAttributes,
2332 current_container.AddEnum (e);
2333 RootContext.Tree.RecordDecl (current_namespace.NS, name, e);
2340 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2341 | COLON type { $$ = $2; }
2347 if (RootContext.Documentation != null)
2348 Lexer.doc_state = XmlCommentState.Allowed;
2350 opt_enum_member_declarations
2352 // here will be evaluated after CLOSE_BLACE is consumed.
2353 if (RootContext.Documentation != null)
2354 Lexer.doc_state = XmlCommentState.Allowed;
2362 opt_enum_member_declarations
2363 : /* empty */ { $$ = new ArrayList (4); }
2364 | enum_member_declarations opt_comma { $$ = $1; }
2367 enum_member_declarations
2368 : enum_member_declaration
2370 ArrayList l = new ArrayList (4);
2375 | enum_member_declarations COMMA enum_member_declaration
2377 ArrayList l = (ArrayList) $1;
2385 enum_member_declaration
2386 : opt_attributes IDENTIFIER
2388 VariableDeclaration vd = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
2390 if (RootContext.Documentation != null) {
2391 vd.DocComment = Lexer.consume_doc_comment ();
2392 Lexer.doc_state = XmlCommentState.Allowed;
2397 | opt_attributes IDENTIFIER
2399 $$ = lexer.Location;
2400 if (RootContext.Documentation != null) {
2401 tmpComment = Lexer.consume_doc_comment ();
2402 Lexer.doc_state = XmlCommentState.NotAllowed;
2407 VariableDeclaration vd = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
2409 if (RootContext.Documentation != null)
2410 vd.DocComment = ConsumeStoredComment ();
2416 delegate_declaration
2419 DELEGATE type member_name
2420 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2423 Location l = lexer.Location;
2424 MemberName name = MakeName ((MemberName) $5);
2425 Delegate del = new Delegate (current_namespace, current_class, (Expression) $4,
2426 (int) $2, name, (Parameters) $7, (Attributes) $1, l);
2428 if (RootContext.Documentation != null) {
2429 del.DocComment = Lexer.consume_doc_comment ();
2430 Lexer.doc_state = XmlCommentState.Allowed;
2433 current_container.AddDelegate (del);
2434 RootContext.Tree.RecordDecl (current_namespace.NS, name, del);
2439 namespace_or_type_name
2441 | namespace_or_type_name DOT IDENTIFIER {
2442 $$ = new MemberName ((MemberName) $1, (string) $3);
2448 $$ = new MemberName ((string) $1);
2453 * Before you think of adding a return_type, notice that we have been
2454 * using two rules in the places where it matters (one rule using type
2455 * and another identical one that uses VOID as the return type). This
2456 * gets rid of a shift/reduce couple
2459 : namespace_or_type_name
2461 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2473 // Note that here only unmanaged types are allowed but we
2474 // can't perform checks during this phase - we do it during
2475 // semantic analysis.
2477 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2481 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2487 | non_expression_type rank_specifier
2489 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2491 | non_expression_type STAR
2493 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2495 | expression rank_specifiers
2497 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2501 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2505 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2506 // through this different path
2508 | multiplicative_expression STAR
2510 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2517 ArrayList types = new ArrayList (4);
2522 | type_list COMMA type
2524 ArrayList types = (ArrayList) $1;
2532 * replaces all the productions for isolating the various
2533 * simple types, but we need this to reuse it easily in local_variable_type
2536 : OBJECT { $$ = TypeManager.system_object_expr; }
2537 | STRING { $$ = TypeManager.system_string_expr; }
2538 | BOOL { $$ = TypeManager.system_boolean_expr; }
2539 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2540 | FLOAT { $$ = TypeManager.system_single_expr; }
2541 | DOUBLE { $$ = TypeManager.system_double_expr; }
2546 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2547 | BYTE { $$ = TypeManager.system_byte_expr; }
2548 | SHORT { $$ = TypeManager.system_int16_expr; }
2549 | USHORT { $$ = TypeManager.system_uint16_expr; }
2550 | INT { $$ = TypeManager.system_int32_expr; }
2551 | UINT { $$ = TypeManager.system_uint32_expr; }
2552 | LONG { $$ = TypeManager.system_int64_expr; }
2553 | ULONG { $$ = TypeManager.system_uint64_expr; }
2554 | CHAR { $$ = TypeManager.system_char_expr; }
2555 | VOID { $$ = TypeManager.system_void_expr; }
2559 : type rank_specifiers
2561 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2566 // Expressions, section 7.5
2576 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2578 | parenthesized_expression
2580 | invocation_expression
2584 | post_increment_expression
2585 | post_decrement_expression
2589 | checked_expression
2590 | unchecked_expression
2591 | pointer_member_access
2592 | anonymous_method_expression
2599 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2600 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2601 | NULL { $$ = NullLiteral.Null; }
2605 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2606 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2607 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2612 object v = lexer.Value;
2618 $$ = IntLiteral.Zero;
2620 $$ = IntLiteral.One;
2622 $$ = new IntLiteral (i);
2623 } else if (v is uint)
2624 $$ = new UIntLiteral ((UInt32) v);
2626 $$ = new LongLiteral ((Int64) v);
2627 else if (v is ulong)
2628 $$ = new ULongLiteral ((UInt64) v);
2630 Console.WriteLine ("OOPS. Unexpected result from scanner");
2635 : TRUE { $$ = new BoolLiteral (true); }
2636 | FALSE { $$ = new BoolLiteral (false); }
2639 parenthesized_expression_0
2640 : OPEN_PARENS expression CLOSE_PARENS
2643 lexer.Deambiguate_CloseParens ();
2644 // After this, the next token returned is one of
2645 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2646 // or CLOSE_PARENS_MINUS.
2650 parenthesized_expression
2651 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2655 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2657 // If a parenthesized expression is followed by a minus, we need to wrap
2658 // the expression inside a ParenthesizedExpression for the CS0075 check
2659 // in Binary.DoResolve().
2660 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2665 : primary_expression DOT IDENTIFIER
2667 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2669 | predefined_type DOT IDENTIFIER
2671 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2679 invocation_expression
2680 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2683 Location l = lexer.Location;
2684 Report.Error (1, l, "Parse error");
2686 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2688 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2690 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2692 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2694 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2696 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
2698 ArrayList args = new ArrayList (1);
2700 $$ = new Invocation ((Expression) $1, args, lexer.Location);
2702 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
2704 ArrayList args = ((ArrayList) $4);
2706 $$ = new Invocation ((Expression) $1, args, lexer.Location);
2711 : /* empty */ { $$ = null; }
2718 ArrayList list = new ArrayList (4);
2722 | argument_list COMMA argument
2724 ArrayList list = (ArrayList) $1;
2728 | argument_list error {
2729 CheckToken (1026, yyToken, "Expected `,' or `)'");
2736 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2738 | non_simple_argument
2745 : REF variable_reference
2747 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2749 | OUT variable_reference
2751 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2753 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
2755 ArrayList list = (ArrayList) $3;
2756 Argument[] args = new Argument [list.Count];
2757 list.CopyTo (args, 0);
2759 Expression expr = new Arglist (args, lexer.Location);
2760 $$ = new Argument (expr, Argument.AType.Expression);
2764 $$ = new Argument (new ArglistAccess (lexer.Location), Argument.AType.ArgList);
2769 : expression { note ("section 5.4"); $$ = $1; }
2773 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2775 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2777 | primary_expression rank_specifiers
2779 // So the super-trick is that primary_expression
2780 // can only be either a SimpleName or a MemberAccess.
2781 // The MemberAccess case arises when you have a fully qualified type-name like :
2783 // SimpleName is when you have
2786 Expression expr = (Expression) $1;
2787 if (expr is ComposedCast){
2788 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2789 } else if (!(expr is SimpleName || expr is MemberAccess)){
2790 Error_ExpectingTypeName (lexer.Location, expr);
2791 $$ = TypeManager.system_object_expr;
2794 // So we extract the string corresponding to the SimpleName
2797 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2805 ArrayList list = new ArrayList (4);
2809 | expression_list COMMA expression
2811 ArrayList list = (ArrayList) $1;
2820 $$ = new This (current_block, lexer.Location);
2825 : BASE DOT IDENTIFIER
2827 $$ = new BaseAccess ((string) $3, lexer.Location);
2829 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2831 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2834 Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
2839 post_increment_expression
2840 : primary_expression OP_INC
2842 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2843 (Expression) $1, lexer.Location);
2847 post_decrement_expression
2848 : primary_expression OP_DEC
2850 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2851 (Expression) $1, lexer.Location);
2856 : object_or_delegate_creation_expression
2857 | array_creation_expression
2860 object_or_delegate_creation_expression
2861 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2863 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2867 array_creation_expression
2868 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2870 opt_array_initializer
2872 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2874 | NEW type rank_specifiers array_initializer
2876 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2880 Report.Error (1031, lexer.Location, "Type expected");
2885 Report.Error (1526, lexer.Location, "A new expression requires () or [] after type");
2901 : rank_specifier opt_rank_specifier
2903 $$ = (string) $2 + (string) $1;
2908 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2910 $$ = "[" + (string) $2 + "]";
2930 | dim_separators COMMA
2932 $$ = (string) $1 + ",";
2936 opt_array_initializer
2948 : OPEN_BRACE CLOSE_BRACE
2950 ArrayList list = new ArrayList (4);
2953 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2955 $$ = (ArrayList) $2;
2959 variable_initializer_list
2960 : variable_initializer
2962 ArrayList list = new ArrayList (4);
2966 | variable_initializer_list COMMA variable_initializer
2968 ArrayList list = (ArrayList) $1;
2975 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2977 $$ = new TypeOfVoid (lexer.Location);
2979 | TYPEOF OPEN_PARENS type CLOSE_PARENS
2981 $$ = new TypeOf ((Expression) $3, lexer.Location);
2986 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2987 $$ = new SizeOf ((Expression) $3, lexer.Location);
2992 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2994 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2998 unchecked_expression
2999 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3001 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
3005 pointer_member_access
3006 : primary_expression OP_PTR IDENTIFIER
3010 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
3011 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
3015 anonymous_method_expression
3016 : DELEGATE opt_anonymous_method_signature _mark_
3018 oob_stack.Push (current_local_parameters);
3019 current_local_parameters = (Parameters)$2;
3021 // Force the next block to be created as a ToplevelBlock
3022 oob_stack.Push (current_block);
3023 oob_stack.Push (top_current_block);
3024 current_block = null;
3028 Location loc = (Location) $3;
3029 top_current_block = (Block) oob_stack.Pop ();
3030 current_block = (Block) oob_stack.Pop ();
3031 if (RootContext.Version == LanguageVersion.ISO_1){
3032 Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
3035 ToplevelBlock anon_block = (ToplevelBlock) $5;
3037 anon_block.Parent = current_block;
3038 $$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block,
3041 current_local_parameters = (Parameters) oob_stack.Pop ();
3045 opt_anonymous_method_signature
3046 : /* empty */ { $$ = null; }
3047 | anonymous_method_signature
3050 anonymous_method_signature
3051 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
3054 $$ = Parameters.EmptyReadOnlyParameters;
3056 ArrayList par_list = (ArrayList) $2;
3057 Parameter [] pars = new Parameter [par_list.Count];
3058 par_list.CopyTo (pars);
3059 $$ = new Parameters (pars, null);
3064 opt_anonymous_method_parameter_list
3065 : /* empty */ { $$ = null; }
3066 | anonymous_method_parameter_list { $$ = $1; }
3069 anonymous_method_parameter_list
3070 : anonymous_method_parameter
3072 ArrayList a = new ArrayList (4);
3076 | anonymous_method_parameter_list COMMA anonymous_method_parameter
3078 ArrayList a = (ArrayList) $1;
3084 anonymous_method_parameter
3085 : opt_parameter_modifier type IDENTIFIER {
3086 $$ = new Parameter ((Expression) $2, (string) $3, (Parameter.Modifier) $1, null, lexer.Location);
3088 | PARAMS type IDENTIFIER {
3089 Report.Error (1670, lexer.Location, "The `params' modifier is not allowed in anonymous method declaration");
3095 : primary_expression
3096 | BANG prefixed_unary_expression
3098 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
3100 | TILDE prefixed_unary_expression
3102 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
3108 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3110 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
3112 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3114 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
3120 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3122 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3127 // The idea to split this out is from Rhys' grammar
3128 // to solve the problem with casts.
3130 prefixed_unary_expression
3132 | PLUS prefixed_unary_expression
3134 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
3136 | MINUS prefixed_unary_expression
3138 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
3140 | OP_INC prefixed_unary_expression
3142 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3143 (Expression) $2, lexer.Location);
3145 | OP_DEC prefixed_unary_expression
3147 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3148 (Expression) $2, lexer.Location);
3150 | STAR prefixed_unary_expression
3152 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
3154 | BITWISE_AND prefixed_unary_expression
3156 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
3160 pre_increment_expression
3161 : OP_INC prefixed_unary_expression
3163 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3164 (Expression) $2, lexer.Location);
3168 pre_decrement_expression
3169 : OP_DEC prefixed_unary_expression
3171 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3172 (Expression) $2, lexer.Location);
3176 multiplicative_expression
3177 : prefixed_unary_expression
3178 | multiplicative_expression STAR prefixed_unary_expression
3180 $$ = new Binary (Binary.Operator.Multiply,
3181 (Expression) $1, (Expression) $3, lexer.Location);
3183 | multiplicative_expression DIV prefixed_unary_expression
3185 $$ = new Binary (Binary.Operator.Division,
3186 (Expression) $1, (Expression) $3, lexer.Location);
3188 | multiplicative_expression PERCENT prefixed_unary_expression
3190 $$ = new Binary (Binary.Operator.Modulus,
3191 (Expression) $1, (Expression) $3, lexer.Location);
3196 : multiplicative_expression
3197 | additive_expression PLUS multiplicative_expression
3199 $$ = new Binary (Binary.Operator.Addition,
3200 (Expression) $1, (Expression) $3, lexer.Location);
3202 | additive_expression MINUS multiplicative_expression
3204 $$ = new Binary (Binary.Operator.Subtraction,
3205 (Expression) $1, (Expression) $3, lexer.Location);
3210 : additive_expression
3211 | shift_expression OP_SHIFT_LEFT additive_expression
3213 $$ = new Binary (Binary.Operator.LeftShift,
3214 (Expression) $1, (Expression) $3, lexer.Location);
3216 | shift_expression OP_SHIFT_RIGHT additive_expression
3218 $$ = new Binary (Binary.Operator.RightShift,
3219 (Expression) $1, (Expression) $3, lexer.Location);
3223 relational_expression
3225 | relational_expression OP_LT shift_expression
3227 $$ = new Binary (Binary.Operator.LessThan,
3228 (Expression) $1, (Expression) $3, lexer.Location);
3230 | relational_expression OP_GT shift_expression
3232 $$ = new Binary (Binary.Operator.GreaterThan,
3233 (Expression) $1, (Expression) $3, lexer.Location);
3235 | relational_expression OP_LE shift_expression
3237 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3238 (Expression) $1, (Expression) $3, lexer.Location);
3240 | relational_expression OP_GE shift_expression
3242 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3243 (Expression) $1, (Expression) $3, lexer.Location);
3245 | relational_expression IS type
3247 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
3249 | relational_expression AS type
3251 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
3256 : relational_expression
3257 | equality_expression OP_EQ relational_expression
3259 $$ = new Binary (Binary.Operator.Equality,
3260 (Expression) $1, (Expression) $3, lexer.Location);
3262 | equality_expression OP_NE relational_expression
3264 $$ = new Binary (Binary.Operator.Inequality,
3265 (Expression) $1, (Expression) $3, lexer.Location);
3270 : equality_expression
3271 | and_expression BITWISE_AND equality_expression
3273 $$ = new Binary (Binary.Operator.BitwiseAnd,
3274 (Expression) $1, (Expression) $3, lexer.Location);
3278 exclusive_or_expression
3280 | exclusive_or_expression CARRET and_expression
3282 $$ = new Binary (Binary.Operator.ExclusiveOr,
3283 (Expression) $1, (Expression) $3, lexer.Location);
3287 inclusive_or_expression
3288 : exclusive_or_expression
3289 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3291 $$ = new Binary (Binary.Operator.BitwiseOr,
3292 (Expression) $1, (Expression) $3, lexer.Location);
3296 conditional_and_expression
3297 : inclusive_or_expression
3298 | conditional_and_expression OP_AND inclusive_or_expression
3300 $$ = new Binary (Binary.Operator.LogicalAnd,
3301 (Expression) $1, (Expression) $3, lexer.Location);
3305 conditional_or_expression
3306 : conditional_and_expression
3307 | conditional_or_expression OP_OR conditional_and_expression
3309 $$ = new Binary (Binary.Operator.LogicalOr,
3310 (Expression) $1, (Expression) $3, lexer.Location);
3314 conditional_expression
3315 : conditional_or_expression
3316 | conditional_or_expression INTERR expression COLON expression
3318 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
3322 assignment_expression
3323 : prefixed_unary_expression ASSIGN expression
3325 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
3327 | prefixed_unary_expression OP_MULT_ASSIGN expression
3329 Location l = lexer.Location;
3331 $$ = new CompoundAssign (
3332 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
3334 | prefixed_unary_expression OP_DIV_ASSIGN expression
3336 Location l = lexer.Location;
3338 $$ = new CompoundAssign (
3339 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
3341 | prefixed_unary_expression OP_MOD_ASSIGN expression
3343 Location l = lexer.Location;
3345 $$ = new CompoundAssign (
3346 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
3348 | prefixed_unary_expression OP_ADD_ASSIGN expression
3350 Location l = lexer.Location;
3352 $$ = new CompoundAssign (
3353 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
3355 | prefixed_unary_expression OP_SUB_ASSIGN expression
3357 Location l = lexer.Location;
3359 $$ = new CompoundAssign (
3360 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
3362 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3364 Location l = lexer.Location;
3366 $$ = new CompoundAssign (
3367 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
3369 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3371 Location l = lexer.Location;
3373 $$ = new CompoundAssign (
3374 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
3376 | prefixed_unary_expression OP_AND_ASSIGN expression
3378 Location l = lexer.Location;
3380 $$ = new CompoundAssign (
3381 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
3383 | prefixed_unary_expression OP_OR_ASSIGN expression
3385 Location l = lexer.Location;
3387 $$ = new CompoundAssign (
3388 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
3390 | prefixed_unary_expression OP_XOR_ASSIGN expression
3392 Location l = lexer.Location;
3394 $$ = new CompoundAssign (
3395 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
3400 : conditional_expression
3401 | assignment_expression
3421 MemberName name = MakeName ((MemberName) $5);
3422 bool partial = (bool) $3;
3423 int mod_flags = (int) $2;
3426 ClassPart part = PartialContainer.CreatePart (
3427 current_namespace, current_class, name, mod_flags,
3428 (Attributes) $1, Kind.Class, lexer.Location);
3430 current_container = part.PartialContainer;
3431 current_class = part;
3433 if ((mod_flags & Modifiers.STATIC) != 0) {
3434 current_class = new StaticClass (
3435 current_namespace, current_class, name,
3436 mod_flags, (Attributes) $1, lexer.Location);
3438 current_class = new Class (
3439 current_namespace, current_class, name,
3440 mod_flags, (Attributes) $1, lexer.Location);
3443 current_container.AddClassOrStruct (current_class);
3444 current_container = current_class;
3445 RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
3451 if (current_class.Name == "System.Object") {
3452 Report.Error (537, current_class.Location,
3453 "The class System.Object cannot have a base " +
3454 "class or implement an interface.");
3456 current_class.Bases = (ArrayList) $7;
3459 if (RootContext.Documentation != null) {
3460 current_class.DocComment = Lexer.consume_doc_comment ();
3461 Lexer.doc_state = XmlCommentState.Allowed;
3466 if (RootContext.Documentation != null)
3467 Lexer.doc_state = XmlCommentState.Allowed;
3471 $$ = pop_current_class ();
3477 { $$ = (bool) false; }
3479 { $$ = (bool) true; }
3483 : /* empty */ { $$ = (int) 0; }
3489 | modifiers modifier
3494 if ((m1 & m2) != 0) {
3495 Location l = lexer.Location;
3496 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
3498 $$ = (int) (m1 | m2);
3503 : NEW { $$ = Modifiers.NEW; }
3504 | PUBLIC { $$ = Modifiers.PUBLIC; }
3505 | PROTECTED { $$ = Modifiers.PROTECTED; }
3506 | INTERNAL { $$ = Modifiers.INTERNAL; }
3507 | PRIVATE { $$ = Modifiers.PRIVATE; }
3508 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3509 | SEALED { $$ = Modifiers.SEALED; }
3510 | STATIC { $$ = Modifiers.STATIC; }
3511 | READONLY { $$ = Modifiers.READONLY; }
3512 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3513 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3514 | EXTERN { $$ = Modifiers.EXTERN; }
3515 | VOLATILE { $$ = Modifiers.VOLATILE; }
3516 | UNSAFE { $$ = Modifiers.UNSAFE; }
3520 : /* empty */ { $$ = null; }
3521 | class_base { $$ = $1; }
3525 : COLON type_list { $$ = $2; }
3533 // A block is "contained" on the following places:
3535 // property_declaration as part of the accessor body (get/set)
3536 // operator_declaration
3537 // constructor_declaration
3538 // destructor_declaration
3539 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3544 if (current_block == null){
3545 current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, lexer.Location);
3546 top_current_block = current_block;
3548 current_block = new Block (current_block, lexer.Location, Location.Null);
3551 opt_statement_list CLOSE_BRACE
3553 while (current_block.Implicit)
3554 current_block = current_block.Parent;
3556 current_block.SetEndLocation (lexer.Location);
3557 current_block = current_block.Parent;
3558 if (current_block == null)
3559 top_current_block = null;
3570 | statement_list statement
3574 : declaration_statement
3576 if ($1 != null && (Block) $1 != current_block){
3577 current_block.AddStatement ((Statement) $1);
3578 current_block = (Block) $1;
3581 | valid_declaration_statement
3583 current_block.AddStatement ((Statement) $1);
3588 valid_declaration_statement
3591 | expression_statement
3592 | selection_statement
3593 | iteration_statement
3597 | unchecked_statement
3605 : valid_declaration_statement
3606 | declaration_statement
3608 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration or labeled statement");
3613 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration or labeled statement");
3621 $$ = EmptyStatement.Value;
3628 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3630 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3631 current_block.AddStatement (labeled);
3636 declaration_statement
3637 : local_variable_declaration SEMICOLON
3640 DictionaryEntry de = (DictionaryEntry) $1;
3642 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3646 | local_constant_declaration SEMICOLON
3649 DictionaryEntry de = (DictionaryEntry) $1;
3651 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3657 * The following is from Rhys' grammar:
3658 * > Types in local variable declarations must be recognized as
3659 * > expressions to prevent reduce/reduce errors in the grammar.
3660 * > The expressions are converted into types during semantic analysis.
3663 : primary_expression opt_rank_specifier
3665 // FIXME: Do something smart here regarding the composition of the type.
3667 // Ok, the above "primary_expression" is there to get rid of
3668 // both reduce/reduce and shift/reduces in the grammar, it should
3669 // really just be "type_name". If you use type_name, a reduce/reduce
3670 // creeps up. If you use namespace_or_type_name (which is all we need
3671 // really) two shift/reduces appear.
3674 // So the super-trick is that primary_expression
3675 // can only be either a SimpleName or a MemberAccess.
3676 // The MemberAccess case arises when you have a fully qualified type-name like :
3678 // SimpleName is when you have
3681 Expression expr = (Expression) $1;
3682 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast)) {
3683 Error_ExpectingTypeName (lexer.Location, expr);
3687 // So we extract the string corresponding to the SimpleName
3691 if ((string) $2 == "")
3694 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3697 | builtin_types opt_rank_specifier
3699 if ((string) $2 == "")
3702 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3706 local_variable_pointer_type
3707 : primary_expression STAR
3709 Expression expr = (Expression) $1;
3710 Location l = lexer.Location;
3712 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast)) {
3713 Error_ExpectingTypeName (l, expr);
3717 $$ = new ComposedCast ((Expression) $1, "*", l);
3719 | builtin_types STAR
3721 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3725 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3727 | local_variable_pointer_type STAR
3729 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3733 local_variable_declaration
3734 : local_variable_type variable_declarators
3737 $$ = new DictionaryEntry ($1, $2);
3741 | local_variable_pointer_type opt_rank_specifier variable_declarators
3746 if ((string) $2 == "")
3747 t = (Expression) $1;
3749 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3750 $$ = new DictionaryEntry (t, $3);
3756 local_constant_declaration
3757 : CONST local_variable_type constant_declarators
3760 $$ = new DictionaryEntry ($2, $3);
3766 expression_statement
3767 : statement_expression SEMICOLON
3774 // We have to do the wrapping here and not in the case above,
3775 // because statement_expression is used for example in for_statement
3777 statement_expression
3778 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3779 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3780 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3781 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3782 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3783 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3784 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3786 Report.Error (1002, lexer.Location, "Expecting `;'");
3791 object_creation_expression
3792 : object_or_delegate_creation_expression
3793 { note ("complain if this is a delegate maybe?"); }
3802 : IF OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS
3805 Location l = (Location) $3;
3807 $$ = new If ((Expression) $4, (Statement) $6, l);
3809 if (RootContext.WarningLevel >= 4){
3810 if ($6 == EmptyStatement.Value)
3811 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3815 | IF OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS
3816 embedded_statement ELSE embedded_statement
3818 Location l = (Location) $3;
3820 $$ = new If ((Expression) $4, (Statement) $6, (Statement) $8, l);
3825 : SWITCH OPEN_PARENS _mark_
3827 switch_stack.Push (current_block);
3829 expression CLOSE_PARENS
3832 $$ = new Switch ((Expression) $5, (ArrayList) $7, (Location) $3);
3833 current_block = (Block) switch_stack.Pop ();
3849 Report.Error (1522, lexer.Location, "Empty switch block");
3857 ArrayList sections = new ArrayList (4);
3862 | switch_sections switch_section
3864 ArrayList sections = (ArrayList) $1;
3874 current_block = current_block.CreateSwitchBlock (lexer.Location);
3878 Block topmost = current_block;
3880 while (topmost.Implicit)
3881 topmost = topmost.Parent;
3882 $$ = new SwitchSection ((ArrayList) $1, topmost);
3889 ArrayList labels = new ArrayList (4);
3894 | switch_labels switch_label
3896 ArrayList labels = (ArrayList) ($1);
3904 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3905 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3908 1523, lexer.Location,
3909 "The keyword case or default must precede code in switch block");
3921 : WHILE OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS embedded_statement
3923 Location l = (Location) $3;
3924 $$ = new While ((Expression) $4, (Statement) $6, l);
3926 if (RootContext.WarningLevel >= 4){
3927 if ($6 == EmptyStatement.Value)
3928 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3934 : DO embedded_statement
3935 WHILE OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS SEMICOLON
3937 Location l = (Location) $5;
3939 $$ = new Do ((Statement) $2, (Expression) $6, l);
3945 opt_for_initializer SEMICOLON _mark_
3947 Block assign_block = new Block (current_block);
3948 current_block = assign_block;
3950 if ($3 is DictionaryEntry){
3951 DictionaryEntry de = (DictionaryEntry) $3;
3953 Expression type = (Expression) de.Key;
3954 ArrayList var_declarators = (ArrayList) de.Value;
3956 foreach (VariableDeclaration decl in var_declarators){
3960 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
3964 Location l = lexer.Location;
3966 if (decl.expression_or_array_initializer is Expression){
3967 expr = (Expression) decl.expression_or_array_initializer;
3968 } else if (decl.expression_or_array_initializer == null) {
3971 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3972 expr = new ArrayCreation (type, "", init, decl.Location);
3975 LocalVariableReference var;
3976 var = new LocalVariableReference (assign_block, decl.identifier, l);
3979 Assign a = new Assign (var, expr, decl.Location);
3981 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3985 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
3986 // This can be referred to as $6 below.
3992 opt_for_condition SEMICOLON
3993 opt_for_iterator CLOSE_PARENS
3996 Location l = (Location) $5;
3998 For f = new For ((Statement) $6, (Expression) $7, (Statement) $9, (Statement) $11, l);
4000 if (RootContext.WarningLevel >= 4){
4001 if ($11 == EmptyStatement.Value)
4002 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
4005 current_block.AddStatement (f);
4006 while (current_block.Implicit)
4007 current_block = current_block.Parent;
4009 current_block = current_block.Parent;
4014 : /* empty */ { $$ = EmptyStatement.Value; }
4019 : local_variable_declaration
4020 | statement_expression_list
4024 : /* empty */ { $$ = null; }
4025 | boolean_expression
4029 : /* empty */ { $$ = EmptyStatement.Value; }
4034 : statement_expression_list
4037 statement_expression_list
4038 : statement_expression
4040 // CHANGE: was `null'
4041 Block b = new Block (current_block, Block.Flags.Implicit);
4043 b.AddStatement ((Statement) $1);
4046 | statement_expression_list COMMA statement_expression
4048 Block b = (Block) $1;
4050 b.AddStatement ((Statement) $3);
4056 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
4058 Report.Error (230, lexer.Location, "Type and identifier are both required in a foreach statement");
4061 | FOREACH OPEN_PARENS type IDENTIFIER IN _mark_
4062 expression CLOSE_PARENS
4064 Block foreach_block = new Block (current_block);
4065 current_block = foreach_block;
4067 Location l = lexer.Location;
4070 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, l);
4072 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4074 // Get a writable reference to this read-only variable.
4076 // Note that the $$ here refers to the value of _this_ code block,
4077 // not the value of the LHS non-terminal. This can be referred to as $9 below.
4078 $$ = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
4085 LocalVariableReference v = (LocalVariableReference) $9;
4086 Location l = (Location) $6;
4089 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
4090 current_block.AddStatement (f);
4093 while (current_block.Implicit)
4094 current_block = current_block.Parent;
4096 current_block = current_block.Parent;
4102 | continue_statement
4112 $$ = new Break (lexer.Location);
4117 : CONTINUE SEMICOLON
4119 $$ = new Continue (lexer.Location);
4124 : GOTO IDENTIFIER SEMICOLON
4126 $$ = new Goto ((string) $2, lexer.Location);
4128 | GOTO CASE constant_expression SEMICOLON
4130 $$ = new GotoCase ((Expression) $3, lexer.Location);
4132 | GOTO DEFAULT SEMICOLON
4134 $$ = new GotoDefault (lexer.Location);
4139 : RETURN opt_expression SEMICOLON
4141 $$ = new Return ((Expression) $2, lexer.Location);
4146 : THROW opt_expression SEMICOLON
4148 $$ = new Throw ((Expression) $2, lexer.Location);
4153 : IDENTIFIER RETURN expression SEMICOLON
4155 string s = (string) $1;
4157 Report.Error (1003, lexer.Location, "; expected");
4160 if (RootContext.Version == LanguageVersion.ISO_1){
4161 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
4164 if (iterator_container == null){
4165 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
4168 iterator_container.SetYields ();
4169 $$ = new Yield ((Expression) $3, lexer.Location);
4172 | IDENTIFIER RETURN SEMICOLON
4174 Report.Error (1627, lexer.Location, "Expression expected after yield return");
4177 | IDENTIFIER BREAK SEMICOLON
4179 string s = (string) $1;
4181 Report.Error (1003, lexer.Location, "; expected");
4184 if (RootContext.Version == LanguageVersion.ISO_1){
4185 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
4188 if (iterator_container == null){
4189 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
4192 iterator_container.SetYields ();
4193 $$ = new YieldBreak (lexer.Location);
4204 : TRY block catch_clauses
4208 ArrayList c = (ArrayList)$3;
4209 for (int i = 0; i < c.Count; ++i) {
4210 Catch cc = (Catch) c [i];
4212 if (i != c.Count - 1)
4213 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
4220 // Now s contains the list of specific catch clauses
4221 // and g contains the general one.
4223 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4225 | TRY block opt_catch_clauses FINALLY block
4228 ArrayList s = new ArrayList (4);
4229 ArrayList catch_list = (ArrayList) $3;
4231 if (catch_list != null){
4232 foreach (Catch cc in catch_list) {
4240 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4244 Report.Error (1524, lexer.Location, "Expected catch or finally");
4249 : /* empty */ { $$ = null; }
4256 ArrayList l = new ArrayList (4);
4261 | catch_clauses catch_clause
4263 ArrayList l = (ArrayList) $1;
4271 : /* empty */ { $$ = null; }
4276 : CATCH opt_catch_args
4278 Expression type = null;
4282 DictionaryEntry cc = (DictionaryEntry) $2;
4283 type = (Expression) cc.Key;
4284 id = (string) cc.Value;
4287 ArrayList one = new ArrayList (4);
4288 Location loc = lexer.Location;
4290 one.Add (new VariableDeclaration (id, null, loc));
4292 current_block = new Block (current_block);
4293 Block b = declare_local_variables (type, one, loc);
4298 Expression type = null;
4302 DictionaryEntry cc = (DictionaryEntry) $2;
4303 type = (Expression) cc.Key;
4304 id = (string) cc.Value;
4307 while (current_block.Implicit)
4308 current_block = current_block.Parent;
4309 current_block = current_block.Parent;
4313 $$ = new Catch (type, id, (Block) $4, ((Block) $4).loc);
4318 : /* empty */ { $$ = null; }
4323 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4325 $$ = new DictionaryEntry ($2, $3);
4332 $$ = new Checked ((Block) $2);
4339 $$ = new Unchecked ((Block) $2);
4346 RootContext.CheckUnsafeOption (lexer.Location);
4348 $$ = new Unsafe ((Block) $3);
4354 type fixed_pointer_declarators
4357 ArrayList list = (ArrayList) $4;
4358 Expression type = (Expression) $3;
4359 Location l = lexer.Location;
4360 int top = list.Count;
4362 Block assign_block = new Block (current_block);
4363 current_block = assign_block;
4365 for (int i = 0; i < top; i++){
4366 Pair p = (Pair) list [i];
4369 v = current_block.AddVariable (type, (string) p.First, l);
4373 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
4381 Location l = (Location) $6;
4383 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $8, l);
4385 if (RootContext.WarningLevel >= 4){
4386 if ($8 == EmptyStatement.Value)
4387 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
4390 current_block.AddStatement (f);
4391 while (current_block.Implicit)
4392 current_block = current_block.Parent;
4394 current_block = current_block.Parent;
4398 fixed_pointer_declarators
4399 : fixed_pointer_declarator {
4400 ArrayList declarators = new ArrayList (4);
4402 declarators.Add ($1);
4405 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4407 ArrayList declarators = (ArrayList) $1;
4409 declarators.Add ($3);
4414 fixed_pointer_declarator
4415 : IDENTIFIER ASSIGN expression
4417 $$ = new Pair ($1, $3);
4421 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
4427 : LOCK OPEN_PARENS expression CLOSE_PARENS
4433 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4438 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS _mark_
4440 Block assign_block = new Block (current_block);
4441 current_block = assign_block;
4443 if ($3 is DictionaryEntry){
4444 DictionaryEntry de = (DictionaryEntry) $3;
4445 Location l = lexer.Location;
4447 Expression type = (Expression) de.Key;
4448 ArrayList var_declarators = (ArrayList) de.Value;
4450 ArrayList vars = new ArrayList (4);
4452 foreach (VariableDeclaration decl in var_declarators){
4454 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4457 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
4460 if (decl.expression_or_array_initializer is Expression){
4461 expr = (Expression) decl.expression_or_array_initializer;
4463 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4465 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4468 expr = new ArrayCreation (type, "", init, decl.Location);
4471 LocalVariableReference var;
4473 // Get a writable reference to this read-only variable.
4474 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4476 // This is so that it is not a warning on using variables
4479 vars.Add (new DictionaryEntry (var, expr));
4481 // Assign a = new Assign (var, expr, decl.Location);
4482 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4485 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
4486 // It can be referred to as $6 below.
4487 $$ = new DictionaryEntry (type, vars);
4494 Using u = new Using ($6, (Statement) $7, (Location) $5);
4495 current_block.AddStatement (u);
4496 while (current_block.Implicit)
4497 current_block = current_block.Parent;
4499 current_block = current_block.Parent;
4503 resource_acquisition
4504 : local_variable_declaration
4508 // Utility rule to save location information
4511 { $$ = lexer.Location; }
4516 // A class used to pass around variable declarations and constants
4518 public class VariableDeclaration {
4519 public string identifier;
4520 public object expression_or_array_initializer;
4521 public Location Location;
4522 public Attributes OptAttributes;
4523 public string DocComment;
4525 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4527 this.identifier = id;
4528 this.expression_or_array_initializer = eoai;
4530 this.OptAttributes = opt_attrs;
4533 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4539 /// Used to pass around interface property information
4541 public class InterfaceAccessorInfo {
4543 public readonly Accessor Get, Set;
4545 public InterfaceAccessorInfo (bool has_get, bool has_set,
4546 Attributes get_attrs, Attributes set_attrs, int get_mod, int set_mod, Location get_loc, Location set_loc)
4549 Get = new Accessor (null, get_mod, get_attrs, get_loc);
4551 Set = new Accessor (null, set_mod, set_attrs, set_loc);
4558 // A class used to hold info about an indexer declarator
4560 public class IndexerDeclaration {
4561 public Expression type;
4562 public MemberName interface_type;
4563 public Parameters param_list;
4565 public IndexerDeclaration (Expression type, MemberName interface_type,
4566 Parameters param_list)
4569 this.interface_type = interface_type;
4570 this.param_list = param_list;
4575 // We use this when we do not have an object in advance that is an IIteratorContainer
4577 public class SimpleIteratorContainer : IIteratorContainer {
4580 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4585 public static SimpleIteratorContainer GetSimple () {
4586 Simple.Yields = false;
4590 public void SetYields () { Yields = true; }
4594 // A class used to hold info about an operator declarator
4596 public class OperatorDeclaration {
4597 public Operator.OpType optype;
4598 public Expression ret_type, arg1type, arg2type;
4599 public string arg1name, arg2name;
4600 public Location location;
4602 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4603 Expression arg1type, string arg1name,
4604 Expression arg2type, string arg2name, Location location)
4607 this.ret_type = ret_type;
4608 this.arg1type = arg1type;
4609 this.arg1name = arg1name;
4610 this.arg2type = arg2type;
4611 this.arg2name = arg2name;
4612 this.location = location;
4617 void Error_ExpectingTypeName (Location l, Expression expr)
4619 if (expr is Invocation){
4620 Report.Error (1002, l, "Expecting `;'");
4622 Report.Error (-1, l, "Invalid Type definition");
4626 TypeContainer pop_current_class ()
4628 TypeContainer retval = current_class;
4630 current_class = current_class.Parent;
4631 current_container = current_container.Parent;
4633 if (current_class != current_container) {
4634 if (!(current_class is ClassPart) ||
4635 ((ClassPart) current_class).PartialContainer != current_container)
4636 throw new InternalErrorException ();
4637 } else if (current_container is ClassPart)
4638 current_container = ((ClassPart) current_class).PartialContainer;
4644 // Given the @class_name name, it creates a fully qualified name
4645 // based on the containing declaration space
4648 MakeName (MemberName class_name)
4650 Namespace ns = current_namespace.NS;
4652 if (current_container.Name == ""){
4654 return new MemberName (ns.MemberName, class_name);
4658 return new MemberName (current_container.MemberName, class_name);
4662 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4664 Block implicit_block;
4665 ArrayList inits = null;
4668 // We use the `Used' property to check whether statements
4669 // have been added to the current block. If so, we need
4670 // to create another block to contain the new declaration
4671 // otherwise, as an optimization, we use the same block to
4672 // add the declaration.
4674 // FIXME: A further optimization is to check if the statements
4675 // that were added were added as part of the initialization
4676 // below. In which case, no other statements have been executed
4677 // and we might be able to reduce the number of blocks for
4678 // situations like this:
4680 // int j = 1; int k = j + 1;
4682 if (current_block.Used)
4683 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4685 implicit_block = current_block;
4687 foreach (VariableDeclaration decl in variable_declarators){
4689 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
4690 if (decl.expression_or_array_initializer != null){
4692 inits = new ArrayList (4);
4699 return implicit_block;
4701 foreach (VariableDeclaration decl in inits){
4705 if (decl.expression_or_array_initializer is Expression){
4706 expr = (Expression) decl.expression_or_array_initializer;
4709 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4711 expr = new ArrayCreation (type, "", init, decl.Location);
4714 LocalVariableReference var;
4715 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4717 assign = new Assign (var, expr, decl.Location);
4719 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4722 return implicit_block;
4725 Block declare_local_constants (Expression type, ArrayList declarators)
4727 Block implicit_block;
4729 if (current_block.Used)
4730 implicit_block = new Block (current_block, Block.Flags.Implicit);
4732 implicit_block = current_block;
4734 foreach (VariableDeclaration decl in declarators){
4735 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
4738 return implicit_block;
4741 void CheckAttributeTarget (string a)
4745 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4749 Location l = lexer.Location;
4750 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4756 void CheckUnaryOperator (Operator.OpType op)
4760 case Operator.OpType.LogicalNot:
4761 case Operator.OpType.OnesComplement:
4762 case Operator.OpType.Increment:
4763 case Operator.OpType.Decrement:
4764 case Operator.OpType.True:
4765 case Operator.OpType.False:
4766 case Operator.OpType.Addition:
4767 case Operator.OpType.Subtraction:
4772 Location l = lexer.Location;
4773 Report.Error (1019, l, "Overloadable unary operator expected");
4779 void CheckBinaryOperator (Operator.OpType op)
4783 case Operator.OpType.Addition:
4784 case Operator.OpType.Subtraction:
4785 case Operator.OpType.Multiply:
4786 case Operator.OpType.Division:
4787 case Operator.OpType.Modulus:
4788 case Operator.OpType.BitwiseAnd:
4789 case Operator.OpType.BitwiseOr:
4790 case Operator.OpType.ExclusiveOr:
4791 case Operator.OpType.LeftShift:
4792 case Operator.OpType.RightShift:
4793 case Operator.OpType.Equality:
4794 case Operator.OpType.Inequality:
4795 case Operator.OpType.GreaterThan:
4796 case Operator.OpType.LessThan:
4797 case Operator.OpType.GreaterThanOrEqual:
4798 case Operator.OpType.LessThanOrEqual:
4802 Location l = lexer.Location;
4803 Report.Error (1020, l, "Overloadable binary operator expected");
4809 void syntax_error (Location l, string msg)
4811 Report.Error (1003, l, "Syntax error, " + msg);
4814 void note (string s)
4816 // Used to put annotations
4821 public Tokenizer Lexer {
4827 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4829 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4830 this.name = file.Name;
4832 current_container = RootContext.Tree.Types;
4833 // TODO: Make RootContext.Tree.Types a PartialContainer.
4834 current_class = current_container;
4835 current_container.NamespaceEntry = current_namespace;
4836 oob_stack = new Stack ();
4837 switch_stack = new Stack ();
4839 lexer = new Tokenizer (reader, file, defines);
4842 public void parse ()
4845 if (yacc_verbose_flag > 1)
4846 yyparse (lexer, new yydebug.yyDebugSimple ());
4849 Tokenizer tokenizer = lexer as Tokenizer;
4850 tokenizer.cleanup ();
4851 } catch (Exception e){
4853 // Removed for production use, use parser verbose to get the output.
4855 // Console.WriteLine (e);
4856 Report.Error (-25, lexer.Location, "Parsing error");
4857 if (yacc_verbose_flag > 0)
4858 Console.WriteLine (e);
4861 RootContext.Tree.Types.NamespaceEntry = null;
4864 void CheckToken (int error, int yyToken, string msg)
4866 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4867 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4870 Report.Error (error, lexer.Location, msg);
4873 void CheckIdentifierToken (int yyToken)
4875 CheckToken (1041, yyToken, "Identifier expected");
4878 string ConsumeStoredComment ()
4880 string s = tmpComment;
4882 Lexer.doc_state = XmlCommentState.Allowed;