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 = tmpComment;
1616 Lexer.doc_state = XmlCommentState.Allowed;
1619 if (SimpleIteratorContainer.Simple.Yields)
1622 // Note again, checking is done in semantic analysis
1623 current_container.AddOperator (op);
1625 current_local_parameters = null;
1626 iterator_container = null;
1632 | SEMICOLON { $$ = null; }
1635 : type OPERATOR overloadable_operator
1636 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1638 Operator.OpType op = (Operator.OpType) $3;
1639 CheckUnaryOperator (op);
1641 if (op == Operator.OpType.Addition)
1642 op = Operator.OpType.UnaryPlus;
1644 if (op == Operator.OpType.Subtraction)
1645 op = Operator.OpType.UnaryNegation;
1647 Parameter [] pars = new Parameter [1];
1648 Expression type = (Expression) $5;
1650 pars [0] = new Parameter (type, (string) $6, Parameter.Modifier.NONE, null);
1652 current_local_parameters = new Parameters (pars, null, lexer.Location);
1654 if (RootContext.Documentation != null) {
1655 tmpComment = Lexer.consume_doc_comment ();
1656 Lexer.doc_state = XmlCommentState.NotAllowed;
1659 $$ = new OperatorDeclaration (op, (Expression) $1, type, (string) $6,
1660 null, null, lexer.Location);
1662 | type OPERATOR overloadable_operator
1664 type IDENTIFIER COMMA
1668 CheckBinaryOperator ((Operator.OpType) $3);
1670 Parameter [] pars = new Parameter [2];
1672 Expression typeL = (Expression) $5;
1673 Expression typeR = (Expression) $8;
1675 pars [0] = new Parameter (typeL, (string) $6, Parameter.Modifier.NONE, null);
1676 pars [1] = new Parameter (typeR, (string) $9, Parameter.Modifier.NONE, null);
1678 current_local_parameters = new Parameters (pars, null, lexer.Location);
1680 if (RootContext.Documentation != null) {
1681 tmpComment = Lexer.consume_doc_comment ();
1682 Lexer.doc_state = XmlCommentState.NotAllowed;
1685 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
1687 typeR, (string) $9, lexer.Location);
1689 | conversion_operator_declarator
1692 overloadable_operator
1694 : BANG { $$ = Operator.OpType.LogicalNot; }
1695 | TILDE { $$ = Operator.OpType.OnesComplement; }
1696 | OP_INC { $$ = Operator.OpType.Increment; }
1697 | OP_DEC { $$ = Operator.OpType.Decrement; }
1698 | TRUE { $$ = Operator.OpType.True; }
1699 | FALSE { $$ = Operator.OpType.False; }
1700 // Unary and binary:
1701 | PLUS { $$ = Operator.OpType.Addition; }
1702 | MINUS { $$ = Operator.OpType.Subtraction; }
1704 | STAR { $$ = Operator.OpType.Multiply; }
1705 | DIV { $$ = Operator.OpType.Division; }
1706 | PERCENT { $$ = Operator.OpType.Modulus; }
1707 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1708 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1709 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1710 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1711 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1712 | OP_EQ { $$ = Operator.OpType.Equality; }
1713 | OP_NE { $$ = Operator.OpType.Inequality; }
1714 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1715 | OP_LT { $$ = Operator.OpType.LessThan; }
1716 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1717 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1720 conversion_operator_declarator
1721 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1723 Parameter [] pars = new Parameter [1];
1725 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1727 current_local_parameters = new Parameters (pars, null, lexer.Location);
1729 if (RootContext.Documentation != null) {
1730 tmpComment = Lexer.consume_doc_comment ();
1731 Lexer.doc_state = XmlCommentState.NotAllowed;
1734 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1735 null, null, lexer.Location);
1737 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1739 Parameter [] pars = new Parameter [1];
1741 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1743 current_local_parameters = new Parameters (pars, null, lexer.Location);
1745 if (RootContext.Documentation != null) {
1746 tmpComment = Lexer.consume_doc_comment ();
1747 Lexer.doc_state = XmlCommentState.NotAllowed;
1750 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1751 null, null, lexer.Location);
1755 syntax_error (lexer.Location, "'operator' expected");
1759 syntax_error (lexer.Location, "'operator' expected");
1763 constructor_declaration
1766 constructor_declarator
1769 Constructor c = (Constructor) $3;
1770 c.Block = (ToplevelBlock) $4;
1771 c.OptAttributes = (Attributes) $1;
1772 c.ModFlags = (int) $2;
1774 if (RootContext.Documentation != null)
1775 c.DocComment = ConsumeStoredComment ();
1777 if (c.Name == current_container.Basename){
1778 if ((c.ModFlags & Modifiers.STATIC) != 0){
1779 if ((c.ModFlags & Modifiers.Accessibility) != 0){
1781 515, c.Location, String.Format (
1782 "`{0}.{1}': static constructor can not have access modifiers",
1783 c.Name, current_container.Name));
1786 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1788 if (c.Initializer != null){
1791 "Static constructors can not have an explicit this or base " +
1792 "constructor invocations");
1795 if (!c.Parameters.Empty){
1797 132, c.Location, "Static constructors should not have parameters");
1800 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1803 // We let another layer check the validity of the constructor.
1804 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
1807 current_container.AddConstructor (c);
1809 current_local_parameters = null;
1810 if (RootContext.Documentation != null)
1811 Lexer.doc_state = XmlCommentState.Allowed;
1815 constructor_declarator
1818 if (RootContext.Documentation != null) {
1819 tmpComment = Lexer.consume_doc_comment ();
1820 Lexer.doc_state = XmlCommentState.Allowed;
1823 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1825 oob_stack.Push (lexer.Location);
1827 current_local_parameters = (Parameters) $4;
1829 opt_constructor_initializer
1831 Location l = (Location) oob_stack.Pop ();
1832 $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $4,
1833 (ConstructorInitializer) $7, l);
1839 | SEMICOLON { $$ = null; }
1842 opt_constructor_initializer
1843 : /* empty */ { $$ = null; }
1844 | constructor_initializer
1847 constructor_initializer
1848 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1850 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1852 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1854 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1857 Report.Error (1018, lexer.Location, "Keyword this or base expected");
1863 : /* EMPTY */ { $$ = 0; }
1864 | UNSAFE { $$ = Modifiers.UNSAFE; }
1865 | EXTERN { $$ = Modifiers.EXTERN; }
1868 destructor_declaration
1869 : opt_attributes opt_finalizer TILDE
1871 if (RootContext.Documentation != null) {
1872 tmpComment = Lexer.consume_doc_comment ();
1873 Lexer.doc_state = XmlCommentState.NotAllowed;
1876 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1878 if ((string) $5 != current_container.Basename){
1879 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1880 } else if (!(current_container is Class)){
1881 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1883 Location l = lexer.Location;
1886 if (!RootContext.StdLib && current_container.Name == "System.Object")
1887 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
1889 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
1891 if ((m & Modifiers.UNSAFE) != 0){
1892 if (!RootContext.Unsafe){
1893 Report.Error (227, l,
1894 "Unsafe code requires the -unsafe command " +
1895 "line option to be specified");
1899 Method d = new Destructor (
1900 current_class, TypeManager.system_void_expr, m, "Finalize",
1901 new Parameters (null, null, l), (Attributes) $1, l);
1902 if (RootContext.Documentation != null)
1903 d.DocComment = ConsumeStoredComment ();
1905 d.Block = (ToplevelBlock) $8;
1906 current_container.AddMethod (d);
1914 EVENT type variable_declarators SEMICOLON
1916 foreach (VariableDeclaration var in (ArrayList) $5) {
1918 MemberName name = new MemberName (var.identifier);
1920 Event e = new EventField (
1921 current_class, (Expression) $4, (int) $2, false, name,
1922 var.expression_or_array_initializer, (Attributes) $1,
1925 current_container.AddEvent (e);
1927 if (RootContext.Documentation != null) {
1928 e.DocComment = Lexer.consume_doc_comment ();
1929 Lexer.doc_state = XmlCommentState.Allowed;
1935 EVENT type namespace_or_type_name
1938 implicit_value_parameter_type = (Expression) $4;
1939 lexer.EventParsing = true;
1940 oob_stack.Push (lexer.Location);
1942 event_accessor_declarations
1944 lexer.EventParsing = false;
1948 Location loc = (Location) oob_stack.Pop ();
1951 Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
1954 Pair pair = (Pair) $8;
1956 MemberName name = (MemberName) $5;
1958 Event e = new EventProperty (
1959 current_class, (Expression) $4, (int) $2, false, name, null,
1960 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
1962 if (RootContext.Documentation != null) {
1963 e.DocComment = Lexer.consume_doc_comment ();
1964 Lexer.doc_state = XmlCommentState.Allowed;
1967 current_container.AddEvent (e);
1968 implicit_value_parameter_type = null;
1971 | opt_attributes opt_modifiers EVENT type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
1972 MemberName mn = (MemberName) $5;
1974 if (mn.Left != null)
1975 Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
1977 Report.Error (71, lexer.Location, "Event declaration should use property syntax");
1979 if (RootContext.Documentation != null)
1980 Lexer.doc_state = XmlCommentState.Allowed;
1984 event_accessor_declarations
1985 : add_accessor_declaration remove_accessor_declaration
1987 $$ = new Pair ($1, $2);
1989 | remove_accessor_declaration add_accessor_declaration
1991 $$ = new Pair ($2, $1);
1993 | add_accessor_declaration { $$ = null; }
1994 | remove_accessor_declaration { $$ = null; }
1997 Report.Error (1055, lexer.Location, "An add or remove accessor expected");
2003 add_accessor_declaration
2004 : opt_attributes ADD
2006 Parameter [] args = new Parameter [1];
2007 Parameter implicit_value_parameter = new Parameter (
2008 implicit_value_parameter_type, "value",
2009 Parameter.Modifier.NONE, null);
2011 args [0] = implicit_value_parameter;
2013 current_local_parameters = new Parameters (args, null, lexer.Location);
2014 lexer.EventParsing = false;
2018 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
2019 lexer.EventParsing = true;
2021 | opt_attributes ADD error {
2022 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
2027 remove_accessor_declaration
2028 : opt_attributes REMOVE
2030 Parameter [] args = new Parameter [1];
2031 Parameter implicit_value_parameter = new Parameter (
2032 implicit_value_parameter_type, "value",
2033 Parameter.Modifier.NONE, null);
2035 args [0] = implicit_value_parameter;
2037 current_local_parameters = new Parameters (args, null, lexer.Location);
2038 lexer.EventParsing = false;
2042 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
2043 lexer.EventParsing = true;
2045 | opt_attributes REMOVE error {
2046 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
2052 : opt_attributes opt_modifiers indexer_declarator
2055 IndexerDeclaration decl = (IndexerDeclaration) $3;
2057 implicit_value_parameter_type = decl.type;
2059 lexer.PropertyParsing = true;
2060 parsing_indexer = true;
2062 indexer_parameters = decl.param_list;
2063 oob_stack.Push (lexer.Location);
2065 accessor_declarations
2067 lexer.PropertyParsing = false;
2068 parsing_indexer = false;
2072 // The signature is computed from the signature of the indexer. Look
2073 // at section 3.6 on the spec
2074 Location loc = (Location) oob_stack.Pop ();
2076 IndexerDeclaration decl = (IndexerDeclaration) $3;
2077 Pair pair = (Pair) $6;
2078 Accessor get_block = (Accessor) pair.First;
2079 Accessor set_block = (Accessor) pair.Second;
2082 if (decl.interface_type != null)
2083 name = new MemberName (decl.interface_type,
2084 TypeContainer.DefaultIndexerName);
2086 name = new MemberName (TypeContainer.DefaultIndexerName);
2088 indexer = new Indexer (current_class, decl.type, name,
2089 (int) $2, false, decl.param_list, (Attributes) $1,
2090 get_block, set_block, loc);
2091 if (RootContext.Documentation != null)
2092 indexer.DocComment = ConsumeStoredComment ();
2094 current_container.AddIndexer (indexer);
2096 current_local_parameters = null;
2097 implicit_value_parameter_type = null;
2098 indexer_parameters = null;
2103 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2105 Parameters pars = (Parameters) $4;
2106 if (pars.HasArglist) {
2107 // "__arglist is not valid in this context"
2108 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2109 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2110 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2112 if (RootContext.Documentation != null) {
2113 tmpComment = Lexer.consume_doc_comment ();
2114 Lexer.doc_state = XmlCommentState.Allowed;
2117 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
2119 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2121 Parameters pars = (Parameters) $6;
2123 if (pars.HasArglist) {
2124 // "__arglist is not valid in this context"
2125 Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2126 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2127 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2130 MemberName name = (MemberName) $2;
2131 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
2133 if (RootContext.Documentation != null) {
2134 tmpComment = Lexer.consume_doc_comment ();
2135 Lexer.doc_state = XmlCommentState.Allowed;
2145 if (RootContext.Documentation != null)
2146 enumTypeComment = Lexer.consume_doc_comment ();
2151 Location enum_location = lexer.Location;
2153 MemberName full_name = MakeName (new MemberName ((string) $4));
2154 Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
2155 full_name, (Attributes) $1, enum_location);
2157 if (RootContext.Documentation != null)
2158 e.DocComment = enumTypeComment;
2160 foreach (VariableDeclaration ev in (ArrayList) $7) {
2161 e.AddEnumMember (ev.identifier,
2162 (Expression) ev.expression_or_array_initializer,
2163 ev.Location, ev.OptAttributes,
2167 string name = full_name.GetName ();
2168 current_container.AddEnum (e);
2169 RootContext.Tree.RecordDecl (name, e);
2175 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2176 | COLON type { $$ = $2; }
2182 if (RootContext.Documentation != null)
2183 Lexer.doc_state = XmlCommentState.Allowed;
2185 opt_enum_member_declarations
2187 // here will be evaluated after CLOSE_BLACE is consumed.
2188 if (RootContext.Documentation != null)
2189 Lexer.doc_state = XmlCommentState.Allowed;
2197 opt_enum_member_declarations
2198 : /* empty */ { $$ = new ArrayList (4); }
2199 | enum_member_declarations opt_comma { $$ = $1; }
2202 enum_member_declarations
2203 : enum_member_declaration
2205 ArrayList l = new ArrayList (4);
2210 | enum_member_declarations COMMA enum_member_declaration
2212 ArrayList l = (ArrayList) $1;
2220 enum_member_declaration
2221 : opt_attributes IDENTIFIER
2223 VariableDeclaration vd = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
2225 if (RootContext.Documentation != null) {
2226 vd.DocComment = Lexer.consume_doc_comment ();
2227 Lexer.doc_state = XmlCommentState.Allowed;
2232 | opt_attributes IDENTIFIER
2234 $$ = lexer.Location;
2235 if (RootContext.Documentation != null) {
2236 tmpComment = Lexer.consume_doc_comment ();
2237 Lexer.doc_state = XmlCommentState.NotAllowed;
2242 VariableDeclaration vd = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
2244 if (RootContext.Documentation != null)
2245 vd.DocComment = ConsumeStoredComment ();
2251 delegate_declaration
2254 DELEGATE type member_name
2255 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2258 Location l = lexer.Location;
2259 MemberName name = MakeName ((MemberName) $5);
2260 Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
2261 (int) $2, name, (Parameters) $7, (Attributes) $1, l);
2263 if (RootContext.Documentation != null) {
2264 del.DocComment = Lexer.consume_doc_comment ();
2265 Lexer.doc_state = XmlCommentState.Allowed;
2268 current_container.AddDelegate (del);
2269 RootContext.Tree.RecordDecl (name.GetName (true), del);
2273 DELEGATE VOID member_name
2274 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2277 Location l = lexer.Location;
2278 MemberName name = MakeName ((MemberName) $5);
2279 Delegate del = new Delegate (
2280 current_namespace, current_container,
2281 TypeManager.system_void_expr, (int) $2, name,
2282 (Parameters) $7, (Attributes) $1, l);
2284 if (RootContext.Documentation != null) {
2285 del.DocComment = Lexer.consume_doc_comment ();
2286 Lexer.doc_state = XmlCommentState.Allowed;
2289 current_container.AddDelegate (del);
2290 RootContext.Tree.RecordDecl (name.GetName (true), del);
2294 namespace_or_type_name
2296 | namespace_or_type_name DOT IDENTIFIER {
2297 $$ = new MemberName ((MemberName) $1, (string) $3);
2303 $$ = new MemberName ((string) $1);
2308 * Before you think of adding a return_type, notice that we have been
2309 * using two rules in the places where it matters (one rule using type
2310 * and another identical one that uses VOID as the return type). This
2311 * gets rid of a shift/reduce couple
2314 : namespace_or_type_name
2316 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2328 // Note that here only unmanaged types are allowed but we
2329 // can't perform checks during this phase - we do it during
2330 // semantic analysis.
2332 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2336 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2342 | non_expression_type rank_specifier
2344 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2346 | non_expression_type STAR
2348 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2350 | expression rank_specifiers
2352 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2356 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2360 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2361 // through this different path
2363 | multiplicative_expression STAR
2365 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2372 ArrayList types = new ArrayList (4);
2377 | type_list COMMA type
2379 ArrayList types = (ArrayList) $1;
2387 * replaces all the productions for isolating the various
2388 * simple types, but we need this to reuse it easily in local_variable_type
2391 : OBJECT { $$ = TypeManager.system_object_expr; }
2392 | STRING { $$ = TypeManager.system_string_expr; }
2393 | BOOL { $$ = TypeManager.system_boolean_expr; }
2394 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2395 | FLOAT { $$ = TypeManager.system_single_expr; }
2396 | DOUBLE { $$ = TypeManager.system_double_expr; }
2401 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2402 | BYTE { $$ = TypeManager.system_byte_expr; }
2403 | SHORT { $$ = TypeManager.system_int16_expr; }
2404 | USHORT { $$ = TypeManager.system_uint16_expr; }
2405 | INT { $$ = TypeManager.system_int32_expr; }
2406 | UINT { $$ = TypeManager.system_uint32_expr; }
2407 | LONG { $$ = TypeManager.system_int64_expr; }
2408 | ULONG { $$ = TypeManager.system_uint64_expr; }
2409 | CHAR { $$ = TypeManager.system_char_expr; }
2410 | VOID { $$ = TypeManager.system_void_expr; }
2414 : type rank_specifiers
2416 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2421 // Expressions, section 7.5
2431 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2433 | parenthesized_expression
2435 | invocation_expression
2439 | post_increment_expression
2440 | post_decrement_expression
2444 | checked_expression
2445 | unchecked_expression
2446 | pointer_member_access
2447 | anonymous_method_expression
2454 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
2455 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
2456 | NULL { $$ = NullLiteral.Null; }
2460 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
2461 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
2462 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2467 object v = lexer.Value;
2473 $$ = IntLiteral.Zero;
2475 $$ = IntLiteral.One;
2477 $$ = new IntLiteral (i);
2478 } else if (v is uint)
2479 $$ = new UIntLiteral ((UInt32) v);
2481 $$ = new LongLiteral ((Int64) v);
2482 else if (v is ulong)
2483 $$ = new ULongLiteral ((UInt64) v);
2485 Console.WriteLine ("OOPS. Unexpected result from scanner");
2490 : TRUE { $$ = new BoolLiteral (true); }
2491 | FALSE { $$ = new BoolLiteral (false); }
2494 parenthesized_expression_0
2495 : OPEN_PARENS expression CLOSE_PARENS
2498 lexer.Deambiguate_CloseParens ();
2499 // After this, the next token returned is one of
2500 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2501 // or CLOSE_PARENS_MINUS.
2505 parenthesized_expression
2506 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2510 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2512 // If a parenthesized expression is followed by a minus, we need to wrap
2513 // the expression inside a ParenthesizedExpression for the CS0075 check
2514 // in Binary.DoResolve().
2515 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2520 : primary_expression DOT IDENTIFIER
2522 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2524 | predefined_type DOT IDENTIFIER
2526 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
2534 invocation_expression
2535 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2538 Location l = lexer.Location;
2539 Report.Error (1, l, "Parse error");
2541 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2543 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2545 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2547 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2549 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2554 : /* empty */ { $$ = null; }
2561 ArrayList list = new ArrayList (4);
2565 | argument_list COMMA argument
2567 ArrayList list = (ArrayList) $1;
2571 | argument_list error {
2572 CheckToken (1026, yyToken, ", or ) expected");
2579 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2581 | REF variable_reference
2583 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2585 | OUT variable_reference
2587 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2589 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
2591 ArrayList list = (ArrayList) $3;
2592 Argument[] args = new Argument [list.Count];
2593 list.CopyTo (args, 0);
2595 Expression expr = new Arglist (args, lexer.Location);
2596 $$ = new Argument (expr, Argument.AType.Expression);
2600 $$ = new Argument (new ArglistAccess (lexer.Location), Argument.AType.ArgList);
2605 : expression { note ("section 5.4"); $$ = $1; }
2609 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
2611 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2613 | primary_expression rank_specifiers
2615 // So the super-trick is that primary_expression
2616 // can only be either a SimpleName or a MemberAccess.
2617 // The MemberAccess case arises when you have a fully qualified type-name like :
2619 // SimpleName is when you have
2622 Expression expr = (Expression) $1;
2623 if (expr is ComposedCast){
2624 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2625 } else if (!(expr is SimpleName || expr is MemberAccess)){
2626 Error_ExpectingTypeName (lexer.Location, expr);
2627 $$ = TypeManager.system_object_expr;
2630 // So we extract the string corresponding to the SimpleName
2633 $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2641 ArrayList list = new ArrayList (4);
2645 | expression_list COMMA expression
2647 ArrayList list = (ArrayList) $1;
2656 $$ = new This (current_block, lexer.Location);
2661 : BASE DOT IDENTIFIER
2663 $$ = new BaseAccess ((string) $3, lexer.Location);
2665 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2667 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2670 Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
2675 post_increment_expression
2676 : primary_expression OP_INC
2678 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2679 (Expression) $1, lexer.Location);
2683 post_decrement_expression
2684 : primary_expression OP_DEC
2686 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2687 (Expression) $1, lexer.Location);
2692 : object_or_delegate_creation_expression
2693 | array_creation_expression
2696 object_or_delegate_creation_expression
2697 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2699 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2703 array_creation_expression
2704 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2706 opt_array_initializer
2708 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2710 | NEW type rank_specifiers array_initializer
2712 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2716 Report.Error (1031, lexer.Location, "Type expected");
2721 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2737 : rank_specifier opt_rank_specifier
2739 $$ = (string) $2 + (string) $1;
2744 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2746 $$ = "[" + (string) $2 + "]";
2766 | dim_separators COMMA
2768 $$ = (string) $1 + ",";
2772 opt_array_initializer
2784 : OPEN_BRACE CLOSE_BRACE
2786 ArrayList list = new ArrayList (4);
2789 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2791 $$ = (ArrayList) $2;
2795 variable_initializer_list
2796 : variable_initializer
2798 ArrayList list = new ArrayList (4);
2802 | variable_initializer_list COMMA variable_initializer
2804 ArrayList list = (ArrayList) $1;
2811 : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
2813 $$ = new TypeOfVoid (lexer.Location);
2815 | TYPEOF OPEN_PARENS type CLOSE_PARENS
2817 $$ = new TypeOf ((Expression) $3, lexer.Location);
2822 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2823 $$ = new SizeOf ((Expression) $3, lexer.Location);
2828 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2830 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2834 unchecked_expression
2835 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2837 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2841 pointer_member_access
2842 : primary_expression OP_PTR IDENTIFIER
2846 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2847 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2851 anonymous_method_expression
2852 : DELEGATE opt_anonymous_method_signature {
2853 oob_stack.Push (current_local_parameters);
2854 current_local_parameters = (Parameters)$2;
2856 // Force the next block to be created as a ToplevelBlock
2857 oob_stack.Push (current_block);
2858 oob_stack.Push (top_current_block);
2859 oob_stack.Push (lexer.Location);
2860 current_block = null;
2862 Location loc = (Location) oob_stack.Pop ();
2863 top_current_block = (Block) oob_stack.Pop ();
2864 current_block = (Block) oob_stack.Pop ();
2865 if (RootContext.Version == LanguageVersion.ISO_1){
2866 Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
2869 ToplevelBlock anon_block = (ToplevelBlock) $4;
2871 anon_block.Parent = current_block;
2872 $$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block,
2875 current_local_parameters = (Parameters) oob_stack.Pop ();
2879 opt_anonymous_method_signature
2880 : /* empty */ { $$ = null; }
2881 | anonymous_method_signature
2884 anonymous_method_signature
2885 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
2888 $$ = Parameters.EmptyReadOnlyParameters;
2890 ArrayList par_list = (ArrayList) $2;
2891 Parameter [] pars = new Parameter [par_list.Count];
2892 par_list.CopyTo (pars);
2893 $$ = new Parameters (pars, null, lexer.Location);
2898 opt_anonymous_method_parameter_list
2899 : /* empty */ { $$ = null; }
2900 | anonymous_method_parameter_list { $$ = $1; }
2903 anonymous_method_parameter_list
2904 : anonymous_method_parameter
2906 ArrayList a = new ArrayList (4);
2910 | anonymous_method_parameter_list COMMA anonymous_method_parameter
2912 ArrayList a = (ArrayList) $1;
2918 anonymous_method_parameter
2919 : opt_parameter_modifier type IDENTIFIER {
2920 $$ = new Parameter ((Expression) $2, (string) $3, (Parameter.Modifier) $1, null);
2922 | PARAMS type IDENTIFIER {
2923 Report.Error (-221, lexer.Location, "params modifier not allowed in anonymous method declaration");
2929 : primary_expression
2930 | BANG prefixed_unary_expression
2932 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2934 | TILDE prefixed_unary_expression
2936 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2942 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
2944 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2946 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
2948 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
2954 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2956 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2961 // The idea to split this out is from Rhys' grammar
2962 // to solve the problem with casts.
2964 prefixed_unary_expression
2966 | PLUS prefixed_unary_expression
2968 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2970 | MINUS prefixed_unary_expression
2972 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2974 | OP_INC prefixed_unary_expression
2976 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2977 (Expression) $2, lexer.Location);
2979 | OP_DEC prefixed_unary_expression
2981 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2982 (Expression) $2, lexer.Location);
2984 | STAR prefixed_unary_expression
2986 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2988 | BITWISE_AND prefixed_unary_expression
2990 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2994 pre_increment_expression
2995 : OP_INC prefixed_unary_expression
2997 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2998 (Expression) $2, lexer.Location);
3002 pre_decrement_expression
3003 : OP_DEC prefixed_unary_expression
3005 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3006 (Expression) $2, lexer.Location);
3010 multiplicative_expression
3011 : prefixed_unary_expression
3012 | multiplicative_expression STAR prefixed_unary_expression
3014 $$ = new Binary (Binary.Operator.Multiply,
3015 (Expression) $1, (Expression) $3, lexer.Location);
3017 | multiplicative_expression DIV prefixed_unary_expression
3019 $$ = new Binary (Binary.Operator.Division,
3020 (Expression) $1, (Expression) $3, lexer.Location);
3022 | multiplicative_expression PERCENT prefixed_unary_expression
3024 $$ = new Binary (Binary.Operator.Modulus,
3025 (Expression) $1, (Expression) $3, lexer.Location);
3030 : multiplicative_expression
3031 | additive_expression PLUS multiplicative_expression
3033 $$ = new Binary (Binary.Operator.Addition,
3034 (Expression) $1, (Expression) $3, lexer.Location);
3036 | additive_expression MINUS multiplicative_expression
3038 $$ = new Binary (Binary.Operator.Subtraction,
3039 (Expression) $1, (Expression) $3, lexer.Location);
3044 : additive_expression
3045 | shift_expression OP_SHIFT_LEFT additive_expression
3047 $$ = new Binary (Binary.Operator.LeftShift,
3048 (Expression) $1, (Expression) $3, lexer.Location);
3050 | shift_expression OP_SHIFT_RIGHT additive_expression
3052 $$ = new Binary (Binary.Operator.RightShift,
3053 (Expression) $1, (Expression) $3, lexer.Location);
3057 relational_expression
3059 | relational_expression OP_LT shift_expression
3061 $$ = new Binary (Binary.Operator.LessThan,
3062 (Expression) $1, (Expression) $3, lexer.Location);
3064 | relational_expression OP_GT shift_expression
3066 $$ = new Binary (Binary.Operator.GreaterThan,
3067 (Expression) $1, (Expression) $3, lexer.Location);
3069 | relational_expression OP_LE shift_expression
3071 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3072 (Expression) $1, (Expression) $3, lexer.Location);
3074 | relational_expression OP_GE shift_expression
3076 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3077 (Expression) $1, (Expression) $3, lexer.Location);
3079 | relational_expression IS type
3081 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
3083 | relational_expression AS type
3085 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
3090 : relational_expression
3091 | equality_expression OP_EQ relational_expression
3093 $$ = new Binary (Binary.Operator.Equality,
3094 (Expression) $1, (Expression) $3, lexer.Location);
3096 | equality_expression OP_NE relational_expression
3098 $$ = new Binary (Binary.Operator.Inequality,
3099 (Expression) $1, (Expression) $3, lexer.Location);
3104 : equality_expression
3105 | and_expression BITWISE_AND equality_expression
3107 $$ = new Binary (Binary.Operator.BitwiseAnd,
3108 (Expression) $1, (Expression) $3, lexer.Location);
3112 exclusive_or_expression
3114 | exclusive_or_expression CARRET and_expression
3116 $$ = new Binary (Binary.Operator.ExclusiveOr,
3117 (Expression) $1, (Expression) $3, lexer.Location);
3121 inclusive_or_expression
3122 : exclusive_or_expression
3123 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3125 $$ = new Binary (Binary.Operator.BitwiseOr,
3126 (Expression) $1, (Expression) $3, lexer.Location);
3130 conditional_and_expression
3131 : inclusive_or_expression
3132 | conditional_and_expression OP_AND inclusive_or_expression
3134 $$ = new Binary (Binary.Operator.LogicalAnd,
3135 (Expression) $1, (Expression) $3, lexer.Location);
3139 conditional_or_expression
3140 : conditional_and_expression
3141 | conditional_or_expression OP_OR conditional_and_expression
3143 $$ = new Binary (Binary.Operator.LogicalOr,
3144 (Expression) $1, (Expression) $3, lexer.Location);
3148 conditional_expression
3149 : conditional_or_expression
3150 | conditional_or_expression INTERR expression COLON expression
3152 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
3156 assignment_expression
3157 : prefixed_unary_expression ASSIGN expression
3159 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
3161 | prefixed_unary_expression OP_MULT_ASSIGN expression
3163 Location l = lexer.Location;
3165 $$ = new CompoundAssign (
3166 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
3168 | prefixed_unary_expression OP_DIV_ASSIGN expression
3170 Location l = lexer.Location;
3172 $$ = new CompoundAssign (
3173 Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
3175 | prefixed_unary_expression OP_MOD_ASSIGN expression
3177 Location l = lexer.Location;
3179 $$ = new CompoundAssign (
3180 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
3182 | prefixed_unary_expression OP_ADD_ASSIGN expression
3184 Location l = lexer.Location;
3186 $$ = new CompoundAssign (
3187 Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
3189 | prefixed_unary_expression OP_SUB_ASSIGN expression
3191 Location l = lexer.Location;
3193 $$ = new CompoundAssign (
3194 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
3196 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3198 Location l = lexer.Location;
3200 $$ = new CompoundAssign (
3201 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
3203 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3205 Location l = lexer.Location;
3207 $$ = new CompoundAssign (
3208 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
3210 | prefixed_unary_expression OP_AND_ASSIGN expression
3212 Location l = lexer.Location;
3214 $$ = new CompoundAssign (
3215 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
3217 | prefixed_unary_expression OP_OR_ASSIGN expression
3219 Location l = lexer.Location;
3221 $$ = new CompoundAssign (
3222 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
3224 | prefixed_unary_expression OP_XOR_ASSIGN expression
3226 Location l = lexer.Location;
3228 $$ = new CompoundAssign (
3229 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
3234 : conditional_expression
3235 | assignment_expression
3255 MemberName name = MakeName ((MemberName) $5);
3256 bool partial = (bool) $3;
3257 int mod_flags = (int) $2;
3260 ClassPart part = PartialContainer.CreatePart (
3261 current_namespace, current_container, name, mod_flags,
3262 (Attributes) $1, Kind.Class, lexer.Location);
3264 current_container = part.PartialContainer;
3265 current_class = part;
3267 if ((mod_flags & Modifiers.STATIC) != 0) {
3268 current_class = new StaticClass (
3269 current_namespace, current_container, name,
3270 mod_flags, (Attributes) $1, lexer.Location);
3272 current_class = new Class (
3273 current_namespace, current_container, name,
3274 mod_flags, (Attributes) $1, lexer.Location);
3277 current_container = current_class;
3278 RootContext.Tree.RecordDecl (name.GetName (true), current_class);
3284 if (current_class.Name == "System.Object") {
3285 Report.Error (537, current_class.Location,
3286 "The class System.Object cannot have a base " +
3287 "class or implement an interface.");
3289 current_class.Bases = (ArrayList) $7;
3292 if (RootContext.Documentation != null) {
3293 current_class.DocComment = Lexer.consume_doc_comment ();
3294 Lexer.doc_state = XmlCommentState.Allowed;
3297 current_class.Register ();
3301 if (RootContext.Documentation != null)
3302 Lexer.doc_state = XmlCommentState.Allowed;
3308 current_container = current_container.Parent;
3309 current_class = current_container;
3315 { $$ = (bool) false; }
3317 { $$ = (bool) true; }
3321 : /* empty */ { $$ = (int) 0; }
3327 | modifiers modifier
3332 if ((m1 & m2) != 0) {
3333 Location l = lexer.Location;
3334 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3336 $$ = (int) (m1 | m2);
3341 : NEW { $$ = Modifiers.NEW; }
3342 | PUBLIC { $$ = Modifiers.PUBLIC; }
3343 | PROTECTED { $$ = Modifiers.PROTECTED; }
3344 | INTERNAL { $$ = Modifiers.INTERNAL; }
3345 | PRIVATE { $$ = Modifiers.PRIVATE; }
3346 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3347 | SEALED { $$ = Modifiers.SEALED; }
3348 | STATIC { $$ = Modifiers.STATIC; }
3349 | READONLY { $$ = Modifiers.READONLY; }
3350 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3351 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3352 | EXTERN { $$ = Modifiers.EXTERN; }
3353 | VOLATILE { $$ = Modifiers.VOLATILE; }
3354 | UNSAFE { $$ = Modifiers.UNSAFE; }
3358 : /* empty */ { $$ = null; }
3359 | class_base { $$ = $1; }
3363 : COLON type_list { $$ = $2; }
3371 // A block is "contained" on the following places:
3373 // property_declaration as part of the accessor body (get/set)
3374 // operator_declaration
3375 // constructor_declaration
3376 // destructor_declaration
3377 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3382 if (current_block == null){
3383 current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, lexer.Location);
3384 top_current_block = current_block;
3386 current_block = new Block (current_block, current_local_parameters,
3387 lexer.Location, Location.Null);
3390 opt_statement_list CLOSE_BRACE
3392 while (current_block.Implicit)
3393 current_block = current_block.Parent;
3395 current_block.SetEndLocation (lexer.Location);
3396 current_block = current_block.Parent;
3397 if (current_block == null)
3398 top_current_block = null;
3409 | statement_list statement
3413 : declaration_statement
3415 if ($1 != null && (Block) $1 != current_block){
3416 current_block.AddStatement ((Statement) $1);
3417 current_block = (Block) $1;
3420 | valid_declaration_statement
3422 current_block.AddStatement ((Statement) $1);
3427 valid_declaration_statement
3430 | expression_statement
3431 | selection_statement
3432 | iteration_statement
3436 | unchecked_statement
3444 : valid_declaration_statement
3445 | declaration_statement
3447 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
3452 Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
3460 $$ = EmptyStatement.Value;
3467 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3469 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3470 current_block.AddStatement (labeled);
3475 declaration_statement
3476 : local_variable_declaration SEMICOLON
3479 DictionaryEntry de = (DictionaryEntry) $1;
3481 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3485 | local_constant_declaration SEMICOLON
3488 DictionaryEntry de = (DictionaryEntry) $1;
3490 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3496 * The following is from Rhys' grammar:
3497 * > Types in local variable declarations must be recognized as
3498 * > expressions to prevent reduce/reduce errors in the grammar.
3499 * > The expressions are converted into types during semantic analysis.
3502 : primary_expression opt_rank_specifier
3504 // FIXME: Do something smart here regarding the composition of the type.
3506 // Ok, the above "primary_expression" is there to get rid of
3507 // both reduce/reduce and shift/reduces in the grammar, it should
3508 // really just be "type_name". If you use type_name, a reduce/reduce
3509 // creeps up. If you use namespace_or_type_name (which is all we need
3510 // really) two shift/reduces appear.
3513 // So the super-trick is that primary_expression
3514 // can only be either a SimpleName or a MemberAccess.
3515 // The MemberAccess case arises when you have a fully qualified type-name like :
3517 // SimpleName is when you have
3520 Expression expr = (Expression) $1;
3521 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast)) {
3522 Error_ExpectingTypeName (lexer.Location, expr);
3526 // So we extract the string corresponding to the SimpleName
3530 if ((string) $2 == "")
3533 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3536 | builtin_types opt_rank_specifier
3538 if ((string) $2 == "")
3541 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3545 local_variable_pointer_type
3546 : primary_expression STAR
3548 Expression expr = (Expression) $1;
3549 Location l = lexer.Location;
3551 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast)) {
3552 Error_ExpectingTypeName (l, expr);
3556 $$ = new ComposedCast ((Expression) $1, "*", l);
3558 | builtin_types STAR
3560 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
3564 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3566 | local_variable_pointer_type STAR
3568 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3572 local_variable_declaration
3573 : local_variable_type variable_declarators
3576 $$ = new DictionaryEntry ($1, $2);
3580 | local_variable_pointer_type opt_rank_specifier variable_declarators
3585 if ((string) $2 == "")
3586 t = (Expression) $1;
3588 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
3589 $$ = new DictionaryEntry (t, $3);
3595 local_constant_declaration
3596 : CONST local_variable_type constant_declarators
3599 $$ = new DictionaryEntry ($2, $3);
3605 expression_statement
3606 : statement_expression SEMICOLON
3613 // We have to do the wrapping here and not in the case above,
3614 // because statement_expression is used for example in for_statement
3616 statement_expression
3617 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3618 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3619 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3620 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3621 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3622 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3623 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3625 Report.Error (1002, lexer.Location, "Expecting `;'");
3630 object_creation_expression
3631 : object_or_delegate_creation_expression
3632 { note ("complain if this is a delegate maybe?"); }
3641 : if_statement_open if_statement_rest
3650 oob_stack.Push (lexer.Location);
3655 : boolean_expression CLOSE_PARENS
3658 Location l = (Location) oob_stack.Pop ();
3660 $$ = new If ((Expression) $1, (Statement) $3, l);
3662 if (RootContext.WarningLevel >= 4){
3663 if ($3 == EmptyStatement.Value)
3664 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3668 | boolean_expression CLOSE_PARENS
3669 embedded_statement ELSE embedded_statement
3671 Location l = (Location) oob_stack.Pop ();
3673 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
3678 : SWITCH OPEN_PARENS
3680 oob_stack.Push (lexer.Location);
3681 switch_stack.Push (current_block);
3683 expression CLOSE_PARENS
3686 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
3687 current_block = (Block) switch_stack.Pop ();
3703 Report.Error (1522, lexer.Location, "Empty switch block");
3711 ArrayList sections = new ArrayList (4);
3716 | switch_sections switch_section
3718 ArrayList sections = (ArrayList) $1;
3728 current_block = current_block.CreateSwitchBlock (lexer.Location);
3732 Block topmost = current_block;
3734 while (topmost.Implicit)
3735 topmost = topmost.Parent;
3736 $$ = new SwitchSection ((ArrayList) $1, topmost);
3743 ArrayList labels = new ArrayList (4);
3748 | switch_labels switch_label
3750 ArrayList labels = (ArrayList) ($1);
3758 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3759 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
3762 1523, lexer.Location,
3763 "The keyword case or default must precede code in switch block");
3777 oob_stack.Push (lexer.Location);
3779 boolean_expression CLOSE_PARENS embedded_statement
3781 Location l = (Location) oob_stack.Pop ();
3782 $$ = new While ((Expression) $4, (Statement) $6, l);
3784 if (RootContext.WarningLevel >= 4){
3785 if ($6 == EmptyStatement.Value)
3786 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3792 : DO embedded_statement
3794 oob_stack.Push (lexer.Location);
3796 boolean_expression CLOSE_PARENS SEMICOLON
3798 Location l = (Location) oob_stack.Pop ();
3800 $$ = new Do ((Statement) $2, (Expression) $6, l);
3806 opt_for_initializer SEMICOLON
3808 Block assign_block = new Block (current_block);
3809 current_block = assign_block;
3811 if ($3 is DictionaryEntry){
3812 DictionaryEntry de = (DictionaryEntry) $3;
3814 Expression type = (Expression) de.Key;
3815 ArrayList var_declarators = (ArrayList) de.Value;
3817 foreach (VariableDeclaration decl in var_declarators){
3821 vi = current_block.AddVariable (
3822 type, decl.identifier, current_local_parameters, decl.Location);
3826 Location l = lexer.Location;
3828 if (decl.expression_or_array_initializer is Expression){
3829 expr = (Expression) decl.expression_or_array_initializer;
3830 } else if (decl.expression_or_array_initializer == null) {
3833 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3834 expr = new ArrayCreation (type, "", init, decl.Location);
3837 LocalVariableReference var;
3838 var = new LocalVariableReference (assign_block, decl.identifier, l);
3841 Assign a = new Assign (var, expr, decl.Location);
3843 assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3849 oob_stack.Push (lexer.Location);
3851 opt_for_condition SEMICOLON
3852 opt_for_iterator CLOSE_PARENS
3855 Location l = (Location) oob_stack.Pop ();
3857 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3859 if (RootContext.WarningLevel >= 4){
3860 if ($10 == EmptyStatement.Value)
3861 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
3864 current_block.AddStatement (f);
3865 while (current_block.Implicit)
3866 current_block = current_block.Parent;
3868 current_block = current_block.Parent;
3873 : /* empty */ { $$ = EmptyStatement.Value; }
3878 : local_variable_declaration
3879 | statement_expression_list
3883 : /* empty */ { $$ = null; }
3884 | boolean_expression
3888 : /* empty */ { $$ = EmptyStatement.Value; }
3893 : statement_expression_list
3896 statement_expression_list
3897 : statement_expression
3899 // CHANGE: was `null'
3900 Block b = new Block (current_block, Block.Flags.Implicit);
3902 b.AddStatement ((Statement) $1);
3905 | statement_expression_list COMMA statement_expression
3907 Block b = (Block) $1;
3909 b.AddStatement ((Statement) $3);
3915 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
3917 Report.Error (230, lexer.Location, "Type and identifier are both required in a foreach statement");
3920 | FOREACH OPEN_PARENS type IDENTIFIER IN
3922 oob_stack.Push (lexer.Location);
3924 expression CLOSE_PARENS
3926 oob_stack.Push (current_block);
3928 Block foreach_block = new Block (current_block);
3929 LocalVariableReference v = null;
3930 Location l = lexer.Location;
3933 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3937 // Get a writable reference to this read-only variable.
3938 v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3940 current_block = foreach_block;
3943 oob_stack.Push (current_block);
3947 Block foreach_block = (Block) oob_stack.Pop ();
3948 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3949 Block prev_block = (Block) oob_stack.Pop ();
3950 Location l = (Location) oob_stack.Pop ();
3952 current_block = prev_block;
3955 Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3956 foreach_block.AddStatement (f);
3965 | continue_statement
3975 $$ = new Break (lexer.Location);
3980 : CONTINUE SEMICOLON
3982 $$ = new Continue (lexer.Location);
3987 : GOTO IDENTIFIER SEMICOLON
3989 $$ = new Goto (current_block, (string) $2, lexer.Location);
3991 | GOTO CASE constant_expression SEMICOLON
3993 $$ = new GotoCase ((Expression) $3, lexer.Location);
3995 | GOTO DEFAULT SEMICOLON
3997 $$ = new GotoDefault (lexer.Location);
4002 : RETURN opt_expression SEMICOLON
4004 $$ = new Return ((Expression) $2, lexer.Location);
4009 : THROW opt_expression SEMICOLON
4011 $$ = new Throw ((Expression) $2, lexer.Location);
4016 : IDENTIFIER RETURN expression SEMICOLON
4018 string s = (string) $1;
4020 Report.Error (1003, lexer.Location, "; expected");
4023 if (RootContext.Version == LanguageVersion.ISO_1){
4024 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
4027 if (iterator_container == null){
4028 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
4031 iterator_container.SetYields ();
4032 $$ = new Yield ((Expression) $3, lexer.Location);
4035 | IDENTIFIER BREAK SEMICOLON
4037 string s = (string) $1;
4039 Report.Error (1003, lexer.Location, "; expected");
4042 if (RootContext.Version == LanguageVersion.ISO_1){
4043 Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
4046 if (iterator_container == null){
4047 Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
4050 iterator_container.SetYields ();
4051 $$ = new YieldBreak (lexer.Location);
4062 : TRY block catch_clauses
4066 ArrayList c = (ArrayList)$3;
4067 for (int i = 0; i < c.Count; ++i) {
4068 Catch cc = (Catch) c [i];
4070 if (i != c.Count - 1)
4071 Report.Error (1017, cc.loc, "Empty catch block must be the last in a series of catch blocks");
4078 // Now s contains the list of specific catch clauses
4079 // and g contains the general one.
4081 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4083 | TRY block opt_catch_clauses FINALLY block
4086 ArrayList s = new ArrayList (4);
4087 ArrayList catch_list = (ArrayList) $3;
4089 if (catch_list != null){
4090 foreach (Catch cc in catch_list) {
4098 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4102 Report.Error (1524, lexer.Location, "Expected catch or finally");
4107 : /* empty */ { $$ = null; }
4114 ArrayList l = new ArrayList (4);
4119 | catch_clauses catch_clause
4121 ArrayList l = (ArrayList) $1;
4129 : /* empty */ { $$ = null; }
4134 : CATCH opt_catch_args
4136 Expression type = null;
4140 DictionaryEntry cc = (DictionaryEntry) $2;
4141 type = (Expression) cc.Key;
4142 id = (string) cc.Value;
4145 ArrayList one = new ArrayList (4);
4146 Location loc = lexer.Location;
4148 one.Add (new VariableDeclaration (id, null, loc));
4151 current_block = new Block (current_block);
4152 Block b = declare_local_variables (type, one, loc);
4157 Expression type = null;
4161 DictionaryEntry cc = (DictionaryEntry) $2;
4162 type = (Expression) cc.Key;
4163 id = (string) cc.Value;
4167 // FIXME: I can change this for an assignment.
4169 while (current_block != (Block) $1)
4170 current_block = current_block.Parent;
4175 $$ = new Catch (type, id , (Block) $4, ((Block) $4).loc);
4180 : /* empty */ { $$ = null; }
4185 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4187 $$ = new DictionaryEntry ($2, $3);
4194 $$ = new Checked ((Block) $2);
4201 $$ = new Unchecked ((Block) $2);
4208 if (!RootContext.Unsafe){
4209 Report.Error (227, lexer.Location,
4210 "Unsafe code can only be used if --unsafe is used");
4213 $$ = new Unsafe ((Block) $3);
4219 type fixed_pointer_declarators
4222 ArrayList list = (ArrayList) $4;
4223 Expression type = (Expression) $3;
4224 Location l = lexer.Location;
4225 int top = list.Count;
4227 Block assign_block = new Block (current_block);
4228 current_block = assign_block;
4230 for (int i = 0; i < top; i++){
4231 Pair p = (Pair) list [i];
4234 v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
4248 Location l = (Location) oob_stack.Pop ();
4250 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4252 if (RootContext.WarningLevel >= 4){
4253 if ($7 == EmptyStatement.Value)
4254 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
4257 current_block.AddStatement (f);
4258 while (current_block.Implicit)
4259 current_block = current_block.Parent;
4261 current_block = current_block.Parent;
4265 fixed_pointer_declarators
4266 : fixed_pointer_declarator {
4267 ArrayList declarators = new ArrayList (4);
4269 declarators.Add ($1);
4272 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4274 ArrayList declarators = (ArrayList) $1;
4276 declarators.Add ($3);
4281 fixed_pointer_declarator
4282 : IDENTIFIER ASSIGN expression
4284 $$ = new Pair ($1, $3);
4288 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
4294 : LOCK OPEN_PARENS expression CLOSE_PARENS
4300 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4305 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4307 Block assign_block = new Block (current_block);
4308 current_block = assign_block;
4310 oob_stack.Push (lexer.Location);
4312 if ($3 is DictionaryEntry){
4313 DictionaryEntry de = (DictionaryEntry) $3;
4314 Location l = lexer.Location;
4316 Expression type = (Expression) de.Key;
4317 ArrayList var_declarators = (ArrayList) de.Value;
4319 ArrayList vars = new ArrayList (4);
4321 foreach (VariableDeclaration decl in var_declarators){
4323 LocalInfo vi = current_block.AddVariable (
4324 type, decl.identifier,
4325 current_local_parameters, decl.Location);
4331 if (decl.expression_or_array_initializer is Expression){
4332 expr = (Expression) decl.expression_or_array_initializer;
4334 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4336 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4339 expr = new ArrayCreation (type, "", init, decl.Location);
4342 LocalVariableReference var;
4344 // Get a writable reference to this read-only variable.
4345 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4347 // This is so that it is not a warning on using variables
4350 vars.Add (new DictionaryEntry (var, expr));
4352 // Assign a = new Assign (var, expr, decl.Location);
4353 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4355 $3 = new DictionaryEntry (type, vars);
4360 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
4361 current_block.AddStatement (u);
4362 while (current_block.Implicit)
4363 current_block = current_block.Parent;
4365 current_block = current_block.Parent;
4369 resource_acquisition
4370 : local_variable_declaration
4377 // A class used to pass around variable declarations and constants
4379 public class VariableDeclaration {
4380 public string identifier;
4381 public object expression_or_array_initializer;
4382 public Location Location;
4383 public Attributes OptAttributes;
4384 public string DocComment;
4386 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4388 this.identifier = id;
4389 this.expression_or_array_initializer = eoai;
4391 this.OptAttributes = opt_attrs;
4394 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4400 /// Used to pass around interface property information
4402 public class InterfaceAccessorInfo {
4404 public readonly Accessor Get, Set;
4406 public InterfaceAccessorInfo (bool has_get, bool has_set,
4407 Attributes get_attrs, Attributes set_attrs, int get_mod, int set_mod, Location get_loc, Location set_loc)
4410 Report.Error (275, get_loc, "Accessibility modifiers can not be used on accessors in interfaces");
4412 Report.Error (275, set_loc, "Accessibility modifiers can not be used on accessors in interfaces");
4415 Get = new Accessor (null, 0, get_attrs, get_loc);
4417 Set = new Accessor (null, 0, set_attrs, set_loc);
4424 // A class used to hold info about an indexer declarator
4426 public class IndexerDeclaration {
4427 public Expression type;
4428 public MemberName interface_type;
4429 public Parameters param_list;
4431 public IndexerDeclaration (Expression type, MemberName interface_type,
4432 Parameters param_list)
4435 this.interface_type = interface_type;
4436 this.param_list = param_list;
4441 // We use this when we do not have an object in advance that is an IIteratorContainer
4443 public class SimpleIteratorContainer : IIteratorContainer {
4446 public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4451 public static SimpleIteratorContainer GetSimple () {
4452 Simple.Yields = false;
4456 public void SetYields () { Yields = true; }
4460 // A class used to hold info about an operator declarator
4462 public class OperatorDeclaration {
4463 public Operator.OpType optype;
4464 public Expression ret_type, arg1type, arg2type;
4465 public string arg1name, arg2name;
4466 public Location location;
4468 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
4469 Expression arg1type, string arg1name,
4470 Expression arg2type, string arg2name, Location location)
4473 this.ret_type = ret_type;
4474 this.arg1type = arg1type;
4475 this.arg1name = arg1name;
4476 this.arg2type = arg2type;
4477 this.arg2name = arg2name;
4478 this.location = location;
4483 void Error_ExpectingTypeName (Location l, Expression expr)
4485 if (expr is Invocation){
4486 Report.Error (1002, l, "; expected");
4488 Report.Error (-1, l, "Invalid Type definition");
4493 // Given the @class_name name, it creates a fully qualified name
4494 // based on the containing declaration space
4497 MakeName (MemberName class_name)
4499 string ns = current_namespace.FullName;
4501 if (current_container.Name == ""){
4503 return new MemberName (new MemberName (ns), class_name);
4507 return new MemberName (current_container.MemberName, class_name);
4511 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
4513 Block implicit_block;
4514 ArrayList inits = null;
4517 // We use the `Used' property to check whether statements
4518 // have been added to the current block. If so, we need
4519 // to create another block to contain the new declaration
4520 // otherwise, as an optimization, we use the same block to
4521 // add the declaration.
4523 // FIXME: A further optimization is to check if the statements
4524 // that were added were added as part of the initialization
4525 // below. In which case, no other statements have been executed
4526 // and we might be able to reduce the number of blocks for
4527 // situations like this:
4529 // int j = 1; int k = j + 1;
4531 if (current_block.Used)
4532 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
4534 implicit_block = current_block;
4536 foreach (VariableDeclaration decl in variable_declarators){
4538 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
4539 if (decl.expression_or_array_initializer != null){
4541 inits = new ArrayList (4);
4548 return implicit_block;
4550 foreach (VariableDeclaration decl in inits){
4554 if (decl.expression_or_array_initializer is Expression){
4555 expr = (Expression) decl.expression_or_array_initializer;
4558 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4560 expr = new ArrayCreation (type, "", init, decl.Location);
4563 LocalVariableReference var;
4564 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
4566 assign = new Assign (var, expr, decl.Location);
4568 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
4571 return implicit_block;
4574 Block declare_local_constants (Expression type, ArrayList declarators)
4576 Block implicit_block;
4578 if (current_block.Used)
4579 implicit_block = new Block (current_block, Block.Flags.Implicit);
4581 implicit_block = current_block;
4583 foreach (VariableDeclaration decl in declarators){
4584 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
4585 current_local_parameters, decl.Location);
4588 return implicit_block;
4591 void CheckAttributeTarget (string a)
4595 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
4599 Location l = lexer.Location;
4600 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
4606 void CheckUnaryOperator (Operator.OpType op)
4610 case Operator.OpType.LogicalNot:
4611 case Operator.OpType.OnesComplement:
4612 case Operator.OpType.Increment:
4613 case Operator.OpType.Decrement:
4614 case Operator.OpType.True:
4615 case Operator.OpType.False:
4616 case Operator.OpType.Addition:
4617 case Operator.OpType.Subtraction:
4622 Location l = lexer.Location;
4623 Report.Error (1019, l, "Overloadable unary operator expected");
4629 void CheckBinaryOperator (Operator.OpType op)
4633 case Operator.OpType.Addition:
4634 case Operator.OpType.Subtraction:
4635 case Operator.OpType.Multiply:
4636 case Operator.OpType.Division:
4637 case Operator.OpType.Modulus:
4638 case Operator.OpType.BitwiseAnd:
4639 case Operator.OpType.BitwiseOr:
4640 case Operator.OpType.ExclusiveOr:
4641 case Operator.OpType.LeftShift:
4642 case Operator.OpType.RightShift:
4643 case Operator.OpType.Equality:
4644 case Operator.OpType.Inequality:
4645 case Operator.OpType.GreaterThan:
4646 case Operator.OpType.LessThan:
4647 case Operator.OpType.GreaterThanOrEqual:
4648 case Operator.OpType.LessThanOrEqual:
4652 Location l = lexer.Location;
4653 Report.Error (1020, l, "Overloadable binary operator expected");
4659 void syntax_error (Location l, string msg)
4661 Report.Error (1003, l, "Syntax error, " + msg);
4664 void output (string s)
4666 Console.WriteLine (s);
4669 void note (string s)
4671 // Used to put annotations
4676 public Tokenizer Lexer {
4682 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
4684 current_namespace = new NamespaceEntry (null, file, null, Location.Null);
4685 this.name = file.Name;
4687 current_container = RootContext.Tree.Types;
4688 current_container.NamespaceEntry = current_namespace;
4689 oob_stack = new Stack ();
4690 switch_stack = new Stack ();
4692 lexer = new Tokenizer (reader, file, defines);
4695 public void parse ()
4698 if (yacc_verbose_flag > 1)
4699 yyparse (lexer, new yydebug.yyDebugSimple ());
4702 Tokenizer tokenizer = lexer as Tokenizer;
4703 tokenizer.cleanup ();
4704 } catch (Exception e){
4706 // Removed for production use, use parser verbose to get the output.
4708 // Console.WriteLine (e);
4709 Report.Error (-25, lexer.Location, "Parsing error");
4710 if (yacc_verbose_flag > 0)
4711 Console.WriteLine (e);
4715 void CheckToken (int error, int yyToken, string msg)
4717 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
4718 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
4721 Report.Error (error, lexer.Location, msg);
4724 void CheckIdentifierToken (int yyToken)
4726 CheckToken (1041, yyToken, "Identifier expected");
4729 string ConsumeStoredComment ()
4731 string s = tmpComment;
4733 Lexer.doc_state = XmlCommentState.Allowed;