2009-11-24 Jb Evain <jbevain@novell.com>
[mcs.git] / mcs / cs-parser.jay
blob019eeb64fa842a82b2884e31a79e82c9347f852b
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 //          Marek Safar         (marek.safar@gmail.com)
8 //
9 // Dual Licensed under the terms of the GNU GPL and the MIT X11 license
11 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (C) 2004 Novell, Inc
14 // TODO:
15 //   (1) Figure out why error productions dont work.  `type-declaration' is a
16 //       great spot to put an `error' because you can reproduce it with this input:
17 //       "public X { }"
19 // Possible optimization:
20 //   Run memory profiler with parsing only, and consider dropping 
21 //   arraylists where not needed.   Some pieces can use linked lists.
24 using System.Text;
25 using System.IO;
26 using System;
28 namespace Mono.CSharp
30         using System.Collections;
32         /// <summary>
33         ///    The C# Parser
34         /// </summary>
35         public class CSharpParser
36         {
37                 [Flags]
38                 enum ParameterModifierType
39                 {
40                         Ref             = 1 << 1,
41                         Out             = 1 << 2,
42                         This    = 1 << 3,
43                         Params  = 1 << 4,
44                         Arglist = 1 << 5,
45                         DefaultValue = 1 << 6,
46                         
47                         All = Ref | Out | This | Params | Arglist | DefaultValue
48                 }
49         
50                 NamespaceEntry  current_namespace;
51                 TypeContainer   current_container;
52                 DeclSpace       current_class;
53         
54                 /// <summary>
55                 ///   Current block is used to add statements as we find
56                 ///   them.  
57                 /// </summary>
58                 Block      current_block;
60                 Delegate   current_delegate;
61                 
62                 GenericMethod current_generic_method;
63                 AnonymousMethodExpression current_anonymous_method;
65                 /// <summary>
66                 ///   This is used by the unary_expression code to resolve
67                 ///   a name against a parameter.  
68                 /// </summary>
69                 
70                 // FIXME: This is very ugly and it's very hard to reset it correctly
71                 // on all places, especially when some parameters are autogenerated.
72                 ParametersCompiled current_local_parameters;
74                 /// <summary>
75                 ///   Using during property parsing to describe the implicit
76                 ///   value parameter that is passed to the "set" and "get"accesor
77                 ///   methods (properties and indexers).
78                 /// </summary>
79                 FullNamedExpression implicit_value_parameter_type;
80                 ParametersCompiled indexer_parameters;
82                 /// <summary>
83                 ///   Hack to help create non-typed array initializer
84                 /// </summary>
85                 public static FullNamedExpression current_array_type;
86                 FullNamedExpression pushed_current_array_type;
88                 /// <summary>
89                 ///   Used to determine if we are parsing the get/set pair
90                 ///   of an indexer or a property
91                 /// </summmary>
92                 bool parsing_indexer;
94                 bool parsing_anonymous_method;
96                 ///
97                 /// An out-of-band stack.
98                 ///
99                 static Stack oob_stack;
101                 ///
102                 /// Switch stack.
103                 ///
104                 Stack switch_stack;
106                 ///
107                 /// Controls the verbosity of the errors produced by the parser
108                 ///
109                 static public int yacc_verbose_flag;
111                 /// 
112                 /// Used by the interactive shell, flags whether EOF was reached
113                 /// and an error was produced
114                 ///
115                 public bool UnexpectedEOF;
117                 ///
118                 /// The current file.
119                 ///
120                 CompilationUnit file;
122                 ///
123                 /// Temporary Xml documentation cache.
124                 /// For enum types, we need one more temporary store.
125                 ///
126                 string tmpComment;
127                 string enumTypeComment;
128                         
129                 /// Current attribute target
130                 string current_attr_target;
131                 
132                 /// assembly and module attribute definitions are enabled
133                 bool global_attrs_enabled = true;
134                 bool has_get, has_set;
135                 
136                 ParameterModifierType valid_param_mod;
137                 
138                 bool default_parameter_used;
140                 /// When using the interactive parser, this holds the
141                 /// resulting expression
142                 public object InteractiveResult;
144                 //
145                 // Keeps track of global data changes to undo on parser error
146                 //
147                 public Undo undo;
148                 
149                 // Stack<ToplevelBlock>
150                 Stack linq_clause_blocks;
152                 // A counter to create new class names in interactive mode
153                 static int class_count;
154                 
155                 CompilerContext compiler;
158 %token EOF
159 %token NONE   /* This token is never returned by our lexer */
160 %token ERROR            // This is used not by the parser, but by the tokenizer.
161                         // do not remove.
164  *These are the C# keywords
165  */
166 %token FIRST_KEYWORD
167 %token ABSTRACT 
168 %token AS
169 %token ADD
170 %token BASE     
171 %token BOOL     
172 %token BREAK    
173 %token BYTE     
174 %token CASE     
175 %token CATCH    
176 %token CHAR     
177 %token CHECKED  
178 %token CLASS    
179 %token CONST    
180 %token CONTINUE 
181 %token DECIMAL  
182 %token DEFAULT  
183 %token DELEGATE 
184 %token DO       
185 %token DOUBLE   
186 %token ELSE     
187 %token ENUM     
188 %token EVENT    
189 %token EXPLICIT 
190 %token EXTERN   
191 %token FALSE    
192 %token FINALLY  
193 %token FIXED    
194 %token FLOAT    
195 %token FOR      
196 %token FOREACH  
197 %token GOTO     
198 %token IF       
199 %token IMPLICIT 
200 %token IN       
201 %token INT      
202 %token INTERFACE
203 %token INTERNAL 
204 %token IS       
205 %token LOCK     
206 %token LONG     
207 %token NAMESPACE
208 %token NEW      
209 %token NULL     
210 %token OBJECT   
211 %token OPERATOR 
212 %token OUT      
213 %token OVERRIDE 
214 %token PARAMS   
215 %token PRIVATE  
216 %token PROTECTED
217 %token PUBLIC   
218 %token READONLY 
219 %token REF      
220 %token RETURN   
221 %token REMOVE
222 %token SBYTE    
223 %token SEALED   
224 %token SHORT    
225 %token SIZEOF   
226 %token STACKALLOC
227 %token STATIC   
228 %token STRING   
229 %token STRUCT   
230 %token SWITCH   
231 %token THIS     
232 %token THROW    
233 %token TRUE     
234 %token TRY      
235 %token TYPEOF   
236 %token UINT     
237 %token ULONG    
238 %token UNCHECKED
239 %token UNSAFE   
240 %token USHORT   
241 %token USING    
242 %token VIRTUAL  
243 %token VOID     
244 %token VOLATILE
245 %token WHERE
246 %token WHILE    
247 %token ARGLIST
248 %token PARTIAL
249 %token ARROW
250 %token FROM
251 %token FROM_FIRST
252 %token JOIN
253 %token ON
254 %token EQUALS
255 %token SELECT
256 %token GROUP
257 %token BY
258 %token LET
259 %token ORDERBY
260 %token ASCENDING
261 %token DESCENDING
262 %token INTO
263 %token INTERR_NULLABLE
264 %token EXTERN_ALIAS
266 /* Generics <,> tokens */
267 %token OP_GENERICS_LT
268 %token OP_GENERICS_LT_DECL
269 %token OP_GENERICS_GT
271 /* C# keywords which are not really keywords */
272 %token GET
273 %token SET
275 %left LAST_KEYWORD
277 /* C# single character operators/punctuation. */
278 %token OPEN_BRACE
279 %token CLOSE_BRACE
280 %token OPEN_BRACKET
281 %token CLOSE_BRACKET
282 %token OPEN_PARENS
283 %token CLOSE_PARENS
285 %token DOT
286 %token COMMA
287 %token COLON
288 %token SEMICOLON
289 %token TILDE
291 %token PLUS
292 %token MINUS
293 %token BANG
294 %token ASSIGN
295 %token OP_LT
296 %token OP_GT
297 %token BITWISE_AND
298 %token BITWISE_OR
299 %token STAR
300 %token PERCENT
301 %token DIV
302 %token CARRET
303 %token INTERR
305 /* C# multi-character operators. */
306 %token DOUBLE_COLON
307 %token OP_INC
308 %token OP_DEC
309 %token OP_SHIFT_LEFT
310 %token OP_SHIFT_RIGHT
311 %token OP_LE
312 %token OP_GE
313 %token OP_EQ
314 %token OP_NE
315 %token OP_AND
316 %token OP_OR
317 %token OP_MULT_ASSIGN
318 %token OP_DIV_ASSIGN
319 %token OP_MOD_ASSIGN
320 %token OP_ADD_ASSIGN
321 %token OP_SUB_ASSIGN
322 %token OP_SHIFT_LEFT_ASSIGN
323 %token OP_SHIFT_RIGHT_ASSIGN
324 %token OP_AND_ASSIGN
325 %token OP_XOR_ASSIGN
326 %token OP_OR_ASSIGN
327 %token OP_PTR
328 %token OP_COALESCING
330 /* Numbers */
331 %token LITERAL_INTEGER
332 %token LITERAL_FLOAT
333 %token LITERAL_DOUBLE
334 %token LITERAL_DECIMAL
335 %token LITERAL_CHARACTER
336 %token LITERAL_STRING
338 %token IDENTIFIER
339 %token OPEN_PARENS_LAMBDA
340 %token OPEN_PARENS_CAST
341 %token GENERIC_DIMENSION
342 %token DEFAULT_COLON
344 // Make the parser go into eval mode parsing (statements and compilation units).
345 %token EVAL_STATEMENT_PARSER
346 %token EVAL_COMPILATION_UNIT_PARSER
347 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
349 // 
350 // This token is generated to trigger the completion engine at this point
352 %token GENERATE_COMPLETION
355 // This token is return repeatedly after the first GENERATE_COMPLETION
356 // token is produced and before the final EOF
358 %token COMPLETE_COMPLETION
360 /* Add precedence rules to solve dangling else s/r conflict */
361 %nonassoc IF
362 %nonassoc ELSE
364 /* Define the operator tokens and their precedences */
365 %right ASSIGN
366 %right OP_COALESCING
367 %right INTERR
368 %left OP_OR
369 %left OP_AND
370 %left BITWISE_OR
371 %left BITWISE_AND
372 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
373 %left PLUS MINUS
374 %left STAR DIV PERCENT
375 %right BANG CARRET UMINUS
376 %nonassoc OP_INC OP_DEC
377 %left OPEN_PARENS
378 %left OPEN_BRACKET OPEN_BRACE
379 %left DOT
381 %start compilation_unit
384 compilation_unit
385         : outer_declarations opt_EOF
386         | outer_declarations global_attributes opt_EOF
387         | global_attributes opt_EOF
388         | opt_EOF /* allow empty files */
389         | interactive_parsing  { Lexer.CompleteOnEOF = false; } opt_EOF
390         ;
392 opt_EOF
393         : /* empty */
394           {
395                 Lexer.check_incorrect_doc_comment ();
396           }
397         | EOF
398           {
399                 Lexer.check_incorrect_doc_comment ();
400           }
401         ;
403 outer_declarations
404         : outer_declaration
405         | outer_declarations outer_declaration
406         ;
408 outer_declaration
409         : extern_alias_directive
410         | using_directive 
411         | namespace_member_declaration
412         ;
414 extern_alias_directives
415         : extern_alias_directive
416         | extern_alias_directives extern_alias_directive
417         ;
419 extern_alias_directive
420         : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
421           {
422                 LocatedToken lt = (LocatedToken) $2;
423                 string s = lt.Value;
424                 if (s != "alias"){
425                         syntax_error (lt.Location, "`alias' expected");
426                 } else if (RootContext.Version == LanguageVersion.ISO_1) {
427                         Report.FeatureIsNotAvailable (lt.Location, "external alias");
428                 } else {
429                         lt = (LocatedToken) $3; 
430                         current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report);
431                 }
432           }
433         | EXTERN_ALIAS error
434           {
435                 syntax_error (GetLocation ($1), "`alias' expected");   // TODO: better
436           }
437         ;
439 using_directives
440         : using_directive 
441         | using_directives using_directive
442         ;
444 using_directive
445         : using_alias_directive
446           {
447                 if (RootContext.Documentation != null)
448                         Lexer.doc_state = XmlCommentState.Allowed;
449           }
450         | using_namespace_directive
451           {
452                 if (RootContext.Documentation != null)
453                         Lexer.doc_state = XmlCommentState.Allowed;
454           }
455         ;
457 using_alias_directive
458         : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
459           {
460                 LocatedToken lt = (LocatedToken) $2;
461                 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
462           }
463         | USING error {
464                 CheckIdentifierToken (yyToken, GetLocation ($2));
465                 $$ = null;
466           }
467         ;
469 using_namespace_directive
470         : USING namespace_name SEMICOLON 
471           {
472                 current_namespace.AddUsing ((MemberName) $2, (Location) $1);
473           }
474         ;
477 // Strictly speaking, namespaces don't have attributes but
478 // we parse global attributes along with namespace declarations and then
479 // detach them
480 // 
481 namespace_declaration
482         : opt_attributes NAMESPACE qualified_identifier
483           {
484                 MemberName name = (MemberName) $3;
486                 if ($1 != null) {
487                         Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
488                 }
490                 current_namespace = new NamespaceEntry (
491                         current_namespace, file, name.GetName ());
492                 current_class = current_namespace.SlaveDeclSpace;
493                 current_container = current_class.PartialContainer;
494           } 
495           namespace_body opt_semicolon
496           { 
497                 current_namespace = current_namespace.Parent;
498                 current_class = current_namespace.SlaveDeclSpace;
499                 current_container = current_class.PartialContainer;
500           }
501         ;
503 qualified_identifier
504         : IDENTIFIER
505           {
506                 LocatedToken lt = (LocatedToken) $1;
507                 $$ = new MemberName (lt.Value, lt.Location);
508           }
509         | qualified_identifier DOT IDENTIFIER
510           {
511                 LocatedToken lt = (LocatedToken) $3;
512                 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);           
513           }
514         | error
515           {
516                 syntax_error (lexer.Location, "`.' expected");
517                 $$ = new MemberName ("<invalid>", lexer.Location);
518           }
519         ;
521 opt_semicolon
522         : /* empty */
523         | SEMICOLON
524         ;
526 opt_comma
527         : /* empty */
528         | COMMA
529         ;
531 namespace_name
532         : namespace_or_type_name
533          {
534                 MemberName name = (MemberName) $1;
536                 if (name.TypeArguments != null)
537                         syntax_error (lexer.Location, "namespace name expected");
539                 $$ = name;
540           }
541         ;
543 namespace_body
544         : OPEN_BRACE
545           {
546                 if (RootContext.Documentation != null)
547                         Lexer.doc_state = XmlCommentState.Allowed;
548           }
549           namespace_body_body
550         ;
551         
552 namespace_body_body
553         : opt_extern_alias_directives
554           opt_using_directives
555           opt_namespace_member_declarations
556           CLOSE_BRACE
557         | error
558           {
559                 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
560           }
561           CLOSE_BRACE
562         | opt_extern_alias_directives
563           opt_using_directives
564           opt_namespace_member_declarations
565           EOF
566           {
567                 Report.Error (1513, lexer.Location, "Expected `}'");
568           }
569         ;
571 opt_using_directives
572         : /* empty */
573         | using_directives
574         ;
576 opt_extern_alias_directives
577         : /* empty */
578         | extern_alias_directives
579         ;
581 opt_namespace_member_declarations
582         : /* empty */
583         | namespace_member_declarations
584         ;
586 namespace_member_declarations
587         : namespace_member_declaration
588         | namespace_member_declarations namespace_member_declaration
589         ;
591 namespace_member_declaration
592         : type_declaration
593           {
594                 if ($1 != null) {
595                         DeclSpace ds = (DeclSpace)$1;
597                         if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
598                                 Report.Error (1527, ds.Location, 
599                                 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
600                         }
601                 }
602                 current_namespace.DeclarationFound = true;
603           }
604         | namespace_declaration {
605                 current_namespace.DeclarationFound = true;
606           }
608         | field_declaration {
609                 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
610           }
611         | method_declaration {
612                 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
613           }
614         ;
616 type_declaration
617         : class_declaration             
618         | struct_declaration
619         | interface_declaration
620         | enum_declaration              
621         | delegate_declaration
623 // Enable this when we have handled all errors, because this acts as a generic fallback
625 //      | error {
626 //              Console.WriteLine ("Token=" + yyToken);
627 //              Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
628 //        }
629         ;
632 // Attributes 17.2
635 global_attributes
636         : attribute_sections
637           {
638                 if ($1 != null) {
639                         Attributes attrs = (Attributes)$1;
640                         if (global_attrs_enabled) {
641                                 CodeGen.Assembly.AddAttributes (attrs.Attrs, current_namespace);
642                         } else {
643                                 foreach (Attribute a in attrs.Attrs) {
644                                         Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
645                                 }
646                         }
647                 }
648                 $$ = $1;
649           }
650         ;
652 opt_attributes
653         : /* empty */ 
654           {
655                 global_attrs_enabled = false;
656                 $$ = null;
657       }
658         | attribute_sections
659           { 
660                 global_attrs_enabled = false;
661                 $$ = $1;
662           }
663     ;
666 attribute_sections
667         : attribute_section
668           {
669                 if (current_attr_target != String.Empty) {
670                         ArrayList sect = (ArrayList) $1;
672                         if (global_attrs_enabled) {
673                                 if (current_attr_target == "module") {
674                                         current_container.Module.Compiled.AddAttributes (sect);
675                                         $$ = null;
676                                 } else if (current_attr_target != null && current_attr_target.Length > 0) {
677                                         CodeGen.Assembly.AddAttributes (sect, current_namespace);
678                                         $$ = null;
679                                 } else {
680                                         $$ = new Attributes (sect);
681                                 }
682                                 if ($$ == null) {
683                                         if (RootContext.Documentation != null) {
684                                                 Lexer.check_incorrect_doc_comment ();
685                                                 Lexer.doc_state =
686                                                         XmlCommentState.Allowed;
687                                         }
688                                 }
689                         } else {
690                                 $$ = new Attributes (sect);
691                         }               
692                 }
693                 else
694                         $$ = null;
695                 current_attr_target = null;
696           }
697         | attribute_sections attribute_section
698           {
699                 if (current_attr_target != String.Empty) {
700                         Attributes attrs = $1 as Attributes;
701                         ArrayList sect = (ArrayList) $2;
703                         if (global_attrs_enabled) {
704                                 if (current_attr_target == "module") {
705                                         current_container.Module.Compiled.AddAttributes (sect);
706                                         $$ = null;
707                                 } else if (current_attr_target == "assembly") {
708                                         CodeGen.Assembly.AddAttributes (sect, current_namespace);
709                                         $$ = null;
710                                 } else {
711                                         if (attrs == null)
712                                                 attrs = new Attributes (sect);
713                                         else
714                                                 attrs.AddAttributes (sect);                     
715                                 }
716                         } else {
717                                 if (attrs == null)
718                                         attrs = new Attributes (sect);
719                                 else
720                                         attrs.AddAttributes (sect);
721                         }               
722                         $$ = attrs;
723                 }
724                 else
725                         $$ = null;
726                 current_attr_target = null;
727           }
728         ;
730 attribute_section
731         : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
732           {
733                 $$ = $3;
734           }
735         | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
736           {
737                 $$ = $2;
738           }
739         ;
741 attribute_target_specifier
742         : attribute_target COLON
743           {
744                 current_attr_target = (string)$1;
745                 $$ = $1;
746           }
747         ;
749 attribute_target
750         : IDENTIFIER
751           {
752                 LocatedToken lt = (LocatedToken) $1;
753                 $$ = CheckAttributeTarget (lt.Value, lt.Location);
754           }
755         | EVENT  { $$ = "event"; }
756         | RETURN { $$ = "return"; }
757         | error
758           {
759                 string name = GetTokenName (yyToken);
760                 $$ = CheckAttributeTarget (name, GetLocation ($1));
761           }
762         ;
764 attribute_list
765         : attribute
766           {
767                 ArrayList attrs = new ArrayList (4);
768                 attrs.Add ($1);
770                 $$ = attrs;
771                
772           }
773         | attribute_list COMMA attribute
774           {
775                 ArrayList attrs = (ArrayList) $1;
776                 attrs.Add ($3);
778                 $$ = attrs;
779           }
780         ;
782 attribute
783         : attribute_name
784           {
785                 ++lexer.parsing_block;
786           }
787           opt_attribute_arguments
788           {
789                 --lexer.parsing_block;
790                 MemberName mname = (MemberName) $1;
791                 if (mname.IsGeneric) {
792                         Report.Error (404, lexer.Location,
793                                       "'<' unexpected: attributes cannot be generic");
794                 }
796                 Arguments [] arguments = (Arguments []) $3;
797                 ATypeNameExpression expr = mname.GetTypeExpression ();
799                 if (current_attr_target == String.Empty)
800                         $$ = null;
801                 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
802                         // FIXME: supply "nameEscaped" parameter here.
803                         $$ = new GlobalAttribute (current_namespace, current_attr_target,
804                                                   expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
805                 else
806                         $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
807           }
808         ;
810 attribute_name
811         : namespace_or_type_name  { /* reserved attribute name or identifier: 17.4 */ }
812         ;
814 opt_attribute_arguments
815         : /* empty */   { $$ = null; }
816         | OPEN_PARENS attribute_arguments CLOSE_PARENS
817           {
818                 $$ = $2;
819           }
820         ;
823 attribute_arguments
824         : /* empty */           { $$ = null; } 
825         | positional_or_named_argument
826           {
827                 Arguments a = new Arguments (4);
828                 a.Add ((Argument) $1);
829                 $$ = new Arguments [] { a, null };
830           }
831         | named_attribute_argument
832           {
833                 Arguments a = new Arguments (4);
834                 a.Add ((Argument) $1);  
835                 $$ = new Arguments [] { null, a };
836           }
837     | attribute_arguments COMMA positional_or_named_argument
838           {
839                 Arguments[] o = (Arguments[]) $1;
840                 if (o [1] != null) {
841                         Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
842                         o [0] = new Arguments (4);
843                 }
844                 
845                 Arguments args = ((Arguments) o [0]);
846                 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
847                         Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
848                 
849                 args.Add ((Argument) $3);
850           }
851     | attribute_arguments COMMA named_attribute_argument
852           {
853                 Arguments[] o = (Arguments[]) $1;
854                 if (o [1] == null) {
855                         o [1] = new Arguments (4);
856                 }
858                 ((Arguments) o [1]).Add ((Argument) $3);
859           }
860     ;
862 positional_or_named_argument
863         : expression
864           {
865                 $$ = new Argument ((Expression) $1);
866           }
867         | named_argument
868         ;
870 named_attribute_argument
871         : IDENTIFIER ASSIGN expression
872           {
873                 $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3);      
874           }
875         ;
876         
877 named_argument
878         : IDENTIFIER COLON expression
879           {
880                 if (RootContext.Version <= LanguageVersion.V_3)
881                         Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
882                         
883                 $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3);
884           }       
885         ;       
887                   
888 class_body
889         :  OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
890         ;
892 opt_class_member_declarations
893         : /* empty */
894         | class_member_declarations
895         ;
897 class_member_declarations
898         : class_member_declaration
899         | class_member_declarations 
900           class_member_declaration
901         ;
903 class_member_declaration
904         : constant_declaration                  // done
905         | field_declaration                     // done
906         | method_declaration                    // done
907         | property_declaration                  // done
908         | event_declaration                     // done
909         | indexer_declaration                   // done
910         | operator_declaration                  // done
911         | constructor_declaration               // done
912         | destructor_declaration                // done
913         | type_declaration
914         | error
915           {
916                 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
917                         GetSymbolName (yyToken));
918                 $$ = null;
919                 lexer.parsing_generic_declaration = false;
920           }
921         ;
923 struct_declaration
924         : opt_attributes
925           opt_modifiers
926           opt_partial
927           STRUCT
928           {
929                 lexer.ConstraintsParsing = true;
930           }
931           type_declaration_name
932           { 
933                 MemberName name = MakeName ((MemberName) $6);
934                 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
935           }
936           opt_class_base
937           opt_type_parameter_constraints_clauses
938           {
939                 lexer.ConstraintsParsing = false;
941                 current_class.SetParameterInfo ((ArrayList) $9);
943                 if (RootContext.Documentation != null)
944                         current_container.DocComment = Lexer.consume_doc_comment ();
945           }
946           struct_body
947           {
948                 --lexer.parsing_declaration;      
949                 if (RootContext.Documentation != null)
950                         Lexer.doc_state = XmlCommentState.Allowed;
951           }
952           opt_semicolon
953           {
954                 $$ = pop_current_class ();
955           }
956         | opt_attributes opt_modifiers opt_partial STRUCT error {
957                 CheckIdentifierToken (yyToken, GetLocation ($5));
958           }
959         ;
961 struct_body
962         : OPEN_BRACE
963           {
964                 if (RootContext.Documentation != null)
965                         Lexer.doc_state = XmlCommentState.Allowed;
966           }
967           opt_struct_member_declarations CLOSE_BRACE
968         ;
970 opt_struct_member_declarations
971         : /* empty */
972         | struct_member_declarations
973         ;
975 struct_member_declarations
976         : struct_member_declaration
977         | struct_member_declarations struct_member_declaration
978         ;
980 struct_member_declaration
981         : constant_declaration
982         | field_declaration
983         | method_declaration
984         | property_declaration
985         | event_declaration
986         | indexer_declaration
987         | operator_declaration
988         | constructor_declaration
989         | type_declaration
991         /*
992          * This is only included so we can flag error 575: 
993          * destructors only allowed on class types
994          */
995         | destructor_declaration 
996         ;
998 constant_declaration
999         : opt_attributes 
1000           opt_modifiers
1001           CONST
1002           type
1003           constant_declarators
1004           SEMICOLON
1005           {
1006                 int modflags = (int) $2;
1007                 foreach (VariableDeclaration constant in (ArrayList) $5){
1008                         Location l = constant.Location;
1009                         if ((modflags & Modifiers.STATIC) != 0) {
1010                                 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + "." + (string) constant.identifier);
1011                                 continue;
1012                         }
1014                         Const c = new Const (
1015                                 current_class, (FullNamedExpression) $4, (string) constant.identifier, 
1016                                 (Expression) constant.expression_or_array_initializer, modflags, 
1017                                 (Attributes) $1, l);
1019                         if (RootContext.Documentation != null) {
1020                                 c.DocComment = Lexer.consume_doc_comment ();
1021                                 Lexer.doc_state = XmlCommentState.Allowed;
1022                         }
1023                         current_container.AddConstant (c);
1024                 }
1025           }
1026         ;
1028 constant_declarators
1029         : constant_declarator 
1030           {
1031                 ArrayList constants = new ArrayList (4);
1032                 if ($1 != null)
1033                         constants.Add ($1);
1034                 $$ = constants;
1035           }
1036         | constant_declarators COMMA constant_declarator
1037           {
1038                 if ($3 != null) {
1039                         ArrayList constants = (ArrayList) $1;
1040                         constants.Add ($3);
1041                 }
1042           }
1043         ;
1045 constant_declarator
1046         : IDENTIFIER ASSIGN
1047           {
1048                 ++lexer.parsing_block;
1049           }     
1050           constant_initializer
1051           {
1052                 --lexer.parsing_block;
1053                 $$ = new VariableDeclaration ((LocatedToken) $1, $4);
1054           }
1055         | IDENTIFIER
1056           {
1057                 // A const field requires a value to be provided
1058                 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
1059                 $$ = null;
1060           }
1061         ;
1062         
1063 constant_initializer
1064         : constant_expression
1065         | array_initializer
1066         ;
1068 field_declaration
1069         : opt_attributes
1070           opt_modifiers
1071           member_type
1072           variable_declarators
1073           SEMICOLON
1074           { 
1075                 FullNamedExpression type = (FullNamedExpression) $3;
1076                 if (type == TypeManager.system_void_expr)
1077                         Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1078                 
1079                 int mod = (int) $2;
1081                 current_array_type = null;
1083                 foreach (VariableMemberDeclaration var in (ArrayList) $4){
1084                         Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
1086                         field.Initializer = var.expression_or_array_initializer;
1088                         if (RootContext.Documentation != null) {
1089                                 field.DocComment = Lexer.consume_doc_comment ();
1090                                 Lexer.doc_state = XmlCommentState.Allowed;
1091                         }
1092                         current_container.AddField (field);
1093                         $$ = field; // FIXME: might be better if it points to the top item
1094                 }
1095           }
1096         | opt_attributes
1097           opt_modifiers
1098           FIXED
1099           member_type
1100           fixed_variable_declarators
1101           SEMICOLON
1102           { 
1103                         FullNamedExpression type = (FullNamedExpression) $4;
1104                         
1105                         int mod = (int) $2;
1107                         current_array_type = null;
1109                         foreach (VariableDeclaration var in (ArrayList) $5) {
1110                                 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1111                                         (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1113                                 if (RootContext.Documentation != null) {
1114                                         field.DocComment = Lexer.consume_doc_comment ();
1115                                         Lexer.doc_state = XmlCommentState.Allowed;
1116                                 }
1117                                 current_container.AddField (field);
1118                                 $$ = field; // FIXME: might be better if it points to the top item
1119                         }
1120           }
1121         | opt_attributes
1122           opt_modifiers
1123           FIXED
1124           member_type
1125           error
1126           {
1127                 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1128           }
1129         ;
1131 fixed_variable_declarators
1132         : fixed_variable_declarator
1133           {
1134                 ArrayList decl = new ArrayList (2);
1135                 decl.Add ($1);
1136                 $$ = decl;
1137           }
1138         | fixed_variable_declarators COMMA fixed_variable_declarator
1139           {
1140                 ArrayList decls = (ArrayList) $1;
1141                 decls.Add ($3);
1142                 $$ = $1;
1143           }
1144         ;
1146 fixed_variable_declarator
1147         : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1148           {
1149                 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1150           }
1151         | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1152           {
1153                 Report.Error (443, lexer.Location, "Value or constant expected");
1154                 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1155           }
1156         ;
1157         
1158         
1159 local_variable_declarators      
1160         : local_variable_declarator 
1161           {
1162                 ArrayList decl = new ArrayList (4);
1163                 if ($1 != null)
1164                         decl.Add ($1);
1165                 $$ = decl;
1166           }
1167         | local_variable_declarators COMMA local_variable_declarator
1168           {
1169                 ArrayList decls = (ArrayList) $1;
1170                 decls.Add ($3);
1171                 $$ = $1;
1172           }
1173         ;
1174         
1175 local_variable_declarator
1176         : IDENTIFIER ASSIGN local_variable_initializer
1177           {
1178                 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1179           }
1180         | IDENTIFIER
1181           {
1182                 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1183           }
1184         | IDENTIFIER variable_bad_array
1185           {
1186                 $$ = null;
1187           }
1188         ;
1190 local_variable_initializer
1191         : expression
1192         | array_initializer
1193         | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
1194           {
1195                 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1196           }
1197         | ARGLIST
1198           {
1199                 $$ = new ArglistAccess ((Location) $1);
1200           }
1201         | STACKALLOC simple_type
1202           {
1203                 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1204                 $$ = new StackAlloc ((Expression) $2, null, (Location) $1);             
1205           }
1206         ;
1208 variable_declarators
1209         : variable_declarator 
1210           {
1211                 ArrayList decl = new ArrayList (4);
1212                 if ($1 != null)
1213                         decl.Add ($1);
1214                 $$ = decl;
1215           }
1216         | variable_declarators COMMA variable_declarator
1217           {
1218                 ArrayList decls = (ArrayList) $1;
1219                 decls.Add ($3);
1220                 $$ = $1;
1221           }
1222         ;
1224 variable_declarator
1225         : member_declaration_name ASSIGN
1226           {
1227                 ++lexer.parsing_block;
1228                 lexer.parsing_generic_declaration = false;
1229           }
1230           variable_initializer
1231           {
1232                 --lexer.parsing_block;
1233                 $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
1234           }
1235         | member_declaration_name
1236           {
1237                 lexer.parsing_generic_declaration = false;
1238                 $$ = new VariableMemberDeclaration ((MemberName) $1, null);
1239           }
1240         | member_declaration_name variable_bad_array
1241           {
1242                 lexer.parsing_generic_declaration = false;        
1243                 $$ = null;
1244           }
1245         ;
1246         
1247 variable_bad_array
1248         : OPEN_BRACKET opt_expression CLOSE_BRACKET
1249           {
1250                 Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1251                         "To declare a fixed size buffer field, use the fixed keyword before the field type");
1252           }
1253         ;
1255 variable_initializer
1256         : expression
1257         | array_initializer
1258         ;
1260 method_declaration
1261         : method_header {
1262                 if (RootContext.Documentation != null)
1263                         Lexer.doc_state = XmlCommentState.NotAllowed;
1264           }
1265           method_body
1266           {
1267                 Method method = (Method) $1;
1268                 method.Block = (ToplevelBlock) $3;
1269                 current_container.AddMethod (method);
1270                 
1271                 if (current_container.Kind == Kind.Interface && method.Block != null) {
1272                         Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1273                 }
1275                 current_generic_method = null;
1276                 current_local_parameters = null;
1278                 if (RootContext.Documentation != null)
1279                         Lexer.doc_state = XmlCommentState.Allowed;
1280           }
1281         ;
1283 method_header
1284         : opt_attributes
1285           opt_modifiers
1286           member_type
1287           method_declaration_name OPEN_PARENS
1288           {
1289                 valid_param_mod = ParameterModifierType.All;
1290           }
1291           opt_formal_parameter_list CLOSE_PARENS
1292           {
1293                 lexer.ConstraintsParsing = true;
1294           }
1295           opt_type_parameter_constraints_clauses
1296           {
1297                 lexer.ConstraintsParsing = false;
1298                 valid_param_mod = 0;
1299                 MemberName name = (MemberName) $4;
1300                 current_local_parameters = (ParametersCompiled) $7;
1302                 if ($10 != null && name.TypeArguments == null)
1303                         Report.Error (80, lexer.Location,
1304                                       "Constraints are not allowed on non-generic declarations");
1306                 Method method;
1308                 GenericMethod generic = null;
1309                 if (name.TypeArguments != null) {
1310                         generic = new GenericMethod (current_namespace, current_class, name,
1311                                                      (FullNamedExpression) $3, current_local_parameters);
1313                         generic.SetParameterInfo ((ArrayList) $10);
1314                 }
1316                 method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
1317                                      name, current_local_parameters, (Attributes) $1);
1319                 current_generic_method = generic;
1321                 if (RootContext.Documentation != null)
1322                         method.DocComment = Lexer.consume_doc_comment ();
1324                 $$ = method;
1325           }
1326         | opt_attributes
1327           opt_modifiers
1328           PARTIAL
1329           VOID method_declaration_name
1330           OPEN_PARENS
1331           {
1332                 valid_param_mod = ParameterModifierType.All;
1333           }
1334           opt_formal_parameter_list CLOSE_PARENS 
1335           {
1336                 lexer.ConstraintsParsing = true;
1337           }
1338           opt_type_parameter_constraints_clauses
1339           {
1340                 lexer.ConstraintsParsing = false;
1341                 valid_param_mod = 0;
1343                 MemberName name = (MemberName) $5;
1344                 current_local_parameters = (ParametersCompiled) $8;
1346                 if ($10 != null && name.TypeArguments == null)
1347                         Report.Error (80, lexer.Location,
1348                                       "Constraints are not allowed on non-generic declarations");
1350                 Method method;
1351                 GenericMethod generic = null;
1352                 if (name.TypeArguments != null) {
1353                         generic = new GenericMethod (current_namespace, current_class, name,
1354                                                      TypeManager.system_void_expr, current_local_parameters);
1356                         generic.SetParameterInfo ((ArrayList) $11);
1357                 }
1359                 int modifiers = (int) $2;
1362                 const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
1363                         Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1365                 if ((modifiers & invalid_partial_mod) != 0) {
1366                         Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1367                         "any of abstract, extern, new, override, sealed, or virtual modifiers");
1368                         modifiers &= ~invalid_partial_mod;
1369                 }
1371                 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1372                         Report.Error (751, name.Location, "A partial method must be declared within a " +
1373                         "partial class or partial struct");
1374                 }
1375                 
1376                 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1377                 
1378                 method = new Method (current_class, generic, TypeManager.system_void_expr,
1379                                      modifiers, name, current_local_parameters, (Attributes) $1);
1381                 current_generic_method = generic;
1383                 if (RootContext.Documentation != null)
1384                         method.DocComment = Lexer.consume_doc_comment ();
1386                 $$ = method;
1387           }
1388         | opt_attributes
1389           opt_modifiers
1390           member_type
1391           modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1392           {
1393                 MemberName name = (MemberName) $5;
1394                 Report.Error (1585, name.Location, 
1395                         "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1397                 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1398                                             0, name, (ParametersCompiled) $7, (Attributes) $1);
1400                 current_local_parameters = (ParametersCompiled) $7;
1402                 if (RootContext.Documentation != null)
1403                         method.DocComment = Lexer.consume_doc_comment ();
1405                 $$ = method;
1406           }
1407         ;
1409 method_body
1410         : block
1411         | SEMICOLON             { $$ = null; }
1412         ;
1414 opt_formal_parameter_list
1415         : /* empty */                   { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1416         | formal_parameter_list
1417         ;
1418         
1419 formal_parameter_list
1420         : fixed_parameters
1421           { 
1422                 ArrayList pars_list = (ArrayList) $1;
1424                 Parameter [] pars = new Parameter [pars_list.Count];
1425                 pars_list.CopyTo (pars);
1427                 $$ = new ParametersCompiled (compiler, pars); 
1428           } 
1429         | fixed_parameters COMMA parameter_array
1430           {
1431                 ArrayList pars_list = (ArrayList) $1;
1432                 pars_list.Add ($3);
1434                 Parameter [] pars = new Parameter [pars_list.Count];
1435                 pars_list.CopyTo (pars);
1437                 $$ = new ParametersCompiled (compiler, pars); 
1438           }
1439         | fixed_parameters COMMA arglist_modifier
1440           {
1441                 ArrayList pars_list = (ArrayList) $1;
1442                 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1444                 Parameter [] pars = new Parameter [pars_list.Count];
1445                 pars_list.CopyTo (pars);
1447                 $$ = new ParametersCompiled (compiler, pars, true);
1448           }
1449         | parameter_array COMMA error
1450           {
1451                 if ($1 != null)
1452                         Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1454                 $$ = new ParametersCompiled (compiler, new Parameter[] { (Parameter) $1 } );                    
1455           }
1456         | fixed_parameters COMMA parameter_array COMMA error
1457           {
1458                 if ($3 != null)
1459                         Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1460                         
1461                 ArrayList pars_list = (ArrayList) $1;
1462                 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1464                 Parameter [] pars = new Parameter [pars_list.Count];
1465                 pars_list.CopyTo (pars);
1467                 $$ = new ParametersCompiled (compiler, pars, true);
1468           }
1469         | arglist_modifier COMMA error
1470           {
1471                 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1473                 $$ = new ParametersCompiled (compiler, new Parameter [] { new ArglistParameter ((Location) $1) }, true);
1474           }
1475         | fixed_parameters COMMA ARGLIST COMMA error 
1476           {
1477                 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1478                 
1479                 ArrayList pars_list = (ArrayList) $1;
1480                 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1482                 Parameter [] pars = new Parameter [pars_list.Count];
1483                 pars_list.CopyTo (pars);
1485                 $$ = new ParametersCompiled (compiler, pars, true);
1486           }
1487         | parameter_array 
1488           {
1489                 $$ = new ParametersCompiled (compiler, new Parameter[] { (Parameter) $1 } );
1490           }
1491         | arglist_modifier
1492           {
1493                 $$ = new ParametersCompiled (compiler, new Parameter [] { new ArglistParameter ((Location) $1) }, true);
1494           }
1495         ;
1497 fixed_parameters
1498         : fixed_parameter       
1499           {
1500                 ArrayList pars = new ArrayList (4);
1501                 Parameter p = (Parameter) $1;
1502                 pars.Add (p);
1503                 
1504                 default_parameter_used = p.HasDefaultValue;
1505                 $$ = pars;
1506           }
1507         | fixed_parameters COMMA fixed_parameter
1508           {
1509                 ArrayList pars = (ArrayList) $1;
1510                 Parameter p = (Parameter) $3;
1511                 if (p != null) {
1512                         if (p.HasExtensionMethodModifier)
1513                                 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1514                         else if (!p.HasDefaultValue && default_parameter_used)
1515                                 Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1517                         default_parameter_used |= p.HasDefaultValue;
1518                         pars.Add (p);
1519                 }
1520                 $$ = $1;
1521           }
1522         ;
1524 fixed_parameter
1525         : opt_attributes
1526           opt_parameter_modifier
1527           parameter_type
1528           IDENTIFIER
1529           {
1530                 LocatedToken lt = (LocatedToken) $4;
1531                 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1532           }
1533         | opt_attributes
1534           opt_parameter_modifier
1535           parameter_type
1536           IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1537           {
1538                 LocatedToken lt = (LocatedToken) $4;
1539                 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1540                 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1541           }
1542         | opt_attributes
1543           opt_parameter_modifier
1544           parameter_type
1545           error
1546           {
1547                 Location l = GetLocation ($4);
1548                 CheckIdentifierToken (yyToken, l);
1549                 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
1550           }
1551         | opt_attributes
1552           opt_parameter_modifier
1553           parameter_type
1554           IDENTIFIER
1555           ASSIGN
1556           constant_expression
1557           {
1558                 if (RootContext.Version <= LanguageVersion.V_3) {
1559                         Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1560                 }
1561                 
1562                 Parameter.Modifier mod = (Parameter.Modifier) $2;
1563                 if (mod != Parameter.Modifier.NONE) {
1564                         switch (mod) {
1565                         case Parameter.Modifier.REF:
1566                         case Parameter.Modifier.OUT:
1567                                 Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1568                                         Parameter.GetModifierSignature (mod));
1569                                 break;
1570                                 
1571                         case Parameter.Modifier.This:
1572                                 Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1573                                         Parameter.GetModifierSignature (mod));
1574                                 break;
1575                         default:
1576                                 throw new NotImplementedException (mod.ToString ());
1577                         }
1578                                 
1579                         mod = Parameter.Modifier.NONE;
1580                 }
1581                 
1582                 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1583                         Report.Error (1065, GetLocation ($6), "Optional parameter is not valid in this context");
1584                 
1585                 LocatedToken lt = (LocatedToken) $4;
1586                 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1587                 if ($6 != null)
1588                         ((Parameter) $$).DefaultValue = (Expression) $6;
1589           }
1590         ;
1592 opt_parameter_modifier
1593         : /* empty */           { $$ = Parameter.Modifier.NONE; }
1594         | parameter_modifiers
1595         ;
1597 parameter_modifiers
1598         : parameter_modifier
1599           {
1600                 $$ = $1;
1601           }
1602         | parameter_modifiers parameter_modifier
1603           {
1604                 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1605                 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1606                 if (((Parameter.Modifier)$1 & p2) == p2) {
1607                         Error_DuplicateParameterModifier (lexer.Location, p2);
1608                 } else {
1609                         switch (mod & ~Parameter.Modifier.This) {
1610                                 case Parameter.Modifier.REF:
1611                                         Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1612                                         break;
1613                                 case Parameter.Modifier.OUT:
1614                                         Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1615                                         break;
1616                                 default:
1617                                         Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1618                                         break;
1619                         }
1620                 }
1621                 $$ = mod;
1622           }
1623         ;
1625 parameter_modifier
1626         : REF
1627           {
1628                 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1629                         Error_ParameterModifierNotValid ("ref", (Location)$1);
1630                         
1631                 $$ = Parameter.Modifier.REF;
1632           }
1633         | OUT
1634           {
1635                 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1636                         Error_ParameterModifierNotValid ("out", (Location)$1);
1637           
1638                 $$ = Parameter.Modifier.OUT;
1639           }
1640         | THIS
1641           {
1642                 if ((valid_param_mod & ParameterModifierType.This) == 0)
1643                         Error_ParameterModifierNotValid ("this", (Location)$1);
1645                 if (RootContext.Version <= LanguageVersion.ISO_2)
1646                         Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1647                                 
1648                 $$ = Parameter.Modifier.This;
1649           }
1650         ;
1652 parameter_array
1653         : opt_attributes params_modifier type IDENTIFIER
1654           {
1655                 LocatedToken lt = (LocatedToken) $4;
1656                 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1657           }
1658         | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1659           {
1660                 Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1661                 
1662                 LocatedToken lt = (LocatedToken) $4;
1663                 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);            
1664           }
1665         | opt_attributes params_modifier type error {
1666                 CheckIdentifierToken (yyToken, GetLocation ($4));
1667                 $$ = null;
1668           }
1669         ;
1670         
1671 params_modifier
1672         : PARAMS
1673           {
1674                 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1675                         Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
1676           }
1677         | PARAMS parameter_modifier
1678           {
1679                 Parameter.Modifier mod = (Parameter.Modifier)$2;
1680                 if ((mod & Parameter.Modifier.This) != 0) {
1681                         Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
1682                 } else {
1683                         Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
1684                 }         
1685           }
1686         | PARAMS params_modifier
1687           {
1688                 Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
1689           }
1690         ;
1691         
1692 arglist_modifier
1693         : ARGLIST
1694           {
1695                 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1696                         Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
1697           }
1698         ;
1699         
1700 property_declaration
1701         : opt_attributes
1702           opt_modifiers
1703           member_type
1704           member_declaration_name
1705           {
1706                 if (RootContext.Documentation != null)
1707                         tmpComment = Lexer.consume_doc_comment ();
1708           }
1709           OPEN_BRACE 
1710           {
1711                 implicit_value_parameter_type = (FullNamedExpression) $3;
1712                 lexer.PropertyParsing = true;
1713           }
1714           accessor_declarations 
1715           {
1716                 lexer.PropertyParsing = false;
1717                 has_get = has_set = false;
1718           }
1719           CLOSE_BRACE
1720           { 
1721                 Property prop;
1722                 Accessors accessors = (Accessors) $8;
1723                 Accessor get_block = accessors != null ? accessors.get_or_add : null;
1724                 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
1725                 bool order = accessors != null ? accessors.declared_in_reverse : false;
1727                 MemberName name = (MemberName) $4;
1728                 FullNamedExpression ptype = (FullNamedExpression) $3;
1730                 prop = new Property (current_class, ptype, (int) $2,
1731                                      name, (Attributes) $1, get_block, set_block, order, current_block);
1733                 if (ptype == TypeManager.system_void_expr)
1734                         Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
1735                         
1736                 if (accessors == null)
1737                         Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
1739                 if (current_container.Kind == Kind.Interface) {
1740                         if (prop.Get.Block != null)
1741                                 Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
1743                         if (prop.Set.Block != null)
1744                                 Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
1745                 }
1747                 current_container.AddProperty (prop);
1748                 implicit_value_parameter_type = null;
1750                 if (RootContext.Documentation != null)
1751                         prop.DocComment = ConsumeStoredComment ();
1753           }
1754         ;
1756 accessor_declarations
1757         : get_accessor_declaration
1758          {
1759                 $$ = new Accessors ((Accessor) $1, null);
1760          }
1761         | get_accessor_declaration accessor_declarations
1762          { 
1763                 Accessors accessors = (Accessors) $2;
1764                 accessors.get_or_add = (Accessor) $1;
1765                 $$ = accessors;
1766          }
1767         | set_accessor_declaration
1768          {
1769                 $$ = new Accessors (null, (Accessor) $1);
1770          }
1771         | set_accessor_declaration accessor_declarations
1772          { 
1773                 Accessors accessors = (Accessors) $2;
1774                 accessors.set_or_remove = (Accessor) $1;
1775                 accessors.declared_in_reverse = true;
1776                 $$ = accessors;
1777          }
1778         | error
1779           {
1780                 if (yyToken == Token.CLOSE_BRACE) {
1781                         $$ = null;
1782                 } else {
1783                         if (yyToken == Token.SEMICOLON)
1784                                 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1785                         else
1786                                 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1788                         $$ = new Accessors (null, null);
1789                 }
1790           }
1791         ;
1793 get_accessor_declaration
1794         : opt_attributes opt_modifiers GET
1795           {
1796                 // If this is not the case, then current_local_parameters has already
1797                 // been set in indexer_declaration
1798                 if (parsing_indexer == false)
1799                         current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1800                 else 
1801                         current_local_parameters = indexer_parameters;
1802                 lexer.PropertyParsing = false;
1803           }
1804           accessor_body
1805           {
1806                 if (has_get) {
1807                         Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1808                         break;
1809                 }
1810                 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1811                 has_get = true;
1812                 current_local_parameters = null;
1813                 lexer.PropertyParsing = true;
1815                 if (RootContext.Documentation != null)
1816                         if (Lexer.doc_state == XmlCommentState.Error)
1817                                 Lexer.doc_state = XmlCommentState.NotAllowed;
1819                 $$ = accessor;
1820           }
1821         ;
1823 set_accessor_declaration
1824         : opt_attributes opt_modifiers SET 
1825           {
1826                 Parameter implicit_value_parameter = new Parameter (
1827                         implicit_value_parameter_type, "value", 
1828                         Parameter.Modifier.NONE, null, (Location) $3);
1830                 if (!parsing_indexer) {
1831                         current_local_parameters = new ParametersCompiled (compiler, new Parameter [] { implicit_value_parameter });
1832                 } else {
1833                         current_local_parameters = ParametersCompiled.MergeGenerated (compiler,
1834                                 indexer_parameters, true, implicit_value_parameter, null);
1835                 }
1836                 
1837                 lexer.PropertyParsing = false;
1838           }
1839           accessor_body
1840           {
1841                 if (has_set) {
1842                         Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1843                         break;
1844                 }
1845                 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1846                 has_set = true;
1847                 current_local_parameters = null;
1848                 lexer.PropertyParsing = true;
1850                 if (RootContext.Documentation != null
1851                         && Lexer.doc_state == XmlCommentState.Error)
1852                         Lexer.doc_state = XmlCommentState.NotAllowed;
1854                 $$ = accessor;
1855           }
1856         ;
1858 accessor_body
1859         : block 
1860         | SEMICOLON
1861           {
1862                 $$ = null;
1863           }
1864         | error
1865           {
1866                 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1867                 $$ = null;
1868           }
1869         ;
1871 interface_declaration
1872         : opt_attributes
1873           opt_modifiers
1874           opt_partial
1875           INTERFACE
1876           {
1877                 lexer.ConstraintsParsing = true;
1878           }
1879           type_declaration_name
1880           {
1881                 MemberName name = MakeName ((MemberName) $6);
1882                 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1883           }
1884           opt_class_base
1885           opt_type_parameter_constraints_clauses
1886           {
1887                 lexer.ConstraintsParsing = false;
1889                 current_class.SetParameterInfo ((ArrayList) $9);
1891                 if (RootContext.Documentation != null) {
1892                         current_container.DocComment = Lexer.consume_doc_comment ();
1893                         Lexer.doc_state = XmlCommentState.Allowed;
1894                 }
1895           }
1896           interface_body
1897           {
1898                 --lexer.parsing_declaration;      
1899                 if (RootContext.Documentation != null)
1900                         Lexer.doc_state = XmlCommentState.Allowed;
1901           }
1902           opt_semicolon 
1903           {
1904                 $$ = pop_current_class ();
1905           }
1906         | opt_attributes opt_modifiers opt_partial INTERFACE error {
1907                 CheckIdentifierToken (yyToken, GetLocation ($5));
1908           }
1909         ;
1911 interface_body
1912         : OPEN_BRACE
1913           opt_interface_member_declarations
1914           CLOSE_BRACE
1915         ;
1917 opt_interface_member_declarations
1918         : /* empty */
1919         | interface_member_declarations
1920         ;
1922 interface_member_declarations
1923         : interface_member_declaration
1924         | interface_member_declarations interface_member_declaration
1925         ;
1927 interface_member_declaration
1928         : constant_declaration
1929           {
1930                 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1931           }
1932         | field_declaration
1933           {
1934                 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1935           }
1936         | method_declaration
1937         | property_declaration
1938         | event_declaration
1939         | indexer_declaration
1940         | operator_declaration
1941           {
1942                 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1943           }
1944         | constructor_declaration
1945           {
1946                 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1947           }
1948         | type_declaration
1949           {
1950                 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1951           }
1952         ;
1954 operator_declaration
1955         : opt_attributes opt_modifiers operator_declarator 
1956           {
1957           }
1958           operator_body
1959           {
1960                 if ($3 == null)
1961                         break;
1963                 OperatorDeclaration decl = (OperatorDeclaration) $3;
1964                 Operator op = new Operator (
1965                         current_class, decl.optype, decl.ret_type, (int) $2, 
1966                         current_local_parameters,
1967                         (ToplevelBlock) $5, (Attributes) $1, decl.location);
1969                 if (RootContext.Documentation != null) {
1970                         op.DocComment = tmpComment;
1971                         Lexer.doc_state = XmlCommentState.Allowed;
1972                 }
1974                 // Note again, checking is done in semantic analysis
1975                 current_container.AddOperator (op);
1977                 current_local_parameters = null;
1978           }
1979         ;
1981 operator_body 
1982         : block
1983         | SEMICOLON { $$ = null; }
1984         ; 
1986 operator_type
1987         : type_expression_or_array
1988         | VOID
1989           {
1990                 Report.Error (590, lexer.Location, "User-defined operators cannot return void");
1991                 $$ = TypeManager.system_void_expr;              
1992           }
1993         ;
1995 operator_declarator
1996         : operator_type OPERATOR overloadable_operator OPEN_PARENS
1997           {
1998                 valid_param_mod = ParameterModifierType.DefaultValue;
1999           }
2000           opt_formal_parameter_list CLOSE_PARENS
2001           {
2002                 valid_param_mod = 0;
2004                 Location loc = (Location) $2;
2005                 Operator.OpType op = (Operator.OpType) $3;
2006                 current_local_parameters = (ParametersCompiled)$6;
2007                 
2008                 int p_count = current_local_parameters.Count;
2009                 if (p_count == 1) {
2010                         if (op == Operator.OpType.Addition)
2011                                 op = Operator.OpType.UnaryPlus;
2012                         else if (op == Operator.OpType.Subtraction)
2013                                 op = Operator.OpType.UnaryNegation;
2014                 }
2015                 
2016                 if (IsUnaryOperator (op)) {
2017                         if (p_count == 2) {
2018                                 Report.Error (1020, loc, "Overloadable binary operator expected");
2019                         } else if (p_count != 1) {
2020                                 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2021                                         Operator.GetName (op));
2022                         }
2023                 } else {
2024                         if (p_count > 2) {
2025                                 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2026                                         Operator.GetName (op));
2027                         } else if (p_count != 2) {
2028                                 Report.Error (1019, loc, "Overloadable unary operator expected");
2029                         }
2030                 }
2031                 
2032                 if (RootContext.Documentation != null) {
2033                         tmpComment = Lexer.consume_doc_comment ();
2034                         Lexer.doc_state = XmlCommentState.NotAllowed;
2035                 }
2037                 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2038           }
2039         | conversion_operator_declarator
2040         ;
2042 overloadable_operator
2043 // Unary operators:
2044         : BANG   { $$ = Operator.OpType.LogicalNot; }
2045         | TILDE  { $$ = Operator.OpType.OnesComplement; }  
2046         | OP_INC { $$ = Operator.OpType.Increment; }
2047         | OP_DEC { $$ = Operator.OpType.Decrement; }
2048         | TRUE   { $$ = Operator.OpType.True; }
2049         | FALSE  { $$ = Operator.OpType.False; }
2050 // Unary and binary:
2051         | PLUS { $$ = Operator.OpType.Addition; }
2052         | MINUS { $$ = Operator.OpType.Subtraction; }
2053 // Binary:
2054         | STAR { $$ = Operator.OpType.Multiply; }
2055         | DIV {  $$ = Operator.OpType.Division; }
2056         | PERCENT { $$ = Operator.OpType.Modulus; }
2057         | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2058         | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2059         | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2060         | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2061         | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2062         | OP_EQ { $$ = Operator.OpType.Equality; }
2063         | OP_NE { $$ = Operator.OpType.Inequality; }
2064         | OP_GT { $$ = Operator.OpType.GreaterThan; }
2065         | OP_LT { $$ = Operator.OpType.LessThan; }
2066         | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2067         | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2068         ;
2070 conversion_operator_declarator
2071         : IMPLICIT OPERATOR type OPEN_PARENS
2072           {
2073                 valid_param_mod = ParameterModifierType.DefaultValue;
2074           }
2075           opt_formal_parameter_list CLOSE_PARENS
2076           {
2077                 valid_param_mod = 0;
2079                 Location loc = (Location) $2;
2080                 current_local_parameters = (ParametersCompiled)$6;  
2081                   
2082                 if (RootContext.Documentation != null) {
2083                         tmpComment = Lexer.consume_doc_comment ();
2084                         Lexer.doc_state = XmlCommentState.NotAllowed;
2085                 }
2087                 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2088           }
2089         | EXPLICIT OPERATOR type OPEN_PARENS
2090           {
2091                 valid_param_mod = ParameterModifierType.DefaultValue;
2092           }
2093           opt_formal_parameter_list CLOSE_PARENS
2094           {
2095                 valid_param_mod = 0;
2096                 
2097                 Location loc = (Location) $2;
2098                 current_local_parameters = (ParametersCompiled)$6;  
2099                   
2100                 if (RootContext.Documentation != null) {
2101                         tmpComment = Lexer.consume_doc_comment ();
2102                         Lexer.doc_state = XmlCommentState.NotAllowed;
2103                 }
2105                 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2106           }
2107         | IMPLICIT error 
2108           {
2109                 Error_SyntaxError (yyToken);
2110                 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2111                 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2112           }
2113         | EXPLICIT error 
2114           {
2115                 Error_SyntaxError (yyToken);
2116                 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2117                 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2118           }
2119         ;
2121 constructor_declaration
2122         : constructor_declarator
2123           constructor_body
2124           { 
2125                 Constructor c = (Constructor) $1;
2126                 c.Block = (ToplevelBlock) $2;
2127                 
2128                 if (RootContext.Documentation != null)
2129                         c.DocComment = ConsumeStoredComment ();
2131                 current_container.AddConstructor (c);
2133                 current_local_parameters = null;
2134                 if (RootContext.Documentation != null)
2135                         Lexer.doc_state = XmlCommentState.Allowed;
2136           }
2137         ;
2139 constructor_declarator
2140         : opt_attributes
2141           opt_modifiers
2142           IDENTIFIER
2143           {
2144                 if (RootContext.Documentation != null) {
2145                         tmpComment = Lexer.consume_doc_comment ();
2146                         Lexer.doc_state = XmlCommentState.Allowed;
2147                 }
2148                 
2149                 valid_param_mod = ParameterModifierType.All;
2150           }
2151           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2152           {
2153                 valid_param_mod = 0;
2154                 current_local_parameters = (ParametersCompiled) $6;  
2155                 
2156                 //
2157                 // start block here, so possible anonymous methods inside
2158                 // constructor initializer can get correct parent block
2159                 //
2160                 start_block (lexer.Location);
2161           }
2162           opt_constructor_initializer
2163           {
2164                 LocatedToken lt = (LocatedToken) $3;
2165                 int mods = (int) $2;
2166                 ConstructorInitializer ci = (ConstructorInitializer) $9;
2168                 Constructor c = new Constructor (current_class, lt.Value, mods,
2169                         (Attributes) $1, current_local_parameters, ci, lt.Location);
2170                 
2171                 if (lt.Value != current_container.MemberName.Name) {
2172                         Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2173                 } else if ((mods & Modifiers.STATIC) != 0) {
2174                         if ((mods & Modifiers.Accessibility) != 0){
2175                                 Report.Error (515, c.Location,
2176                                         "`{0}': static constructor cannot have an access modifier",
2177                                         c.GetSignatureForError ());
2178                         }
2179                         if (ci != null) {
2180                                 Report.Error (514, c.Location,
2181                                         "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2182                                         c.GetSignatureForError ());
2183                         
2184                         }
2185                 }
2186                 
2187                 $$ = c;
2188           }
2189         ;
2191 constructor_body
2192         : block_prepared
2193         | SEMICOLON             { current_block = null; $$ = null; }
2194         ;
2196 opt_constructor_initializer
2197         : /* Empty */
2198         | constructor_initializer
2199         ;
2201 constructor_initializer
2202         : COLON BASE OPEN_PARENS
2203           {
2204                 ++lexer.parsing_block;
2205           }
2206           opt_argument_list CLOSE_PARENS
2207           {
2208                 --lexer.parsing_block;
2209                 $$ = new ConstructorBaseInitializer ((Arguments) $5, (Location) $2);
2210           }
2211         | COLON THIS OPEN_PARENS
2212           {
2213                 ++lexer.parsing_block;
2214           }
2215           opt_argument_list CLOSE_PARENS
2216           {
2217                 --lexer.parsing_block;
2218                 $$ = new ConstructorThisInitializer ((Arguments) $5, (Location) $2);
2219           }
2220         | COLON error {
2221                 Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
2222                 $$ = null;
2223           }
2224         ;
2226 destructor_declaration
2227         : opt_attributes opt_modifiers TILDE 
2228           {
2229                 if (RootContext.Documentation != null) {
2230                         tmpComment = Lexer.consume_doc_comment ();
2231                         Lexer.doc_state = XmlCommentState.NotAllowed;
2232                 }
2233                 
2234                 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2235           }
2236           IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2237           {
2238                 LocatedToken lt = (LocatedToken) $5;
2239                 if (lt.Value != current_container.MemberName.Name){
2240                         Report.Error (574, lt.Location, "Name of destructor must match name of class");
2241                 } else if (current_container.Kind != Kind.Class){
2242                         Report.Error (575, lt.Location, "Only class types can contain destructor");
2243                 } else {
2244                         Destructor d = new Destructor (current_class, (int) $2,
2245                                 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2246                         if (RootContext.Documentation != null)
2247                                 d.DocComment = ConsumeStoredComment ();
2248                   
2249                         d.Block = (ToplevelBlock) $8;
2250                         current_container.AddMethod (d);
2251                 }
2253                 current_local_parameters = null;
2254           }
2255         ;
2257 event_declaration
2258         : opt_attributes
2259           opt_modifiers
2260           EVENT type variable_declarators SEMICOLON
2261           {
2262                 current_array_type = null;
2263                 foreach (VariableMemberDeclaration var in (ArrayList) $5) {
2265                         EventField e = new EventField (
2266                                 current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
2267                                 
2268                         if (var.expression_or_array_initializer != null) {
2269                                 if (current_container.Kind == Kind.Interface) {
2270                                         Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
2271                                 }
2273                                 e.Initializer = var.expression_or_array_initializer;
2274                         }
2275                         
2276                         if (var.MemberName.Left != null) {
2277                                 Report.Error (71, e.Location,
2278                                         "`{0}': An explicit interface implementation of an event must use property syntax",
2279                                         e.GetSignatureForError ());
2280                         }
2282                         current_container.AddEvent (e);
2284                         if (RootContext.Documentation != null) {
2285                                 e.DocComment = Lexer.consume_doc_comment ();
2286                                 Lexer.doc_state = XmlCommentState.Allowed;
2287                         }
2288                 }
2289           }
2290         | opt_attributes
2291           opt_modifiers
2292           EVENT type member_declaration_name
2293           OPEN_BRACE
2294           {
2295                 implicit_value_parameter_type = (FullNamedExpression) $4;  
2296                 current_local_parameters = new ParametersCompiled (compiler,
2297                         new Parameter (implicit_value_parameter_type, "value", 
2298                         Parameter.Modifier.NONE, null, GetLocation ($3)));
2300                 lexer.EventParsing = true;
2301           }
2302           event_accessor_declarations
2303           {
2304                 lexer.EventParsing = false;  
2305           }
2306           CLOSE_BRACE
2307           {
2308                 MemberName name = (MemberName) $5;
2309                 
2310                 if (current_container.Kind == Kind.Interface) {
2311                         Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2312                         $8 = new Accessors (null, null);
2313                 } else if ($8 == null) {
2314                         Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2315                                 current_container.GetSignatureForError (), name.GetSignatureForError ());
2316                         $8 = new Accessors (null, null);
2317                 }
2318                 
2319                 Accessors accessors = (Accessors) $8;
2321                 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2322                         // CS0073 is already reported, so no CS0065 here.
2323                         $$ = null;
2324                 else {
2325                         Event e = new EventProperty (
2326                                 current_class, (FullNamedExpression) $4, (int) $2, name,
2327                                 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2328                         if (RootContext.Documentation != null) {
2329                                 e.DocComment = Lexer.consume_doc_comment ();
2330                                 Lexer.doc_state = XmlCommentState.Allowed;
2331                         }
2333                         current_container.AddEvent (e);
2334                         implicit_value_parameter_type = null;
2335                 }
2336                 current_local_parameters = null;
2337           }
2338         | opt_attributes opt_modifiers EVENT type member_declaration_name error
2339           {
2340                 MemberName mn = (MemberName) $5;
2341                 if (mn.Left != null)
2342                         Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2344                 if (RootContext.Documentation != null)
2345                         Lexer.doc_state = XmlCommentState.Allowed;
2347                 Error_SyntaxError (yyToken);
2348                 $$ = null;
2349           }
2350         ;
2352 event_accessor_declarations
2353         : add_accessor_declaration remove_accessor_declaration
2354           {
2355                 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2356           }
2357         | remove_accessor_declaration add_accessor_declaration
2358           {
2359                 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2360                 accessors.declared_in_reverse = true;
2361                 $$ = accessors;
2362           }     
2363         | add_accessor_declaration  { $$ = null; } 
2364         | remove_accessor_declaration { $$ = null; } 
2365         | error
2366           { 
2367                 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2368                 $$ = null;
2369           }
2370         | { $$ = null; }
2371         ;
2373 add_accessor_declaration
2374         : opt_attributes ADD
2375           {
2376                 lexer.EventParsing = false;
2377           }
2378           block
2379           {
2380                 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2381                 lexer.EventParsing = true;
2382                 $$ = accessor;
2383           }
2384         | opt_attributes ADD error {
2385                 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2386                 $$ = null;
2387           }
2388         | opt_attributes modifiers ADD {
2389                 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2390                 $$ = null;
2391           }
2392         ;
2394 remove_accessor_declaration
2395         : opt_attributes REMOVE
2396           {
2397                 lexer.EventParsing = false;
2398           }
2399           block
2400           {
2401                 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2402                 lexer.EventParsing = true;
2403           }
2404         | opt_attributes REMOVE error {
2405                 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2406                 $$ = null;
2407           }
2408         | opt_attributes modifiers REMOVE {
2409                 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2410                 $$ = null;
2411           }
2412         ;
2414 indexer_declaration
2415         : opt_attributes opt_modifiers
2416           member_type indexer_declaration_name OPEN_BRACKET
2417           {
2418                 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2419           }
2420           opt_formal_parameter_list CLOSE_BRACKET
2421           OPEN_BRACE
2422           {
2423                 valid_param_mod = 0;
2424                 implicit_value_parameter_type = (FullNamedExpression) $3;
2425                 indexer_parameters = (ParametersCompiled) $7;
2426                 
2427                 if (indexer_parameters.IsEmpty) {
2428                         Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
2429                 }
2431                 if (RootContext.Documentation != null) {
2432                         tmpComment = Lexer.consume_doc_comment ();
2433                         Lexer.doc_state = XmlCommentState.Allowed;
2434                 }
2436                 lexer.PropertyParsing = true;
2437                 parsing_indexer  = true;
2438                 
2439           }
2440           accessor_declarations 
2441           {
2442                   lexer.PropertyParsing = false;
2443                   has_get = has_set = false;
2444                   parsing_indexer  = false;
2445           }
2446           CLOSE_BRACE
2447           { 
2448                 Accessors accessors = (Accessors) $11;
2449                 Accessor get_block = accessors != null ? accessors.get_or_add : null;
2450                 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
2451                 bool order = accessors != null ? accessors.declared_in_reverse : false;
2453                 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
2454                         (MemberName)$4, (int) $2, (ParametersCompiled) $7, (Attributes) $1,
2455                         get_block, set_block, order);
2456                                        
2457                 if ($3 == TypeManager.system_void_expr)
2458                         Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
2459                         
2460                 if (accessors == null)
2461                         Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
2463                 if (current_container.Kind == Kind.Interface) {
2464                         if (indexer.Get.Block != null)
2465                                 Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
2467                         if (indexer.Set.Block != null)
2468                                 Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
2469                 }
2471                 if (RootContext.Documentation != null)
2472                         indexer.DocComment = ConsumeStoredComment ();
2474                 current_container.AddIndexer (indexer);
2475                 
2476                 current_local_parameters = null;
2477                 implicit_value_parameter_type = null;
2478                 indexer_parameters = null;
2479           }
2480         ;
2482 enum_declaration
2483         : opt_attributes
2484           opt_modifiers
2485           ENUM type_declaration_name
2486           opt_enum_base {
2487                 if (RootContext.Documentation != null)
2488                         enumTypeComment = Lexer.consume_doc_comment ();
2489           }
2490           enum_body
2491           opt_semicolon
2492           {
2493                 MemberName name = (MemberName) $4;
2494                 if (name.IsGeneric) {
2495                         Report.Error (1675, name.Location, "Enums cannot have type parameters");
2496                 }
2498                 name = MakeName (name);
2499                 Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
2500                                    name, (Attributes) $1);
2501                 
2502                 if (RootContext.Documentation != null)
2503                         e.DocComment = enumTypeComment;
2506                 EnumMember em = null;
2507                 foreach (VariableDeclaration ev in (ArrayList) $7) {
2508                         em = new EnumMember (
2509                                 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2510                                 ev.OptAttributes, ev.Location);
2512 //                      if (RootContext.Documentation != null)
2513                                 em.DocComment = ev.DocComment;
2515                         e.AddEnumMember (em);
2516                 }
2517                 if (RootContext.EvalMode)
2518                         undo.AddTypeContainer (current_container, e);
2520                 current_container.AddTypeContainer (e);
2522                 $$ = e;
2524           }
2525         ;
2527 opt_enum_base
2528         : /* empty */
2529           {
2530                 $$ = TypeManager.system_int32_expr;
2531           }
2532         | COLON type
2533          {
2534                 if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
2535                         $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
2536                         $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
2537                         $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr) {
2538                         Enum.Error_1008 (GetLocation ($2), Report);
2539                         $2 = TypeManager.system_int32_expr;
2540                 }
2541          
2542                 $$ = $2;
2543          }
2544         | COLON error
2545          {
2546                 Error_TypeExpected (lexer.Location);
2547                 $$ = TypeManager.system_int32_expr;
2548          }
2549         ;
2551 enum_body
2552         : OPEN_BRACE
2553           {
2554                 if (RootContext.Documentation != null)
2555                         Lexer.doc_state = XmlCommentState.Allowed;
2556           }
2557           opt_enum_member_declarations
2558           {
2559                 // here will be evaluated after CLOSE_BLACE is consumed.
2560                 if (RootContext.Documentation != null)
2561                         Lexer.doc_state = XmlCommentState.Allowed;
2562           }
2563           CLOSE_BRACE
2564           {
2565                 $$ = $3;
2566           }
2567         ;
2569 opt_enum_member_declarations
2570         : /* empty */                   { $$ = new ArrayList (0); }
2571         | enum_member_declarations opt_comma { $$ = $1; }
2572         ;
2574 enum_member_declarations
2575         : enum_member_declaration 
2576           {
2577                 ArrayList l = new ArrayList (4);
2579                 l.Add ($1);
2580                 $$ = l;
2581           }
2582         | enum_member_declarations COMMA enum_member_declaration
2583           {
2584                 ArrayList l = (ArrayList) $1;
2586                 l.Add ($3);
2588                 $$ = l;
2589           }
2590         ;
2592 enum_member_declaration
2593         : opt_attributes IDENTIFIER 
2594           {
2595                 VariableDeclaration vd = new VariableDeclaration (
2596                         (LocatedToken) $2, null, (Attributes) $1);
2598                 if (RootContext.Documentation != null) {
2599                         vd.DocComment = Lexer.consume_doc_comment ();
2600                         Lexer.doc_state = XmlCommentState.Allowed;
2601                 }
2603                 $$ = vd;
2604           }
2605         | opt_attributes IDENTIFIER
2606           {
2607                 ++lexer.parsing_block;
2608                 if (RootContext.Documentation != null) {
2609                         tmpComment = Lexer.consume_doc_comment ();
2610                         Lexer.doc_state = XmlCommentState.NotAllowed;
2611                 }
2612           }
2613           ASSIGN constant_expression
2614           { 
2615                 --lexer.parsing_block;    
2616                 VariableDeclaration vd = new VariableDeclaration (
2617                         (LocatedToken) $2, $5, (Attributes) $1);
2619                 if (RootContext.Documentation != null)
2620                         vd.DocComment = ConsumeStoredComment ();
2622                 $$ = vd;
2623           }
2624         ;
2626 delegate_declaration
2627         : opt_attributes
2628           opt_modifiers
2629           DELEGATE
2630           member_type type_declaration_name
2631           OPEN_PARENS
2632           {
2633                 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2634           }
2635           opt_formal_parameter_list CLOSE_PARENS
2636           {
2637                 valid_param_mod = 0;
2639                 MemberName name = MakeName ((MemberName) $5);
2640                 ParametersCompiled p = (ParametersCompiled) $8;
2642                 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2643                                              (int) $2, name, p, (Attributes) $1);
2645                 if (RootContext.Documentation != null) {
2646                         del.DocComment = Lexer.consume_doc_comment ();
2647                         Lexer.doc_state = XmlCommentState.Allowed;
2648                 }
2650                 current_container.AddDelegate (del);
2651                 current_delegate = del;
2652                 lexer.ConstraintsParsing = true;
2653           }
2654           opt_type_parameter_constraints_clauses
2655           {
2656                 lexer.ConstraintsParsing = false;
2657           }
2658           SEMICOLON
2659           {
2660                 current_delegate.SetParameterInfo ((ArrayList) $11);
2661                 $$ = current_delegate;
2663                 current_delegate = null;
2664           }
2665         ;
2667 opt_nullable
2668         : /* empty */
2669           {
2670                 $$ = null;
2671           }
2672         | INTERR_NULLABLE
2673           {
2674                 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
2675                         Report.FeatureIsNotSupported (lexer.Location, "nullable types");
2676                 else if (RootContext.Version < LanguageVersion.ISO_2)
2677                         Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
2678           
2679                 $$ = this;
2680           }
2681         ;
2683 namespace_or_type_name
2684         : member_name
2685         | qualified_alias_member IDENTIFIER opt_type_argument_list
2686           {
2687                 LocatedToken lt1 = (LocatedToken) $1;
2688                 LocatedToken lt2 = (LocatedToken) $2;
2689                 
2690                 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2691           }
2692         ;
2694 member_name
2695         : type_name
2696         | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2697           {
2698                 LocatedToken lt = (LocatedToken) $3;
2699                 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2700           }
2701         ;
2703 type_name
2704         : IDENTIFIER opt_type_argument_list
2705           {
2706                 LocatedToken lt = (LocatedToken) $1;
2707                 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);   
2708           }
2709         ;
2710         
2712 // Generics arguments  (any type, without attributes)
2714 opt_type_argument_list
2715         : /* empty */                { $$ = null; } 
2716         | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2717           {
2718                 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
2719                         Report.FeatureIsNotSupported (lexer.Location, "generics");
2720                 else if (RootContext.Version < LanguageVersion.ISO_2)
2721                         Report.FeatureIsNotAvailable (GetLocation ($1), "generics");      
2722           
2723                 $$ = $2;
2724           }
2725         | OP_GENERICS_LT error
2726           {
2727                 Error_TypeExpected (lexer.Location);
2728                 $$ = new TypeArguments ();
2729           }
2730         ;
2732 type_arguments
2733         : type
2734           {
2735                 TypeArguments type_args = new TypeArguments ();
2736                 type_args.Add ((FullNamedExpression) $1);
2737                 $$ = type_args;
2738           }
2739         | type_arguments COMMA type
2740           {
2741                 TypeArguments type_args = (TypeArguments) $1;
2742                 type_args.Add ((FullNamedExpression) $3);
2743                 $$ = type_args;
2744           }       
2745         ;
2748 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2750 type_declaration_name
2751         : IDENTIFIER
2752           {
2753                 lexer.parsing_generic_declaration = true;
2754           }
2755           opt_type_parameter_list
2756           {
2757                 lexer.parsing_generic_declaration = false;
2758                 LocatedToken lt = (LocatedToken) $1;
2759                 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);   
2760           }
2761         ;
2763 member_declaration_name
2764         : method_declaration_name
2765           {
2766                 MemberName mn = (MemberName)$1;
2767                 if (mn.TypeArguments != null)
2768                         syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2769                                 mn.GetSignatureForError ()));
2770           }
2771         ;
2773 method_declaration_name
2774         : type_declaration_name
2775         | explicit_interface IDENTIFIER opt_type_parameter_list
2776           {
2777                 lexer.parsing_generic_declaration = false;        
2778                 LocatedToken lt = (LocatedToken) $2;
2779                 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2780           }
2781         ;
2782         
2783 indexer_declaration_name
2784         : THIS
2785           {
2786                 lexer.parsing_generic_declaration = false;        
2787                 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2788           }
2789         | explicit_interface THIS
2790           {
2791                 lexer.parsing_generic_declaration = false;
2792                 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2793           }
2794         ;
2796 explicit_interface
2797         : IDENTIFIER opt_type_argument_list DOT
2798           {
2799                 LocatedToken lt = (LocatedToken) $1;
2800                 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2801           }
2802         | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2803           {
2804                 LocatedToken lt1 = (LocatedToken) $1;
2805                 LocatedToken lt2 = (LocatedToken) $2;
2806                 
2807                 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2808           }
2809         | explicit_interface IDENTIFIER opt_type_argument_list DOT
2810           {
2811                 LocatedToken lt = (LocatedToken) $2;
2812                 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2813           }
2814         ;
2815         
2816 opt_type_parameter_list
2817         : /* empty */                { $$ = null; } 
2818         | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2819           {
2820                 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
2821                         Report.FeatureIsNotSupported (lexer.Location, "generics");
2822                 else if (RootContext.Version < LanguageVersion.ISO_2)
2823                         Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2824           
2825                 $$ = $2;
2826           }
2827         ;
2829 type_parameters
2830         : type_parameter
2831           {
2832                 TypeArguments type_args = new TypeArguments ();
2833                 type_args.Add ((FullNamedExpression)$1);
2834                 $$ = type_args;
2835           }
2836         | type_parameters COMMA type_parameter
2837           {
2838                 TypeArguments type_args = (TypeArguments) $1;
2839                 type_args.Add ((FullNamedExpression)$3);
2840                 $$ = type_args;
2841           }       
2842         ;
2844 type_parameter
2845         : opt_attributes opt_type_parameter_variance IDENTIFIER
2846           {
2847                 LocatedToken lt = (LocatedToken)$3;
2848                 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2849           }
2850         | error
2851           {
2852                 if (GetTokenName (yyToken) == "type")
2853                         Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2854                 else
2855                         Error_SyntaxError (yyToken);
2856                         
2857                 $$ = new TypeParameterName ("", null, lexer.Location);
2858           }
2859         ;
2862 // All types where void is allowed
2864 type_and_void
2865         : type_expression_or_array
2866         | VOID
2867           {
2868                 $$ = TypeManager.system_void_expr;
2869           }
2870         ;
2871         
2872 member_type
2873         : type_and_void
2874           {
2875                 lexer.parsing_generic_declaration = true;
2876           }
2877         ;
2880 // A type which does not allow `void' to be used
2882 type
2883         : type_expression_or_array
2884         | VOID
2885           {
2886                 Expression.Error_VoidInvalidInTheContext (lexer.Location, Report);
2887                 $$ = TypeManager.system_void_expr;
2888           }     
2889         ;
2890         
2891 simple_type
2892         : type_expression
2893         | VOID
2894           {
2895                 Expression.Error_VoidInvalidInTheContext (lexer.Location, Report);
2896                 $$ = TypeManager.system_void_expr;
2897           }     
2898         ;
2899         
2900 parameter_type
2901         : type_expression_or_array
2902         | VOID
2903           {
2904                 Report.Error (1536, lexer.Location, "Invalid parameter type `void'");
2905                 $$ = TypeManager.system_void_expr;
2906           }     
2907         ;
2909 type_expression_or_array
2910         : type_expression
2911         | type_expression rank_specifiers
2912           {
2913                 string rank_specifiers = (string) $2;
2914                 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
2915           }
2916         ;
2917         
2918 type_expression
2919         : namespace_or_type_name opt_nullable
2920           {
2921                 MemberName name = (MemberName) $1;
2923                 if ($2 != null) {
2924                         $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
2925                 } else {
2926                         if (name.Left == null && name.Name == "var")
2927                                 $$ = current_array_type = new VarExpr (name.Location);
2928                         else
2929                                 $$ = name.GetTypeExpression ();
2930                 }
2931           }
2932         | builtin_types opt_nullable
2933           {
2934                 if ($2 != null)
2935                         $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2936           }
2937         | type_expression STAR
2938           {
2939                 //
2940                 // Note that here only unmanaged types are allowed but we
2941                 // can't perform checks during this phase - we do it during
2942                 // semantic analysis.
2943                 //
2944                 $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
2945           }
2946         | VOID STAR
2947           {
2948                 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2949           }     
2950         ;
2952 type_list
2953         : base_type_name
2954           {
2955                 ArrayList types = new ArrayList (2);
2956                 types.Add ($1);
2957                 $$ = types;
2958           }
2959         | type_list COMMA base_type_name
2960           {
2961                 ArrayList types = (ArrayList) $1;
2962                 types.Add ($3);
2963                 $$ = types;
2964           }
2965         ;
2967 base_type_name
2968         : type
2969           {
2970                 if ($1 is ComposedCast)
2971                         Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2972                 $$ = $1;
2973           }
2974         | error
2975           {
2976                 Error_TypeExpected (lexer.Location);
2977           }
2978         ;
2979         
2981  * replaces all the productions for isolating the various
2982  * simple types, but we need this to reuse it easily in variable_type
2983  */
2984 builtin_types
2985         : OBJECT        { $$ = TypeManager.system_object_expr; }
2986         | STRING        { $$ = TypeManager.system_string_expr; }
2987         | BOOL          { $$ = TypeManager.system_boolean_expr; }
2988         | DECIMAL       { $$ = TypeManager.system_decimal_expr; }
2989         | FLOAT         { $$ = TypeManager.system_single_expr; }
2990         | DOUBLE        { $$ = TypeManager.system_double_expr; }
2991         | integral_type
2992         ;
2994 integral_type
2995         : SBYTE         { $$ = TypeManager.system_sbyte_expr; }
2996         | BYTE          { $$ = TypeManager.system_byte_expr; }
2997         | SHORT         { $$ = TypeManager.system_int16_expr; }
2998         | USHORT        { $$ = TypeManager.system_uint16_expr; }
2999         | INT           { $$ = TypeManager.system_int32_expr; }
3000         | UINT          { $$ = TypeManager.system_uint32_expr; }
3001         | LONG          { $$ = TypeManager.system_int64_expr; }
3002         | ULONG         { $$ = TypeManager.system_uint64_expr; }
3003         | CHAR          { $$ = TypeManager.system_char_expr; }
3004         ;
3006 predefined_type
3007         : builtin_types
3008         | VOID
3009           {
3010                 $$ = TypeManager.system_void_expr;      
3011           }
3012         ;
3015 // Expressions, section 7.5
3019 primary_expression
3020         : primary_expression_no_array_creation
3021         | array_creation_expression
3022         ;
3024 primary_expression_no_array_creation
3025         : literal
3026         | IDENTIFIER opt_type_argument_list
3027           {
3028                 LocatedToken lt = (LocatedToken) $1;
3029                 $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);          
3030           }
3031         | IDENTIFIER GENERATE_COMPLETION {
3032                 LocatedToken lt = (LocatedToken) $1;
3033                $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3034           }
3035         | parenthesized_expression
3036         | default_value_expression
3037         | member_access
3038         | invocation_expression
3039         | element_access
3040         | this_access
3041         | base_access
3042         | post_increment_expression
3043         | post_decrement_expression
3044         | object_or_delegate_creation_expression
3045         | anonymous_type_expression
3046         | typeof_expression
3047         | sizeof_expression
3048         | checked_expression
3049         | unchecked_expression
3050         | pointer_member_access
3051         | anonymous_method_expression
3052         ;
3054 literal
3055         : boolean_literal
3056         | integer_literal
3057         | real_literal
3058         | LITERAL_CHARACTER     { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
3059         | LITERAL_STRING        { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); } 
3060         | NULL                  { $$ = new NullLiteral (lexer.Location); }
3061         ;
3063 real_literal
3064         : LITERAL_FLOAT         { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
3065         | LITERAL_DOUBLE        { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
3066         | LITERAL_DECIMAL       { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
3067         ;
3069 integer_literal
3070         : LITERAL_INTEGER       { 
3071                 object v = lexer.Value;
3073                 if (v is int){
3074                         $$ = new IntLiteral ((int) v, lexer.Location);
3075                 } else if (v is uint)
3076                         $$ = new UIntLiteral ((UInt32) v, lexer.Location);
3077                 else if (v is long)
3078                         $$ = new LongLiteral ((Int64) v, lexer.Location);
3079                 else if (v is ulong)
3080                         $$ = new ULongLiteral ((UInt64) v, lexer.Location);
3081                 else
3082                         Console.WriteLine ("OOPS.  Unexpected result from scanner");
3083           }
3084         ;
3086 boolean_literal
3087         : TRUE                  { $$ = new BoolLiteral (true, lexer.Location); }
3088         | FALSE                 { $$ = new BoolLiteral (false, lexer.Location); }
3089         ;
3093 // Here is the trick, tokenizer may think that parens is a special but
3094 // parser is interested in open parens only, so we merge them.
3095 // Consider: if (a)foo ();
3097 open_parens_any
3098         : OPEN_PARENS
3099         | OPEN_PARENS_CAST
3100         | OPEN_PARENS_LAMBDA
3101         ;
3103 parenthesized_expression
3104         : OPEN_PARENS expression CLOSE_PARENS
3105           {
3106                 $$ = new ParenthesizedExpression ((Expression) $2);
3107           }
3108         | OPEN_PARENS expression COMPLETE_COMPLETION
3109           {
3110                 $$ = new ParenthesizedExpression ((Expression) $2);
3111           }
3112         ;
3113         
3114 member_access
3115         : primary_expression DOT IDENTIFIER opt_type_argument_list
3116           {
3117                 LocatedToken lt = (LocatedToken) $3;
3118                 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3119           }
3120         | predefined_type DOT IDENTIFIER opt_type_argument_list
3121           {
3122                 LocatedToken lt = (LocatedToken) $3;
3123                 // TODO: Location is wrong as some predefined types doesn't hold a location
3124                 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3125           }
3126         | qualified_alias_member IDENTIFIER opt_type_argument_list
3127           {
3128                 LocatedToken lt1 = (LocatedToken) $1;
3129                 LocatedToken lt2 = (LocatedToken) $2;
3131                 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3132           }
3133         | primary_expression DOT GENERATE_COMPLETION {
3134                 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3135           }
3136         | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3137                 LocatedToken lt = (LocatedToken) $3;
3138                 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3139           }
3140         | predefined_type DOT GENERATE_COMPLETION
3141           {
3142                 // TODO: Location is wrong as some predefined types doesn't hold a location
3143                 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3144           }
3145         | predefined_type DOT IDENTIFIER GENERATE_COMPLETION {
3146                 LocatedToken lt = (LocatedToken) $3;
3147                 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3148           }
3149         ;
3151 invocation_expression
3152         : primary_expression open_parens_any opt_argument_list CLOSE_PARENS
3153           {
3154                 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3155           }
3156         ;
3158 opt_object_or_collection_initializer
3159         : /* empty */           { $$ = null; }
3160         | object_or_collection_initializer
3161         ;
3163 object_or_collection_initializer
3164         : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3165           {
3166                 if ($2 == null)
3167                         $$ = CollectionOrObjectInitializers.Empty;
3168                 else
3169                         $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3170           }
3171         | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3172           {
3173                 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3174           }
3175         ;
3177 opt_member_initializer_list
3178         : /* empty */           { $$ = null; }
3179         | member_initializer_list
3180         {
3181                 $$ = $1;
3182         }
3183         ;
3185 member_initializer_list
3186         : member_initializer 
3187           {
3188                 ArrayList a = new ArrayList ();
3189                 a.Add ($1);
3190                 $$ = a;
3191           }
3192         | member_initializer_list COMMA member_initializer
3193           {
3194                 ArrayList a = (ArrayList)$1;
3195                 a.Add ($3);
3196                 $$ = a;
3197           }
3198         ;
3200 member_initializer
3201         : IDENTIFIER ASSIGN initializer_value
3202           {
3203                 LocatedToken lt = $1 as LocatedToken;
3204                 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3205           }
3206         | GENERATE_COMPLETION 
3207           {
3208                 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3209           }
3210         | non_assignment_expression opt_COMPLETE_COMPLETION  {
3211                 CompletionSimpleName csn = $1 as CompletionSimpleName;
3212                 if (csn == null)
3213                         $$ = new CollectionElementInitializer ((Expression)$1);
3214                 else
3215                         $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3216           }
3217         | OPEN_BRACE expression_list CLOSE_BRACE
3218           {
3219                 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3220           }
3221         | OPEN_BRACE CLOSE_BRACE
3222           {
3223                 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3224           }       
3225         ;
3227 initializer_value
3228         : expression
3229         | object_or_collection_initializer
3230         ;
3232 opt_argument_list
3233         : /* empty */           { $$ = null; }
3234         | argument_list
3235         ;
3237 argument_list
3238         : argument_or_named_argument
3239           { 
3240                 Arguments list = new Arguments (4);
3241                 list.Add ((Argument) $1);
3242                 $$ = list;
3243           }
3244         | argument_list COMMA argument
3245           {
3246                 Arguments list = (Arguments) $1;
3247                 if (list [list.Count - 1] is NamedArgument)
3248                         Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3249                 
3250                 list.Add ((Argument) $3);
3251                 $$ = list;
3252           }
3253         | argument_list COMMA named_argument
3254           {
3255                 Arguments list = (Arguments) $1;
3256                 NamedArgument a = (NamedArgument) $3;
3257                 for (int i = 0; i < list.Count; ++i) {
3258                         NamedArgument na = list [i] as NamedArgument;
3259                         if (na != null && na.Name.Value == a.Name.Value)
3260                                 Report.Error (1740, na.Name.Location, "Named argument `{0}' specified multiple times",
3261                                         na.Name.Value);
3262                 }
3263                 
3264                 list.Add (a);
3265                 $$ = list;
3266           }
3267         | argument_list COMMA
3268           {
3269                 Report.Error (839, GetLocation ($2), "An argument is missing");
3270                 $$ = null;
3271           }
3272         | COMMA argument_or_named_argument
3273           {
3274                 Report.Error (839, GetLocation ($1), "An argument is missing");
3275                 $$ = null;
3276           }
3277         ;
3279 argument
3280         : expression
3281           {
3282                 $$ = new Argument ((Expression) $1);
3283           }
3284         | non_simple_argument
3285         ;
3287 argument_or_named_argument
3288         : argument
3289         | named_argument
3290         ;
3292 non_simple_argument
3293         : REF variable_reference 
3294           { 
3295                 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3296           }
3297         | OUT variable_reference 
3298           { 
3299                 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3300           }
3301         | ARGLIST open_parens_any argument_list CLOSE_PARENS
3302           {
3303                 $$ = new Argument (new Arglist ((Arguments) $3, (Location) $1));
3304           }
3305         | ARGLIST open_parens_any CLOSE_PARENS
3306           {
3307                 $$ = new Argument (new Arglist ((Location) $1));
3308           }       
3309         | ARGLIST
3310           {
3311                 $$ = new Argument (new ArglistAccess ((Location) $1));
3312           }
3313         ;
3315 variable_reference
3316         : expression
3317         ;
3319 element_access
3320         : primary_expression_no_array_creation OPEN_BRACKET expression_list_arguments CLOSE_BRACKET     
3321           {
3322                 $$ = new ElementAccess ((Expression) $1, (Arguments) $3);
3323           }
3324         | array_creation_expression OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
3325           {
3326                 // LAMESPEC: Not allowed according to specification
3327                 $$ = new ElementAccess ((Expression) $1, (Arguments) $3);
3328           }     
3329         | primary_expression_no_array_creation rank_specifiers
3330           {
3331                 // So the super-trick is that primary_expression
3332                 // can only be either a SimpleName or a MemberAccess. 
3333                 // The MemberAccess case arises when you have a fully qualified type-name like :
3334                 // Foo.Bar.Blah i;
3335                 // SimpleName is when you have
3336                 // Blah i;
3337                   
3338                 Expression expr = (Expression) $1;  
3339                 if (expr is ComposedCast){
3340                         $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
3341                 } else if (expr is ATypeNameExpression){
3342                         //
3343                         // So we extract the string corresponding to the SimpleName
3344                         // or MemberAccess
3345                         // 
3346                         $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
3347                 } else {
3348                         Error_ExpectingTypeName (expr);
3349                         $$ = TypeManager.system_object_expr;
3350                 }
3351                 
3352                 current_array_type = (FullNamedExpression)$$;
3353           }
3354         ;
3356 expression_list
3357         : expression
3358           {
3359                 ArrayList list = new ArrayList (4);
3360                 list.Add ($1);
3361                 $$ = list;
3362           }
3363         | expression_list COMMA expression
3364           {
3365                 ArrayList list = (ArrayList) $1;
3366                 list.Add ($3);
3367                 $$ = list;
3368           }
3369         ;
3370         
3371 expression_list_arguments
3372         : expression_list_argument
3373           {
3374                 Arguments args = new Arguments (4);
3375                 args.Add ((Argument) $1);
3376                 $$ = args;
3377           }
3378         | expression_list_arguments COMMA expression_list_argument
3379           {
3380                 Arguments args = (Arguments) $1;
3381                 args.Add ((Argument) $3);
3382                 $$ = args;        
3383           }
3384         ;
3385         
3386 expression_list_argument
3387         : expression
3388           {
3389                 $$ = new Argument ((Expression) $1);
3390           }
3391         | named_argument
3392         ;
3394 this_access
3395         : THIS
3396           {
3397                 $$ = new This (current_block, (Location) $1);
3398           }
3399         ;
3401 base_access
3402         : BASE DOT IDENTIFIER opt_type_argument_list
3403           {
3404                 LocatedToken lt = (LocatedToken) $3;
3405                 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3406           }
3407         | BASE OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
3408           {
3409                 $$ = new BaseIndexerAccess ((Arguments) $3, (Location) $1);
3410           }
3411         | BASE error
3412           {
3413                 Error_SyntaxError (yyToken);
3414                 $$ = new BaseAccess (null, GetLocation ($2));
3415           }
3416         ;
3418 post_increment_expression
3419         : primary_expression OP_INC
3420           {
3421                 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
3422           }
3423         ;
3425 post_decrement_expression
3426         : primary_expression OP_DEC
3427           {
3428                 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
3429           }
3430         ;
3432 object_or_delegate_creation_expression
3433         : new_expr_start open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3434           {
3435                 if ($5 != null) {
3436                         if (RootContext.Version <= LanguageVersion.ISO_2)
3437                                 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3438                                 
3439                         $$ = new NewInitialize ((Expression) $1, (Arguments) $3, (CollectionOrObjectInitializers) $5, GetLocation ($1));
3440                 }
3441                 else
3442                         $$ = new New ((Expression) $1, (Arguments) $3, GetLocation ($1));
3443           }
3444         | new_expr_start object_or_collection_initializer
3445           {
3446                 if (RootContext.Version <= LanguageVersion.ISO_2)
3447                         Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3448           
3449                 $$ = new NewInitialize ((Expression) $1, null, (CollectionOrObjectInitializers) $2, GetLocation ($1));
3450           }
3451         ;
3453 array_creation_expression
3454         : new_expr_start OPEN_BRACKET expression_list CLOSE_BRACKET 
3455           opt_rank_specifier    // shift/reduce on OPEN_BRACE
3456           opt_array_initializer
3457           {
3458                 $$ = new ArrayCreation ((FullNamedExpression) $1, (ArrayList) $3, (string) $5, (ArrayList) $6, GetLocation ($1));
3459           }
3460         | new_expr_start rank_specifiers opt_array_initializer
3461           {
3462                 if ($3 == null)
3463                         Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3465                 $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayList) $3, GetLocation ($1));
3466           }
3467         | NEW rank_specifiers array_initializer
3468           {
3469                 if (RootContext.Version <= LanguageVersion.ISO_2)
3470                         Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3471           
3472                 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, GetLocation ($1));
3473           }
3474         | new_expr_start error
3475           {
3476                 Report.Error (1526, GetLocation ($1), "A new expression requires () or [] after type");
3477                 $$ = new ArrayCreation ((FullNamedExpression) $1, "[]", null, GetLocation ($1));
3478           }
3479         ;
3481 new_expr_start
3482         : NEW
3483           {
3484                 ++lexer.parsing_type;
3485           }
3486           simple_type
3487           {
3488                 --lexer.parsing_type;
3489                 $$ = $3;
3490           }
3491         ;
3493 anonymous_type_expression
3494         : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3495           {
3496                 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
3497                         Report.FeatureIsNotSupported (lexer.Location, "anonymous types");
3498                 else if (RootContext.Version <= LanguageVersion.ISO_2)
3499                         Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3501                 $$ = new NewAnonymousType ((ArrayList) $3, current_container, GetLocation ($1));
3502           }
3503         ;
3505 anonymous_type_parameters_opt_comma
3506         : anonymous_type_parameters_opt
3507         | anonymous_type_parameters COMMA
3508         ;
3510 anonymous_type_parameters_opt
3511         : { $$ = null; }
3512         | anonymous_type_parameters
3513         ;
3515 anonymous_type_parameters
3516         : anonymous_type_parameter
3517           {
3518                 ArrayList a = new ArrayList (4);
3519                 a.Add ($1);
3520                 $$ = a;
3521           }
3522         | anonymous_type_parameters COMMA anonymous_type_parameter
3523           {
3524                 ArrayList a = (ArrayList) $1;
3525                 a.Add ($3);
3526                 $$ = a;
3527           }
3528         ;
3530 anonymous_type_parameter
3531         : IDENTIFIER ASSIGN variable_initializer
3532           {
3533                 LocatedToken lt = (LocatedToken)$1;
3534                 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3535           }
3536         | IDENTIFIER
3537           {
3538                 LocatedToken lt = (LocatedToken)$1;
3539                 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3540                         lt.Value, lt.Location);
3541           }
3542         | BASE DOT IDENTIFIER opt_type_argument_list
3543           {
3544                 LocatedToken lt = (LocatedToken) $3;
3545                 BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3546                 $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);            
3547           }       
3548         | member_access
3549           {
3550                 MemberAccess ma = (MemberAccess) $1;
3551                 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3552           }
3553         | error
3554           {
3555                 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3556                 "Anonymous type members must be a member assignment, simple name or member access expression");
3557           }
3558         ;
3560 opt_rank_specifier
3561         : /* empty */
3562           {
3563                 $$ = "";
3564           }
3565         | rank_specifiers
3566           {
3567                 $$ = $1;
3568           }
3569         ;
3571 opt_rank_specifier_or_nullable
3572         : opt_nullable
3573           {
3574                 if ($1 != null)
3575                         $$ = "?";
3576                 else
3577                         $$ = string.Empty;
3578           }
3579         | opt_nullable rank_specifiers
3580           {
3581                 if ($1 != null)
3582                         $$ = "?" + (string) $2;
3583                 else
3584                         $$ = $2;
3585           }
3586         ;
3588 rank_specifiers
3589         : rank_specifier
3590         | rank_specifier rank_specifiers
3591           {
3592                 $$ = (string) $2 + (string) $1;
3593           }
3594         ;
3596 rank_specifier
3597         : OPEN_BRACKET CLOSE_BRACKET
3598           {
3599                 $$ = "[]";
3600           }
3601         | OPEN_BRACKET dim_separators CLOSE_BRACKET
3602           {
3603                 $$ = "[" + (string) $2 + "]";
3604           }
3605         | OPEN_BRACKET error
3606           {
3607                 Error_SyntaxError (178, yyToken, "Invalid rank specifier");
3608                 $$ = "[]";
3609           }
3610         ;
3612 dim_separators
3613         : COMMA
3614           {
3615                 $$ = ",";
3616           }
3617         | dim_separators COMMA
3618           {
3619                 $$ = (string) $1 + ",";
3620           }
3621         ;
3623 opt_array_initializer
3624         : /* empty */
3625           {
3626                 $$ = null;
3627           }
3628         | array_initializer
3629           {
3630                 $$ = $1;
3631           }
3632         ;
3634 array_initializer
3635         : OPEN_BRACE CLOSE_BRACE
3636           {
3637                 ArrayList list = new ArrayList (4);
3638                 $$ = list;
3639           }
3640         | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3641           {
3642                 $$ = (ArrayList) $2;
3643           }
3644         ;
3646 variable_initializer_list
3647         : variable_initializer
3648           {
3649                 ArrayList list = new ArrayList (4);
3650                 list.Add ($1);
3651                 $$ = list;
3652           }
3653         | variable_initializer_list COMMA variable_initializer
3654           {
3655                 ArrayList list = (ArrayList) $1;
3656                 list.Add ($3);
3657                 $$ = list;
3658           }
3659         | error
3660           {
3661                 Error_SyntaxError (yyToken);
3662                 $$ = new ArrayList ();
3663           }
3664         ;
3666 typeof_expression
3667         : TYPEOF
3668       {
3669                 pushed_current_array_type = current_array_type;
3670                 lexer.TypeOfParsing = true;
3671           }
3672           open_parens_any typeof_type_expression CLOSE_PARENS
3673           {
3674                 lexer.TypeOfParsing = false;
3675                 Expression type = (Expression)$4;
3676                 if (type == TypeManager.system_void_expr)
3677                         $$ = new TypeOfVoid ((Location) $1);
3678                 else
3679                         $$ = new TypeOf (type, (Location) $1);
3680                 current_array_type = pushed_current_array_type;
3681           }
3682         ;
3683         
3684 typeof_type_expression
3685         : type_and_void
3686         | unbound_type_name
3687         | error
3688          {
3689                 Error_TypeExpected (lexer.Location);
3690                 $$ = null;
3691          }
3692         ;
3693         
3694 unbound_type_name
3695         : IDENTIFIER generic_dimension
3696           {  
3697                 LocatedToken lt = (LocatedToken) $1;
3699                 $$ = new SimpleName (MemberName.MakeName (lt.Value, (int)$2), lt.Location);
3700           }
3701         | qualified_alias_member IDENTIFIER generic_dimension
3702           {
3703                 LocatedToken lt1 = (LocatedToken) $1;
3704                 LocatedToken lt2 = (LocatedToken) $2;
3706                 $$ = new QualifiedAliasMember (lt1.Value, MemberName.MakeName (lt2.Value, (int) $3), lt1.Location);
3707           }
3708         | unbound_type_name DOT IDENTIFIER
3709           {
3710                 LocatedToken lt = (LocatedToken) $3;
3711                 
3712                 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);         
3713           }
3714         | unbound_type_name DOT IDENTIFIER generic_dimension
3715           {
3716                 LocatedToken lt = (LocatedToken) $3;
3717                 
3718                 $$ = new MemberAccess ((Expression) $1, MemberName.MakeName (lt.Value, (int) $4), lt.Location);         
3719           }
3720         | namespace_or_type_name DOT IDENTIFIER generic_dimension
3721           {
3722                 LocatedToken lt = (LocatedToken) $3;
3723                 MemberName name = (MemberName) $1;
3725                 $$ = new MemberAccess (name.GetTypeExpression (), MemberName.MakeName (lt.Value, (int) $4), lt.Location);               
3726           }
3727         ;
3729 generic_dimension
3730         : GENERIC_DIMENSION
3731           {
3732                 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
3733                         Report.FeatureIsNotSupported (lexer.Location, "generics");
3734                 else if (RootContext.Version < LanguageVersion.ISO_2)
3735                         Report.FeatureIsNotAvailable (lexer.Location, "generics");
3737                 $$ = $1;
3738           }
3739         ;
3740         
3741 qualified_alias_member
3742         : IDENTIFIER DOUBLE_COLON
3743           {
3744                 LocatedToken lt = (LocatedToken) $1;
3745                 if (RootContext.Version == LanguageVersion.ISO_1)
3746                         Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3748                 $$ = lt;                
3749           }
3750         ;
3752 sizeof_expression
3753         : SIZEOF open_parens_any type CLOSE_PARENS { 
3754                 $$ = new SizeOf ((Expression) $3, (Location) $1);
3755           }
3756         ;
3758 checked_expression
3759         : CHECKED open_parens_any expression CLOSE_PARENS
3760           {
3761                 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3762           }
3763         ;
3765 unchecked_expression
3766         : UNCHECKED open_parens_any expression CLOSE_PARENS
3767           {
3768                 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3769           }
3770         ;
3772 pointer_member_access 
3773         : primary_expression OP_PTR IDENTIFIER
3774           {
3775                 Expression deref;
3776                 LocatedToken lt = (LocatedToken) $3;
3778                 deref = new Indirection ((Expression) $1, lt.Location);
3779                 $$ = new MemberAccess (deref, lt.Value);
3780           }
3781         ;
3783 anonymous_method_expression
3784         : DELEGATE opt_anonymous_method_signature
3785           {
3786                 start_anonymous (false, (ParametersCompiled) $2, (Location) $1);
3787           }
3788           block
3789           {
3790                 $$ = end_anonymous ((ToplevelBlock) $4);
3791         }
3792         ;
3794 opt_anonymous_method_signature
3795         : 
3796           {
3797                 $$ = ParametersCompiled.Undefined;
3798           } 
3799         | anonymous_method_signature
3800         ;
3802 anonymous_method_signature
3803         : OPEN_PARENS
3804           {
3805                 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3806           }
3807           opt_formal_parameter_list CLOSE_PARENS
3808           {
3809                 valid_param_mod = 0;
3810                 $$ = $3;
3811           }
3812         ;
3814 default_value_expression
3815         : DEFAULT open_parens_any type CLOSE_PARENS
3816           {
3817                 if (RootContext.Version < LanguageVersion.ISO_2)
3818                         Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
3820                 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3821           }
3822         ;
3824 unary_expression
3825         : primary_expression
3826         | BANG prefixed_unary_expression
3827           {
3828                 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
3829           }
3830         | TILDE prefixed_unary_expression
3831           {
3832                 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
3833           }
3834         | cast_expression
3835         ;
3837 cast_expression
3838         : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3839           {
3840                 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3841           }
3842         | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
3843           {
3844                 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3845           }
3846         ;
3848         //
3849         // The idea to split this out is from Rhys' grammar
3850         // to solve the problem with casts.
3851         //
3852 prefixed_unary_expression
3853         : unary_expression
3854         | PLUS prefixed_unary_expression
3855           { 
3856                 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
3857           } 
3858         | MINUS prefixed_unary_expression 
3859           { 
3860                 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
3861           }
3862         | OP_INC prefixed_unary_expression 
3863           {
3864                 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
3865           }
3866         | OP_DEC prefixed_unary_expression 
3867           {
3868                 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
3869           }
3870         | STAR prefixed_unary_expression
3871           {
3872                 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3873           }
3874         | BITWISE_AND prefixed_unary_expression
3875           {
3876                 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
3877           }
3878         ;
3880 multiplicative_expression
3881         : prefixed_unary_expression
3882         | multiplicative_expression STAR prefixed_unary_expression
3883           {
3884                 $$ = new Binary (Binary.Operator.Multiply, 
3885                                  (Expression) $1, (Expression) $3);
3886           }
3887         | multiplicative_expression DIV prefixed_unary_expression
3888           {
3889                 $$ = new Binary (Binary.Operator.Division, 
3890                                  (Expression) $1, (Expression) $3);
3891           }
3892         | multiplicative_expression PERCENT prefixed_unary_expression 
3893           {
3894                 $$ = new Binary (Binary.Operator.Modulus, 
3895                                  (Expression) $1, (Expression) $3);
3896           }
3897         ;
3899 additive_expression
3900         : multiplicative_expression
3901         | additive_expression PLUS multiplicative_expression 
3902           {
3903                 $$ = new Binary (Binary.Operator.Addition, 
3904                                  (Expression) $1, (Expression) $3);
3905           }
3906         | additive_expression MINUS multiplicative_expression
3907           {
3908                 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3909           }
3910         | parenthesized_expression MINUS multiplicative_expression
3911           {
3912                 // Shift/Reduce conflict
3913                 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3914           }
3915         | additive_expression AS type
3916           {
3917                 $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
3918           }
3919         | additive_expression IS type
3920           {
3921                 $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
3922           }       
3923         ;
3925 shift_expression
3926         : additive_expression
3927         | shift_expression OP_SHIFT_LEFT additive_expression
3928           {
3929                 $$ = new Binary (Binary.Operator.LeftShift, 
3930                                  (Expression) $1, (Expression) $3);
3931           }
3932         | shift_expression OP_SHIFT_RIGHT additive_expression
3933           {
3934                 $$ = new Binary (Binary.Operator.RightShift, 
3935                                  (Expression) $1, (Expression) $3);
3936           }
3937         ; 
3939 relational_expression
3940         : shift_expression
3941         | relational_expression OP_LT shift_expression
3942           {
3943                 $$ = new Binary (Binary.Operator.LessThan, 
3944                                  (Expression) $1, (Expression) $3);
3945           }
3946         | relational_expression OP_GT shift_expression
3947           {
3948                 $$ = new Binary (Binary.Operator.GreaterThan, 
3949                                  (Expression) $1, (Expression) $3);
3950           }
3951         | relational_expression OP_LE shift_expression
3952           {
3953                 $$ = new Binary (Binary.Operator.LessThanOrEqual, 
3954                                  (Expression) $1, (Expression) $3);
3955           }
3956         | relational_expression OP_GE shift_expression
3957           {
3958                 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, 
3959                                  (Expression) $1, (Expression) $3);
3960           }
3961         ;
3963 equality_expression
3964         : relational_expression
3965         | equality_expression OP_EQ relational_expression
3966           {
3967                 $$ = new Binary (Binary.Operator.Equality, 
3968                                  (Expression) $1, (Expression) $3);
3969           }
3970         | equality_expression OP_NE relational_expression
3971           {
3972                 $$ = new Binary (Binary.Operator.Inequality, 
3973                                  (Expression) $1, (Expression) $3);
3974           }
3975         ; 
3977 and_expression
3978         : equality_expression
3979         | and_expression BITWISE_AND equality_expression
3980           {
3981                 $$ = new Binary (Binary.Operator.BitwiseAnd, 
3982                                  (Expression) $1, (Expression) $3);
3983           }
3984         ;
3986 exclusive_or_expression
3987         : and_expression
3988         | exclusive_or_expression CARRET and_expression
3989           {
3990                 $$ = new Binary (Binary.Operator.ExclusiveOr, 
3991                                  (Expression) $1, (Expression) $3);
3992           }
3993         ;
3995 inclusive_or_expression
3996         : exclusive_or_expression
3997         | inclusive_or_expression BITWISE_OR exclusive_or_expression
3998           {
3999                 $$ = new Binary (Binary.Operator.BitwiseOr, 
4000                                  (Expression) $1, (Expression) $3);
4001           }
4002         ;
4004 conditional_and_expression
4005         : inclusive_or_expression
4006         | conditional_and_expression OP_AND inclusive_or_expression
4007           {
4008                 $$ = new Binary (Binary.Operator.LogicalAnd, 
4009                                  (Expression) $1, (Expression) $3);
4010           }
4011         ;
4013 conditional_or_expression
4014         : conditional_and_expression
4015         | conditional_or_expression OP_OR conditional_and_expression
4016           {
4017                 $$ = new Binary (Binary.Operator.LogicalOr, 
4018                                  (Expression) $1, (Expression) $3);
4019           }
4020         ;
4021         
4022 null_coalescing_expression
4023         : conditional_or_expression
4024         | conditional_or_expression OP_COALESCING null_coalescing_expression
4025           {
4026                 if (RootContext.Version < LanguageVersion.ISO_2)
4027                         Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4028                         
4029                 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
4030           }
4031         ;
4033 conditional_expression
4034         : null_coalescing_expression
4035         | null_coalescing_expression INTERR expression COLON expression 
4036           {
4037                 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5);
4038           }
4039         ;
4041 assignment_expression
4042         : prefixed_unary_expression ASSIGN expression
4043           {
4044                 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4045           }
4046         | prefixed_unary_expression OP_MULT_ASSIGN expression
4047           {
4048                 $$ = new CompoundAssign (
4049                         Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4050           }
4051         | prefixed_unary_expression OP_DIV_ASSIGN expression
4052           {
4053                 $$ = new CompoundAssign (
4054                         Binary.Operator.Division, (Expression) $1, (Expression) $3);
4055           }
4056         | prefixed_unary_expression OP_MOD_ASSIGN expression
4057           {
4058                 $$ = new CompoundAssign (
4059                         Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4060           }
4061         | prefixed_unary_expression OP_ADD_ASSIGN expression
4062           {
4063                 $$ = new CompoundAssign (
4064                         Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4065           }
4066         | prefixed_unary_expression OP_SUB_ASSIGN expression
4067           {
4068                 $$ = new CompoundAssign (
4069                         Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4070           }
4071         | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4072           {
4073                 $$ = new CompoundAssign (
4074                         Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4075           }
4076         | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4077           {
4078                 $$ = new CompoundAssign (
4079                         Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4080           }
4081         | prefixed_unary_expression OP_AND_ASSIGN expression
4082           {
4083                 $$ = new CompoundAssign (
4084                         Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4085           }
4086         | prefixed_unary_expression OP_OR_ASSIGN expression
4087           {
4088                 $$ = new CompoundAssign (
4089                         Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4090           }
4091         | prefixed_unary_expression OP_XOR_ASSIGN expression
4092           {
4093                 $$ = new CompoundAssign (
4094                         Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4095           }
4096         ;
4098 lambda_parameter_list
4099         : lambda_parameter
4100           {
4101                 ArrayList pars = new ArrayList (4);
4102                 pars.Add ($1);
4104                 $$ = pars;
4105           }
4106         | lambda_parameter_list COMMA lambda_parameter
4107           {
4108                 ArrayList pars = (ArrayList) $1;
4109                 Parameter p = (Parameter)$3;
4110                 if (pars[0].GetType () != p.GetType ()) {
4111                         Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4112                 }
4113                 
4114                 pars.Add (p);
4115                 $$ = pars;
4116           }
4117         ;
4119 lambda_parameter
4120         : parameter_modifier parameter_type IDENTIFIER
4121           {
4122                 LocatedToken lt = (LocatedToken) $3;
4124                 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4125           }
4126         | parameter_type IDENTIFIER
4127           {
4128                 LocatedToken lt = (LocatedToken) $2;
4130                 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4131           }
4132         | IDENTIFIER
4133           {
4134                 LocatedToken lt = (LocatedToken) $1;
4135                 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4136           }
4137         ;
4139 opt_lambda_parameter_list
4140         : /* empty */                   { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4141         | lambda_parameter_list         { 
4142                 ArrayList pars_list = (ArrayList) $1;
4143                 $$ = new ParametersCompiled (compiler, (Parameter[])pars_list.ToArray (typeof (Parameter)));
4144           }
4145         ;
4147 lambda_expression_body
4148         : {
4149                 start_block (lexer.Location);
4150           }
4151           expression 
4152           {
4153                 Block b = end_block (lexer.Location);
4154                 b.AddStatement (new ContextualReturn ((Expression) $2));
4155                 $$ = b;
4156           } 
4157         | block { 
4158                 $$ = $1; 
4159           } 
4160         ;
4162 lambda_expression
4163         : IDENTIFIER ARROW 
4164           {
4165                 LocatedToken lt = (LocatedToken) $1;
4166                 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4167                 start_anonymous (true, new ParametersCompiled (compiler, p), GetLocation ($1));
4168           }
4169           lambda_expression_body
4170           {
4171                 $$ = end_anonymous ((ToplevelBlock) $4);
4172           }
4173         | OPEN_PARENS_LAMBDA
4174           {
4175                 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4176           }
4177           opt_lambda_parameter_list CLOSE_PARENS ARROW 
4178           {
4179                 valid_param_mod = 0;
4180                 start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
4181           }
4182           lambda_expression_body 
4183           {
4184                 $$ = end_anonymous ((ToplevelBlock) $7);
4185           }
4186         ;
4188 expression
4189         : assignment_expression 
4190         | non_assignment_expression 
4191         ;
4192         
4193 non_assignment_expression
4194         : conditional_expression
4195         | lambda_expression
4196         | query_expression
4197         ;
4199 constant_expression
4200         : expression
4201         ;
4203 boolean_expression
4204         : expression
4205           {
4206                 $$ = new BooleanExpression ((Expression) $1);
4207           }
4208         ;
4211 // 10 classes
4213 class_declaration
4214         : opt_attributes
4215           opt_modifiers
4216           opt_partial
4217           CLASS
4218           {
4219                 lexer.ConstraintsParsing = true;
4220           }
4221           type_declaration_name
4222           {
4223                 MemberName name = MakeName ((MemberName) $6);
4224                 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4225           }
4226           opt_class_base
4227           opt_type_parameter_constraints_clauses
4228           {
4229                 lexer.ConstraintsParsing = false;
4231                 current_class.SetParameterInfo ((ArrayList) $9);
4233                 if (RootContext.Documentation != null) {
4234                         current_container.DocComment = Lexer.consume_doc_comment ();
4235                         Lexer.doc_state = XmlCommentState.Allowed;
4236                 }
4237           }
4238           class_body
4239           {
4240                 --lexer.parsing_declaration;      
4241                 if (RootContext.Documentation != null)
4242                         Lexer.doc_state = XmlCommentState.Allowed;
4243           }
4244           opt_semicolon 
4245           {
4246                 $$ = pop_current_class ();
4247           }
4248         ;       
4250 opt_partial
4251         : /* empty */
4252           { $$ = null; }
4253         | PARTIAL
4254           { $$ = $1; } // location
4255         ;
4257 opt_modifiers
4258         : /* empty */           { $$ = (int) 0; }
4259         | modifiers
4260         ;
4262 modifiers
4263         : modifier
4264         | modifiers modifier
4265           { 
4266                 int m1 = (int) $1;
4267                 int m2 = (int) $2;
4269                 if ((m1 & m2) != 0) {
4270                         Location l = lexer.Location;
4271                         Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4272                 }
4273                 $$ = (int) (m1 | m2);
4274           }
4275         ;
4277 modifier
4278         : NEW
4279           {
4280                 $$ = Modifiers.NEW;
4281                 if (current_container == RootContext.ToplevelTypes)
4282                         Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
4283           }
4284         | PUBLIC                { $$ = Modifiers.PUBLIC; }
4285         | PROTECTED             { $$ = Modifiers.PROTECTED; }
4286         | INTERNAL              { $$ = Modifiers.INTERNAL; }
4287         | PRIVATE               { $$ = Modifiers.PRIVATE; }
4288         | ABSTRACT              { $$ = Modifiers.ABSTRACT; }
4289         | SEALED                { $$ = Modifiers.SEALED; }
4290         | STATIC                { $$ = Modifiers.STATIC; }
4291         | READONLY              { $$ = Modifiers.READONLY; }
4292         | VIRTUAL               { $$ = Modifiers.VIRTUAL; }
4293         | OVERRIDE              { $$ = Modifiers.OVERRIDE; }
4294         | EXTERN                { $$ = Modifiers.EXTERN; }
4295         | VOLATILE              { $$ = Modifiers.VOLATILE; }
4296         | UNSAFE                { $$ = Modifiers.UNSAFE; }
4297         ;
4299 opt_class_base
4300         : /* empty */
4301         | class_base
4302         ;
4304 class_base
4305         : COLON type_list       { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4306         ;
4308 opt_type_parameter_constraints_clauses
4309         : /* empty */           { $$ = null; }
4310         | type_parameter_constraints_clauses 
4311           { $$ = $1; }
4312         ;
4314 type_parameter_constraints_clauses
4315         : type_parameter_constraints_clause {
4316                 ArrayList constraints = new ArrayList (1);
4317                 constraints.Add ($1);
4318                 $$ = constraints;
4319           }
4320         | type_parameter_constraints_clauses type_parameter_constraints_clause {
4321                 ArrayList constraints = (ArrayList) $1;
4322                 Constraints new_constraint = (Constraints)$2;
4324                 foreach (Constraints c in constraints) {
4325                         if (new_constraint.TypeParameter == c.TypeParameter) {
4326                                 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4327                                         new_constraint.TypeParameter);
4328                         }
4329                 }
4331                 constraints.Add (new_constraint);
4332                 $$ = constraints;
4333           }
4334         ; 
4336 type_parameter_constraints_clause
4337         : WHERE IDENTIFIER COLON type_parameter_constraints {
4338                 LocatedToken lt = (LocatedToken) $2;
4339                 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4340           }
4341         ; 
4343 type_parameter_constraints
4344         : type_parameter_constraint {
4345                 ArrayList constraints = new ArrayList (1);
4346                 constraints.Add ($1);
4347                 $$ = constraints;
4348           }
4349         | type_parameter_constraints COMMA type_parameter_constraint {
4350                 ArrayList constraints = (ArrayList) $1;
4352                 constraints.Add ($3);
4353                 $$ = constraints;
4354           }
4355         ;
4357 type_parameter_constraint
4358         : type
4359         | NEW OPEN_PARENS CLOSE_PARENS {
4360                 $$ = SpecialConstraint.Constructor;
4361           }
4362         | CLASS {
4363                 $$ = SpecialConstraint.ReferenceType;
4364           }
4365         | STRUCT {
4366                 $$ = SpecialConstraint.ValueType;
4367           }
4368         ;
4370 opt_type_parameter_variance
4371         : /* empty */
4372           {
4373                 $$ = Variance.None;
4374           }
4375         | type_parameter_variance
4376           {
4377                 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
4378                         Report.FeatureIsNotSupported (lexer.Location, "generic type variance");
4379                 else if (RootContext.Version <= LanguageVersion.V_3)
4380                         Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
4382                 $$ = $1;
4383           }
4384         ;
4386 type_parameter_variance
4387         : OUT
4388           {
4389                 $$ = Variance.Covariant;
4390           }
4391         | IN
4392           {
4393                 $$ = Variance.Contravariant;
4394           }
4395         ;
4398 // Statements (8.2)
4402 // A block is "contained" on the following places:
4403 //      method_body
4404 //      property_declaration as part of the accessor body (get/set)
4405 //      operator_declaration
4406 //      constructor_declaration
4407 //      destructor_declaration
4408 //      event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4409 //      
4410 block
4411         : OPEN_BRACE  
4412           {
4413                 ++lexer.parsing_block;
4414                 start_block ((Location) $1);
4415           } 
4416           opt_statement_list block_end
4417           {
4418                 $$ = $4;
4419           }
4420         ;
4422 block_end 
4423         : CLOSE_BRACE 
4424           {
4425                 --lexer.parsing_block;
4426                 $$ = end_block ((Location) $1);
4427           }
4428         | COMPLETE_COMPLETION
4429           {
4430                 --lexer.parsing_block;
4431                 $$ = end_block (lexer.Location);
4432           }
4433         ;
4436 block_prepared
4437         : OPEN_BRACE
4438           {
4439                 ++lexer.parsing_block;
4440                 current_block.StartLocation = GetLocation ($1);
4441           }
4442           opt_statement_list CLOSE_BRACE 
4443           {
4444                 --lexer.parsing_block;
4445                 $$ = end_block ((Location) $4);
4446           }
4447         ;
4449 opt_statement_list
4450         : /* empty */
4451         | statement_list 
4452         ;
4454 statement_list
4455         : statement
4456         | statement_list statement
4457         ;
4459 statement
4460         : declaration_statement
4461           {
4462                 if ($1 != null && (Block) $1 != current_block){
4463                         current_block.AddStatement ((Statement) $1);
4464                         current_block = (Block) $1;
4465                 }
4466           }
4467         | valid_declaration_statement
4468           {
4469                 current_block.AddStatement ((Statement) $1);
4470           }
4471         | labeled_statement
4472         ;
4475 // The interactive_statement and its derivatives are only 
4476 // used to provide a special version of `expression_statement'
4477 // that has a side effect of assigning the expression to
4478 // $retval
4480 interactive_statement_list
4481         : interactive_statement
4482         | interactive_statement_list interactive_statement
4483         ;
4485 interactive_statement
4486         : declaration_statement
4487           {
4488                 if ($1 != null && (Block) $1 != current_block){
4489                         current_block.AddStatement ((Statement) $1);
4490                         current_block = (Block) $1;
4491                 }
4492           }
4493         | interactive_valid_declaration_statement
4494           {
4495                 current_block.AddStatement ((Statement) $1);
4496           }
4497         | labeled_statement
4498         ;
4500 valid_declaration_statement
4501         : block
4502         | empty_statement
4503         | expression_statement
4504         | selection_statement
4505         | iteration_statement
4506         | jump_statement                  
4507         | try_statement
4508         | checked_statement
4509         | unchecked_statement
4510         | lock_statement
4511         | using_statement
4512         | unsafe_statement
4513         | fixed_statement
4514         ;
4516 interactive_valid_declaration_statement
4517         : block
4518         | empty_statement
4519         | interactive_expression_statement
4520         | selection_statement
4521         | iteration_statement
4522         | jump_statement                  
4523         | try_statement
4524         | checked_statement
4525         | unchecked_statement
4526         | lock_statement
4527         | using_statement
4528         | unsafe_statement
4529         | fixed_statement
4530         ;
4532 embedded_statement
4533         : valid_declaration_statement
4534         | declaration_statement
4535           {
4536                   Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4537                   $$ = null;
4538           }
4539         | labeled_statement
4540           {
4541                   Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4542                   $$ = null;
4543           }
4544         ;
4546 empty_statement
4547         : SEMICOLON
4548           {
4549                   $$ = EmptyStatement.Value;
4550           }
4551         ;
4553 labeled_statement
4554         : IDENTIFIER COLON 
4555           {
4556                 LocatedToken lt = (LocatedToken) $1;
4557                 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4559                 if (current_block.AddLabel (labeled))
4560                         current_block.AddStatement (labeled);
4561           }
4562           statement
4563         ;
4565 declaration_statement
4566         : local_variable_declaration SEMICOLON
4567           {
4568                 current_array_type = null;
4569                 if ($1 != null){
4570                         DictionaryEntry de = (DictionaryEntry) $1;
4571                         Expression e = (Expression) de.Key;
4573                         $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4574                 }
4575           }
4577         | local_constant_declaration SEMICOLON
4578           {
4579                 current_array_type = null;
4580                 if ($1 != null){
4581                         DictionaryEntry de = (DictionaryEntry) $1;
4583                         $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4584                 }
4585           }
4586         ;
4588 /* 
4589  * The following is from Rhys' grammar:
4590  * > Types in local variable declarations must be recognized as 
4591  * > expressions to prevent reduce/reduce errors in the grammar.
4592  * > The expressions are converted into types during semantic analysis.
4593  */
4594 variable_type
4595         : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4596           { 
4597                 // FIXME: Do something smart here regarding the composition of the type.
4599                 // Ok, the above "primary_expression" is there to get rid of
4600                 // both reduce/reduce and shift/reduces in the grammar, it should
4601                 // really just be "type_name".  If you use type_name, a reduce/reduce
4602                 // creeps up.  If you use namespace_or_type_name (which is all we need
4603                 // really) two shift/reduces appear.
4604                 // 
4606                 // So the super-trick is that primary_expression
4607                 // can only be either a SimpleName or a MemberAccess. 
4608                 // The MemberAccess case arises when you have a fully qualified type-name like :
4609                 // Foo.Bar.Blah i;
4610                 // SimpleName is when you have
4611                 // Blah i;
4612                 
4613                 Expression expr = (Expression) $1;
4614                 string rank_or_nullable = (string) $2;
4615                 
4616                 if (expr is ComposedCast){
4617                         $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
4618                 } else if (expr is ATypeNameExpression){
4619                         //
4620                         // So we extract the string corresponding to the SimpleName
4621                         // or MemberAccess
4622                         //
4623                         if (rank_or_nullable.Length == 0) {
4624                                 SimpleName sn = expr as SimpleName;
4625                                 if (sn != null && sn.Name == "var")
4626                                         $$ = current_array_type = new VarExpr (sn.Location);
4627                                 else
4628                                         $$ = $1;
4629                         } else {
4630                                 $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
4631                         }
4632                 } else {
4633                         Error_ExpectingTypeName (expr);
4634                         $$ = TypeManager.system_object_expr;
4635                 }
4636           }
4637         | builtin_types opt_rank_specifier_or_nullable
4638           {
4639                 if ((string) $2 == "")
4640                         $$ = $1;
4641                 else
4642                         $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
4643           }
4644         | VOID opt_rank_specifier
4645           {
4646                 Expression.Error_VoidInvalidInTheContext (lexer.Location, Report);
4647                 $$ = TypeManager.system_void_expr;
4648           }
4649         ;
4651 local_variable_pointer_type
4652         : primary_expression_no_array_creation STAR
4653           {
4654                 ATypeNameExpression expr = $1 as ATypeNameExpression;
4656                 if (expr != null) {
4657                         $$ = new ComposedCast (expr, "*");
4658                 } else {
4659                         Error_ExpectingTypeName ((Expression)$1);
4660                         $$ = expr;
4661                 }
4662           }
4663         | builtin_types STAR
4664           {
4665                 $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
4666           }
4667         | VOID STAR
4668           {
4669                 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4670           }
4671         | local_variable_pointer_type STAR
4672           {
4673                 $$ = new ComposedCast ((FullNamedExpression) $1, "*");
4674           }
4675         ;
4677 local_variable_type
4678         : variable_type
4679         | local_variable_pointer_type opt_rank_specifier
4680           {
4681                 if ($1 != null){
4682                         string rank = (string)$2;
4684                         if (rank == "")
4685                                 $$ = $1;
4686                         else
4687                                 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
4688                 } else {
4689                         $$ = null;
4690                 }
4691           }
4692         ;
4694 local_variable_declaration
4695         : local_variable_type local_variable_declarators
4696           {
4697                 if ($1 != null) {
4698                         VarExpr ve = $1 as VarExpr;
4699                         if (ve != null)
4700                                 ve.VariableInitializer = (ArrayList)$2;
4701                                 
4702                         $$ = new DictionaryEntry ($1, $2);
4703                 } else
4704                         $$ = null;
4705           }
4706         ;
4708 local_constant_declaration
4709         : CONST variable_type constant_declarators
4710           {
4711                 if ($2 != null)
4712                         $$ = new DictionaryEntry ($2, $3);
4713                 else
4714                         $$ = null;
4715           }
4716         ;
4718 expression_statement
4719         : statement_expression SEMICOLON { $$ = $1; }
4720         | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4721         ;
4723 interactive_expression_statement
4724         : interactive_statement_expression SEMICOLON { $$ = $1; }
4725         | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4726         ;
4728         //
4729         // We have to do the wrapping here and not in the case above,
4730         // because statement_expression is used for example in for_statement
4731         //
4732 statement_expression
4733         : expression
4734           {
4735                 ExpressionStatement s = $1 as ExpressionStatement;
4736                 if (s == null) {
4737                         Expression.Error_InvalidExpressionStatement (Report, GetLocation ($1));
4738                         s = EmptyExpressionStatement.Instance;
4739                 }
4741                 $$ = new StatementExpression (s);
4742           }
4743         | error
4744           {
4745                 Error_SyntaxError (yyToken);
4746                 $$ = null;
4747           }
4748         ;
4750 interactive_statement_expression
4751         : expression
4752           {
4753                 Expression expr = (Expression) $1;
4754                 ExpressionStatement s;
4756                 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4757                 $$ = new StatementExpression (s);
4758           }
4759         | error
4760           {
4761                 Error_SyntaxError (yyToken);
4762                 $$ = null;
4763           }
4764         ;
4765         
4766 selection_statement
4767         : if_statement
4768         | switch_statement
4769         ; 
4771 if_statement
4772         : IF open_parens_any boolean_expression CLOSE_PARENS 
4773           embedded_statement
4774           { 
4775                 Location l = (Location) $1;
4777                 $$ = new If ((BooleanExpression) $3, (Statement) $5, l);
4779                 // FIXME: location for warning should be loc property of $5.
4780                 if ($5 == EmptyStatement.Value)
4781                         Report.Warning (642, 3, l, "Possible mistaken empty statement");
4783           }
4784         | IF open_parens_any boolean_expression CLOSE_PARENS
4785           embedded_statement ELSE embedded_statement
4786           {
4787                 Location l = (Location) $1;
4789                 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, l);
4791                 // FIXME: location for warning should be loc property of $5 and $7.
4792                 if ($5 == EmptyStatement.Value)
4793                         Report.Warning (642, 3, l, "Possible mistaken empty statement");
4794                 if ($7 == EmptyStatement.Value)
4795                         Report.Warning (642, 3, l, "Possible mistaken empty statement");
4796           }
4797         ;
4799 switch_statement
4800         : SWITCH open_parens_any
4801           { 
4802                 if (switch_stack == null)
4803                         switch_stack = new Stack (2);
4804                 switch_stack.Push (current_block);
4805           }
4806           expression CLOSE_PARENS 
4807           switch_block
4808           {
4809                 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4810                 current_block = (Block) switch_stack.Pop ();
4811           }
4812         ;
4814 switch_block
4815         : OPEN_BRACE
4816           opt_switch_sections
4817           CLOSE_BRACE
4818           {
4819                 $$ = $2;
4820           }
4821         ;
4823 opt_switch_sections
4824         : /* empty */           
4825           {
4826                 Report.Warning (1522, 1, lexer.Location, "Empty switch block"); 
4827                 $$ = new ArrayList ();
4828           }
4829         | switch_sections
4830         ;
4832 switch_sections
4833         : switch_section 
4834           {
4835                 ArrayList sections = new ArrayList (4);
4837                 sections.Add ($1);
4838                 $$ = sections;
4839           }
4840         | switch_sections switch_section
4841           {
4842                 ArrayList sections = (ArrayList) $1;
4844                 sections.Add ($2);
4845                 $$ = sections;
4846           }
4847         ;
4849 switch_section
4850         : switch_labels
4851           {
4852                 current_block = current_block.CreateSwitchBlock (lexer.Location);
4853           }
4854           statement_list 
4855           {
4856                 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4857           }
4858         ;
4860 switch_labels
4861         : switch_label 
4862           {
4863                 ArrayList labels = new ArrayList (4);
4865                 labels.Add ($1);
4866                 $$ = labels;
4867           }
4868         | switch_labels switch_label 
4869           {
4870                 ArrayList labels = (ArrayList) ($1);
4871                 labels.Add ($2);
4873                 $$ = labels;
4874           }
4875         ;
4877 switch_label
4878         : CASE constant_expression COLON
4879          {
4880                 $$ = new SwitchLabel ((Expression) $2, (Location) $1);
4881          }
4882         | DEFAULT_COLON
4883           {
4884                 $$ = new SwitchLabel (null, (Location) $1);
4885           }
4886         ;
4888 iteration_statement
4889         : while_statement
4890         | do_statement
4891         | for_statement
4892         | foreach_statement
4893         ;
4895 while_statement
4896         : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
4897           {
4898                 Location l = (Location) $1;
4899                 $$ = new While ((BooleanExpression) $3, (Statement) $5, l);
4900           }
4901         ;
4903 do_statement
4904         : DO embedded_statement 
4905           WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
4906           {
4907                 Location l = (Location) $1;
4909                 $$ = new Do ((Statement) $2, (BooleanExpression) $5, l);
4910           }
4911         ;
4913 for_statement
4914         : FOR open_parens_any opt_for_initializer SEMICOLON
4915           {
4916                 Location l = lexer.Location;
4917                 start_block (l);  
4918                 Block assign_block = current_block;
4920                 if ($3 is DictionaryEntry){
4921                         DictionaryEntry de = (DictionaryEntry) $3;
4922                         
4923                         Expression type = (Expression) de.Key;
4924                         ArrayList var_declarators = (ArrayList) de.Value;
4926                         foreach (VariableDeclaration decl in var_declarators){
4928                                 LocalInfo vi;
4930                                 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4931                                 if (vi == null)
4932                                         continue;
4934                                 Expression expr = decl.expression_or_array_initializer;
4935                                         
4936                                 LocalVariableReference var;
4937                                 var = new LocalVariableReference (assign_block, decl.identifier, l);
4939                                 if (expr != null) {
4940                                         Assign a = new SimpleAssign (var, expr, decl.Location);
4941                                         
4942                                         assign_block.AddStatement (new StatementExpression (a));
4943                                 }
4944                         }
4945                         
4946                         // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4947                         // This can be referred to as $5 below.
4948                         $$ = null;
4949                 } else {
4950                         $$ = $3;
4951                 }
4952           } 
4953           opt_for_condition SEMICOLON
4954           opt_for_iterator CLOSE_PARENS 
4955           embedded_statement
4956           {
4957                 Location l = (Location) $1;
4959                 For f = new For ((Statement) $5, (BooleanExpression) $6, (Statement) $8, (Statement) $10, l);
4961                 current_block.AddStatement (f);
4963                 $$ = end_block (lexer.Location);
4964           }
4965         ;
4967 opt_for_initializer
4968         : /* empty */           { $$ = EmptyStatement.Value; }
4969         | for_initializer       
4970         ;
4972 for_initializer
4973         : local_variable_declaration
4974         | statement_expression_list
4975         ;
4977 opt_for_condition
4978         : /* empty */           { $$ = null; }
4979         | boolean_expression
4980         ;
4982 opt_for_iterator
4983         : /* empty */           { $$ = EmptyStatement.Value; }
4984         | for_iterator
4985         ;
4987 for_iterator
4988         : statement_expression_list
4989         ;
4991 statement_expression_list
4992         : statement_expression  
4993           {
4994                 // CHANGE: was `null'
4995                 Statement s = (Statement) $1;
4996                 Block b = new Block (current_block, s.loc, lexer.Location);   
4998                 b.AddStatement (s);
4999                 $$ = b;
5000           }
5001         | statement_expression_list COMMA statement_expression
5002           {
5003                 Block b = (Block) $1;
5005                 b.AddStatement ((Statement) $3);
5006                 $$ = $1;
5007           }
5008         ;
5010 foreach_statement
5011         : FOREACH open_parens_any type IN expression CLOSE_PARENS
5012           {
5013                 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
5014                 $$ = null;
5015           }
5016         | FOREACH open_parens_any type IDENTIFIER IN
5017           expression CLOSE_PARENS 
5018           {
5019                 start_block (lexer.Location);
5020                 Block foreach_block = current_block;
5022                 LocatedToken lt = (LocatedToken) $4;
5023                 Location l = lt.Location;
5024                 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
5025                 if (vi != null) {
5026                         vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
5028                         // Get a writable reference to this read-only variable.
5029                         //
5030                         // Note that the $$ here refers to the value of _this_ code block,
5031                         // not the value of the LHS non-terminal.  This can be referred to as $8 below.
5032                         $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
5033                 } else {
5034                         $$ = null;
5035                 }
5036           } 
5037           embedded_statement 
5038           {
5039                 LocalVariableReference v = (LocalVariableReference) $8;
5040                 Location l = (Location) $1;
5042                 if (v != null) {
5043                         Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
5044                         current_block.AddStatement (f);
5045                 }
5047                 $$ = end_block (lexer.Location);
5048           }
5049         ;
5051 jump_statement
5052         : break_statement
5053         | continue_statement
5054         | goto_statement
5055         | return_statement
5056         | throw_statement
5057         | yield_statement
5058         ;
5060 break_statement
5061         : BREAK SEMICOLON
5062           {
5063                 $$ = new Break ((Location) $1);
5064           }
5065         ;
5067 continue_statement
5068         : CONTINUE SEMICOLON
5069           {
5070                 $$ = new Continue ((Location) $1);
5071           }
5072         ;
5074 goto_statement
5075         : GOTO IDENTIFIER SEMICOLON 
5076           {
5077                 LocatedToken lt = (LocatedToken) $2;
5078                 $$ = new Goto (lt.Value, lt.Location);
5079           }
5080         | GOTO CASE constant_expression SEMICOLON
5081           {
5082                 $$ = new GotoCase ((Expression) $3, (Location) $1);
5083           }
5084         | GOTO DEFAULT SEMICOLON 
5085           {
5086                 $$ = new GotoDefault ((Location) $1);
5087           }
5088         ; 
5090 return_statement
5091         : RETURN opt_expression SEMICOLON
5092           {
5093                 $$ = new Return ((Expression) $2, (Location) $1);
5094           }
5095         ;
5097 throw_statement
5098         : THROW opt_expression SEMICOLON
5099           {
5100                 $$ = new Throw ((Expression) $2, (Location) $1);
5101           }
5102         ;
5104 yield_statement 
5105         : IDENTIFIER RETURN expression SEMICOLON
5106           {
5107                 LocatedToken lt = (LocatedToken) $1;
5108                 string s = lt.Value;
5109                 if (s != "yield"){
5110                         Report.Error (1003, lt.Location, "; expected");
5111                         $$ = null;
5112                 }
5113                 if (RootContext.Version == LanguageVersion.ISO_1){
5114                         Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5115                         $$ = null;
5116                 }
5117                 current_block.Toplevel.IsIterator = true;
5118                 $$ = new Yield ((Expression) $3, lt.Location); 
5119           }
5120         | IDENTIFIER RETURN SEMICOLON
5121           {
5122                 Report.Error (1627, (Location) $2, "Expression expected after yield return");
5123                 $$ = null;
5124           }
5125         | IDENTIFIER BREAK SEMICOLON
5126           {
5127                 LocatedToken lt = (LocatedToken) $1;
5128                 string s = lt.Value;
5129                 if (s != "yield"){
5130                         Report.Error (1003, lt.Location, "; expected");
5131                         $$ = null;
5132                 }
5133                 if (RootContext.Version == LanguageVersion.ISO_1){
5134                         Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5135                         $$ = null;
5136                 }
5137                 
5138                 current_block.Toplevel.IsIterator = true;
5139                 $$ = new YieldBreak (lt.Location);
5140           }
5141         ;
5143 opt_expression
5144         : /* empty */
5145         | expression
5146         ;
5148 try_statement
5149         : TRY block catch_clauses
5150           {
5151                 $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
5152           }
5153         | TRY block FINALLY block
5154           {
5155                 $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
5156           }
5157         | TRY block catch_clauses FINALLY block
5158           {
5159                 $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
5160           }
5161         | TRY block error 
5162           {
5163                 Report.Error (1524, (Location) $1, "Expected catch or finally");
5164                 $$ = null;
5165           }
5166         ;
5168 catch_clauses
5169         : catch_clause 
5170           {
5171                 ArrayList l = new ArrayList (4);
5173                 l.Add ($1);
5174                 $$ = l;
5175           }
5176         | catch_clauses catch_clause
5177           {
5178                 ArrayList l = (ArrayList) $1;
5179                 
5180                 Catch c = (Catch) $2;
5181                 if (((Catch) l [0]).IsGeneral) {
5182                         Report.Error (1017, c.loc, "Try statement already has an empty catch block");
5183                 } else {
5184                         if (c.IsGeneral)
5185                                 l.Insert (0, $2);
5186                         else
5187                                 l.Add ($2);
5188                 }
5189                 
5190                 $$ = l;
5191           }
5192         ;
5194 opt_identifier
5195         : /* empty */   { $$ = null; }
5196         | IDENTIFIER
5197         ;
5199 catch_clause 
5200         : CATCH opt_catch_args 
5201           {
5202                 Expression type = null;
5203                 
5204                 if ($2 != null) {
5205                         DictionaryEntry cc = (DictionaryEntry) $2;
5206                         type = (Expression) cc.Key;
5207                         LocatedToken lt = (LocatedToken) cc.Value;
5209                         if (lt != null){
5210                                 ArrayList one = new ArrayList (4);
5212                                 one.Add (new VariableDeclaration (lt, null));
5214                                 start_block (lexer.Location);
5215                                 current_block = declare_local_variables (type, one, lt.Location);
5216                         }
5217                 }
5218           } block {
5219                 Expression type = null;
5220                 string id = null;
5221                 Block var_block = null;
5223                 if ($2 != null){
5224                         DictionaryEntry cc = (DictionaryEntry) $2;
5225                         type = (Expression) cc.Key;
5226                         LocatedToken lt = (LocatedToken) cc.Value;
5228                         if (lt != null){
5229                                 id = lt.Value;
5230                                 var_block = end_block (lexer.Location);
5231                         }
5232                 }
5234                 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5235           }
5236         ;
5238 opt_catch_args
5239         : /* empty */ { $$ = null; }
5240         | catch_args
5241         ;         
5243 catch_args 
5244         : open_parens_any type opt_identifier CLOSE_PARENS 
5245           {
5246                 $$ = new DictionaryEntry ($2, $3);
5247           }
5248         | open_parens_any CLOSE_PARENS 
5249           {
5250                 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5251                 $$ = null;
5252           }
5253         ;
5255 checked_statement
5256         : CHECKED block
5257           {
5258                 $$ = new Checked ((Block) $2);
5259           }
5260         ;
5262 unchecked_statement
5263         : UNCHECKED block
5264           {
5265                 $$ = new Unchecked ((Block) $2);
5266           }
5267         ;
5269 unsafe_statement
5270         : UNSAFE 
5271           {
5272                 RootContext.CheckUnsafeOption ((Location) $1, Report);
5273           } block {
5274                 $$ = new Unsafe ((Block) $3);
5275           }
5276         ;
5278 fixed_statement
5279         : FIXED open_parens_any 
5280           type_and_void fixed_pointer_declarators 
5281           CLOSE_PARENS
5282           {
5283                 ArrayList list = (ArrayList) $4;
5284                 Expression type = (Expression) $3;
5285                 Location l = (Location) $1;
5286                 int top = list.Count;
5288                 start_block (lexer.Location);
5290                 for (int i = 0; i < top; i++){
5291                         Pair p = (Pair) list [i];
5292                         LocalInfo v;
5294                         v = current_block.AddVariable (type, (string) p.First, l);
5295                         if (v == null)
5296                                 continue;
5298                         v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5299                         v.Pinned = true;
5300                         p.First = v;
5301                         list [i] = p;
5302                 }
5303           }
5304           embedded_statement 
5305           {
5306                 Location l = (Location) $1;
5308                 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5310                 current_block.AddStatement (f);
5312                 $$ = end_block (lexer.Location);
5313           }
5314         ;
5316 fixed_pointer_declarators
5317         : fixed_pointer_declarator      { 
5318                 ArrayList declarators = new ArrayList (4);
5319                 if ($1 != null)
5320                         declarators.Add ($1);
5321                 $$ = declarators;
5322           }
5323         | fixed_pointer_declarators COMMA fixed_pointer_declarator
5324           {
5325                 ArrayList declarators = (ArrayList) $1;
5326                 if ($3 != null)
5327                         declarators.Add ($3);
5328                 $$ = declarators;
5329           }
5330         ;
5332 fixed_pointer_declarator
5333         : IDENTIFIER ASSIGN expression
5334           {
5335                 LocatedToken lt = (LocatedToken) $1;
5336                 // FIXME: keep location
5337                 $$ = new Pair (lt.Value, $3);
5338           }
5339         | IDENTIFIER
5340           {
5341                 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5342                 $$ = null;
5343           }
5344         ;
5346 lock_statement
5347         : LOCK open_parens_any expression CLOSE_PARENS 
5348           {
5349                 //
5350           } 
5351           embedded_statement
5352           {
5353                 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5354           }
5355         ;
5357 using_statement
5358         : USING open_parens_any local_variable_declaration CLOSE_PARENS
5359           {
5360                 start_block (lexer.Location);
5361                 Block assign_block = current_block;
5363                 DictionaryEntry de = (DictionaryEntry) $3;
5364                 Location l = (Location) $1;
5366                 Expression type = (Expression) de.Key;
5367                 ArrayList var_declarators = (ArrayList) de.Value;
5369                 Stack vars = new Stack ();
5371                 foreach (VariableDeclaration decl in var_declarators) {
5372                         LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5373                         if (vi == null)
5374                                 continue;
5375                         vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5377                         Expression expr = decl.expression_or_array_initializer;
5378                         if (expr == null) {
5379                                 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5380                                 continue;
5381                         }
5382                         LocalVariableReference var;
5384                         // Get a writable reference to this read-only variable.
5385                         var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5387                         // This is so that it is not a warning on using variables
5388                         vi.Used = true;
5390                         vars.Push (new DictionaryEntry (var, expr));
5392                         // Assign a = new SimpleAssign (var, expr, decl.Location);
5393                         // assign_block.AddStatement (new StatementExpression (a));
5394                 }
5396                 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5397                 // It can be referred to as $5 below.
5398                 $$ = vars;
5399           }
5400           embedded_statement
5401           {
5402                 Statement stmt = (Statement) $6;
5403                 Stack vars = (Stack) $5;
5404                 Location l = (Location) $1;
5406                 while (vars.Count > 0) {
5407                           DictionaryEntry de = (DictionaryEntry) vars.Pop ();
5408                           stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
5409                 }
5410                 current_block.AddStatement (stmt);
5411                 $$ = end_block (lexer.Location);
5412           }
5413         | USING open_parens_any expression CLOSE_PARENS
5414           {
5415                 start_block (lexer.Location);
5416           }
5417           embedded_statement
5418           {
5419                 current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
5420                 $$ = end_block (lexer.Location);
5421           }
5422         ; 
5425 // LINQ
5427 query_expression
5428         : first_from_clause query_body
5429           {
5430                 lexer.query_parsing = false;
5431                         
5432                 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5433                         
5434                 from.Tail.Next = (Linq.AQueryClause)$2;
5435                 $$ = from;
5436                 
5437                 current_block.SetEndLocation (lexer.Location);
5438                 current_block = current_block.Parent;
5439           }
5440         | nested_from_clause query_body
5441           {
5442                 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5443                         
5444                 from.Tail.Next = (Linq.AQueryClause)$2;
5445                 $$ = from;
5446                 
5447                 current_block.SetEndLocation (lexer.Location);
5448                 current_block = current_block.Parent;
5449           }     
5450         ;
5451         
5452 first_from_clause
5453         : FROM_FIRST IDENTIFIER IN expression
5454           {
5455                 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5456                 current_block = new Linq.QueryBlock (compiler, current_block, (LocatedToken) $2, GetLocation ($1));
5457           }
5458         | FROM_FIRST type IDENTIFIER IN expression
5459           {
5460                 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5461                 current_block = new Linq.QueryBlock (compiler, current_block, (LocatedToken) $3, GetLocation ($1));
5462           }
5463         ;
5465 nested_from_clause
5466         : FROM IDENTIFIER IN expression
5467           {
5468                 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5469                 current_block = new Linq.QueryBlock (compiler, current_block, (LocatedToken) $2, GetLocation ($1));
5470           }
5471         | FROM type IDENTIFIER IN expression
5472           {
5473                 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5474                 current_block = new Linq.QueryBlock (compiler, current_block, (LocatedToken) $3, GetLocation ($1));
5475           }
5476         ;
5477         
5478 from_clause
5479         : FROM IDENTIFIER IN
5480           {
5481                 current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
5482           }
5483           expression
5484           {
5485                 LocatedToken lt = (LocatedToken) $2;
5486                 $$ = new Linq.SelectMany (current_block.Toplevel, lt, (Expression)$5);
5487                 
5488                 current_block.SetEndLocation (lexer.Location);
5489                 current_block = current_block.Parent;
5490                 
5491                 ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, lt);
5492           }       
5493         | FROM type IDENTIFIER IN
5494           {
5495                 current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
5496           }
5497           expression
5498           {
5499                 LocatedToken lt = (LocatedToken) $3;
5500                 FullNamedExpression type = (FullNamedExpression)$2;
5501                 
5502                 $$ = new Linq.SelectMany (current_block.Toplevel, lt, new Linq.Cast (type, (FullNamedExpression)$6));
5503                 
5504                 current_block.SetEndLocation (lexer.Location);
5505                 current_block = current_block.Parent;
5506                 
5507                 ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, lt);
5508           }
5509         ;       
5511 query_body
5512         : opt_query_body_clauses select_or_group_clause opt_query_continuation
5513           {
5514                 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5515                 
5516                 if ($3 != null)
5517                         head.Next = (Linq.AQueryClause)$3;
5518                                 
5519                 if ($1 != null) {
5520                         Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5521                         clause.Tail.Next = head;
5522                         head = clause;
5523                 }
5524                 
5525                 $$ = head;
5526           }
5527         ;
5528         
5529 select_or_group_clause
5530         : SELECT
5531           {
5532                 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5533           }
5534           expression
5535           {
5536                 $$ = new Linq.Select (current_block.Toplevel, (Expression)$3, GetLocation ($1));
5538                 current_block.SetEndLocation (lexer.Location);
5539                 current_block = current_block.Parent;
5540           }
5541         | GROUP
5542           {
5543                 if (linq_clause_blocks == null)
5544                         linq_clause_blocks = new Stack ();
5545                         
5546                 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5547                 linq_clause_blocks.Push (current_block);
5548           }
5549           expression
5550           {
5551                 current_block.SetEndLocation (lexer.Location);
5552                 current_block = current_block.Parent;
5553           
5554                 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5555           }
5556           BY expression
5557           {
5558                 $$ = new Linq.GroupBy (current_block.Toplevel, (Expression)$3, (ToplevelBlock) linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5559                 
5560                 current_block.SetEndLocation (lexer.Location);
5561                 current_block = current_block.Parent;
5562           }
5563         ;
5564         
5565 opt_query_body_clauses
5566         : /* empty */
5567         | query_body_clauses
5568         ;
5569         
5570 query_body_clauses
5571         : query_body_clause
5572         | query_body_clauses query_body_clause
5573           {
5574                 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5575                 $$ = $1;
5576           }
5577         ;
5578         
5579 query_body_clause
5580         : from_clause
5581         | let_clause
5582         | where_clause
5583         | join_clause
5584         | orderby_clause
5585         ;
5586         
5587 let_clause
5588         : LET IDENTIFIER ASSIGN 
5589           {
5590                 current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
5591           }
5592           expression
5593           {
5594                 LocatedToken lt = (LocatedToken) $2;
5595                 $$ = new Linq.Let (current_block.Toplevel, current_container, lt, (Expression)$5);
5596                 
5597                 current_block.SetEndLocation (lexer.Location);
5598                 current_block = current_block.Parent;
5599                 
5600                 ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, lt);
5601           }
5602         ;
5604 where_clause
5605         : WHERE
5606           {
5607                 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5608           }
5609           boolean_expression
5610           {
5611                 $$ = new Linq.Where (current_block.Toplevel, (BooleanExpression)$3, GetLocation ($1));
5613                 current_block.SetEndLocation (lexer.Location);
5614                 current_block = current_block.Parent;
5615           }
5616         ;
5617         
5618 join_clause
5619         : JOIN IDENTIFIER IN
5620           {
5621                 if (linq_clause_blocks == null)
5622                         linq_clause_blocks = new Stack ();
5623                         
5624                 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5625                 linq_clause_blocks.Push (current_block);
5626           }
5627           expression ON
5628           {
5629                 current_block.SetEndLocation (lexer.Location);
5630                 current_block = current_block.Parent;
5632                 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5633                 linq_clause_blocks.Push (current_block);
5634           }
5635           expression EQUALS
5636           {
5637                 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5638                 current_block.SetEndLocation (lexer.Location);
5639                 current_block = current_block.Parent;
5641                 current_block = new Linq.QueryBlock (compiler, current_block, (LocatedToken) $2, lexer.Location);
5642           }
5643           expression opt_join_into
5644           {
5645                 LocatedToken lt = (LocatedToken) $2;
5646                 
5647                 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5648                 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5650                 if ($12 == null) {
5651                         $$ = new Linq.Join (block, lt, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1));
5652                 } else {
5653                         $$ = new Linq.GroupJoin (block, lt, (Expression)$5, outer_selector, current_block.Toplevel,
5654                                 (LocatedToken) $12, GetLocation ($1));
5655                 }
5657                 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5658                 current_block.SetEndLocation (lexer.Location);
5659                 current_block = current_block.Parent;
5660                         
5661                 if ($12 == null)
5662                         ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, lt);
5663                 else
5664                         ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, (LocatedToken) $12);
5665           }
5666         | JOIN type IDENTIFIER IN
5667           {
5668                 if (linq_clause_blocks == null)
5669                         linq_clause_blocks = new Stack ();
5670                         
5671                 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5672                 linq_clause_blocks.Push (current_block);
5673           }
5674           expression ON
5675           {
5676                 current_block.SetEndLocation (lexer.Location);
5677                 current_block = current_block.Parent;
5679                 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5680                 linq_clause_blocks.Push (current_block);
5681           }
5682           expression EQUALS
5683           {
5684                 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5685                 current_block.SetEndLocation (lexer.Location);
5686                 current_block = current_block.Parent;
5688                 current_block = new Linq.QueryBlock (compiler, current_block, (LocatedToken) $3, lexer.Location);
5689           }
5690           expression opt_join_into
5691           {
5692                 LocatedToken lt = (LocatedToken) $3;
5693                 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5694                 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5695                 
5696                 Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$6);
5697                 if ($13 == null) {
5698                         $$ = new Linq.Join (block, lt, cast, outer_selector, current_block.Toplevel, GetLocation ($1));
5699                 } else {
5700                         $$ = new Linq.GroupJoin (block, lt, cast, outer_selector, current_block.Toplevel,
5701                                 (LocatedToken) $13, GetLocation ($1));
5702                 }
5703                 
5704                 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5705                 current_block.SetEndLocation (lexer.Location);
5706                 current_block = current_block.Parent;
5707                         
5708                 if ($13 == null)
5709                         ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, lt);
5710                 else
5711                         ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, (LocatedToken) $13);
5712           }
5713         ;
5714         
5715 opt_join_into
5716         : /* empty */
5717         | INTO IDENTIFIER
5718           {
5719                 $$ = $2;
5720           }
5721         ;
5722         
5723 orderby_clause
5724         : ORDERBY
5725           {
5726                 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5727           }
5728           orderings
5729           {
5730                 current_block.SetEndLocation (lexer.Location);
5731                 current_block = current_block.Parent;
5732           
5733                 $$ = $3;
5734           }
5735         ;
5736         
5737 orderings
5738         : order_by
5739         | order_by COMMA
5740           {
5741                 current_block.SetEndLocation (lexer.Location);
5742                 current_block = current_block.Parent;
5743           
5744                 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5745           }
5746           orderings_then_by
5747           {
5748                 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5749                 $$ = $1;
5750           }
5751         ;
5752         
5753 orderings_then_by
5754         : then_by
5755         | orderings_then_by COMMA
5756          {
5757                 current_block.SetEndLocation (lexer.Location);
5758                 current_block = current_block.Parent;
5759           
5760                 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);   
5761          }
5762          then_by
5763          {
5764                 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5765                 $$ = $1;
5766          }
5767         ;       
5768         
5769 order_by
5770         : expression
5771           {
5772                 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);        
5773           }
5774         | expression ASCENDING
5775           {
5776                 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);        
5777           }
5778         | expression DESCENDING
5779           {
5780                 $$ = new Linq.OrderByDescending (current_block.Toplevel, (Expression)$1);       
5781           }
5782         ;
5784 then_by
5785         : expression
5786           {
5787                 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1); 
5788           }
5789         | expression ASCENDING
5790           {
5791                 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1); 
5792           }
5793         | expression DESCENDING
5794           {
5795                 $$ = new Linq.ThenByDescending (current_block.Toplevel, (Expression)$1);        
5796           }     
5797         ;
5800 opt_query_continuation
5801         : /* empty */
5802         | INTO IDENTIFIER
5803           {
5804                 // query continuation block is not linked with query block but with block
5805                 // before. This means each query can use same range variable names for
5806                 // different identifiers.
5808                 current_block.SetEndLocation (GetLocation ($1));
5809                 current_block = current_block.Parent;
5810                 
5811                 current_block = new Linq.QueryBlock (compiler, current_block, (LocatedToken) $2, GetLocation ($1));
5812           }
5813           query_body
5814           {
5815                 $$ = new Linq.QueryExpression (current_block, (Linq.AQueryClause)$4);
5816           }
5817         ;
5818         
5820 // Support for using the compiler as an interactive parser
5822 // The INTERACTIVE_PARSER token is first sent to parse our
5823 // productions;  If the result is a Statement, the parsing
5824 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5825 // to setup the blocks in advance.
5827 // This setup is here so that in the future we can add 
5828 // support for other constructs (type parsing, namespaces, etc)
5829 // that do not require a block to be setup in advance
5832 interactive_parsing
5833         : EVAL_STATEMENT_PARSER EOF 
5834         | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives 
5835         | EVAL_STATEMENT_PARSER { 
5836                 Evaluator.LoadAliases (current_namespace);
5838                 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5839                         Modifiers.PUBLIC, null), null);
5841                 ArrayList baseclass_list = new ArrayList ();
5842                 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5843                 current_container.AddBasesForPart (current_class, baseclass_list);
5845                 // (ref object retval)
5846                 Parameter [] mpar = new Parameter [1];
5847                 mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
5849                 ParametersCompiled pars = new ParametersCompiled (compiler, mpar);
5850                 current_local_parameters = pars;
5851                 Method method = new Method (
5852                         current_class,
5853                         null, // generic
5854                         TypeManager.system_void_expr,
5855                         Modifiers.PUBLIC | Modifiers.STATIC,
5856                         new MemberName ("Host"),
5857                         pars,
5858                         null /* attributes */);
5860                 oob_stack.Push (method);
5861                 ++lexer.parsing_block;
5862                 start_block (lexer.Location);
5863           }             
5864           interactive_statement_list opt_COMPLETE_COMPLETION
5865           {
5866                 --lexer.parsing_block;
5867                 Method method = (Method) oob_stack.Pop ();
5869                 method.Block = (ToplevelBlock) end_block(lexer.Location);
5870                 current_container.AddMethod (method);
5872                 --lexer.parsing_declaration;
5873                 InteractiveResult = pop_current_class ();
5874                 current_local_parameters = null;
5875           } 
5876         | EVAL_COMPILATION_UNIT_PARSER {
5877                 Evaluator.LoadAliases (current_namespace);
5878           }
5879           interactive_compilation_unit
5880         ;
5882 interactive_compilation_unit
5883         : outer_declarations 
5884         | outer_declarations global_attributes 
5885         | global_attributes 
5886         | /* nothing */
5887         ;
5889 opt_COMPLETE_COMPLETION
5890         : /* nothing */
5891         | COMPLETE_COMPLETION
5892         ;
5894 close_brace_or_complete_completion
5895         : CLOSE_BRACE
5896         | COMPLETE_COMPLETION
5897         ;
5900 // <summary>
5901 //   A class used to pass around variable declarations and constants
5902 // </summary>
5903 public class VariableDeclaration {
5904         public string identifier;
5905         public Expression expression_or_array_initializer;
5906         public Location Location;
5907         public Attributes OptAttributes;
5908         public string DocComment;
5910         public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5911         {
5912                 this.identifier = lt.Value;
5913                 if (eoai is ArrayList) {
5914                         this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5915                 } else {
5916                         this.expression_or_array_initializer = (Expression)eoai;
5917                 }
5918                 this.Location = lt.Location;
5919                 this.OptAttributes = opt_attrs;
5920         }
5922         public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5923         {
5924         }
5927 class VariableMemberDeclaration
5929         public readonly MemberName MemberName;
5930         public Expression expression_or_array_initializer;
5931         
5932         public VariableMemberDeclaration (MemberName mn, object initializer)
5933         {
5934                 MemberName = mn;
5935                 
5936                 if (initializer is ArrayList) {
5937                         this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
5938                 } else {
5939                         this.expression_or_array_initializer = (Expression)initializer;
5940                 }
5941         }
5945 // <summary>
5946 //  A class used to hold info about an operator declarator
5947 // </summary>
5948 struct OperatorDeclaration {
5949         public readonly Operator.OpType optype;
5950         public readonly FullNamedExpression ret_type;
5951         public readonly Location location;
5953         public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5954         {
5955                 optype = op;
5956                 this.ret_type = ret_type;
5957                 this.location = location;
5958         }
5961 void Error_ExpectingTypeName (Expression expr)
5963         if (expr is Invocation){
5964                 Report.Error (1002, expr.Location, "Expecting `;'");
5965         } else {
5966                 Expression.Error_InvalidExpressionStatement (Report, expr.Location);
5967         }
5970 void Error_ParameterModifierNotValid (string modifier, Location loc)
5972         Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5973                                       modifier);
5976 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5978         Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5979                 Parameter.GetModifierSignature (mod));
5982 void Error_TypeExpected (Location loc)
5984         Report.Error (1031, loc, "Type expected");
5987 void Error_NamedArgumentExpected (NamedArgument a)
5989         Report.Error (1738, a.Name.Location, "Named arguments must appear after the positional arguments");
5992 void push_current_class (TypeContainer tc, object partial_token)
5994         if (RootContext.EvalMode){
5995                 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
5996                 undo.AddTypeContainer (current_container, tc);
5997         }
5999         if (partial_token != null)
6000                 current_container = current_container.AddPartial (tc);
6001         else
6002                 current_container = current_container.AddTypeContainer (tc);
6004         ++lexer.parsing_declaration;
6005         current_class = tc;
6008 DeclSpace pop_current_class ()
6010         DeclSpace retval = current_class;
6012         current_class = current_class.Parent;
6013         current_container = current_class.PartialContainer;
6015         return retval;
6018 // <summary>
6019 //   Given the @class_name name, it creates a fully qualified name
6020 //   based on the containing declaration space
6021 // </summary>
6022 MemberName
6023 MakeName (MemberName class_name)
6025         Namespace ns = current_namespace.NS;
6027         if (current_container == RootContext.ToplevelTypes) {
6028                 if (ns.Name.Length != 0)
6029                         return new MemberName (ns.MemberName, class_name);
6030                 else
6031                         return class_name;
6032         } else {
6033                 return new MemberName (current_container.MemberName, class_name);
6034         }
6037 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
6039         Block implicit_block;
6040         ArrayList inits = null;
6042         //
6043         // If we are doing interactive editing, we want variable declarations
6044         // that are in the top block to be added instead to the class as 
6045         // static variables
6046         //
6047         if (RootContext.StatementMode){
6048                 bool hoist = true;
6050                 for (Block b = current_block; b != null; b = b.Parent){
6051                         if (b is ExplicitBlock && !(b is ToplevelBlock)){
6052                                 // There has been an explicit block, we cant add to the class
6053                                 hoist = false;
6054                                 break;
6055                         }
6056                 }               
6057                 if (hoist){
6058                         //
6059                         // We can use "current_block" since we know there are no explicit blocks
6060                         //
6061                         foreach (VariableDeclaration decl in variable_declarators){
6062                                 // We can not use the super-handy f.Initializer, because
6063                                 // multiple lines would force code to be executed out of sync
6064                                 if (decl.expression_or_array_initializer != null){
6065                                         string id = "$" + decl.identifier;
6066                                         LocalInfo vi = current_block.AddVariable (type, id, decl.Location);                                     
6068                                         // Avoid warning about this variable not being used.
6069                                         vi.Used = true;
6071                                         LocalVariableReference var;
6072                                         var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, vi, decl.Location);
6073                                         Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
6074                                         current_block.AddStatement (new StatementExpression (assign));
6075                                         assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
6076                                         current_block.AddStatement (new StatementExpression (assign));
6077                                 } else {
6078                                         Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
6079                                                 new MemberName (decl.identifier, loc), null);
6080                                         current_container.AddField (f);
6082                                         // Register the field to be visible later as a global variable
6083                                         Evaluator.QueueField (f);
6084                                 }
6085                         }
6087                         return current_block;
6088                 }
6089         }
6091         //
6092         // We use the `Used' property to check whether statements
6093         // have been added to the current block.  If so, we need
6094         // to create another block to contain the new declaration
6095         // otherwise, as an optimization, we use the same block to
6096         // add the declaration.
6097         //
6098         // FIXME: A further optimization is to check if the statements
6099         // that were added were added as part of the initialization
6100         // below.  In which case, no other statements have been executed
6101         // and we might be able to reduce the number of blocks for
6102         // situations like this:
6103         //
6104         // int j = 1;  int k = j + 1;
6105         //
6106         if (current_block.Used)
6107                 implicit_block = new Block (current_block, loc, lexer.Location);
6108         else
6109                 implicit_block = current_block;
6111         foreach (VariableDeclaration decl in variable_declarators){
6113                 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
6114                         if (decl.expression_or_array_initializer != null){
6115                                 if (inits == null)
6116                                         inits = new ArrayList (4);
6117                                 inits.Add (decl);
6118                         }
6119                 }
6120         }
6122         if (inits == null)
6123                 return implicit_block;
6125         foreach (VariableDeclaration decl in inits){
6126                 Assign assign;
6127                 Expression expr = decl.expression_or_array_initializer;
6128                 
6129                 LocalVariableReference var;
6130                 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
6132                 assign = new SimpleAssign (var, expr, decl.Location);
6134                 implicit_block.AddStatement (new StatementExpression (assign));
6135         }
6136         
6137         return implicit_block;
6140 Block declare_local_constants (Expression type, ArrayList declarators)
6142         Block implicit_block;
6144         if (current_block.Used)
6145                 implicit_block = new Block (current_block);
6146         else
6147                 implicit_block = current_block;
6149         foreach (VariableDeclaration decl in declarators){
6150                 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
6151         }
6152         
6153         return implicit_block;
6156 string CheckAttributeTarget (string a, Location l)
6158         switch (a) {
6159         case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6160                         return a;
6161         }
6163         Report.Warning (658, 1, l,
6164                  "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6165         return string.Empty;
6168 static bool IsUnaryOperator (Operator.OpType op)
6170         switch (op) {
6171                 
6172         case Operator.OpType.LogicalNot: 
6173         case Operator.OpType.OnesComplement: 
6174         case Operator.OpType.Increment:
6175         case Operator.OpType.Decrement:
6176         case Operator.OpType.True: 
6177         case Operator.OpType.False: 
6178         case Operator.OpType.UnaryPlus: 
6179         case Operator.OpType.UnaryNegation:
6180                 return true;
6181         }
6182         return false;
6185 void syntax_error (Location l, string msg)
6187         Report.Error (1003, l, "Syntax error, " + msg);
6190 Tokenizer lexer;
6192 public Tokenizer Lexer {
6193         get {
6194                 return lexer;
6195         }
6196 }                  
6198 static CSharpParser ()
6200         oob_stack = new Stack ();
6203 public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx)
6205         if (RootContext.EvalMode)
6206                 undo = new Undo ();
6208         this.file = file;
6209         this.compiler = ctx;
6210         current_namespace = new NamespaceEntry (null, file, null);
6211         current_class = current_namespace.SlaveDeclSpace;
6212         current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6213         oob_stack.Clear ();
6214         lexer = new Tokenizer (reader, file, ctx);
6217 public void parse ()
6219         eof_token = Token.EOF;
6220         
6221         try {
6222                 if (yacc_verbose_flag > 1)
6223                         yyparse (lexer, new yydebug.yyDebugSimple ());
6224                 else
6225                         yyparse (lexer);
6226                         
6227                 Tokenizer tokenizer = lexer as Tokenizer;
6228                 tokenizer.cleanup ();           
6229         } catch (Exception e){
6230                 if (e is yyParser.yyUnexpectedEof)
6231                         UnexpectedEOF = true;
6233                 if (e is yyParser.yyException)
6234                         Report.Error (-25, lexer.Location, "Parsing error");
6235                 else if (yacc_verbose_flag > 0)
6236                         throw;  // Used by compiler-tester to test internal errors
6237                 else 
6238                         Report.Error (589, lexer.Location, "Internal compiler error during parsing");
6239         }
6241         if (RootContext.ToplevelTypes.NamespaceEntry != null)
6242                 throw new InternalErrorException ("who set it?");
6245 void CheckToken (int error, int yyToken, string msg, Location loc)
6247         if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6248                 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6249         else
6250                 Report.Error (error, loc, msg);
6253 void CheckIdentifierToken (int yyToken, Location loc)
6255         CheckToken (1041, yyToken, "Identifier expected", loc);
6258 string ConsumeStoredComment ()
6260         string s = tmpComment;
6261         tmpComment = null;
6262         Lexer.doc_state = XmlCommentState.Allowed;
6263         return s;
6266 Location GetLocation (object obj)
6268         if (obj is MemberCore)
6269                 return ((MemberCore) obj).Location;
6270         if (obj is MemberName)
6271                 return ((MemberName) obj).Location;
6272         if (obj is LocatedToken)
6273                 return ((LocatedToken) obj).Location;
6274         if (obj is Location)
6275                 return (Location) obj;
6276         return lexer.Location;
6279 Report Report {
6280         get { return compiler.Report; }
6283 void start_block (Location loc)
6285         if (current_block == null || parsing_anonymous_method) {
6286                 current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, current_generic_method, loc);
6287                 parsing_anonymous_method = false;
6288         } else {
6289                 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6290         }
6293 Block
6294 end_block (Location loc)
6296         Block retval = current_block.Explicit;
6297         retval.SetEndLocation (loc);
6298         current_block = retval.Parent;
6299         return retval;
6302 void
6303 start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6305         if (RootContext.Version == LanguageVersion.ISO_1){
6306                 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6307         }
6309         oob_stack.Push (current_anonymous_method);
6310         oob_stack.Push (current_local_parameters);
6312         current_local_parameters = parameters;
6314         current_anonymous_method = lambda 
6315                 ? new LambdaExpression (loc) 
6316                 : new AnonymousMethodExpression (loc);
6318         // Force the next block to be created as a ToplevelBlock
6319         parsing_anonymous_method = true;
6323  * Completes the anonymous method processing, if lambda_expr is null, this
6324  * means that we have a Statement instead of an Expression embedded 
6325  */
6326 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
6328         AnonymousMethodExpression retval;
6330         current_anonymous_method.Block = anon_block;
6331         retval = current_anonymous_method;
6333         current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6334         current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6336         return retval;
6339 public NamespaceEntry CurrentNamespace {
6340        get { 
6341            return current_namespace;
6342        }
6346 void Error_SyntaxError (int token)
6348         Error_SyntaxError (0, token, "Unexpected symbol");
6351 void Error_SyntaxError (int error_code, int token, string msg)
6353         string symbol = GetSymbolName (token);
6354         string expecting = GetExpecting ();
6355         
6356         if (error_code == 0) {
6357                 if (expecting == "`)'")
6358                         error_code = 1026;
6359                 else
6360                         error_code = 1525;
6361         }
6362         
6363         if (expecting != null)
6364                 Report.Error (error_code, lexer.Location, "{2} `{0}', expecting {1}", 
6365                         symbol, expecting, msg);          
6366         else
6367                 Report.Error (error_code, lexer.Location, "{1} `{0}'", symbol, msg);
6370 string GetExpecting ()
6372         int [] tokens = yyExpectingTokens (yyExpectingState);
6373         ArrayList names = new ArrayList (tokens.Length);
6374         bool has_type = false;
6375         bool has_identifier = false;
6376         for (int i = 0; i < tokens.Length; i++){
6377                 int token = tokens [i];
6378                 has_identifier |= token == Token.IDENTIFIER;
6379                 
6380                 string name = GetTokenName (token);
6381                 if (name == "<internal>")
6382                         continue;
6383                         
6384                 has_type |= name == "type";
6385                 if (names.Contains (name))
6386                         continue;
6387                 
6388                 names.Add (name);
6389         }
6391         //
6392         // Too many tokens to enumerate
6393         //
6394         if (names.Count > 8)
6395                 return null;
6397         if (has_type && has_identifier)
6398                 names.Remove ("identifier");
6400         if (names.Count == 1)
6401                 return "`" + GetTokenName (tokens [0]) + "'";
6402         
6403         StringBuilder sb = new StringBuilder ();
6404         names.Sort ();
6405         int count = names.Count;
6406         for (int i = 0; i < count; i++){
6407                 bool last = i + 1 == count;
6408                 if (last)
6409                         sb.Append ("or ");
6410                 sb.Append ('`');
6411                 sb.Append (names [i]);
6412                 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6413         }
6414         return sb.ToString ();
6418 string GetSymbolName (int token)
6420         switch (token){
6421         case Token.LITERAL_FLOAT:
6422         case Token.LITERAL_INTEGER:
6423         case Token.LITERAL_DOUBLE:
6424         case Token.LITERAL_DECIMAL:
6425         case Token.LITERAL_CHARACTER:
6426         case Token.LITERAL_STRING:
6427                 return lexer.Value.ToString ();
6428         case Token.IDENTIFIER:
6429                 return ((LocatedToken)lexer.Value).Value;
6431         case Token.BOOL:
6432                 return "bool";
6433         case Token.BYTE:
6434                 return "byte";
6435         case Token.CHAR:
6436                 return "char";
6437         case Token.VOID:
6438                 return "void";
6439         case Token.DECIMAL:
6440                 return "decimal";
6441         case Token.DOUBLE:
6442                 return "double";
6443         case Token.FLOAT:
6444                 return "float";
6445         case Token.INT:
6446                 return "int";
6447         case Token.LONG:
6448                 return "long";
6449         case Token.SBYTE:
6450                 return "sbyte";
6451         case Token.SHORT:
6452                 return "short";
6453         case Token.STRING:
6454                 return "string";
6455         case Token.UINT:
6456                 return "uint";
6457         case Token.ULONG:
6458                 return "ulong";
6459         case Token.USHORT:
6460                 return "ushort";
6461         case Token.OBJECT:
6462                 return "object";
6463                 
6464         case Token.PLUS:
6465                 return "+";
6466         case Token.UMINUS:
6467         case Token.MINUS:
6468                 return "-";
6469         case Token.BANG:
6470                 return "!";
6471         case Token.BITWISE_AND:
6472                 return "&";
6473         case Token.BITWISE_OR:
6474                 return "|";
6475         case Token.STAR:
6476                 return "*";
6477         case Token.PERCENT:
6478                 return "%";
6479         case Token.DIV:
6480                 return "/";
6481         case Token.CARRET:
6482                 return "^";
6483         case Token.OP_INC:
6484                 return "++";
6485         case Token.OP_DEC:
6486                 return "--";
6487         case Token.OP_SHIFT_LEFT:
6488                 return "<<";
6489         case Token.OP_SHIFT_RIGHT:
6490                 return ">>";
6491         case Token.OP_LT:
6492                 return "<";
6493         case Token.OP_GT:
6494                 return ">";
6495         case Token.OP_LE:
6496                 return "<=";
6497         case Token.OP_GE:
6498                 return ">=";
6499         case Token.OP_EQ:
6500                 return "==";
6501         case Token.OP_NE:
6502                 return "!=";
6503         case Token.OP_AND:
6504                 return "&&";
6505         case Token.OP_OR:
6506                 return "||";
6507         case Token.OP_PTR:
6508                 return "->";
6509         case Token.OP_COALESCING:       
6510                 return "??";
6511         case Token.OP_MULT_ASSIGN:
6512                 return "*=";
6513         case Token.OP_DIV_ASSIGN:
6514                 return "/=";
6515         case Token.OP_MOD_ASSIGN:
6516                 return "%=";
6517         case Token.OP_ADD_ASSIGN:
6518                 return "+=";
6519         case Token.OP_SUB_ASSIGN:
6520                 return "-=";
6521         case Token.OP_SHIFT_LEFT_ASSIGN:
6522                 return "<<=";
6523         case Token.OP_SHIFT_RIGHT_ASSIGN:
6524                 return ">>=";
6525         case Token.OP_AND_ASSIGN:
6526                 return "&=";
6527         case Token.OP_XOR_ASSIGN:
6528                 return "^=";
6529         case Token.OP_OR_ASSIGN:
6530                 return "|=";
6531         }
6533         return GetTokenName (token);
6536 static string GetTokenName (int token)
6538         switch (token){
6539         case Token.ABSTRACT:
6540                 return "abstract";
6541         case Token.AS:
6542                 return "as";
6543         case Token.ADD:
6544                 return "add";
6545         case Token.BASE:
6546                 return "base";
6547         case Token.BREAK:
6548                 return "break";
6549         case Token.CASE:
6550                 return "case";
6551         case Token.CATCH:
6552                 return "catch";
6553         case Token.CHECKED:
6554                 return "checked";
6555         case Token.CLASS:
6556                 return "class";
6557         case Token.CONST:
6558                 return "const";
6559         case Token.CONTINUE:
6560                 return "continue";
6561         case Token.DEFAULT:
6562                 return "default";
6563         case Token.DELEGATE:
6564                 return "delegate";
6565         case Token.DO:
6566                 return "do";
6567         case Token.ELSE:
6568                 return "else";
6569         case Token.ENUM:
6570                 return "enum";
6571         case Token.EVENT:
6572                 return "event";
6573         case Token.EXPLICIT:
6574                 return "explicit";
6575         case Token.EXTERN:
6576                 return "extern";
6577         case Token.FALSE:
6578                 return "false";
6579         case Token.FINALLY:
6580                 return "finally";
6581         case Token.FIXED:
6582                 return "fixed";
6583         case Token.FOR:
6584                 return "for";
6585         case Token.FOREACH:
6586                 return "foreach";
6587         case Token.GOTO:
6588                 return "goto";
6589         case Token.IF:
6590                 return "if";
6591         case Token.IMPLICIT:
6592                 return "implicit";
6593         case Token.IN:
6594                 return "in";
6595         case Token.INTERFACE:
6596                 return "interface";
6597         case Token.INTERNAL:
6598                 return "internal";
6599         case Token.IS:
6600                 return "is";
6601         case Token.LOCK:
6602                 return "lock";
6603         case Token.NAMESPACE:
6604                 return "namespace";
6605         case Token.NEW:
6606                 return "new";
6607         case Token.NULL:
6608                 return "null";
6609         case Token.OPERATOR:
6610                 return "operator";
6611         case Token.OUT:
6612                 return "out";
6613         case Token.OVERRIDE:
6614                 return "override";
6615         case Token.PARAMS:
6616                 return "params";
6617         case Token.PRIVATE:
6618                 return "private";
6619         case Token.PROTECTED:
6620                 return "protected";
6621         case Token.PUBLIC:
6622                 return "public";
6623         case Token.READONLY:
6624                 return "readonly";
6625         case Token.REF:
6626                 return "ref";
6627         case Token.RETURN:
6628                 return "return";
6629         case Token.REMOVE:
6630                 return "remove";
6631         case Token.SEALED:
6632                 return "sealed";
6633         case Token.SIZEOF:
6634                 return "sizeof";
6635         case Token.STACKALLOC:
6636                 return "stackalloc";
6637         case Token.STATIC:
6638                 return "static";
6639         case Token.STRUCT:
6640                 return "struct";
6641         case Token.SWITCH:
6642                 return "switch";
6643         case Token.THIS:
6644                 return "this";
6645         case Token.THROW:
6646                 return "throw";
6647         case Token.TRUE:
6648                 return "true";
6649         case Token.TRY:
6650                 return "try";
6651         case Token.TYPEOF:
6652                 return "typeof";
6653         case Token.UNCHECKED:
6654                 return "unchecked";
6655         case Token.UNSAFE:
6656                 return "unsafe";
6657         case Token.USING:
6658                 return "using";
6659         case Token.VIRTUAL:
6660                 return "virtual";
6661         case Token.VOLATILE:
6662                 return "volatile";
6663         case Token.WHERE:
6664                 return "where";
6665         case Token.WHILE:
6666                 return "while";
6667         case Token.ARGLIST:
6668                 return "__arglist";
6669         case Token.PARTIAL:
6670                 return "partial";
6671         case Token.ARROW:
6672                 return "=>";
6673         case Token.FROM:
6674         case Token.FROM_FIRST:
6675                 return "from";
6676         case Token.JOIN:
6677                 return "join";
6678         case Token.ON:
6679                 return "on";
6680         case Token.EQUALS:
6681                 return "equals";
6682         case Token.SELECT:
6683                 return "select";
6684         case Token.GROUP:
6685                 return "group";
6686         case Token.BY:
6687                 return "by";
6688         case Token.LET:
6689                 return "let";
6690         case Token.ORDERBY:
6691                 return "orderby";
6692         case Token.ASCENDING:
6693                 return "ascending";
6694         case Token.DESCENDING:
6695                 return "descending";
6696         case Token.INTO:
6697                 return "into";
6698         case Token.GET:
6699                 return "get";
6700         case Token.SET:
6701                 return "set";
6702         case Token.OPEN_BRACE:
6703                 return "{";
6704         case Token.CLOSE_BRACE:
6705                 return "}";
6706         case Token.OPEN_BRACKET:
6707                 return "[";
6708         case Token.CLOSE_BRACKET:
6709                 return "]";
6710         case Token.OPEN_PARENS_CAST:
6711         case Token.OPEN_PARENS_LAMBDA:
6712         case Token.OPEN_PARENS:
6713                 return "(";
6714         case Token.CLOSE_PARENS:
6715                 return ")";
6716         case Token.DOT:
6717                 return ".";
6718         case Token.COMMA:
6719                 return ",";
6720         case Token.DEFAULT_COLON:
6721                 return "default:";
6722         case Token.COLON:
6723                 return ":";
6724         case Token.SEMICOLON:
6725                 return ";";
6726         case Token.TILDE:
6727                 return "~";
6728                 
6729         case Token.PLUS:
6730         case Token.UMINUS:
6731         case Token.MINUS:
6732         case Token.BANG:
6733         case Token.OP_LT:
6734         case Token.OP_GT:
6735         case Token.BITWISE_AND:
6736         case Token.BITWISE_OR:
6737         case Token.STAR:
6738         case Token.PERCENT:
6739         case Token.DIV:
6740         case Token.CARRET:
6741         case Token.OP_INC:
6742         case Token.OP_DEC:
6743         case Token.OP_SHIFT_LEFT:
6744         case Token.OP_SHIFT_RIGHT:
6745         case Token.OP_LE:
6746         case Token.OP_GE:
6747         case Token.OP_EQ:
6748         case Token.OP_NE:
6749         case Token.OP_AND:
6750         case Token.OP_OR:
6751         case Token.OP_PTR:
6752         case Token.OP_COALESCING:       
6753         case Token.OP_MULT_ASSIGN:
6754         case Token.OP_DIV_ASSIGN:
6755         case Token.OP_MOD_ASSIGN:
6756         case Token.OP_ADD_ASSIGN:
6757         case Token.OP_SUB_ASSIGN:
6758         case Token.OP_SHIFT_LEFT_ASSIGN:
6759         case Token.OP_SHIFT_RIGHT_ASSIGN:
6760         case Token.OP_AND_ASSIGN:
6761         case Token.OP_XOR_ASSIGN:
6762         case Token.OP_OR_ASSIGN:
6763                 return "<operator>";
6765         case Token.BOOL:
6766         case Token.BYTE:
6767         case Token.CHAR:
6768         case Token.VOID:
6769         case Token.DECIMAL:
6770         case Token.DOUBLE:
6771         case Token.FLOAT:
6772         case Token.INT:
6773         case Token.LONG:
6774         case Token.SBYTE:
6775         case Token.SHORT:
6776         case Token.STRING:
6777         case Token.UINT:
6778         case Token.ULONG:
6779         case Token.USHORT:
6780         case Token.OBJECT:
6781                 return "type";
6782         
6783         case Token.ASSIGN:
6784                 return "=";
6785         case Token.OP_GENERICS_LT:
6786         case Token.GENERIC_DIMENSION:
6787                 return "<";
6788         case Token.OP_GENERICS_GT:
6789                 return ">";
6790         case Token.INTERR:
6791         case Token.INTERR_NULLABLE:
6792                 return "?";
6793         case Token.DOUBLE_COLON:
6794                 return "::";
6795         case Token.LITERAL_FLOAT:
6796         case Token.LITERAL_INTEGER:
6797         case Token.LITERAL_DOUBLE:
6798         case Token.LITERAL_DECIMAL:
6799         case Token.LITERAL_CHARACTER:
6800         case Token.LITERAL_STRING:
6801                 return "value";
6802         case Token.IDENTIFIER:
6803                 return "identifier";
6805                 // All of these are internal.
6806         case Token.NONE:
6807         case Token.ERROR:
6808         case Token.FIRST_KEYWORD:
6809         case Token.EOF:
6810         case Token.EVAL_COMPILATION_UNIT_PARSER:
6811         case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6812         case Token.EVAL_STATEMENT_PARSER:
6813         case Token.LAST_KEYWORD:
6814         case Token.GENERATE_COMPLETION:
6815         case Token.COMPLETE_COMPLETION:
6816                 return "<internal>";
6818                 // A bit more robust.
6819         default:
6820                 return yyNames [token];
6821         }
6824 /* end end end */