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;
95 /// Current attribute target
96 string current_attr_target;
98 /// assembly and module attribute definition is enabled
99 bool global_attrs_enabled = true;
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 ((string) $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(1518, Lexer.Location, "Attributes cannot be applied to namespaces."
361 + " Expected class, delegate, enum, interface, or struct");
364 MemberName name = (MemberName) $3;
366 if ((current_namespace.Parent != null) && (name.Left != null)) {
367 Report.Error (134, lexer.Location,
368 "Cannot use qualified namespace names in nested " +
369 "namespace declarations");
372 current_namespace = new NamespaceEntry (
373 current_namespace, file, name.GetName (), lexer.Location);
375 namespace_body opt_semicolon
377 current_namespace = current_namespace.Parent;
392 : namespace_or_type_name {
393 MemberName name = (MemberName) $1;
395 $$ = name.GetName ();
402 if (RootContext.Documentation != null)
403 Lexer.doc_state = XmlCommentState.Allowed;
406 opt_namespace_member_declarations
417 opt_namespace_member_declarations
419 | namespace_member_declarations
422 namespace_member_declarations
423 : namespace_member_declaration
424 | namespace_member_declarations namespace_member_declaration
427 namespace_member_declaration
434 Class c = (Class) $1;
435 mod_flags = c.ModFlags;
437 } else if ($1 is Struct){
438 Struct s = (Struct) $1;
439 mod_flags = s.ModFlags;
444 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
446 1527, lexer.Location,
447 "Namespace elements cant be explicitly " +
448 "declared private or protected in `" + name + "'");
450 current_namespace.DeclarationFound = true;
452 | namespace_declaration {
453 current_namespace.DeclarationFound = true;
456 | field_declaration {
457 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
459 | method_declaration {
460 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
467 | interface_declaration
469 | delegate_declaration
471 // Enable this when we have handled all errors, because this acts as a generic fallback
474 // Console.WriteLine ("Token=" + yyToken);
475 // Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
487 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
495 global_attrs_enabled = false;
500 global_attrs_enabled = false;
509 ArrayList sect = (ArrayList) $1;
511 if (global_attrs_enabled) {
512 if (current_attr_target == "module") {
513 CodeGen.Module.AddAttributes (sect);
515 } else if (current_attr_target == "assembly") {
516 CodeGen.Assembly.AddAttributes (sect);
519 $$ = new Attributes (sect);
522 if (RootContext.Documentation != null) {
523 Lexer.check_incorrect_doc_comment ();
525 XmlCommentState.Allowed;
529 $$ = new Attributes (sect);
531 current_attr_target = null;
533 | attribute_sections attribute_section
535 Attributes attrs = $1 as Attributes;
536 ArrayList sect = (ArrayList) $2;
538 if (global_attrs_enabled) {
539 if (current_attr_target == "module") {
540 CodeGen.Module.AddAttributes (sect);
542 } else if (current_attr_target == "assembly") {
543 CodeGen.Assembly.AddAttributes (sect);
547 attrs = new Attributes (sect);
549 attrs.AddAttributes (sect);
553 attrs = new Attributes (sect);
555 attrs.AddAttributes (sect);
558 current_attr_target = null;
563 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
567 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
573 attribute_target_specifier
574 : attribute_target COLON
576 current_attr_target = (string)$1;
584 CheckAttributeTarget ((string) $1);
587 | EVENT { $$ = "event"; }
588 | RETURN { $$ = "return"; }
594 ArrayList attrs = new ArrayList (4);
600 | attribute_list COMMA attribute
602 ArrayList attrs = (ArrayList) $1;
614 opt_attribute_arguments
616 MemberName mname = (MemberName) $1;
617 string name = mname.GetName ();
618 if (current_attr_target == "assembly" || current_attr_target == "module")
619 $$ = new GlobalAttribute (current_container, current_attr_target,
620 name, (ArrayList) $3, (Location) $2);
622 $$ = new Attribute (current_attr_target, name, (ArrayList) $3,
628 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
631 opt_attribute_arguments
632 : /* empty */ { $$ = null; }
633 | OPEN_PARENS attribute_arguments CLOSE_PARENS
641 : opt_positional_argument_list
646 ArrayList args = new ArrayList (4);
652 | positional_argument_list COMMA named_argument_list
654 ArrayList args = new ArrayList (4);
660 | named_argument_list
662 ArrayList args = new ArrayList (4);
671 opt_positional_argument_list
672 : /* empty */ { $$ = null; }
673 | positional_argument_list
676 positional_argument_list
679 ArrayList args = new ArrayList (4);
680 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
684 | positional_argument_list COMMA expression
686 ArrayList args = (ArrayList) $1;
687 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
696 ArrayList args = new ArrayList (4);
701 | named_argument_list COMMA named_argument
703 ArrayList args = (ArrayList) $1;
708 | named_argument_list COMMA expression
710 Report.Error (1016, lexer.Location, "Named attribute argument expected");
716 : IDENTIFIER ASSIGN expression
718 $$ = new DictionaryEntry (
720 new Argument ((Expression) $3, Argument.AType.Expression));
726 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
729 opt_class_member_declarations
731 | class_member_declarations
734 class_member_declarations
735 : class_member_declaration
736 | class_member_declarations
737 class_member_declaration
740 class_member_declaration
741 : constant_declaration // done
742 | field_declaration // done
743 | method_declaration // done
744 | property_declaration // done
745 | event_declaration // done
746 | indexer_declaration // done
747 | operator_declaration // done
748 | constructor_declaration // done
749 | destructor_declaration // done
759 MemberName name = MakeName ((MemberName) $5);
760 bool partial = (bool) $3;
763 ClassPart part = PartialContainer.CreatePart (
764 current_namespace, current_container, name, (int) $2,
765 (Attributes) $1, Kind.Struct, lexer.Location);
767 current_container = part.PartialContainer;
768 current_class = part;
770 current_class = new Struct (
771 current_namespace, current_container, name, (int) $2,
772 (Attributes) $1, lexer.Location);
774 current_container = current_class;
775 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
781 current_class.Bases = (ArrayList) $7;
783 if (RootContext.Documentation != null)
784 current_class.DocComment = Lexer.consume_doc_comment ();
786 current_class.Register ();
790 if (RootContext.Documentation != null)
791 Lexer.doc_state = XmlCommentState.Allowed;
797 current_container = current_container.Parent;
798 current_class = current_container;
800 | opt_attributes opt_modifiers opt_partial STRUCT error {
801 CheckIdentifierToken (yyToken);
808 if (RootContext.Documentation != null)
809 Lexer.doc_state = XmlCommentState.Allowed;
811 opt_struct_member_declarations CLOSE_BRACE
814 opt_struct_member_declarations
816 | struct_member_declarations
819 struct_member_declarations
820 : struct_member_declaration
821 | struct_member_declarations struct_member_declaration
824 struct_member_declaration
825 : constant_declaration
828 | property_declaration
830 | indexer_declaration
831 | operator_declaration
832 | constructor_declaration
836 * This is only included so we can flag error 575:
837 * destructors only allowed on class types
839 | destructor_declaration
850 int modflags = (int) $2;
851 foreach (VariableDeclaration constant in (ArrayList) $5){
852 Location l = constant.Location;
853 if ((modflags & Modifiers.STATIC) != 0) {
854 Report.Error (504, l, "The constant '{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
858 Const c = new Const (
859 current_class, (Expression) $4, (string) constant.identifier,
860 (Expression) constant.expression_or_array_initializer, modflags,
863 if (RootContext.Documentation != null) {
864 c.DocComment = Lexer.consume_doc_comment ();
865 Lexer.doc_state = XmlCommentState.Allowed;
867 current_container.AddConstant (c);
873 : constant_declarator
875 ArrayList constants = new ArrayList (4);
880 | constant_declarators COMMA constant_declarator
883 ArrayList constants = (ArrayList) $1;
890 : IDENTIFIER ASSIGN constant_expression
892 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
896 // A const field requires a value to be provided
897 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
909 Expression type = (Expression) $3;
912 foreach (VariableDeclaration var in (ArrayList) $4){
913 Location l = var.Location;
915 Field field = new Field (current_class, type, mod, var.identifier,
916 var.expression_or_array_initializer,
919 if (RootContext.Documentation != null) {
920 field.DocComment = Lexer.consume_doc_comment ();
921 Lexer.doc_state = XmlCommentState.Allowed;
923 current_container.AddField (field);
931 Report.Error (670, lexer.Location, "void type is not allowed for fields");
936 : variable_declarator
938 ArrayList decl = new ArrayList (4);
942 | variable_declarators COMMA variable_declarator
944 ArrayList decls = (ArrayList) $1;
951 : IDENTIFIER ASSIGN variable_initializer
953 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
957 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
970 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
972 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
976 Report.Error (1575, lexer.Location, "A stackalloc expression requires [] after type");
983 iterator_container = (IIteratorContainer) $1;
984 if (RootContext.Documentation != null)
985 Lexer.doc_state = XmlCommentState.NotAllowed;
989 Method method = (Method) $1;
990 Block b = (Block) $3;
991 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
994 if ((method.ModFlags & extern_abstract) == 0){
996 501, lexer.Location, current_container.MakeName (method.Name) +
997 "must declare a body because it is not marked abstract or extern");
1000 if ((method.ModFlags & Modifiers.EXTERN) != 0){
1002 179, lexer.Location, current_container.MakeName (method.Name) +
1003 " is declared extern, but has a body");
1007 method.Block = (ToplevelBlock) $3;
1008 current_container.AddMethod (method);
1010 current_local_parameters = null;
1011 iterator_container = null;
1013 if (RootContext.Documentation != null)
1014 Lexer.doc_state = XmlCommentState.Allowed;
1028 1585, lexer.Location, "Member modifier `" +
1029 Modifiers.Name (i) + "' must precede member type and name");
1040 type namespace_or_type_name
1041 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1043 MemberName name = (MemberName) $4;
1045 Method method = new Method (current_class, (Expression) $3, (int) $2,
1046 false, name, (Parameters) $6, (Attributes) $1,
1049 current_local_parameters = (Parameters) $6;
1051 if (RootContext.Documentation != null)
1052 method.DocComment = Lexer.consume_doc_comment ();
1058 VOID namespace_or_type_name
1059 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1061 MemberName name = (MemberName) $4;
1063 Method method = new Method (current_class, TypeManager.system_void_expr,
1064 (int) $2, false, name, (Parameters) $6,
1065 (Attributes) $1, lexer.Location);
1067 current_local_parameters = (Parameters) $6;
1069 if (RootContext.Documentation != null)
1070 method.DocComment = Lexer.consume_doc_comment ();
1077 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1079 Report.Error (1585, lexer.Location,
1080 String.Format ("Modifier {0} should appear before type",
1081 Modifiers.Name ((int) $4)));
1082 MemberName name = (MemberName) $4;
1084 Method method = new Method (current_class, TypeManager.system_void_expr,
1085 0, false, name, (Parameters) $7, (Attributes) $1,
1088 current_local_parameters = (Parameters) $7;
1090 if (RootContext.Documentation != null)
1091 method.DocComment = Lexer.consume_doc_comment ();
1099 | SEMICOLON { $$ = null; }
1102 opt_formal_parameter_list
1103 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1104 | formal_parameter_list
1107 formal_parameter_list
1110 ArrayList pars_list = (ArrayList) $1;
1112 Parameter [] pars = new Parameter [pars_list.Count];
1113 pars_list.CopyTo (pars);
1115 $$ = new Parameters (pars, null, lexer.Location);
1117 | fixed_parameters COMMA parameter_array
1119 ArrayList pars_list = (ArrayList) $1;
1121 Parameter [] pars = new Parameter [pars_list.Count];
1122 pars_list.CopyTo (pars);
1124 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
1126 | fixed_parameters COMMA ARGLIST
1128 ArrayList pars_list = (ArrayList) $1;
1130 Parameter [] pars = new Parameter [pars_list.Count];
1131 pars_list.CopyTo (pars);
1133 $$ = new Parameters (pars, true, lexer.Location);
1135 | parameter_array COMMA fixed_parameters
1137 Report.Error (231, lexer.Location, "A params parameter must be the last parameter in a formal parameter list");
1140 | ARGLIST COMMA fixed_parameters
1142 Report.Error (257, lexer.Location, "An __arglist parameter must be the last parameter in a formal parameter list");
1147 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1151 $$ = new Parameters (null, true, lexer.Location);
1158 ArrayList pars = new ArrayList (4);
1163 | fixed_parameters COMMA fixed_parameter
1165 ArrayList pars = (ArrayList) $1;
1174 opt_parameter_modifier
1178 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1181 opt_parameter_modifier
1184 Report.Error (1001, lexer.Location, "Identifier expected");
1188 opt_parameter_modifier
1191 CheckIdentifierToken (yyToken);
1195 opt_parameter_modifier
1201 Report.Error (241, lexer.Location, "Default parameter specifiers are not permitted");
1206 opt_parameter_modifier
1207 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1208 | parameter_modifier
1212 : REF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1213 | OUT { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1217 : opt_attributes PARAMS type IDENTIFIER
1219 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1220 note ("type must be a single-dimension array type");
1222 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1224 Report.Error (1611, lexer.Location, "The params parameter cannot be declared as ref or out");
1227 | opt_attributes PARAMS type error {
1228 CheckIdentifierToken (yyToken);
1233 property_declaration
1237 namespace_or_type_name
1239 if (RootContext.Documentation != null)
1240 tmpComment = Lexer.consume_doc_comment ();
1244 implicit_value_parameter_type = (Expression) $3;
1246 lexer.PropertyParsing = true;
1248 $$ = lexer.Location;
1250 iterator_container = SimpleIteratorContainer.GetSimple ();
1252 accessor_declarations
1254 lexer.PropertyParsing = false;
1259 Pair pair = (Pair) $8;
1260 Accessor get_block = (Accessor) pair.First;
1261 Accessor set_block = (Accessor) pair.Second;
1263 Location loc = (Location) $7;
1264 MemberName name = (MemberName) $4;
1266 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1267 name, (Attributes) $1, get_block, set_block, loc);
1268 if (SimpleIteratorContainer.Simple.Yields)
1271 current_container.AddProperty (prop);
1272 implicit_value_parameter_type = null;
1273 iterator_container = null;
1275 if (RootContext.Documentation != null)
1276 prop.DocComment = ConsumeStoredComment ();
1281 accessor_declarations
1282 : get_accessor_declaration opt_set_accessor_declaration
1284 $$ = new Pair ($1, $2);
1286 | set_accessor_declaration opt_get_accessor_declaration
1288 $$ = new Pair ($2, $1);
1292 opt_get_accessor_declaration
1293 : /* empty */ { $$ = null; }
1294 | get_accessor_declaration
1297 opt_set_accessor_declaration
1298 : /* empty */ { $$ = null; }
1299 | set_accessor_declaration
1302 get_accessor_declaration
1303 : opt_attributes opt_modifiers GET
1305 // If this is not the case, then current_local_parameters has already
1306 // been set in indexer_declaration
1307 if (parsing_indexer == false)
1308 current_local_parameters = null;
1310 current_local_parameters = indexer_parameters;
1311 lexer.PropertyParsing = false;
1315 $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
1316 current_local_parameters = null;
1317 lexer.PropertyParsing = true;
1319 if (RootContext.Documentation != null)
1320 if (Lexer.doc_state == XmlCommentState.Error)
1321 Lexer.doc_state = XmlCommentState.NotAllowed;
1325 set_accessor_declaration
1326 : opt_attributes opt_modifiers SET
1329 Parameter implicit_value_parameter = new Parameter (
1330 implicit_value_parameter_type, "value",
1331 Parameter.Modifier.NONE, null);
1333 if (parsing_indexer == false) {
1334 args = new Parameter [1];
1335 args [0] = implicit_value_parameter;
1336 current_local_parameters = new Parameters (args, null, lexer.Location);
1338 Parameter [] fpars = indexer_parameters.FixedParameters;
1341 int count = fpars.Length;
1343 args = new Parameter [count + 1];
1344 fpars.CopyTo (args, 0);
1345 args [count] = implicit_value_parameter;
1348 current_local_parameters = new Parameters (
1349 args, indexer_parameters.ArrayParameter, lexer.Location);
1352 lexer.PropertyParsing = false;
1356 $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
1357 current_local_parameters = null;
1358 lexer.PropertyParsing = true;
1360 if (RootContext.Documentation != null
1361 && Lexer.doc_state == XmlCommentState.Error)
1362 Lexer.doc_state = XmlCommentState.NotAllowed;
1368 | SEMICOLON { $$ = null; }
1371 interface_declaration
1375 INTERFACE member_name
1377 MemberName name = MakeName ((MemberName) $5);
1378 bool partial = (bool) $3;
1381 ClassPart part = PartialContainer.CreatePart (
1382 current_namespace, current_container, name, (int) $2,
1383 (Attributes) $1, Kind.Interface, lexer.Location);
1385 current_container = part.PartialContainer;
1386 current_class = part;
1388 current_class = new Interface (
1389 current_namespace, current_container, name, (int) $2,
1390 (Attributes) $1, lexer.Location);
1392 current_container = current_class;
1393 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
1398 current_class.Bases = (ArrayList) $7;
1400 if (RootContext.Documentation != null) {
1401 current_class.DocComment = Lexer.consume_doc_comment ();
1402 Lexer.doc_state = XmlCommentState.Allowed;
1405 current_class.Register ();
1409 if (RootContext.Documentation != null)
1410 Lexer.doc_state = XmlCommentState.Allowed;
1416 current_container = current_container.Parent;
1417 current_class = current_container;
1419 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1420 CheckIdentifierToken (yyToken);
1426 opt_interface_member_declarations
1430 opt_interface_member_declarations
1432 | interface_member_declarations
1435 interface_member_declarations
1436 : interface_member_declaration
1437 | interface_member_declarations interface_member_declaration
1440 interface_member_declaration
1441 : interface_method_declaration
1443 Method m = (Method) $1;
1445 current_container.AddMethod (m);
1447 if (RootContext.Documentation != null)
1448 Lexer.doc_state = XmlCommentState.Allowed;
1450 | interface_property_declaration
1452 Property p = (Property) $1;
1454 current_container.AddProperty (p);
1456 if (RootContext.Documentation != null)
1457 Lexer.doc_state = XmlCommentState.Allowed;
1459 | interface_event_declaration
1462 Event e = (Event) $1;
1463 current_container.AddEvent (e);
1466 if (RootContext.Documentation != null)
1467 Lexer.doc_state = XmlCommentState.Allowed;
1469 | interface_indexer_declaration
1471 Indexer i = (Indexer) $1;
1473 current_container.AddIndexer (i);
1475 if (RootContext.Documentation != null)
1476 Lexer.doc_state = XmlCommentState.Allowed;
1484 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1489 interface_method_declaration
1490 : opt_attributes opt_new type namespace_or_type_name
1491 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1494 MemberName name = (MemberName) $4;
1496 $$ = new Method (current_class, (Expression) $3, (int) $2, true,
1497 name, (Parameters) $6, (Attributes) $1, lexer.Location);
1498 if (RootContext.Documentation != null)
1499 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1501 | opt_attributes opt_new VOID namespace_or_type_name
1502 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1505 MemberName name = (MemberName) $4;
1507 $$ = new Method (current_class, TypeManager.system_void_expr, (int) $2,
1508 true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
1509 if (RootContext.Documentation != null)
1510 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1514 interface_property_declaration
1519 { lexer.PropertyParsing = true; }
1521 { lexer.PropertyParsing = false; }
1524 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1526 $$ = new Property (current_class, (Expression) $3, (int) $2, true,
1527 new MemberName ((string) $4), (Attributes) $1,
1528 pinfo.Get, pinfo.Set, lexer.Location);
1529 if (RootContext.Documentation != null)
1530 ((Property) $$).DocComment = Lexer.consume_doc_comment ();
1535 CheckIdentifierToken (yyToken);
1541 : opt_attributes opt_modifiers GET SEMICOLON
1542 { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, (int) $2, 0, lexer.Location, lexer.Location); }
1543 | opt_attributes opt_modifiers SET SEMICOLON
1544 { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1, 0, (int) $2, lexer.Location, lexer.Location); }
1545 | opt_attributes opt_modifiers GET SEMICOLON opt_attributes opt_modifiers SET SEMICOLON
1546 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $5, (int) $2, (int) $6, lexer.Location, lexer.Location); }
1547 | opt_attributes opt_modifiers SET SEMICOLON opt_attributes opt_modifiers GET SEMICOLON
1548 { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $5, (Attributes) $1, (int) $6, (int) $2, lexer.Location, lexer.Location); }
1551 interface_event_declaration
1552 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1554 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1555 new MemberName ((string) $5), null,
1556 (Attributes) $1, lexer.Location);
1557 if (RootContext.Documentation != null)
1558 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1560 | opt_attributes opt_new EVENT type error {
1561 CheckIdentifierToken (yyToken);
1564 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1565 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1568 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
1569 Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
1574 interface_indexer_declaration
1575 : opt_attributes opt_new type THIS
1576 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1578 { lexer.PropertyParsing = true; }
1580 { lexer.PropertyParsing = false; }
1583 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1585 $$ = new Indexer (current_class, (Expression) $3,
1586 new MemberName (TypeContainer.DefaultIndexerName),
1587 (int) $2, true, (Parameters) $6, (Attributes) $1,
1588 info.Get, info.Set, lexer.Location);
1589 if (RootContext.Documentation != null)
1590 ((Indexer) $$).DocComment = ConsumeStoredComment ();
1594 operator_declaration
1595 : opt_attributes opt_modifiers operator_declarator
1597 iterator_container = SimpleIteratorContainer.GetSimple ();
1601 OperatorDeclaration decl = (OperatorDeclaration) $3;
1603 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
1605 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null);
1606 if (decl.arg2type != null)
1607 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null);
1609 Operator op = new Operator (
1610 current_class, decl.optype, decl.ret_type, (int) $2,
1611 new Parameters (param_list, null, decl.location),
1612 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1614 if (RootContext.Documentation != null)
1615 op.DocComment = ConsumeStoredComment ();
1617 if (SimpleIteratorContainer.Simple.Yields)
1620 // Note again, checking is done in semantic analysis
1621 current_container.AddOperator (op);
1623 current_local_parameters = null;
1624 iterator_container = null;
1630 | SEMICOLON { $$ = null; }
1633 : type OPERATOR overloadable_operator
1634 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1636 Operator.OpType op = (Operator.OpType) $3;
1637 CheckUnaryOperator (op);
1639 if (op == Operator.OpType.Addition)
1640 op = Operator.OpType.UnaryPlus;
1642 if (op == Operator.OpType.Subtraction)
1643 op = Operator.OpType.UnaryNegation;
1645 Parameter [] pars = new Parameter [1];
1646 Expression type = (Expression) $5;
1648 pars [0] = new Parameter (type, (string) $6, Parameter.Modifier.NONE, null);
1650 current_local_parameters = new Parameters (pars, null, lexer.Location);
1652 if (RootContext.Documentation != null) {
1653 tmpComment = Lexer.consume_doc_comment ();
1654 Lexer.doc_state = XmlCommentState.Allowed;
1657 $$ = new OperatorDeclaration (op, (Expression) $1, type, (string) $6,
1658 null, null, lexer.Location);
1660 | type OPERATOR overloadable_operator
1662 type IDENTIFIER COMMA
1666 CheckBinaryOperator ((Operator.OpType) $3);
1668 Parameter [] pars = new Parameter [2];
1670 Expression typeL = (Expression) $5;
1671 Expression typeR = (Expression) $8;
1673 pars [0] = new Parameter (typeL, (string) $6, Parameter.Modifier.NONE, null);
1674 pars [1] = new Parameter (typeR, (string) $9, Parameter.Modifier.NONE, null);
1676 current_local_parameters = new Parameters (pars, null, lexer.Location);
1678 if (RootContext.Documentation != null) {
1679 tmpComment = Lexer.consume_doc_comment ();
1680 Lexer.doc_state = XmlCommentState.Allowed;
1683 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1685 typeR, (string) $9, lexer.Location);
1687 | conversion_operator_declarator
1690 overloadable_operator
1692 : BANG { $$ = Operator.OpType.LogicalNot; }
1693 | TILDE { $$ = Operator.OpType.OnesComplement; }
1694 | OP_INC { $$ = Operator.OpType.Increment; }
1695 | OP_DEC { $$ = Operator.OpType.Decrement; }
1696 | TRUE { $$ = Operator.OpType.True; }
1697 | FALSE { $$ = Operator.OpType.False; }
1698 // Unary and binary:
1699 | PLUS { $$ = Operator.OpType.Addition; }
1700 | MINUS { $$ = Operator.OpType.Subtraction; }
1702 | STAR { $$ = Operator.OpType.Multiply; }
1703 | DIV { $$ = Operator.OpType.Division; }
1704 | PERCENT { $$ = Operator.OpType.Modulus; }
1705 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1706 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1707 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1708 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1709 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1710 | OP_EQ { $$ = Operator.OpType.Equality; }
1711 | OP_NE { $$ = Operator.OpType.Inequality; }
1712 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1713 | OP_LT { $$ = Operator.OpType.LessThan; }
1714 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1715 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1718 conversion_operator_declarator
1719 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1721 Parameter [] pars = new Parameter [1];
1723 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1725 current_local_parameters = new Parameters (pars, null, lexer.Location);
1727 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1728 null, null, lexer.Location);
1730 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1732 Parameter [] pars = new Parameter [1];
1734 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1736 current_local_parameters = new Parameters (pars, null, lexer.Location);
1738 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1739 null, null, lexer.Location);
1743 syntax_error (lexer.Location, "'operator' expected");
1747 syntax_error (lexer.Location, "'operator' expected");
1751 constructor_declaration
1754 constructor_declarator
1757 Constructor c = (Constructor) $3;
1758 c.Block = (ToplevelBlock) $4;
1759 c.OptAttributes = (Attributes) $1;
1760 c.ModFlags = (int) $2;
1762 if (RootContext.Documentation != null)
1763 c.DocComment = ConsumeStoredComment ();
1765 if (c.Name == current_container.Basename){
1766 if ((c.ModFlags & Modifiers.STATIC) != 0){
1767 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1769 515, c.Location, String.Format (
1770 "`{0}.{1}': static constructor can not have access modifiers",
1771 c.Name, current_container.Name));
1774 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1776 if (c.Initializer != null){
1779 "Static constructors can not have an explicit this or base " +
1780 "constructor invocations");
1783 if (!c.Parameters.Empty){
1785 132, c.Location, "Static constructors should not have parameters");
1788 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1791 // We let another layer check the validity of the constructor.
1792 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1795 current_container.AddConstructor (c);
1797 current_local_parameters = null;
1798 if (RootContext.Documentation != null)
1799 Lexer.doc_state = XmlCommentState.Allowed;
1803 constructor_declarator
1806 if (RootContext.Documentation != null) {
1807 tmpComment = Lexer.consume_doc_comment ();
1808 Lexer.doc_state = XmlCommentState.Allowed;
1811 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1813 oob_stack.Push (lexer.Location);
1815 current_local_parameters = (Parameters) $4;
1817 opt_constructor_initializer
1819 Location l = (Location) oob_stack.Pop ();
1820 $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $4,
1821 (ConstructorInitializer) $7, l);
1827 | SEMICOLON { $$ = null; }
1830 opt_constructor_initializer
1831 : /* empty */ { $$ = null; }
1832 | constructor_initializer
1835 constructor_initializer
1836 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1838 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1840 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1842 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1845 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1851 : /* EMPTY */ { $$ = 0; }
1852 | UNSAFE { $$ = Modifiers.UNSAFE; }
1853 | EXTERN { $$ = Modifiers.EXTERN; }
1856 destructor_declaration
1857 : opt_attributes opt_finalizer TILDE
1859 if (RootContext.Documentation != null) {
1860 tmpComment = Lexer.consume_doc_comment ();
1861 Lexer.doc_state = XmlCommentState.NotAllowed;
1864 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1866 if ((string) $5 != current_container.Basename){
1867 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1868 } else if (!(current_container is Class)){
1869 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1871 Location l = lexer.Location;
1874 if (!RootContext.StdLib && current_container.Name == "System.Object")
1875 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1877 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1879 if ((m & Modifiers.UNSAFE) != 0){
1880 if (!RootContext.Unsafe){
1881 Report.Error (227, l,
1882 "Unsafe code requires the -unsafe command " +
1883 "line option to be specified");
1887 Method d = new Destructor (
1888 current_class, TypeManager.system_void_expr, m, "Finalize",
1889 new Parameters (null, null, l), (Attributes) $1, l);
1890 if (RootContext.Documentation != null)
1891 d.DocComment = ConsumeStoredComment ();
1893 d.Block = (ToplevelBlock) $8;
1894 current_container.AddMethod (d);
1902 EVENT type variable_declarators SEMICOLON
1904 foreach (VariableDeclaration var in (ArrayList) $5) {
1906 MemberName name = new MemberName (var.identifier);
1908 Event e = new EventField (
1909 current_class, (Expression) $4, (int) $2, false, name,
1910 var.expression_or_array_initializer, (Attributes) $1,
1913 current_container.AddEvent (e);
1915 if (RootContext.Documentation != null) {
1916 e.DocComment = Lexer.consume_doc_comment ();
1917 Lexer.doc_state = XmlCommentState.Allowed;
1923 EVENT type namespace_or_type_name
1926 implicit_value_parameter_type = (Expression) $4;
1927 lexer.EventParsing = true;
1928 oob_stack.Push (lexer.Location);
1930 event_accessor_declarations
1932 lexer.EventParsing = false;
1936 Location loc = (Location) oob_stack.Pop ();
1939 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1942 Pair pair = (Pair) $8;
1944 MemberName name = (MemberName) $5;
1946 Event e = new EventProperty (
1947 current_class, (Expression) $4, (int) $2, false, name, null,
1948 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
1950 if (RootContext.Documentation != null) {
1951 e.DocComment = Lexer.consume_doc_comment ();
1952 Lexer.doc_state = XmlCommentState.Allowed;
1955 current_container.AddEvent (e);
1956 implicit_value_parameter_type = null;
1959 | opt_attributes opt_modifiers EVENT type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
1960 MemberName mn = (MemberName) $5;
1962 if (mn.Left != null)
1963 Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
1965 Report.Error (71, lexer.Location, "Event declaration should use property syntax");
1967 if (RootContext.Documentation != null)
1968 Lexer.doc_state = XmlCommentState.Allowed;
1972 event_accessor_declarations
1973 : add_accessor_declaration remove_accessor_declaration
1975 $$ = new Pair ($1, $2);
1977 | remove_accessor_declaration add_accessor_declaration
1979 $$ = new Pair ($2, $1);
1981 | add_accessor_declaration { $$ = null; }
1982 | remove_accessor_declaration { $$ = null; }
1985 Report.Error (1055, lexer.Location, "An add or remove accessor expected");
1991 add_accessor_declaration
1992 : opt_attributes ADD
1994 Parameter [] args = new Parameter [1];
1995 Parameter implicit_value_parameter = new Parameter (
1996 implicit_value_parameter_type, "value",
1997 Parameter.Modifier.NONE, null);
1999 args [0] = implicit_value_parameter;
2001 current_local_parameters = new Parameters (args, null, lexer.Location);
2002 lexer.EventParsing = false;
2006 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
2007 lexer.EventParsing = true;
2009 | opt_attributes ADD error {
2010 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
2015 remove_accessor_declaration
2016 : opt_attributes REMOVE
2018 Parameter [] args = new Parameter [1];
2019 Parameter implicit_value_parameter = new Parameter (
2020 implicit_value_parameter_type, "value",
2021 Parameter.Modifier.NONE, null);
2023 args [0] = implicit_value_parameter;
2025 current_local_parameters = new Parameters (args, null, lexer.Location);
2026 lexer.EventParsing = false;
2030 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
2031 lexer.EventParsing = true;
2033 | opt_attributes REMOVE error {
2034 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
2040 : opt_attributes opt_modifiers indexer_declarator
2043 IndexerDeclaration decl = (IndexerDeclaration) $3;
2045 implicit_value_parameter_type = decl.type;
2047 lexer.PropertyParsing = true;
2048 parsing_indexer = true;
2050 indexer_parameters = decl.param_list;
2051 oob_stack.Push (lexer.Location);
2053 accessor_declarations
2055 lexer.PropertyParsing = false;
2056 parsing_indexer = false;
2060 // The signature is computed from the signature of the indexer. Look
2061 // at section 3.6 on the spec
2062 Location loc = (Location) oob_stack.Pop ();
2064 IndexerDeclaration decl = (IndexerDeclaration) $3;
2065 Pair pair = (Pair) $6;
2066 Accessor get_block = (Accessor) pair.First;
2067 Accessor set_block = (Accessor) pair.Second;
2070 if (decl.interface_type != null)
2071 name = new MemberName (decl.interface_type,
2072 TypeContainer.DefaultIndexerName);
2074 name = new MemberName (TypeContainer.DefaultIndexerName);
2076 indexer = new Indexer (current_class, decl.type, name,
2077 (int) $2, false, decl.param_list, (Attributes) $1,
2078 get_block, set_block, loc);
2079 if (RootContext.Documentation != null)
2080 indexer.DocComment = ConsumeStoredComment ();
2082 current_container.AddIndexer (indexer);
2084 current_local_parameters = null;
2085 implicit_value_parameter_type = null;
2086 indexer_parameters = null;
2091 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2093 Parameters pars = (Parameters) $4;
2094 if (pars.HasArglist) {
2095 // "__arglist is not valid in this context"
2096 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2097 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2098 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2100 if (RootContext.Documentation != null) {
2101 tmpComment = Lexer.consume_doc_comment ();
2102 Lexer.doc_state = XmlCommentState.Allowed;
2105 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
2107 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2109 Parameters pars = (Parameters) $6;
2111 if (pars.HasArglist) {
2112 // "__arglist is not valid in this context"
2113 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2114 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2115 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2118 MemberName name = (MemberName) $2;
2119 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
2121 if (RootContext.Documentation != null) {
2122 tmpComment = Lexer.consume_doc_comment ();
2123 Lexer.doc_state = XmlCommentState.Allowed;
2133 if (RootContext.Documentation != null)
2134 enumTypeComment = Lexer.consume_doc_comment ();
2139 Location enum_location = lexer.Location;
2141 MemberName full_name = MakeName (new MemberName ((string) $4));
2142 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
2143 full_name, (Attributes) $1, enum_location);
2145 if (RootContext.Documentation != null)
2146 e.DocComment = enumTypeComment;
2148 foreach (VariableDeclaration ev in (ArrayList) $7) {
2149 e.AddEnumMember (ev.identifier,
2150 (Expression) ev.expression_or_array_initializer,
2151 ev.Location, ev.OptAttributes,
2155 string name = full_name.GetName ();
2156 current_container.AddEnum (e);
2157 RootContext.Tree.RecordDecl (name, e);
2163 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2164 | COLON type { $$ = $2; }
2170 if (RootContext.Documentation != null)
2171 Lexer.doc_state = XmlCommentState.Allowed;
2173 opt_enum_member_declarations
2175 // here will be evaluated after CLOSE_BLACE is consumed.
2176 if (RootContext.Documentation != null)
2177 Lexer.doc_state = XmlCommentState.Allowed;
2185 opt_enum_member_declarations
2186 : /* empty */ { $$ = new ArrayList (4); }
2187 | enum_member_declarations opt_comma { $$ = $1; }
2190 enum_member_declarations
2191 : enum_member_declaration
2193 ArrayList l = new ArrayList (4);
2198 | enum_member_declarations COMMA enum_member_declaration
2200 ArrayList l = (ArrayList) $1;
2208 enum_member_declaration
2209 : opt_attributes IDENTIFIER
2211 VariableDeclaration vd = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
2213 if (RootContext.Documentation != null) {
2214 vd.DocComment = Lexer.consume_doc_comment ();
2215 Lexer.doc_state = XmlCommentState.Allowed;
2220 | opt_attributes IDENTIFIER
2222 $$ = lexer.Location;
2223 if (RootContext.Documentation != null) {
2224 tmpComment = Lexer.consume_doc_comment ();
2225 Lexer.doc_state = XmlCommentState.NotAllowed;
2230 VariableDeclaration vd = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
2232 if (RootContext.Documentation != null)
2233 vd.DocComment = ConsumeStoredComment ();
2239 delegate_declaration
2242 DELEGATE type member_name
2243 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2246 Location l = lexer.Location;
2247 MemberName name = MakeName ((MemberName) $5);
2248 Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
2249 (int) $2, name, (Parameters) $7, (Attributes) $1, l);
2251 if (RootContext.Documentation != null) {
2252 del.DocComment = Lexer.consume_doc_comment ();
2253 Lexer.doc_state = XmlCommentState.Allowed;
2256 current_container.AddDelegate (del);
2257 RootContext.Tree.RecordDecl (name.GetName (true), del);
2261 DELEGATE VOID member_name
2262 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2265 Location l = lexer.Location;
2266 MemberName name = MakeName ((MemberName) $5);
2267 Delegate del = new Delegate (
2268 current_namespace, current_container,
2269 TypeManager.system_void_expr, (int) $2, name,
2270 (Parameters) $7, (Attributes) $1, l);
2272 if (RootContext.Documentation != null) {
2273 del.DocComment = Lexer.consume_doc_comment ();
2274 Lexer.doc_state = XmlCommentState.Allowed;
2277 current_container.AddDelegate (del);
2278 RootContext.Tree.RecordDecl (name.GetName (true), del);
2282 namespace_or_type_name
2284 | namespace_or_type_name DOT IDENTIFIER {
2285 $$ = new MemberName ((MemberName) $1, (string) $3);
2291 $$ = new MemberName ((string) $1);
2296 * Before you think of adding a return_type, notice that we have been
2297 * using two rules in the places where it matters (one rule using type
2298 * and another identical one that uses VOID as the return type). This
2299 * gets rid of a shift/reduce couple
2302 : namespace_or_type_name
2304 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2316 // Note that here only unmanaged types are allowed but we
2317 // can't perform checks during this phase - we do it during
2318 // semantic analysis.
2320 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2324 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2330 | non_expression_type rank_specifier
2332 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2334 | non_expression_type STAR
2336 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2338 | expression rank_specifiers
2340 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2344 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2348 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2349 // through this different path
2351 | multiplicative_expression STAR
2353 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2360 ArrayList types = new ArrayList (4);
2365 | type_list COMMA type
2367 ArrayList types = (ArrayList) $1;
2375 * replaces all the productions for isolating the various
2376 * simple types, but we need this to reuse it easily in local_variable_type
2379 : OBJECT { $$ = TypeManager.system_object_expr; }
2380 | STRING { $$ = TypeManager.system_string_expr; }
2381 | BOOL { $$ = TypeManager.system_boolean_expr; }
2382 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2383 | FLOAT { $$ = TypeManager.system_single_expr; }
2384 | DOUBLE { $$ = TypeManager.system_double_expr; }
2389 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2390 | BYTE { $$ = TypeManager.system_byte_expr; }
2391 | SHORT { $$ = TypeManager.system_int16_expr; }
2392 | USHORT { $$ = TypeManager.system_uint16_expr; }
2393 | INT { $$ = TypeManager.system_int32_expr; }
2394 | UINT { $$ = TypeManager.system_uint32_expr; }
2395 | LONG { $$ = TypeManager.system_int64_expr; }
2396 | ULONG { $$ = TypeManager.system_uint64_expr; }
2397 | CHAR { $$ = TypeManager.system_char_expr; }
2398 | VOID { $$ = TypeManager.system_void_expr; }
2402 : type rank_specifiers
2404 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2409 // Expressions, section 7.5
2419 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2421 | parenthesized_expression
2423 | invocation_expression
2427 | post_increment_expression
2428 | post_decrement_expression
2432 | checked_expression
2433 | unchecked_expression
2434 | pointer_member_access
2435 | anonymous_method_expression
2442 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2443 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2444 | NULL { $$ = NullLiteral.Null; }
2448 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2449 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2450 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2455 object v = lexer.Value;
2461 $$ = IntLiteral.Zero;
2463 $$ = IntLiteral.One;
2465 $$ = new IntLiteral (i);
2466 } else if (v is uint)
2467 $$ = new UIntLiteral ((UInt32) v);
2469 $$ = new LongLiteral ((Int64) v);
2470 else if (v is ulong)
2471 $$ = new ULongLiteral ((UInt64) v);
2473 Console.WriteLine ("OOPS. Unexpected result from scanner");
2478 : TRUE { $$ = new BoolLiteral (true); }
2479 | FALSE { $$ = new BoolLiteral (false); }
2482 parenthesized_expression_0
2483 : OPEN_PARENS expression CLOSE_PARENS
2486 lexer.Deambiguate_CloseParens ();
2487 // After this, the next token returned is one of
2488 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2489 // or CLOSE_PARENS_MINUS.
2493 parenthesized_expression
2494 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2498 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2500 // If a parenthesized expression is followed by a minus, we need to wrap
2501 // the expression inside a ParenthesizedExpression for the CS0075 check
2502 // in Binary.DoResolve().
2503 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2508 : primary_expression DOT IDENTIFIER
2510 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2512 | predefined_type DOT IDENTIFIER
2514 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2522 invocation_expression
2523 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2526 Location l = lexer.Location;
2527 Report.Error (1, l, "Parse error");
2529 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2531 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2533 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2535 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2537 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2542 : /* empty */ { $$ = null; }
2549 ArrayList list = new ArrayList (4);
2553 | argument_list COMMA argument
2555 ArrayList list = (ArrayList) $1;
2559 | argument_list error {
2560 CheckToken (1026, yyToken, ", or ) expected");
2567 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2569 | REF variable_reference
2571 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2573 | OUT variable_reference
2575 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2577 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
2579 ArrayList list = (ArrayList) $3;
2580 Argument[] args = new Argument [list.Count];
2581 list.CopyTo (args, 0);
2583 Expression expr = new Arglist (args, lexer.Location);
2584 $$ = new Argument (expr, Argument.AType.Expression);
2588 $$ = new Argument (new ArglistAccess (lexer.Location), Argument.AType.ArgList);
2593 : expression { note ("section 5.4"); $$ = $1; }
2597 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2599 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2601 | primary_expression rank_specifiers
2603 // So the super-trick is that primary_expression
2604 // can only be either a SimpleName or a MemberAccess.
2605 // The MemberAccess case arises when you have a fully qualified type-name like :
2607 // SimpleName is when you have
2610 Expression expr = (Expression) $1;
2611 if (expr is ComposedCast){
2612 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2613 } else if (!(expr is SimpleName || expr is MemberAccess)){
2614 Error_ExpectingTypeName (lexer.Location, expr);
2615 $$ = TypeManager.system_object_expr;
2618 // So we extract the string corresponding to the SimpleName
2621 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2629 ArrayList list = new ArrayList (4);
2633 | expression_list COMMA expression
2635 ArrayList list = (ArrayList) $1;
2644 $$ = new This (current_block, lexer.Location);
2649 : BASE DOT IDENTIFIER
2651 $$ = new BaseAccess ((string) $3, lexer.Location);
2653 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2655 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2658 Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
2663 post_increment_expression
2664 : primary_expression OP_INC
2666 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2667 (Expression) $1, lexer.Location);
2671 post_decrement_expression
2672 : primary_expression OP_DEC
2674 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2675 (Expression) $1, lexer.Location);
2680 : object_or_delegate_creation_expression
2681 | array_creation_expression
2684 object_or_delegate_creation_expression
2685 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2687 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2691 array_creation_expression
2692 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2694 opt_array_initializer
2696 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2698 | NEW type rank_specifiers array_initializer
2700 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2704 Report.Error (1031, lexer.Location, "Type expected");
2709 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2725 : rank_specifier opt_rank_specifier
2727 $$ = (string) $2 + (string) $1;
2732 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2734 $$ = "[" + (string) $2 + "]";
2754 | dim_separators COMMA
2756 $$ = (string) $1 + ",";
2760 opt_array_initializer
2772 : OPEN_BRACE CLOSE_BRACE
2774 ArrayList list = new ArrayList (4);
2777 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2779 $$ = (ArrayList) $2;
2783 variable_initializer_list
2784 : variable_initializer
2786 ArrayList list = new ArrayList (4);
2790 | variable_initializer_list COMMA variable_initializer
2792 ArrayList list = (ArrayList) $1;
2799 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2801 $$ = new TypeOfVoid (lexer.Location);
2803 | TYPEOF OPEN_PARENS type CLOSE_PARENS
2805 $$ = new TypeOf ((Expression) $3, lexer.Location);
2810 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2811 $$ = new SizeOf ((Expression) $3, lexer.Location);
2816 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2818 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2822 unchecked_expression
2823 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2825 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2829 pointer_member_access
2830 : primary_expression OP_PTR IDENTIFIER
2834 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2835 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2839 anonymous_method_expression
2840 : DELEGATE opt_anonymous_method_signature {
2841 oob_stack.Push (current_local_parameters);
2842 current_local_parameters = (Parameters)$2;
2844 // Force the next block to be created as a ToplevelBlock
2845 oob_stack.Push (current_block);
2846 oob_stack.Push (top_current_block);
2847 oob_stack.Push (lexer.Location);
2848 current_block = null;
2850 Location loc = (Location) oob_stack.Pop ();
2851 top_current_block = (Block) oob_stack.Pop ();
2852 current_block = (Block) oob_stack.Pop ();
2853 if (RootContext.Version == LanguageVersion.ISO_1){
2854 Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
2857 ToplevelBlock anon_block = (ToplevelBlock) $4;
2859 anon_block.Parent = current_block;
2860 $$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block,
2863 current_local_parameters = (Parameters) oob_stack.Pop ();
2867 opt_anonymous_method_signature
2868 : /* empty */ { $$ = null; }
2869 | anonymous_method_signature
2872 anonymous_method_signature
2873 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2876 $$ = Parameters.EmptyReadOnlyParameters;
2878 ArrayList par_list = (ArrayList) $2;
2879 Parameter [] pars = new Parameter [par_list.Count];
2880 par_list.CopyTo (pars);
2881 $$ = new Parameters (pars, null, lexer.Location);
2886 opt_anonymous_method_parameter_list
2887 : /* empty */ { $$ = null; }
2888 | anonymous_method_parameter_list { $$ = $1; }
2891 anonymous_method_parameter_list
2892 : anonymous_method_parameter
2894 ArrayList a = new ArrayList (4);
2898 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2900 ArrayList a = (ArrayList) $1;
2906 anonymous_method_parameter
2907 : opt_parameter_modifier type IDENTIFIER {
2908 $$ = new Parameter ((Expression) $2, (string) $3, (Parameter.Modifier) $1, null);
2910 | PARAMS type IDENTIFIER {
2911 Report.Error (-221, lexer.Location, "params modifier not allowed in anonymous method declaration");
2917 : primary_expression
2918 | BANG prefixed_unary_expression
2920 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2922 | TILDE prefixed_unary_expression
2924 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2930 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2932 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2934 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2936 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2942 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2944 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2949 // The idea to split this out is from Rhys' grammar
2950 // to solve the problem with casts.
2952 prefixed_unary_expression
2954 | PLUS prefixed_unary_expression
2956 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2958 | MINUS prefixed_unary_expression
2960 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2962 | OP_INC prefixed_unary_expression
2964 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2965 (Expression) $2, lexer.Location);
2967 | OP_DEC prefixed_unary_expression
2969 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2970 (Expression) $2, lexer.Location);
2972 | STAR prefixed_unary_expression
2974 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2976 | BITWISE_AND prefixed_unary_expression
2978 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2982 pre_increment_expression
2983 : OP_INC prefixed_unary_expression
2985 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2986 (Expression) $2, lexer.Location);
2990 pre_decrement_expression
2991 : OP_DEC prefixed_unary_expression
2993 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2994 (Expression) $2, lexer.Location);
2998 multiplicative_expression
2999 : prefixed_unary_expression
3000 | multiplicative_expression STAR prefixed_unary_expression
3002 $$ = new Binary (Binary.Operator.Multiply,
3003 (Expression) $1, (Expression) $3, lexer.Location);
3005 | multiplicative_expression DIV prefixed_unary_expression
3007 $$ = new Binary (Binary.Operator.Division,
3008 (Expression) $1, (Expression) $3, lexer.Location);
3010 | multiplicative_expression PERCENT prefixed_unary_expression
3012 $$ = new Binary (Binary.Operator.Modulus,
3013 (Expression) $1, (Expression) $3, lexer.Location);
3018 : multiplicative_expression
3019 | additive_expression PLUS multiplicative_expression
3021 $$ = new Binary (Binary.Operator.Addition,
3022 (Expression) $1, (Expression) $3, lexer.Location);
3024 | additive_expression MINUS multiplicative_expression
3026 $$ = new Binary (Binary.Operator.Subtraction,
3027 (Expression) $1, (Expression) $3, lexer.Location);
3032 : additive_expression
3033 | shift_expression OP_SHIFT_LEFT additive_expression
3035 $$ = new Binary (Binary.Operator.LeftShift,
3036 (Expression) $1, (Expression) $3, lexer.Location);
3038 | shift_expression OP_SHIFT_RIGHT additive_expression
3040 $$ = new Binary (Binary.Operator.RightShift,
3041 (Expression) $1, (Expression) $3, lexer.Location);
3045 relational_expression
3047 | relational_expression OP_LT shift_expression
3049 $$ = new Binary (Binary.Operator.LessThan,
3050 (Expression) $1, (Expression) $3, lexer.Location);
3052 | relational_expression OP_GT shift_expression
3054 $$ = new Binary (Binary.Operator.GreaterThan,
3055 (Expression) $1, (Expression) $3, lexer.Location);
3057 | relational_expression OP_LE shift_expression
3059 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3060 (Expression) $1, (Expression) $3, lexer.Location);
3062 | relational_expression OP_GE shift_expression
3064 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3065 (Expression) $1, (Expression) $3, lexer.Location);
3067 | relational_expression IS type
3069 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
3071 | relational_expression AS type
3073 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
3078 : relational_expression
3079 | equality_expression OP_EQ relational_expression
3081 $$ = new Binary (Binary.Operator.Equality,
3082 (Expression) $1, (Expression) $3, lexer.Location);
3084 | equality_expression OP_NE relational_expression
3086 $$ = new Binary (Binary.Operator.Inequality,
3087 (Expression) $1, (Expression) $3, lexer.Location);
3092 : equality_expression
3093 | and_expression BITWISE_AND equality_expression
3095 $$ = new Binary (Binary.Operator.BitwiseAnd,
3096 (Expression) $1, (Expression) $3, lexer.Location);
3100 exclusive_or_expression
3102 | exclusive_or_expression CARRET and_expression
3104 $$ = new Binary (Binary.Operator.ExclusiveOr,
3105 (Expression) $1, (Expression) $3, lexer.Location);
3109 inclusive_or_expression
3110 : exclusive_or_expression
3111 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3113 $$ = new Binary (Binary.Operator.BitwiseOr,
3114 (Expression) $1, (Expression) $3, lexer.Location);
3118 conditional_and_expression
3119 : inclusive_or_expression
3120 | conditional_and_expression OP_AND inclusive_or_expression
3122 $$ = new Binary (Binary.Operator.LogicalAnd,
3123 (Expression) $1, (Expression) $3, lexer.Location);
3127 conditional_or_expression
3128 : conditional_and_expression
3129 | conditional_or_expression OP_OR conditional_and_expression
3131 $$ = new Binary (Binary.Operator.LogicalOr,
3132 (Expression) $1, (Expression) $3, lexer.Location);
3136 conditional_expression
3137 : conditional_or_expression
3138 | conditional_or_expression INTERR expression COLON expression
3140 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
3144 assignment_expression
3145 : prefixed_unary_expression ASSIGN expression
3147 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
3149 | prefixed_unary_expression OP_MULT_ASSIGN expression
3151 Location l = lexer.Location;
3153 $$ = new CompoundAssign (
3154 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
3156 | prefixed_unary_expression OP_DIV_ASSIGN expression
3158 Location l = lexer.Location;
3160 $$ = new CompoundAssign (
3161 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
3163 | prefixed_unary_expression OP_MOD_ASSIGN expression
3165 Location l = lexer.Location;
3167 $$ = new CompoundAssign (
3168 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
3170 | prefixed_unary_expression OP_ADD_ASSIGN expression
3172 Location l = lexer.Location;
3174 $$ = new CompoundAssign (
3175 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
3177 | prefixed_unary_expression OP_SUB_ASSIGN expression
3179 Location l = lexer.Location;
3181 $$ = new CompoundAssign (
3182 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
3184 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3186 Location l = lexer.Location;
3188 $$ = new CompoundAssign (
3189 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
3191 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3193 Location l = lexer.Location;
3195 $$ = new CompoundAssign (
3196 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
3198 | prefixed_unary_expression OP_AND_ASSIGN expression
3200 Location l = lexer.Location;
3202 $$ = new CompoundAssign (
3203 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
3205 | prefixed_unary_expression OP_OR_ASSIGN expression
3207 Location l = lexer.Location;
3209 $$ = new CompoundAssign (
3210 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
3212 | prefixed_unary_expression OP_XOR_ASSIGN expression
3214 Location l = lexer.Location;
3216 $$ = new CompoundAssign (
3217 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
3222 : conditional_expression
3223 | assignment_expression
3243 MemberName name = MakeName ((MemberName) $5);
3244 bool partial = (bool) $3;
3245 int mod_flags = (int) $2;
3248 ClassPart part = PartialContainer.CreatePart (
3249 current_namespace, current_container, name, mod_flags,
3250 (Attributes) $1, Kind.Class, lexer.Location);
3252 current_container = part.PartialContainer;
3253 current_class = part;
3255 if ((mod_flags & Modifiers.STATIC) != 0) {
3256 current_class = new StaticClass (
3257 current_namespace, current_container, name,
3258 mod_flags, (Attributes) $1, lexer.Location);
3260 current_class = new Class (
3261 current_namespace, current_container, name,
3262 mod_flags, (Attributes) $1, lexer.Location);
3265 current_container = current_class;
3266 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
3272 if (current_class.Name == "System.Object") {
3273 Report.Error (537, current_class.Location,
3274 "The class System.Object cannot have a base " +
3275 "class or implement an interface.");
3277 current_class.Bases = (ArrayList) $7;
3280 if (RootContext.Documentation != null) {
3281 current_class.DocComment = Lexer.consume_doc_comment ();
3282 Lexer.doc_state = XmlCommentState.Allowed;
3285 current_class.Register ();
3289 if (RootContext.Documentation != null)
3290 Lexer.doc_state = XmlCommentState.Allowed;
3296 current_container = current_container.Parent;
3297 current_class = current_container;
3303 { $$ = (bool) false; }
3305 { $$ = (bool) true; }
3309 : /* empty */ { $$ = (int) 0; }
3315 | modifiers modifier
3320 if ((m1 & m2) != 0) {
3321 Location l = lexer.Location;
3322 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3324 $$ = (int) (m1 | m2);
3329 : NEW { $$ = Modifiers.NEW; }
3330 | PUBLIC { $$ = Modifiers.PUBLIC; }
3331 | PROTECTED { $$ = Modifiers.PROTECTED; }
3332 | INTERNAL { $$ = Modifiers.INTERNAL; }
3333 | PRIVATE { $$ = Modifiers.PRIVATE; }
3334 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3335 | SEALED { $$ = Modifiers.SEALED; }
3336 | STATIC { $$ = Modifiers.STATIC; }
3337 | READONLY { $$ = Modifiers.READONLY; }
3338 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3339 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3340 | EXTERN { $$ = Modifiers.EXTERN; }
3341 | VOLATILE { $$ = Modifiers.VOLATILE; }
3342 | UNSAFE { $$ = Modifiers.UNSAFE; }
3346 : /* empty */ { $$ = null; }
3347 | class_base { $$ = $1; }
3351 : COLON type_list { $$ = $2; }
3359 // A block is "contained" on the following places:
3361 // property_declaration as part of the accessor body (get/set)
3362 // operator_declaration
3363 // constructor_declaration
3364 // destructor_declaration
3365 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3370 if (current_block == null){
3371 current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, lexer.Location);
3372 top_current_block = current_block;
3374 current_block = new Block (current_block, current_local_parameters,
3375 lexer.Location, Location.Null);
3378 opt_statement_list CLOSE_BRACE
3380 while (current_block.Implicit)
3381 current_block = current_block.Parent;
3383 current_block.SetEndLocation (lexer.Location);
3384 current_block = current_block.Parent;
3385 if (current_block == null)
3386 top_current_block = null;
3397 | statement_list statement
3401 : declaration_statement
3403 if ($1 != null && (Block) $1 != current_block){
3404 current_block.AddStatement ((Statement) $1);
3405 current_block = (Block) $1;
3408 | valid_declaration_statement
3410 current_block.AddStatement ((Statement) $1);
3415 valid_declaration_statement
3418 | expression_statement
3419 | selection_statement
3420 | iteration_statement
3424 | unchecked_statement
3432 : valid_declaration_statement
3433 | declaration_statement
3435 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
3440 Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
3448 $$ = EmptyStatement.Value;
3455 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3457 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3458 current_block.AddStatement (labeled);
3463 declaration_statement
3464 : local_variable_declaration SEMICOLON
3467 DictionaryEntry de = (DictionaryEntry) $1;
3469 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3473 | local_constant_declaration SEMICOLON
3476 DictionaryEntry de = (DictionaryEntry) $1;
3478 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3484 * The following is from Rhys' grammar:
3485 * > Types in local variable declarations must be recognized as
3486 * > expressions to prevent reduce/reduce errors in the grammar.
3487 * > The expressions are converted into types during semantic analysis.
3490 : primary_expression opt_rank_specifier
3492 // FIXME: Do something smart here regarding the composition of the type.
3494 // Ok, the above "primary_expression" is there to get rid of
3495 // both reduce/reduce and shift/reduces in the grammar, it should
3496 // really just be "type_name". If you use type_name, a reduce/reduce
3497 // creeps up. If you use namespace_or_type_name (which is all we need
3498 // really) two shift/reduces appear.
3501 // So the super-trick is that primary_expression
3502 // can only be either a SimpleName or a MemberAccess.
3503 // The MemberAccess case arises when you have a fully qualified type-name like :
3505 // SimpleName is when you have
3508 Expression expr = (Expression) $1;
3509 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast)) {
3510 Error_ExpectingTypeName (lexer.Location, expr);
3514 // So we extract the string corresponding to the SimpleName
3518 if ((string) $2 == "")
3521 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3524 | builtin_types opt_rank_specifier
3526 if ((string) $2 == "")
3529 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3533 local_variable_pointer_type
3534 : primary_expression STAR
3536 Expression expr = (Expression) $1;
3537 Location l = lexer.Location;
3539 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast)) {
3540 Error_ExpectingTypeName (l, expr);
3544 $$ = new ComposedCast ((Expression) $1, "*", l);
3546 | builtin_types STAR
3548 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3552 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3554 | local_variable_pointer_type STAR
3556 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3560 local_variable_declaration
3561 : local_variable_type variable_declarators
3564 $$ = new DictionaryEntry ($1, $2);
3568 | local_variable_pointer_type opt_rank_specifier variable_declarators
3573 if ((string) $2 == "")
3574 t = (Expression) $1;
3576 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3577 $$ = new DictionaryEntry (t, $3);
3583 local_constant_declaration
3584 : CONST local_variable_type constant_declarators
3587 $$ = new DictionaryEntry ($2, $3);
3593 expression_statement
3594 : statement_expression SEMICOLON
3601 // We have to do the wrapping here and not in the case above,
3602 // because statement_expression is used for example in for_statement
3604 statement_expression
3605 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3606 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3607 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3608 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3609 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3610 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3611 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3613 Report.Error (1002, lexer.Location, "Expecting `;'");
3618 object_creation_expression
3619 : object_or_delegate_creation_expression
3620 { note ("complain if this is a delegate maybe?"); }
3629 : if_statement_open if_statement_rest
3638 oob_stack.Push (lexer.Location);
3643 : boolean_expression CLOSE_PARENS
3646 Location l = (Location) oob_stack.Pop ();
3648 $$ = new If ((Expression) $1, (Statement) $3, l);
3650 if (RootContext.WarningLevel >= 3){
3651 if ($3 == EmptyStatement.Value)
3652 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3656 | boolean_expression CLOSE_PARENS
3657 embedded_statement ELSE embedded_statement
3659 Location l = (Location) oob_stack.Pop ();
3661 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3666 : SWITCH OPEN_PARENS
3668 oob_stack.Push (lexer.Location);
3669 switch_stack.Push (current_block);
3671 expression CLOSE_PARENS
3674 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3675 current_block = (Block) switch_stack.Pop ();
3691 Report.Error (1522, lexer.Location, "Empty switch block");
3699 ArrayList sections = new ArrayList (4);
3704 | switch_sections switch_section
3706 ArrayList sections = (ArrayList) $1;
3716 current_block = current_block.CreateSwitchBlock (lexer.Location);
3720 Block topmost = current_block;
3722 while (topmost.Implicit)
3723 topmost = topmost.Parent;
3724 $$ = new SwitchSection ((ArrayList) $1, topmost);
3731 ArrayList labels = new ArrayList (4);
3736 | switch_labels switch_label
3738 ArrayList labels = (ArrayList) ($1);
3746 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3747 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3750 1523, lexer.Location,
3751 "The keyword case or default must precede code in switch block");
3765 oob_stack.Push (lexer.Location);
3767 boolean_expression CLOSE_PARENS embedded_statement
3769 Location l = (Location) oob_stack.Pop ();
3770 $$ = new While ((Expression) $4, (Statement) $6, l);
3772 if (RootContext.WarningLevel >= 3){
3773 if ($6 == EmptyStatement.Value)
3774 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3780 : DO embedded_statement
3782 oob_stack.Push (lexer.Location);
3784 boolean_expression CLOSE_PARENS SEMICOLON
3786 Location l = (Location) oob_stack.Pop ();
3788 $$ = new Do ((Statement) $2, (Expression) $6, l);
3794 opt_for_initializer SEMICOLON
3796 Block assign_block = new Block (current_block);
3797 current_block = assign_block;
3799 if ($3 is DictionaryEntry){
3800 DictionaryEntry de = (DictionaryEntry) $3;
3802 Expression type = (Expression) de.Key;
3803 ArrayList var_declarators = (ArrayList) de.Value;
3805 foreach (VariableDeclaration decl in var_declarators){
3809 vi = current_block.AddVariable (
3810 type, decl.identifier, current_local_parameters, decl.Location);
3814 Location l = lexer.Location;
3816 if (decl.expression_or_array_initializer is Expression){
3817 expr = (Expression) decl.expression_or_array_initializer;
3818 } else if (decl.expression_or_array_initializer == null) {
3821 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3822 expr = new ArrayCreation (type, "", init, decl.Location);
3825 LocalVariableReference var;
3826 var = new LocalVariableReference (assign_block, decl.identifier, l);
3829 Assign a = new Assign (var, expr, decl.Location);
3831 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3837 oob_stack.Push (lexer.Location);
3839 opt_for_condition SEMICOLON
3840 opt_for_iterator CLOSE_PARENS
3843 Location l = (Location) oob_stack.Pop ();
3845 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3847 if (RootContext.WarningLevel >= 3){
3848 if ($10 == EmptyStatement.Value)
3849 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3852 current_block.AddStatement (f);
3853 while (current_block.Implicit)
3854 current_block = current_block.Parent;
3856 current_block = current_block.Parent;
3861 : /* empty */ { $$ = EmptyStatement.Value; }
3866 : local_variable_declaration
3867 | statement_expression_list
3871 : /* empty */ { $$ = null; }
3872 | boolean_expression
3876 : /* empty */ { $$ = EmptyStatement.Value; }
3881 : statement_expression_list
3884 statement_expression_list
3885 : statement_expression
3887 // CHANGE: was `null'
3888 Block b = new Block (current_block, Block.Flags.Implicit);
3890 b.AddStatement ((Statement) $1);
3893 | statement_expression_list COMMA statement_expression
3895 Block b = (Block) $1;
3897 b.AddStatement ((Statement) $3);
3903 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
3905 Report.Error (230, lexer.Location, "Type and identifier are both required in a foreach statement");
3908 | FOREACH OPEN_PARENS type IDENTIFIER IN
3910 oob_stack.Push (lexer.Location);
3912 expression CLOSE_PARENS
3914 oob_stack.Push (current_block);
3916 Block foreach_block = new Block (current_block);
3917 LocalVariableReference v = null;
3918 Location l = lexer.Location;
3921 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3925 // Get a writable reference to this read-only variable.
3926 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3928 current_block = foreach_block;
3931 oob_stack.Push (current_block);
3935 Block foreach_block = (Block) oob_stack.Pop ();
3936 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3937 Block prev_block = (Block) oob_stack.Pop ();
3938 Location l = (Location) oob_stack.Pop ();
3940 current_block = prev_block;
3943 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3944 foreach_block.AddStatement (f);
3953 | continue_statement
3963 $$ = new Break (lexer.Location);
3968 : CONTINUE SEMICOLON
3970 $$ = new Continue (lexer.Location);
3975 : GOTO IDENTIFIER SEMICOLON
3977 $$ = new Goto (current_block, (string) $2, lexer.Location);
3979 | GOTO CASE constant_expression SEMICOLON
3981 $$ = new GotoCase ((Expression) $3, lexer.Location);
3983 | GOTO DEFAULT SEMICOLON
3985 $$ = new GotoDefault (lexer.Location);
3990 : RETURN opt_expression SEMICOLON
3992 $$ = new Return ((Expression) $2, lexer.Location);
3997 : THROW opt_expression SEMICOLON
3999 $$ = new Throw ((Expression) $2, lexer.Location);
4004 : IDENTIFIER RETURN expression SEMICOLON
4006 string s = (string) $1;
4008 Report.Error (1003, lexer.Location, "; expected");
4011 if (RootContext.Version == LanguageVersion.ISO_1){
4012 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
4015 if (iterator_container == null){
4016 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
4019 iterator_container.SetYields ();
4020 $$ = new Yield ((Expression) $3, lexer.Location);
4023 | IDENTIFIER BREAK SEMICOLON
4025 string s = (string) $1;
4027 Report.Error (1003, lexer.Location, "; expected");
4030 if (RootContext.Version == LanguageVersion.ISO_1){
4031 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
4034 if (iterator_container == null){
4035 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
4038 iterator_container.SetYields ();
4039 $$ = new YieldBreak (lexer.Location);
4050 : TRY block catch_clauses
4054 ArrayList c = (ArrayList)$3;
4055 for (int i = 0; i < c.Count; ++i) {
4056 Catch cc = (Catch) c [i];
4058 if (i != c.Count - 1)
4059 Report.Error (1017, cc.loc, "Empty catch block must be the last in a series of catch blocks");
4066 // Now s contains the list of specific catch clauses
4067 // and g contains the general one.
4069 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4071 | TRY block opt_catch_clauses FINALLY block
4074 ArrayList s = new ArrayList (4);
4075 ArrayList catch_list = (ArrayList) $3;
4077 if (catch_list != null){
4078 foreach (Catch cc in catch_list) {
4086 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4090 Report.Error (1524, lexer.Location, "Expected catch or finally");
4095 : /* empty */ { $$ = null; }
4102 ArrayList l = new ArrayList (4);
4107 | catch_clauses catch_clause
4109 ArrayList l = (ArrayList) $1;
4117 : /* empty */ { $$ = null; }
4122 : CATCH opt_catch_args
4124 Expression type = null;
4128 DictionaryEntry cc = (DictionaryEntry) $2;
4129 type = (Expression) cc.Key;
4130 id = (string) cc.Value;
4133 ArrayList one = new ArrayList (4);
4134 Location loc = lexer.Location;
4136 one.Add (new VariableDeclaration (id, null, loc));
4139 current_block = new Block (current_block);
4140 Block b = declare_local_variables (type, one, loc);
4145 Expression type = null;
4149 DictionaryEntry cc = (DictionaryEntry) $2;
4150 type = (Expression) cc.Key;
4151 id = (string) cc.Value;
4155 // FIXME: I can change this for an assignment.
4157 while (current_block != (Block) $1)
4158 current_block = current_block.Parent;
4163 $$ = new Catch (type, id , (Block) $4, ((Block) $4).loc);
4168 : /* empty */ { $$ = null; }
4173 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4175 $$ = new DictionaryEntry ($2, $3);
4182 $$ = new Checked ((Block) $2);
4189 $$ = new Unchecked ((Block) $2);
4196 if (!RootContext.Unsafe){
4197 Report.Error (227, lexer.Location,
4198 "Unsafe code can only be used if --unsafe is used");
4201 $$ = new Unsafe ((Block) $3);
4207 type fixed_pointer_declarators
4210 ArrayList list = (ArrayList) $4;
4211 Expression type = (Expression) $3;
4212 Location l = lexer.Location;
4213 int top = list.Count;
4215 Block assign_block = new Block (current_block);
4216 current_block = assign_block;
4218 for (int i = 0; i < top; i++){
4219 Pair p = (Pair) list [i];
4222 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4236 Location l = (Location) oob_stack.Pop ();
4238 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4240 if (RootContext.WarningLevel >= 3){
4241 if ($7 == EmptyStatement.Value)
4242 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
4245 current_block.AddStatement (f);
4246 while (current_block.Implicit)
4247 current_block = current_block.Parent;
4249 current_block = current_block.Parent;
4253 fixed_pointer_declarators
4254 : fixed_pointer_declarator {
4255 ArrayList declarators = new ArrayList (4);
4257 declarators.Add ($1);
4260 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4262 ArrayList declarators = (ArrayList) $1;
4264 declarators.Add ($3);
4269 fixed_pointer_declarator
4270 : IDENTIFIER ASSIGN expression
4272 $$ = new Pair ($1, $3);
4276 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
4282 : LOCK OPEN_PARENS expression CLOSE_PARENS
4288 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4293 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4295 Block assign_block = new Block (current_block);
4296 current_block = assign_block;
4298 oob_stack.Push (lexer.Location);
4300 if ($3 is DictionaryEntry){
4301 DictionaryEntry de = (DictionaryEntry) $3;
4302 Location l = lexer.Location;
4304 Expression type = (Expression) de.Key;
4305 ArrayList var_declarators = (ArrayList) de.Value;
4307 ArrayList vars = new ArrayList (4);
4309 foreach (VariableDeclaration decl in var_declarators){
4311 LocalInfo vi = current_block.AddVariable (
4312 type, decl.identifier,
4313 current_local_parameters, decl.Location);
4319 if (decl.expression_or_array_initializer is Expression){
4320 expr = (Expression) decl.expression_or_array_initializer;
4322 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4324 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4327 expr = new ArrayCreation (type, "", init, decl.Location);
4330 LocalVariableReference var;
4332 // Get a writable reference to this read-only variable.
4333 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4335 // This is so that it is not a warning on using variables
4338 vars.Add (new DictionaryEntry (var, expr));
4340 // Assign a = new Assign (var, expr, decl.Location);
4341 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4343 $3 = new DictionaryEntry (type, vars);
4348 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4349 current_block.AddStatement (u);
4350 while (current_block.Implicit)
4351 current_block = current_block.Parent;
4353 current_block = current_block.Parent;
4357 resource_acquisition
4358 : local_variable_declaration
4365 // A class used to pass around variable declarations and constants
4367 public class VariableDeclaration {
4368 public string identifier;
4369 public object expression_or_array_initializer;
4370 public Location Location;
4371 public Attributes OptAttributes;
4372 public string DocComment;
4374 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4376 this.identifier = id;
4377 this.expression_or_array_initializer = eoai;
4379 this.OptAttributes = opt_attrs;
4382 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4388 /// Used to pass around interface property information
4390 public class InterfaceAccessorInfo {
4392 public readonly Accessor Get, Set;
4394 public InterfaceAccessorInfo (bool has_get, bool has_set,
4395 Attributes get_attrs, Attributes set_attrs, int get_mod, int set_mod, Location get_loc, Location set_loc)
4398 Report.Error (275, get_loc, "Accessibility modifiers can not be used on accessors in interfaces");
4400 Report.Error (275, set_loc, "Accessibility modifiers can not be used on accessors in interfaces");
4403 Get = new Accessor (null, 0, get_attrs, get_loc);
4405 Set = new Accessor (null, 0, set_attrs, set_loc);
4412 // A class used to hold info about an indexer declarator
4414 public class IndexerDeclaration {
4415 public Expression type;
4416 public MemberName interface_type;
4417 public Parameters param_list;
4419 public IndexerDeclaration (Expression type, MemberName interface_type,
4420 Parameters param_list)
4423 this.interface_type = interface_type;
4424 this.param_list = param_list;
4429 // We use this when we do not have an object in advance that is an IIteratorContainer
4431 public class SimpleIteratorContainer : IIteratorContainer {
4434 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4439 public static SimpleIteratorContainer GetSimple () {
4440 Simple.Yields = false;
4444 public void SetYields () { Yields = true; }
4448 // A class used to hold info about an operator declarator
4450 public class OperatorDeclaration {
4451 public Operator.OpType optype;
4452 public Expression ret_type, arg1type, arg2type;
4453 public string arg1name, arg2name;
4454 public Location location;
4456 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4457 Expression arg1type, string arg1name,
4458 Expression arg2type, string arg2name, Location location)
4461 this.ret_type = ret_type;
4462 this.arg1type = arg1type;
4463 this.arg1name = arg1name;
4464 this.arg2type = arg2type;
4465 this.arg2name = arg2name;
4466 this.location = location;
4471 void Error_ExpectingTypeName (Location l, Expression expr)
4473 if (expr is Invocation){
4474 Report.Error (1002, l, "; expected");
4476 Report.Error (-1, l, "Invalid Type definition");
4481 // Given the @class_name name, it creates a fully qualified name
4482 // based on the containing declaration space
4485 MakeName (MemberName class_name)
4487 string ns = current_namespace.FullName;
4489 if (current_container.Name == ""){
4491 return new MemberName (new MemberName (ns), class_name);
4495 return new MemberName (current_container.MemberName, class_name);
4499 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4501 Block implicit_block;
4502 ArrayList inits = null;
4505 // We use the `Used' property to check whether statements
4506 // have been added to the current block. If so, we need
4507 // to create another block to contain the new declaration
4508 // otherwise, as an optimization, we use the same block to
4509 // add the declaration.
4511 // FIXME: A further optimization is to check if the statements
4512 // that were added were added as part of the initialization
4513 // below. In which case, no other statements have been executed
4514 // and we might be able to reduce the number of blocks for
4515 // situations like this:
4517 // int j = 1; int k = j + 1;
4519 if (current_block.Used)
4520 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4522 implicit_block = current_block;
4524 foreach (VariableDeclaration decl in variable_declarators){
4526 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4527 if (decl.expression_or_array_initializer != null){
4529 inits = new ArrayList (4);
4536 return implicit_block;
4538 foreach (VariableDeclaration decl in inits){
4542 if (decl.expression_or_array_initializer is Expression){
4543 expr = (Expression) decl.expression_or_array_initializer;
4546 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4548 expr = new ArrayCreation (type, "", init, decl.Location);
4551 LocalVariableReference var;
4552 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4554 assign = new Assign (var, expr, decl.Location);
4556 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4559 return implicit_block;
4562 Block declare_local_constants (Expression type, ArrayList declarators)
4564 Block implicit_block;
4566 if (current_block.Used)
4567 implicit_block = new Block (current_block, Block.Flags.Implicit);
4569 implicit_block = current_block;
4571 foreach (VariableDeclaration decl in declarators){
4572 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4573 current_local_parameters, decl.Location);
4576 return implicit_block;
4579 void CheckAttributeTarget (string a)
4583 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4587 Location l = lexer.Location;
4588 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4594 void CheckUnaryOperator (Operator.OpType op)
4598 case Operator.OpType.LogicalNot:
4599 case Operator.OpType.OnesComplement:
4600 case Operator.OpType.Increment:
4601 case Operator.OpType.Decrement:
4602 case Operator.OpType.True:
4603 case Operator.OpType.False:
4604 case Operator.OpType.Addition:
4605 case Operator.OpType.Subtraction:
4610 Location l = lexer.Location;
4611 Report.Error (1019, l, "Overloadable unary operator expected");
4617 void CheckBinaryOperator (Operator.OpType op)
4621 case Operator.OpType.Addition:
4622 case Operator.OpType.Subtraction:
4623 case Operator.OpType.Multiply:
4624 case Operator.OpType.Division:
4625 case Operator.OpType.Modulus:
4626 case Operator.OpType.BitwiseAnd:
4627 case Operator.OpType.BitwiseOr:
4628 case Operator.OpType.ExclusiveOr:
4629 case Operator.OpType.LeftShift:
4630 case Operator.OpType.RightShift:
4631 case Operator.OpType.Equality:
4632 case Operator.OpType.Inequality:
4633 case Operator.OpType.GreaterThan:
4634 case Operator.OpType.LessThan:
4635 case Operator.OpType.GreaterThanOrEqual:
4636 case Operator.OpType.LessThanOrEqual:
4640 Location l = lexer.Location;
4641 Report.Error (1020, l, "Overloadable binary operator expected");
4647 void syntax_error (Location l, string msg)
4649 Report.Error (1003, l, "Syntax error, " + msg);
4652 void output (string s)
4654 Console.WriteLine (s);
4657 void note (string s)
4659 // Used to put annotations
4664 public Tokenizer Lexer {
4670 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4672 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4673 this.name = file.Name;
4675 current_container = RootContext.Tree.Types;
4676 current_container.NamespaceEntry = current_namespace;
4677 oob_stack = new Stack ();
4678 switch_stack = new Stack ();
4680 lexer = new Tokenizer (reader, file, defines);
4683 public void parse ()
4686 if (yacc_verbose_flag > 1)
4687 yyparse (lexer, new yydebug.yyDebugSimple ());
4690 Tokenizer tokenizer = lexer as Tokenizer;
4691 tokenizer.cleanup ();
4692 } catch (Exception e){
4694 // Removed for production use, use parser verbose to get the output.
4696 // Console.WriteLine (e);
4697 Report.Error (-25, lexer.Location, "Parsing error");
4698 if (yacc_verbose_flag > 0)
4699 Console.WriteLine (e);
4703 void CheckToken (int error, int yyToken, string msg)
4705 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4706 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4709 Report.Error (error, lexer.Location, msg);
4712 void CheckIdentifierToken (int yyToken)
4714 CheckToken (1041, yyToken, "Identifier expected");
4717 string ConsumeStoredComment ()
4719 string s = tmpComment;
4721 Lexer.doc_state = XmlCommentState.Allowed;