2003-04-14 Gaurav Vaish <gvaish_mono AT lycos.com>
[mono.git] / mcs / mcs / cs-parser.jay
1 %{
2 //
3 // cs-parser.jay: The Parser for the C# compiler
4 //
5 // Authors: Miguel de Icaza (miguel@gnu.org)
6 //          Ravi Pratap     (ravi@ximian.com)
7 //
8 // Licensed under the terms of the GNU GPL
9 //
10 // (C) 2001 Ximian, Inc (http://www.ximian.com)
11 //
12 // TODO:
13 //   (1) Figure out why error productions dont work.  `type-declaration' is a
14 //       great spot to put an `error' because you can reproduce it with this input:
15 //       "public X { }"
16 //
17 // 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         | opt_attributes ADD error {
1574                 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1575                 $$ = null;
1576           }
1577         ;
1578
1579 remove_accessor_declaration
1580         : opt_attributes REMOVE
1581           {
1582                 Parameter [] args = new Parameter [1];
1583                 Parameter implicit_value_parameter = new Parameter (
1584                         implicit_value_parameter_type, "value", 
1585                         Parameter.Modifier.NONE, null);
1586
1587                 args [0] = implicit_value_parameter;
1588                 
1589                 current_local_parameters = new Parameters (args, null, lexer.Location);  
1590                 lexer.EventParsing = false;
1591           }
1592           block
1593           {
1594                 $$ = new Accessor ((Block) $4, (Attributes) $1);
1595                 lexer.EventParsing = true;
1596           }
1597         | opt_attributes REMOVE error {
1598                 Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
1599                 $$ = null;
1600           }
1601         ;
1602
1603 indexer_declaration
1604         : opt_attributes opt_modifiers indexer_declarator 
1605           OPEN_BRACE 
1606           {
1607                 IndexerDeclaration decl = (IndexerDeclaration) $3;
1608
1609                 implicit_value_parameter_type = decl.type;
1610                 
1611                 lexer.PropertyParsing = true;
1612                 parsing_indexer  = true;
1613                 
1614                 indexer_parameters = decl.param_list;
1615                 oob_stack.Push (lexer.Location);
1616           }
1617           accessor_declarations 
1618           {
1619                   lexer.PropertyParsing = false;
1620                   parsing_indexer  = false;
1621           }
1622           CLOSE_BRACE
1623           { 
1624                 // The signature is computed from the signature of the indexer.  Look
1625                 // at section 3.6 on the spec
1626                 Location loc = (Location) oob_stack.Pop ();
1627                 Indexer indexer;
1628                 IndexerDeclaration decl = (IndexerDeclaration) $3;
1629                 Pair pair = (Pair) $6;
1630                 Accessor get_block = (Accessor) pair.First;
1631                 Accessor set_block = (Accessor) pair.Second;
1632
1633                 indexer = new Indexer (decl.type, decl.interface_type, (int) $2, decl.param_list,
1634                                        get_block, set_block, (Attributes) $1, loc);
1635
1636                 // Note that there is no equivalent of CheckDef for this case
1637                 // We shall handle this in semantic analysis
1638                 
1639                 current_container.AddIndexer (indexer);
1640                 
1641                 current_local_parameters = null;
1642                 implicit_value_parameter_type = null;
1643                 indexer_parameters = null;
1644           }
1645         ;
1646
1647 indexer_declarator
1648         : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1649           {
1650                 Parameters pars = (Parameters) $4;
1651
1652                 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1653                         Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1654                 }
1655
1656                 $$ = new IndexerDeclaration ((Expression) $1, null, pars);
1657           }
1658         | type qualified_identifier DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1659           {
1660                 Parameters pars = (Parameters) $6;
1661
1662                 if (pars.FixedParameters == null && pars.ArrayParameter == null){
1663                         Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1664                 }
1665                 $$ = new IndexerDeclaration ((Expression) $1, (string) $2, pars);
1666           }
1667         ;
1668
1669 enum_declaration
1670         : opt_attributes
1671           opt_modifiers
1672           ENUM IDENTIFIER 
1673           opt_enum_base
1674           enum_body
1675           opt_semicolon
1676           { 
1677                 Location enum_location = lexer.Location;
1678
1679                 string full_name = MakeName ((string) $4);
1680                 Enum e = new Enum (current_container, (Expression) $5, (int) $2, full_name, 
1681                                    (Attributes) $1, enum_location);
1682                 
1683                 foreach (VariableDeclaration ev in (ArrayList) $6) {
1684                         Location loc = (Location) ev.Location;
1685
1686                         CheckDef (e.AddEnumMember (ev.identifier, 
1687                                                    (Expression) ev.expression_or_array_initializer,
1688                                                    loc, ev.OptAttributes),
1689                                   ev.identifier, loc);
1690                 }
1691
1692                 e.Namespace = current_namespace;
1693
1694                 CheckDef (current_container.AddEnum (e), full_name, enum_location);
1695                 RootContext.Tree.RecordDecl (full_name, e);
1696
1697           }
1698         ;
1699
1700 opt_enum_base
1701         : /* empty */           { $$ = TypeManager.system_int32_expr; }
1702         | COLON type            { $$ = $2;   }
1703         ;
1704
1705 enum_body
1706         : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1707           {
1708                 $$ = $2;
1709           }
1710         ;
1711
1712 opt_enum_member_declarations
1713         : /* empty */                   { $$ = new ArrayList (); }
1714         | enum_member_declarations opt_comma { $$ = $1; }
1715         ;
1716
1717 enum_member_declarations
1718         : enum_member_declaration 
1719           {
1720                 ArrayList l = new ArrayList ();
1721
1722                 l.Add ($1);
1723                 $$ = l;
1724           }
1725         | enum_member_declarations COMMA enum_member_declaration
1726           {
1727                 ArrayList l = (ArrayList) $1;
1728
1729                 l.Add ($3);
1730
1731                 $$ = l;
1732           }
1733         ;
1734
1735 enum_member_declaration
1736         : opt_attributes IDENTIFIER 
1737           {
1738                 $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
1739           }
1740         | opt_attributes IDENTIFIER
1741           {
1742                   $$ = lexer.Location;
1743           }
1744           ASSIGN expression
1745           { 
1746                 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
1747           }
1748         ;
1749
1750 delegate_declaration
1751         : opt_attributes
1752           opt_modifiers
1753           DELEGATE type   
1754           IDENTIFIER OPEN_PARENS 
1755           opt_formal_parameter_list
1756           CLOSE_PARENS 
1757           SEMICOLON
1758           {
1759                 Location l = lexer.Location;
1760                 Delegate del = new Delegate (current_container, (Expression) $4, (int) $2, 
1761                                              MakeName ((string) $5), (Parameters) $7, 
1762                                              (Attributes) $1, l);
1763                   
1764                 del.Namespace = current_namespace;
1765                 CheckDef (current_container.AddDelegate (del), del.Name, l);
1766           }     
1767         | opt_attributes
1768           opt_modifiers
1769           DELEGATE VOID   
1770           IDENTIFIER OPEN_PARENS 
1771           opt_formal_parameter_list
1772           CLOSE_PARENS 
1773           SEMICOLON
1774           {
1775                 Location l = lexer.Location;
1776                 Delegate del = new Delegate (
1777                         current_container,
1778                         TypeManager.system_void_expr, (int) $2, MakeName ((string) $5), 
1779                         (Parameters) $7, (Attributes) $1, l);
1780
1781                 del.Namespace = current_namespace;
1782                 CheckDef (current_container.AddDelegate (del), del.Name, l);
1783           }
1784         ;
1785
1786 type_name
1787         : namespace_or_type_name
1788         ;
1789
1790 namespace_or_type_name
1791         : qualified_identifier
1792         ;
1793
1794 /* 
1795  * Before you think of adding a return_type, notice that we have been
1796  * using two rules in the places where it matters (one rule using type
1797  * and another identical one that uses VOID as the return type).  This
1798  * gets rid of a shift/reduce couple
1799  */
1800 type
1801         : type_name {   /* class_type */
1802                 /* 
1803                    This does interfaces, delegates, struct_types, class_types, 
1804                    parent classes, and more! 4.2 
1805                  */
1806                 $$ = DecomposeQI ((string) $1, lexer.Location);
1807           }
1808         | builtin_types
1809         | array_type
1810         | pointer_type    
1811         ;
1812
1813
1814 pointer_type
1815         : type STAR
1816           {
1817                 //
1818                 // Note that here only unmanaged types are allowed but we
1819                 // can't perform checks during this phase - we do it during
1820                 // semantic analysis.
1821                 //
1822                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
1823           }
1824         | VOID STAR
1825           {
1826                 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
1827           }
1828         ;
1829
1830 non_expression_type
1831         : builtin_types 
1832         | non_expression_type rank_specifier
1833           {
1834                 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1835           }
1836         | non_expression_type STAR
1837           {
1838                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
1839           }
1840         | expression rank_specifiers 
1841           {
1842                 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1843           }
1844         | expression STAR 
1845           {
1846                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
1847           }
1848         
1849         //
1850         // We need this because the parser will happily go and reduce IDENTIFIER STAR
1851         // through this different path
1852         //
1853         | multiplicative_expression STAR 
1854           {
1855                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
1856           }
1857         ;
1858
1859 type_list
1860         : type
1861           {
1862                 ArrayList types = new ArrayList ();
1863
1864                 types.Add ($1);
1865                 $$ = types;
1866           }
1867         | type_list COMMA type
1868           {
1869                 ArrayList types = (ArrayList) $1;
1870
1871                 types.Add ($3);
1872                 $$ = types;
1873           }
1874         ;
1875
1876 /*
1877  * replaces all the productions for isolating the various
1878  * simple types, but we need this to reuse it easily in local_variable_type
1879  */
1880 builtin_types
1881         : OBJECT        { $$ = TypeManager.system_object_expr; }
1882         | STRING        { $$ = TypeManager.system_string_expr; }
1883         | BOOL          { $$ = TypeManager.system_boolean_expr; }
1884         | DECIMAL       { $$ = TypeManager.system_decimal_expr; }
1885         | FLOAT         { $$ = TypeManager.system_single_expr; }
1886         | DOUBLE        { $$ = TypeManager.system_double_expr; }
1887         | integral_type
1888         ;
1889
1890 integral_type
1891         : SBYTE         { $$ = TypeManager.system_sbyte_expr; }
1892         | BYTE          { $$ = TypeManager.system_byte_expr; }
1893         | SHORT         { $$ = TypeManager.system_int16_expr; }
1894         | USHORT        { $$ = TypeManager.system_uint16_expr; }
1895         | INT           { $$ = TypeManager.system_int32_expr; }
1896         | UINT          { $$ = TypeManager.system_uint32_expr; }
1897         | LONG          { $$ = TypeManager.system_int64_expr; }
1898         | ULONG         { $$ = TypeManager.system_uint64_expr; }
1899         | CHAR          { $$ = TypeManager.system_char_expr; }
1900         | VOID          { $$ = TypeManager.system_void_expr; }
1901         ;
1902
1903 interface_type
1904         : type_name
1905         ;
1906
1907 array_type
1908         : type rank_specifiers
1909           {
1910                 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1911           }
1912         ;
1913
1914 //
1915 // Expressions, section 7.5
1916 //
1917 primary_expression
1918         : literal
1919           {
1920                 // 7.5.1: Literals
1921           }
1922  
1923         | qualified_identifier
1924           {
1925                 string name = (string) $1;
1926
1927                 $$ = null;
1928                 $$ = DecomposeQI (name, lexer.Location);
1929           }
1930         | parenthesized_expression
1931         | member_access
1932         | invocation_expression
1933         | element_access
1934         | this_access
1935         | base_access
1936         | post_increment_expression
1937         | post_decrement_expression
1938         | new_expression
1939         | typeof_expression
1940         | sizeof_expression
1941         | checked_expression
1942         | unchecked_expression
1943         | pointer_member_access
1944         ;
1945
1946 literal
1947         : boolean_literal
1948         | integer_literal
1949         | real_literal
1950         | LITERAL_CHARACTER     { $$ = new CharLiteral ((char) lexer.Value); }
1951         | LITERAL_STRING        { $$ = new StringLiteral ((string) lexer.Value); }
1952         | NULL                  { $$ = NullLiteral.Null; }
1953         ;
1954
1955 real_literal
1956         : LITERAL_FLOAT         { $$ = new FloatLiteral ((float) lexer.Value); }
1957         | LITERAL_DOUBLE        { $$ = new DoubleLiteral ((double) lexer.Value); }
1958         | LITERAL_DECIMAL       { $$ = new DecimalLiteral ((decimal) lexer.Value); }
1959         ;
1960
1961 integer_literal
1962         : LITERAL_INTEGER       { 
1963                 object v = lexer.Value;
1964
1965                 if (v is int)
1966                         $$ = new IntLiteral ((Int32) v); 
1967                 else if (v is uint)
1968                         $$ = new UIntLiteral ((UInt32) v);
1969                 else if (v is long)
1970                         $$ = new LongLiteral ((Int64) v);
1971                 else if (v is ulong)
1972                         $$ = new ULongLiteral ((UInt64) v);
1973                 else
1974                         Console.WriteLine ("OOPS.  Unexpected result from scanner");
1975           }
1976         ;
1977
1978 boolean_literal
1979         : TRUE                  { $$ = new BoolLiteral (true); }
1980         | FALSE                 { $$ = new BoolLiteral (false); }
1981         ;
1982
1983 parenthesized_expression
1984         : OPEN_PARENS expression CLOSE_PARENS
1985           { $$ = $2; }
1986         ;
1987
1988 member_access
1989         : primary_expression DOT IDENTIFIER
1990           {
1991                 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
1992           }
1993         | predefined_type DOT IDENTIFIER
1994           {
1995                 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
1996           }
1997         ;
1998
1999 predefined_type
2000         : builtin_types
2001         ;
2002
2003 invocation_expression
2004         : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2005           {
2006                 if ($1 == null) {
2007                         Location l = lexer.Location;
2008                         Report.Error (1, l, "Parse error");
2009                 }
2010                 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
2011           }
2012         ; 
2013
2014 opt_argument_list
2015         : /* empty */           { $$ = null; }
2016         | argument_list
2017         ;
2018
2019 argument_list
2020         : argument              
2021           { 
2022                 ArrayList list = new ArrayList ();
2023                 list.Add ($1);
2024                 $$ = list;
2025           }
2026         | argument_list COMMA argument
2027           {
2028                 ArrayList list = (ArrayList) $1;
2029                 list.Add ($3);
2030                 $$ = list;
2031           }
2032         ;
2033
2034 argument
2035         : expression
2036           {
2037                 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
2038           }
2039         | REF variable_reference 
2040           { 
2041                 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
2042           }
2043         | OUT variable_reference 
2044           { 
2045                 $$ = new Argument ((Expression) $2, Argument.AType.Out);
2046           }
2047         ;
2048
2049 variable_reference
2050         : expression { note ("section 5.4"); $$ = $1; }
2051         ;
2052
2053 element_access
2054         : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET 
2055           {
2056                 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
2057           }
2058         | primary_expression rank_specifiers
2059           {
2060                 // So the super-trick is that primary_expression
2061                 // can only be either a SimpleName or a MemberAccess. 
2062                 // The MemberAccess case arises when you have a fully qualified type-name like :
2063                 // Foo.Bar.Blah i;
2064                 // SimpleName is when you have
2065                 // Blah i;
2066                   
2067                 Expression expr = (Expression) $1;  
2068                 if (!(expr is SimpleName || expr is MemberAccess)) {
2069                         Error_ExpectingTypeName (lexer.Location, expr);
2070                         $$ = TypeManager.system_object_expr;
2071                 } else {
2072                         //
2073                         // So we extract the string corresponding to the SimpleName
2074                         // or MemberAccess
2075                         // 
2076                         $$ = new SimpleName (GetQualifiedIdentifier (expr) + (string) $2, lexer.Location);
2077                 }
2078           }
2079         ;
2080
2081 expression_list
2082         : expression
2083           {
2084                 ArrayList list = new ArrayList ();
2085                 list.Add ($1);
2086                 $$ = list;
2087           }
2088         | expression_list COMMA expression
2089           {
2090                 ArrayList list = (ArrayList) $1;
2091                 list.Add ($3);
2092                 $$ = list;
2093           }
2094         ;
2095
2096 this_access
2097         : THIS
2098           {
2099                 $$ = new This (current_block, lexer.Location);
2100           }
2101         ;
2102
2103 base_access
2104         : BASE DOT IDENTIFIER
2105           {
2106                 $$ = new BaseAccess ((string) $3, lexer.Location);
2107           }
2108         | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
2109           {
2110                 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2111           }
2112         ;
2113
2114 post_increment_expression
2115         : primary_expression OP_INC
2116           {
2117                 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2118                                        (Expression) $1, lexer.Location);
2119           }
2120         ;
2121
2122 post_decrement_expression
2123         : primary_expression OP_DEC
2124           {
2125                 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2126                                        (Expression) $1, lexer.Location);
2127           }
2128         ;
2129
2130 new_expression
2131         : object_or_delegate_creation_expression
2132         | array_creation_expression
2133         ;
2134
2135 object_or_delegate_creation_expression
2136         : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2137           {
2138                 $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
2139           }
2140         ;
2141
2142 array_creation_expression
2143         : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET 
2144           opt_rank_specifier
2145           opt_array_initializer
2146           {
2147                 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
2148           }
2149         | NEW type rank_specifiers array_initializer
2150           {
2151                 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
2152           }
2153         | NEW type error 
2154           {
2155                 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2156           }
2157         ;
2158
2159 opt_rank_specifier
2160         : /* empty */
2161           {
2162                   $$ = "";
2163           }
2164         | rank_specifiers
2165           {
2166                         $$ = $1;
2167           }
2168         ;
2169
2170 rank_specifiers
2171         : rank_specifier opt_rank_specifier
2172           {
2173                   $$ = (string) $2 + (string) $1;
2174           }
2175         ;
2176
2177 rank_specifier
2178         : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2179           {
2180                 $$ = "[" + (string) $2 + "]";
2181           }
2182         ;
2183
2184 opt_dim_separators
2185         : /* empty */
2186           {
2187                 $$ = "";
2188           }
2189         | dim_separators
2190           {
2191                   $$ = $1;
2192           }               
2193         ;
2194
2195 dim_separators
2196         : COMMA
2197           {
2198                 $$ = ",";
2199           }
2200         | dim_separators COMMA
2201           {
2202                 $$ = (string) $1 + ",";
2203           }
2204         ;
2205
2206 opt_array_initializer
2207         : /* empty */
2208           {
2209                 $$ = null;
2210           }
2211         | array_initializer
2212           {
2213                 $$ = $1;
2214           }
2215         ;
2216
2217 array_initializer
2218         : OPEN_BRACE CLOSE_BRACE
2219           {
2220                 ArrayList list = new ArrayList ();
2221                 $$ = list;
2222           }
2223         | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2224           {
2225                 $$ = (ArrayList) $2;
2226           }
2227         ;
2228
2229 variable_initializer_list
2230         : variable_initializer
2231           {
2232                 ArrayList list = new ArrayList ();
2233                 list.Add ($1);
2234                 $$ = list;
2235           }
2236         | variable_initializer_list COMMA variable_initializer
2237           {
2238                 ArrayList list = (ArrayList) $1;
2239                 list.Add ($3);
2240                 $$ = list;
2241           }
2242         ;
2243
2244 typeof_expression
2245         : TYPEOF OPEN_PARENS type CLOSE_PARENS
2246           {
2247                 $$ = new TypeOf ((Expression) $3, lexer.Location);
2248           }
2249         ;
2250
2251 sizeof_expression
2252         : SIZEOF OPEN_PARENS type CLOSE_PARENS { 
2253                 $$ = new SizeOf ((Expression) $3, lexer.Location);
2254           }
2255         ;
2256
2257 checked_expression
2258         : CHECKED OPEN_PARENS expression CLOSE_PARENS
2259           {
2260                 $$ = new CheckedExpr ((Expression) $3, lexer.Location);
2261           }
2262         ;
2263
2264 unchecked_expression
2265         : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2266           {
2267                 $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
2268           }
2269         ;
2270
2271 pointer_member_access 
2272         : primary_expression OP_PTR IDENTIFIER
2273           {
2274                 Expression deref;
2275
2276                 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
2277                 $$ = new MemberAccess (deref, (string) $3, lexer.Location);
2278           }
2279
2280 unary_expression
2281         : primary_expression
2282         | BANG prefixed_unary_expression
2283           {
2284                 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2285           }
2286         | TILDE prefixed_unary_expression
2287           {
2288                 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2289           }
2290         | cast_expression
2291         ;
2292
2293 cast_expression
2294         : OPEN_PARENS expression CLOSE_PARENS unary_expression
2295           {
2296                   $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2297           }
2298         | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2299           {
2300                   $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2301           }
2302         ;
2303
2304         //
2305         // The idea to split this out is from Rhys' grammar
2306         // to solve the problem with casts.
2307         //
2308 prefixed_unary_expression
2309         : unary_expression
2310         | PLUS prefixed_unary_expression
2311           { 
2312                 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2313           } 
2314         | MINUS prefixed_unary_expression 
2315           { 
2316                 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2317           }
2318         | OP_INC prefixed_unary_expression 
2319           {
2320                 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2321                                        (Expression) $2, lexer.Location);
2322           }
2323         | OP_DEC prefixed_unary_expression 
2324           {
2325                 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2326                                        (Expression) $2, lexer.Location);
2327           }
2328         | STAR prefixed_unary_expression
2329           {
2330                 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2331           }
2332         | BITWISE_AND prefixed_unary_expression
2333           {
2334                 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2335           }
2336         ;
2337
2338 pre_increment_expression
2339         : OP_INC prefixed_unary_expression 
2340           {
2341                 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2342                                        (Expression) $2, lexer.Location);
2343           }
2344         ;
2345
2346 pre_decrement_expression
2347         : OP_DEC prefixed_unary_expression 
2348           {
2349                 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2350                                        (Expression) $2, lexer.Location);
2351           }
2352         ;
2353
2354 multiplicative_expression
2355         : prefixed_unary_expression
2356         | multiplicative_expression STAR prefixed_unary_expression
2357           {
2358                 $$ = new Binary (Binary.Operator.Multiply, 
2359                                  (Expression) $1, (Expression) $3, lexer.Location);
2360           }
2361         | multiplicative_expression DIV prefixed_unary_expression
2362           {
2363                 $$ = new Binary (Binary.Operator.Division, 
2364                                  (Expression) $1, (Expression) $3, lexer.Location);
2365           }
2366         | multiplicative_expression PERCENT prefixed_unary_expression 
2367           {
2368                 $$ = new Binary (Binary.Operator.Modulus, 
2369                                  (Expression) $1, (Expression) $3, lexer.Location);
2370           }
2371         ;
2372
2373 additive_expression
2374         : multiplicative_expression
2375         | additive_expression PLUS multiplicative_expression 
2376           {
2377                 $$ = new Binary (Binary.Operator.Addition, 
2378                                  (Expression) $1, (Expression) $3, lexer.Location);
2379           }
2380         | additive_expression MINUS multiplicative_expression
2381           {
2382                 $$ = new Binary (Binary.Operator.Subtraction, 
2383                                  (Expression) $1, (Expression) $3, lexer.Location);
2384           }
2385         ;
2386
2387 shift_expression
2388         : additive_expression
2389         | shift_expression OP_SHIFT_LEFT additive_expression
2390           {
2391                 $$ = new Binary (Binary.Operator.LeftShift, 
2392                                  (Expression) $1, (Expression) $3, lexer.Location);
2393           }
2394         | shift_expression OP_SHIFT_RIGHT additive_expression
2395           {
2396                 $$ = new Binary (Binary.Operator.RightShift, 
2397                                  (Expression) $1, (Expression) $3, lexer.Location);
2398           }
2399         ; 
2400
2401 relational_expression
2402         : shift_expression
2403         | relational_expression OP_LT shift_expression
2404           {
2405                 $$ = new Binary (Binary.Operator.LessThan, 
2406                                  (Expression) $1, (Expression) $3, lexer.Location);
2407           }
2408         | relational_expression OP_GT shift_expression
2409           {
2410                 $$ = new Binary (Binary.Operator.GreaterThan, 
2411                                  (Expression) $1, (Expression) $3, lexer.Location);
2412           }
2413         | relational_expression OP_LE shift_expression
2414           {
2415                 $$ = new Binary (Binary.Operator.LessThanOrEqual, 
2416                                  (Expression) $1, (Expression) $3, lexer.Location);
2417           }
2418         | relational_expression OP_GE shift_expression
2419           {
2420                 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, 
2421                                  (Expression) $1, (Expression) $3, lexer.Location);
2422           }
2423         | relational_expression IS type
2424           {
2425                 $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
2426           }
2427         | relational_expression AS type
2428           {
2429                 $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
2430           }
2431         ;
2432
2433 equality_expression
2434         : relational_expression
2435         | equality_expression OP_EQ relational_expression
2436           {
2437                 $$ = new Binary (Binary.Operator.Equality, 
2438                                  (Expression) $1, (Expression) $3, lexer.Location);
2439           }
2440         | equality_expression OP_NE relational_expression
2441           {
2442                 $$ = new Binary (Binary.Operator.Inequality, 
2443                                  (Expression) $1, (Expression) $3, lexer.Location);
2444           }
2445         ; 
2446
2447 and_expression
2448         : equality_expression
2449         | and_expression BITWISE_AND equality_expression
2450           {
2451                 $$ = new Binary (Binary.Operator.BitwiseAnd, 
2452                                  (Expression) $1, (Expression) $3, lexer.Location);
2453           }
2454         ;
2455
2456 exclusive_or_expression
2457         : and_expression
2458         | exclusive_or_expression CARRET and_expression
2459           {
2460                 $$ = new Binary (Binary.Operator.ExclusiveOr, 
2461                                  (Expression) $1, (Expression) $3, lexer.Location);
2462           }
2463         ;
2464
2465 inclusive_or_expression
2466         : exclusive_or_expression
2467         | inclusive_or_expression BITWISE_OR exclusive_or_expression
2468           {
2469                 $$ = new Binary (Binary.Operator.BitwiseOr, 
2470                                  (Expression) $1, (Expression) $3, lexer.Location);
2471           }
2472         ;
2473
2474 conditional_and_expression
2475         : inclusive_or_expression
2476         | conditional_and_expression OP_AND inclusive_or_expression
2477           {
2478                 $$ = new Binary (Binary.Operator.LogicalAnd, 
2479                                  (Expression) $1, (Expression) $3, lexer.Location);
2480           }
2481         ;
2482
2483 conditional_or_expression
2484         : conditional_and_expression
2485         | conditional_or_expression OP_OR conditional_and_expression
2486           {
2487                 $$ = new Binary (Binary.Operator.LogicalOr, 
2488                                  (Expression) $1, (Expression) $3, lexer.Location);
2489           }
2490         ;
2491
2492 conditional_expression
2493         : conditional_or_expression
2494         | conditional_or_expression INTERR expression COLON expression 
2495           {
2496                 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2497           }
2498         ;
2499
2500 assignment_expression
2501         : prefixed_unary_expression ASSIGN expression
2502           {
2503                 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2504           }
2505         | prefixed_unary_expression OP_MULT_ASSIGN expression
2506           {
2507                 Location l = lexer.Location;
2508
2509                 $$ = new CompoundAssign (
2510                         Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
2511           }
2512         | prefixed_unary_expression OP_DIV_ASSIGN expression
2513           {
2514                 Location l = lexer.Location;
2515
2516                 $$ = new CompoundAssign (
2517                         Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
2518           }
2519         | prefixed_unary_expression OP_MOD_ASSIGN expression
2520           {
2521                 Location l = lexer.Location;
2522
2523                 $$ = new CompoundAssign (
2524                         Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
2525           }
2526         | prefixed_unary_expression OP_ADD_ASSIGN expression
2527           {
2528                 Location l = lexer.Location;
2529
2530                 $$ = new CompoundAssign (
2531                         Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
2532           }
2533         | prefixed_unary_expression OP_SUB_ASSIGN expression
2534           {
2535                 Location l = lexer.Location;
2536
2537                 $$ = new CompoundAssign (
2538                         Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
2539           }
2540         | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2541           {
2542                 Location l = lexer.Location;
2543
2544                 $$ = new CompoundAssign (
2545                         Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
2546           }
2547         | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2548           {
2549                 Location l = lexer.Location;
2550
2551                 $$ = new CompoundAssign (
2552                         Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
2553           }
2554         | prefixed_unary_expression OP_AND_ASSIGN expression
2555           {
2556                 Location l = lexer.Location;
2557
2558                 $$ = new CompoundAssign (
2559                         Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
2560           }
2561         | prefixed_unary_expression OP_OR_ASSIGN expression
2562           {
2563                 Location l = lexer.Location;
2564
2565                 $$ = new CompoundAssign (
2566                         Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
2567           }
2568         | prefixed_unary_expression OP_XOR_ASSIGN expression
2569           {
2570                 Location l = lexer.Location;
2571
2572                 $$ = new CompoundAssign (
2573                         Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
2574           }
2575         ;
2576
2577 expression
2578         : conditional_expression
2579         | assignment_expression
2580         ;
2581
2582 constant_expression
2583         : expression
2584         ;
2585
2586 boolean_expression
2587         : expression
2588         ;
2589
2590 //
2591 // 10 classes
2592 //
2593 class_declaration
2594         : opt_attributes
2595           opt_modifiers
2596           CLASS IDENTIFIER
2597           {
2598                 Class new_class;
2599                 string name;
2600
2601                 name = MakeName ((string) $4);
2602
2603                 new_class = new Class (current_container, name, (int) $2, 
2604                                        (Attributes) $1, lexer.Location);
2605                 current_container = new_class;
2606                 current_container.Namespace = current_namespace;
2607                 RootContext.Tree.RecordDecl (name, new_class);
2608           }
2609           opt_class_base
2610           class_body 
2611           opt_semicolon 
2612           {
2613                 Class new_class = (Class) current_container;
2614
2615                 if ($6 != null)
2616                         new_class.Bases = (ArrayList) $6;
2617
2618                 current_container = current_container.Parent;
2619                 CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
2620
2621                 $$ = new_class;
2622           }
2623         ;       
2624
2625 opt_modifiers
2626         : /* empty */           { $$ = (int) 0; }
2627         | modifiers
2628         ;
2629
2630 modifiers
2631         : modifier
2632         | modifiers modifier
2633           { 
2634                 int m1 = (int) $1;
2635                 int m2 = (int) $2;
2636
2637                 if ((m1 & m2) != 0) {
2638                         Location l = lexer.Location;
2639                         Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
2640                 }
2641                 $$ = (int) (m1 | m2);
2642           }
2643         ;
2644
2645 modifier
2646         : NEW                   { $$ = Modifiers.NEW; }
2647         | PUBLIC                { $$ = Modifiers.PUBLIC; }
2648         | PROTECTED             { $$ = Modifiers.PROTECTED; }
2649         | INTERNAL              { $$ = Modifiers.INTERNAL; }
2650         | PRIVATE               { $$ = Modifiers.PRIVATE; }
2651         | ABSTRACT              { $$ = Modifiers.ABSTRACT; }
2652         | SEALED                { $$ = Modifiers.SEALED; }
2653         | STATIC                { $$ = Modifiers.STATIC; }
2654         | READONLY              { $$ = Modifiers.READONLY; }
2655         | VIRTUAL               { $$ = Modifiers.VIRTUAL; }
2656         | OVERRIDE              { $$ = Modifiers.OVERRIDE; }
2657         | EXTERN                { $$ = Modifiers.EXTERN; }
2658         | VOLATILE              { $$ = Modifiers.VOLATILE; }
2659         | UNSAFE                { $$ = Modifiers.UNSAFE; }
2660         ;
2661
2662 opt_class_base
2663         : /* empty */           { $$ = null; }
2664         | class_base            { $$ = $1;   }
2665         ;
2666
2667 class_base
2668         : COLON type_list { $$ = $2; }
2669         ;
2670
2671 //
2672 // Statements (8.2)
2673 //
2674
2675 //
2676 // A block is "contained" on the following places:
2677 //      method_body
2678 //      property_declaration as part of the accessor body (get/set)
2679 //      operator_declaration
2680 //      constructor_declaration
2681 //      destructor_declaration
2682 //      event_declaration as part of add_accessor_declaration or remove_accessor_declaration
2683 //      
2684 block
2685         : OPEN_BRACE 
2686           {
2687                 current_block = new Block (current_block, current_local_parameters,
2688                                            lexer.Location, Location.Null);
2689           } 
2690           opt_statement_list CLOSE_BRACE 
2691           { 
2692                 while (current_block.Implicit)
2693                         current_block = current_block.Parent;
2694                 $$ = current_block;
2695                 current_block.SetEndLocation (lexer.Location);
2696                 current_block = current_block.Parent;
2697           }
2698         ;
2699
2700 opt_statement_list
2701         : /* empty */
2702         | statement_list 
2703         ;
2704
2705 statement_list
2706         : statement
2707         | statement_list statement
2708         ;
2709
2710 statement
2711         : declaration_statement
2712           {
2713                 if ($1 != null && (Block) $1 != current_block){
2714                         current_block.AddStatement ((Statement) $1);
2715                         current_block = (Block) $1;
2716                 }
2717           }
2718         | embedded_statement
2719           {
2720                 Statement s = (Statement) $1;
2721
2722
2723                 current_block.AddStatement ((Statement) $1);
2724           }
2725         | labeled_statement
2726         ;
2727
2728 embedded_statement
2729         : block
2730         | empty_statement
2731         | expression_statement
2732         | selection_statement
2733         | iteration_statement
2734         | jump_statement                  
2735         | try_statement
2736         | checked_statement
2737         | unchecked_statement
2738         | lock_statement
2739         | using_statement
2740         | unsafe_statement
2741         | fixed_statement
2742         ;
2743
2744 empty_statement
2745         : SEMICOLON
2746           {
2747                   $$ = new EmptyStatement ();
2748           }
2749         ;
2750
2751 labeled_statement
2752         : IDENTIFIER COLON 
2753           {
2754                 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
2755
2756                 if (!current_block.AddLabel ((string) $1, labeled)){
2757                         Location l = lexer.Location;
2758                         Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
2759                 }       
2760                 current_block.AddStatement (labeled);
2761           }
2762           statement
2763         ;
2764
2765 declaration_statement
2766         : local_variable_declaration SEMICOLON
2767           {
2768                 if ($1 != null){
2769                         DictionaryEntry de = (DictionaryEntry) $1;
2770
2771                         $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
2772                 }
2773           }
2774
2775         | local_constant_declaration SEMICOLON
2776           {
2777                 if ($1 != null){
2778                         DictionaryEntry de = (DictionaryEntry) $1;
2779
2780                         $$ = declare_local_constant ((Expression) de.Key, (VariableDeclaration) de.Value);
2781                 }
2782           }
2783         ;
2784
2785 /* 
2786  * The following is from Rhys' grammar:
2787  * > Types in local variable declarations must be recognized as 
2788  * > expressions to prevent reduce/reduce errors in the grammar.
2789  * > The expressions are converted into types during semantic analysis.
2790  */
2791 local_variable_type
2792         : primary_expression opt_rank_specifier
2793           { 
2794                 // FIXME: Do something smart here regarding the composition of the type.
2795
2796                 // Ok, the above "primary_expression" is there to get rid of
2797                 // both reduce/reduce and shift/reduces in the grammar, it should
2798                 // really just be "type_name".  If you use type_name, a reduce/reduce
2799                 // creeps up.  If you use qualified_identifier (which is all we need
2800                 // really) two shift/reduces appear.
2801                 // 
2802
2803                 // So the super-trick is that primary_expression
2804                 // can only be either a SimpleName or a MemberAccess. 
2805                 // The MemberAccess case arises when you have a fully qualified type-name like :
2806                 // Foo.Bar.Blah i;
2807                 // SimpleName is when you have
2808                 // Blah i;
2809                   
2810                 Expression expr = (Expression) $1;  
2811                 if (!(expr is SimpleName || expr is MemberAccess)) {
2812                         Error_ExpectingTypeName (lexer.Location, expr);
2813                         $$ = null;
2814                 } else {
2815                         //
2816                         // So we extract the string corresponding to the SimpleName
2817                         // or MemberAccess
2818                         // 
2819                         if ((string) $2 == "")
2820                                 $$ = $1;
2821                         else
2822                                 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2823                 }
2824           }
2825         | builtin_types opt_rank_specifier
2826           {
2827                 if ((string) $2 == "")
2828                         $$ = $1;
2829                 else
2830                         $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2831           }
2832         ;
2833
2834 local_variable_pointer_type
2835         : primary_expression STAR
2836           {
2837                 Expression expr = (Expression) $1;  
2838                 Location l = lexer.Location;
2839
2840                 if (!(expr is SimpleName || expr is MemberAccess)) {
2841                         Error_ExpectingTypeName (l, expr);
2842
2843                         $$ = null;
2844                 } else 
2845                         $$ = new ComposedCast ((Expression) $1, "*", l);
2846           }
2847         | builtin_types STAR
2848           {
2849                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
2850           }
2851         | VOID STAR
2852           {
2853                 $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
2854           }
2855         | local_variable_pointer_type STAR
2856           {
2857                 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
2858           }
2859         ;
2860
2861 local_variable_declaration
2862         : local_variable_type variable_declarators
2863           {
2864                 if ($1 != null)
2865                         $$ = new DictionaryEntry ($1, $2);
2866                 else
2867                         $$ = null;
2868           }
2869         | local_variable_pointer_type opt_rank_specifier variable_declarators
2870         {
2871                 if ($1 != null){
2872                         Expression t;
2873
2874                         if ((string) $2 == "")
2875                                 t = (Expression) $1;
2876                         else
2877                                 t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
2878                         $$ = new DictionaryEntry (t, $3);
2879                 } else 
2880                         $$ = null;
2881         }
2882         ;
2883
2884 local_constant_declaration
2885         : CONST local_variable_type constant_declarator
2886           {
2887                 if ($2 != null)
2888                         $$ = new DictionaryEntry ($2, $3);
2889                 else
2890                         $$ = null;
2891           }
2892         ;
2893
2894 expression_statement
2895         : statement_expression SEMICOLON
2896           {
2897                 $$ = $1;
2898           }
2899         ;
2900
2901         //
2902         // We have to do the wrapping here and not in the case above,
2903         // because statement_expression is used for example in for_statement
2904         //
2905 statement_expression
2906         : invocation_expression         { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2907         | object_creation_expression    { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2908         | assignment_expression         { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2909         | post_increment_expression     { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2910         | post_decrement_expression     { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2911         | pre_increment_expression      { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2912         | pre_decrement_expression      { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
2913         | error {
2914                 Report.Error (1002, lexer.Location, "Expecting `;'");
2915           }
2916         ;
2917
2918 object_creation_expression
2919         : object_or_delegate_creation_expression
2920           { note ("complain if this is a delegate maybe?"); } 
2921         ;
2922
2923 selection_statement
2924         : if_statement
2925         | switch_statement
2926         ; 
2927
2928 if_statement
2929         : if_statement_open if_statement_rest
2930           {
2931                 $$ = $2;
2932           }
2933         ;
2934
2935 if_statement_open
2936         : IF OPEN_PARENS 
2937           {
2938                 oob_stack.Push (lexer.Location);
2939           }
2940         ;
2941
2942 if_statement_rest
2943         : boolean_expression CLOSE_PARENS 
2944           embedded_statement
2945           { 
2946                 Location l = (Location) oob_stack.Pop ();
2947
2948                 $$ = new If ((Expression) $1, (Statement) $3, l);
2949
2950                 if (RootContext.WarningLevel >= 3){
2951                         if ($3 is EmptyStatement)
2952                                 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
2953                 }
2954
2955           }
2956         | boolean_expression CLOSE_PARENS
2957           embedded_statement ELSE embedded_statement
2958           {
2959                 Location l = (Location) oob_stack.Pop ();
2960
2961                 $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
2962           }
2963         ;
2964
2965 switch_statement
2966         : SWITCH OPEN_PARENS 
2967           { 
2968                 oob_stack.Push (lexer.Location);
2969                 switch_stack.Push (current_block);
2970           }
2971           expression CLOSE_PARENS 
2972           switch_block
2973           {
2974                 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
2975                 current_block = (Block) switch_stack.Pop ();
2976           }
2977         ;
2978
2979 switch_block
2980         : OPEN_BRACE
2981           opt_switch_sections
2982           CLOSE_BRACE
2983           {
2984                 $$ = $2;
2985           }
2986         ;
2987
2988 opt_switch_sections
2989         : /* empty */           
2990           {
2991                 Report.Error (1522, lexer.Location, "Empty switch block"); 
2992           }
2993         | switch_sections
2994         ;
2995
2996 switch_sections
2997         : switch_section 
2998           {
2999                 ArrayList sections = new ArrayList ();
3000
3001                 sections.Add ($1);
3002                 $$ = sections;
3003           }
3004         | switch_sections switch_section
3005           {
3006                 ArrayList sections = (ArrayList) $1;
3007
3008                 sections.Add ($2);
3009                 $$ = sections;
3010           }
3011         ;
3012
3013 switch_section
3014         : switch_labels
3015           {
3016                 current_block = new Block (current_block, lexer.Location, lexer.Location);
3017           }
3018           statement_list 
3019           {
3020                 Block topmost = current_block;
3021
3022                 while (topmost.Implicit)
3023                         topmost = topmost.Parent;
3024                 $$ = new SwitchSection ((ArrayList) $1, topmost);
3025           }
3026         ;
3027
3028 switch_labels
3029         : switch_label 
3030           {
3031                 ArrayList labels = new ArrayList ();
3032
3033                 labels.Add ($1);
3034                 $$ = labels;
3035           }
3036         | switch_labels switch_label 
3037           {
3038                 ArrayList labels = (ArrayList) ($1);
3039                 labels.Add ($2);
3040
3041                 $$ = labels;
3042           }
3043         ;
3044
3045 switch_label
3046         : CASE constant_expression COLON        { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
3047         | DEFAULT COLON                         { $$ = new SwitchLabel (null, lexer.Location); }
3048         | error {
3049                 Report.Error (
3050                         1523, lexer.Location, 
3051                         "The keyword case or default must precede code in switch block");
3052           }
3053         ;
3054
3055 iteration_statement
3056         : while_statement
3057         | do_statement
3058         | for_statement
3059         | foreach_statement
3060         ;
3061
3062 while_statement
3063         : WHILE OPEN_PARENS 
3064         {
3065                 oob_stack.Push (lexer.Location);
3066         }
3067         boolean_expression CLOSE_PARENS embedded_statement
3068         {
3069                 Location l = (Location) oob_stack.Pop ();
3070                 $$ = new While ((Expression) $4, (Statement) $6, l);
3071         
3072                 if (RootContext.WarningLevel >= 3){
3073                         if ($6 is EmptyStatement)
3074                                 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3075                 }
3076         }
3077         ;
3078
3079 do_statement
3080         : DO embedded_statement 
3081           WHILE OPEN_PARENS {
3082                 oob_stack.Push (lexer.Location);
3083           }
3084           boolean_expression CLOSE_PARENS SEMICOLON
3085           {
3086                 Location l = (Location) oob_stack.Pop ();
3087
3088                 $$ = new Do ((Statement) $2, (Expression) $6, l);
3089           }
3090         ;
3091
3092 for_statement
3093         : FOR OPEN_PARENS 
3094           opt_for_initializer SEMICOLON
3095           {
3096                 Block assign_block = new Block (current_block);
3097                 current_block = assign_block;
3098
3099                 if ($3 is DictionaryEntry){
3100                         DictionaryEntry de = (DictionaryEntry) $3;
3101                         
3102                         Expression type = (Expression) de.Key;
3103                         ArrayList var_declarators = (ArrayList) de.Value;
3104
3105                         foreach (VariableDeclaration decl in var_declarators){
3106
3107                                 VariableInfo vi;
3108
3109                                 vi = current_block.AddVariable (
3110                                         type, decl.identifier, current_local_parameters, decl.Location);
3111                                 if (vi == null)
3112                                         continue;
3113
3114                                 Location l = lexer.Location;
3115                                 Expression expr;
3116                                 if (decl.expression_or_array_initializer is Expression){
3117                                         expr = (Expression) decl.expression_or_array_initializer;
3118                                 } else if (decl.expression_or_array_initializer == null) {
3119                                         expr = null;
3120                                 } else {
3121                                         ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3122                                         expr = new ArrayCreation (type, "", init, decl.Location);
3123                                 }
3124                                         
3125                                 LocalVariableReference var;
3126                                 var = new LocalVariableReference (assign_block, decl.identifier, l);
3127
3128                                 if (expr != null) {
3129                                         Assign a = new Assign (var, expr, decl.Location);
3130                                         
3131                                         assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3132                                 }
3133                         }
3134                         
3135                         $3 = null;
3136                 } 
3137                 oob_stack.Push (lexer.Location);
3138           } 
3139           opt_for_condition SEMICOLON
3140           opt_for_iterator CLOSE_PARENS 
3141           embedded_statement
3142           {
3143                 Location l = (Location) oob_stack.Pop ();
3144
3145                 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
3146
3147                 if (RootContext.WarningLevel >= 3){
3148                         if ($10 is EmptyStatement)
3149                                 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
3150                 }
3151
3152                 current_block.AddStatement (f);
3153                 while (current_block.Implicit)
3154                         current_block = current_block.Parent;
3155                 $$ = current_block;
3156                 current_block = current_block.Parent;
3157           }
3158         ;
3159
3160 opt_for_initializer
3161         : /* empty */           { $$ = new EmptyStatement (); }
3162         | for_initializer       
3163         ;
3164
3165 for_initializer
3166         : local_variable_declaration
3167         | statement_expression_list
3168         ;
3169
3170 opt_for_condition
3171         : /* empty */           { $$ = null; }
3172         | boolean_expression
3173         ;
3174
3175 opt_for_iterator
3176         : /* empty */           { $$ = new EmptyStatement (); }
3177         | for_iterator
3178         ;
3179
3180 for_iterator
3181         : statement_expression_list
3182         ;
3183
3184 statement_expression_list
3185         : statement_expression  
3186           {
3187                 // CHANGE: was `null'
3188                 Block b = new Block (current_block, true);   
3189
3190                 b.AddStatement ((Statement) $1);
3191                 $$ = b;
3192           }
3193         | statement_expression_list COMMA statement_expression
3194           {
3195                 Block b = (Block) $1;
3196
3197                 b.AddStatement ((Statement) $3);
3198                 $$ = $1;
3199           }
3200         ;
3201
3202 foreach_statement
3203         : FOREACH OPEN_PARENS type IDENTIFIER IN 
3204           {
3205                 oob_stack.Push (lexer.Location);
3206           }
3207           expression CLOSE_PARENS 
3208           {
3209                 oob_stack.Push (current_block);
3210
3211                 Block foreach_block = new Block (current_block, true);
3212                 LocalVariableReference v = null;
3213                 Location l = lexer.Location;
3214                 VariableInfo vi;
3215
3216                 vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
3217                 if (vi != null) {
3218                         vi.ReadOnly = true;
3219
3220                         // Get a writable reference to this read-only variable.
3221                         v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
3222                 }
3223                 current_block = foreach_block;
3224
3225                 oob_stack.Push (v);
3226                 oob_stack.Push (current_block);
3227           } 
3228           embedded_statement 
3229           {
3230                 Block foreach_block = (Block) oob_stack.Pop ();
3231                 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3232                 Block prev_block = (Block) oob_stack.Pop ();
3233                 Location l = (Location) oob_stack.Pop ();
3234
3235                 current_block = prev_block;
3236
3237                 if (v != null) {
3238                         Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
3239                         foreach_block.AddStatement (f);
3240                 }
3241
3242                 $$ = foreach_block;
3243           }
3244         ;
3245
3246 jump_statement
3247         : break_statement
3248         | continue_statement
3249         | goto_statement
3250         | return_statement
3251         | throw_statement
3252         ;
3253
3254 break_statement
3255         : BREAK SEMICOLON
3256           {
3257                 $$ = new Break (lexer.Location);
3258           }
3259         ;
3260
3261 continue_statement
3262         : CONTINUE SEMICOLON
3263           {
3264                 $$ = new Continue (lexer.Location);
3265           }
3266         ;
3267
3268 goto_statement
3269         : GOTO IDENTIFIER SEMICOLON 
3270           {
3271                 $$ = new Goto (current_block, (string) $2, lexer.Location);
3272           }
3273         | GOTO CASE constant_expression SEMICOLON
3274           {
3275                 $$ = new GotoCase ((Expression) $3, lexer.Location);
3276           }
3277         | GOTO DEFAULT SEMICOLON 
3278           {
3279                 $$ = new GotoDefault (lexer.Location);
3280           }
3281         ; 
3282
3283 return_statement
3284         : RETURN opt_expression SEMICOLON
3285           {
3286                 $$ = new Return ((Expression) $2, lexer.Location);
3287           }
3288         ;
3289
3290 throw_statement
3291         : THROW opt_expression SEMICOLON
3292           {
3293                 $$ = new Throw ((Expression) $2, lexer.Location);
3294           }
3295         ;
3296
3297 opt_expression
3298         : /* empty */
3299         | expression
3300         ;
3301
3302 try_statement
3303         : TRY block catch_clauses 
3304         {
3305                 Catch g = null;
3306                 ArrayList s = new ArrayList ();
3307                 
3308                 foreach (Catch cc in (ArrayList) $3) {
3309                         if (cc.IsGeneral)
3310                                 g = cc;
3311                         else
3312                                 s.Add (cc);
3313                 }
3314
3315                 // Now s contains the list of specific catch clauses
3316                 // and g contains the general one.
3317                 
3318                 $$ = new Try ((Block) $2, s, g, null, lexer.Location);
3319         }
3320         | TRY block opt_catch_clauses FINALLY block
3321           {
3322                 Catch g = null;
3323                 ArrayList s = new ArrayList ();
3324                 ArrayList catch_list = (ArrayList) $3;
3325
3326                 if (catch_list != null){
3327                         foreach (Catch cc in catch_list) {
3328                                 if (cc.IsGeneral)
3329                                         g = cc;
3330                                 else
3331                                         s.Add (cc);
3332                         }
3333                 }
3334
3335                 $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
3336           }
3337         | TRY block error 
3338           {
3339                 Report.Error (1524, lexer.Location, "Expected catch or finally");
3340           }
3341         ;
3342
3343 opt_catch_clauses
3344         : /* empty */  { $$ = null; }
3345         | catch_clauses
3346         ;
3347
3348 catch_clauses
3349         : catch_clause 
3350           {
3351                 ArrayList l = new ArrayList ();
3352
3353                 l.Add ($1);
3354                 $$ = l;
3355           }
3356         | catch_clauses catch_clause
3357           {
3358                 ArrayList l = (ArrayList) $1;
3359
3360                 l.Add ($2);
3361                 $$ = l;
3362           }
3363         ;
3364
3365 opt_identifier
3366         : /* empty */   { $$ = null; }
3367         | IDENTIFIER
3368         ;
3369
3370 catch_clause 
3371         : CATCH opt_catch_args 
3372         {
3373                 Expression type = null;
3374                 string id = null;
3375                 
3376                 if ($2 != null) {
3377                         DictionaryEntry cc = (DictionaryEntry) $2;
3378                         type = (Expression) cc.Key;
3379                         id   = (string) cc.Value;
3380
3381                         if (id != null){
3382                                 ArrayList one = new ArrayList ();
3383                                 Location loc = lexer.Location;
3384
3385                                 one.Add (new VariableDeclaration (id, null, loc));
3386
3387                                 $1 = current_block;
3388                                 current_block = new Block (current_block);
3389                                 Block b = declare_local_variables (type, one, loc);
3390                                 current_block = b;
3391                         }
3392                 }
3393         } block {
3394                 Expression type = null;
3395                 string id = null;
3396
3397                 if ($2 != null){
3398                         DictionaryEntry cc = (DictionaryEntry) $2;
3399                         type = (Expression) cc.Key;
3400                         id   = (string) cc.Value;
3401
3402                         if ($1 != null){
3403                                 //
3404                                 // FIXME: I can change this for an assignment.
3405                                 //
3406                                 while (current_block != (Block) $1)
3407                                         current_block = current_block.Parent;
3408                         }
3409                 }
3410
3411
3412                 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3413         }
3414         ;
3415
3416 opt_catch_args
3417         : /* empty */ { $$ = null; }
3418         | catch_args
3419         ;         
3420
3421 catch_args 
3422         : OPEN_PARENS type opt_identifier CLOSE_PARENS 
3423         {
3424                 $$ = new DictionaryEntry ($2, $3);
3425         }
3426         ;
3427
3428 checked_statement
3429         : CHECKED block
3430           {
3431                 $$ = new Checked ((Block) $2);
3432           }
3433         ;
3434
3435 unchecked_statement
3436         : UNCHECKED block
3437           {
3438                 $$ = new Unchecked ((Block) $2);
3439           }
3440         ;
3441
3442 unsafe_statement
3443         : UNSAFE 
3444         {
3445                 if (!RootContext.Unsafe){
3446                         Report.Error (227, lexer.Location, 
3447                                 "Unsafe code can only be used if --unsafe is used");
3448                 }
3449         } block {
3450                 $$ = new Unsafe ((Block) $3);
3451         }
3452         ;
3453
3454 fixed_statement
3455         : FIXED OPEN_PARENS 
3456           type fixed_pointer_declarators 
3457           CLOSE_PARENS 
3458           {
3459                 Block assign_block = new Block (current_block, true);
3460                 ArrayList list = (ArrayList) $4;
3461                 Expression type = (Expression) $3;
3462                 Location l = lexer.Location;
3463                 int top = list.Count;
3464
3465                 for (int i = 0; i < top; i++){
3466                         Pair p = (Pair) list [i];
3467                         VariableInfo v;
3468
3469                         v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
3470                         if (v == null)
3471                                 continue;
3472                         v.ReadOnly = true;
3473                         p.First = v;
3474                         list [i] = p;
3475                 }
3476                 current_block.AddStatement (assign_block);
3477                 current_block = assign_block;
3478                 oob_stack.Push (assign_block);
3479                 oob_stack.Push (l);
3480           }
3481           embedded_statement 
3482           {
3483                 Location l = (Location) oob_stack.Pop ();
3484                 Block assign_block = (Block) oob_stack.Pop ();
3485
3486                 ArrayList list = (ArrayList) $4;
3487                 int top = list.Count;
3488
3489                 $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
3490           }
3491         ;
3492
3493 fixed_pointer_declarators
3494         : fixed_pointer_declarator      { 
3495                 ArrayList declarators = new ArrayList (); 
3496                 declarators.Add ($1);
3497                 $$ = declarators;
3498           }
3499         | fixed_pointer_declarators COMMA fixed_pointer_declarator
3500           {
3501                 ArrayList declarators = (ArrayList) $1;
3502                 declarators.Add ($3);
3503                 $$ = declarators;
3504           }
3505         ;
3506
3507 fixed_pointer_declarator
3508         : IDENTIFIER ASSIGN expression
3509           {     
3510                 $$ = new Pair ($1, $3);
3511           }
3512         ;
3513
3514 lock_statement
3515         : LOCK OPEN_PARENS expression CLOSE_PARENS 
3516           {
3517                 //
3518           } 
3519           embedded_statement
3520           {
3521                 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
3522           }
3523         ;
3524
3525 using_statement
3526         : USING OPEN_PARENS resource_acquisition CLOSE_PARENS 
3527           {
3528                 Block assign_block = new Block (current_block);
3529                 current_block = assign_block;
3530
3531                 oob_stack.Push (lexer.Location);
3532                 
3533                 if ($3 is DictionaryEntry){
3534                         DictionaryEntry de = (DictionaryEntry) $3;
3535                         Location l = lexer.Location;
3536
3537                         Expression type = (Expression) de.Key;
3538                         ArrayList var_declarators = (ArrayList) de.Value;
3539
3540                         ArrayList vars = new ArrayList ();
3541
3542                         foreach (VariableDeclaration decl in var_declarators){
3543
3544                                 VariableInfo vi = current_block.AddVariable (
3545                                         type, decl.identifier, 
3546                                         current_local_parameters, decl.Location);
3547                                 if (vi == null)
3548                                         continue;
3549                                 vi.ReadOnly = true;
3550
3551                                 Expression expr;
3552                                 if (decl.expression_or_array_initializer is Expression){
3553                                         expr = (Expression) decl.expression_or_array_initializer;
3554                                 } else {
3555                                         ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3556                                         
3557                                         expr = new ArrayCreation (type, "", init, decl.Location);
3558                                 }
3559
3560                                 LocalVariableReference var;
3561
3562                                 // Get a writable reference to this read-only variable.
3563                                 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
3564
3565                                 // This is so that it is not a warning on using variables
3566                                 vi.Used = true;
3567
3568                                 vars.Add (new DictionaryEntry (var, expr));                             
3569
3570                                 // Assign a = new Assign (var, expr, decl.Location);
3571                                 // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
3572                         }
3573                         $3 = new DictionaryEntry (type, vars);
3574                  }
3575           } 
3576           embedded_statement
3577           {
3578                 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
3579                 current_block.AddStatement (u);
3580                 while (current_block.Implicit)
3581                         current_block = current_block.Parent;
3582                 $$ = current_block;
3583                 current_block = current_block.Parent;
3584           }
3585         ; 
3586
3587 resource_acquisition
3588         : local_variable_declaration
3589         | expression
3590         ;
3591
3592 %%
3593
3594 // <summary>
3595 //   A class used to pass around variable declarations and constants
3596 // </summary>
3597 public class VariableDeclaration {
3598         public string identifier;
3599         public object expression_or_array_initializer;
3600         public Location Location;
3601         public Attributes OptAttributes;
3602
3603         public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
3604         {
3605                 this.identifier = id;
3606                 this.expression_or_array_initializer = eoai;
3607                 this.Location = l;
3608                 this.OptAttributes = opt_attrs;
3609         }
3610
3611         public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
3612         {
3613         }
3614 }
3615
3616 // <summary>
3617 //   A class used to hold info about an indexer declarator
3618 // </summary>
3619
3620 public class IndexerDeclaration {
3621         public Expression type;
3622         public string interface_type;
3623         public Parameters param_list;
3624
3625         public IndexerDeclaration (Expression type, string interface_type, Parameters param_list)
3626         {
3627                 this.type = type;
3628                 this.interface_type = interface_type;
3629                 this.param_list = param_list;
3630         }
3631 }
3632
3633 // <summary>
3634 //  A class used to hold info about an operator declarator
3635 // </summary>
3636
3637 public class OperatorDeclaration {
3638         public Operator.OpType optype;
3639         public Expression ret_type, arg1type, arg2type;
3640         public string arg1name, arg2name;
3641         public Location location;
3642
3643         public OperatorDeclaration (Operator.OpType op, Expression ret_type, 
3644                                     Expression arg1type, string arg1name,
3645                                     Expression arg2type, string arg2name, Location location)
3646         {
3647                 optype = op;
3648                 this.ret_type = ret_type;
3649                 this.arg1type = arg1type;
3650                 this.arg1name = arg1name;
3651                 this.arg2type = arg2type;
3652                 this.arg2name = arg2name;
3653                 this.location = location;
3654         }
3655
3656 }
3657
3658 void Error_ExpectingTypeName (Location l, Expression expr)
3659 {
3660         if (expr is Invocation){
3661                 Report.Error (1002, l, "; expected");
3662         } else {
3663                 Report.Error (-1, l, "Invalid Type definition");
3664         }
3665 }
3666
3667 // <summary>
3668 //   Given the @class_name name, it creates a fully qualified name
3669 //   based on the containing declaration space
3670 // </summary>
3671 string 
3672 MakeName (string class_name)
3673 {
3674         string ns = current_namespace.Name;
3675         string container_name = current_container.Name;
3676
3677         if (container_name == ""){
3678                 if (ns != "")
3679                         return ns + "." + class_name;
3680                 else
3681                         return class_name;
3682         } else
3683                 return container_name + "." + class_name;
3684 }
3685
3686 // <summary>
3687 //   Used to report back to the user the result of a declaration
3688 //   in the current declaration space
3689 // </summary>
3690 void 
3691 CheckDef (AdditionResult result, string name, Location l)
3692 {
3693         if (result == AdditionResult.Success)
3694                 return;
3695
3696         switch (result){
3697         case AdditionResult.NameExists:
3698                 Report.Error (102, l, "The container `" + current_container.Name + 
3699                                  "' already contains a definition for `"+
3700                                  name + "'");
3701                 break;
3702
3703
3704                 //
3705                 // This is handled only for static Constructors, because
3706                 // in reality we handle these by the semantic analysis later
3707                 //
3708         case AdditionResult.MethodExists:
3709                 Report.Error (
3710                         111, l, "Class `"+current_container.Name+
3711                         "' already defines a member called '" + 
3712                         name + "' with the same parameter types (more than one default constructor)");
3713                 break;
3714
3715         case AdditionResult.EnclosingClash:
3716                 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
3717                 break;
3718                 
3719         case AdditionResult.NotAConstructor:
3720                 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
3721                 break;
3722         }
3723 }
3724
3725 void 
3726 CheckDef (bool result, string name, Location l)
3727 {
3728         if (result)
3729                 return;
3730         CheckDef (AdditionResult.NameExists, name, l);
3731 }
3732
3733 Expression DecomposeQI (string name, Location loc)
3734 {
3735         Expression o;
3736
3737         if (name.IndexOf ('.') == -1){
3738                 return new SimpleName (name, loc);
3739         } else {
3740                 int pos = name.LastIndexOf (".");
3741                 string left = name.Substring (0, pos);
3742                 string right = name.Substring (pos + 1);
3743
3744                 o = DecomposeQI (left, loc);
3745
3746                 return new MemberAccess (o, right, loc);
3747         }
3748 }
3749
3750 // <summary>
3751 //  This method is used to get at the complete string representation of
3752 //  a fully-qualified type name, hiding inside a MemberAccess ;-)
3753 //  This is necessary because local_variable_type admits primary_expression
3754 //  as the type of the variable. So we do some extra checking
3755 // </summary>
3756 string GetQualifiedIdentifier (Expression expr)
3757 {
3758         if (expr is SimpleName)
3759                 return ((SimpleName)expr).Name;
3760         else if (expr is MemberAccess)
3761                 return GetQualifiedIdentifier (((MemberAccess)expr).Expr) + "." + ((MemberAccess) expr).Identifier;
3762         else 
3763                 throw new Exception ("Expr has to be either SimpleName or MemberAccess! (" + expr + ")");
3764         
3765 }
3766
3767 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
3768 {
3769         Block implicit_block;
3770         ArrayList inits = null;
3771
3772         //
3773         // We use the `Used' property to check whether statements
3774         // have been added to the current block.  If so, we need
3775         // to create another block to contain the new declaration
3776         // otherwise, as an optimization, we use the same block to
3777         // add the declaration.
3778         //
3779         // FIXME: A further optimization is to check if the statements
3780         // that were added were added as part of the initialization
3781         // below.  In which case, no other statements have been executed
3782         // and we might be able to reduce the number of blocks for
3783         // situations like this:
3784         //
3785         // int j = 1;  int k = j + 1;
3786         //
3787         if (current_block.Used) {
3788                 implicit_block = new Block (current_block, true, loc, Location.Null);
3789                 implicit_block.AddChildVariableNames (current_block);
3790         } else
3791                 implicit_block = current_block;
3792
3793         foreach (VariableDeclaration decl in variable_declarators){
3794
3795                 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
3796                         if (decl.expression_or_array_initializer != null){
3797                                 if (inits == null)
3798                                         inits = new ArrayList ();
3799                                 inits.Add (decl);
3800                         }
3801                 }
3802         }
3803
3804         if (inits == null)
3805                 return implicit_block;
3806
3807         foreach (VariableDeclaration decl in inits){
3808                 Assign assign;
3809                 Expression expr;
3810                 
3811                 if (decl.expression_or_array_initializer is Expression){
3812                         expr = (Expression) decl.expression_or_array_initializer;
3813
3814                 } else {
3815                         ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3816                         
3817                         expr = new ArrayCreation (type, "", init, decl.Location);
3818                 }
3819
3820                 LocalVariableReference var;
3821                 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
3822
3823                 assign = new Assign (var, expr, decl.Location);
3824
3825                 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
3826         }
3827         
3828         return implicit_block;
3829 }
3830
3831 Block declare_local_constant (Expression type, VariableDeclaration decl)
3832 {
3833         Block implicit_block;
3834
3835         if (current_block.Used)
3836                 implicit_block = new Block (current_block, true);
3837         else
3838                 implicit_block = current_block;
3839
3840         if (!(implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
3841                                           current_local_parameters, decl.Location))){
3842         }
3843         
3844         return implicit_block;
3845 }
3846
3847 void CheckAttributeTarget (string a)
3848 {
3849         switch (a) {
3850
3851         case "assembly" : case "field" : case "method" : case "param" : case "property" : case "type" :
3852                 return;
3853                 
3854         default :
3855                 Location l = lexer.Location;
3856                 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
3857                 break;
3858         }
3859
3860 }
3861
3862 void CheckUnaryOperator (Operator.OpType op)
3863 {
3864         switch (op) {
3865                 
3866         case Operator.OpType.LogicalNot: 
3867         case Operator.OpType.OnesComplement: 
3868         case Operator.OpType.Increment:
3869         case Operator.OpType.Decrement:
3870         case Operator.OpType.True: 
3871         case Operator.OpType.False: 
3872         case Operator.OpType.Addition: 
3873         case Operator.OpType.Subtraction:
3874                 
3875                 break;
3876                 
3877         default :
3878                 Location l = lexer.Location;
3879                 Report.Error (1019, l, "Overloadable unary operator expected"); 
3880                 break;
3881                 
3882         }
3883 }
3884
3885 void CheckBinaryOperator (Operator.OpType op)
3886 {
3887         switch (op) {
3888                 
3889         case Operator.OpType.Addition: 
3890         case Operator.OpType.Subtraction: 
3891         case Operator.OpType.Multiply:
3892         case Operator.OpType.Division:
3893         case Operator.OpType.Modulus: 
3894         case Operator.OpType.BitwiseAnd: 
3895         case Operator.OpType.BitwiseOr:
3896         case Operator.OpType.ExclusiveOr: 
3897         case Operator.OpType.LeftShift: 
3898         case Operator.OpType.RightShift:
3899         case Operator.OpType.Equality: 
3900         case Operator.OpType.Inequality:
3901         case Operator.OpType.GreaterThan: 
3902         case Operator.OpType.LessThan: 
3903         case Operator.OpType.GreaterThanOrEqual:
3904         case Operator.OpType.LessThanOrEqual:
3905                 break;
3906                 
3907         default :
3908                 Location l = lexer.Location;
3909                 Report.Error (1020, l, "Overloadable binary operator expected");
3910                 break;
3911         }
3912         
3913 }
3914
3915 void syntax_error (Location l, string msg)
3916 {
3917         Report.Error (1003, l, "Syntax error, " + msg);
3918 }
3919
3920 void output (string s)
3921 {
3922         Console.WriteLine (s);
3923 }
3924
3925 void note (string s)
3926 {
3927         // Used to put annotations
3928 }
3929
3930 Tokenizer lexer;
3931
3932 public Tokenizer Lexer {
3933         get {
3934                 return lexer;
3935         }
3936 }                  
3937
3938 public CSharpParser (StreamReader reader, SourceFile file, ArrayList defines)
3939 {
3940         current_namespace = new Namespace (null, file, "");
3941         this.name = file.Name;
3942         this.file = file;
3943         current_container = RootContext.Tree.Types;
3944         current_container.Namespace = current_namespace;
3945         oob_stack = new Stack ();
3946         switch_stack = new Stack ();
3947
3948         lexer = new Tokenizer (reader, file, defines);
3949 }
3950
3951 public override void parse ()
3952 {
3953         try {
3954                 if (yacc_verbose_flag)
3955                         yyparse (lexer, new yydebug.yyDebugSimple ());
3956                 else
3957                         yyparse (lexer);
3958                 Tokenizer tokenizer = lexer as Tokenizer;
3959                 tokenizer.cleanup ();           
3960         } catch (Exception e){
3961                 // Please do not remove this, it is used during debugging
3962                 // of the grammar
3963                 //
3964                 Report.Error (-25, lexer.Location, ": Parsing error ");
3965                 Console.WriteLine (e);
3966         }
3967 }
3968
3969 /* end end end */
3970 }