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