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