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