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