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