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