Switch to compiler-tester
[mono.git] / mcs / gmcs / cs-parser.jay
1 %{
2 //
3 // cs-parser.jay: The Parser for the C# compiler
4 //
5 // Authors: Miguel de Icaza (miguel@gnu.org)
6 //          Ravi Pratap     (ravi@ximian.com)
7 //
8 // Licensed under the terms of the GNU GPL
9 //
10 // (C) 2001 Ximian, Inc (http://www.ximian.com)
11 // (C) 2004 Novell, Inc
12 //
13 // TODO:
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:
16 //       "public X { }"
17 //
18 // Possible optimization:
19 //   Run memory profiler with parsing only, and consider dropping 
20 //   arraylists where not needed.   Some pieces can use linked lists.
21 //
22 using System.Text;
23 using System.IO;
24 using System;
25
26 namespace Mono.CSharp
27 {
28         using System.Collections;
29
30         /// <summary>
31         ///    The C# Parser
32         /// </summary>
33         public class CSharpParser {
34                 NamespaceEntry  current_namespace;
35                 TypeContainer   current_container;
36                 TypeContainer   current_class;
37         
38                 IIteratorContainer iterator_container;
39
40                 /// <summary>
41                 ///   Current block is used to add statements as we find
42                 ///   them.  
43                 /// </summary>
44                 Block      current_block, top_current_block;
45
46                 Delegate   current_delegate;
47
48                 /// <summary>
49                 ///   This is used by the unary_expression code to resolve
50                 ///   a name against a parameter.  
51                 /// </summary>
52                 Parameters current_local_parameters;
53
54                 /// <summary>
55                 ///   Using during property parsing to describe the implicit
56                 ///   value parameter that is passed to the "set" and "get"accesor
57                 ///   methods (properties and indexers).
58                 /// </summary>
59                 Expression implicit_value_parameter_type;
60                 Parameters indexer_parameters;
61
62                 /// <summary>
63                 ///   Used to determine if we are parsing the get/set pair
64                 ///   of an indexer or a property
65                 /// </summmary>
66                 bool  parsing_indexer;
67
68                 ///
69                 /// An out-of-band stack.
70                 ///
71                 Stack oob_stack;
72
73                 ///
74                 /// Switch stack.
75                 ///
76                 Stack switch_stack;
77
78                 static public int yacc_verbose_flag;
79
80                 // Name of the file we are parsing
81                 public string name;
82
83                 ///
84                 /// The current file.
85                 ///
86                 SourceFile file;
87
88                 ///
89                 /// Temporary Xml documentation cache.
90                 /// For enum types, we need one more temporary store.
91                 ///
92                 string tmpComment;
93                 string enumTypeComment;
94                         
95                 /// Current attribute target
96                 string current_attr_target;
97                 
98                 /// assembly and module attribute definition is enabled
99                 bool global_attrs_enabled = true;
100                 bool has_get, has_set;
101
102 %}
103
104 %token EOF
105 %token NONE   /* This token is never returned by our lexer */
106 %token ERROR            // This is used not by the parser, but by the tokenizer.
107                         // do not remove.
108
109 /*
110  *These are the C# keywords
111  */
112 %token FIRST_KEYWORD
113 %token ABSTRACT 
114 %token AS
115 %token ADD
116 %token ASSEMBLY
117 %token BASE     
118 %token BOOL     
119 %token BREAK    
120 %token BYTE     
121 %token CASE     
122 %token CATCH    
123 %token CHAR     
124 %token CHECKED  
125 %token CLASS    
126 %token CONST    
127 %token CONTINUE 
128 %token DECIMAL  
129 %token DEFAULT  
130 %token DELEGATE 
131 %token DO       
132 %token DOUBLE   
133 %token ELSE     
134 %token ENUM     
135 %token EVENT    
136 %token EXPLICIT 
137 %token EXTERN   
138 %token FALSE    
139 %token FINALLY  
140 %token FIXED    
141 %token FLOAT    
142 %token FOR      
143 %token FOREACH  
144 %token GOTO     
145 %token IF       
146 %token IMPLICIT 
147 %token IN       
148 %token INT      
149 %token INTERFACE
150 %token INTERNAL 
151 %token IS       
152 %token LOCK     
153 %token LONG     
154 %token NAMESPACE
155 %token NEW      
156 %token NULL     
157 %token OBJECT   
158 %token OPERATOR 
159 %token OUT      
160 %token OVERRIDE 
161 %token PARAMS   
162 %token PRIVATE  
163 %token PROTECTED
164 %token PUBLIC   
165 %token READONLY 
166 %token REF      
167 %token RETURN   
168 %token REMOVE
169 %token SBYTE    
170 %token SEALED   
171 %token SHORT    
172 %token SIZEOF   
173 %token STACKALLOC
174 %token STATIC   
175 %token STRING   
176 %token STRUCT   
177 %token SWITCH   
178 %token THIS     
179 %token THROW    
180 %token TRUE     
181 %token TRY      
182 %token TYPEOF   
183 %token UINT     
184 %token ULONG    
185 %token UNCHECKED
186 %token UNSAFE   
187 %token USHORT   
188 %token USING    
189 %token VIRTUAL  
190 %token VOID     
191 %token VOLATILE
192 %token WHERE
193 %token WHILE    
194 %token ARGLIST
195 %token PARTIAL
196
197 /* C# keywords which are not really keywords */
198 %token GET           "get"
199 %token SET           "set"
200
201 %left LAST_KEYWORD
202
203 /* C# single character operators/punctuation. */
204 %token OPEN_BRACE    "{"
205 %token CLOSE_BRACE   "}"
206 %token OPEN_BRACKET  "["
207 %token CLOSE_BRACKET "]"
208 %token OPEN_PARENS   "("
209 %token CLOSE_PARENS  ")"
210 %token DOT           "."
211 %token COMMA         ","
212 %token COLON         ":"
213 %token SEMICOLON     ";"
214 %token TILDE         "~"
215
216 %token PLUS           "+"
217 %token MINUS          "-"
218 %token BANG           "!"
219 %token ASSIGN         "="
220 %token OP_LT          "<"
221 %token OP_GENERICS_LT "<"
222 %token OP_GT          ">"
223 %token OP_GENERICS_GT ">"
224 %token BITWISE_AND    "&"
225 %token BITWISE_OR     "|"
226 %token STAR           "*"
227 %token PERCENT        "%"
228 %token DIV            "/"
229 %token CARRET         "^"
230 %token INTERR         "?"
231
232 /* C# multi-character operators. */
233 %token OP_INC                 "++"
234 %token OP_DEC                 "--"
235 %token OP_SHIFT_LEFT          "<<"
236 %token OP_SHIFT_RIGHT         ">>"
237 %token OP_LE                  "<="
238 %token OP_GE                  ">="
239 %token OP_EQ                  "=="
240 %token OP_NE                  "!="
241 %token OP_AND                 "&&"
242 %token OP_OR                  "||"
243 %token OP_MULT_ASSIGN         "*="
244 %token OP_DIV_ASSIGN          "/="
245 %token OP_MOD_ASSIGN          "%="
246 %token OP_ADD_ASSIGN          "+="
247 %token OP_SUB_ASSIGN          "-="
248 %token OP_SHIFT_LEFT_ASSIGN   "<<="
249 %token OP_SHIFT_RIGHT_ASSIGN  ">>="
250 %token OP_AND_ASSIGN          "&="
251 %token OP_XOR_ASSIGN          "^="
252 %token OP_OR_ASSIGN           "|="
253 %token OP_PTR                 "->"
254
255 /* Numbers */
256 %token LITERAL_INTEGER           "int literal"
257 %token LITERAL_FLOAT             "float literal"
258 %token LITERAL_DOUBLE            "double literal"
259 %token LITERAL_DECIMAL           "decimal literal"
260 %token LITERAL_CHARACTER         "character literal"
261 %token LITERAL_STRING            "string literal"
262
263 %token IDENTIFIER
264 %token CLOSE_PARENS_CAST
265 %token CLOSE_PARENS_NO_CAST
266 %token CLOSE_PARENS_OPEN_PARENS
267 %token CLOSE_PARENS_MINUS
268 %token DEFAULT_OPEN_PARENS
269 %token GENERIC_DIMENSION
270
271 /* Add precedence rules to solve dangling else s/r conflict */
272 %nonassoc LOWPREC
273 %nonassoc IF
274 %nonassoc ELSE
275 %right ASSIGN
276 %left OP_OR
277 %left OP_AND
278 %left BITWISE_OR
279 %left BITWISE_AND
280 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
281 %left PLUS MINUS
282 %left STAR DIV PERCENT
283 %right BANG CARRET UMINUS
284 %nonassoc OP_INC OP_DEC
285 %left OPEN_PARENS
286 %left OPEN_BRACKET OPEN_BRACE
287 %left DOT
288 %nonassoc HIGHPREC
289
290 %start compilation_unit
291 %%
292
293 compilation_unit
294         : outer_declarations opt_EOF
295         | outer_declarations global_attributes opt_EOF
296         | global_attributes opt_EOF
297         | opt_EOF /* allow empty files */
298         ;
299         
300 opt_EOF
301         : /* empty */
302         {
303                 Lexer.check_incorrect_doc_comment ();
304         }
305         | EOF
306         {
307                 Lexer.check_incorrect_doc_comment ();
308         }
309         ;
310
311 outer_declarations
312         : outer_declaration
313         | outer_declarations outer_declaration
314         ;
315  
316 outer_declaration
317         : using_directive
318         | namespace_member_declaration
319         ;
320   
321 using_directives
322         : using_directive 
323         | using_directives using_directive
324         ;
325
326 using_directive
327         : using_alias_directive
328         {
329                 if (RootContext.Documentation != null)
330                         Lexer.doc_state = XmlCommentState.Allowed;
331         }
332         | using_namespace_directive
333         {
334                 if (RootContext.Documentation != null)
335                         Lexer.doc_state = XmlCommentState.Allowed;
336         }
337         ;
338
339 using_alias_directive
340         : USING IDENTIFIER ASSIGN 
341           namespace_or_type_name SEMICOLON
342           {
343                 current_namespace.UsingAlias ((string) $2, (MemberName) $4, lexer.Location);
344           }
345         | USING error {
346                 CheckIdentifierToken (yyToken);
347           }
348         ;
349
350 using_namespace_directive
351         : USING namespace_name SEMICOLON 
352           {
353                 current_namespace.Using ((MemberName) $2, lexer.Location);
354           }
355         ;
356
357 //
358 // Strictly speaking, namespaces don't have attributes but
359 // we parse global attributes along with namespace declarations and then
360 // detach them
361 // 
362 namespace_declaration
363         : opt_attributes NAMESPACE namespace_or_type_name
364         {
365                 if ($1 != null) {
366                         Report.Error(1671, Lexer.Location, "A namespace declaration cannot have modifiers or attributes");
367                 }
368
369                 MemberName name = (MemberName) $3;
370
371                 if (name.TypeArguments != null)
372                         syntax_error (lexer.Location, "namespace name expected");
373
374                 current_namespace = new NamespaceEntry (
375                         current_namespace, file, name.GetName (), lexer.Location);
376           } 
377           namespace_body opt_semicolon
378           { 
379                 current_namespace = current_namespace.Parent;
380           }
381         ;
382
383 opt_semicolon
384         : /* empty */
385         | SEMICOLON
386         ;
387
388 opt_comma
389         : /* empty */
390         | COMMA
391         ;
392
393 namespace_name
394         : namespace_or_type_name {
395                 MemberName name = (MemberName) $1;
396
397                 if (name.TypeArguments != null)
398                         syntax_error (lexer.Location, "namespace name expected");
399
400                 $$ = name;
401           }
402         ;
403
404 namespace_body
405         : OPEN_BRACE
406           {
407                 if (RootContext.Documentation != null)
408                         Lexer.doc_state = XmlCommentState.Allowed;
409           }
410           opt_using_directives
411           opt_namespace_member_declarations
412           CLOSE_BRACE
413         ;
414
415 opt_using_directives
416         : /* empty */
417         | using_directives
418         ;
419
420 opt_namespace_member_declarations
421         : /* empty */
422         | namespace_member_declarations
423         ;
424
425 namespace_member_declarations
426         : namespace_member_declaration
427         | namespace_member_declarations namespace_member_declaration
428         ;
429
430 namespace_member_declaration
431         : type_declaration
432           {
433                 if ($1 != null) {
434                         DeclSpace ds = (DeclSpace)$1;
435
436                         if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
437                                 Report.Error (1527, lexer.Location, 
438                                 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
439                         }
440                 }
441                 current_namespace.DeclarationFound = true;
442           }
443         | namespace_declaration {
444                 current_namespace.DeclarationFound = true;
445           }
446
447         | field_declaration {
448                 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
449           }
450         | method_declaration {
451                 Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
452           }
453         ;
454
455 type_declaration
456         : class_declaration             
457         | struct_declaration            
458         | interface_declaration         
459         | enum_declaration              
460         | delegate_declaration
461 //
462 // Enable this when we have handled all errors, because this acts as a generic fallback
463 //
464 //      | error {
465 //              Console.WriteLine ("Token=" + yyToken);
466 //              Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
467 //        }
468         ;
469
470 //
471 // Attributes 17.2
472 //
473
474 global_attributes
475         : attribute_sections
476 {
477         if ($1 != null)
478                 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
479
480         $$ = $1;
481 }
482
483 opt_attributes
484         : /* empty */ 
485           {
486                 global_attrs_enabled = false;
487                 $$ = null;
488       }
489         | attribute_sections
490           { 
491                 global_attrs_enabled = false;
492                 $$ = $1;
493           }
494     ;
495  
496
497 attribute_sections
498         : attribute_section
499           {
500                 ArrayList sect = (ArrayList) $1;
501
502                 if (global_attrs_enabled) {
503                         if (current_attr_target == "module") {
504                                 CodeGen.Module.AddAttributes (sect);
505                                 $$ = null;
506                         } else if (current_attr_target == "assembly") {
507                                 CodeGen.Assembly.AddAttributes (sect);
508                                 $$ = null;
509                         } else {
510                                 $$ = new Attributes (sect);
511                         }
512                         if ($$ == null) {
513                                 if (RootContext.Documentation != null) {
514                                         Lexer.check_incorrect_doc_comment ();
515                                         Lexer.doc_state =
516                                                 XmlCommentState.Allowed;
517                                 }
518                         }
519                 } else {
520                         $$ = new Attributes (sect);
521                 }               
522                 current_attr_target = null;
523       }
524         | attribute_sections attribute_section
525           {
526                 Attributes attrs = $1 as Attributes;
527                 ArrayList sect = (ArrayList) $2;
528
529                 if (global_attrs_enabled) {
530                         if (current_attr_target == "module") {
531                                 CodeGen.Module.AddAttributes (sect);
532                                 $$ = null;
533                         } else if (current_attr_target == "assembly") {
534                                 CodeGen.Assembly.AddAttributes (sect);
535                                 $$ = null;
536                         } else {
537                                 if (attrs == null)
538                                         attrs = new Attributes (sect);
539                                 else
540                                         attrs.AddAttributes (sect);                     
541                         }
542                 } else {
543                         if (attrs == null)
544                                 attrs = new Attributes (sect);
545                         else
546                                 attrs.AddAttributes (sect);
547                 }               
548                 $$ = attrs;
549                 current_attr_target = null;
550           }
551         ;
552
553 attribute_section
554         : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
555           {
556                 $$ = $3;
557           }
558         | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
559           {
560                 $$ = $2;
561           }
562         ;
563  
564 attribute_target_specifier
565         : attribute_target COLON
566           {
567                 current_attr_target = (string)$1;
568                 $$ = $1;
569           }
570         ;
571
572 attribute_target
573         : IDENTIFIER
574           {
575                 CheckAttributeTarget ((string) $1);
576                 $$ = $1;
577           }
578         | EVENT  { $$ = "event"; }        
579         | RETURN { $$ = "return"; }
580         ;
581
582 attribute_list
583         : attribute
584           {
585                 ArrayList attrs = new ArrayList (4);
586                 attrs.Add ($1);
587
588                 $$ = attrs;
589                
590           }
591         | attribute_list COMMA attribute
592           {
593                 ArrayList attrs = (ArrayList) $1;
594                 attrs.Add ($3);
595
596                 $$ = attrs;
597           }
598         ;
599
600 attribute
601         : attribute_name
602           {
603                 $$ = lexer.Location;
604           }
605           opt_attribute_arguments
606           {
607                 Location loc = (Location) $2;
608                 MemberName mname = (MemberName) $1;
609                 if (mname.IsGeneric) {
610                         Report.Error (404, lexer.Location,
611                                       "'<' unexpected: attributes cannot be generic");
612                 }
613
614                 MemberName left = mname.Left;
615                 string identifier = mname.Name;
616
617                 Expression left_expr = left == null ? null : left.GetTypeExpression (loc);
618
619                 if (current_attr_target == "assembly" || current_attr_target == "module")
620                         $$ = new GlobalAttribute (current_class, current_attr_target,
621                                                   left_expr, identifier, (ArrayList) $3, loc);
622                 else
623                         $$ = new Attribute (current_attr_target, left_expr, identifier, (ArrayList) $3, loc);
624           }
625         ;
626
627 attribute_name
628         : namespace_or_type_name  { /* reserved attribute name or identifier: 17.4 */ }
629         ;
630
631 opt_attribute_arguments
632         : /* empty */   { $$ = null; }
633         | OPEN_PARENS attribute_arguments CLOSE_PARENS
634           {
635                 $$ = $2;
636           }
637         ;
638
639
640 attribute_arguments
641         : opt_positional_argument_list
642           {
643                 if ($1 == null)
644                         $$ = null;
645                 else {
646                         ArrayList args = new ArrayList (4);
647                         args.Add ($1);
648                 
649                         $$ = args;
650                 }
651           }
652         | positional_argument_list COMMA named_argument_list
653           {
654                 ArrayList args = new ArrayList (4);
655                 args.Add ($1);
656                 args.Add ($3);
657
658                 $$ = args;
659           }
660         | named_argument_list
661           {
662                 ArrayList args = new ArrayList (4);
663                 args.Add (null);
664                 args.Add ($1);
665                 
666                 $$ = args;
667           }
668         ;
669
670
671 opt_positional_argument_list
672         : /* empty */           { $$ = null; } 
673         | positional_argument_list
674         ;
675
676 positional_argument_list
677         : expression
678           {
679                 ArrayList args = new ArrayList (4);
680                 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
681
682                 $$ = args;
683           }
684         | positional_argument_list COMMA expression
685          {
686                 ArrayList args = (ArrayList) $1;
687                 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
688
689                 $$ = args;
690          }
691         ;
692
693 named_argument_list
694         : named_argument
695           {
696                 ArrayList args = new ArrayList (4);
697                 args.Add ($1);
698
699                 $$ = args;
700           }
701         | named_argument_list COMMA named_argument
702           {       
703                 ArrayList args = (ArrayList) $1;
704                 args.Add ($3);
705
706                 $$ = args;
707           }
708           | named_argument_list COMMA expression
709             {
710                   Report.Error (1016, lexer.Location, "Named attribute argument expected");
711                   $$ = null;
712                 }
713         ;
714
715 named_argument
716         : IDENTIFIER ASSIGN expression
717           {
718                 $$ = new DictionaryEntry (
719                         (string) $1, 
720                         new Argument ((Expression) $3, Argument.AType.Expression));
721           }
722         ;
723
724                   
725 class_body
726         :  OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
727         ;
728
729 opt_class_member_declarations
730         : /* empty */
731         | class_member_declarations
732         ;
733
734 class_member_declarations
735         : class_member_declaration
736         | class_member_declarations 
737           class_member_declaration
738         ;
739
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
750         | type_declaration
751         ;
752
753 struct_declaration
754         : opt_attributes
755           opt_modifiers
756           opt_partial
757           STRUCT
758           {
759                 lexer.ConstraintsParsing = true;
760           }
761           member_name
762           { 
763                 MemberName name = MakeName ((MemberName) $6);
764                 bool partial = (bool) $3;
765
766                 if (partial) {
767                         ClassPart part = PartialContainer.CreatePart (
768                                 current_namespace, current_class, name, (int) $2,
769                                 (Attributes) $1, Kind.Struct, lexer.Location);
770
771                         current_container = part.PartialContainer;
772                         current_class = part;
773                 } else {
774                         current_class = new Struct (
775                                 current_namespace, current_class, name, (int) $2,
776                                 (Attributes) $1, lexer.Location);
777
778                         current_container.AddClassOrStruct (current_class);
779                         current_container = current_class;
780                         RootContext.Tree.RecordDecl (name, current_class);
781                 }
782           }
783           opt_class_base
784           opt_type_parameter_constraints_clauses
785           {
786                 lexer.ConstraintsParsing = false;
787
788                 if ($8 != null)
789                         current_class.Bases = (ArrayList) $8;
790
791                 current_class.SetParameterInfo ((ArrayList) $9);
792
793                 if (RootContext.Documentation != null)
794                         current_class.DocComment = Lexer.consume_doc_comment ();
795           }
796           struct_body
797           {
798                 if (RootContext.Documentation != null)
799                         Lexer.doc_state = XmlCommentState.Allowed;
800           }
801           opt_semicolon
802           {
803                 $$ = pop_current_class ();
804           }
805         | opt_attributes opt_modifiers opt_partial STRUCT error {
806                 CheckIdentifierToken (yyToken);
807           }
808         ;
809
810 struct_body
811         : OPEN_BRACE
812           {
813                 if (RootContext.Documentation != null)
814                         Lexer.doc_state = XmlCommentState.Allowed;
815           }
816           opt_struct_member_declarations CLOSE_BRACE
817         ;
818
819 opt_struct_member_declarations
820         : /* empty */
821         | struct_member_declarations
822         ;
823
824 struct_member_declarations
825         : struct_member_declaration
826         | struct_member_declarations struct_member_declaration
827         ;
828
829 struct_member_declaration
830         : constant_declaration
831         | field_declaration
832         | method_declaration
833         | property_declaration
834         | event_declaration
835         | indexer_declaration
836         | operator_declaration
837         | constructor_declaration
838         | type_declaration
839
840         /*
841          * This is only included so we can flag error 575: 
842          * destructors only allowed on class types
843          */
844         | destructor_declaration 
845         ;
846
847 constant_declaration
848         : opt_attributes 
849           opt_modifiers
850           CONST
851           type
852           constant_declarators
853           SEMICOLON
854           {
855                 int modflags = (int) $2;
856                 foreach (VariableDeclaration constant in (ArrayList) $5){
857                         Location l = constant.Location;
858                         if ((modflags & Modifiers.STATIC) != 0) {
859                                 Report.Error (504, l, "The constant '{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
860                                 continue;
861                         }
862
863                         Const c = new Const (
864                                 current_class, (Expression) $4, (string) constant.identifier, 
865                                 (Expression) constant.expression_or_array_initializer, modflags, 
866                                 (Attributes) $1, l);
867
868                         if (RootContext.Documentation != null) {
869                                 c.DocComment = Lexer.consume_doc_comment ();
870                                 Lexer.doc_state = XmlCommentState.Allowed;
871                         }
872                         current_container.AddConstant (c);
873                 }
874           }
875         ;
876
877 constant_declarators
878         : constant_declarator 
879           {
880                 ArrayList constants = new ArrayList (4);
881                 if ($1 != null)
882                         constants.Add ($1);
883                 $$ = constants;
884           }
885         | constant_declarators COMMA constant_declarator
886           {
887                 if ($3 != null) {
888                         ArrayList constants = (ArrayList) $1;
889                         constants.Add ($3);
890                 }
891           }
892         ;
893
894 constant_declarator
895         : IDENTIFIER ASSIGN constant_expression
896           {
897                 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
898           }
899         | IDENTIFIER
900           {
901                 // A const field requires a value to be provided
902                 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
903                 $$ = null;
904           }
905         ;
906
907 field_declaration
908         : opt_attributes
909           opt_modifiers
910           type 
911           variable_declarators
912           SEMICOLON
913           { 
914                 Expression type = (Expression) $3;
915                 int mod = (int) $2;
916
917                 foreach (VariableDeclaration var in (ArrayList) $4){
918                         Field field = new Field (current_class, type, mod, var.identifier, 
919                                                  var.expression_or_array_initializer, 
920                                                  (Attributes) $1, var.Location);
921
922                         if (RootContext.Documentation != null) {
923                                 field.DocComment = Lexer.consume_doc_comment ();
924                                 Lexer.doc_state = XmlCommentState.Allowed;
925                         }
926                         current_container.AddField (field);
927                 }
928           }
929         | opt_attributes
930           opt_modifiers
931           FIXED
932           type 
933           fixed_variable_declarators
934           SEMICOLON
935           { 
936                         Expression type = (Expression) $4;
937                         int mod = (int) $2;
938
939                         foreach (VariableDeclaration var in (ArrayList) $5) {
940                                 FixedField field = new FixedField (current_class, type, mod, var.identifier,
941                                         (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
942
943                                 if (RootContext.Documentation != null) {
944                                         field.DocComment = Lexer.consume_doc_comment ();
945                                         Lexer.doc_state = XmlCommentState.Allowed;
946                                 }
947                                 current_container.AddField (field);
948                         }
949           }
950         | opt_attributes
951           opt_modifiers
952           VOID  
953           variable_declarators
954           SEMICOLON {
955                 Report.Error (670, lexer.Location, "void type is not allowed for fields");
956           }
957         ;
958
959 fixed_variable_declarators
960         : fixed_variable_declarator
961                 {
962                         ArrayList decl = new ArrayList (2);
963                         decl.Add ($1);
964                         $$ = decl;
965                 }
966         | fixed_variable_declarators COMMA fixed_variable_declarator
967                 {
968                         ArrayList decls = (ArrayList) $1;
969                         decls.Add ($3);
970                         $$ = $1;
971                 }
972         ;
973
974 fixed_variable_declarator
975         : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
976                 {
977                         $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
978                 }
979         ;
980
981 variable_declarators
982         : variable_declarator 
983           {
984                 ArrayList decl = new ArrayList (4);
985                 if ($1 != null)
986                         decl.Add ($1);
987                 $$ = decl;
988           }
989         | variable_declarators COMMA variable_declarator
990           {
991                 ArrayList decls = (ArrayList) $1;
992                 decls.Add ($3);
993                 $$ = $1;
994           }
995         ;
996
997 variable_declarator
998         : IDENTIFIER ASSIGN variable_initializer
999           {
1000                 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
1001           }
1002         | IDENTIFIER
1003           {
1004                 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
1005           }
1006         | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1007           {
1008                 Report.Error (650, lexer.Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1009                         "To declare a fixed size buffer field, use the fixed keyword before the field type");
1010                 $$ = null;
1011           }
1012         ;
1013
1014 variable_initializer
1015         : expression
1016           {
1017                 $$ = $1;
1018           }
1019         | array_initializer
1020           {
1021                 $$ = $1;
1022           }
1023         | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1024           {
1025                 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
1026           }
1027         | STACKALLOC type
1028           {
1029                 Report.Error (1575, lexer.Location, "A stackalloc expression requires [] after type");
1030                 $$ = null;
1031           }
1032         ;
1033
1034 method_declaration
1035         : method_header {
1036                 iterator_container = (IIteratorContainer) $1;
1037                 if (RootContext.Documentation != null)
1038                         Lexer.doc_state = XmlCommentState.NotAllowed;
1039           }
1040           method_body
1041           {
1042                 Method method = (Method) $1;
1043                 Block b = (Block) $3;
1044                 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
1045
1046                 if (b == null){
1047                         if ((method.ModFlags & extern_abstract) == 0){
1048                                 Report.Error (
1049                                         501, lexer.Location,  current_container.MakeName (method.Name) +
1050                                         "must declare a body because it is not marked abstract or extern");
1051                         }
1052                 } else {
1053                         if ((method.ModFlags & Modifiers.EXTERN) != 0){
1054                                 Report.Error (
1055                                         179, lexer.Location, current_container.MakeName (method.Name) +
1056                                         " is declared extern, but has a body");
1057                         }
1058                 }
1059
1060                 method.Block = (ToplevelBlock) $3;
1061                 current_container.AddMethod (method);
1062
1063                 current_local_parameters = null;
1064                 iterator_container = null;
1065
1066                 if (RootContext.Documentation != null)
1067                         Lexer.doc_state = XmlCommentState.Allowed;
1068           }
1069         ;
1070
1071 method_header
1072         : opt_attributes
1073           opt_modifiers
1074           type namespace_or_type_name
1075           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
1076           {
1077                 lexer.ConstraintsParsing = true;
1078           }
1079           opt_type_parameter_constraints_clauses
1080           {
1081                 lexer.ConstraintsParsing = false;
1082
1083                 MemberName name = (MemberName) $4;
1084
1085                 if ($9 != null && name.TypeArguments == null)
1086                         Report.Error (80, lexer.Location,
1087                                       "Contraints are not allowed on non-generic declarations");
1088
1089                 Method method;
1090
1091                 GenericMethod generic = null;
1092                 if (name.TypeArguments != null) {
1093                         generic = new GenericMethod (current_namespace, current_class,
1094                                                      name, lexer.Location);
1095
1096                         generic.SetParameterInfo ((ArrayList) $9);
1097                 }
1098
1099                 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1100                                      name, (Parameters) $6, (Attributes) $1, lexer.Location);
1101
1102                 current_local_parameters = (Parameters) $6;
1103
1104                 if (RootContext.Documentation != null)
1105                         method.DocComment = Lexer.consume_doc_comment ();
1106
1107                 $$ = method;
1108           }
1109         | opt_attributes
1110           opt_modifiers
1111           VOID namespace_or_type_name
1112           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
1113           {
1114                 lexer.ConstraintsParsing = true;
1115           }
1116           opt_type_parameter_constraints_clauses
1117           {
1118                 lexer.ConstraintsParsing = false;
1119
1120                 MemberName name = (MemberName) $4;
1121
1122                 if ($9 != null && name.TypeArguments == null)
1123                         Report.Error (80, lexer.Location,
1124                                       "Contraints are not allowed on non-generic declarations");
1125
1126                 Method method;
1127                 GenericMethod generic = null;
1128                 if (name.TypeArguments != null) {
1129                         generic = new GenericMethod (current_namespace, current_class,
1130                                                      name, lexer.Location);
1131
1132                         generic.SetParameterInfo ((ArrayList) $9);
1133                 }
1134
1135                 method = new Method (current_class, generic, TypeManager.system_void_expr,
1136                                      (int) $2, false, name, (Parameters) $6, (Attributes) $1,
1137                                      lexer.Location);
1138
1139                 current_local_parameters = (Parameters) $6;
1140
1141                 if (RootContext.Documentation != null)
1142                         method.DocComment = Lexer.consume_doc_comment ();
1143
1144                 $$ = method;
1145           }
1146         | opt_attributes
1147           opt_modifiers
1148           type 
1149           modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1150           {
1151                 Report.Error (1585, lexer.Location, 
1152                         String.Format ("Modifier {0} should appear before type", 
1153                                 Modifiers.Name ((int) $4)));
1154                 MemberName name = (MemberName) $4;
1155
1156                 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1157                                             0, false, name, (Parameters) $6, (Attributes) $1,
1158                                             lexer.Location);
1159
1160                 current_local_parameters = (Parameters) $6;
1161
1162                 if (RootContext.Documentation != null)
1163                         method.DocComment = Lexer.consume_doc_comment ();
1164
1165                 $$ = method;
1166           }
1167         ;
1168
1169 method_body
1170         : block
1171         | SEMICOLON             { $$ = null; }
1172         ;
1173
1174 opt_formal_parameter_list
1175         : /* empty */                   { $$ = Parameters.EmptyReadOnlyParameters; }
1176         | formal_parameter_list
1177         ;
1178
1179 formal_parameter_list
1180         : fixed_parameters              
1181           { 
1182                 ArrayList pars_list = (ArrayList) $1;
1183
1184                 Parameter [] pars = new Parameter [pars_list.Count];
1185                 pars_list.CopyTo (pars);
1186
1187                 $$ = new Parameters (pars, null, lexer.Location); 
1188           } 
1189         | fixed_parameters COMMA parameter_array
1190           {
1191                 ArrayList pars_list = (ArrayList) $1;
1192
1193                 Parameter [] pars = new Parameter [pars_list.Count];
1194                 pars_list.CopyTo (pars);
1195
1196                 $$ = new Parameters (pars, (Parameter) $3, lexer.Location); 
1197           }
1198         | fixed_parameters COMMA ARGLIST
1199           {
1200                 ArrayList pars_list = (ArrayList) $1;
1201
1202                 Parameter [] pars = new Parameter [pars_list.Count];
1203                 pars_list.CopyTo (pars);
1204
1205                 $$ = new Parameters (pars, true, lexer.Location);
1206           }
1207         | parameter_array COMMA fixed_parameters
1208           {
1209                 Report.Error (231, lexer.Location, "A params parameter must be the last parameter in a formal parameter list");
1210                 $$ = null;
1211           }
1212         | ARGLIST COMMA fixed_parameters
1213           {
1214                 Report.Error (257, lexer.Location, "An __arglist parameter must be the last parameter in a formal parameter list");
1215                 $$ = null;
1216           }
1217         | parameter_array 
1218           {
1219                 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
1220           }
1221         | ARGLIST
1222           {
1223                 $$ = new Parameters (null, true, lexer.Location);
1224           }
1225         ;
1226
1227 fixed_parameters
1228         : fixed_parameter       
1229           {
1230                 ArrayList pars = new ArrayList (4);
1231
1232                 pars.Add ($1);
1233                 $$ = pars;
1234           }
1235         | fixed_parameters COMMA fixed_parameter
1236           {
1237                 ArrayList pars = (ArrayList) $1;
1238
1239                 pars.Add ($3);
1240                 $$ = $1;
1241           }
1242         ;
1243
1244 fixed_parameter
1245         : opt_attributes
1246           opt_parameter_modifier
1247           type
1248           IDENTIFIER
1249           {
1250                 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
1251           }
1252         | opt_attributes
1253           opt_parameter_modifier
1254           type
1255           IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1256           {
1257                 Report.Error (1552, lexer.Location, "Array type specifier, [], must appear before parameter name");
1258                 $$ = null;
1259           }
1260         | opt_attributes
1261           opt_parameter_modifier
1262           type
1263           {
1264                 Report.Error (1001, lexer.Location, "Identifier expected");
1265                 $$ = null;
1266           }
1267         | opt_attributes
1268           opt_parameter_modifier
1269           type
1270           error {
1271                 CheckIdentifierToken (yyToken);
1272                 $$ = null;
1273           }
1274         | opt_attributes
1275           opt_parameter_modifier
1276           type
1277           IDENTIFIER
1278           ASSIGN
1279           constant_expression
1280            {
1281                  Report.Error (241, lexer.Location, "Default parameter specifiers are not permitted");
1282                  $$ = null;
1283            }
1284         ;
1285
1286 opt_parameter_modifier
1287         : /* empty */           { $$ = Parameter.Modifier.NONE; }
1288         | parameter_modifier
1289         ;
1290
1291 parameter_modifier
1292         : REF                   { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
1293         | OUT                   { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
1294         ;
1295
1296 parameter_array
1297         : opt_attributes PARAMS type IDENTIFIER
1298           { 
1299                 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
1300                 note ("type must be a single-dimension array type"); 
1301           }
1302         | opt_attributes PARAMS parameter_modifier type IDENTIFIER 
1303           {
1304                 Report.Error (1611, lexer.Location, "The params parameter cannot be declared as ref or out");
1305                 $$ = null;
1306           }
1307         | opt_attributes PARAMS type error {
1308                 CheckIdentifierToken (yyToken);
1309                 $$ = null;
1310           }
1311         ;
1312
1313 property_declaration
1314         : opt_attributes
1315           opt_modifiers
1316           type
1317           namespace_or_type_name
1318           {
1319                 if (RootContext.Documentation != null)
1320                         tmpComment = Lexer.consume_doc_comment ();
1321           }
1322           OPEN_BRACE 
1323           {
1324                 implicit_value_parameter_type = (Expression) $3;
1325
1326                 lexer.PropertyParsing = true;
1327
1328                 $$ = lexer.Location;
1329
1330                 iterator_container = SimpleIteratorContainer.GetSimple ();
1331           }
1332           accessor_declarations 
1333           {
1334                 lexer.PropertyParsing = false;
1335                 has_get = has_set = false;
1336           }
1337           CLOSE_BRACE
1338           { 
1339                 if ($8 == null)
1340                         break;
1341
1342                 Property prop;
1343                 Pair pair = (Pair) $8;
1344                 Accessor get_block = (Accessor) pair.First;
1345                 Accessor set_block = (Accessor) pair.Second;
1346
1347                 Location loc = (Location) $7;
1348                 MemberName name = (MemberName) $4;
1349
1350                 if (name.TypeArguments != null)
1351                         syntax_error (lexer.Location, "a property can't have type arguments");
1352
1353                 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1354                                      name, (Attributes) $1, get_block, set_block, loc);
1355                 if (SimpleIteratorContainer.Simple.Yields)
1356                         prop.SetYields ();
1357                 
1358                 current_container.AddProperty (prop);
1359                 implicit_value_parameter_type = null;
1360                 iterator_container = null;
1361
1362                 if (RootContext.Documentation != null)
1363                         prop.DocComment = ConsumeStoredComment ();
1364
1365           }
1366         ;
1367
1368 accessor_declarations
1369         : get_accessor_declaration
1370          {
1371                 $$ = new Pair ($1, null);
1372          }
1373         | get_accessor_declaration accessor_declarations
1374          { 
1375                 Pair pair = (Pair) $2;
1376                 pair.First = $1;
1377                 $$ = pair;
1378          }
1379         | set_accessor_declaration
1380          {
1381                 $$ = new Pair (null, $1);
1382          }
1383         | set_accessor_declaration accessor_declarations
1384          { 
1385                 Pair pair = (Pair) $2;
1386                 pair.Second = $1;
1387                 $$ = pair;
1388          }
1389         | error
1390           {
1391                 Report.Error (1014, lexer.Location, "A get or set accessor expected");
1392                 $$ = null;
1393           }
1394         ;
1395
1396 get_accessor_declaration
1397         : opt_attributes opt_modifiers GET
1398           {
1399                 // If this is not the case, then current_local_parameters has already
1400                 // been set in indexer_declaration
1401                 if (parsing_indexer == false)
1402                         current_local_parameters = null;
1403                 else 
1404                         current_local_parameters = indexer_parameters;
1405                 lexer.PropertyParsing = false;
1406           }
1407           accessor_body
1408           {
1409                 if (has_get) {
1410                         Report.Error (1007, lexer.Location, "Property accessor already defined");
1411                         break;
1412                 }
1413                 $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
1414                 has_get = true;
1415                 current_local_parameters = null;
1416                 lexer.PropertyParsing = true;
1417
1418                 if (RootContext.Documentation != null)
1419                         if (Lexer.doc_state == XmlCommentState.Error)
1420                                 Lexer.doc_state = XmlCommentState.NotAllowed;
1421           }
1422         ;
1423
1424 set_accessor_declaration
1425         : opt_attributes opt_modifiers SET 
1426           {
1427                 Parameter [] args;
1428                 Parameter implicit_value_parameter = new Parameter (
1429                         implicit_value_parameter_type, "value", 
1430                         Parameter.Modifier.NONE, null);
1431
1432                 if (parsing_indexer == false) {
1433                         args  = new Parameter [1];
1434                         args [0] = implicit_value_parameter;
1435                         current_local_parameters = new Parameters (args, null, lexer.Location);
1436                 } else {
1437                         Parameter [] fpars = indexer_parameters.FixedParameters;
1438
1439                         if (fpars != null){
1440                                 int count = fpars.Length;
1441
1442                                 args = new Parameter [count + 1];
1443                                 fpars.CopyTo (args, 0);
1444                                 args [count] = implicit_value_parameter;
1445                         } else 
1446                                 args = null;
1447                         current_local_parameters = new Parameters (
1448                                 args, indexer_parameters.ArrayParameter, lexer.Location);
1449                 }
1450                 
1451                 lexer.PropertyParsing = false;
1452           }
1453           accessor_body
1454           {
1455                 if (has_set) {
1456                         Report.Error (1007, lexer.Location, "Property accessor already defined");
1457                         break;
1458                 }
1459                 $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
1460                 has_set = true;
1461                 current_local_parameters = null;
1462                 lexer.PropertyParsing = true;
1463
1464                 if (RootContext.Documentation != null
1465                         && Lexer.doc_state == XmlCommentState.Error)
1466                         Lexer.doc_state = XmlCommentState.NotAllowed;
1467           }
1468         ;
1469
1470 accessor_body
1471         : block 
1472         | SEMICOLON             { $$ = null; }
1473         ;
1474
1475 interface_declaration
1476         : opt_attributes
1477           opt_modifiers
1478           opt_partial
1479           INTERFACE
1480           {
1481                 lexer.ConstraintsParsing = true;
1482           }
1483           member_name
1484           {
1485                 MemberName name = MakeName ((MemberName) $6);
1486                 bool partial = (bool) $3;
1487
1488                 if (partial) {
1489                         ClassPart part = PartialContainer.CreatePart (
1490                                 current_namespace, current_class, name, (int) $2,
1491                                 (Attributes) $1, Kind.Interface, lexer.Location);
1492
1493                         current_container = part.PartialContainer;
1494                         current_class = part;
1495                 } else {
1496                         current_class = new Interface (
1497                                 current_namespace, current_class, name, (int) $2,
1498                                 (Attributes) $1, lexer.Location);
1499
1500                         current_container.AddInterface (current_class);
1501                         current_container = current_class;
1502                         RootContext.Tree.RecordDecl (name, current_class);
1503                 }
1504           }
1505           opt_class_base
1506           opt_type_parameter_constraints_clauses
1507           {
1508                 lexer.ConstraintsParsing = false;
1509
1510                 if ($8 != null)
1511                         current_class.Bases = (ArrayList) $8;
1512
1513                 current_class.SetParameterInfo ((ArrayList) $9);
1514
1515                 if (RootContext.Documentation != null) {
1516                         current_class.DocComment = Lexer.consume_doc_comment ();
1517                         Lexer.doc_state = XmlCommentState.Allowed;
1518                 }
1519           }
1520           interface_body
1521           { 
1522                 if (RootContext.Documentation != null)
1523                         Lexer.doc_state = XmlCommentState.Allowed;
1524           }
1525           opt_semicolon 
1526           {
1527                 $$ = pop_current_class ();
1528           }
1529         | opt_attributes opt_modifiers opt_partial INTERFACE error {
1530                 CheckIdentifierToken (yyToken);
1531           }
1532         ;
1533
1534 interface_body
1535         : OPEN_BRACE
1536           opt_interface_member_declarations
1537           CLOSE_BRACE
1538         ;
1539
1540 opt_interface_member_declarations
1541         : /* empty */
1542         | interface_member_declarations
1543         ;
1544
1545 interface_member_declarations
1546         : interface_member_declaration
1547         | interface_member_declarations interface_member_declaration
1548         ;
1549
1550 interface_member_declaration
1551         : interface_method_declaration          
1552           { 
1553                 if ($1 == null)
1554                         break;
1555
1556                 Method m = (Method) $1;
1557
1558                 if (m.IsExplicitImpl)
1559                         Report.Error (541, lexer.Location, 
1560                                 "Explicit interface declaration can only be declared in a class or struct");
1561
1562                 current_container.AddMethod (m);
1563
1564                 if (RootContext.Documentation != null)
1565                         Lexer.doc_state = XmlCommentState.Allowed;
1566           }
1567         | interface_property_declaration        
1568           { 
1569                 if ($1 == null)
1570                         break;
1571
1572                 Property p = (Property) $1;
1573
1574                 if (p.IsExplicitImpl)
1575                         Report.Error (541, lexer.Location, 
1576                                 "Explicit interface declaration can only be declared in a class or struct");
1577
1578                 current_container.AddProperty (p);
1579
1580                 if (RootContext.Documentation != null)
1581                         Lexer.doc_state = XmlCommentState.Allowed;
1582           }
1583         | interface_event_declaration 
1584           { 
1585                 if ($1 != null){
1586                         Event e = (Event) $1;
1587
1588                         if (e.IsExplicitImpl)
1589                                 Report.Error (541, lexer.Location, 
1590                                     "Explicit interface declaration can only be declared in a class or struct");
1591                         
1592                         current_container.AddEvent (e);
1593                 }
1594
1595                 if (RootContext.Documentation != null)
1596                         Lexer.doc_state = XmlCommentState.Allowed;
1597           }
1598         | interface_indexer_declaration
1599           { 
1600                 if ($1 == null)
1601                         break;
1602
1603                 Indexer i = (Indexer) $1;
1604
1605                 if (i.IsExplicitImpl)
1606                         Report.Error (541, lexer.Location, 
1607                                 "Explicit interface declaration can only be declared in a class or struct");
1608
1609                 current_container.AddIndexer (i);
1610
1611                 if (RootContext.Documentation != null)
1612                         Lexer.doc_state = XmlCommentState.Allowed;
1613           }
1614         | delegate_declaration
1615           {
1616                 Report.Error (524, lexer.Location, "Interfaces can not declare delegates");
1617           }
1618         | class_declaration
1619           {
1620                 Report.Error (524, lexer.Location, "Interfaces can not declare classes");
1621           }
1622         | struct_declaration
1623           {
1624                 Report.Error (524, lexer.Location, "Interfaces can not declare structures");
1625           }
1626         | enum_declaration 
1627           {
1628                 Report.Error (524, lexer.Location, "Interfaces can not declare enumerations");
1629           }
1630         | interface_declaration 
1631           {
1632                 Report.Error (524, lexer.Location, "Interfaces can not declare interfaces");
1633           } 
1634         | constant_declaration
1635           {
1636                 Report.Error (525, lexer.Location, "Interfaces cannot contain constants");
1637           }
1638         ;
1639
1640 opt_new
1641         : opt_modifiers 
1642           {
1643                 int val = (int) $1;
1644                 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
1645                 $$ = val;
1646           }
1647         ;
1648
1649 interface_method_declaration
1650         : opt_attributes opt_new type namespace_or_type_name
1651           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1652           {
1653                 lexer.ConstraintsParsing = true;
1654           }
1655           opt_type_parameter_constraints_clauses
1656           SEMICOLON
1657           {
1658                 lexer.ConstraintsParsing = false;
1659
1660                 MemberName name = (MemberName) $4;
1661
1662                 if ($9 != null && name.TypeArguments == null)
1663                         Report.Error (80, lexer.Location,
1664                                       "Contraints are not allowed on non-generic declarations");
1665
1666                 GenericMethod generic = null;
1667                 if (name.TypeArguments != null) {
1668                         generic = new GenericMethod (current_namespace, current_class,
1669                                                      name, lexer.Location);
1670
1671                         generic.SetParameterInfo ((ArrayList) $9);
1672                 }
1673
1674                 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1675                                  (Parameters) $6, (Attributes) $1, lexer.Location);
1676                 if (RootContext.Documentation != null)
1677                         ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1678           }
1679         | opt_attributes opt_new VOID namespace_or_type_name
1680           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1681           {
1682                 lexer.ConstraintsParsing = true;
1683           }
1684           opt_type_parameter_constraints_clauses
1685           SEMICOLON
1686           {
1687                 lexer.ConstraintsParsing = false;
1688
1689                 MemberName name = (MemberName) $4;
1690
1691                 if ($9 != null && name.TypeArguments == null)
1692                         Report.Error (80, lexer.Location,
1693                                       "Contraints are not allowed on non-generic declarations");
1694
1695                 GenericMethod generic = null;
1696                 if (name.TypeArguments != null) {
1697                         generic = new GenericMethod (current_namespace, current_class,
1698                                                      name, lexer.Location);
1699
1700                         generic.SetParameterInfo ((ArrayList) $9);
1701                 }
1702
1703                 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1704                                  true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
1705                 if (RootContext.Documentation != null)
1706                         ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1707           }
1708         | opt_attributes opt_new type namespace_or_type_name
1709           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1710           {
1711                 lexer.ConstraintsParsing = true;
1712           }
1713           opt_type_parameter_constraints_clauses
1714           OPEN_BRACE opt_statement_list CLOSE_BRACE
1715           {
1716                 lexer.ConstraintsParsing = false;
1717                 Report.Error (531, lexer.Location, "'{0}': interface members cannot have a definition", $4);
1718                 $$ = null;
1719           }
1720
1721         ;
1722
1723 interface_property_declaration
1724         : opt_attributes
1725           opt_new
1726           type IDENTIFIER 
1727           OPEN_BRACE 
1728           { lexer.PropertyParsing = true; }
1729           interface_accessors 
1730           { lexer.PropertyParsing = false; }
1731           CLOSE_BRACE
1732           {
1733                 if ($3 == TypeManager.system_void_expr) {
1734                         Report.Error (547, lexer.Location, "'{0}': property cannot have void type", $4);
1735                         break;
1736                 }
1737
1738                 if ($7 == null)
1739                         break;
1740
1741                 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
1742
1743                 $$ = new Property (current_class, (Expression) $3, (int) $2, true,
1744                                    new MemberName ((string) $4), (Attributes) $1,
1745                                    pinfo.Get, pinfo.Set, lexer.Location);
1746                 if (RootContext.Documentation != null)
1747                         ((Property) $$).DocComment = Lexer.consume_doc_comment ();
1748           }
1749         | opt_attributes
1750           opt_new
1751           type error {
1752                 CheckIdentifierToken (yyToken);
1753                 $$ = null;
1754           }
1755         ;
1756
1757 interface_accessors
1758         : opt_attributes opt_modifiers GET SEMICOLON    
1759         { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, (int) $2, 0, lexer.Location, lexer.Location); }
1760         | opt_attributes opt_modifiers GET OPEN_BRACE
1761          {  
1762                 Report.Error (531, lexer.Location, "'{0}': interface members cannot have a definition", ".get");
1763                 $$ = null;
1764          }
1765         | opt_attributes opt_modifiers SET SEMICOLON            
1766         { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1, 0, (int) $2, lexer.Location, lexer.Location); }
1767         | opt_attributes opt_modifiers GET SEMICOLON opt_attributes opt_modifiers SET SEMICOLON 
1768           { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $5, (int) $2, (int) $6, lexer.Location, lexer.Location); }
1769         | opt_attributes opt_modifiers SET SEMICOLON opt_attributes opt_modifiers GET SEMICOLON
1770           { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $5, (Attributes) $1, (int) $6, (int) $2, lexer.Location, lexer.Location); }
1771         |
1772           {
1773                 Report.Error (548, lexer.Location, "'{0}' : property or indexer must have at least one accessor", "");
1774           }
1775         ;
1776
1777 interface_event_declaration
1778         : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1779           {
1780                 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1781                                      new MemberName ((string) $5), null,
1782                                      (Attributes) $1, lexer.Location);
1783                 if (RootContext.Documentation != null)
1784                         ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1785           }
1786         | opt_attributes opt_new EVENT type error {
1787                 CheckIdentifierToken (yyToken);
1788                 $$ = null;
1789           }
1790         | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN  {
1791                 Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
1792                 $$ = null;
1793           }
1794         | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1795         {
1796                 lexer.EventParsing = true;
1797         }
1798         event_accessor_declarations
1799         {
1800                 lexer.EventParsing = false;
1801         }
1802         CLOSE_BRACE {
1803                 Report.Error (69, lexer.Location, "Event in interface cannot have add or remove accessors");
1804                 $$ = null;
1805           }
1806         ;
1807
1808 interface_indexer_declaration 
1809         : opt_attributes opt_new type THIS 
1810           OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1811           OPEN_BRACE 
1812           { lexer.PropertyParsing = true; }
1813           interface_accessors 
1814           { lexer.PropertyParsing = false; }
1815           CLOSE_BRACE
1816           {
1817                 if ($10 == null)
1818                         break;
1819
1820                 InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
1821
1822                 $$ = new Indexer (current_class, (Expression) $3,
1823                                   new MemberName (TypeContainer.DefaultIndexerName),
1824                                   (int) $2, true, (Parameters) $6, (Attributes) $1,
1825                                   info.Get, info.Set, lexer.Location);
1826                 if (RootContext.Documentation != null)
1827                         ((Indexer) $$).DocComment = ConsumeStoredComment ();
1828           }
1829         ;
1830
1831 operator_declaration
1832         : opt_attributes opt_modifiers operator_declarator 
1833           {
1834                 iterator_container = SimpleIteratorContainer.GetSimple ();
1835           }
1836           operator_body
1837           {
1838                 if ($3 == null)
1839                         break;
1840
1841                 OperatorDeclaration decl = (OperatorDeclaration) $3;
1842                 
1843                 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
1844
1845                 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null);
1846                 if (decl.arg2type != null)
1847                         param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null);
1848
1849                 Operator op = new Operator (
1850                         current_class, decl.optype, decl.ret_type, (int) $2, 
1851                         new Parameters (param_list, null, decl.location),
1852                         (ToplevelBlock) $5, (Attributes) $1, decl.location);
1853
1854                 if (RootContext.Documentation != null) {
1855                         op.DocComment = tmpComment;
1856                         Lexer.doc_state = XmlCommentState.Allowed;
1857                 }
1858
1859                 if (SimpleIteratorContainer.Simple.Yields)
1860                         op.SetYields ();
1861
1862                 // Note again, checking is done in semantic analysis
1863                 current_container.AddOperator (op);
1864
1865                 current_local_parameters = null;
1866                 iterator_container = null;
1867           }
1868         ;
1869
1870 operator_body 
1871         : block
1872         | SEMICOLON { $$ = null; }
1873         ; 
1874 operator_declarator
1875         : type OPERATOR overloadable_operator 
1876           OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1877         {
1878                 Operator.OpType op = (Operator.OpType) $3;
1879                 CheckUnaryOperator (op);
1880
1881                 if (op == Operator.OpType.Addition)
1882                         op = Operator.OpType.UnaryPlus;
1883
1884                 if (op == Operator.OpType.Subtraction)
1885                         op = Operator.OpType.UnaryNegation;
1886
1887                 Parameter [] pars = new Parameter [1];
1888                 Expression type = (Expression) $5;
1889
1890                 pars [0] = new Parameter (type, (string) $6, Parameter.Modifier.NONE, null);
1891
1892                 current_local_parameters = new Parameters (pars, null, lexer.Location);
1893
1894                 if (RootContext.Documentation != null) {
1895                         tmpComment = Lexer.consume_doc_comment ();
1896                         Lexer.doc_state = XmlCommentState.NotAllowed;
1897                 }
1898
1899                 $$ = new OperatorDeclaration (op, (Expression) $1, type, (string) $6,
1900                                               null, null, lexer.Location);
1901         }
1902         | type OPERATOR overloadable_operator
1903           OPEN_PARENS 
1904                 type IDENTIFIER COMMA
1905                 type IDENTIFIER 
1906           CLOSE_PARENS
1907         {
1908                 CheckBinaryOperator ((Operator.OpType) $3);
1909
1910                 Parameter [] pars = new Parameter [2];
1911
1912                 Expression typeL = (Expression) $5;
1913                 Expression typeR = (Expression) $8;
1914
1915                pars [0] = new Parameter (typeL, (string) $6, Parameter.Modifier.NONE, null);
1916                pars [1] = new Parameter (typeR, (string) $9, Parameter.Modifier.NONE, null);
1917
1918                current_local_parameters = new Parameters (pars, null, lexer.Location);
1919
1920                 if (RootContext.Documentation != null) {
1921                         tmpComment = Lexer.consume_doc_comment ();
1922                         Lexer.doc_state = XmlCommentState.NotAllowed;
1923                 }
1924                
1925                $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1, 
1926                                              typeL, (string) $6,
1927                                              typeR, (string) $9, lexer.Location);
1928         }
1929         | conversion_operator_declarator
1930         | type OPERATOR overloadable_operator
1931           OPEN_PARENS 
1932                 type IDENTIFIER COMMA
1933                 type IDENTIFIER COMMA
1934                 type IDENTIFIER
1935           CLOSE_PARENS
1936         {
1937                 Report.Error (1534, lexer.Location, "Overloaded binary operator '{0}' takes two parameters", $3);
1938                 $$ = null;
1939         }
1940         | type OPERATOR overloadable_operator 
1941           OPEN_PARENS CLOSE_PARENS
1942         {
1943                 Report.Error (1535, lexer.Location, "Overloaded unary operator '{0}' takes one parameter", $3);
1944                 $$ = null;
1945         }
1946         ;
1947
1948 overloadable_operator
1949 // Unary operators:
1950         : BANG   { $$ = Operator.OpType.LogicalNot; }
1951         | TILDE  { $$ = Operator.OpType.OnesComplement; }  
1952         | OP_INC { $$ = Operator.OpType.Increment; }
1953         | OP_DEC { $$ = Operator.OpType.Decrement; }
1954         | TRUE   { $$ = Operator.OpType.True; }
1955         | FALSE  { $$ = Operator.OpType.False; }
1956 // Unary and binary:
1957         | PLUS { $$ = Operator.OpType.Addition; }
1958         | MINUS { $$ = Operator.OpType.Subtraction; }
1959 // Binary:
1960         | STAR { $$ = Operator.OpType.Multiply; }
1961         | DIV {  $$ = Operator.OpType.Division; }
1962         | PERCENT { $$ = Operator.OpType.Modulus; }
1963         | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1964         | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1965         | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1966         | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1967         | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1968         | OP_EQ { $$ = Operator.OpType.Equality; }
1969         | OP_NE { $$ = Operator.OpType.Inequality; }
1970         | OP_GT { $$ = Operator.OpType.GreaterThan; }
1971         | OP_LT { $$ = Operator.OpType.LessThan; }
1972         | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1973         | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1974         ;
1975
1976 conversion_operator_declarator
1977         : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1978           {
1979                 Parameter [] pars = new Parameter [1];
1980
1981                 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1982
1983                 current_local_parameters = new Parameters (pars, null, lexer.Location);  
1984                   
1985                 if (RootContext.Documentation != null) {
1986                         tmpComment = Lexer.consume_doc_comment ();
1987                         Lexer.doc_state = XmlCommentState.NotAllowed;
1988                 }
1989
1990                 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1991                                               null, null, lexer.Location);
1992           }
1993         | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1994           {
1995                 Parameter [] pars = new Parameter [1];
1996
1997                 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1998
1999                 current_local_parameters = new Parameters (pars, null, lexer.Location);  
2000                   
2001                 if (RootContext.Documentation != null) {
2002                         tmpComment = Lexer.consume_doc_comment ();
2003                         Lexer.doc_state = XmlCommentState.NotAllowed;
2004                 }
2005
2006                 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
2007                                               null, null, lexer.Location);
2008           }
2009         | IMPLICIT error 
2010           {
2011                 syntax_error (lexer.Location, "'operator' expected");
2012           }
2013         | EXPLICIT error 
2014           {
2015                 syntax_error (lexer.Location, "'operator' expected");
2016           }
2017         ;
2018
2019 constructor_declaration
2020         : opt_attributes
2021           opt_modifiers
2022           constructor_declarator
2023           constructor_body
2024           { 
2025                 Constructor c = (Constructor) $3;
2026                 c.Block = (ToplevelBlock) $4;
2027                 c.OptAttributes = (Attributes) $1;
2028                 c.ModFlags = (int) $2;
2029         
2030                 if (RootContext.Documentation != null)
2031                         c.DocComment = ConsumeStoredComment ();
2032
2033                 if (c.Name == current_container.Basename){
2034                         if ((c.ModFlags & Modifiers.STATIC) != 0){
2035                                 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2036                                         Report.Error (
2037                                                 515, c.Location, String.Format (
2038                                                 "`{0}.{1}': static constructor can not have access modifiers",
2039                                                 c.Name, current_container.Name));
2040                                 }
2041         
2042                                 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);   
2043         
2044                                 if (c.Initializer != null){
2045                                         Report.Error (
2046                                                 514, c.Location, 
2047                                                 "Static constructors can not have an explicit this or base " +
2048                                                 "constructor invocations");
2049                                 }
2050         
2051                                 if (!c.Parameters.Empty){
2052                                         Report.Error (
2053                                                 132, c.Location, "Static constructors should not have parameters");
2054                                 }
2055                         } else {
2056                                 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2057                         }
2058                 } else {
2059                         // We let another layer check the validity of the constructor.
2060                         //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2061                 }
2062
2063                 current_container.AddConstructor (c);
2064
2065                 current_local_parameters = null;
2066                 if (RootContext.Documentation != null)
2067                         Lexer.doc_state = XmlCommentState.Allowed;
2068           }
2069         ;
2070
2071 constructor_declarator
2072         : IDENTIFIER
2073           {
2074                 if (RootContext.Documentation != null) {
2075                         tmpComment = Lexer.consume_doc_comment ();
2076                         Lexer.doc_state = XmlCommentState.Allowed;
2077                 }
2078           }
2079           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS _mark_
2080           {
2081                 current_local_parameters = (Parameters) $4;
2082           }
2083           opt_constructor_initializer
2084           {
2085                 $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $4,
2086                                       (ConstructorInitializer) $8, (Location) $6);
2087           }
2088         ;
2089
2090 constructor_body
2091         : block
2092         | SEMICOLON             { $$ = null; }
2093         ;
2094
2095 opt_constructor_initializer
2096         : /* empty */                   { $$ = null; }
2097         | constructor_initializer
2098         ;
2099
2100 constructor_initializer
2101         : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
2102           {
2103                 $$ = new ConstructorBaseInitializer ((ArrayList) $4, lexer.Location);
2104           }
2105         | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
2106           {
2107                 $$ = new ConstructorThisInitializer ((ArrayList) $4, lexer.Location);
2108           }
2109         | COLON error {
2110                 Report.Error (1018, lexer.Location, "Keyword this or base expected");
2111                 $$ = null;
2112           }
2113         ;
2114
2115 opt_finalizer
2116         : /* EMPTY */           { $$ = 0; }
2117         | UNSAFE                { $$ = Modifiers.UNSAFE; }
2118         | EXTERN                { $$ = Modifiers.EXTERN; }
2119         ;
2120         
2121 destructor_declaration
2122         : opt_attributes opt_finalizer TILDE 
2123           {
2124                 if (RootContext.Documentation != null) {
2125                         tmpComment = Lexer.consume_doc_comment ();
2126                         Lexer.doc_state = XmlCommentState.NotAllowed;
2127                 }
2128           }
2129           IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2130           {
2131                 if ((string) $5 != current_container.MemberName.Name){
2132                         Report.Error (574, lexer.Location, "Name of destructor must match name of class");
2133                 } else if (current_container.Kind != Kind.Class){
2134                         Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
2135                 } else {
2136                         Location l = lexer.Location;
2137
2138                         int m = (int) $2;
2139                         if (!RootContext.StdLib && current_container.Name == "System.Object")
2140                                 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2141                         else
2142                                 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2143                         
2144                         if ((m & Modifiers.UNSAFE) != 0){
2145                                 if (!RootContext.Unsafe){
2146                                         Report.Error (227, l,
2147                                               "Unsafe code requires the -unsafe command " +
2148                                               "line option to be specified");
2149                                 }
2150                         }
2151                         
2152                         Method d = new Destructor (
2153                                 current_class, TypeManager.system_void_expr, m, "Finalize", 
2154                                 new Parameters (null, null, l), (Attributes) $1, l);
2155                         if (RootContext.Documentation != null)
2156                                 d.DocComment = ConsumeStoredComment ();
2157                   
2158                         d.Block = (ToplevelBlock) $8;
2159                         current_container.AddMethod (d);
2160                 }
2161           }
2162         ;
2163
2164 event_declaration
2165         : opt_attributes
2166           opt_modifiers
2167           EVENT type variable_declarators SEMICOLON
2168           {
2169                 foreach (VariableDeclaration var in (ArrayList) $5) {
2170
2171                         MemberName name = new MemberName (var.identifier);
2172
2173                         Event e = new EventField (
2174                                 current_class, (Expression) $4, (int) $2, false, name,
2175                                 var.expression_or_array_initializer, (Attributes) $1,
2176                                 lexer.Location);
2177
2178                         current_container.AddEvent (e);
2179
2180                         if (RootContext.Documentation != null) {
2181                                 e.DocComment = Lexer.consume_doc_comment ();
2182                                 Lexer.doc_state = XmlCommentState.Allowed;
2183                         }
2184                 }
2185           }
2186         | opt_attributes
2187           opt_modifiers
2188           EVENT type namespace_or_type_name
2189           OPEN_BRACE _mark_
2190           {
2191                 implicit_value_parameter_type = (Expression) $4;  
2192                 lexer.EventParsing = true;
2193           }
2194           event_accessor_declarations
2195           {
2196                 lexer.EventParsing = false;  
2197           }
2198           CLOSE_BRACE
2199           {
2200                 Location loc = (Location) $7;
2201
2202                 if ($9 == null){
2203                         Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
2204                         $$ = null;
2205                 } else {
2206                         Pair pair = (Pair) $9;
2207                         
2208                         MemberName name = (MemberName) $5;
2209
2210                         if (name.TypeArguments != null)
2211                                 syntax_error (lexer.Location, "an event can't have type arguments");
2212
2213                         Event e = new EventProperty (
2214                                 current_class, (Expression) $4, (int) $2, false, name, null,
2215                                 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
2216                                 loc);
2217                         if (RootContext.Documentation != null) {
2218                                 e.DocComment = Lexer.consume_doc_comment ();
2219                                 Lexer.doc_state = XmlCommentState.Allowed;
2220                         }
2221
2222                         current_container.AddEvent (e);
2223                         implicit_value_parameter_type = null;
2224                 }
2225           }
2226         | opt_attributes opt_modifiers EVENT type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
2227                 MemberName mn = (MemberName) $5;
2228
2229                 if (mn.Left != null)
2230                         Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
2231                 else 
2232                         Report.Error (71, lexer.Location, "Event declaration should use property syntax");
2233
2234                 if (RootContext.Documentation != null)
2235                         Lexer.doc_state = XmlCommentState.Allowed;
2236           }
2237         ;
2238
2239 event_accessor_declarations
2240         : add_accessor_declaration remove_accessor_declaration
2241         {
2242                 $$ = new Pair ($1, $2);
2243         }
2244         | remove_accessor_declaration add_accessor_declaration
2245         {
2246                 $$ = new Pair ($2, $1);
2247         }       
2248         | add_accessor_declaration  { $$ = null; } 
2249         | remove_accessor_declaration { $$ = null; } 
2250         | error
2251         { 
2252                 Report.Error (1055, lexer.Location, "An add or remove accessor expected");
2253                 $$ = null;
2254         }
2255         | { $$ = null; }
2256         ;
2257
2258 add_accessor_declaration
2259         : opt_attributes ADD
2260           {
2261                 Parameter [] args = new Parameter [1];
2262                 Parameter implicit_value_parameter = new Parameter (
2263                         implicit_value_parameter_type, "value", 
2264                         Parameter.Modifier.NONE, null);
2265
2266                 args [0] = implicit_value_parameter;
2267                 
2268                 current_local_parameters = new Parameters (args, null, lexer.Location);  
2269                 lexer.EventParsing = false;
2270           }
2271           block
2272           {
2273                 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
2274                 lexer.EventParsing = true;
2275           }
2276         | opt_attributes ADD error {
2277                 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
2278                 $$ = null;
2279           }
2280         | opt_attributes modifiers ADD {
2281                 Report.Error (1609, lexer.Location, "Modifiers cannot be placed on event accessor declarations");
2282                 $$ = null;
2283           }
2284         ;
2285
2286 remove_accessor_declaration
2287         : opt_attributes REMOVE
2288           {
2289                 Parameter [] args = new Parameter [1];
2290                 Parameter implicit_value_parameter = new Parameter (
2291                         implicit_value_parameter_type, "value", 
2292                         Parameter.Modifier.NONE, null);
2293
2294                 args [0] = implicit_value_parameter;
2295                 
2296                 current_local_parameters = new Parameters (args, null, lexer.Location);  
2297                 lexer.EventParsing = false;
2298           }
2299           block
2300           {
2301                 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
2302                 lexer.EventParsing = true;
2303           }
2304         | opt_attributes REMOVE error {
2305                 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
2306                 $$ = null;
2307           }
2308         | opt_attributes modifiers REMOVE {
2309                 Report.Error (1609, lexer.Location, "Modifiers cannot be placed on event accessor declarations");
2310                 $$ = null;
2311           }
2312         ;
2313
2314 indexer_declaration
2315         : opt_attributes opt_modifiers indexer_declarator 
2316           OPEN_BRACE _mark_
2317           {
2318                 IndexerDeclaration decl = (IndexerDeclaration) $3;
2319
2320                 implicit_value_parameter_type = decl.type;
2321                 
2322                 lexer.PropertyParsing = true;
2323                 parsing_indexer  = true;
2324                 
2325                 indexer_parameters = decl.param_list;
2326           }
2327           accessor_declarations 
2328           {
2329                   lexer.PropertyParsing = false;
2330                   has_get = has_set = false;
2331                   parsing_indexer  = false;
2332           }
2333           CLOSE_BRACE
2334           { 
2335                 if ($7 == null)
2336                         break;
2337
2338                 // The signature is computed from the signature of the indexer.  Look
2339                 // at section 3.6 on the spec
2340                 Location loc = (Location) $5;
2341                 Indexer indexer;
2342                 IndexerDeclaration decl = (IndexerDeclaration) $3;
2343                 Pair pair = (Pair) $7;
2344                 Accessor get_block = (Accessor) pair.First;
2345                 Accessor set_block = (Accessor) pair.Second;
2346
2347                 MemberName name;
2348                 if (decl.interface_type != null)
2349                         name = new MemberName (decl.interface_type,
2350                                                TypeContainer.DefaultIndexerName, null);
2351                 else
2352                         name = new MemberName (TypeContainer.DefaultIndexerName);
2353
2354                 indexer = new Indexer (current_class, decl.type, name,
2355                                        (int) $2, false, decl.param_list, (Attributes) $1,
2356                                        get_block, set_block, loc);
2357                 if (RootContext.Documentation != null)
2358                         indexer.DocComment = ConsumeStoredComment ();
2359
2360                 current_container.AddIndexer (indexer);
2361                 
2362                 current_local_parameters = null;
2363                 implicit_value_parameter_type = null;
2364                 indexer_parameters = null;
2365           }
2366         ;
2367
2368 indexer_declarator
2369         : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2370           {
2371                 Parameters pars = (Parameters) $4;
2372                 if (pars.HasArglist) {
2373                         // "__arglist is not valid in this context"
2374                         Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2375                 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2376                         Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2377                 }
2378                 if (RootContext.Documentation != null) {
2379                         tmpComment = Lexer.consume_doc_comment ();
2380                         Lexer.doc_state = XmlCommentState.Allowed;
2381                 }
2382
2383                 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
2384           }
2385         | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2386           {
2387                 Parameters pars = (Parameters) $6;
2388
2389                 if (pars.HasArglist) {
2390                         // "__arglist is not valid in this context"
2391                         Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
2392                 } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
2393                         Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
2394                 }
2395
2396                 MemberName name = (MemberName) $2;
2397
2398                 $$ = new IndexerDeclaration ((Expression) $1, name, pars);
2399
2400                 if (RootContext.Documentation != null) {
2401                         tmpComment = Lexer.consume_doc_comment ();
2402                         Lexer.doc_state = XmlCommentState.Allowed;
2403                 }
2404           }
2405         ;
2406
2407 enum_declaration
2408         : opt_attributes
2409           opt_modifiers
2410           opt_partial
2411           ENUM IDENTIFIER 
2412           opt_enum_base {
2413                 if (RootContext.Documentation != null)
2414                         enumTypeComment = Lexer.consume_doc_comment ();
2415           }
2416           enum_body
2417           opt_semicolon
2418           {
2419                 bool partial = (bool) $3;
2420
2421                 if (partial) {
2422                         Report.Error (267, lexer.Location, "The partial modifier can only appear before a 'class', 'struct', or 'interface'");
2423                         break;  // assumes that the parser put us in a switch
2424                 }
2425
2426                 Location enum_location = lexer.Location;
2427
2428                 MemberName name = MakeName (new MemberName ((string) $5));
2429                 Enum e = new Enum (current_namespace, current_class, (Expression) $6, (int) $2,
2430                                    name, (Attributes) $1, enum_location);
2431                 
2432                 if (RootContext.Documentation != null)
2433                         e.DocComment = enumTypeComment;
2434
2435                 foreach (VariableDeclaration ev in (ArrayList) $8) {
2436                         e.AddEnumMember (ev.identifier, 
2437                                          (Expression) ev.expression_or_array_initializer,
2438                                          ev.Location, ev.OptAttributes,
2439                                          ev.DocComment);
2440                 }
2441
2442                 current_container.AddEnum (e);
2443                 RootContext.Tree.RecordDecl (name, e);
2444                 $$ = e;
2445
2446           }
2447         ;
2448
2449 opt_enum_base
2450         : /* empty */           { $$ = TypeManager.system_int32_expr; }
2451         | COLON type            { $$ = $2;   }
2452         ;
2453
2454 enum_body
2455         : OPEN_BRACE
2456           {
2457                 if (RootContext.Documentation != null)
2458                         Lexer.doc_state = XmlCommentState.Allowed;
2459           }
2460           opt_enum_member_declarations
2461           {
2462                 // here will be evaluated after CLOSE_BLACE is consumed.
2463                 if (RootContext.Documentation != null)
2464                         Lexer.doc_state = XmlCommentState.Allowed;
2465           }
2466           CLOSE_BRACE
2467           {
2468                 $$ = $3;
2469           }
2470         ;
2471
2472 opt_enum_member_declarations
2473         : /* empty */                   { $$ = new ArrayList (4); }
2474         | enum_member_declarations opt_comma { $$ = $1; }
2475         ;
2476
2477 enum_member_declarations
2478         : enum_member_declaration 
2479           {
2480                 ArrayList l = new ArrayList (4);
2481
2482                 l.Add ($1);
2483                 $$ = l;
2484           }
2485         | enum_member_declarations COMMA enum_member_declaration
2486           {
2487                 ArrayList l = (ArrayList) $1;
2488
2489                 l.Add ($3);
2490
2491                 $$ = l;
2492           }
2493         ;
2494
2495 enum_member_declaration
2496         : opt_attributes IDENTIFIER 
2497           {
2498                 VariableDeclaration vd = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
2499
2500                 if (RootContext.Documentation != null) {
2501                         vd.DocComment = Lexer.consume_doc_comment ();
2502                         Lexer.doc_state = XmlCommentState.Allowed;
2503                 }
2504
2505                 $$ = vd;
2506           }
2507         | opt_attributes IDENTIFIER
2508           {
2509                 $$ = lexer.Location;
2510                 if (RootContext.Documentation != null) {
2511                         tmpComment = Lexer.consume_doc_comment ();
2512                         Lexer.doc_state = XmlCommentState.NotAllowed;
2513                 }
2514           }
2515           ASSIGN expression
2516           { 
2517                 VariableDeclaration vd = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
2518
2519                 if (RootContext.Documentation != null)
2520                         vd.DocComment = ConsumeStoredComment ();
2521
2522                 $$ = vd;
2523           }
2524         ;
2525
2526 delegate_declaration
2527         : opt_attributes
2528           opt_modifiers
2529           DELEGATE
2530           {
2531                 lexer.ConstraintsParsing = true;
2532           }
2533           type member_name
2534           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2535           {
2536                 Location l = lexer.Location;
2537                 MemberName name = MakeName ((MemberName) $6);
2538                 Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
2539                                              (int) $2, name, (Parameters) $8, (Attributes) $1, l);
2540
2541                 if (RootContext.Documentation != null) {
2542                         del.DocComment = Lexer.consume_doc_comment ();
2543                         Lexer.doc_state = XmlCommentState.Allowed;
2544                 }
2545
2546                 current_container.AddDelegate (del);
2547                 RootContext.Tree.RecordDecl (name, del);
2548
2549                 current_delegate = del;
2550           }
2551           opt_type_parameter_constraints_clauses
2552           {
2553                 lexer.ConstraintsParsing = false;
2554           }
2555           SEMICOLON
2556           {
2557                 current_delegate.SetParameterInfo ((ArrayList) $10);
2558                 $$ = current_delegate;
2559
2560                 current_delegate = null;
2561           }
2562         ;
2563
2564 opt_nullable
2565         : /* empty */
2566           {
2567                 lexer.CheckNullable (false);
2568                 $$ = false;
2569           }
2570         | INTERR
2571           {
2572                 lexer.CheckNullable (true);
2573                 $$ = true;
2574           }
2575         ;
2576
2577 namespace_or_type_name
2578         : member_name
2579         | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2580                 $$ = new MemberName ((MemberName) $1, (string) $3, (TypeArguments) $4);
2581           }
2582         ;
2583
2584 member_name
2585         : IDENTIFIER opt_type_argument_list {
2586                 $$ = new MemberName ((string) $1, (TypeArguments) $2);
2587           }
2588         ;
2589
2590 opt_type_argument_list
2591         : /* empty */                { $$ = null; } 
2592         | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2593           {
2594                 $$ = $2;
2595           }
2596         | GENERIC_DIMENSION
2597           {
2598                 $$ = new TypeArguments ((int) $1, lexer.Location);
2599           }
2600         ;
2601
2602 type_arguments
2603         : type {
2604                 TypeArguments type_args = new TypeArguments (lexer.Location);
2605                 type_args.Add ((Expression) $1);
2606                 $$ = type_args;
2607           }
2608         | type_arguments COMMA type {
2609                 TypeArguments type_args = (TypeArguments) $1;
2610                 type_args.Add ((Expression) $3);
2611                 $$ = type_args;
2612           }
2613         ;
2614         
2615 /* 
2616  * Before you think of adding a return_type, notice that we have been
2617  * using two rules in the places where it matters (one rule using type
2618  * and another identical one that uses VOID as the return type).  This
2619  * gets rid of a shift/reduce couple
2620  */
2621 type
2622         : namespace_or_type_name opt_nullable
2623           {
2624                 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2625
2626                 if ((bool) $2)
2627                         $$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
2628           }
2629         | builtin_types opt_nullable
2630           {
2631                 if ((bool) $2)
2632                         $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2633           }
2634         | array_type
2635         | pointer_type
2636         ;
2637
2638 pointer_type
2639         : type STAR
2640           {
2641                 //
2642                 // Note that here only unmanaged types are allowed but we
2643                 // can't perform checks during this phase - we do it during
2644                 // semantic analysis.
2645                 //
2646                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2647           }
2648         | VOID STAR
2649           {
2650                 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
2651           }
2652         ;
2653
2654 non_expression_type
2655         : builtin_types opt_nullable
2656           {
2657                 if ((bool) $2)
2658                         $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2659           }
2660         | non_expression_type rank_specifier
2661           {
2662                 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2663           }
2664         | non_expression_type STAR
2665           {
2666                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2667           }
2668         | expression rank_specifiers 
2669           {
2670                 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2671           }
2672         | expression STAR 
2673           {
2674                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2675           }
2676         
2677         //
2678         // We need this because the parser will happily go and reduce IDENTIFIER STAR
2679         // through this different path
2680         //
2681         | multiplicative_expression STAR 
2682           {
2683                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2684           }
2685         ;
2686
2687 type_list
2688         : type
2689           {
2690                 ArrayList types = new ArrayList (4);
2691
2692                 types.Add ($1);
2693                 $$ = types;
2694           }
2695         | type_list COMMA type
2696           {
2697                 ArrayList types = (ArrayList) $1;
2698
2699                 types.Add ($3);
2700                 $$ = types;
2701           }
2702         ;
2703
2704 /*
2705  * replaces all the productions for isolating the various
2706  * simple types, but we need this to reuse it easily in local_variable_type
2707  */
2708 builtin_types
2709         : OBJECT        { $$ = TypeManager.system_object_expr; }
2710         | STRING        { $$ = TypeManager.system_string_expr; }
2711         | BOOL          { $$ = TypeManager.system_boolean_expr; }
2712         | DECIMAL       { $$ = TypeManager.system_decimal_expr; }
2713         | FLOAT         { $$ = TypeManager.system_single_expr; }
2714         | DOUBLE        { $$ = TypeManager.system_double_expr; }
2715         | integral_type
2716         ;
2717
2718 integral_type
2719         : SBYTE         { $$ = TypeManager.system_sbyte_expr; }
2720         | BYTE          { $$ = TypeManager.system_byte_expr; }
2721         | SHORT         { $$ = TypeManager.system_int16_expr; }
2722         | USHORT        { $$ = TypeManager.system_uint16_expr; }
2723         | INT           { $$ = TypeManager.system_int32_expr; }
2724         | UINT          { $$ = TypeManager.system_uint32_expr; }
2725         | LONG          { $$ = TypeManager.system_int64_expr; }
2726         | ULONG         { $$ = TypeManager.system_uint64_expr; }
2727         | CHAR          { $$ = TypeManager.system_char_expr; }
2728         | VOID          { $$ = TypeManager.system_void_expr; }
2729         ;
2730
2731 array_type
2732         : type rank_specifiers opt_nullable
2733           {
2734                 string rank_specifiers = (string) $2;
2735                 if ((bool) $3)
2736                         rank_specifiers += "?";
2737
2738                 $$ = new ComposedCast ((Expression) $1, rank_specifiers, lexer.Location);
2739           }
2740         ;
2741
2742 //
2743 // Expressions, section 7.5
2744 //
2745 primary_expression
2746         : literal
2747           {
2748                 // 7.5.1: Literals
2749           }
2750         | member_name
2751           {
2752                 $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
2753           }
2754         | parenthesized_expression
2755         | default_value_expression
2756         | member_access
2757         | invocation_expression
2758         | element_access
2759         | this_access
2760         | base_access
2761         | post_increment_expression
2762         | post_decrement_expression
2763         | new_expression
2764         | typeof_expression
2765         | sizeof_expression
2766         | checked_expression
2767         | unchecked_expression
2768         | pointer_member_access
2769         | anonymous_method_expression
2770         ;
2771
2772 literal
2773         : boolean_literal
2774         | integer_literal
2775         | real_literal
2776         | LITERAL_CHARACTER     { $$ = new CharLiteral ((char) lexer.Value); }
2777         | LITERAL_STRING        { $$ = new StringLiteral ((string) lexer.Value); }
2778         | NULL                  { $$ = NullLiteral.Null; }
2779         ;
2780
2781 real_literal
2782         : LITERAL_FLOAT         { $$ = new FloatLiteral ((float) lexer.Value); }
2783         | LITERAL_DOUBLE        { $$ = new DoubleLiteral ((double) lexer.Value); }
2784         | LITERAL_DECIMAL       { $$ = new DecimalLiteral ((decimal) lexer.Value); }
2785         ;
2786
2787 integer_literal
2788         : LITERAL_INTEGER       { 
2789                 object v = lexer.Value;
2790
2791                 if (v is int){
2792                         int i = (int) v;
2793
2794                         if (i == 0)
2795                                 $$ = IntLiteral.Zero;
2796                         else if (i == 1)
2797                                 $$ = IntLiteral.One;
2798                         else
2799                                 $$ = new IntLiteral (i);
2800                 } else if (v is uint)
2801                         $$ = new UIntLiteral ((UInt32) v);
2802                 else if (v is long)
2803                         $$ = new LongLiteral ((Int64) v);
2804                 else if (v is ulong)
2805                         $$ = new ULongLiteral ((UInt64) v);
2806                 else
2807                         Console.WriteLine ("OOPS.  Unexpected result from scanner");
2808           }
2809         ;
2810
2811 boolean_literal
2812         : TRUE                  { $$ = new BoolLiteral (true); }
2813         | FALSE                 { $$ = new BoolLiteral (false); }
2814         ;
2815
2816 parenthesized_expression_0
2817         : OPEN_PARENS expression CLOSE_PARENS
2818           {
2819                 $$ = $2;
2820                 lexer.Deambiguate_CloseParens ();
2821                 // After this, the next token returned is one of
2822                 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2823                 // or CLOSE_PARENS_MINUS.
2824           }
2825         ;
2826
2827 parenthesized_expression
2828         : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2829           {
2830                 $$ = $1;
2831           }
2832         | parenthesized_expression_0 CLOSE_PARENS_MINUS
2833           {
2834                 // If a parenthesized expression is followed by a minus, we need to wrap
2835                 // the expression inside a ParenthesizedExpression for the CS0075 check
2836                 // in Binary.DoResolve().
2837                 $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
2838           }
2839         ;;
2840
2841 member_access
2842         : primary_expression DOT IDENTIFIER opt_type_argument_list
2843           {
2844                 $$ = new MemberAccess ((Expression) $1, (string) $3,
2845                                        (TypeArguments) $4, lexer.Location);
2846           }
2847         | predefined_type DOT IDENTIFIER opt_type_argument_list
2848           {
2849                 $$ = new MemberAccess ((Expression) $1, (string) $3,
2850                                        (TypeArguments) $4, lexer.Location);
2851           }
2852         ;
2853
2854 predefined_type
2855         : builtin_types
2856         ;
2857
2858 invocation_expression
2859         : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2860           {
2861                 if ($1 == null) {
2862                         Location l = lexer.Location;
2863                         Report.Error (1, l, "Parse error");
2864                 }
2865                 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2866           }
2867         | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2868           {
2869                 $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
2870           }
2871         | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2872           {
2873                 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
2874           }
2875         | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
2876           {
2877                 ArrayList args = new ArrayList (1);
2878                 args.Add ($4);
2879                 $$ = new Invocation ((Expression) $1, args, lexer.Location);
2880           }
2881         | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
2882           {
2883                 ArrayList args = ((ArrayList) $4);
2884                 args.Add ($6);
2885                 $$ = new Invocation ((Expression) $1, args, lexer.Location);
2886           }
2887         ;
2888
2889 opt_argument_list
2890         : /* empty */           { $$ = null; }
2891         | argument_list
2892         ;
2893
2894 argument_list
2895         : argument              
2896           { 
2897                 ArrayList list = new ArrayList (4);
2898                 list.Add ($1);
2899                 $$ = list;
2900           }
2901         | argument_list COMMA argument
2902           {
2903                 ArrayList list = (ArrayList) $1;
2904                 list.Add ($3);
2905                 $$ = list;
2906           }
2907         | argument_list error {
2908                 CheckToken (1026, yyToken, ", or ) expected");
2909           }
2910         ;
2911
2912 argument
2913         : expression
2914           {
2915                 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2916           }
2917         | non_simple_argument
2918           {
2919                 $$ = $1;
2920           }
2921         ;
2922
2923 non_simple_argument
2924         : REF variable_reference 
2925           { 
2926                 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2927           }
2928         | OUT variable_reference 
2929           { 
2930                 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2931           }
2932         | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
2933           {
2934                 ArrayList list = (ArrayList) $3;
2935                 Argument[] args = new Argument [list.Count];
2936                 list.CopyTo (args, 0);
2937
2938                 Expression expr = new Arglist (args, lexer.Location);
2939                 $$ = new Argument (expr, Argument.AType.Expression);
2940           }
2941         | ARGLIST
2942           {
2943                 $$ = new Argument (new ArglistAccess (lexer.Location), Argument.AType.ArgList);
2944           }
2945         ;
2946
2947 variable_reference
2948         : expression { note ("section 5.4"); $$ = $1; }
2949         ;
2950
2951 element_access
2952         : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET 
2953           {
2954                 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2955           }
2956         | primary_expression rank_specifiers
2957           {
2958                 // So the super-trick is that primary_expression
2959                 // can only be either a SimpleName or a MemberAccess. 
2960                 // The MemberAccess case arises when you have a fully qualified type-name like :
2961                 // Foo.Bar.Blah i;
2962                 // SimpleName is when you have
2963                 // Blah i;
2964                   
2965                 Expression expr = (Expression) $1;  
2966                 if (expr is ComposedCast){
2967                         $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2968                 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType)){
2969                         Error_ExpectingTypeName (lexer.Location, expr);
2970                         $$ = TypeManager.system_object_expr;
2971                 } else {
2972                         //
2973                         // So we extract the string corresponding to the SimpleName
2974                         // or MemberAccess
2975                         // 
2976                         $$ = new ComposedCast (expr, (string) $2, lexer.Location);
2977                 }
2978           }
2979         ;
2980
2981 expression_list
2982         : expression
2983           {
2984                 ArrayList list = new ArrayList (4);
2985                 list.Add ($1);
2986                 $$ = list;
2987           }
2988         | expression_list COMMA expression
2989           {
2990                 ArrayList list = (ArrayList) $1;
2991                 list.Add ($3);
2992                 $$ = list;
2993           }
2994         ;
2995
2996 this_access
2997         : THIS
2998           {
2999                 $$ = new This (current_block, lexer.Location);
3000           }
3001         ;
3002
3003 base_access
3004         : BASE DOT IDENTIFIER
3005           {
3006                 $$ = new BaseAccess ((string) $3, lexer.Location);
3007           }
3008         | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3009           {
3010                 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
3011           }
3012         | BASE error {
3013                 Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
3014                 $$ = null;
3015           }
3016         ;
3017
3018 post_increment_expression
3019         : primary_expression OP_INC
3020           {
3021                 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3022                                        (Expression) $1, lexer.Location);
3023           }
3024         ;
3025
3026 post_decrement_expression
3027         : primary_expression OP_DEC
3028           {
3029                 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3030                                        (Expression) $1, lexer.Location);
3031           }
3032         ;
3033
3034 new_expression
3035         : object_or_delegate_creation_expression
3036         | array_creation_expression
3037         ;
3038
3039 object_or_delegate_creation_expression
3040         : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
3041           {
3042                 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
3043           }
3044         ;
3045
3046 array_creation_expression
3047         : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET 
3048           opt_rank_specifier
3049           opt_array_initializer
3050           {
3051                 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
3052           }
3053         | NEW type rank_specifiers array_initializer
3054           {
3055                 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
3056           }
3057         | NEW error
3058           {
3059                 Report.Error (1031, lexer.Location, "Type expected");
3060                 $$ = null;
3061           }          
3062         | NEW type error 
3063           {
3064                 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
3065           }
3066         ;
3067
3068 opt_rank_specifier
3069         : /* empty */
3070           {
3071                   $$ = "";
3072           }
3073         | rank_specifiers
3074           {
3075                         $$ = $1;
3076           }
3077         ;
3078
3079 opt_rank_specifier_or_nullable
3080         : /* empty */
3081           {
3082                 $$ = "";
3083           }
3084         | INTERR
3085           {
3086                 $$ = "?";
3087           }
3088         | opt_nullable rank_specifiers
3089           {
3090                 if ((bool) $1)
3091                         $$ = "?" + $2;
3092                 else
3093                         $$ = $2;
3094           }
3095         | opt_nullable rank_specifiers INTERR
3096           {
3097                 if ((bool) $1)
3098                         $$ = "?" + $2 + "?";
3099                 else
3100                         $$ = $2 + "?";
3101           }
3102         ;
3103
3104 rank_specifiers
3105         : rank_specifier opt_rank_specifier
3106           {
3107                   $$ = (string) $2 + (string) $1;
3108           }
3109         ;
3110
3111 rank_specifier
3112         : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3113           {
3114                 $$ = "[" + (string) $2 + "]";
3115           }
3116         ;
3117
3118 opt_dim_separators
3119         : /* empty */
3120           {
3121                 $$ = "";
3122           }
3123         | dim_separators
3124           {
3125                   $$ = $1;
3126           }               
3127         ;
3128
3129 dim_separators
3130         : COMMA
3131           {
3132                 $$ = ",";
3133           }
3134         | dim_separators COMMA
3135           {
3136                 $$ = (string) $1 + ",";
3137           }
3138         ;
3139
3140 opt_array_initializer
3141         : /* empty */
3142           {
3143                 $$ = null;
3144           }
3145         | array_initializer
3146           {
3147                 $$ = $1;
3148           }
3149         ;
3150
3151 array_initializer
3152         : OPEN_BRACE CLOSE_BRACE
3153           {
3154                 ArrayList list = new ArrayList (4);
3155                 $$ = list;
3156           }
3157         | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3158           {
3159                 $$ = (ArrayList) $2;
3160           }
3161         ;
3162
3163 variable_initializer_list
3164         : variable_initializer
3165           {
3166                 ArrayList list = new ArrayList (4);
3167                 list.Add ($1);
3168                 $$ = list;
3169           }
3170         | variable_initializer_list COMMA variable_initializer
3171           {
3172                 ArrayList list = (ArrayList) $1;
3173                 list.Add ($3);
3174                 $$ = list;
3175           }
3176         ;
3177
3178 void_pointer_expression
3179         : void_pointer_expression STAR
3180           {
3181                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
3182           }
3183         | VOID STAR
3184           {
3185                 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
3186           }
3187         ;
3188
3189 typeof_expression
3190         : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
3191           {
3192                 $$ = new TypeOfVoid (lexer.Location);
3193           }
3194         | TYPEOF OPEN_PARENS void_pointer_expression CLOSE_PARENS
3195           {
3196                 $$ = new TypeOf ((Expression) $3, lexer.Location);
3197           }
3198         | TYPEOF OPEN_PARENS
3199           {
3200                 lexer.TypeOfParsing = true;
3201           }
3202           type CLOSE_PARENS
3203           {
3204                 lexer.TypeOfParsing = false;
3205                 $$ = new TypeOf ((Expression) $4, lexer.Location);
3206           }
3207         ;
3208
3209 sizeof_expression
3210         : SIZEOF OPEN_PARENS type CLOSE_PARENS { 
3211                 $$ = new SizeOf ((Expression) $3, lexer.Location);
3212           }
3213         ;
3214
3215 checked_expression
3216         : CHECKED OPEN_PARENS expression CLOSE_PARENS
3217           {
3218                 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
3219           }
3220         ;
3221
3222 unchecked_expression
3223         : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3224           {
3225                 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
3226           }
3227         ;
3228
3229 pointer_member_access 
3230         : primary_expression OP_PTR IDENTIFIER
3231           {
3232                 Expression deref;
3233
3234                 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
3235                 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
3236           }
3237         ;
3238
3239 anonymous_method_expression
3240         : DELEGATE opt_anonymous_method_signature _mark_
3241           {
3242                 oob_stack.Push (current_local_parameters);
3243                 current_local_parameters = (Parameters)$2;
3244
3245                 // Force the next block to be created as a ToplevelBlock
3246                 oob_stack.Push (current_block);
3247                 oob_stack.Push (top_current_block);
3248                 current_block = null;
3249           } 
3250           block
3251           {
3252                 Location loc = (Location) $3;
3253                 top_current_block = (Block) oob_stack.Pop ();
3254                 current_block = (Block) oob_stack.Pop ();
3255                 if (RootContext.Version == LanguageVersion.ISO_1){
3256                                 Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
3257                                 $$ = null;
3258                 } else  {
3259                         ToplevelBlock anon_block = (ToplevelBlock) $5;
3260
3261                         anon_block.Parent = current_block;
3262                         $$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block, 
3263                                 anon_block, loc);
3264                 }
3265                         current_local_parameters = (Parameters) oob_stack.Pop ();
3266                 }
3267         ;
3268
3269 opt_anonymous_method_signature
3270         : /* empty */                   { $$ = null; } 
3271         | anonymous_method_signature
3272         ;
3273
3274 anonymous_method_signature
3275         : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS 
3276           {
3277                 if ($2 == null)
3278                         $$ = Parameters.EmptyReadOnlyParameters;
3279                 else {
3280                         ArrayList par_list = (ArrayList) $2;
3281                         Parameter [] pars = new Parameter [par_list.Count];
3282                         par_list.CopyTo (pars);
3283                         $$ = new Parameters (pars, null, lexer.Location);
3284                 }
3285           }
3286         ;
3287
3288 opt_anonymous_method_parameter_list
3289         : /* empty */   { $$ = null; } 
3290         | anonymous_method_parameter_list  { $$ = $1; }
3291         ;
3292
3293 anonymous_method_parameter_list
3294         : anonymous_method_parameter 
3295           {
3296                 ArrayList a = new ArrayList (4);
3297                 a.Add ($1);
3298                 $$ = a;
3299           }
3300         | anonymous_method_parameter_list COMMA anonymous_method_parameter 
3301           {
3302                 ArrayList a = (ArrayList) $1;
3303                 a.Add ($3);
3304                 $$ = a;
3305           }
3306         ; 
3307
3308 anonymous_method_parameter
3309         : opt_parameter_modifier type IDENTIFIER {
3310                 $$ = new Parameter ((Expression) $2, (string) $3, (Parameter.Modifier) $1, null);
3311           }
3312         | PARAMS type IDENTIFIER {
3313                 Report.Error (1670, lexer.Location, "params modifier not allowed in anonymous method declaration");
3314                 $$ = null;
3315           }
3316         ;
3317
3318 default_value_expression
3319         : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3320           {
3321                 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3322           }
3323         ;
3324
3325 unary_expression
3326         : primary_expression
3327         | BANG prefixed_unary_expression
3328           {
3329                 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
3330           }
3331         | TILDE prefixed_unary_expression
3332           {
3333                 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
3334           }
3335         | cast_expression
3336         ;
3337
3338 cast_list
3339         : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3340           {
3341                 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
3342           }
3343         | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3344           {
3345                 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
3346           }     
3347         ;
3348
3349 cast_expression
3350         : cast_list
3351         | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3352           {
3353                 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3354           }
3355         ;
3356
3357         //
3358         // The idea to split this out is from Rhys' grammar
3359         // to solve the problem with casts.
3360         //
3361 prefixed_unary_expression
3362         : unary_expression
3363         | PLUS prefixed_unary_expression
3364           { 
3365                 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
3366           } 
3367         | MINUS prefixed_unary_expression 
3368           { 
3369                 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
3370           }
3371         | OP_INC prefixed_unary_expression 
3372           {
3373                 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3374                                        (Expression) $2, lexer.Location);
3375           }
3376         | OP_DEC prefixed_unary_expression 
3377           {
3378                 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3379                                        (Expression) $2, lexer.Location);
3380           }
3381         | STAR prefixed_unary_expression
3382           {
3383                 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
3384           }
3385         | BITWISE_AND prefixed_unary_expression
3386           {
3387                 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
3388           }
3389         ;
3390
3391 pre_increment_expression
3392         : OP_INC prefixed_unary_expression 
3393           {
3394                 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3395                                        (Expression) $2, lexer.Location);
3396           }
3397         ;
3398
3399 pre_decrement_expression
3400         : OP_DEC prefixed_unary_expression 
3401           {
3402                 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3403                                        (Expression) $2, lexer.Location);
3404           }
3405         ;
3406
3407 multiplicative_expression
3408         : prefixed_unary_expression
3409         | multiplicative_expression STAR prefixed_unary_expression
3410           {
3411                 $$ = new Binary (Binary.Operator.Multiply, 
3412                                  (Expression) $1, (Expression) $3, lexer.Location);
3413           }
3414         | multiplicative_expression DIV prefixed_unary_expression
3415           {
3416                 $$ = new Binary (Binary.Operator.Division, 
3417                                  (Expression) $1, (Expression) $3, lexer.Location);
3418           }
3419         | multiplicative_expression PERCENT prefixed_unary_expression 
3420           {
3421                 $$ = new Binary (Binary.Operator.Modulus, 
3422                                  (Expression) $1, (Expression) $3, lexer.Location);
3423           }
3424         ;
3425
3426 additive_expression
3427         : multiplicative_expression
3428         | additive_expression PLUS multiplicative_expression 
3429           {
3430                 $$ = new Binary (Binary.Operator.Addition, 
3431                                  (Expression) $1, (Expression) $3, lexer.Location);
3432           }
3433         | additive_expression MINUS multiplicative_expression
3434           {
3435                 $$ = new Binary (Binary.Operator.Subtraction, 
3436                                  (Expression) $1, (Expression) $3, lexer.Location);
3437           }
3438         ;
3439
3440 shift_expression
3441         : additive_expression
3442         | shift_expression OP_SHIFT_LEFT additive_expression
3443           {
3444                 $$ = new Binary (Binary.Operator.LeftShift, 
3445                                  (Expression) $1, (Expression) $3, lexer.Location);
3446           }
3447         | shift_expression OP_SHIFT_RIGHT additive_expression
3448           {
3449                 $$ = new Binary (Binary.Operator.RightShift, 
3450                                  (Expression) $1, (Expression) $3, lexer.Location);
3451           }
3452         ; 
3453
3454 opt_error
3455         : /* empty */
3456           {
3457                 $$ = false;
3458           }
3459         | error
3460           {
3461                 lexer.PutbackNullable ();
3462                 $$ = true;
3463           }
3464         ;
3465
3466 nullable_type_or_conditional
3467         : type opt_error
3468           {
3469                 if (((bool) $2) && ($1 is ComposedCast))
3470                         $$ = ((ComposedCast) $1).RemoveNullable ();
3471                 else
3472                         $$ = $1;
3473           }
3474         ;
3475
3476 relational_expression
3477         : shift_expression
3478         | relational_expression OP_LT shift_expression
3479           {
3480                 $$ = new Binary (Binary.Operator.LessThan, 
3481                                  (Expression) $1, (Expression) $3, lexer.Location);
3482           }
3483         | relational_expression OP_GT shift_expression
3484           {
3485                 $$ = new Binary (Binary.Operator.GreaterThan, 
3486                                  (Expression) $1, (Expression) $3, lexer.Location);
3487           }
3488         | relational_expression OP_LE shift_expression
3489           {
3490                 $$ = new Binary (Binary.Operator.LessThanOrEqual, 
3491                                  (Expression) $1, (Expression) $3, lexer.Location);
3492           }
3493         | relational_expression OP_GE shift_expression
3494           {
3495                 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, 
3496                                  (Expression) $1, (Expression) $3, lexer.Location);
3497           }
3498         | relational_expression IS
3499           {
3500                 yyErrorFlag = 3;
3501           } nullable_type_or_conditional
3502           {
3503                 Report.Debug (64, "PARSE IS", $1, $1.GetType (), $4, $4.GetType (), lexer.Location);
3504                 $$ = new Is ((Expression) $1, (Expression) $4, lexer.Location);
3505           }
3506         | relational_expression AS
3507           {
3508                 yyErrorFlag = 3;
3509           } nullable_type_or_conditional
3510           {
3511                 $$ = new As ((Expression) $1, (Expression) $4, lexer.Location);
3512           }
3513         ;
3514
3515 equality_expression
3516         : relational_expression
3517         | equality_expression OP_EQ relational_expression
3518           {
3519                 $$ = new Binary (Binary.Operator.Equality, 
3520                                  (Expression) $1, (Expression) $3, lexer.Location);
3521           }
3522         | equality_expression OP_NE relational_expression
3523           {
3524                 $$ = new Binary (Binary.Operator.Inequality, 
3525                                  (Expression) $1, (Expression) $3, lexer.Location);
3526           }
3527         ; 
3528
3529 and_expression
3530         : equality_expression
3531         | and_expression BITWISE_AND equality_expression
3532           {
3533                 $$ = new Binary (Binary.Operator.BitwiseAnd, 
3534                                  (Expression) $1, (Expression) $3, lexer.Location);
3535           }
3536         ;
3537
3538 exclusive_or_expression
3539         : and_expression
3540         | exclusive_or_expression CARRET and_expression
3541           {
3542                 $$ = new Binary (Binary.Operator.ExclusiveOr, 
3543                                  (Expression) $1, (Expression) $3, lexer.Location);
3544           }
3545         ;
3546
3547 inclusive_or_expression
3548         : exclusive_or_expression
3549         | inclusive_or_expression BITWISE_OR exclusive_or_expression
3550           {
3551                 $$ = new Binary (Binary.Operator.BitwiseOr, 
3552                                  (Expression) $1, (Expression) $3, lexer.Location);
3553           }
3554         ;
3555
3556 conditional_and_expression
3557         : inclusive_or_expression
3558         | conditional_and_expression OP_AND inclusive_or_expression
3559           {
3560                 $$ = new Binary (Binary.Operator.LogicalAnd, 
3561                                  (Expression) $1, (Expression) $3, lexer.Location);
3562           }
3563         ;
3564
3565 conditional_or_expression
3566         : conditional_and_expression
3567         | conditional_or_expression OP_OR conditional_and_expression
3568           {
3569                 $$ = new Binary (Binary.Operator.LogicalOr, 
3570                                  (Expression) $1, (Expression) $3, lexer.Location);
3571           }
3572         ;
3573
3574 conditional_expression
3575         : conditional_or_expression
3576         | conditional_or_expression INTERR expression COLON expression 
3577           {
3578                 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
3579           }
3580         | conditional_or_expression INTERR INTERR expression
3581           {
3582                 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $4, lexer.Location);
3583           }
3584         // We'll be resolved into a `parenthesized_expression_0' later on.
3585         | conditional_or_expression INTERR CLOSE_PARENS
3586           {
3587                 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
3588                 lexer.PutbackCloseParens ();
3589           }
3590         ;
3591
3592 assignment_expression
3593         : prefixed_unary_expression ASSIGN expression
3594           {
3595                 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
3596           }
3597         | prefixed_unary_expression OP_MULT_ASSIGN expression
3598           {
3599                 Location l = lexer.Location;
3600
3601                 $$ = new CompoundAssign (
3602                         Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
3603           }
3604         | prefixed_unary_expression OP_DIV_ASSIGN expression
3605           {
3606                 Location l = lexer.Location;
3607
3608                 $$ = new CompoundAssign (
3609                         Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
3610           }
3611         | prefixed_unary_expression OP_MOD_ASSIGN expression
3612           {
3613                 Location l = lexer.Location;
3614
3615                 $$ = new CompoundAssign (
3616                         Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
3617           }
3618         | prefixed_unary_expression OP_ADD_ASSIGN expression
3619           {
3620                 Location l = lexer.Location;
3621
3622                 $$ = new CompoundAssign (
3623                         Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
3624           }
3625         | prefixed_unary_expression OP_SUB_ASSIGN expression
3626           {
3627                 Location l = lexer.Location;
3628
3629                 $$ = new CompoundAssign (
3630                         Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
3631           }
3632         | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3633           {
3634                 Location l = lexer.Location;
3635
3636                 $$ = new CompoundAssign (
3637                         Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
3638           }
3639         | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3640           {
3641                 Location l = lexer.Location;
3642
3643                 $$ = new CompoundAssign (
3644                         Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
3645           }
3646         | prefixed_unary_expression OP_AND_ASSIGN expression
3647           {
3648                 Location l = lexer.Location;
3649
3650                 $$ = new CompoundAssign (
3651                         Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
3652           }
3653         | prefixed_unary_expression OP_OR_ASSIGN expression
3654           {
3655                 Location l = lexer.Location;
3656
3657                 $$ = new CompoundAssign (
3658                         Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
3659           }
3660         | prefixed_unary_expression OP_XOR_ASSIGN expression
3661           {
3662                 Location l = lexer.Location;
3663
3664                 $$ = new CompoundAssign (
3665                         Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
3666           }
3667         ;
3668
3669 expression
3670         : conditional_expression
3671         | assignment_expression
3672         ;
3673
3674 constant_expression
3675         : expression
3676         ;
3677
3678 boolean_expression
3679         : expression
3680         ;
3681
3682 //
3683 // 10 classes
3684 //
3685 class_declaration
3686         : opt_attributes
3687           opt_modifiers
3688           opt_partial
3689           CLASS
3690           {
3691                 lexer.ConstraintsParsing = true;
3692           }
3693           member_name
3694           {
3695                 MemberName name = MakeName ((MemberName) $6);
3696                 bool partial = (bool) $3;
3697                 int mod_flags = (int) $2;
3698
3699                 if (partial) {
3700                         ClassPart part = PartialContainer.CreatePart (
3701                                 current_namespace, current_class, name, mod_flags,
3702                                 (Attributes) $1, Kind.Class, lexer.Location);
3703
3704                         current_container = part.PartialContainer;
3705                         current_class = part;
3706                 } else {
3707                         if ((mod_flags & Modifiers.STATIC) != 0) {
3708                                 current_class = new StaticClass (
3709                                         current_namespace, current_class, name,
3710                                         mod_flags, (Attributes) $1, lexer.Location);
3711                         } else {
3712                                 current_class = new Class (
3713                                         current_namespace, current_class, name,
3714                                         mod_flags, (Attributes) $1, lexer.Location);
3715                         }
3716
3717                         current_container.AddClassOrStruct (current_class);
3718                         current_container = current_class;
3719                         RootContext.Tree.RecordDecl (name, current_class);
3720                 }
3721           }
3722           opt_class_base
3723           opt_type_parameter_constraints_clauses
3724           {
3725                 lexer.ConstraintsParsing = false;
3726
3727                 if ($8 != null) {
3728                         if (current_class.Name == "System.Object") {
3729                                 Report.Error (537, current_class.Location,
3730                                               "The class System.Object cannot have a base " +
3731                                               "class or implement an interface.");
3732                         }
3733                         current_class.Bases = (ArrayList) $8;
3734                 }
3735
3736                 current_class.SetParameterInfo ((ArrayList) $9);
3737
3738                 if (RootContext.Documentation != null) {
3739                         current_class.DocComment = Lexer.consume_doc_comment ();
3740                         Lexer.doc_state = XmlCommentState.Allowed;
3741                 }
3742           }
3743           class_body
3744           {
3745                 if (RootContext.Documentation != null)
3746                         Lexer.doc_state = XmlCommentState.Allowed;
3747           }
3748           opt_semicolon 
3749           {
3750                 $$ = pop_current_class ();
3751           }
3752         ;       
3753
3754 opt_partial
3755         : /* empty */
3756           { $$ = (bool) false; }
3757         | PARTIAL
3758           { $$ = (bool) true; }
3759         ;
3760
3761 opt_modifiers
3762         : /* empty */           { $$ = (int) 0; }
3763         | modifiers
3764         ;
3765
3766 modifiers
3767         : modifier
3768         | modifiers modifier
3769           { 
3770                 int m1 = (int) $1;
3771                 int m2 = (int) $2;
3772
3773                 if ((m1 & m2) != 0) {
3774                         Location l = lexer.Location;
3775                         Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
3776                 }
3777                 $$ = (int) (m1 | m2);
3778           }
3779         ;
3780
3781 modifier
3782         : NEW                   { $$ = Modifiers.NEW; }
3783         | PUBLIC                { $$ = Modifiers.PUBLIC; }
3784         | PROTECTED             { $$ = Modifiers.PROTECTED; }
3785         | INTERNAL              { $$ = Modifiers.INTERNAL; }
3786         | PRIVATE               { $$ = Modifiers.PRIVATE; }
3787         | ABSTRACT              { $$ = Modifiers.ABSTRACT; }
3788         | SEALED                { $$ = Modifiers.SEALED; }
3789         | STATIC                { $$ = Modifiers.STATIC; }
3790         | READONLY              { $$ = Modifiers.READONLY; }
3791         | VIRTUAL               { $$ = Modifiers.VIRTUAL; }
3792         | OVERRIDE              { $$ = Modifiers.OVERRIDE; }
3793         | EXTERN                { $$ = Modifiers.EXTERN; }
3794         | VOLATILE              { $$ = Modifiers.VOLATILE; }
3795         | UNSAFE                { $$ = Modifiers.UNSAFE; }
3796         ;
3797
3798 opt_class_base
3799         : /* empty */           { $$ = null; }
3800         | class_base            { $$ = $1;   }
3801         ;
3802
3803 class_base
3804         : COLON type_list { $$ = $2; }
3805         ;
3806
3807 opt_type_parameter_constraints_clauses
3808         : /* empty */           { $$ = null; }
3809         | type_parameter_constraints_clauses 
3810           { $$ = $1; }
3811         ;
3812
3813 type_parameter_constraints_clauses
3814         : type_parameter_constraints_clause {
3815                 ArrayList constraints = new ArrayList (1);
3816                 constraints.Add ($1);
3817                 $$ = constraints;
3818           }
3819         | type_parameter_constraints_clauses type_parameter_constraints_clause {
3820                 ArrayList constraints = (ArrayList) $1;
3821
3822                 constraints.Add ($2);
3823                 $$ = constraints;
3824           }
3825         ; 
3826
3827 type_parameter_constraints_clause
3828         : WHERE IDENTIFIER COLON type_parameter_constraints {
3829                 $$ = new Constraints ((string) $2, (ArrayList) $4, lexer.Location);
3830           }
3831         ; 
3832
3833 type_parameter_constraints
3834         : type_parameter_constraint {
3835                 ArrayList constraints = new ArrayList (1);
3836                 constraints.Add ($1);
3837                 $$ = constraints;
3838           }
3839         | type_parameter_constraints COMMA type_parameter_constraint {
3840                 ArrayList constraints = (ArrayList) $1;
3841
3842                 constraints.Add ($3);
3843                 $$ = constraints;
3844           }
3845         ;
3846
3847 type_parameter_constraint
3848         : type
3849         | NEW OPEN_PARENS CLOSE_PARENS {
3850                 $$ = SpecialConstraint.Constructor;
3851           }
3852         | CLASS {
3853                 $$ = SpecialConstraint.ReferenceType;
3854           }
3855         | STRUCT {
3856                 $$ = SpecialConstraint.ValueType;
3857           }
3858         ;
3859
3860 //
3861 // Statements (8.2)
3862 //
3863
3864 //
3865 // A block is "contained" on the following places:
3866 //      method_body
3867 //      property_declaration as part of the accessor body (get/set)
3868 //      operator_declaration
3869 //      constructor_declaration
3870 //      destructor_declaration
3871 //      event_declaration as part of add_accessor_declaration or remove_accessor_declaration
3872 //      
3873 block
3874         : OPEN_BRACE 
3875           {
3876                 if (current_block == null){
3877                         current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, lexer.Location);
3878                         top_current_block = current_block;
3879                 } else {
3880                         current_block = new Block (current_block, lexer.Location, Location.Null);
3881                 }
3882           } 
3883           opt_statement_list CLOSE_BRACE 
3884           { 
3885                 while (current_block.Implicit)
3886                         current_block = current_block.Parent;
3887                 $$ = current_block;
3888                 current_block.SetEndLocation (lexer.Location);
3889                 current_block = current_block.Parent;
3890                 if (current_block == null)
3891                         top_current_block = null;
3892           }
3893         ;
3894
3895 opt_statement_list
3896         : /* empty */
3897         | statement_list 
3898         ;
3899
3900 statement_list
3901         : statement
3902         | statement_list statement
3903         ;
3904
3905 statement
3906         : declaration_statement
3907           {
3908                 if ($1 != null && (Block) $1 != current_block){
3909                         current_block.AddStatement ((Statement) $1);
3910                         current_block = (Block) $1;
3911                 }
3912           }
3913         | valid_declaration_statement
3914           {
3915                 current_block.AddStatement ((Statement) $1);
3916           }
3917         | labeled_statement
3918         ;
3919
3920 valid_declaration_statement
3921         : block
3922         | empty_statement
3923         | expression_statement
3924         | selection_statement
3925         | iteration_statement
3926         | jump_statement                  
3927         | try_statement
3928         | checked_statement
3929         | unchecked_statement
3930         | lock_statement
3931         | using_statement
3932         | unsafe_statement
3933         | fixed_statement
3934         ;
3935
3936 embedded_statement
3937         : valid_declaration_statement
3938         | declaration_statement
3939           {
3940                   Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
3941                   $$ = null;
3942           }
3943         | labeled_statement
3944           {
3945                   Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
3946                   $$ = null;
3947           }
3948         ;
3949
3950 empty_statement
3951         : SEMICOLON
3952           {
3953                   $$ = EmptyStatement.Value;
3954           }
3955         ;
3956
3957 labeled_statement
3958         : IDENTIFIER COLON 
3959           {
3960                 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
3961
3962                 if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
3963                         current_block.AddStatement (labeled);
3964           }
3965           statement
3966         ;
3967
3968 declaration_statement
3969         : local_variable_declaration SEMICOLON
3970           {
3971                 if ($1 != null){
3972                         DictionaryEntry de = (DictionaryEntry) $1;
3973
3974                         $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
3975                 }
3976           }
3977
3978         | local_constant_declaration SEMICOLON
3979           {
3980                 if ($1 != null){
3981                         DictionaryEntry de = (DictionaryEntry) $1;
3982
3983                         $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
3984                 }
3985           }
3986         ;
3987
3988 /* 
3989  * The following is from Rhys' grammar:
3990  * > Types in local variable declarations must be recognized as 
3991  * > expressions to prevent reduce/reduce errors in the grammar.
3992  * > The expressions are converted into types during semantic analysis.
3993  */
3994 local_variable_type
3995         : primary_expression opt_rank_specifier_or_nullable
3996           { 
3997                 // FIXME: Do something smart here regarding the composition of the type.
3998
3999                 // Ok, the above "primary_expression" is there to get rid of
4000                 // both reduce/reduce and shift/reduces in the grammar, it should
4001                 // really just be "type_name".  If you use type_name, a reduce/reduce
4002                 // creeps up.  If you use namespace_or_type_name (which is all we need
4003                 // really) two shift/reduces appear.
4004                 // 
4005
4006                 // So the super-trick is that primary_expression
4007                 // can only be either a SimpleName or a MemberAccess. 
4008                 // The MemberAccess case arises when you have a fully qualified type-name like :
4009                 // Foo.Bar.Blah i;
4010                 // SimpleName is when you have
4011                 // Blah i;
4012                   
4013                 Expression expr = (Expression) $1;  
4014                 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
4015                         Error_ExpectingTypeName (lexer.Location, expr);
4016                         $$ = null;
4017                 } else {
4018                         //
4019                         // So we extract the string corresponding to the SimpleName
4020                         // or MemberAccess
4021                         // 
4022
4023                         if ((string) $2 == "")
4024                                 $$ = $1;
4025                         else
4026                                 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4027                 }
4028           }
4029         | builtin_types opt_rank_specifier_or_nullable
4030           {
4031                 if ((string) $2 == "")
4032                         $$ = $1;
4033                 else
4034                         $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4035           }
4036         ;
4037
4038 local_variable_pointer_type
4039         : primary_expression STAR
4040           {
4041                 Expression expr = (Expression) $1;  
4042                 Location l = lexer.Location;
4043
4044                 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType)) {
4045                         Error_ExpectingTypeName (l, expr);
4046
4047                         $$ = null;
4048                 } else 
4049                         $$ = new ComposedCast ((Expression) $1, "*", l);
4050           }
4051         | builtin_types STAR
4052           {
4053                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
4054           }
4055         | VOID STAR
4056           {
4057                 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
4058           }
4059         | local_variable_pointer_type STAR
4060           {
4061                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4062           }
4063         ;
4064
4065 local_variable_declaration
4066         : local_variable_type variable_declarators
4067           {
4068                 if ($1 != null)
4069                         $$ = new DictionaryEntry ($1, $2);
4070                 else
4071                         $$ = null;
4072           }
4073         | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4074         {
4075                 if ($1 != null){
4076                         Expression t;
4077
4078                         if ((string) $2 == "")
4079                                 t = (Expression) $1;
4080                         else
4081                                 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4082                         $$ = new DictionaryEntry (t, $3);
4083                 } else 
4084                         $$ = null;
4085         }
4086         ;
4087
4088 local_constant_declaration
4089         : CONST local_variable_type constant_declarators
4090           {
4091                 if ($2 != null)
4092                         $$ = new DictionaryEntry ($2, $3);
4093                 else
4094                         $$ = null;
4095           }
4096         ;
4097
4098 expression_statement
4099         : statement_expression SEMICOLON
4100           {
4101                 $$ = $1;
4102           }
4103         ;
4104
4105         //
4106         // We have to do the wrapping here and not in the case above,
4107         // because statement_expression is used for example in for_statement
4108         //
4109 statement_expression
4110         : invocation_expression         { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
4111         | object_creation_expression    { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
4112         | assignment_expression         { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
4113         | post_increment_expression     { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
4114         | post_decrement_expression     { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
4115         | pre_increment_expression      { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
4116         | pre_decrement_expression      { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
4117         | error {
4118                 Report.Error (1002, lexer.Location, "Expecting `;'");
4119                 $$ = null;
4120           }
4121         ;
4122
4123 object_creation_expression
4124         : object_or_delegate_creation_expression
4125           { note ("complain if this is a delegate maybe?"); } 
4126         ;
4127
4128 selection_statement
4129         : if_statement
4130         | switch_statement
4131         ; 
4132
4133 if_statement
4134         : IF OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS 
4135           embedded_statement
4136           { 
4137                 Location l = (Location) $3;
4138
4139                 $$ = new If ((Expression) $4, (Statement) $6, l);
4140
4141                 if (RootContext.WarningLevel >= 4){
4142                         if ($6 == EmptyStatement.Value)
4143                                 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
4144                 }
4145
4146           }
4147         | IF OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS
4148           embedded_statement ELSE embedded_statement
4149           {
4150                 Location l = (Location) $3;
4151
4152                 $$ = new If ((Expression) $4, (Statement) $6, (Statement) $8, l);
4153           }
4154         ;
4155
4156 switch_statement
4157         : SWITCH OPEN_PARENS _mark_
4158           { 
4159                 switch_stack.Push (current_block);
4160           }
4161           expression CLOSE_PARENS 
4162           switch_block
4163           {
4164                 $$ = new Switch ((Expression) $5, (ArrayList) $7, (Location) $3);
4165                 current_block = (Block) switch_stack.Pop ();
4166           }
4167         ;
4168
4169 switch_block
4170         : OPEN_BRACE
4171           opt_switch_sections
4172           CLOSE_BRACE
4173           {
4174                 $$ = $2;
4175           }
4176         ;
4177
4178 opt_switch_sections
4179         : /* empty */           
4180           {
4181                 Report.Error (1522, lexer.Location, "Empty switch block"); 
4182           }
4183         | switch_sections
4184         ;
4185
4186 switch_sections
4187         : switch_section 
4188           {
4189                 ArrayList sections = new ArrayList (4);
4190
4191                 sections.Add ($1);
4192                 $$ = sections;
4193           }
4194         | switch_sections switch_section
4195           {
4196                 ArrayList sections = (ArrayList) $1;
4197
4198                 sections.Add ($2);
4199                 $$ = sections;
4200           }
4201         ;
4202
4203 switch_section
4204         : switch_labels
4205           {
4206                 current_block = current_block.CreateSwitchBlock (lexer.Location);
4207           }
4208           statement_list 
4209           {
4210                 Block topmost = current_block;
4211
4212                 while (topmost.Implicit)
4213                         topmost = topmost.Parent;
4214                 $$ = new SwitchSection ((ArrayList) $1, topmost);
4215           }
4216         ;
4217
4218 switch_labels
4219         : switch_label 
4220           {
4221                 ArrayList labels = new ArrayList (4);
4222
4223                 labels.Add ($1);
4224                 $$ = labels;
4225           }
4226         | switch_labels switch_label 
4227           {
4228                 ArrayList labels = (ArrayList) ($1);
4229                 labels.Add ($2);
4230
4231                 $$ = labels;
4232           }
4233         ;
4234
4235 switch_label
4236         : CASE constant_expression COLON        { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
4237         | DEFAULT COLON                         { $$ = new SwitchLabel (null, lexer.Location); }
4238         | error {
4239                 Report.Error (
4240                         1523, lexer.Location, 
4241                         "The keyword case or default must precede code in switch block");
4242           }
4243         ;
4244
4245 iteration_statement
4246         : while_statement
4247         | do_statement
4248         | for_statement
4249         | foreach_statement
4250         ;
4251
4252 while_statement
4253         : WHILE OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS embedded_statement
4254         {
4255                 Location l = (Location) $3;
4256                 $$ = new While ((Expression) $4, (Statement) $6, l);
4257         
4258                 if (RootContext.WarningLevel >= 4){
4259                         if ($6 == EmptyStatement.Value)
4260                                 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
4261                 }
4262         }
4263         ;
4264
4265 do_statement
4266         : DO embedded_statement 
4267           WHILE OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS SEMICOLON
4268           {
4269                 Location l = (Location) $5;
4270
4271                 $$ = new Do ((Statement) $2, (Expression) $6, l);
4272           }
4273         ;
4274
4275 for_statement
4276         : FOR OPEN_PARENS 
4277           opt_for_initializer SEMICOLON _mark_
4278           {
4279                 Block assign_block = new Block (current_block);
4280                 current_block = assign_block;
4281
4282                 if ($3 is DictionaryEntry){
4283                         DictionaryEntry de = (DictionaryEntry) $3;
4284                         
4285                         Expression type = (Expression) de.Key;
4286                         ArrayList var_declarators = (ArrayList) de.Value;
4287
4288                         foreach (VariableDeclaration decl in var_declarators){
4289
4290                                 LocalInfo vi;
4291
4292                                 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4293                                 if (vi == null)
4294                                         continue;
4295
4296                                 Location l = lexer.Location;
4297                                 Expression expr;
4298                                 if (decl.expression_or_array_initializer is Expression){
4299                                         expr = (Expression) decl.expression_or_array_initializer;
4300                                 } else if (decl.expression_or_array_initializer == null) {
4301                                         expr = null;
4302                                 } else {
4303                                         ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4304                                         expr = new ArrayCreation (type, "", init, decl.Location);
4305                                 }
4306                                         
4307                                 LocalVariableReference var;
4308                                 var = new LocalVariableReference (assign_block, decl.identifier, l);
4309
4310                                 if (expr != null) {
4311                                         Assign a = new Assign (var, expr, decl.Location);
4312                                         
4313                                         assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4314                                 }
4315                         }
4316                         
4317                         // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4318                         // This can be referred to as $6 below.
4319                         $$ = null;
4320                 } else {
4321                         $$ = $3;
4322                 }
4323           } 
4324           opt_for_condition SEMICOLON
4325           opt_for_iterator CLOSE_PARENS 
4326           embedded_statement
4327           {
4328                 Location l = (Location) $5;
4329
4330                 For f = new For ((Statement) $6, (Expression) $7, (Statement) $9, (Statement) $11, l);
4331
4332                 if (RootContext.WarningLevel >= 4){
4333                         if ($11 == EmptyStatement.Value)
4334                                 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
4335                 }
4336
4337                 current_block.AddStatement (f);
4338                 while (current_block.Implicit)
4339                         current_block = current_block.Parent;
4340                 $$ = current_block;
4341                 current_block = current_block.Parent;
4342           }
4343         ;
4344
4345 opt_for_initializer
4346         : /* empty */           { $$ = EmptyStatement.Value; }
4347         | for_initializer       
4348         ;
4349
4350 for_initializer
4351         : local_variable_declaration
4352         | statement_expression_list
4353         ;
4354
4355 opt_for_condition
4356         : /* empty */           { $$ = null; }
4357         | boolean_expression
4358         ;
4359
4360 opt_for_iterator
4361         : /* empty */           { $$ = EmptyStatement.Value; }
4362         | for_iterator
4363         ;
4364
4365 for_iterator
4366         : statement_expression_list
4367         ;
4368
4369 statement_expression_list
4370         : statement_expression  
4371           {
4372                 // CHANGE: was `null'
4373                 Block b = new Block (current_block, Block.Flags.Implicit);   
4374
4375                 b.AddStatement ((Statement) $1);
4376                 $$ = b;
4377           }
4378         | statement_expression_list COMMA statement_expression
4379           {
4380                 Block b = (Block) $1;
4381
4382                 b.AddStatement ((Statement) $3);
4383                 $$ = $1;
4384           }
4385         ;
4386
4387 foreach_statement
4388         : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
4389         {
4390                 Report.Error (230, lexer.Location, "Type and identifier are both required in a foreach statement");
4391                 $$ = null;
4392         }
4393         | FOREACH OPEN_PARENS type IDENTIFIER IN _mark_
4394           expression CLOSE_PARENS 
4395           {
4396                 Block foreach_block = new Block (current_block);
4397                 current_block = foreach_block;
4398
4399                 Location l = lexer.Location;
4400                 LocalInfo vi;
4401
4402                 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, l);
4403                 if (vi != null) {
4404                         vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4405
4406                         // Get a writable reference to this read-only variable.
4407                         //
4408                         // Note that the $$ here refers to the value of _this_ code block,
4409                         // not the value of the LHS non-terminal.  This can be referred to as $9 below.
4410                         $$ = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
4411                 } else {
4412                         $$ = null;
4413                 }
4414           } 
4415           embedded_statement 
4416           {
4417                 LocalVariableReference v = (LocalVariableReference) $9;
4418                 Location l = (Location) $6;
4419
4420                 if (v != null) {
4421                         Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
4422                         current_block.AddStatement (f);
4423                 }
4424
4425                 while (current_block.Implicit)
4426                           current_block = current_block.Parent;
4427                 $$ = current_block;
4428                 current_block = current_block.Parent;
4429           }
4430         ;
4431
4432 jump_statement
4433         : break_statement
4434         | continue_statement
4435         | goto_statement
4436         | return_statement
4437         | throw_statement
4438         | yield_statement
4439         ;
4440
4441 break_statement
4442         : BREAK SEMICOLON
4443           {
4444                 $$ = new Break (lexer.Location);
4445           }
4446         ;
4447
4448 continue_statement
4449         : CONTINUE SEMICOLON
4450           {
4451                 $$ = new Continue (lexer.Location);
4452           }
4453         ;
4454
4455 goto_statement
4456         : GOTO IDENTIFIER SEMICOLON 
4457           {
4458                 $$ = new Goto ((string) $2, lexer.Location);
4459           }
4460         | GOTO CASE constant_expression SEMICOLON
4461           {
4462                 $$ = new GotoCase ((Expression) $3, lexer.Location);
4463           }
4464         | GOTO DEFAULT SEMICOLON 
4465           {
4466                 $$ = new GotoDefault (lexer.Location);
4467           }
4468         ; 
4469
4470 return_statement
4471         : RETURN opt_expression SEMICOLON
4472           {
4473                 $$ = new Return ((Expression) $2, lexer.Location);
4474           }
4475         ;
4476
4477 throw_statement
4478         : THROW opt_expression SEMICOLON
4479           {
4480                 $$ = new Throw ((Expression) $2, lexer.Location);
4481           }
4482         ;
4483
4484 yield_statement 
4485         : IDENTIFIER RETURN expression SEMICOLON
4486           {
4487                 string s = (string) $1;
4488                 if (s != "yield"){
4489                         Report.Error (1003, lexer.Location, "; expected");
4490                         $$ = null;
4491                 }
4492                 if (RootContext.Version == LanguageVersion.ISO_1){
4493                         Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
4494                         $$ = null;
4495                 }
4496                 if (iterator_container == null){
4497                         Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
4498                         $$ = null;
4499                 } else {
4500                         iterator_container.SetYields ();
4501                         $$ = new Yield ((Expression) $3, lexer.Location); 
4502                 }
4503           }
4504         | IDENTIFIER RETURN SEMICOLON
4505         {
4506                 Report.Error (1627, lexer.Location, "Expression expected after yield return");
4507                 $$ = null;
4508         }
4509         | IDENTIFIER BREAK SEMICOLON
4510           {
4511                 string s = (string) $1;
4512                 if (s != "yield"){
4513                         Report.Error (1003, lexer.Location, "; expected");
4514                         $$ = null;
4515                 }
4516                 if (RootContext.Version == LanguageVersion.ISO_1){
4517                         Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
4518                         $$ = null;
4519                 }
4520                 if (iterator_container == null){
4521                         Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
4522                         $$ = null;
4523                 } else {
4524                         iterator_container.SetYields ();
4525                         $$ = new YieldBreak (lexer.Location);
4526                 }
4527           }
4528         ;
4529
4530 opt_expression
4531         : /* empty */
4532         | expression
4533         ;
4534
4535 try_statement
4536         : TRY block catch_clauses 
4537         {
4538                 Catch g = null;
4539                 
4540                 ArrayList c = (ArrayList)$3;
4541                 for (int i = 0; i < c.Count; ++i) {
4542                         Catch cc = (Catch) c [i];
4543                         if (cc.IsGeneral) {
4544                                 if (i != c.Count - 1)
4545                                         Report.Error (1017, cc.loc, "Empty catch block must be the last in a series of catch blocks");
4546                                 g = cc;
4547                                 c.RemoveAt (i);
4548                                 i--;
4549                         }
4550                 }
4551
4552                 // Now s contains the list of specific catch clauses
4553                 // and g contains the general one.
4554                 
4555                 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4556         }
4557         | TRY block opt_catch_clauses FINALLY block
4558           {
4559                 Catch g = null;
4560                 ArrayList s = new ArrayList (4);
4561                 ArrayList catch_list = (ArrayList) $3;
4562
4563                 if (catch_list != null){
4564                         foreach (Catch cc in catch_list) {
4565                                 if (cc.IsGeneral)
4566                                         g = cc;
4567                                 else
4568                                         s.Add (cc);
4569                         }
4570                 }
4571
4572                 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4573           }
4574         | TRY block error 
4575           {
4576                 Report.Error (1524, lexer.Location, "Expected catch or finally");
4577           }
4578         ;
4579
4580 opt_catch_clauses
4581         : /* empty */  { $$ = null; }
4582         | catch_clauses
4583         ;
4584
4585 catch_clauses
4586         : catch_clause 
4587           {
4588                 ArrayList l = new ArrayList (4);
4589
4590                 l.Add ($1);
4591                 $$ = l;
4592           }
4593         | catch_clauses catch_clause
4594           {
4595                 ArrayList l = (ArrayList) $1;
4596
4597                 l.Add ($2);
4598                 $$ = l;
4599           }
4600         ;
4601
4602 opt_identifier
4603         : /* empty */   { $$ = null; }
4604         | IDENTIFIER
4605         ;
4606
4607 catch_clause 
4608         : CATCH opt_catch_args 
4609         {
4610                 Expression type = null;
4611                 string id = null;
4612                 
4613                 if ($2 != null) {
4614                         DictionaryEntry cc = (DictionaryEntry) $2;
4615                         type = (Expression) cc.Key;
4616                         id   = (string) cc.Value;
4617
4618                         if (id != null){
4619                                 ArrayList one = new ArrayList (4);
4620                                 Location loc = lexer.Location;
4621
4622                                 one.Add (new VariableDeclaration (id, null, loc));
4623
4624                                 current_block = new Block (current_block);
4625                                 Block b = declare_local_variables (type, one, loc);
4626                                 current_block = b;
4627                         }
4628                 }
4629         } block {
4630                 Expression type = null;
4631                 string id = null;
4632
4633                 if ($2 != null){
4634                         DictionaryEntry cc = (DictionaryEntry) $2;
4635                         type = (Expression) cc.Key;
4636                         id   = (string) cc.Value;
4637
4638                         if (id != null){
4639                                 while (current_block.Implicit)
4640                                         current_block = current_block.Parent;
4641                                 current_block = current_block.Parent;
4642                         }
4643                 }
4644
4645                 $$ = new Catch (type, id, (Block) $4, ((Block) $4).loc);
4646         }
4647         ;
4648
4649 opt_catch_args
4650         : /* empty */ { $$ = null; }
4651         | catch_args
4652         ;         
4653
4654 catch_args 
4655         : OPEN_PARENS type opt_identifier CLOSE_PARENS 
4656         {
4657                 $$ = new DictionaryEntry ($2, $3);
4658         }
4659         ;
4660
4661 checked_statement
4662         : CHECKED block
4663           {
4664                 $$ = new Checked ((Block) $2);
4665           }
4666         ;
4667
4668 unchecked_statement
4669         : UNCHECKED block
4670           {
4671                 $$ = new Unchecked ((Block) $2);
4672           }
4673         ;
4674
4675 unsafe_statement
4676         : UNSAFE 
4677         {
4678                 if (!RootContext.Unsafe){
4679                         Report.Error (227, lexer.Location, 
4680                                 "Unsafe code can only be used if -unsafe is used");
4681                 }
4682         } block {
4683                 $$ = new Unsafe ((Block) $3);
4684         }
4685         ;
4686
4687 fixed_statement
4688         : FIXED OPEN_PARENS 
4689           type fixed_pointer_declarators 
4690           CLOSE_PARENS _mark_
4691           {
4692                 ArrayList list = (ArrayList) $4;
4693                 Expression type = (Expression) $3;
4694                 Location l = lexer.Location;
4695                 int top = list.Count;
4696
4697                 Block assign_block = new Block (current_block);
4698                 current_block = assign_block;
4699
4700                 for (int i = 0; i < top; i++){
4701                         Pair p = (Pair) list [i];
4702                         LocalInfo v;
4703
4704                         v = current_block.AddVariable (type, (string) p.First, l);
4705                         if (v == null)
4706                                 continue;
4707
4708                         v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
4709                         v.Pinned = true;
4710                         p.First = v;
4711                         list [i] = p;
4712                 }
4713           }
4714           embedded_statement 
4715           {
4716                 Location l = (Location) $6;
4717
4718                 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $8, l);
4719
4720                 if (RootContext.WarningLevel >= 4){
4721                         if ($8 == EmptyStatement.Value)
4722                                 Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
4723                 }
4724
4725                 current_block.AddStatement (f);
4726                 while (current_block.Implicit)
4727                         current_block = current_block.Parent;
4728                 $$ = current_block;
4729                 current_block = current_block.Parent;
4730           }
4731         ;
4732
4733 fixed_pointer_declarators
4734         : fixed_pointer_declarator      { 
4735                 ArrayList declarators = new ArrayList (4);
4736                 if ($1 != null)
4737                         declarators.Add ($1);
4738                 $$ = declarators;
4739           }
4740         | fixed_pointer_declarators COMMA fixed_pointer_declarator
4741           {
4742                 ArrayList declarators = (ArrayList) $1;
4743                 if ($3 != null)
4744                         declarators.Add ($3);
4745                 $$ = declarators;
4746           }
4747         ;
4748
4749 fixed_pointer_declarator
4750         : IDENTIFIER ASSIGN expression
4751           {     
4752                 $$ = new Pair ($1, $3);
4753           }
4754         | IDENTIFIER
4755           {
4756                 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
4757                 $$ = null;
4758           }
4759         ;
4760
4761 lock_statement
4762         : LOCK OPEN_PARENS expression CLOSE_PARENS 
4763           {
4764                 //
4765           } 
4766           embedded_statement
4767           {
4768                 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
4769           }
4770         ;
4771
4772 using_statement
4773         : USING OPEN_PARENS resource_acquisition CLOSE_PARENS _mark_
4774           {
4775                 Block assign_block = new Block (current_block);
4776                 current_block = assign_block;
4777
4778                 if ($3 is DictionaryEntry){
4779                         DictionaryEntry de = (DictionaryEntry) $3;
4780                         Location l = lexer.Location;
4781
4782                         Expression type = (Expression) de.Key;
4783                         ArrayList var_declarators = (ArrayList) de.Value;
4784
4785                         ArrayList vars = new ArrayList (4);
4786
4787                         foreach (VariableDeclaration decl in var_declarators){
4788
4789                                 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4790                                 if (vi == null)
4791                                         continue;
4792                                 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
4793
4794                                 Expression expr;
4795                                 if (decl.expression_or_array_initializer is Expression){
4796                                         expr = (Expression) decl.expression_or_array_initializer;
4797                                 } else {
4798                                         ArrayList init = (ArrayList) decl.expression_or_array_initializer;
4799                                         if (init == null) {
4800                                                 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4801                                         }
4802                                         
4803                                         expr = new ArrayCreation (type, "", init, decl.Location);
4804                                 }
4805
4806                                 LocalVariableReference var;
4807
4808                                 // Get a writable reference to this read-only variable.
4809                                 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4810
4811                                 // This is so that it is not a warning on using variables
4812                                 vi.Used = true;
4813
4814                                 vars.Add (new DictionaryEntry (var, expr));                             
4815
4816                                 // Assign a = new Assign (var, expr, decl.Location);
4817                                 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
4818                         }
4819
4820                         // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
4821                         // It can be referred to as $6 below.
4822                         $$ = new DictionaryEntry (type, vars);
4823                  } else {
4824                         $$ = $3;
4825                  }
4826           } 
4827           embedded_statement
4828           {
4829                 Using u = new Using ($6, (Statement) $7, (Location) $5);
4830                 current_block.AddStatement (u);
4831                 while (current_block.Implicit)
4832                         current_block = current_block.Parent;
4833                 $$ = current_block;
4834                 current_block = current_block.Parent;
4835           }
4836         ; 
4837
4838 resource_acquisition
4839         : local_variable_declaration
4840         | expression
4841         ;
4842
4843 // Utility rule to save location information
4844 _mark_
4845         : /* empty */
4846         { $$ = lexer.Location; }
4847
4848 %%
4849
4850 // <summary>
4851 //   A class used to pass around variable declarations and constants
4852 // </summary>
4853 public class VariableDeclaration {
4854         public string identifier;
4855         public object expression_or_array_initializer;
4856         public Location Location;
4857         public Attributes OptAttributes;
4858         public string DocComment;
4859
4860         public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
4861         {
4862                 this.identifier = id;
4863                 this.expression_or_array_initializer = eoai;
4864                 this.Location = l;
4865                 this.OptAttributes = opt_attrs;
4866         }
4867
4868         public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
4869         {
4870         }
4871 }
4872
4873 /// <summary>
4874 ///  Used to pass around interface property information
4875 /// </summary>
4876 public class InterfaceAccessorInfo {
4877
4878         public readonly Accessor Get, Set;
4879
4880         public InterfaceAccessorInfo (bool has_get, bool has_set,
4881                                       Attributes get_attrs, Attributes set_attrs, int get_mod, int set_mod, Location get_loc, Location set_loc)
4882         {
4883                 if (get_mod != 0)
4884                         Report.Error (275, get_loc, "Accessibility modifiers can not be used on accessors in interfaces");
4885                 if (set_mod != 0)
4886                         Report.Error (275, set_loc, "Accessibility modifiers can not be used on accessors in interfaces");
4887                         
4888                 if (has_get)
4889                         Get = new Accessor (null, 0, get_attrs, get_loc);
4890                 if (has_set)
4891                         Set = new Accessor (null, 0, set_attrs, set_loc);
4892         }
4893
4894 }
4895
4896
4897 // <summary>
4898 //   A class used to hold info about an indexer declarator
4899 // </summary>
4900 public class IndexerDeclaration {
4901         public Expression type;
4902         public MemberName interface_type;
4903         public Parameters param_list;
4904
4905         public IndexerDeclaration (Expression type, MemberName interface_type,
4906                                    Parameters param_list)
4907         {
4908                 this.type = type;
4909                 this.interface_type = interface_type;
4910                 this.param_list = param_list;
4911         }
4912 }
4913
4914 //
4915 // We use this when we do not have an object in advance that is an IIteratorContainer
4916 //
4917 public class SimpleIteratorContainer : IIteratorContainer {
4918         public bool Yields;
4919
4920         public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
4921
4922         //
4923         // Reset and return
4924         //
4925         public static SimpleIteratorContainer GetSimple () { 
4926                 Simple.Yields = false;
4927                 return Simple;
4928         }
4929
4930         public void SetYields () { Yields = true; } 
4931 }
4932
4933 // <summary>
4934 //  A class used to hold info about an operator declarator
4935 // </summary>
4936 public class OperatorDeclaration {
4937         public Operator.OpType optype;
4938         public Expression ret_type, arg1type, arg2type;
4939         public string arg1name, arg2name;
4940         public Location location;
4941
4942         public OperatorDeclaration (Operator.OpType op, Expression ret_type, 
4943                                     Expression arg1type, string arg1name,
4944                                     Expression arg2type, string arg2name, Location location)
4945         {
4946                 optype = op;
4947                 this.ret_type = ret_type;
4948                 this.arg1type = arg1type;
4949                 this.arg1name = arg1name;
4950                 this.arg2type = arg2type;
4951                 this.arg2name = arg2name;
4952                 this.location = location;
4953         }
4954
4955 }
4956
4957 void Error_ExpectingTypeName (Location l, Expression expr)
4958 {
4959         if (expr is Invocation){
4960                 Report.Error (1002, l, "; expected");
4961         } else {
4962                 Report.Error (-1, l, "Invalid Type definition");
4963         }
4964 }
4965
4966 TypeContainer pop_current_class ()
4967 {
4968         TypeContainer retval = current_class;
4969
4970         current_class = current_class.Parent;
4971         current_container = current_container.Parent;
4972         
4973         if (current_class != current_container) {
4974                 if (!(current_class is ClassPart) ||
4975                     ((ClassPart) current_class).PartialContainer != current_container)
4976                         throw new InternalErrorException ();
4977         } else if (current_container is ClassPart)
4978                 current_container = ((ClassPart) current_class).PartialContainer;
4979
4980         return retval;
4981 }
4982
4983 // <summary>
4984 //   Given the @class_name name, it creates a fully qualified name
4985 //   based on the containing declaration space
4986 // </summary>
4987 MemberName
4988 MakeName (MemberName class_name)
4989 {
4990         Namespace ns = current_namespace.NS;
4991
4992         if (current_container.Name == ""){
4993                 if (ns.Name != "")
4994                         return new MemberName (ns.MemberName, class_name);
4995                 else
4996                         return class_name;
4997         } else {
4998                 return new MemberName (current_container.MemberName, class_name);
4999         }
5000 }
5001
5002 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5003 {
5004         Block implicit_block;
5005         ArrayList inits = null;
5006
5007         //
5008         // We use the `Used' property to check whether statements
5009         // have been added to the current block.  If so, we need
5010         // to create another block to contain the new declaration
5011         // otherwise, as an optimization, we use the same block to
5012         // add the declaration.
5013         //
5014         // FIXME: A further optimization is to check if the statements
5015         // that were added were added as part of the initialization
5016         // below.  In which case, no other statements have been executed
5017         // and we might be able to reduce the number of blocks for
5018         // situations like this:
5019         //
5020         // int j = 1;  int k = j + 1;
5021         //
5022         if (current_block.Used)
5023                 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
5024         else
5025                 implicit_block = current_block;
5026
5027         foreach (VariableDeclaration decl in variable_declarators){
5028
5029                 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5030                         if (decl.expression_or_array_initializer != null){
5031                                 if (inits == null)
5032                                         inits = new ArrayList (4);
5033                                 inits.Add (decl);
5034                         }
5035                 }
5036         }
5037
5038         if (inits == null)
5039                 return implicit_block;
5040
5041         foreach (VariableDeclaration decl in inits){
5042                 Assign assign;
5043                 Expression expr;
5044                 
5045                 if (decl.expression_or_array_initializer is Expression){
5046                         expr = (Expression) decl.expression_or_array_initializer;
5047
5048                 } else {
5049                         ArrayList init = (ArrayList) decl.expression_or_array_initializer;
5050                         
5051                         expr = new ArrayCreation (type, "", init, decl.Location);
5052                 }
5053
5054                 LocalVariableReference var;
5055                 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5056
5057                 assign = new Assign (var, expr, decl.Location);
5058
5059                 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
5060         }
5061         
5062         return implicit_block;
5063 }
5064
5065 Block declare_local_constants (Expression type, ArrayList declarators)
5066 {
5067         Block implicit_block;
5068
5069         if (current_block.Used)
5070                 implicit_block = new Block (current_block, Block.Flags.Implicit);
5071         else
5072                 implicit_block = current_block;
5073
5074         foreach (VariableDeclaration decl in declarators){
5075                 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5076         }
5077         
5078         return implicit_block;
5079 }
5080
5081 void CheckAttributeTarget (string a)
5082 {
5083         switch (a) {
5084
5085         case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5086                 return;
5087                 
5088         default :
5089                 Location l = lexer.Location;
5090                 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
5091                 break;
5092         }
5093
5094 }
5095
5096 void CheckUnaryOperator (Operator.OpType op)
5097 {
5098         switch (op) {
5099                 
5100         case Operator.OpType.LogicalNot: 
5101         case Operator.OpType.OnesComplement: 
5102         case Operator.OpType.Increment:
5103         case Operator.OpType.Decrement:
5104         case Operator.OpType.True: 
5105         case Operator.OpType.False: 
5106         case Operator.OpType.Addition: 
5107         case Operator.OpType.Subtraction:
5108                 
5109                 break;
5110                 
5111         default :
5112                 Location l = lexer.Location;
5113                 Report.Error (1019, l, "Overloadable unary operator expected"); 
5114                 break;
5115                 
5116         }
5117 }
5118
5119 void CheckBinaryOperator (Operator.OpType op)
5120 {
5121         switch (op) {
5122                 
5123         case Operator.OpType.Addition: 
5124         case Operator.OpType.Subtraction: 
5125         case Operator.OpType.Multiply:
5126         case Operator.OpType.Division:
5127         case Operator.OpType.Modulus: 
5128         case Operator.OpType.BitwiseAnd: 
5129         case Operator.OpType.BitwiseOr:
5130         case Operator.OpType.ExclusiveOr: 
5131         case Operator.OpType.LeftShift: 
5132         case Operator.OpType.RightShift:
5133         case Operator.OpType.Equality: 
5134         case Operator.OpType.Inequality:
5135         case Operator.OpType.GreaterThan: 
5136         case Operator.OpType.LessThan: 
5137         case Operator.OpType.GreaterThanOrEqual:
5138         case Operator.OpType.LessThanOrEqual:
5139                 break;
5140                 
5141         default :
5142                 Location l = lexer.Location;
5143                 Report.Error (1020, l, "Overloadable binary operator expected");
5144                 break;
5145         }
5146         
5147 }
5148
5149 void syntax_error (Location l, string msg)
5150 {
5151         Report.Error (1003, l, "Syntax error, " + msg);
5152 }
5153
5154 void note (string s)
5155 {
5156         // Used to put annotations
5157 }
5158
5159 Tokenizer lexer;
5160
5161 public Tokenizer Lexer {
5162         get {
5163                 return lexer;
5164         }
5165 }                  
5166
5167 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5168 {
5169         current_namespace = new NamespaceEntry (null, file, null, Location.Null);
5170         this.name = file.Name;
5171         this.file = file;
5172         current_container = RootContext.Tree.Types;
5173         // TODO: Make RootContext.Tree.Types a PartialContainer.
5174         current_class = current_container;
5175         current_container.NamespaceEntry = current_namespace;
5176         oob_stack = new Stack ();
5177         switch_stack = new Stack ();
5178
5179         lexer = new Tokenizer (reader, file, defines);
5180 }
5181
5182 public void parse ()
5183 {
5184         try {
5185                 if (yacc_verbose_flag > 1)
5186                         yyparse (lexer, new yydebug.yyDebugSimple ());
5187                 else
5188                         yyparse (lexer);
5189                 Tokenizer tokenizer = lexer as Tokenizer;
5190                 tokenizer.cleanup ();
5191         } catch (Exception e){
5192                 //
5193                 // Removed for production use, use parser verbose to get the output.
5194                 //
5195                 // Console.WriteLine (e);
5196                 Report.Error (-25, lexer.Location, "Parsing error");
5197                 if (yacc_verbose_flag > 0)
5198                         Console.WriteLine (e);
5199         }
5200
5201         RootContext.Tree.Types.NamespaceEntry = null;
5202 }
5203
5204 void CheckToken (int error, int yyToken, string msg)
5205 {
5206         if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
5207                 Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
5208                 return;
5209         }               
5210         Report.Error (error, lexer.Location, msg);
5211 }
5212
5213 void CheckIdentifierToken (int yyToken)
5214 {
5215         CheckToken (1041, yyToken, "Identifier expected");
5216 }
5217
5218 string ConsumeStoredComment ()
5219 {
5220         string s = tmpComment;
5221         tmpComment = null;
5222         Lexer.doc_state = XmlCommentState.Allowed;
5223         return s;
5224 }
5225
5226 /* end end end */
5227 }