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