2002-12-11 Jeroen Janssen <japj@darius.demon.nl>
[mono.git] / mcs / mcs / 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 //
12 // TODO:
13 //   (1) Figure out why error productions dont work.  `type-declaration' is a
14 //       great spot to put an `error' because you can reproduce it with this input:
15 //       "public X { }"
16 //
17 //
18 using System.Text;
19 using System.IO;
20 using System;
21
22 namespace Mono.CSharp
23 {
24         using System.Collections;
25         using Mono.Languages;
26
27         /// <summary>
28         ///    The C# Parser
29         /// </summary>
30         public class CSharpParser : GenericParser {
31                 Namespace     current_namespace;
32                 TypeContainer current_container;
33         
34                 // <summary>
35                 //   Current block is used to add statements as we find
36                 //   them.  
37                 // </summary>
38
39                 Block      current_block;
40
41                 // <summary>
42                 //   Current interface is used by the various declaration
43                 //   productions in the interface declaration to "add"
44                 //   the interfaces as we find them.
45                 // </summary>
46                 Interface  current_interface;
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
79 %token EOF
80 %token NONE   /* This token is never returned by our lexer */
81 %token ERROR            // This is used not by the parser, but by the tokenizer.
82                         // do not remove.
83
84 /*
85  *These are the C# keywords
86  */
87 %token ABSTRACT 
88 %token AS
89 %token ADD
90 %token ASSEMBLY
91 %token BASE     
92 %token BOOL     
93 %token BREAK    
94 %token BYTE     
95 %token CASE     
96 %token CATCH    
97 %token CHAR     
98 %token CHECKED  
99 %token CLASS    
100 %token CONST    
101 %token CONTINUE 
102 %token DECIMAL  
103 %token DEFAULT  
104 %token DELEGATE 
105 %token DO       
106 %token DOUBLE   
107 %token ELSE     
108 %token ENUM     
109 %token EVENT    
110 %token EXPLICIT 
111 %token EXTERN   
112 %token FALSE    
113 %token FINALLY  
114 %token FIXED    
115 %token FLOAT    
116 %token FOR      
117 %token FOREACH  
118 %token GOTO     
119 %token IF       
120 %token IMPLICIT 
121 %token IN       
122 %token INT      
123 %token INTERFACE
124 %token INTERNAL 
125 %token IS       
126 %token LOCK     
127 %token LONG     
128 %token NAMESPACE
129 %token NEW      
130 %token NULL     
131 %token OBJECT   
132 %token OPERATOR 
133 %token OUT      
134 %token OVERRIDE 
135 %token PARAMS   
136 %token PRIVATE  
137 %token PROTECTED
138 %token PUBLIC   
139 %token READONLY 
140 %token REF      
141 %token RETURN   
142 %token REMOVE
143 %token SBYTE    
144 %token SEALED   
145 %token SHORT    
146 %token SIZEOF   
147 %token STACKALLOC
148 %token STATIC   
149 %token STRING   
150 %token STRUCT   
151 %token SWITCH   
152 %token THIS     
153 %token THROW    
154 %token TRUE     
155 %token TRY      
156 %token TYPEOF   
157 %token UINT     
158 %token ULONG    
159 %token UNCHECKED
160 %token UNSAFE   
161 %token USHORT   
162 %token USING    
163 %token VIRTUAL  
164 %token VOID     
165 %token VOLATILE
166 %token WHILE    
167
168 /* C# keywords which are not really keywords */
169 %token GET           "get"
170 %token SET           "set"
171
172 /* C# single character operators/punctuation. */
173 %token OPEN_BRACE    "{"
174 %token CLOSE_BRACE   "}"
175 %token OPEN_BRACKET  "["
176 %token CLOSE_BRACKET "]"
177 %token OPEN_PARENS   "("
178 %token CLOSE_PARENS  ")"
179 %token DOT           "."
180 %token COMMA         ","
181 %token COLON         ":"
182 %token SEMICOLON     ";"
183 %token TILDE         "~"
184
185 %token PLUS           "+"
186 %token MINUS          "-"
187 %token BANG           "!"
188 %token ASSIGN         "="
189 %token OP_LT          "<"
190 %token OP_GT          ">"
191 %token BITWISE_AND    "&"
192 %token BITWISE_OR     "|"
193 %token STAR           "*"
194 %token PERCENT        "%"
195 %token DIV            "/"
196 %token CARRET         "^"
197 %token INTERR         "?"
198
199 /* C# multi-character operators. */
200 %token OP_INC                 "++"
201 %token OP_DEC                 "--"
202 %token OP_SHIFT_LEFT          "<<"
203 %token OP_SHIFT_RIGHT         ">>"
204 %token OP_LE                  "<="
205 %token OP_GE                  ">="
206 %token OP_EQ                  "=="
207 %token OP_NE                  "!="
208 %token OP_AND                 "&&"
209 %token OP_OR                  "||"
210 %token OP_MULT_ASSIGN         "*="
211 %token OP_DIV_ASSIGN          "/="
212 %token OP_MOD_ASSIGN          "%="
213 %token OP_ADD_ASSIGN          "+="
214 %token OP_SUB_ASSIGN          "-="
215 %token OP_SHIFT_LEFT_ASSIGN   "<<="
216 %token OP_SHIFT_RIGHT_ASSIGN  ">>="
217 %token OP_AND_ASSIGN          "&="
218 %token OP_XOR_ASSIGN          "^="
219 %token OP_OR_ASSIGN           "|="
220 %token OP_PTR                 "->"
221
222 /* Numbers */
223 %token LITERAL_INTEGER           "int literal"
224 %token LITERAL_FLOAT             "float literal"
225 %token LITERAL_DOUBLE            "double literal"
226 %token LITERAL_DECIMAL           "decimal literal"
227 %token LITERAL_CHARACTER         "character literal"
228 %token LITERAL_STRING            "string literal"
229
230 %token IDENTIFIER
231
232 /* Add precedence rules to solve dangling else s/r conflict */
233 %nonassoc LOWPREC
234 %nonassoc IF
235 %nonassoc ELSE
236 %right ASSIGN
237 %left OP_OR
238 %left OP_AND
239 %left BITWISE_OR
240 %left BITWISE_AND
241 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
242 %left PLUS MINUS
243 %left STAR DIV PERCENT
244 %right BANG CARRET UMINUS
245 %nonassoc OP_INC OP_DEC
246 %left OPEN_PARENS
247 %left OPEN_BRACKET OPEN_BRACE
248 %left DOT
249 %nonassoc HIGHPREC
250
251 %start compilation_unit
252 %%
253
254 compilation_unit
255         : outer_declarations opt_EOF
256         | outer_declarations attribute_sections opt_EOF
257         | attribute_sections opt_EOF
258         | opt_EOF /* allow empty files */
259         ;
260         
261 opt_EOF
262         : /* empty */
263         | EOF
264         ;
265
266 outer_declarations
267         : outer_declaration
268         | outer_declarations outer_declaration
269         ;
270  
271 outer_declaration
272         : using_directive
273         | namespace_member_declaration
274         ;
275   
276 using_directives
277         : using_directive 
278         | using_directives using_directive
279         ;
280
281 using_directive
282         : using_alias_directive
283         | using_namespace_directive
284         ;
285
286 using_alias_directive
287         : USING IDENTIFIER ASSIGN 
288           namespace_or_type_name SEMICOLON
289           {
290                   current_namespace.UsingAlias ((string) $2, (string) $4, lexer.Location);
291           }
292         ;
293
294 using_namespace_directive
295         : USING namespace_name SEMICOLON 
296           {
297                 current_namespace.Using ((string) $2, lexer.Location);
298           }
299         ;
300
301 //
302 // Strictly speaking, namespaces don't have attributes but
303 // we parse global attributes along with namespace declarations and then
304 // detach them
305 // 
306 namespace_declaration
307         : opt_attributes NAMESPACE qualified_identifier 
308         {
309                 Attributes attrs = (Attributes) $1;
310
311                 if (attrs != null) {
312                         foreach (AttributeSection asec in attrs.AttributeSections)
313                                 if (asec.Target == "assembly")
314                                         RootContext.AddGlobalAttribute (
315                                                 current_container, asec, lexer.Location);
316                 }
317
318                 current_namespace = RootContext.Tree.RecordNamespace (current_namespace, name, (string) $3);
319         } 
320           namespace_body opt_semicolon
321           { 
322                 current_namespace = current_namespace.Parent;
323           }
324         ;
325
326 opt_semicolon
327         : /* empty */
328         | SEMICOLON
329         ;
330
331 opt_comma
332         : /* empty */
333         | COMMA
334         ;
335
336 qualified_identifier
337         : IDENTIFIER
338         | qualified_identifier DOT IDENTIFIER { 
339             $$ = (($1).ToString ()) + "." + ($3.ToString ()); }
340         ;
341
342
343 namespace_name
344         : namespace_or_type_name
345         ;
346
347 namespace_body
348         : OPEN_BRACE
349           opt_using_directives
350           opt_namespace_member_declarations
351           CLOSE_BRACE
352           {
353           }
354         ;
355
356 opt_using_directives
357         : /* empty */
358         | using_directives
359         ;
360
361 opt_namespace_member_declarations
362         : /* empty */
363         | namespace_member_declarations
364         ;
365
366 namespace_member_declarations
367         : namespace_member_declaration
368         | namespace_member_declarations namespace_member_declaration
369         ;
370
371 namespace_member_declaration
372         : type_declaration
373           {
374                 string name = "";
375                 int mod_flags;
376
377                 if ($1 is Class){
378                         Class c = (Class) $1;
379                         mod_flags = c.ModFlags;
380                         name = c.Name;
381                 } else if ($1 is Struct){
382                         Struct s = (Struct) $1;
383                         mod_flags = s.ModFlags;
384                         name = s.Name;
385                 } else
386                         break;
387
388                 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
389                         Report.Error (
390                                 1527, lexer.Location, 
391                                 "Namespace elements cant be explicitly " +
392                                 "declared private or protected in `" + name + "'");
393                 }
394                 current_namespace.DeclarationFound = true;
395           }
396         | namespace_declaration
397         ;
398
399 type_declaration
400         : class_declaration             
401         | struct_declaration            
402         | interface_declaration         
403         | enum_declaration              
404         | delegate_declaration
405 //
406 // Enable this when we have handled all errors, because this acts as a generic fallback
407 //
408 //      | error {
409 //              Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
410 //        }
411         ;
412
413 //
414 // Attributes 17.2
415 //
416
417 opt_attributes
418         : /* empty */
419         | attribute_sections { $$ = $1; }
420         ;
421  
422 attribute_sections
423         : attribute_section
424           {
425                 AttributeSection sect = (AttributeSection) $1;
426
427                 if (sect.Target == "assembly") 
428                         RootContext.AddGlobalAttribute (current_container, sect, lexer.Location);
429                 
430
431                 $$ = new Attributes ((AttributeSection) $1, lexer.Location);
432           }
433         | attribute_sections attribute_section
434           {
435                 Attributes attrs = null;
436                 AttributeSection sect = (AttributeSection) $2;
437
438                 if (sect.Target == "assembly")
439                         RootContext.AddGlobalAttribute (current_container, sect, lexer.Location);
440
441                 if ($1 != null) {
442                         attrs = (Attributes) $1;
443                         attrs.AddAttribute (sect);
444                 }
445                 
446                 $$ = attrs;
447           }
448         ;
449
450 attribute_section
451         : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
452           {
453                 string target = null;
454                 
455                 if ($2 != null)
456                         target = (string) $2;
457                 
458                 $$ = new AttributeSection (target, (ArrayList) $3);
459           }
460         | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
461           {
462                 $$ = new AttributeSection (null, (ArrayList) $2);
463           }
464         ;
465  
466 attribute_target_specifier
467         : attribute_target COLON
468           {
469                 $$ = $1;
470           }
471         ;
472
473 attribute_target
474         : IDENTIFIER
475           {
476                 CheckAttributeTarget ((string) $1);
477                 $$ = $1;
478           }
479         | EVENT  { $$ = "event"; }        
480         | RETURN { $$ = "return"; }
481         ;
482
483 attribute_list
484         : attribute
485           {
486                 ArrayList attrs = new ArrayList ();
487                 attrs.Add ($1);
488
489                 $$ = attrs;
490                
491           }
492         | attribute_list COMMA attribute
493           {
494                 ArrayList attrs = (ArrayList) $1;
495                 attrs.Add ($3);
496
497                 $$ = attrs;
498           }
499         ;
500
501 attribute
502         : attribute_name
503           {
504                 $$ = lexer.Location;
505           }
506           opt_attribute_arguments
507           {
508                 $$ = new Attribute ((string) $1, (ArrayList) $3, (Location) $2);
509           }
510         ;
511
512 attribute_name
513         : type_name  { /* reserved attribute name or identifier: 17.4 */ }
514         ;
515
516 opt_attribute_arguments
517         : /* empty */   { $$ = null; }
518         | OPEN_PARENS attribute_arguments CLOSE_PARENS
519           {
520                 $$ = $2;
521           }
522         ;
523
524
525 attribute_arguments
526         : opt_positional_argument_list
527           {
528                 if ($1 == null)
529                         $$ = null;
530                 else {
531                         ArrayList args = new ArrayList ();
532                         args.Add ($1);
533                 
534                         $$ = args;
535                 }
536           }
537         | positional_argument_list COMMA named_argument_list
538           {
539                 ArrayList args = new ArrayList ();
540                 args.Add ($1);
541                 args.Add ($3);
542
543                 $$ = args;
544           }
545         | named_argument_list
546           {
547                 ArrayList args = new ArrayList ();
548                 args.Add (null);
549                 args.Add ($1);
550                 
551                 $$ = args;
552           }
553         ;
554
555
556 opt_positional_argument_list
557         : /* empty */           { $$ = null; } 
558         | positional_argument_list
559         ;
560
561 positional_argument_list
562         : expression
563           {
564                 ArrayList args = new ArrayList ();
565                 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
566
567                 $$ = args;
568           }
569         | positional_argument_list COMMA expression
570          {
571                 ArrayList args = (ArrayList) $1;
572                 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
573
574                 $$ = args;
575          }
576         ;
577
578 named_argument_list
579         : named_argument
580           {
581                 ArrayList args = new ArrayList ();
582                 args.Add ($1);
583
584                 $$ = args;
585           }
586         | named_argument_list COMMA named_argument
587           {       
588                 ArrayList args = (ArrayList) $1;
589                 args.Add ($3);
590
591                 $$ = args;
592           }
593         ;
594
595 named_argument
596         : IDENTIFIER ASSIGN expression
597           {
598                 $$ = new DictionaryEntry (
599                         (string) $1, 
600                         new Argument ((Expression) $3, Argument.AType.Expression));
601           }
602         ;
603
604                   
605 class_body
606         :  OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
607         ;
608
609 opt_class_member_declarations
610         : /* empty */
611         | class_member_declarations
612         ;
613
614 class_member_declarations
615         : class_member_declaration
616         | class_member_declarations 
617           class_member_declaration
618         ;
619
620 class_member_declaration
621         : constant_declaration                  // done
622         | field_declaration                     // done
623         | method_declaration                    // done
624         | property_declaration                  // done
625         | event_declaration                     // done
626         | indexer_declaration                   // done
627         | operator_declaration                  // done
628         | constructor_declaration               // done
629         | destructor_declaration                // done
630         | type_declaration
631         ;
632
633 struct_declaration
634         : opt_attributes
635           opt_modifiers
636           STRUCT IDENTIFIER
637           { 
638                 Struct new_struct;
639                 string full_struct_name = MakeName ((string) $4);
640
641                 new_struct = new Struct (current_container, full_struct_name, (int) $2, 
642                                          (Attributes) $1, lexer.Location);
643                 current_container = new_struct;
644                 current_container.Namespace = current_namespace;
645                 RootContext.Tree.RecordDecl (full_struct_name, new_struct);
646           }
647           opt_class_base
648           struct_body
649           opt_semicolon
650           {
651                 Struct new_struct = (Struct) current_container;
652
653                 if ($6 != null)
654                         new_struct.Bases = (ArrayList) $6;
655
656                 current_container = current_container.Parent;
657                 CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
658                 $$ = new_struct;
659           }
660         ;
661
662 struct_body
663         : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
664         ;
665
666 opt_struct_member_declarations
667         : /* empty */
668         | struct_member_declarations
669         ;
670
671 struct_member_declarations
672         : struct_member_declaration
673         | struct_member_declarations struct_member_declaration
674         ;
675
676 struct_member_declaration
677         : constant_declaration
678         | field_declaration
679         | method_declaration
680         | property_declaration
681         | event_declaration
682         | indexer_declaration
683         | operator_declaration
684         | constructor_declaration
685         | type_declaration
686
687         /*
688          * This is only included so we can flag error 575: 
689          * destructors only allowed on class types
690          */
691         | destructor_declaration 
692         ;
693
694 constant_declaration
695         : opt_attributes 
696           opt_modifiers
697           CONST
698           type
699           constant_declarators
700           SEMICOLON
701           {
702                 foreach (VariableDeclaration constant in (ArrayList) $5){
703                         Location l = constant.Location;
704
705                         Const c = new Const (
706                                 (Expression) $4, (string) constant.identifier, 
707                                 (Expression) constant.expression_or_array_initializer, (int) $2, 
708                                 (Attributes) $1, l);
709
710                         CheckDef (current_container.AddConstant (c), c.Name, l);
711                 }
712           }
713         ;
714
715 constant_declarators
716         : constant_declarator 
717           {
718                 ArrayList constants = new ArrayList ();
719                 constants.Add ($1);
720                 $$ = constants;
721           }
722         | constant_declarators COMMA constant_declarator
723           {
724                 ArrayList constants = (ArrayList) $1;
725
726                 constants.Add ($3);
727           }
728         ;
729
730 constant_declarator
731         : IDENTIFIER ASSIGN constant_expression
732           {
733                 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
734           }
735         ;
736
737 field_declaration
738         : opt_attributes
739           opt_modifiers
740           type 
741           variable_declarators
742           SEMICOLON
743           { 
744                 Expression type = (Expression) $3;
745                 int mod = (int) $2;
746
747                 foreach (VariableDeclaration var in (ArrayList) $4){
748                         Location l = var.Location;
749
750                         Field field = new Field (type, mod, var.identifier, 
751                                                  var.expression_or_array_initializer, 
752                                                  (Attributes) $1, l);
753
754                         CheckDef (current_container.AddField (field), field.Name, l);
755                 }
756           }
757         ;
758
759 variable_declarators
760         : variable_declarator 
761           {
762                 ArrayList decl = new ArrayList ();
763                 decl.Add ($1);
764                 $$ = decl;
765           }
766         | variable_declarators COMMA variable_declarator
767           {
768                 ArrayList decls = (ArrayList) $1;
769                 decls.Add ($3);
770                 $$ = $1;
771           }
772         ;
773
774 variable_declarator
775         : IDENTIFIER ASSIGN variable_initializer
776           {
777                 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
778           }
779         | IDENTIFIER
780           {
781                 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
782           }
783         ;
784
785 variable_initializer
786         : expression
787           {
788                 $$ = $1;
789           }
790         | array_initializer
791           {
792                 $$ = $1;
793           }
794         | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
795           {
796                 $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
797           }
798         ;
799
800 method_declaration
801         : method_header
802           method_body
803           {
804                 Method method = (Method) $1;
805                 Block b = (Block) $2;
806                 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
807
808                 if (b == null){
809                         if ((method.ModFlags & extern_abstract) == 0){
810                                 Report.Error (
811                                         501, lexer.Location,  current_container.MakeName (method.Name) +
812                                         "must declare a body because it is not marked abstract or extern");
813                         }
814                 } else {
815                         if ((method.ModFlags & Modifiers.EXTERN) != 0){
816                                 Report.Error (
817                                         179, lexer.Location, current_container.MakeName (method.Name) +
818                                         " is declared extern, but has a body");
819                         }
820                 }
821
822                 method.Block = (Block) $2;
823                 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
824
825                 current_local_parameters = null;
826           }
827         ;
828
829 opt_error_modifier
830         : /* empty */
831         | modifiers 
832           {
833                 int m = (int) $1;
834                 int i = 1;
835
836                 while (m != 0){
837                         if ((i & m) != 0){
838                                 Report.Error (
839                                         1585, lexer.Location, "Member modifier `" + 
840                                         Modifiers.Name (i) + "' must precede member type and name");
841                         }
842                         m &= ~i;
843                         i = i << 1;
844                 }
845           }
846         ;
847
848 method_header
849         : opt_attributes
850           opt_modifiers
851           type
852           member_name
853           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
854           {
855                 Method method = new Method ((Expression) $3, (int) $2, (string) $4, 
856                                             (Parameters) $6, (Attributes) $1, lexer.Location);
857
858                 current_local_parameters = (Parameters) $6;
859
860                 $$ = method;
861           }
862         | opt_attributes
863           opt_modifiers
864           VOID
865           member_name
866           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
867           {
868                 Method method = new Method (TypeManager.system_void_expr, (int) $2, (string) $4, 
869                                             (Parameters) $6, (Attributes) $1, lexer.Location);
870
871                 current_local_parameters = (Parameters) $6;
872                 $$ = method;
873           }
874         ;
875
876 method_body
877         : block
878         | SEMICOLON             { $$ = null; }
879         ;
880
881 opt_formal_parameter_list
882         : /* empty */                   { $$ = Parameters.EmptyReadOnlyParameters; }
883         | formal_parameter_list
884         ;
885
886 formal_parameter_list
887         : fixed_parameters              
888           { 
889                 ArrayList pars_list = (ArrayList) $1;
890
891                 Parameter [] pars = new Parameter [pars_list.Count];
892                 pars_list.CopyTo (pars);
893
894                 $$ = new Parameters (pars, null, lexer.Location); 
895           } 
896         | fixed_parameters COMMA parameter_array
897           {
898                 ArrayList pars_list = (ArrayList) $1;
899
900                 Parameter [] pars = new Parameter [pars_list.Count];
901                 pars_list.CopyTo (pars);
902
903                 $$ = new Parameters (pars, (Parameter) $3, lexer.Location); 
904           }
905         | parameter_array 
906           {
907                 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
908           }
909         ;
910
911 fixed_parameters
912         : fixed_parameter       
913           {
914                 ArrayList pars = new ArrayList ();
915
916                 pars.Add ($1);
917                 $$ = pars;
918           }
919         | fixed_parameters COMMA fixed_parameter
920           {
921                 ArrayList pars = (ArrayList) $1;
922
923                 pars.Add ($3);
924                 $$ = $1;
925           }
926         ;
927
928 fixed_parameter
929         : opt_attributes
930           opt_parameter_modifier
931           type
932           IDENTIFIER
933           {
934                 $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
935           }
936         ;
937
938 opt_parameter_modifier
939         : /* empty */           { $$ = Parameter.Modifier.NONE; }
940         | parameter_modifier
941         ;
942
943 parameter_modifier
944         : REF                   { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
945         | OUT                   { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
946         ;
947
948 parameter_array
949         : opt_attributes PARAMS type IDENTIFIER
950           { 
951                 $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
952                 note ("type must be a single-dimension array type"); 
953           }
954         ;
955
956 member_name 
957         : qualified_identifier
958         ;
959
960 property_declaration
961         : opt_attributes
962           opt_modifiers
963           type member_name
964           OPEN_BRACE 
965           {
966                 implicit_value_parameter_type = (Expression) $3;
967
968                 lexer.PropertyParsing = true;
969
970                 $$ = lexer.Location;
971           }
972           accessor_declarations 
973           {
974                 lexer.PropertyParsing = false;
975           }
976           CLOSE_BRACE
977           { 
978                 Property prop;
979                 Pair pair = (Pair) $7;
980                 Accessor get_block = (Accessor) pair.First;
981                 Accessor set_block = (Accessor) pair.Second;
982
983                 Location loc = (Location) $6;
984                 prop = new Property ((Expression) $3, (string) $4, (int) $2, get_block, set_block,
985                                      (Attributes) $1, loc);
986                 
987                 CheckDef (current_container.AddProperty (prop), prop.Name, loc);
988                 implicit_value_parameter_type = null;
989           }
990         ;
991
992 accessor_declarations
993         : get_accessor_declaration opt_set_accessor_declaration
994           { 
995                 $$ = new Pair ($1, $2);
996           }
997         | set_accessor_declaration opt_get_accessor_declaration
998           {
999                 $$ = new Pair ($2, $1);
1000           }
1001         ;
1002
1003 opt_get_accessor_declaration
1004         : /* empty */                   { $$ = null; }
1005         | get_accessor_declaration
1006         ;
1007
1008 opt_set_accessor_declaration
1009         : /* empty */                   { $$ = null; }
1010         | set_accessor_declaration
1011         ;
1012
1013 get_accessor_declaration
1014         : opt_attributes GET
1015           {
1016                 // If this is not the case, then current_local_parameters has already
1017                 // been set in indexer_declaration
1018                 if (parsing_indexer == false)
1019                         current_local_parameters = null;
1020                 else 
1021                         current_local_parameters = indexer_parameters;
1022                 lexer.PropertyParsing = false;
1023           }
1024           accessor_body
1025           {
1026                 $$ = new Accessor ((Block) $4, (Attributes) $1);
1027                 current_local_parameters = null;
1028                 lexer.PropertyParsing = true;
1029           }
1030         ;
1031
1032 set_accessor_declaration
1033         : opt_attributes SET 
1034           {
1035                 Parameter [] args;
1036                 Parameter implicit_value_parameter = new Parameter (
1037                         implicit_value_parameter_type, "value", 
1038                         Parameter.Modifier.NONE, null);
1039
1040                 if (parsing_indexer == false) {
1041                         args  = new Parameter [1];
1042                         args [0] = implicit_value_parameter;
1043                         current_local_parameters = new Parameters (args, null, lexer.Location);
1044                 } else {
1045                         Parameter [] fpars = indexer_parameters.FixedParameters;
1046
1047                         if (fpars != null){
1048                                 int count = fpars.Length;
1049
1050                                 args = new Parameter [count + 1];
1051                                 fpars.CopyTo (args, 0);
1052                                 args [count] = implicit_value_parameter;
1053                         } else 
1054                                 args = null;
1055                         current_local_parameters = new Parameters (
1056                                 args, indexer_parameters.ArrayParameter, lexer.Location);
1057                 }
1058                 
1059                 lexer.PropertyParsing = false;
1060           }
1061           accessor_body
1062           {
1063                 $$ = new Accessor ((Block) $4, (Attributes) $1);
1064                 current_local_parameters = null;
1065                 lexer.PropertyParsing = true;
1066           }
1067         ;
1068
1069 accessor_body
1070         : block 
1071         | SEMICOLON             { $$ = null; }
1072         ;
1073
1074 interface_declaration
1075         : opt_attributes
1076           opt_modifiers
1077           INTERFACE IDENTIFIER
1078           {
1079                 Interface new_interface;
1080                 string full_interface_name = MakeName ((string) $4);
1081
1082                 new_interface = new Interface (current_container, full_interface_name, (int) $2, 
1083                                                (Attributes) $1, lexer.Location);
1084                 if (current_interface != null) {
1085                         Location l = lexer.Location;
1086                         Report.Error (-2, l, "Internal compiler error: interface inside interface");
1087                 }
1088                 current_interface = new_interface;
1089                 new_interface.Namespace = current_namespace;
1090                 RootContext.Tree.RecordDecl (full_interface_name, new_interface);
1091           }
1092           opt_interface_base
1093           interface_body opt_semicolon
1094           { 
1095                 Interface new_interface = (Interface) current_interface;
1096
1097                 if ($6 != null)
1098                         new_interface.Bases = (ArrayList) $6;
1099
1100                 current_interface = null;
1101                 CheckDef (current_container.AddInterface (new_interface), 
1102                           new_interface.Name, new_interface.Location);
1103           }
1104         ;
1105
1106 opt_interface_base
1107         : /* empty */                     { $$ = null; }
1108         | interface_base
1109         ;
1110
1111 interface_base
1112         : COLON interface_type_list       { $$ = $2; }
1113         ;
1114
1115 interface_type_list
1116         : interface_type
1117           {
1118                 ArrayList interfaces = new ArrayList ();
1119
1120                 interfaces.Add ($1);
1121                 $$ = interfaces;
1122           }
1123         | interface_type_list COMMA interface_type
1124           {
1125                 ArrayList interfaces = (ArrayList) $1;
1126                 interfaces.Add ($3);
1127                 $$ = interfaces;
1128           }
1129         ;
1130
1131 interface_body
1132         : OPEN_BRACE
1133           opt_interface_member_declarations
1134           CLOSE_BRACE
1135         ;
1136
1137 opt_interface_member_declarations
1138         : /* empty */
1139         | interface_member_declarations
1140         ;
1141
1142 interface_member_declarations
1143         : interface_member_declaration
1144         | interface_member_declarations interface_member_declaration
1145         ;
1146
1147 interface_member_declaration
1148         : interface_method_declaration          
1149           { 
1150                 InterfaceMethod m = (InterfaceMethod) $1;
1151
1152                 CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
1153           }
1154         | interface_property_declaration        
1155           { 
1156                 InterfaceProperty p = (InterfaceProperty) $1;
1157
1158                 CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
1159           }
1160         | interface_event_declaration 
1161           { 
1162                 InterfaceEvent e = (InterfaceEvent) $1;
1163
1164                 CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
1165           }
1166         | interface_indexer_declaration
1167           { 
1168                 InterfaceIndexer i = (InterfaceIndexer) $1;
1169
1170                 CheckDef (current_interface.AddIndexer (i), "indexer", i.Location);
1171           }
1172         ;
1173
1174 opt_new
1175         : /* empty */   { $$ = false; }
1176         | NEW           { $$ = true; }
1177         ;
1178
1179 interface_method_declaration
1180         : opt_attributes opt_new type IDENTIFIER 
1181           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1182           SEMICOLON
1183           {
1184                 $$ = new InterfaceMethod ((Expression) $3, (string) $4, (bool) $2, 
1185                                           (Parameters) $6, (Attributes) $1, lexer.Location);
1186           }
1187         | opt_attributes opt_new VOID IDENTIFIER 
1188           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1189           SEMICOLON
1190           {
1191                 $$ = new InterfaceMethod (
1192                         TypeManager.system_void_expr, (string) $4, (bool) $2, (Parameters) $6, 
1193                                           (Attributes) $1, lexer.Location);
1194           }
1195         ;
1196
1197 interface_property_declaration
1198         : opt_attributes
1199           opt_new
1200           type IDENTIFIER 
1201           OPEN_BRACE 
1202           { lexer.PropertyParsing = true; }
1203           interface_accesors 
1204           { lexer.PropertyParsing = false; }
1205           CLOSE_BRACE
1206           {
1207                 int gs = (int) $7;
1208
1209                 $$ = new InterfaceProperty ((Expression) $3, (string) $4, (bool) $2, 
1210                                             (gs & 1) == 1, (gs & 2) == 2, (Attributes) $1,
1211                                             lexer.Location);
1212           }
1213         ;
1214
1215 interface_accesors
1216         : opt_attributes GET SEMICOLON          { $$ = 1; }
1217         | opt_attributes SET SEMICOLON          { $$ = 2; }
1218         | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON 
1219           { $$ = 3; }
1220         | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1221           { $$ = 3; }
1222         ;
1223
1224 interface_event_declaration
1225         : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1226           {
1227                 $$ = new InterfaceEvent ((Expression) $4, (string) $5, (bool) $2, (Attributes) $1,
1228                                          lexer.Location);
1229           }
1230         ;
1231
1232 interface_indexer_declaration 
1233         : opt_attributes opt_new type THIS 
1234           OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1235           OPEN_BRACE 
1236           { lexer.PropertyParsing = true; }
1237           interface_accesors 
1238           { lexer.PropertyParsing = false; }
1239           CLOSE_BRACE
1240           {
1241                 int a_flags = (int) $10;
1242
1243                 bool do_get = (a_flags & 1) == 1;
1244                 bool do_set = (a_flags & 2) == 2;
1245
1246                 $$ = new InterfaceIndexer ((Expression) $3, (Parameters) $6, do_get, do_set,
1247                                            (bool) $2, (Attributes) $1, lexer.Location);
1248           }
1249         ;
1250
1251 operator_declaration
1252         : opt_attributes opt_modifiers operator_declarator operator_body
1253           {
1254                 OperatorDeclaration decl = (OperatorDeclaration) $3;
1255                 
1256                 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1257                                             decl.arg2type, decl.arg2name, (Block) $4, (Attributes) $1, decl.location);
1258
1259                 // Note again, checking is done in semantic analysis
1260                 current_container.AddOperator (op);
1261
1262                 current_local_parameters = null;
1263           }
1264         ;
1265
1266 operator_body 
1267         : block
1268         | SEMICOLON { $$ = null; }
1269         ; 
1270 operator_declarator
1271         : type OPERATOR overloadable_operator 
1272           OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1273         {
1274                 Operator.OpType op = (Operator.OpType) $3;
1275                 CheckUnaryOperator (op);
1276
1277                 if (op == Operator.OpType.Addition)
1278                         op = Operator.OpType.UnaryPlus;
1279
1280                 if (op == Operator.OpType.Subtraction)
1281                         op = Operator.OpType.UnaryNegation;
1282
1283                 Parameter [] pars = new Parameter [1];
1284
1285                 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1286
1287                 current_local_parameters = new Parameters (pars, null, lexer.Location);
1288
1289                 $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
1290                                               null, null, lexer.Location);
1291         }
1292         | type OPERATOR overloadable_operator
1293           OPEN_PARENS 
1294                 type IDENTIFIER COMMA
1295                 type IDENTIFIER 
1296           CLOSE_PARENS
1297         {
1298                CheckBinaryOperator ((Operator.OpType) $3);
1299
1300                Parameter [] pars = new Parameter [2];
1301
1302                pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1303                pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
1304
1305                current_local_parameters = new Parameters (pars, null, lexer.Location);
1306                
1307                $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1, 
1308                                              (Expression) $5, (string) $6,
1309                                              (Expression) $8, (string) $9, lexer.Location);
1310         }
1311         | conversion_operator_declarator
1312         ;
1313
1314 overloadable_operator
1315 // Unary operators:
1316         : BANG   { $$ = Operator.OpType.LogicalNot; }
1317         | TILDE  { $$ = Operator.OpType.OnesComplement; }  
1318         | OP_INC { $$ = Operator.OpType.Increment; }
1319         | OP_DEC { $$ = Operator.OpType.Decrement; }
1320         | TRUE   { $$ = Operator.OpType.True; }
1321         | FALSE  { $$ = Operator.OpType.False; }
1322 // Unary and binary:
1323         | PLUS { $$ = Operator.OpType.Addition; }
1324         | MINUS { $$ = Operator.OpType.Subtraction; }
1325 // Binary:
1326         | STAR { $$ = Operator.OpType.Multiply; }
1327         | DIV {  $$ = Operator.OpType.Division; }
1328         | PERCENT { $$ = Operator.OpType.Modulus; }
1329         | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1330         | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1331         | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1332         | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1333         | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1334         | OP_EQ { $$ = Operator.OpType.Equality; }
1335         | OP_NE { $$ = Operator.OpType.Inequality; }
1336         | OP_GT { $$ = Operator.OpType.GreaterThan; }
1337         | OP_LT { $$ = Operator.OpType.LessThan; }
1338         | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1339         | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1340         ;
1341
1342 conversion_operator_declarator
1343         : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1344           {
1345                 Parameter [] pars = new Parameter [1];
1346
1347                 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1348
1349                 current_local_parameters = new Parameters (pars, null, lexer.Location);  
1350                   
1351                 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
1352                                               null, null, lexer.Location);
1353           }
1354         | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1355           {
1356                 Parameter [] pars = new Parameter [1];
1357
1358                 pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
1359
1360                 current_local_parameters = new Parameters (pars, null, lexer.Location);  
1361                   
1362                 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
1363                                               null, null, lexer.Location);
1364           }
1365         | IMPLICIT error 
1366           {
1367                 syntax_error (lexer.Location, "'operator' expected");
1368           }
1369         | EXPLICIT error 
1370           {
1371                 syntax_error (lexer.Location, "'operator' expected");
1372           }
1373         ;
1374
1375 constructor_declaration
1376         : opt_attributes
1377           opt_modifiers
1378           constructor_declarator
1379           constructor_body
1380           { 
1381                 Constructor c = (Constructor) $3;
1382                 c.Block = (Block) $4;
1383                 c.OptAttributes = (Attributes) $1;
1384         
1385                 if ((c.ModFlags & Modifiers.STATIC) != 0){
1386                         c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, 0, c.Location);   
1387
1388                         if ((c.ModFlags & Modifiers.Accessibility) != 0) {
1389                                 Report.Error (
1390                                         515, c.Location, 
1391                                         "Access modifiers are not allowed on static constructors");
1392                         }
1393
1394                         if (c.Initializer != null){
1395                                 Report.Error (
1396                                         514, c.Location, 
1397                                         "Static constructors can not have an explicit this or base " +
1398                                         "constructor invocations");
1399                         }
1400
1401                         if (!c.Parameters.Empty){
1402                                 Report.Error (
1403                                         132, c.Location, "Static constructors should not have parameters");
1404                         }
1405                 } else {
1406                         c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
1407                 }
1408                 
1409                 CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
1410
1411                 current_local_parameters = null;
1412           }
1413         ;
1414
1415 constructor_declarator
1416         : IDENTIFIER 
1417           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
1418           {
1419                 oob_stack.Push (lexer.Location);
1420
1421                 current_local_parameters = (Parameters) $3;
1422           }
1423           opt_constructor_initializer
1424           {
1425                 Location l = (Location) oob_stack.Pop ();
1426                 $$ = new Constructor ((string) $1, (Parameters) $3, (ConstructorInitializer) $6, l);
1427           }
1428         ;
1429
1430 constructor_body
1431         : block
1432         | SEMICOLON             { $$ = null; }
1433         ;
1434
1435 opt_constructor_initializer
1436         : /* empty */                   { $$ = null; }
1437         | constructor_initializer
1438         ;
1439
1440 constructor_initializer
1441         : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1442           {
1443                 $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1444           }
1445         | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1446           {
1447                 $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
1448           }
1449         ;
1450
1451 destructor_declaration
1452         : opt_attributes TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1453           {
1454                 if ((string) $3 != current_container.Basename){
1455                         Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1456                 } else if (!(current_container is Class)){
1457                         Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1458                 } else {
1459                         Location l = lexer.Location;
1460
1461                         int m;
1462                         if (!RootContext.StdLib && current_container.Name == "System.Object")
1463                                 m = Modifiers.PROTECTED | Modifiers.VIRTUAL;
1464                         else
1465                                 m = Modifiers.PROTECTED | Modifiers.OVERRIDE;
1466
1467                         Method d = new Method (
1468                                 TypeManager.system_void_expr, m, "Finalize", 
1469                                 new Parameters (null, null, l), (Attributes) $1, l);
1470                   
1471                         d.Block = (Block) $6;
1472                         CheckDef (current_container.AddMethod (d), d.Name, d.Location);
1473                 }
1474           }
1475         ;
1476
1477 event_declaration
1478         : opt_attributes
1479           opt_modifiers
1480           EVENT type variable_declarators SEMICOLON
1481           {
1482                 foreach (VariableDeclaration var in (ArrayList) $5) {
1483
1484                         Event e = new Event ((Expression) $4, var.identifier, 
1485                                              var.expression_or_array_initializer,
1486                                              (int) $2, null, null, (Attributes) $1, lexer.Location);
1487
1488                         CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1489                                        
1490                 }
1491           }
1492         | opt_attributes
1493           opt_modifiers
1494           EVENT type member_name
1495           OPEN_BRACE
1496           {
1497                 implicit_value_parameter_type = (Expression) $4;  
1498                 lexer.EventParsing = true;
1499                 oob_stack.Push (lexer.Location);
1500           }
1501           event_accessor_declarations
1502           {
1503                 lexer.EventParsing = false;  
1504           }
1505           CLOSE_BRACE
1506           {
1507                 Location loc = (Location) oob_stack.Pop ();
1508
1509                 Pair pair = (Pair) $8;
1510                 Accessor add_accessor = null;
1511                 Accessor rem_accessor = null;
1512
1513                 if (pair.First != null)
1514                         add_accessor = (Accessor) pair.First;
1515                 if (pair.Second != null)
1516                         rem_accessor = (Accessor) pair.Second;
1517                 
1518                 Event e = new Event ((Expression) $4, (string) $5, null, (int) $2, add_accessor, rem_accessor,
1519                                      (Attributes) $1, loc);
1520                 
1521                 CheckDef (current_container.AddEvent (e), e.Name, loc);
1522                 implicit_value_parameter_type = null;
1523           }
1524         ;
1525
1526 event_accessor_declarations
1527         : add_accessor_declaration remove_accessor_declaration
1528         {
1529                 $$ = new Pair ($1, $2);
1530         }
1531         | remove_accessor_declaration add_accessor_declaration
1532         {
1533                 $$ = new Pair ($2, $1);
1534         }       
1535         ;
1536
1537 add_accessor_declaration
1538         : opt_attributes ADD
1539           {
1540                 Parameter [] args = new Parameter [1];
1541                 Parameter implicit_value_parameter = new Parameter (
1542                         implicit_value_parameter_type, "value", 
1543                         Parameter.Modifier.NONE, null);
1544
1545                 args [0] = implicit_value_parameter;
1546                 
1547                 current_local_parameters = new Parameters (args, null, lexer.Location);  
1548                 lexer.EventParsing = false;
1549           }
1550           block
1551           {
1552                 $$ = new Accessor ((Block) $4, (Attributes) $1);
1553                 lexer.EventParsing = true;
1554           }
1555         ;
1556
1557 remove_accessor_declaration
1558         : opt_attributes REMOVE
1559           {
1560                 Parameter [] args = new Parameter [1];
1561                 Parameter implicit_value_parameter = new Parameter (
1562                         implicit_value_parameter_type, "value", 
1563                         Parameter.Modifier.NONE, null);
1564
1565                 args [0] = implicit_value_parameter;
1566                 
1567                 current_local_parameters = new Parameters (args, null, lexer.Location);  
1568                 lexer.EventParsing = false;
1569           }
1570           block
1571           {
1572                 $$ = new Accessor ((Block) $4, (Attributes) $1);
1573                 lexer.EventParsing = true;
1574           }
1575         ;
1576
1577 indexer_declaration
1578         : opt_attributes opt_modifiers indexer_declarator 
1579           OPEN_BRACE 
1580           {
1581                 IndexerDeclaration decl = (IndexerDeclaration) $3;
1582
1583                 implicit_value_parameter_type = decl.type;
1584                 
1585                 lexer.PropertyParsing = true;
1586                 parsing_indexer  = true;
1587                 
1588                 indexer_parameters = decl.param_list;
1589                 oob_stack.Push (lexer.Location);
1590           }
1591           accessor_declarations 
1592           {
1593                   lexer.PropertyParsing = false;
1594                   parsing_indexer  = false;
1595           }
1596           CLOSE_BRACE
1597           { 
1598                 // The signature is computed from the signature of the indexer.  Look
1599                 // at section 3.6 on the spec
1600                 Location loc = (Location) oob_stack.Pop ();
1601                 Indexer indexer;
1602                 IndexerDeclaration decl = (IndexerDeclaration) $3;
1603                 Pair pair = (Pair) $6;
1604                 Accessor get_block = (Accessor) pair.First;
1605                 Accessor set_block = (Accessor) pair.Second;
1606
1607                 indexer = new Indexer (decl.type, decl.interface_type, (int) $2, decl.param_list,
1608                                        get_block, set_block, (Attributes) $1, loc);
1609
1610                 // Note that there is no equivalent of CheckDef for this case
1611                 // We shall handle this in semantic analysis
1612                 
1613                 current_container.AddIndexer (indexer);
1614                 
1615                 current_local_parameters = null;
1616                 implicit_value_parameter_type = null;
1617                 indexer_parameters = null;
1618           }
1619         ;
1620
1621 indexer_declarator
1622         : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1623           {
1624                 Parameters pars = (Parameters) $4;
1625
1626                 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1627                         Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1628                 }
1629
1630                 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1631           }
1632         | type qualified_identifier DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1633           {
1634                 Parameters pars = (Parameters) $6;
1635
1636                 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1637                         Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1638                 }
1639                 $$ = new IndexerDeclaration ((Expression) $1, (string) $2, pars);
1640           }
1641         ;
1642
1643 enum_declaration
1644         : opt_attributes
1645           opt_modifiers
1646           ENUM IDENTIFIER 
1647           opt_enum_base
1648           enum_body
1649           opt_semicolon
1650           { 
1651                 Location enum_location = lexer.Location;
1652
1653                 string full_name = MakeName ((string) $4);
1654                 Enum e = new Enum (current_container, (Expression) $5, (int) $2, full_name, 
1655                                    (Attributes) $1, enum_location);
1656                 
1657                 foreach (VariableDeclaration ev in (ArrayList) $6) {
1658                         Location loc = (Location) ev.Location;
1659
1660                         CheckDef (e.AddEnumMember (ev.identifier, 
1661                                                    (Expression) ev.expression_or_array_initializer,
1662                                                    loc, ev.OptAttributes),
1663                                   ev.identifier, loc);
1664                 }
1665
1666                 e.Namespace = current_namespace;
1667
1668                 CheckDef (current_container.AddEnum (e), full_name, enum_location);
1669                 RootContext.Tree.RecordDecl (full_name, e);
1670
1671           }
1672         ;
1673
1674 opt_enum_base
1675         : /* empty */           { $$ = TypeManager.system_int32_expr; }
1676         | COLON type            { $$ = $2;   }
1677         ;
1678
1679 enum_body
1680         : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1681           {
1682                 $$ = $2;
1683           }
1684         ;
1685
1686 opt_enum_member_declarations
1687         : /* empty */                   { $$ = new ArrayList (); }
1688         | enum_member_declarations opt_comma { $$ = $1; }
1689         ;
1690
1691 enum_member_declarations
1692         : enum_member_declaration 
1693           {
1694                 ArrayList l = new ArrayList ();
1695
1696                 l.Add ($1);
1697                 $$ = l;
1698           }
1699         | enum_member_declarations COMMA enum_member_declaration
1700           {
1701                 ArrayList l = (ArrayList) $1;
1702
1703                 l.Add ($3);
1704
1705                 $$ = l;
1706           }
1707         ;
1708
1709 enum_member_declaration
1710         : opt_attributes IDENTIFIER 
1711           {
1712                 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
1713           }
1714         | opt_attributes IDENTIFIER
1715           {
1716                   $$ = lexer.Location;
1717           }
1718           ASSIGN expression
1719           { 
1720                 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
1721           }
1722         ;
1723
1724 delegate_declaration
1725         : opt_attributes
1726           opt_modifiers
1727           DELEGATE type   
1728           IDENTIFIER OPEN_PARENS 
1729           opt_formal_parameter_list
1730           CLOSE_PARENS 
1731           SEMICOLON
1732           {
1733                 Location l = lexer.Location;
1734                 Delegate del = new Delegate (current_container, (Expression) $4, (int) $2, 
1735                                              MakeName ((string) $5), (Parameters) $7, 
1736                                              (Attributes) $1, l);
1737                   
1738                 del.Namespace = current_namespace;
1739                 CheckDef (current_container.AddDelegate (del), del.Name, l);
1740           }     
1741         | opt_attributes
1742           opt_modifiers
1743           DELEGATE VOID   
1744           IDENTIFIER OPEN_PARENS 
1745           opt_formal_parameter_list
1746           CLOSE_PARENS 
1747           SEMICOLON
1748           {
1749                 Location l = lexer.Location;
1750                 Delegate del = new Delegate (
1751                         current_container,
1752                         TypeManager.system_void_expr, (int) $2, MakeName ((string) $5), 
1753                         (Parameters) $7, (Attributes) $1, l);
1754
1755                 del.Namespace = current_namespace;
1756                 CheckDef (current_container.AddDelegate (del), del.Name, l);
1757           }
1758         ;
1759
1760 type_name
1761         : namespace_or_type_name
1762         ;
1763
1764 namespace_or_type_name
1765         : qualified_identifier
1766         ;
1767
1768 /* 
1769  * Before you think of adding a return_type, notice that we have been
1770  * using two rules in the places where it matters (one rule using type
1771  * and another identical one that uses VOID as the return type).  This
1772  * gets rid of a shift/reduce couple
1773  */
1774 type
1775         : type_name {   /* class_type */
1776                 /* 
1777                    This does interfaces, delegates, struct_types, class_types, 
1778                    parent classes, and more! 4.2 
1779                  */
1780                 $$ = DecomposeQI ((string) $1, lexer.Location);
1781           }
1782         | builtin_types
1783         | array_type
1784         | pointer_type    
1785         ;
1786
1787
1788 pointer_type
1789         : type STAR
1790           {
1791                 //
1792                 // Note that here only unmanaged types are allowed but we
1793                 // can't perform checks during this phase - we do it during
1794                 // semantic analysis.
1795                 //
1796                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
1797           }
1798         | VOID STAR
1799           {
1800                 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
1801           }
1802         ;
1803
1804 non_expression_type
1805         : builtin_types 
1806         | non_expression_type rank_specifier
1807           {
1808                 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1809           }
1810         | non_expression_type STAR
1811           {
1812                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
1813           }
1814         | expression rank_specifiers 
1815           {
1816                 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1817           }
1818         | expression STAR 
1819           {
1820                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
1821           }
1822         
1823         //
1824         // We need this because the parser will happily go and reduce IDENTIFIER STAR
1825         // through this different path
1826         //
1827         | multiplicative_expression STAR 
1828           {
1829                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
1830           }
1831         ;
1832
1833 type_list
1834         : type
1835           {
1836                 ArrayList types = new ArrayList ();
1837
1838                 types.Add ($1);
1839                 $$ = types;
1840           }
1841         | type_list COMMA type
1842           {
1843                 ArrayList types = (ArrayList) $1;
1844
1845                 types.Add ($3);
1846                 $$ = types;
1847           }
1848         ;
1849
1850 /*
1851  * replaces all the productions for isolating the various
1852  * simple types, but we need this to reuse it easily in local_variable_type
1853  */
1854 builtin_types
1855         : OBJECT        { $$ = TypeManager.system_object_expr; }
1856         | STRING        { $$ = TypeManager.system_string_expr; }
1857         | BOOL          { $$ = TypeManager.system_boolean_expr; }
1858         | DECIMAL       { $$ = TypeManager.system_decimal_expr; }
1859         | FLOAT         { $$ = TypeManager.system_single_expr; }
1860         | DOUBLE        { $$ = TypeManager.system_double_expr; }
1861         | integral_type
1862         ;
1863
1864 integral_type
1865         : SBYTE         { $$ = TypeManager.system_sbyte_expr; }
1866         | BYTE          { $$ = TypeManager.system_byte_expr; }
1867         | SHORT         { $$ = TypeManager.system_int16_expr; }
1868         | USHORT        { $$ = TypeManager.system_uint16_expr; }
1869         | INT           { $$ = TypeManager.system_int32_expr; }
1870         | UINT          { $$ = TypeManager.system_uint32_expr; }
1871         | LONG          { $$ = TypeManager.system_int64_expr; }
1872         | ULONG         { $$ = TypeManager.system_uint64_expr; }
1873         | CHAR          { $$ = TypeManager.system_char_expr; }
1874         | VOID          { $$ = TypeManager.system_void_expr; }
1875         ;
1876
1877 interface_type
1878         : type_name
1879         ;
1880
1881 array_type
1882         : type rank_specifiers
1883           {
1884                 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1885           }
1886         ;
1887
1888 //
1889 // Expressions, section 7.5
1890 //
1891 primary_expression
1892         : literal
1893           {
1894                 // 7.5.1: Literals
1895           }
1896  
1897         | qualified_identifier
1898           {
1899                 string name = (string) $1;
1900
1901                 $$ = null;
1902                 $$ = DecomposeQI (name, lexer.Location);
1903           }
1904         | parenthesized_expression
1905         | member_access
1906         | invocation_expression
1907         | element_access
1908         | this_access
1909         | base_access
1910         | post_increment_expression
1911         | post_decrement_expression
1912         | new_expression
1913         | typeof_expression
1914         | sizeof_expression
1915         | checked_expression
1916         | unchecked_expression
1917         | pointer_member_access
1918         ;
1919
1920 literal
1921         : boolean_literal
1922         | integer_literal
1923         | real_literal
1924         | LITERAL_CHARACTER     { $$ = new CharLiteral ((char) lexer.Value); }
1925         | LITERAL_STRING        { $$ = new StringLiteral ((string) lexer.Value); }
1926         | NULL                  { $$ = NullLiteral.Null; }
1927         ;
1928
1929 real_literal
1930         : LITERAL_FLOAT         { $$ = new FloatLiteral ((float) lexer.Value); }
1931         | LITERAL_DOUBLE        { $$ = new DoubleLiteral ((double) lexer.Value); }
1932         | LITERAL_DECIMAL       { $$ = new DecimalLiteral ((decimal) lexer.Value); }
1933         ;
1934
1935 integer_literal
1936         : LITERAL_INTEGER       { 
1937                 object v = lexer.Value;
1938
1939                 if (v is int)
1940                         $$ = new IntLiteral ((Int32) v); 
1941                 else if (v is uint)
1942                         $$ = new UIntLiteral ((UInt32) v);
1943                 else if (v is long)
1944                         $$ = new LongLiteral ((Int64) v);
1945                 else if (v is ulong)
1946                         $$ = new ULongLiteral ((UInt64) v);
1947                 else
1948                         Console.WriteLine ("OOPS.  Unexpected result from scanner");
1949           }
1950         ;
1951
1952 boolean_literal
1953         : TRUE                  { $$ = new BoolLiteral (true); }
1954         | FALSE                 { $$ = new BoolLiteral (false); }
1955         ;
1956
1957 parenthesized_expression
1958         : OPEN_PARENS expression CLOSE_PARENS
1959           { $$ = $2; }
1960         ;
1961
1962 member_access
1963         : primary_expression DOT IDENTIFIER
1964           {
1965                 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
1966           }
1967         | predefined_type DOT IDENTIFIER
1968           {
1969                 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
1970           }
1971         ;
1972
1973 predefined_type
1974         : builtin_types
1975         ;
1976
1977 invocation_expression
1978         : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
1979           {
1980                 if ($1 == null) {
1981                         Location l = lexer.Location;
1982                         Report.Error (1, l, "Parse error");
1983                 }
1984                 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
1985           }
1986         ; 
1987
1988 opt_argument_list
1989         : /* empty */           { $$ = null; }
1990         | argument_list
1991         ;
1992
1993 argument_list
1994         : argument              
1995           { 
1996                 ArrayList list = new ArrayList ();
1997                 list.Add ($1);
1998                 $$ = list;
1999           }
2000         | argument_list COMMA argument
2001           {
2002                 ArrayList list = (ArrayList) $1;
2003                 list.Add ($3);
2004                 $$ = list;
2005           }
2006         ;
2007
2008 argument
2009         : expression
2010           {
2011                 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2012           }
2013         | REF variable_reference 
2014           { 
2015                 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2016           }
2017         | OUT variable_reference 
2018           { 
2019                 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2020           }
2021         ;
2022
2023 variable_reference
2024         : expression { note ("section 5.4"); $$ = $1; }
2025         ;
2026
2027 element_access
2028         : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET 
2029           {
2030                 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2031           }
2032         | primary_expression rank_specifiers
2033           {
2034                 // So the super-trick is that primary_expression
2035                 // can only be either a SimpleName or a MemberAccess. 
2036                 // The MemberAccess case arises when you have a fully qualified type-name like :
2037                 // Foo.Bar.Blah i;
2038                 // SimpleName is when you have
2039                 // Blah i;
2040                   
2041                 Expression expr = (Expression) $1;  
2042                 if (!(expr is SimpleName || expr is MemberAccess)) {
2043                         Error_ExpectingTypeName (lexer.Location, expr);
2044                         $$ = TypeManager.system_object_expr;
2045                 } else {
2046                         //
2047                         // So we extract the string corresponding to the SimpleName
2048                         // or MemberAccess
2049                         // 
2050                         $$ = new SimpleName (GetQualifiedIdentifier (expr) + (string) $2, lexer.Location);
2051                 }
2052           }
2053         ;
2054
2055 expression_list
2056         : expression
2057           {
2058                 ArrayList list = new ArrayList ();
2059                 list.Add ($1);
2060                 $$ = list;
2061           }
2062         | expression_list COMMA expression
2063           {
2064                 ArrayList list = (ArrayList) $1;
2065                 list.Add ($3);
2066                 $$ = list;
2067           }
2068         ;
2069
2070 this_access
2071         : THIS
2072           {
2073                 $$ = new This (current_block, lexer.Location);
2074           }
2075         ;
2076
2077 base_access
2078         : BASE DOT IDENTIFIER
2079           {
2080                 $$ = new BaseAccess ((string) $3, lexer.Location);
2081           }
2082         | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2083           {
2084                 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2085           }
2086         ;
2087
2088 post_increment_expression
2089         : primary_expression OP_INC
2090           {
2091                 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2092                                        (Expression) $1, lexer.Location);
2093           }
2094         ;
2095
2096 post_decrement_expression
2097         : primary_expression OP_DEC
2098           {
2099                 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2100                                        (Expression) $1, lexer.Location);
2101           }
2102         ;
2103
2104 new_expression
2105         : object_or_delegate_creation_expression
2106         | array_creation_expression
2107         ;
2108
2109 object_or_delegate_creation_expression
2110         : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2111           {
2112                 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2113           }
2114         ;
2115
2116 array_creation_expression
2117         : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET 
2118           opt_rank_specifier
2119           opt_array_initializer
2120           {
2121                 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2122           }
2123         | NEW type rank_specifiers array_initializer
2124           {
2125                 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2126           }
2127         | NEW type error 
2128           {
2129                 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2130           }
2131         ;
2132
2133 opt_rank_specifier
2134         : /* empty */
2135           {
2136                   $$ = "";
2137           }
2138         | rank_specifiers
2139           {
2140                         $$ = $1;
2141           }
2142         ;
2143
2144 rank_specifiers
2145         : rank_specifier opt_rank_specifier
2146           {
2147                   $$ = (string) $2 + (string) $1;
2148           }
2149         ;
2150
2151 rank_specifier
2152         : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2153           {
2154                 $$ = "[" + (string) $2 + "]";
2155           }
2156         ;
2157
2158 opt_dim_separators
2159         : /* empty */
2160           {
2161                 $$ = "";
2162           }
2163         | dim_separators
2164           {
2165                   $$ = $1;
2166           }               
2167         ;
2168
2169 dim_separators
2170         : COMMA
2171           {
2172                 $$ = ",";
2173           }
2174         | dim_separators COMMA
2175           {
2176                 $$ = (string) $1 + ",";
2177           }
2178         ;
2179
2180 opt_array_initializer
2181         : /* empty */
2182           {
2183                 $$ = null;
2184           }
2185         | array_initializer
2186           {
2187                 $$ = $1;
2188           }
2189         ;
2190
2191 array_initializer
2192         : OPEN_BRACE CLOSE_BRACE
2193           {
2194                 ArrayList list = new ArrayList ();
2195                 $$ = list;
2196           }
2197         | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2198           {
2199                 $$ = (ArrayList) $2;
2200           }
2201         ;
2202
2203 variable_initializer_list
2204         : variable_initializer
2205           {
2206                 ArrayList list = new ArrayList ();
2207                 list.Add ($1);
2208                 $$ = list;
2209           }
2210         | variable_initializer_list COMMA variable_initializer
2211           {
2212                 ArrayList list = (ArrayList) $1;
2213                 list.Add ($3);
2214                 $$ = list;
2215           }
2216         ;
2217
2218 typeof_expression
2219         : TYPEOF OPEN_PARENS type CLOSE_PARENS
2220           {
2221                 $$ = new TypeOf ((Expression) $3, lexer.Location);
2222           }
2223         ;
2224
2225 sizeof_expression
2226         : SIZEOF OPEN_PARENS type CLOSE_PARENS { 
2227                 $$ = new SizeOf ((Expression) $3, lexer.Location);
2228           }
2229         ;
2230
2231 checked_expression
2232         : CHECKED OPEN_PARENS expression CLOSE_PARENS
2233           {
2234                 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2235           }
2236         ;
2237
2238 unchecked_expression
2239         : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2240           {
2241                 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2242           }
2243         ;
2244
2245 pointer_member_access 
2246         : primary_expression OP_PTR IDENTIFIER
2247           {
2248                 Expression deref;
2249
2250                 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2251                 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2252           }
2253
2254 unary_expression
2255         : primary_expression
2256         | BANG prefixed_unary_expression
2257           {
2258                 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2259           }
2260         | TILDE prefixed_unary_expression
2261           {
2262                 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2263           }
2264         | cast_expression
2265         ;
2266
2267 cast_expression
2268         : OPEN_PARENS expression CLOSE_PARENS unary_expression
2269           {
2270                   $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2271           }
2272         | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2273           {
2274                   $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2275           }
2276         ;
2277
2278         //
2279         // The idea to split this out is from Rhys' grammar
2280         // to solve the problem with casts.
2281         //
2282 prefixed_unary_expression
2283         : unary_expression
2284         | PLUS prefixed_unary_expression
2285           { 
2286                 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2287           } 
2288         | MINUS prefixed_unary_expression 
2289           { 
2290                 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2291           }
2292         | OP_INC prefixed_unary_expression 
2293           {
2294                 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2295                                        (Expression) $2, lexer.Location);
2296           }
2297         | OP_DEC prefixed_unary_expression 
2298           {
2299                 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2300                                        (Expression) $2, lexer.Location);
2301           }
2302         | STAR prefixed_unary_expression
2303           {
2304                 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2305           }
2306         | BITWISE_AND prefixed_unary_expression
2307           {
2308                 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2309           }
2310         ;
2311
2312 pre_increment_expression
2313         : OP_INC prefixed_unary_expression 
2314           {
2315                 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2316                                        (Expression) $2, lexer.Location);
2317           }
2318         ;
2319
2320 pre_decrement_expression
2321         : OP_DEC prefixed_unary_expression 
2322           {
2323                 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2324                                        (Expression) $2, lexer.Location);
2325           }
2326         ;
2327
2328 multiplicative_expression
2329         : prefixed_unary_expression
2330         | multiplicative_expression STAR prefixed_unary_expression
2331           {
2332                 $$ = new Binary (Binary.Operator.Multiply, 
2333                                  (Expression) $1, (Expression) $3, lexer.Location);
2334           }
2335         | multiplicative_expression DIV prefixed_unary_expression
2336           {
2337                 $$ = new Binary (Binary.Operator.Division, 
2338                                  (Expression) $1, (Expression) $3, lexer.Location);
2339           }
2340         | multiplicative_expression PERCENT prefixed_unary_expression 
2341           {
2342                 $$ = new Binary (Binary.Operator.Modulus, 
2343                                  (Expression) $1, (Expression) $3, lexer.Location);
2344           }
2345         ;
2346
2347 additive_expression
2348         : multiplicative_expression
2349         | additive_expression PLUS multiplicative_expression 
2350           {
2351                 $$ = new Binary (Binary.Operator.Addition, 
2352                                  (Expression) $1, (Expression) $3, lexer.Location);
2353           }
2354         | additive_expression MINUS multiplicative_expression
2355           {
2356                 $$ = new Binary (Binary.Operator.Subtraction, 
2357                                  (Expression) $1, (Expression) $3, lexer.Location);
2358           }
2359         ;
2360
2361 shift_expression
2362         : additive_expression
2363         | shift_expression OP_SHIFT_LEFT additive_expression
2364           {
2365                 $$ = new Binary (Binary.Operator.LeftShift, 
2366                                  (Expression) $1, (Expression) $3, lexer.Location);
2367           }
2368         | shift_expression OP_SHIFT_RIGHT additive_expression
2369           {
2370                 $$ = new Binary (Binary.Operator.RightShift, 
2371                                  (Expression) $1, (Expression) $3, lexer.Location);
2372           }
2373         ; 
2374
2375 relational_expression
2376         : shift_expression
2377         | relational_expression OP_LT shift_expression
2378           {
2379                 $$ = new Binary (Binary.Operator.LessThan, 
2380                                  (Expression) $1, (Expression) $3, lexer.Location);
2381           }
2382         | relational_expression OP_GT shift_expression
2383           {
2384                 $$ = new Binary (Binary.Operator.GreaterThan, 
2385                                  (Expression) $1, (Expression) $3, lexer.Location);
2386           }
2387         | relational_expression OP_LE shift_expression
2388           {
2389                 $$ = new Binary (Binary.Operator.LessThanOrEqual, 
2390                                  (Expression) $1, (Expression) $3, lexer.Location);
2391           }
2392         | relational_expression OP_GE shift_expression
2393           {
2394                 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, 
2395                                  (Expression) $1, (Expression) $3, lexer.Location);
2396           }
2397         | relational_expression IS type
2398           {
2399                 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2400           }
2401         | relational_expression AS type
2402           {
2403                 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2404           }
2405         ;
2406
2407 equality_expression
2408         : relational_expression
2409         | equality_expression OP_EQ relational_expression
2410           {
2411                 $$ = new Binary (Binary.Operator.Equality, 
2412                                  (Expression) $1, (Expression) $3, lexer.Location);
2413           }
2414         | equality_expression OP_NE relational_expression
2415           {
2416                 $$ = new Binary (Binary.Operator.Inequality, 
2417                                  (Expression) $1, (Expression) $3, lexer.Location);
2418           }
2419         ; 
2420
2421 and_expression
2422         : equality_expression
2423         | and_expression BITWISE_AND equality_expression
2424           {
2425                 $$ = new Binary (Binary.Operator.BitwiseAnd, 
2426                                  (Expression) $1, (Expression) $3, lexer.Location);
2427           }
2428         ;
2429
2430 exclusive_or_expression
2431         : and_expression
2432         | exclusive_or_expression CARRET and_expression
2433           {
2434                 $$ = new Binary (Binary.Operator.ExclusiveOr, 
2435                                  (Expression) $1, (Expression) $3, lexer.Location);
2436           }
2437         ;
2438
2439 inclusive_or_expression
2440         : exclusive_or_expression
2441         | inclusive_or_expression BITWISE_OR exclusive_or_expression
2442           {
2443                 $$ = new Binary (Binary.Operator.BitwiseOr, 
2444                                  (Expression) $1, (Expression) $3, lexer.Location);
2445           }
2446         ;
2447
2448 conditional_and_expression
2449         : inclusive_or_expression
2450         | conditional_and_expression OP_AND inclusive_or_expression
2451           {
2452                 $$ = new Binary (Binary.Operator.LogicalAnd, 
2453                                  (Expression) $1, (Expression) $3, lexer.Location);
2454           }
2455         ;
2456
2457 conditional_or_expression
2458         : conditional_and_expression
2459         | conditional_or_expression OP_OR conditional_and_expression
2460           {
2461                 $$ = new Binary (Binary.Operator.LogicalOr, 
2462                                  (Expression) $1, (Expression) $3, lexer.Location);
2463           }
2464         ;
2465
2466 conditional_expression
2467         : conditional_or_expression
2468         | conditional_or_expression INTERR expression COLON expression 
2469           {
2470                 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2471           }
2472         ;
2473
2474 assignment_expression
2475         : prefixed_unary_expression ASSIGN expression
2476           {
2477                 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2478           }
2479         | prefixed_unary_expression OP_MULT_ASSIGN expression
2480           {
2481                 Location l = lexer.Location;
2482
2483                 $$ = new CompoundAssign (
2484                         Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
2485           }
2486         | prefixed_unary_expression OP_DIV_ASSIGN expression
2487           {
2488                 Location l = lexer.Location;
2489
2490                 $$ = new CompoundAssign (
2491                         Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
2492           }
2493         | prefixed_unary_expression OP_MOD_ASSIGN expression
2494           {
2495                 Location l = lexer.Location;
2496
2497                 $$ = new CompoundAssign (
2498                         Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
2499           }
2500         | prefixed_unary_expression OP_ADD_ASSIGN expression
2501           {
2502                 Location l = lexer.Location;
2503
2504                 $$ = new CompoundAssign (
2505                         Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
2506           }
2507         | prefixed_unary_expression OP_SUB_ASSIGN expression
2508           {
2509                 Location l = lexer.Location;
2510
2511                 $$ = new CompoundAssign (
2512                         Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
2513           }
2514         | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2515           {
2516                 Location l = lexer.Location;
2517
2518                 $$ = new CompoundAssign (
2519                         Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
2520           }
2521         | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2522           {
2523                 Location l = lexer.Location;
2524
2525                 $$ = new CompoundAssign (
2526                         Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
2527           }
2528         | prefixed_unary_expression OP_AND_ASSIGN expression
2529           {
2530                 Location l = lexer.Location;
2531
2532                 $$ = new CompoundAssign (
2533                         Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
2534           }
2535         | prefixed_unary_expression OP_OR_ASSIGN expression
2536           {
2537                 Location l = lexer.Location;
2538
2539                 $$ = new CompoundAssign (
2540                         Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
2541           }
2542         | prefixed_unary_expression OP_XOR_ASSIGN expression
2543           {
2544                 Location l = lexer.Location;
2545
2546                 $$ = new CompoundAssign (
2547                         Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
2548           }
2549         ;
2550
2551 expression
2552         : conditional_expression
2553         | assignment_expression
2554         ;
2555
2556 constant_expression
2557         : expression
2558         ;
2559
2560 boolean_expression
2561         : expression
2562         ;
2563
2564 //
2565 // 10 classes
2566 //
2567 class_declaration
2568         : opt_attributes
2569           opt_modifiers
2570           CLASS IDENTIFIER
2571           {
2572                 Class new_class;
2573                 string name;
2574
2575                 name = MakeName ((string) $4);
2576
2577                 new_class = new Class (current_container, name, (int) $2, 
2578                                        (Attributes) $1, lexer.Location);
2579                 current_container = new_class;
2580                 current_container.Namespace = current_namespace;
2581                 RootContext.Tree.RecordDecl (name, new_class);
2582           }
2583           opt_class_base
2584           class_body 
2585           opt_semicolon 
2586           {
2587                 Class new_class = (Class) current_container;
2588
2589                 if ($6 != null)
2590                         new_class.Bases = (ArrayList) $6;
2591
2592                 current_container = current_container.Parent;
2593                 CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
2594
2595                 $$ = new_class;
2596           }
2597         ;       
2598
2599 opt_modifiers
2600         : /* empty */           { $$ = (int) 0; }
2601         | modifiers
2602         ;
2603
2604 modifiers
2605         : modifier
2606         | modifiers modifier
2607           { 
2608                 int m1 = (int) $1;
2609                 int m2 = (int) $2;
2610
2611                 if ((m1 & m2) != 0) {
2612                         Location l = lexer.Location;
2613                         Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
2614                 }
2615                 $$ = (int) (m1 | m2);
2616           }
2617         ;
2618
2619 modifier
2620         : NEW                   { $$ = Modifiers.NEW; }
2621         | PUBLIC                { $$ = Modifiers.PUBLIC; }
2622         | PROTECTED             { $$ = Modifiers.PROTECTED; }
2623         | INTERNAL              { $$ = Modifiers.INTERNAL; }
2624         | PRIVATE               { $$ = Modifiers.PRIVATE; }
2625         | ABSTRACT              { $$ = Modifiers.ABSTRACT; }
2626         | SEALED                { $$ = Modifiers.SEALED; }
2627         | STATIC                { $$ = Modifiers.STATIC; }
2628         | READONLY              { $$ = Modifiers.READONLY; }
2629         | VIRTUAL               { $$ = Modifiers.VIRTUAL; }
2630         | OVERRIDE              { $$ = Modifiers.OVERRIDE; }
2631         | EXTERN                { $$ = Modifiers.EXTERN; }
2632         | VOLATILE              { $$ = Modifiers.VOLATILE; }
2633         | UNSAFE                { $$ = Modifiers.UNSAFE; }
2634         ;
2635
2636 opt_class_base
2637         : /* empty */           { $$ = null; }
2638         | class_base            { $$ = $1;   }
2639         ;
2640
2641 class_base
2642         : COLON type_list { $$ = $2; }
2643         ;
2644
2645 //
2646 // Statements (8.2)
2647 //
2648
2649 //
2650 // A block is "contained" on the following places:
2651 //      method_body
2652 //      property_declaration as part of the accessor body (get/set)
2653 //      operator_declaration
2654 //      constructor_declaration
2655 //      destructor_declaration
2656 //      event_declaration as part of add_accessor_declaration or remove_accessor_declaration
2657 //      
2658 block
2659         : OPEN_BRACE 
2660           {
2661                 current_block = new Block (current_block, current_local_parameters,
2662                                            lexer.Location, Location.Null);
2663           } 
2664           opt_statement_list CLOSE_BRACE 
2665           { 
2666                 while (current_block.Implicit)
2667                         current_block = current_block.Parent;
2668                 $$ = current_block;
2669                 current_block.SetEndLocation (lexer.Location);
2670                 current_block = current_block.Parent;
2671           }
2672         ;
2673
2674 opt_statement_list
2675         : /* empty */
2676         | statement_list 
2677         ;
2678
2679 statement_list
2680         : statement
2681         | statement_list statement
2682         ;
2683
2684 statement
2685         : declaration_statement
2686           {
2687                 if ($1 != null && (Block) $1 != current_block){
2688                         current_block.AddStatement ((Statement) $1);
2689                         current_block = (Block) $1;
2690                 }
2691           }
2692         | embedded_statement
2693           {
2694                 Statement s = (Statement) $1;
2695
2696
2697                 current_block.AddStatement ((Statement) $1);
2698           }
2699         | labeled_statement
2700         ;
2701
2702 embedded_statement
2703         : block
2704         | empty_statement
2705         | expression_statement
2706         | selection_statement
2707         | iteration_statement
2708         | jump_statement                  
2709         | try_statement
2710         | checked_statement
2711         | unchecked_statement
2712         | lock_statement
2713         | using_statement
2714         | unsafe_statement
2715         | fixed_statement
2716         ;
2717
2718 empty_statement
2719         : SEMICOLON
2720           {
2721                   $$ = new EmptyStatement ();
2722           }
2723         ;
2724
2725 labeled_statement
2726         : IDENTIFIER COLON 
2727           {
2728                 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
2729
2730                 if (!current_block.AddLabel ((string) $1, labeled)){
2731                         Location l = lexer.Location;
2732                         Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
2733                 }       
2734                 current_block.AddStatement (labeled);
2735           }
2736           statement
2737         ;
2738
2739 declaration_statement
2740         : local_variable_declaration SEMICOLON
2741           {
2742                 if ($1 != null){
2743                         DictionaryEntry de = (DictionaryEntry) $1;
2744
2745                         $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
2746                 }
2747           }
2748
2749         | local_constant_declaration SEMICOLON
2750           {
2751                 if ($1 != null){
2752                         DictionaryEntry de = (DictionaryEntry) $1;
2753
2754                         $$ = declare_local_constant ((Expression) de.Key, (VariableDeclaration) de.Value);
2755                 }
2756           }
2757         ;
2758
2759 /* 
2760  * The following is from Rhys' grammar:
2761  * > Types in local variable declarations must be recognized as 
2762  * > expressions to prevent reduce/reduce errors in the grammar.
2763  * > The expressions are converted into types during semantic analysis.
2764  */
2765 local_variable_type
2766         : primary_expression opt_rank_specifier
2767           { 
2768                 // FIXME: Do something smart here regarding the composition of the type.
2769
2770                 // Ok, the above "primary_expression" is there to get rid of
2771                 // both reduce/reduce and shift/reduces in the grammar, it should
2772                 // really just be "type_name".  If you use type_name, a reduce/reduce
2773                 // creeps up.  If you use qualified_identifier (which is all we need
2774                 // really) two shift/reduces appear.
2775                 // 
2776
2777                 // So the super-trick is that primary_expression
2778                 // can only be either a SimpleName or a MemberAccess. 
2779                 // The MemberAccess case arises when you have a fully qualified type-name like :
2780                 // Foo.Bar.Blah i;
2781                 // SimpleName is when you have
2782                 // Blah i;
2783                   
2784                 Expression expr = (Expression) $1;  
2785                 if (!(expr is SimpleName || expr is MemberAccess)) {
2786                         Error_ExpectingTypeName (lexer.Location, expr);
2787                         $$ = null;
2788                 } else {
2789                         //
2790                         // So we extract the string corresponding to the SimpleName
2791                         // or MemberAccess
2792                         // 
2793                         if ((string) $2 == "")
2794                                 $$ = $1;
2795                         else
2796                                 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2797                 }
2798           }
2799         | builtin_types opt_rank_specifier
2800           {
2801                 if ((string) $2 == "")
2802                         $$ = $1;
2803                 else
2804                         $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2805           }
2806         ;
2807
2808 local_variable_pointer_type
2809         : primary_expression STAR
2810           {
2811                 Expression expr = (Expression) $1;  
2812                 Location l = lexer.Location;
2813
2814                 if (!(expr is SimpleName || expr is MemberAccess)) {
2815                         Error_ExpectingTypeName (l, expr);
2816
2817                         $$ = null;
2818                 } else 
2819                         $$ = new ComposedCast ((Expression) $1, "*", l);
2820           }
2821         | builtin_types STAR
2822           {
2823                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
2824           }
2825         | VOID STAR
2826           {
2827                 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
2828           }
2829         | local_variable_pointer_type STAR
2830           {
2831                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2832           }
2833         ;
2834
2835 local_variable_declaration
2836         : local_variable_type variable_declarators
2837           {
2838                 if ($1 != null)
2839                         $$ = new DictionaryEntry ($1, $2);
2840                 else
2841                         $$ = null;
2842           }
2843         | local_variable_pointer_type opt_rank_specifier variable_declarators
2844         {
2845                 if ($1 != null){
2846                         Expression t;
2847
2848                         if ((string) $2 == "")
2849                                 t = (Expression) $1;
2850                         else
2851                                 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2852                         $$ = new DictionaryEntry (t, $3);
2853                 } else 
2854                         $$ = null;
2855         }
2856         ;
2857
2858 local_constant_declaration
2859         : CONST local_variable_type constant_declarator
2860           {
2861                 if ($2 != null)
2862                         $$ = new DictionaryEntry ($2, $3);
2863                 else
2864                         $$ = null;
2865           }
2866         ;
2867
2868 expression_statement
2869         : statement_expression SEMICOLON
2870           {
2871                 $$ = $1;
2872           }
2873         ;
2874
2875         //
2876         // We have to do the wrapping here and not in the case above,
2877         // because statement_expression is used for example in for_statement
2878         //
2879 statement_expression
2880         : invocation_expression         { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2881         | object_creation_expression    { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2882         | assignment_expression         { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2883         | post_increment_expression     { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2884         | post_decrement_expression     { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2885         | pre_increment_expression      { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2886         | pre_decrement_expression      { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2887         | error {
2888                 Report.Error (1002, lexer.Location, "Expecting `;'");
2889           }
2890         ;
2891
2892 object_creation_expression
2893         : object_or_delegate_creation_expression
2894           { note ("complain if this is a delegate maybe?"); } 
2895         ;
2896
2897 selection_statement
2898         : if_statement
2899         | switch_statement
2900         ; 
2901
2902 if_statement
2903         : if_statement_open if_statement_rest
2904           {
2905                 $$ = $2;
2906           }
2907         ;
2908
2909 if_statement_open
2910         : IF OPEN_PARENS 
2911           {
2912                 oob_stack.Push (lexer.Location);
2913           }
2914         ;
2915
2916 if_statement_rest
2917         : boolean_expression CLOSE_PARENS 
2918           embedded_statement
2919           { 
2920                 Location l = (Location) oob_stack.Pop ();
2921
2922                 $$ = new If ((Expression) $1, (Statement) $3, l);
2923
2924                 if (RootContext.WarningLevel >= 3){
2925                         if ($3 is EmptyStatement)
2926                                 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
2927                 }
2928
2929           }
2930         | boolean_expression CLOSE_PARENS
2931           embedded_statement ELSE embedded_statement
2932           {
2933                 Location l = (Location) oob_stack.Pop ();
2934
2935                 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
2936           }
2937         ;
2938
2939 switch_statement
2940         : SWITCH OPEN_PARENS 
2941           { 
2942                 oob_stack.Push (lexer.Location);
2943                 switch_stack.Push (current_block);
2944           }
2945           expression CLOSE_PARENS 
2946           switch_block
2947           {
2948                 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
2949                 current_block = (Block) switch_stack.Pop ();
2950           }
2951         ;
2952
2953 switch_block
2954         : OPEN_BRACE
2955           opt_switch_sections
2956           CLOSE_BRACE
2957           {
2958                 $$ = $2;
2959           }
2960         ;
2961
2962 opt_switch_sections
2963         : /* empty */           
2964           {
2965                 Report.Error (1522, lexer.Location, "Empty switch block"); 
2966           }
2967         | switch_sections
2968         ;
2969
2970 switch_sections
2971         : switch_section 
2972           {
2973                 ArrayList sections = new ArrayList ();
2974
2975                 sections.Add ($1);
2976                 $$ = sections;
2977           }
2978         | switch_sections switch_section
2979           {
2980                 ArrayList sections = (ArrayList) $1;
2981
2982                 sections.Add ($2);
2983                 $$ = sections;
2984           }
2985         ;
2986
2987 switch_section
2988         : switch_labels
2989           {
2990                 current_block = new Block (current_block, lexer.Location, lexer.Location);
2991           }
2992           statement_list 
2993           {
2994                 Block topmost = current_block;
2995
2996                 while (topmost.Implicit)
2997                         topmost = topmost.Parent;
2998                 $$ = new SwitchSection ((ArrayList) $1, topmost);
2999           }
3000         ;
3001
3002 switch_labels
3003         : switch_label 
3004           {
3005                 ArrayList labels = new ArrayList ();
3006
3007                 labels.Add ($1);
3008                 $$ = labels;
3009           }
3010         | switch_labels switch_label 
3011           {
3012                 ArrayList labels = (ArrayList) ($1);
3013                 labels.Add ($2);
3014
3015                 $$ = labels;
3016           }
3017         ;
3018
3019 switch_label
3020         : CASE constant_expression COLON        { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3021         | DEFAULT COLON                         { $$ = new SwitchLabel (null, lexer.Location); }
3022         | error {
3023                 Report.Error (
3024                         1523, lexer.Location, 
3025                         "The keyword case or default must precede code in switch block");
3026           }
3027         ;
3028
3029 iteration_statement
3030         : while_statement
3031         | do_statement
3032         | for_statement
3033         | foreach_statement
3034         ;
3035
3036 while_statement
3037         : WHILE OPEN_PARENS 
3038         {
3039                 oob_stack.Push (lexer.Location);
3040         }
3041         boolean_expression CLOSE_PARENS embedded_statement
3042         {
3043                 Location l = (Location) oob_stack.Pop ();
3044                 $$ = new While ((Expression) $4, (Statement) $6, l);
3045         
3046                 if (RootContext.WarningLevel >= 3){
3047                         if ($6 is EmptyStatement)
3048                                 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3049                 }
3050         }
3051         ;
3052
3053 do_statement
3054         : DO embedded_statement 
3055           WHILE OPEN_PARENS {
3056                 oob_stack.Push (lexer.Location);
3057           }
3058           boolean_expression CLOSE_PARENS SEMICOLON
3059           {
3060                 Location l = (Location) oob_stack.Pop ();
3061
3062                 $$ = new Do ((Statement) $2, (Expression) $6, l);
3063           }
3064         ;
3065
3066 for_statement
3067         : FOR OPEN_PARENS 
3068           opt_for_initializer SEMICOLON
3069           {
3070                 Block assign_block = new Block (current_block);
3071                 current_block = assign_block;
3072
3073                 if ($3 is DictionaryEntry){
3074                         DictionaryEntry de = (DictionaryEntry) $3;
3075                         
3076                         Expression type = (Expression) de.Key;
3077                         ArrayList var_declarators = (ArrayList) de.Value;
3078
3079                         foreach (VariableDeclaration decl in var_declarators){
3080
3081                                 VariableInfo vi;
3082
3083                                 vi = current_block.AddVariable (
3084                                         type, decl.identifier, current_local_parameters, decl.Location);
3085                                 if (vi == null)
3086                                         continue;
3087
3088                                 Location l = lexer.Location;
3089                                 Expression expr;
3090                                 if (decl.expression_or_array_initializer is Expression){
3091                                         expr = (Expression) decl.expression_or_array_initializer;
3092                                 } else if (decl.expression_or_array_initializer == null) {
3093                                         expr = null;
3094                                 } else {
3095                                         ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3096                                         expr = new ArrayCreation (type, "", init, decl.Location);
3097                                 }
3098                                         
3099                                 LocalVariableReference var;
3100                                 var = new LocalVariableReference (assign_block, decl.identifier, l);
3101
3102                                 if (expr != null) {
3103                                         Assign a = new Assign (var, expr, decl.Location);
3104                                         
3105                                         assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3106                                 }
3107                         }
3108                         
3109                         $3 = null;
3110                 } 
3111                 oob_stack.Push (lexer.Location);
3112           } 
3113           opt_for_condition SEMICOLON
3114           opt_for_iterator CLOSE_PARENS 
3115           embedded_statement
3116           {
3117                 Location l = (Location) oob_stack.Pop ();
3118
3119                 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3120
3121                 if (RootContext.WarningLevel >= 3){
3122                         if ($10 is EmptyStatement)
3123                                 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3124                 }
3125
3126                 current_block.AddStatement (f);
3127                 while (current_block.Implicit)
3128                         current_block = current_block.Parent;
3129                 $$ = current_block;
3130                 current_block = current_block.Parent;
3131           }
3132         ;
3133
3134 opt_for_initializer
3135         : /* empty */           { $$ = new EmptyStatement (); }
3136         | for_initializer       
3137         ;
3138
3139 for_initializer
3140         : local_variable_declaration
3141         | statement_expression_list
3142         ;
3143
3144 opt_for_condition
3145         : /* empty */           { $$ = null; }
3146         | boolean_expression
3147         ;
3148
3149 opt_for_iterator
3150         : /* empty */           { $$ = new EmptyStatement (); }
3151         | for_iterator
3152         ;
3153
3154 for_iterator
3155         : statement_expression_list
3156         ;
3157
3158 statement_expression_list
3159         : statement_expression  
3160           {
3161                 // CHANGE: was `null'
3162                 Block b = new Block (current_block, true);   
3163
3164                 b.AddStatement ((Statement) $1);
3165                 $$ = b;
3166           }
3167         | statement_expression_list COMMA statement_expression
3168           {
3169                 Block b = (Block) $1;
3170
3171                 b.AddStatement ((Statement) $3);
3172                 $$ = $1;
3173           }
3174         ;
3175
3176 foreach_statement
3177         : FOREACH OPEN_PARENS type IDENTIFIER IN 
3178           {
3179                 oob_stack.Push (lexer.Location);
3180           }
3181           expression CLOSE_PARENS 
3182           {
3183                 oob_stack.Push (current_block);
3184
3185                 Block foreach_block = new Block (current_block, true);
3186                 LocalVariableReference v = null;
3187                 Location l = lexer.Location;
3188                 VariableInfo vi;
3189
3190                 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3191                 if (vi != null) {
3192                         vi.ReadOnly = true;
3193
3194                         // Get a writable reference to this read-only variable.
3195                         v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3196                 }
3197                 current_block = foreach_block;
3198
3199                 oob_stack.Push (v);
3200                 oob_stack.Push (current_block);
3201           } 
3202           embedded_statement 
3203           {
3204                 Block foreach_block = (Block) oob_stack.Pop ();
3205                 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3206                 Block prev_block = (Block) oob_stack.Pop ();
3207                 Location l = (Location) oob_stack.Pop ();
3208
3209                 current_block = prev_block;
3210
3211                 if (v != null) {
3212                         Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3213                         foreach_block.AddStatement (f);
3214                 }
3215
3216                 $$ = foreach_block;
3217           }
3218         ;
3219
3220 jump_statement
3221         : break_statement
3222         | continue_statement
3223         | goto_statement
3224         | return_statement
3225         | throw_statement
3226         ;
3227
3228 break_statement
3229         : BREAK SEMICOLON
3230           {
3231                 $$ = new Break (lexer.Location);
3232           }
3233         ;
3234
3235 continue_statement
3236         : CONTINUE SEMICOLON
3237           {
3238                 $$ = new Continue (lexer.Location);
3239           }
3240         ;
3241
3242 goto_statement
3243         : GOTO IDENTIFIER SEMICOLON 
3244           {
3245                 $$ = new Goto (current_block, (string) $2, lexer.Location);
3246           }
3247         | GOTO CASE constant_expression SEMICOLON
3248           {
3249                 $$ = new GotoCase ((Expression) $3, lexer.Location);
3250           }
3251         | GOTO DEFAULT SEMICOLON 
3252           {
3253                 $$ = new GotoDefault (lexer.Location);
3254           }
3255         ; 
3256
3257 return_statement
3258         : RETURN opt_expression SEMICOLON
3259           {
3260                 $$ = new Return ((Expression) $2, lexer.Location);
3261           }
3262         ;
3263
3264 throw_statement
3265         : THROW opt_expression SEMICOLON
3266           {
3267                 $$ = new Throw ((Expression) $2, lexer.Location);
3268           }
3269         ;
3270
3271 opt_expression
3272         : /* empty */
3273         | expression
3274         ;
3275
3276 try_statement
3277         : TRY block catch_clauses 
3278         {
3279                 Catch g = null;
3280                 ArrayList s = new ArrayList ();
3281                 
3282                 foreach (Catch cc in (ArrayList) $3) {
3283                         if (cc.IsGeneral)
3284                                 g = cc;
3285                         else
3286                                 s.Add (cc);
3287                 }
3288
3289                 // Now s contains the list of specific catch clauses
3290                 // and g contains the general one.
3291                 
3292                 $$ = new Try ((Block) $2, s, g, null, lexer.Location);
3293         }
3294         | TRY block opt_catch_clauses FINALLY block
3295           {
3296                 Catch g = null;
3297                 ArrayList s = new ArrayList ();
3298                 ArrayList catch_list = (ArrayList) $3;
3299
3300                 if (catch_list != null){
3301                         foreach (Catch cc in catch_list) {
3302                                 if (cc.IsGeneral)
3303                                         g = cc;
3304                                 else
3305                                         s.Add (cc);
3306                         }
3307                 }
3308
3309                 $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
3310           }
3311         | TRY block error 
3312           {
3313                 Report.Error (1524, lexer.Location, "Expected catch or finally");
3314           }
3315         ;
3316
3317 opt_catch_clauses
3318         : /* empty */  { $$ = null; }
3319         | catch_clauses
3320         ;
3321
3322 catch_clauses
3323         : catch_clause 
3324           {
3325                 ArrayList l = new ArrayList ();
3326
3327                 l.Add ($1);
3328                 $$ = l;
3329           }
3330         | catch_clauses catch_clause
3331           {
3332                 ArrayList l = (ArrayList) $1;
3333
3334                 l.Add ($2);
3335                 $$ = l;
3336           }
3337         ;
3338
3339 opt_identifier
3340         : /* empty */   { $$ = null; }
3341         | IDENTIFIER
3342         ;
3343
3344 catch_clause 
3345         : CATCH opt_catch_args 
3346         {
3347                 Expression type = null;
3348                 string id = null;
3349                 
3350                 if ($2 != null) {
3351                         DictionaryEntry cc = (DictionaryEntry) $2;
3352                         type = (Expression) cc.Key;
3353                         id   = (string) cc.Value;
3354
3355                         if (id != null){
3356                                 ArrayList one = new ArrayList ();
3357                                 Location loc = lexer.Location;
3358
3359                                 one.Add (new VariableDeclaration (id, null, loc));
3360
3361                                 $1 = current_block;
3362                                 current_block = new Block (current_block);
3363                                 Block b = declare_local_variables (type, one, loc);
3364                                 current_block = b;
3365                         }
3366                 }
3367         } block {
3368                 Expression type = null;
3369                 string id = null;
3370
3371                 if ($2 != null){
3372                         DictionaryEntry cc = (DictionaryEntry) $2;
3373                         type = (Expression) cc.Key;
3374                         id   = (string) cc.Value;
3375
3376                         if ($1 != null){
3377                                 //
3378                                 // FIXME: I can change this for an assignment.
3379                                 //
3380                                 while (current_block != (Block) $1)
3381                                         current_block = current_block.Parent;
3382                         }
3383                 }
3384
3385
3386                 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3387         }
3388         ;
3389
3390 opt_catch_args
3391         : /* empty */ { $$ = null; }
3392         | catch_args
3393         ;         
3394
3395 catch_args 
3396         : OPEN_PARENS type opt_identifier CLOSE_PARENS 
3397         {
3398                 $$ = new DictionaryEntry ($2, $3);
3399         }
3400         ;
3401
3402 checked_statement
3403         : CHECKED block
3404           {
3405                 $$ = new Checked ((Block) $2);
3406           }
3407         ;
3408
3409 unchecked_statement
3410         : UNCHECKED block
3411           {
3412                 $$ = new Unchecked ((Block) $2);
3413           }
3414         ;
3415
3416 unsafe_statement
3417         : UNSAFE 
3418         {
3419                 if (!RootContext.Unsafe){
3420                         Report.Error (227, lexer.Location, 
3421                                 "Unsafe code can only be used if --unsafe is used");
3422                 }
3423         } block {
3424                 $$ = new Unsafe ((Block) $3);
3425         }
3426         ;
3427
3428 fixed_statement
3429         : FIXED OPEN_PARENS 
3430           pointer_type fixed_pointer_declarators 
3431           CLOSE_PARENS 
3432           {
3433                 Block assign_block = new Block (current_block, true);
3434                 ArrayList list = (ArrayList) $4;
3435                 Expression type = (Expression) $3;
3436                 Location l = lexer.Location;
3437                 int top = list.Count;
3438
3439                 for (int i = 0; i < top; i++){
3440                         Pair p = (Pair) list [i];
3441                         VariableInfo v;
3442
3443                         v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
3444                         if (v == null)
3445                                 continue;
3446                         v.ReadOnly = true;
3447                         p.First = v;
3448                         list [i] = p;
3449                 }
3450                 current_block.AddStatement (assign_block);
3451                 current_block = assign_block;
3452                 oob_stack.Push (assign_block);
3453                 oob_stack.Push (l);
3454           }
3455           embedded_statement 
3456           {
3457                 Location l = (Location) oob_stack.Pop ();
3458                 Block assign_block = (Block) oob_stack.Pop ();
3459
3460                 ArrayList list = (ArrayList) $4;
3461                 int top = list.Count;
3462
3463                 $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
3464           }
3465         ;
3466
3467 fixed_pointer_declarators
3468         : fixed_pointer_declarator      { 
3469                 ArrayList declarators = new ArrayList (); 
3470                 declarators.Add ($1);
3471                 $$ = declarators;
3472           }
3473         | fixed_pointer_declarators COMMA fixed_pointer_declarator
3474           {
3475                 ArrayList declarators = (ArrayList) $1;
3476                 declarators.Add ($3);
3477                 $$ = declarators;
3478           }
3479         ;
3480
3481 fixed_pointer_declarator
3482         : IDENTIFIER ASSIGN expression
3483           {     
3484                 $$ = new Pair ($1, $3);
3485           }
3486         ;
3487
3488 lock_statement
3489         : LOCK OPEN_PARENS expression CLOSE_PARENS 
3490           {
3491                 //
3492           } 
3493           embedded_statement
3494           {
3495                 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
3496           }
3497         ;
3498
3499 using_statement
3500         : USING OPEN_PARENS resource_acquisition CLOSE_PARENS 
3501           {
3502                 Block assign_block = new Block (current_block);
3503                 current_block = assign_block;
3504
3505                 oob_stack.Push (lexer.Location);
3506                 
3507                 if ($3 is DictionaryEntry){
3508                         DictionaryEntry de = (DictionaryEntry) $3;
3509                         Location l = lexer.Location;
3510
3511                         Expression type = (Expression) de.Key;
3512                         ArrayList var_declarators = (ArrayList) de.Value;
3513
3514                         ArrayList vars = new ArrayList ();
3515
3516                         foreach (VariableDeclaration decl in var_declarators){
3517
3518                                 VariableInfo vi = current_block.AddVariable (
3519                                         type, decl.identifier, 
3520                                         current_local_parameters, decl.Location);
3521                                 if (vi == null)
3522                                         continue;
3523                                 vi.ReadOnly = true;
3524
3525                                 Expression expr;
3526                                 if (decl.expression_or_array_initializer is Expression){
3527                                         expr = (Expression) decl.expression_or_array_initializer;
3528                                 } else {
3529                                         ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3530                                         
3531                                         expr = new ArrayCreation (type, "", init, decl.Location);
3532                                 }
3533
3534                                 LocalVariableReference var;
3535
3536                                 // Get a writable reference to this read-only variable.
3537                                 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
3538
3539                                 // This is so that it is not a warning on using variables
3540                                 vi.Used = true;
3541
3542                                 vars.Add (new DictionaryEntry (var, expr));                             
3543
3544                                 // Assign a = new Assign (var, expr, decl.Location);
3545                                 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3546                         }
3547                         $3 = new DictionaryEntry (type, vars);
3548                  }
3549           } 
3550           embedded_statement
3551           {
3552                 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
3553                 current_block.AddStatement (u);
3554                 while (current_block.Implicit)
3555                         current_block = current_block.Parent;
3556                 $$ = current_block;
3557                 current_block = current_block.Parent;
3558           }
3559         ; 
3560
3561 resource_acquisition
3562         : local_variable_declaration
3563         | expression
3564         ;
3565
3566 %%
3567
3568 // <summary>
3569 //   A class used to pass around variable declarations and constants
3570 // </summary>
3571 public class VariableDeclaration {
3572         public string identifier;
3573         public object expression_or_array_initializer;
3574         public Location Location;
3575         public Attributes OptAttributes;
3576
3577         public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
3578         {
3579                 this.identifier = id;
3580                 this.expression_or_array_initializer = eoai;
3581                 this.Location = l;
3582                 this.OptAttributes = opt_attrs;
3583         }
3584
3585         public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
3586         {
3587         }
3588 }
3589
3590 // <summary>
3591 //   A class used to hold info about an indexer declarator
3592 // </summary>
3593
3594 public class IndexerDeclaration {
3595         public Expression type;
3596         public string interface_type;
3597         public Parameters param_list;
3598
3599         public IndexerDeclaration (Expression type, string interface_type, Parameters param_list)
3600         {
3601                 this.type = type;
3602                 this.interface_type = interface_type;
3603                 this.param_list = param_list;
3604         }
3605 }
3606
3607 // <summary>
3608 //  A class used to hold info about an operator declarator
3609 // </summary>
3610
3611 public class OperatorDeclaration {
3612         public Operator.OpType optype;
3613         public Expression ret_type, arg1type, arg2type;
3614         public string arg1name, arg2name;
3615         public Location location;
3616
3617         public OperatorDeclaration (Operator.OpType op, Expression ret_type, 
3618                                     Expression arg1type, string arg1name,
3619                                     Expression arg2type, string arg2name, Location location)
3620         {
3621                 optype = op;
3622                 this.ret_type = ret_type;
3623                 this.arg1type = arg1type;
3624                 this.arg1name = arg1name;
3625                 this.arg2type = arg2type;
3626                 this.arg2name = arg2name;
3627                 this.location = location;
3628         }
3629
3630 }
3631
3632 void Error_ExpectingTypeName (Location l, Expression expr)
3633 {
3634         if (expr is Invocation){
3635                 Report.Error (1002, l, "; expected");
3636         } else {
3637                 Report.Error (-1, l, "Invalid Type definition");
3638         }
3639 }
3640
3641 // <summary>
3642 //   Given the @class_name name, it creates a fully qualified name
3643 //   based on the containing declaration space
3644 // </summary>
3645 string 
3646 MakeName (string class_name)
3647 {
3648         string ns = current_namespace.Name;
3649         string container_name = current_container.Name;
3650
3651         if (container_name == ""){
3652                 if (ns != "")
3653                         return ns + "." + class_name;
3654                 else
3655                         return class_name;
3656         } else
3657                 return container_name + "." + class_name;
3658 }
3659
3660 // <summary>
3661 //   Used to report back to the user the result of a declaration
3662 //   in the current declaration space
3663 // </summary>
3664 void 
3665 CheckDef (AdditionResult result, string name, Location l)
3666 {
3667         if (result == AdditionResult.Success)
3668                 return;
3669
3670         switch (result){
3671         case AdditionResult.NameExists:
3672                 Report.Error (102, l, "The container `" + current_container.Name + 
3673                                  "' already contains a definition for `"+
3674                                  name + "'");
3675                 break;
3676
3677
3678                 //
3679                 // This is handled only for static Constructors, because
3680                 // in reality we handle these by the semantic analysis later
3681                 //
3682         case AdditionResult.MethodExists:
3683                 Report.Error (
3684                         111, l, "Class `"+current_container.Name+
3685                         "' already defines a member called '" + 
3686                         name + "' with the same parameter types (more than one default constructor)");
3687                 break;
3688
3689         case AdditionResult.EnclosingClash:
3690                 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
3691                 break;
3692                 
3693         case AdditionResult.NotAConstructor:
3694                 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
3695                 break;
3696         }
3697 }
3698
3699 void 
3700 CheckDef (bool result, string name, Location l)
3701 {
3702         if (result)
3703                 return;
3704         CheckDef (AdditionResult.NameExists, name, l);
3705 }
3706
3707 Expression DecomposeQI (string name, Location loc)
3708 {
3709         Expression o;
3710
3711         if (name.IndexOf ('.') == -1){
3712                 return new SimpleName (name, loc);
3713         } else {
3714                 int pos = name.LastIndexOf (".");
3715                 string left = name.Substring (0, pos);
3716                 string right = name.Substring (pos + 1);
3717
3718                 o = DecomposeQI (left, loc);
3719
3720                 return new MemberAccess (o, right, loc);
3721         }
3722 }
3723
3724 // <summary>
3725 //  This method is used to get at the complete string representation of
3726 //  a fully-qualified type name, hiding inside a MemberAccess ;-)
3727 //  This is necessary because local_variable_type admits primary_expression
3728 //  as the type of the variable. So we do some extra checking
3729 // </summary>
3730 string GetQualifiedIdentifier (Expression expr)
3731 {
3732         if (expr is SimpleName)
3733                 return ((SimpleName)expr).Name;
3734         else if (expr is MemberAccess)
3735                 return GetQualifiedIdentifier (((MemberAccess)expr).Expr) + "." + ((MemberAccess) expr).Identifier;
3736         else 
3737                 throw new Exception ("Expr has to be either SimpleName or MemberAccess! (" + expr + ")");
3738         
3739 }
3740
3741 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
3742 {
3743         Block implicit_block;
3744         ArrayList inits = null;
3745
3746         //
3747         // We use the `Used' property to check whether statements
3748         // have been added to the current block.  If so, we need
3749         // to create another block to contain the new declaration
3750         // otherwise, as an optimization, we use the same block to
3751         // add the declaration.
3752         //
3753         // FIXME: A further optimization is to check if the statements
3754         // that were added were added as part of the initialization
3755         // below.  In which case, no other statements have been executed
3756         // and we might be able to reduce the number of blocks for
3757         // situations like this:
3758         //
3759         // int j = 1;  int k = j + 1;
3760         //
3761         if (current_block.Used) {
3762                 implicit_block = new Block (current_block, true, loc, Location.Null);
3763                 implicit_block.AddChildVariableNames (current_block);
3764         } else
3765                 implicit_block = current_block;
3766
3767         foreach (VariableDeclaration decl in variable_declarators){
3768
3769                 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
3770                         if (decl.expression_or_array_initializer != null){
3771                                 if (inits == null)
3772                                         inits = new ArrayList ();
3773                                 inits.Add (decl);
3774                         }
3775                 }
3776         }
3777
3778         if (inits == null)
3779                 return implicit_block;
3780
3781         foreach (VariableDeclaration decl in inits){
3782                 Assign assign;
3783                 Expression expr;
3784                 
3785                 if (decl.expression_or_array_initializer is Expression){
3786                         expr = (Expression) decl.expression_or_array_initializer;
3787
3788                 } else {
3789                         ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3790                         
3791                         expr = new ArrayCreation (type, "", init, decl.Location);
3792                 }
3793
3794                 LocalVariableReference var;
3795                 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
3796
3797                 assign = new Assign (var, expr, decl.Location);
3798
3799                 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
3800         }
3801         
3802         return implicit_block;
3803 }
3804
3805 Block declare_local_constant (Expression type, VariableDeclaration decl)
3806 {
3807         Block implicit_block;
3808
3809         if (current_block.Used)
3810                 implicit_block = new Block (current_block, true);
3811         else
3812                 implicit_block = current_block;
3813
3814         if (!(implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
3815                                           current_local_parameters, decl.Location))){
3816         }
3817         
3818         return implicit_block;
3819 }
3820
3821 void CheckAttributeTarget (string a)
3822 {
3823         switch (a) {
3824
3825         case "assembly" : case "field" : case "method" : case "param" : case "property" : case "type" :
3826                 return;
3827                 
3828         default :
3829                 Location l = lexer.Location;
3830                 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
3831                 break;
3832         }
3833
3834 }
3835
3836 void CheckUnaryOperator (Operator.OpType op)
3837 {
3838         switch (op) {
3839                 
3840         case Operator.OpType.LogicalNot: 
3841         case Operator.OpType.OnesComplement: 
3842         case Operator.OpType.Increment:
3843         case Operator.OpType.Decrement:
3844         case Operator.OpType.True: 
3845         case Operator.OpType.False: 
3846         case Operator.OpType.Addition: 
3847         case Operator.OpType.Subtraction:
3848                 
3849                 break;
3850                 
3851         default :
3852                 Location l = lexer.Location;
3853                 Report.Error (1019, l, "Overloadable unary operator expected"); 
3854                 break;
3855                 
3856         }
3857 }
3858
3859 void CheckBinaryOperator (Operator.OpType op)
3860 {
3861         switch (op) {
3862                 
3863         case Operator.OpType.Addition: 
3864         case Operator.OpType.Subtraction: 
3865         case Operator.OpType.Multiply:
3866         case Operator.OpType.Division:
3867         case Operator.OpType.Modulus: 
3868         case Operator.OpType.BitwiseAnd: 
3869         case Operator.OpType.BitwiseOr:
3870         case Operator.OpType.ExclusiveOr: 
3871         case Operator.OpType.LeftShift: 
3872         case Operator.OpType.RightShift:
3873         case Operator.OpType.Equality: 
3874         case Operator.OpType.Inequality:
3875         case Operator.OpType.GreaterThan: 
3876         case Operator.OpType.LessThan: 
3877         case Operator.OpType.GreaterThanOrEqual:
3878         case Operator.OpType.LessThanOrEqual:
3879                 break;
3880                 
3881         default :
3882                 Location l = lexer.Location;
3883                 Report.Error (1020, l, "Overloadable binary operator expected");
3884                 break;
3885         }
3886         
3887 }
3888
3889 void syntax_error (Location l, string msg)
3890 {
3891         Report.Error (1003, l, "Syntax error, " + msg);
3892 }
3893
3894 void output (string s)
3895 {
3896         Console.WriteLine (s);
3897 }
3898
3899 void note (string s)
3900 {
3901         // Used to put annotations
3902 }
3903
3904 Tokenizer lexer;
3905
3906 public Tokenizer Lexer {
3907         get {
3908                 return lexer;
3909         }
3910 }                  
3911
3912 public CSharpParser (StreamReader reader, string name, ArrayList defines)
3913 {
3914         current_namespace = new Namespace (null, "");
3915         this.name = name;
3916         current_container = RootContext.Tree.Types;
3917         current_container.Namespace = current_namespace;
3918         oob_stack = new Stack ();
3919         switch_stack = new Stack ();
3920
3921         lexer = new Tokenizer (reader, name, defines);
3922 }
3923
3924 public override void parse ()
3925 {
3926         try {
3927                 if (yacc_verbose_flag)
3928                         yyparse (lexer, new yydebug.yyDebugSimple ());
3929                 else
3930                         yyparse (lexer);
3931         } catch (Exception e){
3932                 // Please do not remove this, it is used during debugging
3933                 // of the grammar
3934                 //
3935                 Console.WriteLine (lexer.location + "  : Parsing error ");
3936                 Console.WriteLine (e);
3937         }
3938 }
3939
3940 /* end end end */
3941 }