[mcs] Throw expression cannot be placed after any colon.
[mono.git] / mcs / mcs / cs-parser.jay
1 %{
2 //
3 // cs-parser.jay: The Parser for the C# compiler
4 //
5 // Authors: Miguel de Icaza (miguel@gnome.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
10 //
11 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (C) 2004-2011 Novell, Inc
13 // Copyright 2011-2012 Xamarin Inc.
14 //
15
16 using System.Text;
17 using System.IO;
18 using System;
19 using System.Collections.Generic;
20
21 namespace Mono.CSharp
22 {
23         /// <summary>
24         ///    The C# Parser
25         /// </summary>
26         public class CSharpParser
27         {
28                 [Flags]
29                 enum ParameterModifierType
30                 {
31                         Ref             = 1 << 1,
32                         Out             = 1 << 2,
33                         This    = 1 << 3,
34                         Params  = 1 << 4,
35                         Arglist = 1 << 5,
36                         DefaultValue = 1 << 6,
37                         
38                         All = Ref | Out | This | Params | Arglist | DefaultValue,
39                         PrimaryConstructor = Ref | Out | Params | DefaultValue
40                 }
41                 
42                 static readonly object ModifierNone = 0;
43         
44                 NamespaceContainer current_namespace;
45                 TypeContainer current_container;
46                 TypeDefinition current_type;
47                 PropertyBase current_property;
48                 EventProperty current_event;
49                 EventField current_event_field;
50                 FieldBase current_field;
51         
52                 /// <summary>
53                 ///   Current block is used to add statements as we find
54                 ///   them.  
55                 /// </summary>
56                 Block      current_block;
57                 
58                 BlockVariable current_variable;
59
60                 Delegate   current_delegate;
61                 
62                 AnonymousMethodExpression current_anonymous_method;
63
64                 /// <summary>
65                 ///   This is used by the unary_expression code to resolve
66                 ///   a name against a parameter.  
67                 /// </summary>
68                 
69                 // FIXME: This is very ugly and it's very hard to reset it correctly
70                 // on all places, especially when some parameters are autogenerated.
71                 ParametersCompiled current_local_parameters;
72
73                 bool parsing_anonymous_method;
74                 
75                 bool async_block;
76
77                 ///
78                 /// An out-of-band stack.
79                 ///
80                 Stack<object> oob_stack;
81
82                 ///
83                 /// Controls the verbosity of the errors produced by the parser
84                 ///
85                 int yacc_verbose_flag;
86
87                 /// 
88                 /// Used by the interactive shell, flags whether EOF was reached
89                 /// and an error was produced
90                 ///
91                 public bool UnexpectedEOF;
92
93                 ///
94                 /// The current file.
95                 ///
96                 readonly CompilationSourceFile file;
97
98                 ///
99                 /// Temporary Xml documentation cache.
100                 /// For enum types, we need one more temporary store.
101                 ///
102                 string tmpComment;
103                 string enumTypeComment;
104                         
105                 /// Current attribute target
106                 string current_attr_target;
107                 
108                 ParameterModifierType valid_param_mod;
109                 
110                 bool default_parameter_used;
111
112                 /// When using the interactive parser, this holds the
113                 /// resulting expression
114                 public Class InteractiveResult;
115
116                 //
117                 // Keeps track of global data changes to undo on parser error
118                 //
119                 public Undo undo;
120
121                 bool? interactive_async;
122                 
123                 Stack<Linq.QueryBlock> linq_clause_blocks;
124
125                 ModuleContainer module;
126                 
127                 readonly CompilerContext compiler;
128                 readonly LanguageVersion lang_version;
129                 readonly bool doc_support;
130                 readonly CompilerSettings settings;
131                 readonly Report report;
132                 
133                 //
134                 // Instead of allocating carrier array everytime we
135                 // share the bucket for very common constructs which can never
136                 // be recursive
137                 //
138                 List<Parameter> parameters_bucket;
139                 
140                 //
141                 // Full AST support members
142                 //
143                 LocationsBag lbag;
144                 List<Tuple<Modifiers, Location>> mod_locations;
145                 Stack<Location> location_stack;
146 %}
147
148 %token EOF
149 %token NONE   /* This token is never returned by our lexer */
150 %token ERROR            // This is used not by the parser, but by the tokenizer.
151                         // do not remove.
152
153 /*
154  *These are the C# keywords
155  */
156 %token FIRST_KEYWORD
157 %token ABSTRACT 
158 %token AS
159 %token ADD
160 %token BASE     
161 %token BOOL     
162 %token BREAK    
163 %token BYTE     
164 %token CASE     
165 %token CATCH    
166 %token CHAR     
167 %token CHECKED  
168 %token CLASS    
169 %token CONST    
170 %token CONTINUE 
171 %token DECIMAL  
172 %token DEFAULT  
173 %token DELEGATE 
174 %token DO       
175 %token DOUBLE   
176 %token ELSE     
177 %token ENUM     
178 %token EVENT    
179 %token EXPLICIT 
180 %token EXTERN   
181 %token FALSE    
182 %token FINALLY  
183 %token FIXED    
184 %token FLOAT    
185 %token FOR      
186 %token FOREACH  
187 %token GOTO     
188 %token IF       
189 %token IMPLICIT 
190 %token IN       
191 %token INT      
192 %token INTERFACE
193 %token INTERNAL 
194 %token IS       
195 %token LOCK     
196 %token LONG     
197 %token NAMESPACE
198 %token NEW      
199 %token NULL     
200 %token OBJECT   
201 %token OPERATOR 
202 %token OUT      
203 %token OVERRIDE 
204 %token PARAMS   
205 %token PRIVATE  
206 %token PROTECTED
207 %token PUBLIC   
208 %token READONLY 
209 %token REF      
210 %token RETURN   
211 %token REMOVE
212 %token SBYTE    
213 %token SEALED   
214 %token SHORT    
215 %token SIZEOF   
216 %token STACKALLOC
217 %token STATIC   
218 %token STRING   
219 %token STRUCT   
220 %token SWITCH   
221 %token THIS     
222 %token THROW
223 %token TRUE     
224 %token TRY      
225 %token TYPEOF   
226 %token UINT     
227 %token ULONG    
228 %token UNCHECKED
229 %token UNSAFE   
230 %token USHORT   
231 %token USING    
232 %token VIRTUAL  
233 %token VOID     
234 %token VOLATILE
235 %token WHERE
236 %token WHILE    
237 %token ARGLIST
238 %token PARTIAL
239 %token ARROW
240 %token FROM
241 %token FROM_FIRST
242 %token JOIN
243 %token ON
244 %token EQUALS
245 %token SELECT
246 %token GROUP
247 %token BY
248 %token LET
249 %token ORDERBY
250 %token ASCENDING
251 %token DESCENDING
252 %token INTO
253 %token INTERR_NULLABLE
254 %token EXTERN_ALIAS
255 %token REFVALUE
256 %token REFTYPE
257 %token MAKEREF
258 %token ASYNC
259 %token AWAIT
260 %token INTERR_OPERATOR
261 %token WHEN
262 %token INTERPOLATED_STRING
263 %token INTERPOLATED_STRING_END
264 %token THROW_EXPR
265
266 /* C# keywords which are not really keywords */
267 %token GET
268 %token SET
269
270 %left LAST_KEYWORD
271
272 /* C# single character operators/punctuation. */
273 %token OPEN_BRACE
274 %token CLOSE_BRACE
275 %token OPEN_BRACKET
276 %token CLOSE_BRACKET
277 %token OPEN_PARENS
278 %token CLOSE_PARENS
279
280 %token DOT
281 %token COMMA
282 %token COLON
283 %token SEMICOLON
284 %token TILDE
285
286 %token PLUS
287 %token MINUS
288 %token BANG
289 %token ASSIGN
290 %token OP_LT
291 %token OP_GT
292 %token BITWISE_AND
293 %token BITWISE_OR
294 %token STAR
295 %token PERCENT
296 %token DIV
297 %token CARRET
298 %token INTERR
299
300 /* C# multi-character operators. */
301 %token DOUBLE_COLON
302 %token OP_INC
303 %token OP_DEC
304 %token OP_SHIFT_LEFT
305 %token OP_SHIFT_RIGHT
306 %token OP_LE
307 %token OP_GE
308 %token OP_EQ
309 %token OP_NE
310 %token OP_AND
311 %token OP_OR
312 %token OP_MULT_ASSIGN
313 %token OP_DIV_ASSIGN
314 %token OP_MOD_ASSIGN
315 %token OP_ADD_ASSIGN
316 %token OP_SUB_ASSIGN
317 %token OP_SHIFT_LEFT_ASSIGN
318 %token OP_SHIFT_RIGHT_ASSIGN
319 %token OP_AND_ASSIGN
320 %token OP_XOR_ASSIGN
321 %token OP_OR_ASSIGN
322 %token OP_PTR
323 %token OP_COALESCING
324
325 /* Generics <,> tokens */
326 %token OP_GENERICS_LT
327 %token OP_GENERICS_LT_DECL
328 %token OP_GENERICS_GT
329
330 %token LITERAL
331
332 %token IDENTIFIER
333 %token OPEN_PARENS_LAMBDA
334 %token OPEN_PARENS_CAST
335 %token GENERIC_DIMENSION
336 %token DEFAULT_COLON
337 %token OPEN_BRACKET_EXPR
338
339 // Make the parser go into eval mode parsing (statements and compilation units).
340 %token EVAL_STATEMENT_PARSER
341 %token EVAL_COMPILATION_UNIT_PARSER
342 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
343
344 %token DOC_SEE
345
346 // 
347 // This token is generated to trigger the completion engine at this point
348 //
349 %token GENERATE_COMPLETION
350
351 //
352 // This token is return repeatedly after the first GENERATE_COMPLETION
353 // token is produced and before the final EOF
354 //
355 %token COMPLETE_COMPLETION
356
357 /* Add precedence rules to solve dangling else s/r conflict */
358 %nonassoc IF
359 %nonassoc ELSE
360
361 /* Define the operator tokens and their precedences */
362 %right ASSIGN
363 %right OP_COALESCING
364 %right INTERR
365 %left OP_OR
366 %left OP_AND
367 %left BITWISE_OR
368 %left BITWISE_AND
369 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
370 %left PLUS MINUS
371 %left STAR DIV PERCENT
372 %right BANG CARRET UMINUS
373 %nonassoc OP_INC OP_DEC
374 %left OPEN_PARENS
375 %left OPEN_BRACKET OPEN_BRACE
376 %left DOT
377
378 %start compilation_unit
379 %%
380
381 compilation_unit
382         : outer_declaration opt_EOF
383           {
384                 Lexer.check_incorrect_doc_comment ();
385           }
386         | interactive_parsing  { Lexer.CompleteOnEOF = false; } opt_EOF
387         | documentation_parsing
388         ;
389         
390 outer_declaration
391         : opt_extern_alias_directives opt_using_directives
392         | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
393           {
394                 if ($4 != null) {
395                         Attributes attrs = (Attributes) $4;
396                         report.Error (1730, attrs.Attrs [0].Location,
397                                 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
398
399                         current_namespace.UnattachedAttributes = attrs;
400                 }
401           }
402         | opt_extern_alias_directives opt_using_directives attribute_sections
403           {
404                 Attributes attrs = (Attributes) $3;
405                 if (attrs != null) {
406                         foreach (var a in attrs.Attrs) {
407                                 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
408                                         continue;
409
410                                 if (a.ExplicitTarget == null)
411                                         report.Error (-1671, a.Location, "Global attributes must have attribute target specified");
412                         }
413                 }
414
415                 module.AddAttributes ((Attributes) $3, current_namespace);
416           }
417         | error
418           {
419                 if (yyToken == Token.EXTERN_ALIAS)
420                         report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
421                 else
422                         Error_SyntaxError (yyToken);
423           }
424         ;
425         
426 opt_EOF
427         : /* empty */
428         | EOF
429         ;
430
431 extern_alias_directives
432         : extern_alias_directive
433         | extern_alias_directives extern_alias_directive
434         ;
435
436 extern_alias_directive
437         : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
438           {
439                 var lt = (LocatedToken) $2;
440                 string s = lt.Value;
441                 if (s != "alias") {
442                         syntax_error (lt.Location, "`alias' expected");
443                 } else {
444                         if (lang_version == LanguageVersion.ISO_1)
445                                 FeatureIsNotAvailable (lt.Location, "external alias");
446
447                         lt = (LocatedToken) $3;
448                         if (lt.Value == QualifiedAliasMember.GlobalAlias) {
449                                 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
450                         }
451                         
452                         var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
453                         current_namespace.AddUsing (na);
454                         
455                         lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
456                 }
457           }
458         | EXTERN_ALIAS error
459           {
460                 Error_SyntaxError (yyToken);
461           }
462         ;
463  
464 using_directives
465         : using_directive 
466         | using_directives using_directive
467         ;
468
469 using_directive
470         : using_namespace
471           {
472                 if (doc_support)
473                         Lexer.doc_state = XmlCommentState.Allowed;
474           }
475         ;
476
477 using_namespace
478         : USING opt_static namespace_or_type_expr SEMICOLON
479           {
480                 UsingClause uc;
481                 if ($2 != null) {
482                         if (lang_version <= LanguageVersion.V_5)
483                                 FeatureIsNotAvailable (GetLocation ($2), "using static");
484
485                         uc = new UsingType ((ATypeNameExpression) $3, GetLocation ($1));
486                         lbag.AddLocation (uc, GetLocation ($2), GetLocation ($4));
487                 } else {
488                         uc = new UsingNamespace ((ATypeNameExpression) $3, GetLocation ($1));
489                         lbag.AddLocation (uc, GetLocation ($4));
490                 }
491
492                 current_namespace.AddUsing (uc);
493           }
494         | USING opt_static IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
495           {
496                 var lt = (LocatedToken) $3;
497                 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
498                         report.Warning (440, 2, lt.Location,
499                          "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
500                 }
501
502                 if ($2 != null) {
503                         report.Error (8085, GetLocation ($2), "A `using static' directive cannot be used to declare an alias");
504                 }
505
506                 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $5, GetLocation ($1));
507                 current_namespace.AddUsing (un);
508                 
509                 lbag.AddLocation (un, GetLocation ($4), GetLocation ($6));
510           }
511         | USING error
512          {
513                 Error_SyntaxError (yyToken);
514                 $$ = null;
515          }
516         ;
517
518 opt_static
519         :
520         | STATIC
521         ;
522
523 //
524 // Strictly speaking, namespaces don't have attributes but
525 // we parse global attributes along with namespace declarations and then
526 // detach them
527 // 
528 namespace_declaration
529         : opt_attributes NAMESPACE namespace_name
530           {
531                 Attributes attrs = (Attributes) $1;
532                 var name = (MemberName) $3;
533                 if (attrs != null) {
534                         bool valid_global_attrs = true;
535                         if ((current_namespace.DeclarationFound || current_namespace != file)) {
536                                 valid_global_attrs = false;
537                         } else {
538                                 foreach (var a in attrs.Attrs) {
539                                         if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
540                                                 continue;
541                                                 
542                                         valid_global_attrs = false;
543                                         break;
544                                 }
545                         }
546                         
547                         if (!valid_global_attrs)
548                                 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
549                 }
550         
551                 module.AddAttributes (attrs, current_namespace);
552                 
553                 var ns = new NamespaceContainer (name, current_namespace);
554                 current_namespace.AddTypeContainer (ns);
555                 current_container = current_namespace = ns;
556           }
557           OPEN_BRACE
558           {
559                 if (doc_support)
560                         Lexer.doc_state = XmlCommentState.Allowed;
561           }
562           opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
563           {
564                 if ($11 != null)
565                         lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
566                 else
567                         lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
568           
569                 current_container = current_namespace = current_namespace.Parent;
570           }
571         | opt_attributes NAMESPACE namespace_name
572           {
573                 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
574
575                 var name = (MemberName) $3;             
576                 var ns = new NamespaceContainer (name, current_namespace);
577                 lbag.AddLocation (ns, GetLocation ($2));
578                 current_namespace.AddTypeContainer (ns);
579           }
580         ;
581
582 opt_semicolon_error
583         : /* empty */
584         | SEMICOLON
585         | error
586           {
587                 Error_SyntaxError (yyToken);
588                 $$ = null;
589           }
590         ;
591
592 namespace_name
593         : IDENTIFIER
594           {
595                 var lt = (LocatedToken) $1;
596                 $$ = new MemberName (lt.Value, lt.Location);
597           }
598         | namespace_name DOT IDENTIFIER
599           {
600                 var lt = (LocatedToken) $3;
601                 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);           
602                 lbag.AddLocation ($$, GetLocation ($2));
603           }
604         | error
605           {
606                 Error_SyntaxError (yyToken);
607                 $$ = new MemberName ("<invalid>", lexer.Location);
608           }
609         ;
610
611 opt_semicolon
612         : /* empty */
613         | SEMICOLON
614         ;
615
616 opt_comma
617         : /* empty */
618         | COMMA
619         ;
620
621 opt_using_directives
622         : /* empty */
623         | using_directives
624         ;
625
626 opt_extern_alias_directives
627         : /* empty */
628         | extern_alias_directives
629         ;
630
631 opt_namespace_or_type_declarations
632         : /* empty */
633         | namespace_or_type_declarations
634         ;
635
636 namespace_or_type_declarations
637         : namespace_or_type_declaration
638         | namespace_or_type_declarations namespace_or_type_declaration
639         ;
640
641 namespace_or_type_declaration
642         : type_declaration
643           {
644                 if ($1 != null) {
645                         TypeContainer ds = (TypeContainer)$1;
646
647                         if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
648                                 report.Error (1527, ds.Location, 
649                                 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
650                         }
651
652                         // Here is a trick, for explicit attributes we don't know where they belong to until
653                         // we parse succeeding declaration hence we parse them as normal and re-attach them
654                         // when we know whether they are global (assembly:, module:) or local (type:).
655                         if (ds.OptAttributes != null) {
656                                 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
657                         }
658                 }
659                 current_namespace.DeclarationFound = true;
660           }
661         | namespace_declaration
662           {
663                 current_namespace.DeclarationFound = true;
664           }
665         | attribute_sections CLOSE_BRACE {
666                 current_namespace.UnattachedAttributes = (Attributes) $1;
667                 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
668                 lexer.putback ('}');
669           }
670         ;
671
672 type_declaration
673         : class_declaration             
674         | struct_declaration
675         | interface_declaration
676         | enum_declaration              
677         | delegate_declaration
678 //
679 // Enable this when we have handled all errors, because this acts as a generic fallback
680 //
681 //      | error {
682 //              Console.WriteLine ("Token=" + yyToken);
683 //              report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
684 //        }
685         ;
686
687 //
688 // Attributes
689 //
690
691 opt_attributes
692         : /* empty */ 
693         | attribute_sections
694     ;
695  
696 attribute_sections
697         : attribute_section
698           {
699                 var sect = (List<Attribute>) $1;
700                 $$ = new Attributes (sect);
701           }
702         | attribute_sections attribute_section
703           {
704                 Attributes attrs = $1 as Attributes;
705                 var sect = (List<Attribute>) $2;
706                 if (attrs == null)
707                         attrs = new Attributes (sect);
708                 else if (sect != null)
709                         attrs.AddAttributes (sect);
710                 $$ = attrs;
711           }
712         ;
713         
714 attribute_section
715         : OPEN_BRACKET
716           {
717                 PushLocation (GetLocation ($1));
718                 lexer.parsing_attribute_section = true;
719           }
720           attribute_section_cont
721           {
722                 lexer.parsing_attribute_section = false;
723                 $$ = $3;
724           }
725         ;       
726         
727 attribute_section_cont
728         : attribute_target COLON
729           {
730                 current_attr_target = (string) $1;
731                 if (current_attr_target == "assembly" || current_attr_target == "module") {
732                         Lexer.check_incorrect_doc_comment ();
733                 }
734           }
735           attribute_list opt_comma CLOSE_BRACKET
736           {
737                 // when attribute target is invalid
738                 if (current_attr_target == string.Empty)
739                         $$ = new List<Attribute> (0);
740                 else
741                         $$ = $4;
742
743                 lbag.InsertLocation ($$, 0, PopLocation ());
744                 if ($5 != null) {
745                         lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
746                 } else {
747                         lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
748                 }
749
750                 current_attr_target = null;
751                 lexer.parsing_attribute_section = false;
752           }
753         | attribute_list opt_comma CLOSE_BRACKET
754           {
755                 $$ = $1;
756
757                 lbag.InsertLocation ($$, 0, PopLocation ());
758                 if ($2 != null) {
759                         lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
760                 } else {
761                         lbag.AddLocation ($$, GetLocation($3));
762                 }
763           }
764         | IDENTIFIER error
765           {
766                 Error_SyntaxError (yyToken);
767
768                 var lt = (LocatedToken) $1;
769                 var tne = new SimpleName (lt.Value, null, lt.Location);
770
771                 $$ = new List<Attribute> () {
772                         new Attribute (null, tne, null, GetLocation ($1), false)
773                 };
774           }
775         | error
776           {
777                 if (CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1)).Length > 0)
778                         Error_SyntaxError (yyToken);
779
780                 $$ = null;
781           }
782         ;       
783
784 attribute_target
785         : IDENTIFIER
786           {
787                 var lt = (LocatedToken) $1;
788                 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
789           }
790         | EVENT  { $$ = "event"; }
791         | RETURN { $$ = "return"; }
792         ;
793
794 attribute_list
795         : attribute
796           {
797                 $$ = new List<Attribute> (4) { (Attribute) $1 };
798           }
799         | attribute_list COMMA attribute
800           {
801                 var attrs = (List<Attribute>) $1;
802                 if (attrs != null) {
803                         attrs.Add ((Attribute) $3);
804                         lbag.AppendTo (attrs, GetLocation ($2));
805                 }
806
807                 $$ = attrs;
808           }
809         ;
810
811 attribute
812         : attribute_name
813           {
814                 ++lexer.parsing_block;
815           }
816           opt_attribute_arguments
817           {
818                 --lexer.parsing_block;
819                 
820                 var tne = (ATypeNameExpression) $1;
821                 if (tne.HasTypeArguments) {
822                         report.Error (404, tne.Location, "Attributes cannot be generic");
823                 }
824
825                 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
826           }
827         ;
828
829 attribute_name
830         : namespace_or_type_expr
831         ;
832
833 opt_attribute_arguments
834         : /* empty */   { $$ = null; }
835         | OPEN_PARENS attribute_arguments CLOSE_PARENS
836           {
837                 $$ = $2;
838           }
839         ;
840
841
842 attribute_arguments
843         : /* empty */           { $$ = null; } 
844         | positional_or_named_argument
845           {
846                 Arguments a = new Arguments (4);
847                 a.Add ((Argument) $1);
848                 $$ = new Arguments [] { a, null };
849           }
850         | named_attribute_argument
851           {
852                 Arguments a = new Arguments (4);
853                 a.Add ((Argument) $1);  
854                 $$ = new Arguments [] { null, a };
855           }
856     | attribute_arguments COMMA positional_or_named_argument
857           {
858                 Arguments[] o = (Arguments[]) $1;
859                 if (o [1] != null) {
860                         report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
861                         o [0] = new Arguments (4);
862                 }
863                 
864                 Arguments args = ((Arguments) o [0]);
865                 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
866                         Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
867                 
868                 args.Add ((Argument) $3);
869           }
870     | attribute_arguments COMMA named_attribute_argument
871           {
872                 Arguments[] o = (Arguments[]) $1;
873                 if (o [1] == null) {
874                         o [1] = new Arguments (4);
875                 }
876
877                 ((Arguments) o [1]).Add ((Argument) $3);
878           }
879     ;
880
881 positional_or_named_argument
882         : expression
883           {
884                 $$ = new Argument ((Expression) $1);
885           }
886         | named_argument
887         | error
888           {
889                 Error_SyntaxError (yyToken);
890                 $$ = null;
891           }
892         ;
893
894 named_attribute_argument
895         : IDENTIFIER ASSIGN
896           {
897                 ++lexer.parsing_block;
898           }
899           expression
900           {
901                 --lexer.parsing_block;
902                 var lt = (LocatedToken) $1;
903                 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);          
904                 lbag.AddLocation ($$, GetLocation($2));
905           }
906         ;
907         
908 named_argument
909         : identifier_inside_body COLON opt_named_modifier named_argument_expr
910           {
911                 if (lang_version <= LanguageVersion.V_3)
912                         FeatureIsNotAvailable (GetLocation ($1), "named argument");
913                         
914                 // Avoid boxing in common case (no modifier)
915                 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
916                         
917                 var lt = (LocatedToken) $1;
918                 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
919                 lbag.AddLocation ($$, GetLocation($2));
920           }
921         ;
922
923 named_argument_expr
924         : expression_or_error
925 //      | declaration_expression
926         ;
927         
928 opt_named_modifier
929         : /* empty */   { $$ = null; }
930         | REF
931           { 
932                 $$ = Argument.AType.Ref;
933           }
934         | OUT
935           { 
936                 $$ = Argument.AType.Out;
937           }
938         ;
939                   
940 opt_class_member_declarations
941         : /* empty */
942         | class_member_declarations
943         ;
944
945 class_member_declarations
946         : class_member_declaration
947           {
948                 lexer.parsing_modifiers = true;
949                 lexer.parsing_block = 0;
950           }
951         | class_member_declarations class_member_declaration
952           {
953                 lexer.parsing_modifiers = true;
954                 lexer.parsing_block = 0;
955           }
956         ;
957         
958 class_member_declaration
959         : constant_declaration
960         | field_declaration
961         | method_declaration
962         | property_declaration
963         | event_declaration
964         | indexer_declaration
965         | operator_declaration
966         | constructor_declaration
967         | primary_constructor_body
968         | destructor_declaration
969         | type_declaration
970         | attributes_without_members
971         | incomplete_member
972         | error
973           {
974                 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
975                         GetSymbolName (yyToken));
976                 $$ = null;
977                 lexer.parsing_generic_declaration = false;
978           }     
979         ;
980
981 primary_constructor_body
982         : OPEN_BRACE
983           {
984                 current_local_parameters = current_type.PrimaryConstructorParameters;
985                 if (current_local_parameters == null) {
986                         report.Error (9010, GetLocation ($1), "Primary constructor body is not allowed");
987                         current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
988                 }
989
990                 ++lexer.parsing_block;
991                 start_block (GetLocation ($1));
992           }
993           opt_statement_list block_end
994           {
995                 current_local_parameters = null;
996                 var t = current_type as ClassOrStruct;
997                 if (t != null) {
998                         var b = (ToplevelBlock) $4;
999                         if (t.PrimaryConstructorBlock != null) {
1000                                 report.Error (8041, b.StartLocation, "Primary constructor already has a body");
1001                         } else {
1002                                 t.PrimaryConstructorBlock = b;
1003                         }
1004                 }
1005           }
1006         ;
1007
1008 struct_declaration
1009         : opt_attributes
1010           opt_modifiers
1011           opt_partial
1012           STRUCT
1013           {
1014           }
1015           type_declaration_name
1016           { 
1017                 lexer.ConstraintsParsing = true;
1018                 valid_param_mod = ParameterModifierType.PrimaryConstructor;
1019                 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1020           }
1021           opt_primary_parameters
1022           opt_class_base
1023           opt_type_parameter_constraints_clauses
1024           {
1025                 valid_param_mod = 0;
1026                 lexer.ConstraintsParsing = false;
1027
1028                 if ($8 != null)
1029                         current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
1030
1031                 if ($10 != null)
1032                         current_container.SetConstraints ((List<Constraints>) $10);
1033
1034                 if (doc_support)
1035                         current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1036
1037                 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1038                 
1039                 lexer.parsing_modifiers = true;
1040           }
1041           OPEN_BRACE
1042           {
1043                 if (doc_support)
1044                         Lexer.doc_state = XmlCommentState.Allowed;
1045           }
1046           opt_class_member_declarations CLOSE_BRACE
1047           {
1048                 --lexer.parsing_declaration;
1049                 if (doc_support)
1050                         Lexer.doc_state = XmlCommentState.Allowed;
1051           }
1052           opt_semicolon
1053           {
1054                 if ($16 == null) {
1055                         lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
1056                 } else {
1057                         lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
1058                 }
1059                 $$ = pop_current_class ();
1060           }
1061         | opt_attributes opt_modifiers opt_partial STRUCT error
1062           {
1063                 Error_SyntaxError (yyToken);
1064           }
1065         ;
1066         
1067 constant_declaration
1068         : opt_attributes 
1069           opt_modifiers
1070           CONST type IDENTIFIER
1071           {
1072                 var lt = (LocatedToken) $5;
1073                 var mod = (Modifiers) $2;
1074                 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1075                 current_type.AddMember (current_field);
1076                 
1077                 if ((mod & Modifiers.STATIC) != 0) {
1078                         report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1079                 }
1080                 
1081                 $$ = current_field;
1082           }
1083           constant_initializer opt_constant_declarators SEMICOLON
1084           {
1085                 if (doc_support) {
1086                         current_field.DocComment = Lexer.consume_doc_comment ();
1087                         Lexer.doc_state = XmlCommentState.Allowed;
1088                 }
1089                 
1090                 current_field.Initializer = (ConstInitializer) $7;
1091                 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1092                 current_field = null;
1093           }
1094         | opt_attributes 
1095           opt_modifiers
1096           CONST type error
1097           {
1098                 Error_SyntaxError (yyToken);
1099
1100                 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1101           }     
1102         ;
1103         
1104 opt_constant_declarators
1105         : /* empty */
1106         | constant_declarators
1107         ;
1108         
1109 constant_declarators
1110         : constant_declarator
1111           {
1112                 current_field.AddDeclarator ((FieldDeclarator) $1);
1113           }
1114         | constant_declarators constant_declarator
1115           {
1116                 current_field.AddDeclarator ((FieldDeclarator) $2);
1117           }
1118         ;
1119         
1120 constant_declarator
1121         : COMMA IDENTIFIER constant_initializer
1122           {
1123                 var lt = (LocatedToken) $2;
1124                 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1125                 lbag.AddLocation ($$, GetLocation ($1));
1126           }
1127         ;               
1128
1129 constant_initializer
1130         : ASSIGN
1131           {
1132                 ++lexer.parsing_block;
1133           }
1134           constant_initializer_expr
1135           {
1136                 --lexer.parsing_block;
1137                 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1138           }
1139         | error
1140           {
1141                 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1142                 $$ = null;
1143           }       
1144         ;
1145         
1146 constant_initializer_expr
1147         : constant_expression
1148         | array_initializer
1149         ;
1150
1151 field_declaration
1152         : opt_attributes
1153           opt_modifiers
1154           member_type IDENTIFIER
1155           {
1156                 lexer.parsing_generic_declaration = false;
1157
1158                 FullNamedExpression type = (FullNamedExpression) $3;
1159                 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1160                         report.Error (670, GetLocation ($3), "Fields cannot have void type");
1161                         
1162                 var lt = (LocatedToken) $4;
1163                 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1164                 current_type.AddField (current_field);
1165                 $$ = current_field;
1166           }
1167           opt_field_initializer
1168           opt_field_declarators
1169           SEMICOLON
1170           { 
1171                 if (doc_support) {
1172                         current_field.DocComment = Lexer.consume_doc_comment ();
1173                         Lexer.doc_state = XmlCommentState.Allowed;
1174                 }
1175                         
1176                 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1177                 $$ = current_field;
1178                 current_field = null;
1179           }
1180         | opt_attributes
1181           opt_modifiers
1182           FIXED simple_type IDENTIFIER
1183           { 
1184                 if (lang_version < LanguageVersion.ISO_2)
1185                         FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1186
1187                 var lt = (LocatedToken) $5;
1188                 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1189                         new MemberName (lt.Value, lt.Location), (Attributes) $1);
1190                         
1191                 current_type.AddField (current_field);
1192           }
1193           fixed_field_size opt_fixed_field_declarators SEMICOLON
1194           {
1195                 if (doc_support) {
1196                         current_field.DocComment = Lexer.consume_doc_comment ();
1197                         Lexer.doc_state = XmlCommentState.Allowed;
1198             }
1199
1200                 current_field.Initializer = (ConstInitializer) $7;          
1201                 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1202                 $$ = current_field;
1203             current_field = null;
1204           }
1205         | opt_attributes
1206           opt_modifiers
1207           FIXED simple_type error
1208           SEMICOLON
1209           {
1210                 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1211           }
1212         ;
1213         
1214 opt_field_initializer
1215         : /* empty */
1216         | ASSIGN
1217           {
1218                 ++lexer.parsing_block;
1219                 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1220                 start_block (GetLocation ($1));
1221           }
1222           variable_initializer
1223           {
1224                 --lexer.parsing_block;
1225                 current_field.Initializer = (Expression) $3;
1226                 lbag.AppendToMember (current_field, GetLocation ($1));
1227                 end_block (lexer.Location);
1228                 current_local_parameters = null;
1229           }
1230         ;
1231         
1232 opt_field_declarators
1233         : /* empty */
1234         | field_declarators
1235         ;
1236         
1237 field_declarators
1238         : field_declarator
1239           {
1240                 current_field.AddDeclarator ((FieldDeclarator) $1);
1241           }
1242         | field_declarators field_declarator
1243           {
1244                 current_field.AddDeclarator ((FieldDeclarator) $2);
1245           }
1246         ;
1247         
1248 field_declarator
1249         : COMMA IDENTIFIER
1250           {
1251                 var lt = (LocatedToken) $2;
1252                 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1253                 lbag.AddLocation ($$, GetLocation ($1));
1254           }
1255         | COMMA IDENTIFIER ASSIGN
1256           {
1257                 ++lexer.parsing_block;
1258           }
1259           variable_initializer
1260           {
1261                 --lexer.parsing_block;
1262                 var lt = (LocatedToken) $2;       
1263                 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1264                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1265           }
1266         ;       
1267
1268 opt_fixed_field_declarators
1269         : /* empty */
1270         | fixed_field_declarators
1271         ;
1272         
1273 fixed_field_declarators
1274         : fixed_field_declarator
1275           {
1276                 current_field.AddDeclarator ((FieldDeclarator) $1);
1277           }
1278         | fixed_field_declarators fixed_field_declarator
1279           {
1280                 current_field.AddDeclarator ((FieldDeclarator) $2);
1281           }
1282         ;
1283         
1284 fixed_field_declarator
1285         : COMMA IDENTIFIER fixed_field_size
1286           {
1287                 var lt = (LocatedToken) $2;       
1288                 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1289                 lbag.AddLocation ($$, GetLocation ($1));
1290           }
1291         ;
1292
1293 fixed_field_size
1294         : OPEN_BRACKET
1295           {
1296                 ++lexer.parsing_block;
1297           }
1298           expression CLOSE_BRACKET
1299           {
1300                 --lexer.parsing_block;
1301                 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1302                 lbag.AddLocation ($$, GetLocation ($4));
1303           }
1304         | OPEN_BRACKET error
1305           {
1306                 report.Error (443, lexer.Location, "Value or constant expected");
1307                 $$ = null;
1308           }       
1309         ;
1310
1311 variable_initializer
1312         : expression
1313         | array_initializer
1314         | error
1315           {
1316                 // It has to be here for the parent to safely restore artificial block
1317                 Error_SyntaxError (yyToken);
1318                 $$ = null;
1319           }
1320         ;
1321
1322 method_declaration
1323         : method_header
1324           {
1325                 if (doc_support)
1326                         Lexer.doc_state = XmlCommentState.NotAllowed;
1327
1328                 // Was added earlier in the case of body being eof for full ast
1329           }
1330           method_body_expression_block
1331           {
1332                 Method method = (Method) $1;
1333                 method.Block = (ToplevelBlock) $3;
1334                 async_block = false;
1335                 
1336                 if (method.Block == null) {
1337                         method.ParameterInfo.CheckParameters (method);
1338
1339                         if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1340                                 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1341                                         method.GetSignatureForError ());
1342                         }
1343                 } else {
1344                         if (current_container.Kind == MemberKind.Interface) {
1345                                 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1346                                         method.GetSignatureForError ());
1347                         }
1348                 }
1349
1350                 current_local_parameters = null;
1351
1352                 if (doc_support)
1353                         Lexer.doc_state = XmlCommentState.Allowed;
1354           }
1355         ;
1356
1357 method_header
1358         : opt_attributes
1359           opt_modifiers
1360           member_type
1361           method_declaration_name OPEN_PARENS
1362           {
1363                 valid_param_mod = ParameterModifierType.All;
1364           }
1365           opt_formal_parameter_list CLOSE_PARENS
1366           {
1367                 valid_param_mod = 0;
1368                 MemberName name = (MemberName) $4;
1369                 current_local_parameters = (ParametersCompiled) $7;
1370
1371                 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1372                                      name, current_local_parameters, (Attributes) $1);
1373
1374                 current_type.AddMember (method);
1375
1376                 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1377
1378                 if (doc_support)
1379                         method.DocComment = Lexer.consume_doc_comment ();
1380
1381                 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1382
1383                 $$ = method;
1384
1385                 lexer.ConstraintsParsing = true;
1386           }
1387           opt_type_parameter_constraints_clauses
1388           {
1389                 lexer.ConstraintsParsing = false;
1390
1391                 if ($10 != null) {
1392                         var method = (Method) $9;
1393                         method.SetConstraints ((List<Constraints>) $10);
1394                 }
1395
1396                 $$ = $9;
1397           }
1398         | opt_attributes
1399           opt_modifiers
1400           PARTIAL
1401           VOID
1402           {
1403                 lexer.parsing_generic_declaration = true;
1404           }
1405           method_declaration_name
1406           OPEN_PARENS
1407           {
1408                 lexer.parsing_generic_declaration = false;
1409                 valid_param_mod = ParameterModifierType.All;
1410           }
1411           opt_formal_parameter_list CLOSE_PARENS 
1412           {
1413                 lexer.ConstraintsParsing = true;
1414           }
1415           opt_type_parameter_constraints_clauses
1416           {
1417                 lexer.ConstraintsParsing = false;
1418                 valid_param_mod = 0;
1419
1420                 MemberName name = (MemberName) $6;
1421                 current_local_parameters = (ParametersCompiled) $9;
1422
1423                 var modifiers = (Modifiers) $2;
1424                 modifiers |= Modifiers.PARTIAL;
1425
1426                 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1427                                      modifiers, name, current_local_parameters, (Attributes) $1);
1428
1429                 current_type.AddMember (method);
1430
1431                 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1432
1433                 if ($12 != null)
1434                         method.SetConstraints ((List<Constraints>) $12);
1435
1436                 if (doc_support)
1437                         method.DocComment = Lexer.consume_doc_comment ();
1438
1439                 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1440                 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1441                 $$ = method;
1442           }
1443         | opt_attributes
1444           opt_modifiers
1445           member_type
1446           modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1447           {
1448                 MemberName name = (MemberName) $5;
1449                 report.Error (1585, name.Location, 
1450                         "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1451
1452                 var method = Method.Create (current_type, (FullNamedExpression) $3,
1453                                             0, name, (ParametersCompiled) $7, (Attributes) $1);
1454
1455                 current_type.AddMember (method);
1456
1457                 current_local_parameters = (ParametersCompiled) $7;
1458
1459                 if (doc_support)
1460                         method.DocComment = Lexer.consume_doc_comment ();
1461
1462                 $$ = method;
1463           }
1464         | opt_attributes
1465           opt_modifiers
1466           member_type
1467           method_declaration_name error
1468           {
1469                 Error_SyntaxError (yyToken);
1470                 current_local_parameters = ParametersCompiled.Undefined;
1471
1472                 MemberName name = (MemberName) $4;
1473                 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1474                                                                         name, current_local_parameters, (Attributes) $1);
1475
1476                 current_type.AddMember (method);
1477
1478                 if (doc_support)
1479                         method.DocComment = Lexer.consume_doc_comment ();
1480
1481                 $$ = method;
1482           }
1483         ;
1484
1485 method_body_expression_block
1486         : method_body
1487         | expression_block
1488         ;
1489
1490 method_body
1491         : block
1492         | SEMICOLON             { $$ = null; }
1493         ;
1494
1495 expression_block
1496         : ARROW
1497          {
1498                 if (lang_version < LanguageVersion.V_6) {
1499                         FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1500                 }
1501
1502                 ++lexer.parsing_block;
1503                 start_block (GetLocation ($1));
1504          }
1505          expression SEMICOLON
1506          {
1507                 lexer.parsing_block = 0;
1508                 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1509                 var b = end_block (GetLocation ($4));
1510                 b.IsCompilerGenerated = true;
1511                 $$ = b;
1512          }
1513         ;
1514
1515 opt_formal_parameter_list
1516         : /* empty */                   { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1517         | formal_parameter_list
1518         ;
1519         
1520 formal_parameter_list
1521         : fixed_parameters
1522           {
1523                 var pars_list = (List<Parameter>) $1;
1524                 $$ = new ParametersCompiled (pars_list.ToArray ());
1525           } 
1526         | fixed_parameters COMMA parameter_array
1527           {
1528                 var pars_list = (List<Parameter>) $1;
1529                 pars_list.Add ((Parameter) $3);
1530
1531                 $$ = new ParametersCompiled (pars_list.ToArray ()); 
1532           }
1533         | fixed_parameters COMMA arglist_modifier
1534           {
1535                 var pars_list = (List<Parameter>) $1;
1536                 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1537                 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1538           }
1539         | parameter_array COMMA error
1540           {
1541                 if ($1 != null)
1542                         report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1543
1544                 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );                      
1545           }
1546         | fixed_parameters COMMA parameter_array COMMA error
1547           {
1548                 if ($3 != null)
1549                         report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1550
1551                 var pars_list = (List<Parameter>) $1;
1552                 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1553
1554                 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1555           }
1556         | arglist_modifier COMMA error
1557           {
1558                 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1559
1560                 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1561           }
1562         | fixed_parameters COMMA ARGLIST COMMA error 
1563           {
1564                 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1565
1566                 var pars_list = (List<Parameter>) $1;
1567                 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1568
1569                 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1570           }
1571         | parameter_array 
1572           {
1573                 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1574           }
1575         | arglist_modifier
1576           {
1577                 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1578           }
1579         | error
1580           {
1581                 Error_SyntaxError (yyToken);
1582                 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1583           }
1584         ;
1585
1586 fixed_parameters
1587         : fixed_parameter       
1588           {
1589                 parameters_bucket.Clear ();
1590                 Parameter p = (Parameter) $1;
1591                 parameters_bucket.Add (p);
1592                 
1593                 default_parameter_used = p.HasDefaultValue;
1594                 $$ = parameters_bucket;
1595           }
1596         | fixed_parameters COMMA fixed_parameter
1597           {
1598                 var pars = (List<Parameter>) $1;
1599                 Parameter p = (Parameter) $3;
1600                 if (p != null) {
1601                         if (p.HasExtensionMethodModifier)
1602                                 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1603                         else if (!p.HasDefaultValue && default_parameter_used)
1604                                 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1605
1606                         default_parameter_used |= p.HasDefaultValue;
1607                         pars.Add (p);
1608                         
1609                         lbag.AddLocation (p, GetLocation ($2));
1610                 }
1611                 
1612                 $$ = $1;
1613           }
1614         ;
1615
1616 fixed_parameter
1617         : opt_attributes
1618           opt_parameter_modifier
1619           parameter_type
1620           identifier_inside_body
1621           {
1622                 var lt = (LocatedToken) $4;
1623                 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1624           }
1625         | opt_attributes
1626           opt_parameter_modifier
1627           parameter_type
1628           identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1629           {
1630                 var lt = (LocatedToken) $4;
1631                 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1632                 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1633           }
1634         | attribute_sections error
1635           {
1636                 Error_SyntaxError (yyToken);
1637                 Location l = GetLocation ($2);
1638                 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1639           }
1640         | opt_attributes
1641           opt_parameter_modifier
1642           parameter_type
1643           error
1644           {
1645                 Error_SyntaxError (yyToken);
1646                 Location l = GetLocation ($4);
1647                 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1648           }
1649         | opt_attributes
1650           opt_parameter_modifier
1651           parameter_type
1652           identifier_inside_body
1653           ASSIGN
1654           {
1655                 ++lexer.parsing_block;
1656           }
1657           constant_expression
1658           {
1659                 --lexer.parsing_block;
1660                 if (lang_version <= LanguageVersion.V_3) {
1661                         FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1662                 }
1663                 
1664                 Parameter.Modifier mod = (Parameter.Modifier) $2;
1665                 if (mod != Parameter.Modifier.NONE) {
1666                         switch (mod) {
1667                         case Parameter.Modifier.REF:
1668                         case Parameter.Modifier.OUT:
1669                                 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1670                                         Parameter.GetModifierSignature (mod));
1671                                 break;
1672                                 
1673                         case Parameter.Modifier.This:
1674                                 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1675                                         Parameter.GetModifierSignature (mod));
1676                                 break;
1677                         default:
1678                                 throw new NotImplementedException (mod.ToString ());
1679                         }
1680                                 
1681                         mod = Parameter.Modifier.NONE;
1682                 }
1683                 
1684                 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1685                         report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1686                 
1687                 var lt = (LocatedToken) $4;
1688                 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1689                 lbag.AddLocation ($$, GetLocation ($5));
1690                 
1691                 if ($7 != null)
1692                         ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1693           }
1694         ;
1695
1696 opt_parameter_modifier
1697         : /* empty */           { $$ = Parameter.Modifier.NONE; }
1698         | parameter_modifiers
1699         ;
1700
1701 parameter_modifiers
1702         : parameter_modifier
1703           {
1704                 $$ = $1;
1705           }
1706         | parameter_modifiers parameter_modifier
1707           {
1708                 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1709                 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1710                 if (((Parameter.Modifier)$1 & p2) == p2) {
1711                         Error_DuplicateParameterModifier (lexer.Location, p2);
1712                 } else {
1713                         switch (mod & ~Parameter.Modifier.This) {
1714                                 case Parameter.Modifier.REF:
1715                                         report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1716                                         break;
1717                                 case Parameter.Modifier.OUT:
1718                                         report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1719                                         break;
1720                                 default:
1721                                         report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1722                                         break;
1723                         }
1724                 }
1725                 $$ = mod;
1726           }
1727         ;
1728
1729 parameter_modifier
1730         : REF
1731           {
1732                 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1733                         Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1734                         
1735                 $$ = Parameter.Modifier.REF;
1736           }
1737         | OUT
1738           {
1739                 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1740                         Error_ParameterModifierNotValid ("out", GetLocation ($1));
1741           
1742                 $$ = Parameter.Modifier.OUT;
1743           }
1744         | THIS
1745           {
1746                 if ((valid_param_mod & ParameterModifierType.This) == 0)
1747                         Error_ParameterModifierNotValid ("this", GetLocation ($1));
1748
1749                 if (lang_version <= LanguageVersion.ISO_2)
1750                         FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1751                                 
1752                 $$ = Parameter.Modifier.This;
1753           }
1754         ;
1755
1756 parameter_array
1757         : opt_attributes params_modifier type IDENTIFIER
1758           {
1759                 var lt = (LocatedToken) $4;
1760                 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1761           }
1762         | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1763           {
1764                 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1765                 
1766                 var lt = (LocatedToken) $4;
1767                 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);            
1768           }
1769         | opt_attributes params_modifier type error
1770           {
1771                 Error_SyntaxError (yyToken);
1772
1773                 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1774           }
1775         ;
1776         
1777 params_modifier
1778         : PARAMS
1779           {
1780                 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1781                         report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1782           }
1783         | PARAMS parameter_modifier
1784           {
1785                 Parameter.Modifier mod = (Parameter.Modifier)$2;
1786                 if ((mod & Parameter.Modifier.This) != 0) {
1787                         report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1788                 } else {
1789                         report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1790                 }         
1791           }
1792         | PARAMS params_modifier
1793           {
1794                 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1795           }
1796         ;
1797         
1798 arglist_modifier
1799         : ARGLIST
1800           {
1801                 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1802                         report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1803           }
1804         ;
1805
1806 property_declaration
1807         : opt_attributes
1808           opt_modifiers
1809           member_type
1810           member_declaration_name
1811           {
1812                 lexer.parsing_generic_declaration = false;
1813                 if (doc_support)
1814                         tmpComment = Lexer.consume_doc_comment ();
1815           }
1816           OPEN_BRACE
1817           {
1818                 var type = (FullNamedExpression) $3;
1819                 current_property = new Property (current_type, type, (Modifiers) $2,
1820                         (MemberName) $4, (Attributes) $1);
1821                         
1822                 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1823                         report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());                                     
1824                         
1825                 current_type.AddMember (current_property);
1826                 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1827                 
1828                 lexer.PropertyParsing = true;
1829           }
1830           accessor_declarations 
1831           {
1832                 lexer.PropertyParsing = false;
1833
1834                 if (doc_support)
1835                         current_property.DocComment = ConsumeStoredComment ();
1836           }
1837           CLOSE_BRACE
1838           {
1839                 lbag.AppendToMember (current_property, GetLocation ($10));
1840                 lexer.parsing_modifiers = true;
1841           }
1842           opt_property_initializer
1843           {
1844                 current_property = null;
1845           }
1846         | opt_attributes
1847           opt_modifiers
1848           member_type
1849           member_declaration_name
1850           {
1851                 lexer.parsing_generic_declaration = false;
1852                 if (doc_support)
1853                         tmpComment = Lexer.consume_doc_comment ();
1854                 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1855           }
1856           expression_block
1857           {
1858                 var type = (FullNamedExpression) $3;
1859                 var property = new Property (current_type, type, (Modifiers) $2,
1860                         (MemberName) $4, (Attributes) $1);
1861
1862                 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1863                 property.Get.Block = (ToplevelBlock) $6;
1864
1865                 if (current_container.Kind == MemberKind.Interface) {
1866                         report.Error (531, property.Get.Block.StartLocation,
1867                                 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1868                 }
1869
1870                 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1871                         report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1872
1873                 if (doc_support)
1874                         property.DocComment = ConsumeStoredComment ();
1875
1876                 current_type.AddMember (property);
1877
1878                 current_local_parameters = null;
1879           }
1880         ;
1881
1882 opt_property_initializer
1883         : /* empty */
1884         | ASSIGN
1885           {
1886                 ++lexer.parsing_block;
1887                 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1888                 start_block (GetLocation ($1));
1889           }
1890           property_initializer SEMICOLON
1891           {
1892                 --lexer.parsing_block;
1893                 ((Property)current_property).Initializer = (Expression) $3;
1894                 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1895                 end_block (GetLocation ($4));
1896                 current_local_parameters = null;
1897
1898                 if (doc_support)
1899                         Lexer.doc_state = XmlCommentState.Allowed;
1900           }
1901         ;
1902
1903 property_initializer
1904         : expression
1905         | array_initializer
1906         ;
1907
1908 indexer_declaration
1909         : opt_attributes opt_modifiers
1910           member_type indexer_declaration_name OPEN_BRACKET
1911           {
1912                 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1913           }
1914           opt_formal_parameter_list CLOSE_BRACKET 
1915           {
1916                 valid_param_mod = 0;
1917                 var type = (FullNamedExpression) $3;
1918                 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1919                         
1920                 current_property = indexer;
1921
1922                 current_type.AddIndexer (indexer);
1923                 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1924                 
1925                 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1926                         report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());           
1927
1928                 if (indexer.ParameterInfo.IsEmpty) {
1929                         report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1930                 }
1931
1932                 if (doc_support) {
1933                         tmpComment = Lexer.consume_doc_comment ();
1934                         Lexer.doc_state = XmlCommentState.Allowed;
1935                 }
1936
1937                 lexer.PropertyParsing = true;
1938                 current_local_parameters = (ParametersCompiled) $7;
1939           }
1940           indexer_body
1941           {
1942                 lexer.PropertyParsing = false;
1943                 current_local_parameters = null;
1944
1945                 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1946                         ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1947           
1948                 if (doc_support)
1949                         current_property.DocComment = ConsumeStoredComment ();
1950                         
1951                 current_property = null;                
1952           }
1953         ;
1954
1955 indexer_body
1956         : OPEN_BRACE accessor_declarations CLOSE_BRACE
1957           {
1958                 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1959           }
1960         | expression_block
1961           {
1962                 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1963                 current_property.Get.Block = (ToplevelBlock) $1;
1964           }
1965         ;
1966
1967 accessor_declarations
1968         : get_accessor_declaration
1969         | get_accessor_declaration accessor_declarations
1970         | set_accessor_declaration
1971         | set_accessor_declaration accessor_declarations
1972         | error
1973           {
1974                 if (yyToken == Token.CLOSE_BRACE) {
1975                         report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1976                 } else {
1977                         if (yyToken == Token.SEMICOLON)
1978                                 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1979                         else
1980                                 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1981                 }
1982           }
1983         ;
1984
1985 get_accessor_declaration
1986         : opt_attributes opt_modifiers GET
1987           {
1988                 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1989                         FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1990                 }
1991           
1992                 if (current_property.Get != null) {
1993                         report.Error (1007, GetLocation ($3), "Property accessor already defined");
1994                 }
1995                 
1996                 if (current_property is Indexer) {
1997                         current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1998                                 (Attributes) $1, GetLocation ($3));
1999                 } else {
2000                         current_property.Get = new Property.GetMethod (current_property,
2001                                 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
2002                 }       
2003           
2004                 current_local_parameters = current_property.Get.ParameterInfo;    
2005                 lbag.AddMember (current_property.Get, mod_locations);
2006                 lexer.PropertyParsing = false;
2007           }
2008           accessor_body
2009           {
2010                 if ($5 != null) {
2011                         current_property.Get.Block = (ToplevelBlock) $5;                        
2012                 
2013                         if (current_container.Kind == MemberKind.Interface) {
2014                                 report.Error (531, current_property.Get.Block.StartLocation,
2015                                         "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
2016                         }               
2017                 }
2018           
2019                 current_local_parameters = null;
2020                 lexer.PropertyParsing = true;
2021
2022                 if (doc_support)
2023                         if (Lexer.doc_state == XmlCommentState.Error)
2024                                 Lexer.doc_state = XmlCommentState.NotAllowed;
2025           }
2026         ;
2027
2028 set_accessor_declaration
2029         : opt_attributes opt_modifiers SET 
2030           {
2031                 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2032                         FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2033                 }
2034                 
2035                 if (current_property.Set != null) {
2036                         report.Error (1007, GetLocation ($3), "Property accessor already defined");
2037                 }
2038           
2039                 if (current_property is Indexer) {
2040                         current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2041                                 ParametersCompiled.MergeGenerated (compiler,
2042                                 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2043                                         current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2044                                         null),
2045                                 (Attributes) $1, GetLocation ($3));
2046                 } else {
2047                         current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2, 
2048                                 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2049                                 (Attributes) $1, GetLocation ($3));
2050                 }
2051                 
2052                 current_local_parameters = current_property.Set.ParameterInfo;  
2053                 lbag.AddMember (current_property.Set, mod_locations);
2054                 lexer.PropertyParsing = false;
2055           }
2056           accessor_body
2057           {
2058                 if ($5 != null) {               
2059                         current_property.Set.Block = (ToplevelBlock) $5;
2060                 
2061                         if (current_container.Kind == MemberKind.Interface) {
2062                                 report.Error (531, current_property.Set.Block.StartLocation,
2063                                         "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2064                         }
2065                 }
2066                 
2067                 current_local_parameters = null;
2068                 lexer.PropertyParsing = true;
2069
2070                 if (doc_support
2071                         && Lexer.doc_state == XmlCommentState.Error)
2072                         Lexer.doc_state = XmlCommentState.NotAllowed;
2073           }
2074         ;
2075
2076 accessor_body
2077         : block
2078         | expression_block
2079         | SEMICOLON
2080           {
2081                 // TODO: lbag
2082                 $$ = null;
2083           }
2084         | error
2085           {
2086                 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2087                 $$ = null;
2088           }
2089         ;
2090
2091
2092 interface_declaration
2093         : opt_attributes
2094           opt_modifiers
2095           opt_partial
2096           INTERFACE
2097           {
2098           }
2099           type_declaration_name
2100           {
2101                 lexer.ConstraintsParsing = true;
2102                 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2103                 lbag.AddMember (current_container, mod_locations, GetLocation ($4));            
2104           }
2105           opt_class_base
2106           opt_type_parameter_constraints_clauses
2107           {
2108                 lexer.ConstraintsParsing = false;
2109
2110                 if ($9 != null)
2111                         current_container.SetConstraints ((List<Constraints>) $9);
2112
2113                 if (doc_support) {
2114                         current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2115                         Lexer.doc_state = XmlCommentState.Allowed;
2116                 }
2117                 
2118                 lexer.parsing_modifiers = true;
2119           }
2120           OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2121           {
2122                 --lexer.parsing_declaration;      
2123                 if (doc_support)
2124                         Lexer.doc_state = XmlCommentState.Allowed;
2125           }
2126           opt_semicolon 
2127           {
2128                 if ($15 == null) {
2129                         lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2130                 } else {
2131                         lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2132                 }
2133                 $$ = pop_current_class ();
2134           }
2135         | opt_attributes opt_modifiers opt_partial INTERFACE error
2136           {
2137                 Error_SyntaxError (yyToken);      
2138           }
2139         ;
2140
2141 opt_interface_member_declarations
2142         : /* empty */
2143         | interface_member_declarations
2144         ;
2145
2146 interface_member_declarations
2147         : interface_member_declaration
2148           {
2149                 lexer.parsing_modifiers = true;
2150                 lexer.parsing_block = 0;
2151           }
2152         | interface_member_declarations interface_member_declaration
2153           {
2154                 lexer.parsing_modifiers = true;
2155                 lexer.parsing_block = 0;
2156           }
2157         ;
2158
2159 interface_member_declaration
2160         : constant_declaration
2161           {
2162                 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2163           }
2164         | field_declaration
2165           {
2166                 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2167           }
2168         | method_declaration
2169         | property_declaration
2170         | event_declaration
2171         | indexer_declaration
2172         | operator_declaration
2173           {
2174                 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2175           }
2176         | constructor_declaration
2177           {
2178                 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2179           }
2180         | type_declaration
2181           {
2182                 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2183           }
2184         ;
2185
2186 operator_declaration
2187         : opt_attributes opt_modifiers operator_declarator 
2188           {
2189           }
2190           method_body_expression_block
2191           {
2192                 OperatorDeclaration decl = (OperatorDeclaration) $3;
2193                 if (decl != null) {
2194                         Operator op = new Operator (
2195                                 current_type, decl.optype, decl.ret_type, (Modifiers) $2, 
2196                                 current_local_parameters,
2197                                 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2198                                 
2199                         if (op.Block == null)
2200                                 op.ParameterInfo.CheckParameters (op);
2201
2202                         if (doc_support) {
2203                                 op.DocComment = tmpComment;
2204                                 Lexer.doc_state = XmlCommentState.Allowed;
2205                         }
2206
2207                         // Note again, checking is done in semantic analysis
2208                         current_type.AddOperator (op);
2209
2210                         lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2211                 }
2212                 
2213                 current_local_parameters = null;
2214           }
2215         ;
2216
2217 operator_type
2218         : type_expression_or_array
2219         | VOID
2220           {
2221                 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2222                 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2223           }
2224         ;
2225
2226 operator_declarator
2227         : operator_type OPERATOR overloadable_operator OPEN_PARENS
2228           {
2229                 valid_param_mod = ParameterModifierType.DefaultValue;
2230                 if ((Operator.OpType) $3 == Operator.OpType.Is)
2231                         valid_param_mod |= ParameterModifierType.Out;
2232           }
2233           opt_formal_parameter_list CLOSE_PARENS
2234           {
2235                 valid_param_mod = 0;
2236
2237                 Location loc = GetLocation ($2);
2238                 Operator.OpType op = (Operator.OpType) $3;
2239                 current_local_parameters = (ParametersCompiled)$6;
2240                 
2241                 int p_count = current_local_parameters.Count;
2242                 if (p_count == 1) {
2243                         if (op == Operator.OpType.Addition)
2244                                 op = Operator.OpType.UnaryPlus;
2245                         else if (op == Operator.OpType.Subtraction)
2246                                 op = Operator.OpType.UnaryNegation;
2247                 }
2248                 
2249                 if (IsUnaryOperator (op)) {
2250                         if (p_count == 2) {
2251                                 report.Error (1020, loc, "Overloadable binary operator expected");
2252                         } else if (p_count != 1) {
2253                                 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2254                                         Operator.GetName (op));
2255                         }
2256                 } else if (op == Operator.OpType.Is) {
2257                         // TODO: Special checks for is operator
2258                 } else {
2259                         if (p_count == 1) {
2260                                 report.Error (1019, loc, "Overloadable unary operator expected");
2261                         } else if (p_count != 2) {
2262                                 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2263                                         Operator.GetName (op));
2264                         }
2265                 }
2266                 
2267                 if (doc_support) {
2268                         tmpComment = Lexer.consume_doc_comment ();
2269                         Lexer.doc_state = XmlCommentState.NotAllowed;
2270                 }
2271
2272                 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2273                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2274           }
2275         | conversion_operator_declarator
2276         ;
2277
2278 overloadable_operator
2279 // Unary operators:
2280         : BANG   { $$ = Operator.OpType.LogicalNot; }
2281         | TILDE  { $$ = Operator.OpType.OnesComplement; }  
2282         | OP_INC { $$ = Operator.OpType.Increment; }
2283         | OP_DEC { $$ = Operator.OpType.Decrement; }
2284         | TRUE   { $$ = Operator.OpType.True; }
2285         | FALSE  { $$ = Operator.OpType.False; }
2286 // Unary and binary:
2287         | PLUS { $$ = Operator.OpType.Addition; }
2288         | MINUS { $$ = Operator.OpType.Subtraction; }
2289 // Binary:
2290         | STAR { $$ = Operator.OpType.Multiply; }
2291         | DIV {  $$ = Operator.OpType.Division; }
2292         | PERCENT { $$ = Operator.OpType.Modulus; }
2293         | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2294         | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2295         | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2296         | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2297         | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2298         | OP_EQ { $$ = Operator.OpType.Equality; }
2299         | OP_NE { $$ = Operator.OpType.Inequality; }
2300         | OP_GT { $$ = Operator.OpType.GreaterThan; }
2301         | OP_LT { $$ = Operator.OpType.LessThan; }
2302         | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2303         | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2304         | IS
2305           {
2306                 if (lang_version != LanguageVersion.Experimental)
2307                         FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2308
2309                 $$ = Operator.OpType.Is;
2310           }
2311         ;
2312
2313 conversion_operator_declarator
2314         : IMPLICIT OPERATOR type OPEN_PARENS
2315           {
2316                 valid_param_mod = ParameterModifierType.DefaultValue;
2317           }
2318           opt_formal_parameter_list CLOSE_PARENS
2319           {
2320                 valid_param_mod = 0;
2321
2322                 Location loc = GetLocation ($2);
2323                 current_local_parameters = (ParametersCompiled)$6;  
2324
2325                 if (current_local_parameters.Count != 1) {
2326                         report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2327                 }
2328
2329                 if (doc_support) {
2330                         tmpComment = Lexer.consume_doc_comment ();
2331                         Lexer.doc_state = XmlCommentState.NotAllowed;
2332                 }
2333
2334                 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2335                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2336           }
2337         | EXPLICIT OPERATOR type OPEN_PARENS
2338           {
2339                 valid_param_mod = ParameterModifierType.DefaultValue;
2340           }
2341           opt_formal_parameter_list CLOSE_PARENS
2342           {
2343                 valid_param_mod = 0;
2344                 
2345                 Location loc = GetLocation ($2);
2346                 current_local_parameters = (ParametersCompiled)$6;  
2347
2348                 if (current_local_parameters.Count != 1) {
2349                         report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2350                 }
2351
2352                 if (doc_support) {
2353                         tmpComment = Lexer.consume_doc_comment ();
2354                         Lexer.doc_state = XmlCommentState.NotAllowed;
2355                 }
2356
2357                 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2358                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2359           }
2360         | IMPLICIT error 
2361           {
2362                 Error_SyntaxError (yyToken);
2363                 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2364                 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2365           }
2366         | EXPLICIT error 
2367           {
2368                 Error_SyntaxError (yyToken);
2369                 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2370                 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2371           }
2372         ;
2373
2374 constructor_declaration
2375         : constructor_declarator
2376           constructor_body
2377           { 
2378                 Constructor c = (Constructor) $1;
2379                 c.Block = (ToplevelBlock) $2;
2380                 
2381                 if (doc_support)
2382                         c.DocComment = ConsumeStoredComment ();
2383
2384                 current_local_parameters = null;
2385                 if (doc_support)
2386                         Lexer.doc_state = XmlCommentState.Allowed;
2387           }
2388         ;
2389
2390 constructor_declarator
2391         : opt_attributes
2392           opt_modifiers
2393           IDENTIFIER
2394           {
2395                 if (doc_support) {
2396                         tmpComment = Lexer.consume_doc_comment ();
2397                         Lexer.doc_state = XmlCommentState.Allowed;
2398                 }
2399                 
2400                 valid_param_mod = ParameterModifierType.All;
2401           }
2402           OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2403           {
2404                 valid_param_mod = 0;
2405                 current_local_parameters = (ParametersCompiled) $6;
2406                 
2407                 var lt = (LocatedToken) $3;
2408                 var mods = (Modifiers) $2;
2409                 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2410
2411                 if (lt.Value != current_container.MemberName.Name) {
2412                         report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2413                 } else if ((mods & Modifiers.STATIC) != 0) {
2414                         if (!current_local_parameters.IsEmpty) {
2415                                 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2416                                         c.GetSignatureForError ());
2417                         }
2418
2419                         if ((mods & Modifiers.AccessibilityMask) != 0){
2420                                 report.Error (515, c.Location,
2421                                         "`{0}': static constructor cannot have an access modifier",
2422                                         c.GetSignatureForError ());
2423                         }
2424                 } else {
2425                         if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2426                                 report.Error (568, c.Location, "Structs cannot contain explicit parameterless constructors");
2427                         }
2428                 }
2429
2430                 current_type.AddConstructor (c);
2431                 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2432                 $$ = c;
2433
2434                 //
2435                 // start block here, so possible anonymous methods inside
2436                 // constructor initializer can get correct parent block
2437                 //
2438                 start_block (lexer.Location);
2439           }
2440           opt_constructor_initializer
2441           {
2442                 if ($9 != null) {
2443                         var c = (Constructor) $8;
2444                         c.Initializer = (ConstructorInitializer) $9;
2445                         
2446                         if (c.IsStatic) {
2447                                 report.Error (514, c.Location,
2448                                         "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2449                                         c.GetSignatureForError ());
2450                         }
2451                 }
2452
2453                 $$ = $8;
2454           }
2455         ;
2456
2457 constructor_body
2458         : block_prepared
2459         | SEMICOLON             { current_block = null; $$ = null; }
2460         ;
2461
2462 opt_constructor_initializer
2463         : /* Empty */
2464         | constructor_initializer
2465         ;
2466
2467 constructor_initializer
2468         : COLON BASE OPEN_PARENS
2469           {
2470                 ++lexer.parsing_block;
2471           }
2472           opt_argument_list CLOSE_PARENS
2473           {
2474                 --lexer.parsing_block;
2475                 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2476                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2477           }
2478         | COLON THIS OPEN_PARENS
2479           {
2480                 ++lexer.parsing_block;
2481           }
2482           opt_argument_list CLOSE_PARENS
2483           {
2484                 --lexer.parsing_block;
2485                 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2486                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2487           }
2488         | COLON error
2489           {
2490                 Error_SyntaxError (yyToken);      
2491                 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2492                 lbag.AddLocation ($$, GetLocation ($1));
2493           }
2494         | error
2495           {
2496                 Error_SyntaxError (yyToken);
2497                 $$ = null;
2498           }
2499         ;
2500
2501 destructor_declaration
2502         : opt_attributes opt_modifiers TILDE 
2503           {
2504                 if (doc_support) {
2505                         tmpComment = Lexer.consume_doc_comment ();
2506                         Lexer.doc_state = XmlCommentState.NotAllowed;
2507                 }
2508                 
2509                 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2510           }
2511           IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2512           {
2513                 var lt = (LocatedToken) $5;
2514                 if (lt.Value != current_container.MemberName.Name){
2515                         report.Error (574, lt.Location, "Name of destructor must match name of class");
2516                 } else if (current_container.Kind != MemberKind.Class){
2517                         report.Error (575, lt.Location, "Only class types can contain destructor");
2518                 }
2519                 
2520                 Destructor d = new Destructor (current_type, (Modifiers) $2,
2521                         ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2522                 if (doc_support)
2523                         d.DocComment = ConsumeStoredComment ();
2524                   
2525                 d.Block = (ToplevelBlock) $8;
2526                 current_type.AddMember (d);
2527                 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2528
2529                 current_local_parameters = null;
2530           }
2531         ;
2532
2533 event_declaration
2534         : opt_attributes
2535           opt_modifiers
2536           EVENT type member_declaration_name
2537           {
2538                 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2539                 current_type.AddMember (current_event_field);
2540                 
2541                 if (current_event_field.MemberName.ExplicitInterface != null) {
2542                         report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2543                         current_event_field.GetSignatureForError ());
2544                 }
2545                 
2546                 $$ = current_event_field;
2547           }
2548           opt_event_initializer
2549           opt_event_declarators
2550           SEMICOLON
2551           {
2552                 if (doc_support) {
2553                         current_event_field.DocComment = Lexer.consume_doc_comment ();
2554                         Lexer.doc_state = XmlCommentState.Allowed;
2555                 }
2556                 
2557                 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2558                 current_event_field = null;
2559           }
2560         | opt_attributes
2561           opt_modifiers
2562           EVENT type member_declaration_name
2563           OPEN_BRACE
2564           {
2565                 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2566                 current_type.AddMember (current_event);
2567                 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2568                 
2569                 lexer.EventParsing = true;
2570           }
2571           event_accessor_declarations
2572           {
2573                 if (current_container.Kind == MemberKind.Interface)
2574                         report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2575           
2576                 lexer.EventParsing = false;
2577           }
2578           CLOSE_BRACE
2579           {
2580                 if (doc_support) {
2581                         current_event.DocComment = Lexer.consume_doc_comment ();
2582                         Lexer.doc_state = XmlCommentState.Allowed;
2583                 }
2584                 
2585                 lbag.AppendToMember (current_event, GetLocation ($9));
2586                 current_event = null;   
2587                 current_local_parameters = null;
2588           }
2589         | opt_attributes
2590           opt_modifiers
2591           EVENT type error
2592           {
2593                 Error_SyntaxError (yyToken);
2594
2595                 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2596           }
2597         ;
2598         
2599 opt_event_initializer
2600         : /* empty */
2601         | ASSIGN
2602           {
2603                 ++lexer.parsing_block;
2604           }
2605           event_variable_initializer
2606           {
2607                 --lexer.parsing_block;
2608                 current_event_field.Initializer = (Expression) $3;
2609           }
2610         ;
2611         
2612 opt_event_declarators
2613         : /* empty */
2614         | event_declarators
2615         ;
2616         
2617 event_declarators
2618         : event_declarator
2619           {
2620                 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2621           }
2622         | event_declarators event_declarator
2623           {
2624                 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2625           }
2626         ;
2627         
2628 event_declarator
2629         : COMMA IDENTIFIER
2630           {
2631                 var lt = (LocatedToken) $2;
2632                 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2633                 lbag.AddLocation ($$, GetLocation ($1));
2634           }
2635         | COMMA IDENTIFIER ASSIGN
2636           {
2637                 ++lexer.parsing_block;
2638           }
2639           event_variable_initializer
2640           {
2641                 --lexer.parsing_block;
2642                 var lt = (LocatedToken) $2;       
2643                 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2644                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2645           }
2646         ;
2647         
2648 event_variable_initializer
2649         : {
2650                 if (current_container.Kind == MemberKind.Interface) {
2651                         report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2652                                 current_event_field.GetSignatureForError ());
2653                 }
2654                 
2655                 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2656                         report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2657                                 current_event_field.GetSignatureForError ());
2658                 }               
2659           }
2660           variable_initializer
2661           {
2662                 $$ = $2;
2663           }
2664         ;
2665         
2666 event_accessor_declarations
2667         : add_accessor_declaration remove_accessor_declaration
2668         | remove_accessor_declaration add_accessor_declaration
2669         | add_accessor_declaration
2670           {
2671                 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2672                         current_event.GetSignatureForError ());
2673           } 
2674         | remove_accessor_declaration
2675           {
2676                 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2677                         current_event.GetSignatureForError ());
2678           }     
2679         | error
2680           { 
2681                 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2682                 $$ = null;
2683           }
2684         ;
2685
2686 add_accessor_declaration
2687         : opt_attributes opt_modifiers ADD
2688           {
2689                 if ($2 != ModifierNone) {
2690                         report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2691                 }
2692                 
2693                 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2694                 current_local_parameters = current_event.Add.ParameterInfo;
2695                 
2696                 lbag.AddMember (current_event.Add, mod_locations);
2697                 lexer.EventParsing = false;             
2698           }
2699           event_accessor_block
2700           {
2701                 lexer.EventParsing = true;
2702           
2703                 current_event.Add.Block = (ToplevelBlock) $5;
2704                 
2705                 if (current_container.Kind == MemberKind.Interface) {
2706                         report.Error (531, current_event.Add.Block.StartLocation,
2707                                 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2708                 }
2709                 
2710                 current_local_parameters = null;
2711           }
2712         ;
2713         
2714 remove_accessor_declaration
2715         : opt_attributes opt_modifiers REMOVE
2716           {
2717                 if ($2 != ModifierNone) {
2718                         report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2719                 }
2720                 
2721                 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2722                 current_local_parameters = current_event.Remove.ParameterInfo;
2723
2724                 lbag.AddMember (current_event.Remove, mod_locations);
2725                 lexer.EventParsing = false;             
2726           }
2727           event_accessor_block
2728           {
2729                 lexer.EventParsing = true;
2730           
2731                 current_event.Remove.Block = (ToplevelBlock) $5;
2732                 
2733                 if (current_container.Kind == MemberKind.Interface) {
2734                         report.Error (531, current_event.Remove.Block.StartLocation,
2735                                 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2736                 }
2737                 
2738                 current_local_parameters = null;
2739           }
2740         ;
2741
2742 event_accessor_block
2743         : opt_semicolon
2744           {
2745                 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2746                 $$ = null;
2747           }
2748         | block
2749         | expression_block
2750         ;
2751
2752 attributes_without_members
2753         : attribute_sections CLOSE_BRACE
2754           {
2755                 current_type.UnattachedAttributes = (Attributes) $1;
2756                 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2757                 lexer.putback ('}');
2758           }
2759         ;
2760
2761 // For full ast try to recover incomplete ambiguous member
2762 // declaration in form on class X { public int }
2763 incomplete_member
2764         : opt_attributes opt_modifiers member_type CLOSE_BRACE
2765           {
2766                 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2767  
2768                 lexer.putback ('}');
2769
2770                 lexer.parsing_generic_declaration = false;
2771                 FullNamedExpression type = (FullNamedExpression) $3;
2772                 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2773                 current_type.AddField (current_field);
2774                 $$ = current_field;
2775           }
2776         ;
2777           
2778 enum_declaration
2779         : opt_attributes
2780           opt_modifiers
2781           ENUM type_declaration_name
2782           opt_enum_base
2783           {
2784                 if (doc_support)
2785                         enumTypeComment = Lexer.consume_doc_comment ();
2786           }
2787           OPEN_BRACE
2788           {
2789                 if (doc_support)
2790                         Lexer.doc_state = XmlCommentState.Allowed;
2791
2792                 MemberName name = (MemberName) $4;
2793                 if (name.IsGeneric) {
2794                         report.Error (1675, name.Location, "Enums cannot have type parameters");
2795                 }
2796                 
2797                 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2798           }
2799           opt_enum_member_declarations
2800           {
2801                 lexer.parsing_modifiers = true;
2802           
2803                 // here will be evaluated after CLOSE_BLACE is consumed.
2804                 if (doc_support)
2805                         Lexer.doc_state = XmlCommentState.Allowed;
2806           }
2807           CLOSE_BRACE opt_semicolon
2808           {
2809                 if (doc_support)
2810                         current_container.DocComment = enumTypeComment;
2811                         
2812                 --lexer.parsing_declaration;
2813
2814 //                      if (doc_support)
2815 //                              em.DocComment = ev.DocComment;
2816
2817                 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2818                 $$ = pop_current_class ();
2819           }
2820         ;
2821
2822 opt_enum_base
2823         : /* empty */
2824         | COLON type
2825          {
2826                 $$ = $2;
2827          }
2828         | COLON error
2829          {
2830                 Error_TypeExpected (GetLocation ($1));
2831                 $$ = null;
2832          }
2833         ;
2834
2835 opt_enum_member_declarations
2836         : /* empty */
2837         | enum_member_declarations
2838         | enum_member_declarations COMMA
2839           {
2840                 lbag.AddLocation ($1, GetLocation ($2));
2841           }
2842         ;
2843
2844 enum_member_declarations
2845         : enum_member_declaration
2846         | enum_member_declarations COMMA enum_member_declaration
2847           {
2848                 lbag.AddLocation ($1, GetLocation ($2));
2849                 $$ = $3;
2850           }
2851         ;
2852
2853 enum_member_declaration
2854         : opt_attributes IDENTIFIER
2855           {
2856                 var lt = (LocatedToken) $2;
2857                 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2858                 ((Enum) current_type).AddEnumMember (em);
2859
2860                 if (doc_support) {
2861                         em.DocComment = Lexer.consume_doc_comment ();
2862                         Lexer.doc_state = XmlCommentState.Allowed;
2863                 }
2864
2865                 $$ = em;
2866           }
2867         | opt_attributes IDENTIFIER
2868           {
2869                 ++lexer.parsing_block;
2870                 if (doc_support) {
2871                         tmpComment = Lexer.consume_doc_comment ();
2872                         Lexer.doc_state = XmlCommentState.NotAllowed;
2873                 }
2874           }
2875           ASSIGN constant_expression
2876           { 
2877                 --lexer.parsing_block;
2878                 
2879                 var lt = (LocatedToken) $2;
2880                 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2881                 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2882                 ((Enum) current_type).AddEnumMember (em);
2883                 
2884                 if (doc_support)
2885                         em.DocComment = ConsumeStoredComment ();
2886
2887                 $$ = em;
2888           }
2889         | opt_attributes IDENTIFIER error
2890           {
2891                 Error_SyntaxError (yyToken);
2892           
2893                 var lt = (LocatedToken) $2;
2894                 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2895                 ((Enum) current_type).AddEnumMember (em);
2896
2897                 if (doc_support) {
2898                         em.DocComment = Lexer.consume_doc_comment ();
2899                         Lexer.doc_state = XmlCommentState.Allowed;
2900                 }
2901
2902                 $$ = em;
2903           }
2904         | attributes_without_members
2905         ;
2906
2907 delegate_declaration
2908         : opt_attributes
2909           opt_modifiers
2910           DELEGATE
2911           member_type type_declaration_name
2912           OPEN_PARENS
2913           {
2914                 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2915           }
2916           opt_formal_parameter_list CLOSE_PARENS
2917           {
2918                 valid_param_mod = 0;
2919
2920                 ParametersCompiled p = (ParametersCompiled) $8;
2921
2922                 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2923
2924                 p.CheckParameters (del);
2925
2926                 current_container.AddTypeContainer (del);
2927
2928                 current_delegate = del;
2929                 lexer.ConstraintsParsing = true;
2930           }
2931           opt_type_parameter_constraints_clauses
2932           {
2933                 lexer.ConstraintsParsing = false;
2934           }
2935           SEMICOLON
2936           {
2937                 if (doc_support) {
2938                         current_delegate.DocComment = Lexer.consume_doc_comment ();
2939                         Lexer.doc_state = XmlCommentState.Allowed;
2940                 }
2941           
2942                 if ($11 != null)
2943                         current_delegate.SetConstraints ((List<Constraints>) $11);
2944                 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2945
2946                 $$ = current_delegate;
2947
2948                 current_delegate = null;
2949           }
2950         ;
2951
2952 opt_nullable
2953         : /* empty */
2954         | INTERR_NULLABLE
2955           {
2956                 if (lang_version < LanguageVersion.ISO_2)
2957                         FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2958           
2959                 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2960           }
2961         ;
2962
2963 namespace_or_type_expr
2964         : member_name
2965         | qualified_alias_member IDENTIFIER opt_type_argument_list
2966           {
2967                 var lt1 = (LocatedToken) $1;
2968                 var lt2 = (LocatedToken) $2;
2969                 
2970                 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2971                 lbag.AddLocation ($$, GetLocation ($2));
2972           }
2973         | qualified_alias_member IDENTIFIER generic_dimension
2974           {
2975                 var lt1 = (LocatedToken) $1;
2976                 var lt2 = (LocatedToken) $2;
2977
2978                 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2979                 lbag.AddLocation ($$, GetLocation ($2));
2980           }
2981         ;
2982
2983 member_name
2984         : simple_name_expr
2985         | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2986           {
2987                 var lt = (LocatedToken) $3;
2988                 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2989                 lbag.AddLocation ($$, GetLocation ($2));
2990           }
2991         | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2992           {
2993                 var lt = (LocatedToken) $3;
2994                 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2995                 lbag.AddLocation ($$, GetLocation ($2));
2996           }
2997         ;
2998
2999 simple_name_expr
3000         : IDENTIFIER opt_type_argument_list
3001           {
3002                 var lt = (LocatedToken) $1;
3003                 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3004           }
3005         | IDENTIFIER generic_dimension
3006           {  
3007                 var lt = (LocatedToken) $1;
3008                 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3009           }
3010         ;
3011
3012 //
3013 // Generics arguments  (any type, without attributes)
3014 //
3015 opt_type_argument_list
3016         : /* empty */
3017         | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3018           {
3019                 if (lang_version < LanguageVersion.ISO_2)
3020                         FeatureIsNotAvailable (GetLocation ($1), "generics");     
3021           
3022                 $$ = $2;
3023           }
3024         | OP_GENERICS_LT error
3025           {
3026                 Error_TypeExpected (lexer.Location);
3027                 $$ = new TypeArguments ();
3028           }
3029         ;
3030
3031 type_arguments
3032         : type
3033           {
3034                 TypeArguments type_args = new TypeArguments ();
3035                 type_args.Add ((FullNamedExpression) $1);
3036                 $$ = type_args;
3037           }
3038         | type_arguments COMMA type
3039           {
3040                 TypeArguments type_args = (TypeArguments) $1;
3041                 type_args.Add ((FullNamedExpression) $3);
3042                 $$ = type_args;
3043           }       
3044         ;
3045
3046 //
3047 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3048 //
3049 type_declaration_name
3050         : IDENTIFIER
3051           {
3052                 lexer.parsing_generic_declaration = true;
3053           }
3054           opt_type_parameter_list
3055           {
3056                 lexer.parsing_generic_declaration = false;
3057                 var lt = (LocatedToken) $1;
3058                 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3059           }
3060         ;
3061
3062 member_declaration_name
3063         : method_declaration_name
3064           {
3065                 MemberName mn = (MemberName)$1;
3066                 if (mn.TypeParameters != null)
3067                         syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3068                                 mn.GetSignatureForError ()));
3069           }
3070         ;
3071
3072 method_declaration_name
3073         : type_declaration_name
3074         | explicit_interface IDENTIFIER opt_type_parameter_list
3075           {
3076                 lexer.parsing_generic_declaration = false;        
3077                 var lt = (LocatedToken) $2;
3078                 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3079           }
3080         ;
3081         
3082 indexer_declaration_name
3083         : THIS
3084           {
3085                 lexer.parsing_generic_declaration = false;        
3086                 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3087           }
3088         | explicit_interface THIS
3089           {
3090                 lexer.parsing_generic_declaration = false;
3091                 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3092           }
3093         ;
3094
3095 explicit_interface
3096         : IDENTIFIER opt_type_argument_list DOT
3097           {
3098                 var lt = (LocatedToken) $1;
3099                 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3100                 lbag.AddLocation ($$, GetLocation ($3));
3101           }
3102         | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3103           {
3104                 var lt1 = (LocatedToken) $1;
3105                 var lt2 = (LocatedToken) $2;
3106
3107                 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3108                 lbag.AddLocation ($$, GetLocation ($4));
3109           }
3110         | explicit_interface IDENTIFIER opt_type_argument_list DOT
3111           {
3112                 var lt = (LocatedToken) $2;
3113                 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3114                 lbag.AddLocation ($$, GetLocation ($4));
3115           }
3116         ;
3117         
3118 opt_type_parameter_list
3119         : /* empty */
3120         | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3121           {
3122                 if (lang_version < LanguageVersion.ISO_2)
3123                         FeatureIsNotAvailable (GetLocation ($1), "generics");
3124           
3125                 $$ = $2;
3126                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3127           }
3128         ;
3129
3130 type_parameters
3131         : type_parameter
3132           {
3133                 var tparams = new TypeParameters ();
3134                 tparams.Add ((TypeParameter)$1);
3135                 $$ = tparams;
3136           }
3137         | type_parameters COMMA type_parameter
3138           {
3139                 var tparams = (TypeParameters) $1;
3140                 tparams.Add ((TypeParameter)$3);
3141                 $$ = tparams;
3142                 lbag.AddLocation ($3, GetLocation ($3));
3143           }       
3144         ;
3145
3146 type_parameter
3147         : opt_attributes opt_type_parameter_variance IDENTIFIER
3148           {
3149                 var lt = (LocatedToken)$3;
3150                 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3151           }
3152         | error
3153           {
3154                 if (GetTokenName (yyToken) == "type")
3155                         report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3156                 else
3157                         Error_SyntaxError (yyToken);
3158                         
3159                 $$ = new TypeParameter (MemberName.Null, null, null);
3160           }
3161         ;
3162
3163 //
3164 // All types where void is allowed
3165 //
3166 type_and_void
3167         : type_expression_or_array
3168         | VOID
3169           {
3170                 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3171           }
3172         ;
3173         
3174 member_type
3175         : type_and_void
3176           {
3177                 lexer.parsing_generic_declaration = true;
3178           }
3179         ;
3180         
3181 //
3182 // A type which does not allow `void' to be used
3183 //
3184 type
3185         : type_expression_or_array
3186         | void_invalid
3187         ;
3188         
3189 simple_type
3190         : type_expression
3191         | void_invalid
3192         ;
3193         
3194 parameter_type
3195         : type_expression_or_array
3196         | VOID
3197           {
3198                 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3199                 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3200           }
3201         ;
3202
3203 type_expression_or_array
3204         : type_expression
3205         | type_expression rank_specifiers
3206           {
3207                 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3208           }
3209         ;
3210         
3211 type_expression
3212         : namespace_or_type_expr opt_nullable
3213           {
3214                 if ($2 != null) {
3215                         $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3216                 } else {
3217                         var sn = $1 as SimpleName;
3218                         if (sn != null && sn.Name == "var")
3219                                 $$ = new VarExpr (sn.Location);
3220                         else
3221                                 $$ = $1;
3222                 }
3223           }
3224         | namespace_or_type_expr pointer_stars
3225           {
3226                 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3227           }
3228         | builtin_type_expression
3229         ;
3230
3231 void_invalid
3232         : VOID
3233           {
3234                 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3235                 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3236           }
3237         ;
3238
3239 builtin_type_expression
3240         : builtin_types opt_nullable
3241           {
3242                 if ($2 != null)
3243                         $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3244           }
3245         | builtin_types pointer_stars
3246           {
3247                 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3248           }
3249         | VOID pointer_stars
3250           {
3251                 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3252           }
3253         ;
3254
3255 type_list
3256         : base_type_name
3257           {
3258                 var types = new List<FullNamedExpression> (2);
3259                 types.Add ((FullNamedExpression) $1);
3260                 $$ = types;
3261           }
3262         | type_list COMMA base_type_name
3263           {
3264                 var types = (List<FullNamedExpression>) $1;
3265                 types.Add ((FullNamedExpression) $3);
3266                 $$ = types;
3267           }
3268         ;
3269
3270 base_type_name
3271         : type
3272           {
3273                 if ($1 is ComposedCast) {
3274                         report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3275                 }
3276                 $$ = $1;
3277           }
3278         ;
3279         
3280 /*
3281  * replaces all the productions for isolating the various
3282  * simple types, but we need this to reuse it easily in variable_type
3283  */
3284 builtin_types
3285         : OBJECT        { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3286         | STRING        { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3287         | BOOL          { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3288         | DECIMAL       { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3289         | FLOAT         { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3290         | DOUBLE        { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3291         | integral_type
3292         ;
3293
3294 integral_type
3295         : SBYTE         { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3296         | BYTE          { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3297         | SHORT         { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3298         | USHORT        { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3299         | INT           { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3300         | UINT          { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3301         | LONG          { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3302         | ULONG         { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3303         | CHAR          { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3304         ;
3305
3306 //
3307 // Expressions, section 7.5
3308 //
3309
3310
3311 primary_expression
3312         : type_name_expression
3313         | literal
3314         | array_creation_expression
3315         | parenthesized_expression
3316         | default_value_expression
3317         | invocation_expression
3318         | element_access
3319         | this_access
3320         | base_access
3321         | post_increment_expression
3322         | post_decrement_expression
3323         | object_or_delegate_creation_expression
3324         | anonymous_type_expression
3325         | typeof_expression
3326         | sizeof_expression
3327         | checked_expression
3328         | unchecked_expression
3329         | pointer_member_access
3330         | anonymous_method_expression
3331         | undocumented_expressions
3332         | interpolated_string
3333         ;
3334
3335 type_name_expression
3336         : simple_name_expr
3337         | IDENTIFIER GENERATE_COMPLETION {
3338                 var lt = (LocatedToken) $1;
3339                $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3340           }
3341         | member_access
3342         ;
3343
3344 literal
3345         : boolean_literal
3346         | LITERAL
3347         | NULL                  { $$ = new NullLiteral (GetLocation ($1)); }
3348         ;
3349
3350 boolean_literal
3351         : TRUE                  { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3352         | FALSE                 { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3353         ;
3354
3355 interpolated_string
3356         : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3357           {
3358                 if (lang_version < LanguageVersion.V_6)
3359                         FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3360
3361                 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3362           }
3363         | INTERPOLATED_STRING_END
3364           {
3365                 if (lang_version < LanguageVersion.V_6)
3366                         FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3367
3368                 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3369           }
3370         ;
3371
3372 interpolations
3373         : interpolation
3374           {
3375                 var list = new List<Expression> ();
3376                 list.Add ((InterpolatedStringInsert) $1);
3377                 $$ = list;
3378           }
3379         | interpolations INTERPOLATED_STRING interpolation
3380           {
3381                 var list = (List<Expression>) $1;
3382                 list.Add ((StringLiteral) $2);
3383                 list.Add ((InterpolatedStringInsert) $3);
3384                 $$ = list;
3385           }
3386         ;
3387
3388 interpolation
3389         : expression
3390           {
3391                 $$ = new InterpolatedStringInsert ((Expression) $1);
3392           }
3393         | expression COMMA expression
3394           {
3395                 $$ = new InterpolatedStringInsert ((Expression) $1) {
3396                         Alignment = (Expression)$3
3397                 };
3398           }
3399         | expression COLON
3400           {
3401                 lexer.parsing_interpolation_format = true;
3402           }
3403           LITERAL
3404           {
3405                 lexer.parsing_interpolation_format = false;
3406
3407                 $$ = new InterpolatedStringInsert ((Expression) $1) {
3408                         Format = (string)$4
3409                 };
3410           }
3411         | expression COMMA expression COLON
3412           {
3413                 lexer.parsing_interpolation_format = true;
3414           }
3415           LITERAL
3416           {
3417                 lexer.parsing_interpolation_format = false;
3418
3419                 $$ = new InterpolatedStringInsert ((Expression) $1) {
3420                         Alignment = (Expression)$3,
3421                         Format = (string) $6
3422                 };
3423           }
3424         ;
3425
3426
3427 //
3428 // Here is the trick, tokenizer may think that parens is a special but
3429 // parser is interested in open parens only, so we merge them.
3430 // Consider: if (a)foo ();
3431 //
3432 open_parens_any
3433         : OPEN_PARENS
3434         | OPEN_PARENS_CAST
3435         ;
3436
3437 // 
3438 // Use this production to accept closing parenthesis or 
3439 // performing completion
3440 //
3441 close_parens
3442         : CLOSE_PARENS
3443         | COMPLETE_COMPLETION
3444         ;
3445
3446
3447 parenthesized_expression
3448         : OPEN_PARENS expression CLOSE_PARENS
3449           {
3450                 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3451                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3452           }
3453         | OPEN_PARENS expression COMPLETE_COMPLETION
3454           {
3455                 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3456           }
3457         ;
3458
3459 member_access
3460         : primary_expression DOT identifier_inside_body opt_type_argument_list
3461           {
3462                 var lt = (LocatedToken) $3;
3463                 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3464                 lbag.AddLocation ($$, GetLocation ($2));
3465           }
3466         | primary_expression DOT identifier_inside_body generic_dimension
3467           {
3468                 var lt = (LocatedToken) $3;
3469                 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3470                 lbag.AddLocation ($$, GetLocation ($2));
3471           }
3472         | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3473           {
3474                 if (lang_version < LanguageVersion.V_6)
3475                         FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3476
3477                 var lt = (LocatedToken) $4;
3478                 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3479                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3480           }
3481         | builtin_types DOT identifier_inside_body opt_type_argument_list
3482           {
3483                 var lt = (LocatedToken) $3;
3484                 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3485                 lbag.AddLocation ($$, GetLocation ($2));
3486           }
3487         | BASE DOT identifier_inside_body opt_type_argument_list
3488           {
3489                 var lt = (LocatedToken) $3;
3490                 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3491                 lbag.AddLocation ($$, GetLocation ($2));
3492           }
3493         | AWAIT DOT identifier_inside_body opt_type_argument_list
3494           {
3495                 var lt = (LocatedToken) $3;
3496                 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3497                 lbag.AddLocation ($$, GetLocation ($2));
3498           }
3499         | qualified_alias_member identifier_inside_body opt_type_argument_list
3500           {
3501                 var lt1 = (LocatedToken) $1;
3502                 var lt2 = (LocatedToken) $2;
3503
3504                 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3505                 lbag.AddLocation ($$, GetLocation ($2));
3506           }
3507         | qualified_alias_member identifier_inside_body generic_dimension
3508           {
3509                 var lt1 = (LocatedToken) $1;
3510                 var lt2 = (LocatedToken) $2;
3511
3512                 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3513                 lbag.AddLocation ($$, GetLocation ($2));
3514           }
3515         | primary_expression DOT GENERATE_COMPLETION {
3516                 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3517           }
3518         | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3519                 var lt = (LocatedToken) $3;
3520                 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3521           }
3522         | builtin_types DOT GENERATE_COMPLETION
3523           {
3524                 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3525           }
3526         | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3527                 var lt = (LocatedToken) $3;
3528                 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3529           }
3530         ;
3531
3532 invocation_expression
3533         : primary_expression open_parens_any opt_argument_list close_parens
3534           {
3535                 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3536                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3537           }
3538         | primary_expression open_parens_any argument_list error
3539           {
3540                 Error_SyntaxError (yyToken);
3541
3542                 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3543                 lbag.AddLocation ($$, GetLocation ($2));
3544           }
3545         | primary_expression open_parens_any error
3546           {
3547                 Error_SyntaxError (yyToken);
3548
3549                 $$ = new Invocation ((Expression) $1, null);
3550                 lbag.AddLocation ($$, GetLocation ($2));
3551           }
3552         ;
3553
3554 opt_object_or_collection_initializer
3555         : /* empty */           { $$ = null; }
3556         | object_or_collection_initializer
3557         ;
3558
3559 object_or_collection_initializer
3560         : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3561           {
3562                 if ($2 == null) {
3563                         $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3564                 } else {
3565                         $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3566                 }
3567                 lbag.AddLocation ($$, GetLocation ($3));
3568           }
3569         | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3570           {
3571                 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3572                 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3573           }
3574         ;
3575
3576 opt_member_initializer_list
3577         : /* empty */           { $$ = null; }
3578         | member_initializer_list
3579         {
3580                 $$ = $1;
3581         }
3582         ;
3583
3584 member_initializer_list
3585         : member_initializer
3586           {
3587                 var a = new List<Expression> ();
3588                 a.Add ((Expression) $1);
3589                 $$ = a;
3590           }
3591         | member_initializer_list COMMA member_initializer
3592           {
3593                 var a = (List<Expression>)$1;
3594                 a.Add ((Expression) $3);
3595                 $$ = a;
3596           }
3597         | member_initializer_list error {
3598                 Error_SyntaxError (yyToken);
3599                 $$ = $1;
3600           }
3601         ;
3602
3603 member_initializer
3604         : IDENTIFIER ASSIGN initializer_value
3605           {
3606                 var lt = (LocatedToken) $1;
3607                 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3608                 lbag.AddLocation ($$, GetLocation ($2));
3609           }
3610         | AWAIT ASSIGN initializer_value
3611           {
3612                 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3613                 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3614                 lbag.AddLocation ($$, GetLocation ($2));
3615           }
3616         | GENERATE_COMPLETION 
3617           {
3618                 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3619           }
3620         | non_assignment_expression opt_COMPLETE_COMPLETION  {
3621                 CompletionSimpleName csn = $1 as CompletionSimpleName;
3622                 if (csn == null)
3623                         $$ = new CollectionElementInitializer ((Expression)$1);
3624                 else
3625                         $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3626           }
3627         | OPEN_BRACE expression_list CLOSE_BRACE
3628           {
3629                 if ($2 == null)
3630                         $$ = new CollectionElementInitializer (GetLocation ($1));
3631                 else
3632                         $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3633
3634                 lbag.AddLocation ($$, GetLocation ($3));
3635           }
3636         | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3637           {
3638                 if (lang_version < LanguageVersion.V_6)
3639                         FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3640
3641                 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3642                 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3643           }
3644         | OPEN_BRACE CLOSE_BRACE
3645           {
3646                 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3647                 $$ = new CollectionElementInitializer (GetLocation ($1));
3648                 lbag.AddLocation ($$, GetLocation ($2));
3649           }
3650         ;
3651
3652 initializer_value
3653         : expression
3654         | object_or_collection_initializer
3655         ;
3656
3657 opt_argument_list
3658         : /* empty */           { $$ = null; }
3659         | argument_list
3660         ;
3661
3662 argument_list
3663         : argument_or_named_argument
3664           { 
3665                 Arguments list = new Arguments (4);
3666                 list.Add ((Argument) $1);
3667                 $$ = list;
3668           }
3669         | argument_list COMMA argument
3670           {
3671                 Arguments list = (Arguments) $1;
3672                 if (list [list.Count - 1] is NamedArgument)
3673                         Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3674                 
3675                 list.Add ((Argument) $3);
3676                 $$ = list;
3677           }
3678         | argument_list COMMA named_argument
3679           {
3680                 Arguments list = (Arguments) $1;
3681                 NamedArgument a = (NamedArgument) $3;
3682                 for (int i = 0; i < list.Count; ++i) {
3683                         NamedArgument na = list [i] as NamedArgument;
3684                         if (na != null && na.Name == a.Name)
3685                                 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3686                                         na.Name);
3687                 }
3688                 
3689                 list.Add (a);
3690                 $$ = list;
3691           }
3692         | argument_list COMMA error
3693           {
3694                 if (lexer.putback_char == -1)
3695                         lexer.putback (')'); // TODO: Wrong but what can I do
3696                 Error_SyntaxError (yyToken);
3697                 $$ = $1;
3698           }
3699         | COMMA error
3700           {
3701                 report.Error (839, GetLocation ($1), "An argument is missing");
3702                 $$ = null;
3703           }
3704         ;
3705
3706 argument
3707         : expression
3708           {
3709                 $$ = new Argument ((Expression) $1);
3710           }
3711         | non_simple_argument
3712         ;
3713
3714 argument_or_named_argument
3715         : argument
3716         | named_argument
3717         ;
3718
3719 non_simple_argument
3720         : REF variable_reference 
3721           { 
3722                 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3723                 lbag.AddLocation ($$, GetLocation ($1));
3724           }
3725         | REF declaration_expression
3726           {
3727                 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3728           }
3729         | OUT variable_reference 
3730           { 
3731                 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3732                 lbag.AddLocation ($$, GetLocation ($1));
3733           }
3734         | OUT declaration_expression
3735           {
3736                 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3737           }
3738         | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3739           {
3740                 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3741                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3742           }
3743         | ARGLIST OPEN_PARENS CLOSE_PARENS
3744           {
3745                 $$ = new Argument (new Arglist (GetLocation ($1)));
3746                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3747           }       
3748         ;
3749
3750 declaration_expression
3751         : OPEN_PARENS declaration_expression CLOSE_PARENS
3752           {
3753                 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3754                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3755           }
3756 /*
3757         | CHECKED open_parens_any declaration_expression CLOSE_PARENS
3758           {
3759                 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3760                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3761           }
3762         | UNCHECKED open_parens_any declaration_expression CLOSE_PARENS
3763           {
3764                 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3765                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3766           }
3767 */
3768         | variable_type identifier_inside_body
3769           {
3770                 if (lang_version != LanguageVersion.Experimental)
3771                         FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3772
3773                 var lt = (LocatedToken) $2;
3774                 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3775                 current_block.AddLocalName (lv);
3776                 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3777           }
3778         | variable_type identifier_inside_body ASSIGN expression
3779           {
3780                 if (lang_version != LanguageVersion.Experimental)
3781                         FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3782
3783                 var lt = (LocatedToken) $2;
3784                 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3785                 current_block.AddLocalName (lv);
3786                 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv) {
3787                         Initializer = (Expression) $4
3788                 };
3789           }
3790         ;
3791
3792 variable_reference
3793         : expression
3794         ;
3795
3796 element_access
3797         : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET  
3798           {
3799                 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3800                 lbag.AddLocation ($$, GetLocation ($4));
3801           }
3802         | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET  
3803           {
3804                 if (lang_version < LanguageVersion.V_6)
3805                         FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3806
3807                 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3808                         ConditionalAccess = true
3809                 };
3810
3811                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3812           }
3813         | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3814           {
3815                 Error_SyntaxError (yyToken);
3816                 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3817           }
3818         | primary_expression OPEN_BRACKET_EXPR error
3819           {
3820                 Error_SyntaxError (yyToken);
3821                 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3822           }
3823         ;
3824
3825 expression_list
3826         : expression_or_error
3827           {
3828                 var list = new List<Expression> (4);
3829                 list.Add ((Expression) $1);
3830                 $$ = list;
3831           }
3832         | expression_list COMMA expression_or_error
3833           {
3834                 var list = (List<Expression>) $1;
3835                 list.Add ((Expression) $3);
3836                 $$ = list;
3837           }
3838         ;
3839         
3840 expression_list_arguments
3841         : expression_list_argument
3842           {
3843                 Arguments args = new Arguments (4);
3844                 args.Add ((Argument) $1);
3845                 $$ = args;
3846           }
3847         | expression_list_arguments COMMA expression_list_argument
3848           {
3849                 Arguments args = (Arguments) $1;
3850                 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3851                         Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3852           
3853                 args.Add ((Argument) $3);
3854                 $$ = args;        
3855           }
3856         ;
3857         
3858 expression_list_argument
3859         : expression
3860           {
3861                 $$ = new Argument ((Expression) $1);
3862           }
3863         | named_argument
3864         ;
3865
3866 this_access
3867         : THIS
3868           {
3869                 $$ = new This (GetLocation ($1));
3870           }
3871         ;
3872
3873 base_access
3874         : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3875           {
3876                 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3877                 lbag.AddLocation ($$, GetLocation ($4));
3878           }
3879         | BASE OPEN_BRACKET error
3880           {
3881                 Error_SyntaxError (yyToken);
3882                 $$ = new ElementAccess (null, null, GetLocation ($2));
3883           }
3884         ;
3885
3886 post_increment_expression
3887         : primary_expression OP_INC
3888           {
3889                 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3890           }
3891         ;
3892
3893 post_decrement_expression
3894         : primary_expression OP_DEC
3895           {
3896                 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3897           }
3898         ;
3899         
3900 object_or_delegate_creation_expression
3901         : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3902           {
3903                 if ($6 != null) {
3904                         if (lang_version <= LanguageVersion.ISO_2)
3905                                 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3906                                 
3907                         $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3908                 } else {
3909                         $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3910                 }
3911                 
3912                 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3913           }
3914         | NEW new_expr_type object_or_collection_initializer
3915           {
3916                 if (lang_version <= LanguageVersion.ISO_2)
3917                         FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3918           
3919                 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3920           }
3921         ;
3922
3923 array_creation_expression
3924         : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3925           opt_rank_specifier
3926           opt_array_initializer
3927           {
3928                 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3929                                 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3930                                         Next = (ComposedTypeSpecifier) $6
3931                                 }, (ArrayInitializer) $7, GetLocation ($1)) {
3932                         NoEmptyInterpolation = true
3933                 };
3934
3935                 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3936           }
3937         | NEW new_expr_type rank_specifiers opt_array_initializer
3938           {
3939                 if ($4 == null)
3940                         report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3941
3942                 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) {
3943                         NoEmptyInterpolation = true
3944                 };
3945           }
3946         | NEW rank_specifier array_initializer
3947           {
3948                 if (lang_version <= LanguageVersion.ISO_2)
3949                         FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3950           
3951                 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3952           }
3953         | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3954           {
3955                 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3956                 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3957           }
3958         | NEW new_expr_type error
3959           {
3960                 Error_SyntaxError (yyToken);
3961                 // It can be any of new expression, create the most common one
3962                 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3963           }
3964         ;
3965
3966 new_expr_type
3967         : {
3968                 ++lexer.parsing_type;
3969           }
3970           simple_type
3971           {
3972                 --lexer.parsing_type;
3973                 $$ = $2;
3974           }
3975         ;
3976
3977 anonymous_type_expression
3978         : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3979           {
3980                 if (lang_version <= LanguageVersion.ISO_2)
3981                         FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3982
3983                 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3984                 
3985                 // TODO: lbag comma location
3986                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3987           }
3988         | NEW OPEN_BRACE GENERATE_COMPLETION
3989           {
3990                 $$ = new EmptyCompletion ();
3991           }
3992         ;
3993
3994 anonymous_type_parameters_opt_comma
3995         : anonymous_type_parameters_opt
3996         | anonymous_type_parameters COMMA
3997         ;
3998
3999 anonymous_type_parameters_opt
4000         : { $$ = null; }
4001         | anonymous_type_parameters
4002         ;
4003
4004 anonymous_type_parameters
4005         : anonymous_type_parameter
4006           {
4007                 var a = new List<AnonymousTypeParameter> (4);
4008                 a.Add ((AnonymousTypeParameter) $1);
4009                 $$ = a;
4010           }
4011         | anonymous_type_parameters COMMA anonymous_type_parameter
4012           {
4013                 var a = (List<AnonymousTypeParameter>) $1;
4014                 a.Add ((AnonymousTypeParameter) $3);
4015                 $$ = a;
4016           }
4017         | COMPLETE_COMPLETION
4018           {
4019                 $$ = new EmptyCompletion ();
4020           }
4021         | anonymous_type_parameter COMPLETE_COMPLETION
4022           {
4023                 $$ = $1;
4024           }
4025         ;
4026
4027 anonymous_type_parameter
4028         : identifier_inside_body ASSIGN variable_initializer
4029           {
4030                 var lt = (LocatedToken)$1;
4031                 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4032                 lbag.AddLocation ($$, GetLocation ($2));
4033           }
4034         | identifier_inside_body
4035           {
4036                 var lt = (LocatedToken)$1;
4037                 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4038                         lt.Value, lt.Location);
4039           }
4040         | member_access
4041           {
4042                 MemberAccess ma = (MemberAccess) $1;
4043                 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4044           }
4045         | error
4046           {
4047                 report.Error (746, lexer.Location,
4048                         "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4049                 $$ = null;
4050           }
4051         ;
4052
4053 opt_rank_specifier
4054         : /* empty */
4055         | rank_specifiers
4056         ;
4057
4058 rank_specifiers
4059         : rank_specifier
4060         | rank_specifier rank_specifiers
4061           {
4062                 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4063                 $$ = $1;
4064           }
4065         ;
4066
4067 rank_specifier
4068         : OPEN_BRACKET CLOSE_BRACKET
4069           {
4070                 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4071                 lbag.AddLocation ($$, GetLocation ($2));
4072           }
4073         | OPEN_BRACKET dim_separators CLOSE_BRACKET
4074           {
4075                 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4076                 lbag.AddLocation ($$, GetLocation ($3));
4077           }
4078         ;
4079
4080 dim_separators
4081         : COMMA
4082           {
4083                 $$ = 2;
4084           }
4085         | dim_separators COMMA
4086           {
4087                 $$ = ((int) $1) + 1;
4088           }
4089         ;
4090
4091 opt_array_initializer
4092         : /* empty */
4093           {
4094                 $$ = null;
4095           }
4096         | array_initializer
4097           {
4098                 $$ = $1;
4099           }
4100         ;
4101
4102 array_initializer
4103         : OPEN_BRACE CLOSE_BRACE
4104           {
4105                 var ai = new ArrayInitializer (0, GetLocation ($1));
4106                 ai.VariableDeclaration = current_variable;
4107                 lbag.AddLocation (ai, GetLocation ($2));
4108                 $$ = ai;
4109           }
4110         | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4111           {
4112                 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4113                 ai.VariableDeclaration = current_variable;
4114                 if ($3 != null) {
4115                         lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4116                 } else {
4117                         lbag.AddLocation (ai, GetLocation ($4));
4118                 }
4119                 $$ = ai;
4120           }
4121         ;
4122
4123 variable_initializer_list
4124         : variable_initializer
4125           {
4126                 var list = new List<Expression> (4);
4127                 list.Add ((Expression) $1);
4128                 $$ = list;
4129           }
4130         | variable_initializer_list COMMA variable_initializer
4131           {
4132                 var list = (List<Expression>) $1;
4133                 list.Add ((Expression) $3);
4134                 $$ = list;
4135           }
4136         ;
4137
4138 typeof_expression
4139         : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4140           {
4141                 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4142                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4143           }
4144         ;
4145         
4146 typeof_type_expression
4147         : type_and_void
4148         | error
4149          {
4150                 Error_TypeExpected (lexer.Location);
4151                 $$ = null;
4152          }
4153         ;
4154
4155 generic_dimension
4156         : GENERIC_DIMENSION
4157           {
4158                 if (lang_version < LanguageVersion.ISO_2)
4159                         FeatureIsNotAvailable (GetLocation ($1), "generics");
4160
4161                 $$ = $1;
4162           }
4163         ;
4164         
4165 qualified_alias_member
4166         : IDENTIFIER DOUBLE_COLON
4167           {
4168                 var lt = (LocatedToken) $1;
4169                 if (lang_version == LanguageVersion.ISO_1)
4170                         FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4171
4172                 $$ = lt;                
4173           }
4174         ;
4175
4176 sizeof_expression
4177         : SIZEOF open_parens_any type CLOSE_PARENS
4178           { 
4179                 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4180                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4181           }
4182         | SIZEOF open_parens_any type error
4183           {
4184                 Error_SyntaxError (yyToken);
4185
4186                 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4187                 lbag.AddLocation ($$, GetLocation ($2));
4188           }
4189         ;
4190
4191 checked_expression
4192         : CHECKED open_parens_any expression CLOSE_PARENS
4193           {
4194                 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4195                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4196           }
4197         | CHECKED error
4198           {
4199                 Error_SyntaxError (yyToken);
4200
4201                 $$ = new CheckedExpr (null, GetLocation ($1));
4202           }
4203         ;
4204
4205 unchecked_expression
4206         : UNCHECKED open_parens_any expression CLOSE_PARENS
4207           {
4208                 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4209                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4210           }
4211         | UNCHECKED error
4212           {
4213                 Error_SyntaxError (yyToken);
4214
4215                 $$ = new UnCheckedExpr (null, GetLocation ($1));
4216           }
4217         ;
4218
4219 pointer_member_access
4220         : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4221           {
4222                 var lt = (LocatedToken) $3;
4223                 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4224           }
4225         ;
4226
4227 anonymous_method_expression
4228         : DELEGATE opt_anonymous_method_signature
4229           {
4230                 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4231           }
4232           block
4233           {
4234                 $$ = end_anonymous ((ParametersBlock) $4);
4235           }
4236         | ASYNC DELEGATE opt_anonymous_method_signature
4237           {
4238                 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4239           }
4240           block
4241           {
4242                 $$ = end_anonymous ((ParametersBlock) $5);
4243           }
4244         ;
4245
4246 opt_anonymous_method_signature
4247         : 
4248           {
4249                 $$ = ParametersCompiled.Undefined;
4250           } 
4251         | anonymous_method_signature
4252         ;
4253
4254 anonymous_method_signature
4255         : OPEN_PARENS
4256           {
4257                 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4258           }
4259           opt_formal_parameter_list CLOSE_PARENS
4260           {
4261                 valid_param_mod = 0;
4262                 $$ = $3;
4263           }
4264         ;
4265
4266 default_value_expression
4267         : DEFAULT open_parens_any type CLOSE_PARENS
4268           {
4269                 if (lang_version < LanguageVersion.ISO_2)
4270                         FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4271
4272                 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4273                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4274           }
4275         ;
4276
4277 unary_expression
4278         : primary_expression
4279         | BANG prefixed_unary_expression
4280           {
4281                 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4282           }
4283         | TILDE prefixed_unary_expression
4284           {
4285                 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4286           }
4287         | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4288           {
4289                 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4290                 lbag.AddLocation ($$, GetLocation ($3));
4291           }
4292         | AWAIT prefixed_unary_expression
4293           {
4294                 if (!async_block) {
4295                          if (current_anonymous_method is LambdaExpression) {
4296                                 report.Error (4034, GetLocation ($1),
4297                                         "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4298                         } else if (current_anonymous_method != null) {
4299                                 report.Error (4035, GetLocation ($1),
4300                                         "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4301                         } else if (interactive_async != null) {
4302                                 current_block.Explicit.RegisterAsyncAwait ();
4303                                 interactive_async = true;
4304                         } else {
4305                                 report.Error (4033, GetLocation ($1),
4306                                         "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4307                         }
4308                 } else {
4309                         current_block.Explicit.RegisterAsyncAwait ();
4310                 }
4311                 
4312                 $$ = new Await ((Expression) $2, GetLocation ($1));
4313           }
4314         | THROW_EXPR prefixed_unary_expression
4315           {
4316                 if (lang_version < LanguageVersion.V_7)
4317                         FeatureIsNotAvailable (lexer.Location, "throw expression");
4318
4319                 $$ = new ThrowExpression ((Expression) $2, GetLocation ($1));
4320           }
4321         | BANG error
4322           {
4323                 Error_SyntaxError (yyToken);
4324
4325                 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4326           }
4327         | TILDE error
4328           {
4329                 Error_SyntaxError (yyToken);
4330
4331                 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4332           }
4333         | OPEN_PARENS_CAST type CLOSE_PARENS error
4334           {
4335                 Error_SyntaxError (yyToken);
4336
4337                 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4338                 lbag.AddLocation ($$, GetLocation ($3));
4339           }
4340         | AWAIT error
4341           {
4342                 Error_SyntaxError (yyToken);
4343
4344                 $$ = new Await (null, GetLocation ($1));
4345           }
4346         ;
4347
4348         //
4349         // The idea to split this out is from Rhys' grammar
4350         // to solve the problem with casts.
4351         //
4352 prefixed_unary_expression
4353         : unary_expression
4354         | PLUS prefixed_unary_expression
4355           { 
4356                 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4357           } 
4358         | MINUS prefixed_unary_expression 
4359           { 
4360                 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4361           }
4362         | OP_INC prefixed_unary_expression 
4363           {
4364                 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4365           }
4366         | OP_DEC prefixed_unary_expression 
4367           {
4368                 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4369           }
4370         | STAR prefixed_unary_expression
4371           {
4372                 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4373           }
4374         | BITWISE_AND prefixed_unary_expression
4375           {
4376                 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4377           }
4378         | PLUS error
4379           { 
4380                 Error_SyntaxError (yyToken);
4381
4382                 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4383           } 
4384         | MINUS error 
4385           { 
4386                 Error_SyntaxError (yyToken);
4387
4388                 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4389           }
4390         | OP_INC error 
4391           {
4392                 Error_SyntaxError (yyToken);
4393
4394                 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4395           }
4396         | OP_DEC error 
4397           {
4398                 Error_SyntaxError (yyToken);
4399
4400                 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4401           }
4402         | STAR error
4403           {
4404                 Error_SyntaxError (yyToken);
4405
4406                 $$ = new Indirection (null, GetLocation ($1));
4407           }
4408         | BITWISE_AND error
4409           {
4410                 Error_SyntaxError (yyToken);
4411
4412                 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4413           }
4414         ;
4415
4416 multiplicative_expression
4417         : prefixed_unary_expression
4418         | multiplicative_expression STAR prefixed_unary_expression
4419           {
4420                 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4421                 lbag.AddLocation ($$, GetLocation ($2));
4422           }
4423         | multiplicative_expression DIV prefixed_unary_expression
4424           {
4425                 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4426                 lbag.AddLocation ($$, GetLocation ($2));
4427           }
4428         | multiplicative_expression PERCENT prefixed_unary_expression 
4429           {
4430                 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4431                 lbag.AddLocation ($$, GetLocation ($2));
4432           }
4433         | multiplicative_expression STAR error
4434           {
4435                 Error_SyntaxError (yyToken);
4436
4437                 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4438                 lbag.AddLocation ($$, GetLocation ($2));
4439           }
4440         | multiplicative_expression DIV error
4441           {
4442                 Error_SyntaxError (yyToken);
4443
4444                 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4445                 lbag.AddLocation ($$, GetLocation ($2));
4446           }
4447         | multiplicative_expression PERCENT error 
4448           {
4449                 Error_SyntaxError (yyToken);
4450
4451                 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4452                 lbag.AddLocation ($$, GetLocation ($2));
4453           }
4454         ;
4455
4456 additive_expression
4457         : multiplicative_expression
4458         | additive_expression PLUS multiplicative_expression 
4459           {
4460                 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4461                 lbag.AddLocation ($$, GetLocation ($2));
4462           }
4463         | additive_expression MINUS multiplicative_expression
4464           {
4465                 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4466                 lbag.AddLocation ($$, GetLocation ($2));
4467           }
4468         | additive_expression PLUS error
4469           {
4470                 Error_SyntaxError (yyToken);
4471
4472                 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4473                 lbag.AddLocation ($$, GetLocation ($2));
4474           }
4475         | additive_expression MINUS error
4476           {
4477                 Error_SyntaxError (yyToken);
4478
4479                 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4480                 lbag.AddLocation ($$, GetLocation ($2));
4481           }
4482         | additive_expression AS type
4483           {
4484                 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4485           }
4486         | additive_expression IS pattern_type_expr opt_identifier
4487           {
4488                 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4489                 if ($4 != null) {
4490                         if (lang_version != LanguageVersion.Experimental)
4491                                 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4492
4493                         var lt = (LocatedToken) $4;
4494                         is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4495                         current_block.AddLocalName (is_expr.Variable);
4496                 }
4497
4498                 $$ = is_expr;
4499           }
4500         | additive_expression IS pattern_expr
4501           {
4502                 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4503                 if (lang_version != LanguageVersion.Experimental)
4504                         FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4505
4506                 $$ = is_expr;
4507           }
4508         | additive_expression AS error
4509           {
4510                 Error_SyntaxError (yyToken);
4511
4512                 $$ = new As ((Expression) $1, null, GetLocation ($2));
4513           }
4514         | additive_expression IS error
4515           {
4516                 Error_SyntaxError (yyToken);
4517
4518                 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4519           }
4520         | AWAIT IS type
4521           {
4522                 var lt = (LocatedToken) $1;
4523                 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4524           }
4525         | AWAIT AS type
4526           {
4527                 var lt = (LocatedToken) $1;
4528                 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4529           }
4530         ;
4531
4532 pattern_type_expr
4533         : variable_type
4534         ;
4535
4536 pattern_expr
4537         : literal
4538         | PLUS prefixed_unary_expression
4539           {
4540                 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4541           }
4542         | MINUS prefixed_unary_expression
4543           {
4544                 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4545           }
4546         | sizeof_expression
4547         | default_value_expression
4548         | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4549           {
4550                 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4551                 lbag.AddLocation ($$, GetLocation ($3));
4552           }
4553         | STAR
4554           {
4555                 $$ = new WildcardPattern (GetLocation ($1));
4556           }
4557         | pattern_expr_invocation
4558         | pattern_property
4559         ;
4560
4561 pattern_expr_invocation
4562         : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4563           {
4564                 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4565           }
4566         ;
4567
4568 pattern_property
4569         : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4570           {
4571                 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4572           }
4573         ;
4574
4575 pattern_property_list
4576         : pattern_property_entry
4577           {
4578                 var list = new List<PropertyPatternMember> ();
4579                 list.Add ((PropertyPatternMember) $1);
4580                 $$ = list;
4581           }
4582         | pattern_property_list COMMA pattern_property_entry
4583           {
4584                 var list = (List<PropertyPatternMember>) $1;
4585                 list.Add ((PropertyPatternMember) $3);
4586                 $$ = list;
4587           }
4588         ;
4589
4590 pattern_property_entry
4591         : identifier_inside_body IS pattern
4592           {
4593                 var lt = (LocatedToken) $1;
4594                 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4595           }
4596         ;
4597
4598 pattern
4599         : pattern_expr
4600         | pattern_type_expr opt_identifier
4601           {
4602                 if ($2 != null) {
4603                         var lt = (LocatedToken) $2;
4604                         var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4605                         current_block.AddLocalName (variable);
4606                 }
4607           }
4608         ;
4609
4610 opt_pattern_list
4611         : /* empty */
4612           {
4613                 $$ = new Arguments (0);
4614           }
4615         | pattern_list
4616         ;
4617
4618 pattern_list
4619         : pattern_argument
4620           {
4621                 Arguments args = new Arguments (4);
4622                 args.Add ((Argument) $1);
4623                 $$ = args;
4624           }
4625         | pattern_list COMMA pattern_argument
4626           {
4627                 Arguments args = (Arguments) $1;
4628                 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4629                         Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4630
4631                 args.Add ((Argument) $3);
4632                 $$ = args;
4633           }
4634         ;
4635
4636 pattern_argument
4637         : pattern
4638           {
4639                 $$ = new Argument ((Expression) $1);
4640           }
4641         | IDENTIFIER COLON pattern
4642           {
4643                 var lt = (LocatedToken) $1;
4644                 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4645           }
4646         ;
4647
4648 shift_expression
4649         : additive_expression
4650         | shift_expression OP_SHIFT_LEFT additive_expression
4651           {
4652                 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4653                 lbag.AddLocation ($$, GetLocation ($2));
4654           }
4655         | shift_expression OP_SHIFT_RIGHT additive_expression
4656           {
4657                 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4658                 lbag.AddLocation ($$, GetLocation ($2));
4659           }
4660         | shift_expression OP_SHIFT_LEFT error
4661           {
4662                 Error_SyntaxError (yyToken);
4663
4664                 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4665                 lbag.AddLocation ($$, GetLocation ($2));
4666           }
4667         | shift_expression OP_SHIFT_RIGHT error
4668           {
4669                 Error_SyntaxError (yyToken);
4670
4671                 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4672                 lbag.AddLocation ($$, GetLocation ($2));
4673           }
4674         ; 
4675
4676 relational_expression
4677         : shift_expression
4678         | relational_expression OP_LT shift_expression
4679           {
4680                 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4681                 lbag.AddLocation ($$, GetLocation ($2));
4682           }
4683         | relational_expression OP_GT shift_expression
4684           {
4685                 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4686                 lbag.AddLocation ($$, GetLocation ($2));
4687           }
4688         | relational_expression OP_LE shift_expression
4689           {
4690                 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4691                 lbag.AddLocation ($$, GetLocation ($2));
4692           }
4693         | relational_expression OP_GE shift_expression
4694           {
4695                 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4696                 lbag.AddLocation ($$, GetLocation ($2));
4697           }
4698         | relational_expression OP_LT error
4699           {
4700                 Error_SyntaxError (yyToken);
4701
4702                 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4703                 lbag.AddLocation ($$, GetLocation ($2));
4704           }
4705         | relational_expression OP_GT error
4706           {
4707                 Error_SyntaxError (yyToken);
4708
4709                 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4710                 lbag.AddLocation ($$, GetLocation ($2));
4711           }
4712         | relational_expression OP_LE error
4713           {
4714                 Error_SyntaxError (yyToken);
4715
4716                 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4717                 lbag.AddLocation ($$, GetLocation ($2));
4718           }
4719         | relational_expression OP_GE error
4720           {
4721                 Error_SyntaxError (yyToken);
4722
4723                 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4724                 lbag.AddLocation ($$, GetLocation ($2));
4725           }
4726         ;
4727
4728 equality_expression
4729         : relational_expression
4730         | equality_expression OP_EQ relational_expression
4731           {
4732                 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4733                 lbag.AddLocation ($$, GetLocation ($2));
4734           }
4735         | equality_expression OP_NE relational_expression
4736           {
4737                 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4738                 lbag.AddLocation ($$, GetLocation ($2));
4739           }
4740         | equality_expression OP_EQ error
4741           {
4742                 Error_SyntaxError (yyToken);
4743
4744                 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4745                 lbag.AddLocation ($$, GetLocation ($2));
4746           }
4747         | equality_expression OP_NE error
4748           {
4749                 Error_SyntaxError (yyToken);
4750
4751                 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4752                 lbag.AddLocation ($$, GetLocation ($2));
4753           }
4754         ; 
4755
4756 and_expression
4757         : equality_expression
4758         | and_expression BITWISE_AND equality_expression
4759           {
4760                 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4761                 lbag.AddLocation ($$, GetLocation ($2));
4762           }
4763         | and_expression BITWISE_AND error
4764           {
4765                 Error_SyntaxError (yyToken);
4766
4767                 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4768                 lbag.AddLocation ($$, GetLocation ($2));
4769           }
4770         ;
4771
4772 exclusive_or_expression
4773         : and_expression
4774         | exclusive_or_expression CARRET and_expression
4775           {
4776                 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4777                 lbag.AddLocation ($$, GetLocation ($2));
4778           }
4779         | exclusive_or_expression CARRET error
4780           {
4781                 Error_SyntaxError (yyToken);
4782
4783                 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4784                 lbag.AddLocation ($$, GetLocation ($2));
4785           }
4786         ;
4787
4788 inclusive_or_expression
4789         : exclusive_or_expression
4790         | inclusive_or_expression BITWISE_OR exclusive_or_expression
4791           {
4792                 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4793                 lbag.AddLocation ($$, GetLocation ($2));
4794           }
4795         | inclusive_or_expression BITWISE_OR error
4796           {
4797                 Error_SyntaxError (yyToken);
4798
4799                 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4800                 lbag.AddLocation ($$, GetLocation ($2));
4801           }
4802         ;
4803
4804 conditional_and_expression
4805         : inclusive_or_expression
4806         | conditional_and_expression OP_AND inclusive_or_expression
4807           {
4808                 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4809                 lbag.AddLocation ($$, GetLocation ($2));
4810           }
4811         | conditional_and_expression OP_AND error
4812           {
4813                 Error_SyntaxError (yyToken);
4814
4815                 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4816                 lbag.AddLocation ($$, GetLocation ($2));
4817           }
4818         ;
4819
4820 conditional_or_expression
4821         : conditional_and_expression
4822         | conditional_or_expression OP_OR conditional_and_expression
4823           {
4824                 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4825                 lbag.AddLocation ($$, GetLocation ($2));
4826           }
4827         | conditional_or_expression OP_OR error
4828           {
4829                 Error_SyntaxError (yyToken);
4830
4831                 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4832                 lbag.AddLocation ($$, GetLocation ($2));
4833           }
4834         ;
4835         
4836 null_coalescing_expression
4837         : conditional_or_expression
4838         | conditional_or_expression OP_COALESCING null_coalescing_expression
4839           {
4840                 if (lang_version < LanguageVersion.ISO_2)
4841                         FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4842                         
4843                 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4844                 lbag.AddLocation ($$, GetLocation ($2));
4845           }
4846         ;
4847
4848 conditional_expression
4849         : null_coalescing_expression
4850         | null_coalescing_expression INTERR expression COLON expression
4851           {
4852                 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4853                 lbag.AddLocation ($$, GetLocation ($4));
4854           }
4855         | null_coalescing_expression INTERR expression COLON THROW prefixed_unary_expression
4856           {
4857                 if (lang_version < LanguageVersion.V_7)
4858                         FeatureIsNotAvailable (lexer.Location, "throw expression");
4859
4860                 var expr = new ThrowExpression ((Expression) $6, GetLocation ($5));
4861                 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, expr, GetLocation ($2));
4862                 lbag.AddLocation ($$, GetLocation ($4));
4863           }
4864         | null_coalescing_expression INTERR expression error
4865           {
4866                 Error_SyntaxError (yyToken);
4867
4868                 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4869           }
4870         | null_coalescing_expression INTERR expression COLON error
4871           {
4872                 Error_SyntaxError (yyToken);
4873
4874                 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4875                 lbag.AddLocation ($$, GetLocation ($4));
4876           }
4877         | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4878           {
4879                 Error_SyntaxError (Token.CLOSE_BRACE);
4880
4881                 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4882                 lbag.AddLocation ($$, GetLocation ($4));
4883                 lexer.putback ('}');
4884           }
4885         ;
4886
4887 assignment_expression
4888         : prefixed_unary_expression ASSIGN expression
4889           {
4890                 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4891                 lbag.AddLocation ($$, GetLocation ($2));
4892           }
4893         | prefixed_unary_expression OP_MULT_ASSIGN expression
4894           {
4895                 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4896                 lbag.AddLocation ($$, GetLocation ($2));
4897           }
4898         | prefixed_unary_expression OP_DIV_ASSIGN expression
4899           {
4900                 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4901                 lbag.AddLocation ($$, GetLocation ($2));
4902           }
4903         | prefixed_unary_expression OP_MOD_ASSIGN expression
4904           {
4905                 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4906                 lbag.AddLocation ($$, GetLocation ($2));
4907           }
4908         | prefixed_unary_expression OP_ADD_ASSIGN expression
4909           {
4910                 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4911                 lbag.AddLocation ($$, GetLocation ($2));
4912           }
4913         | prefixed_unary_expression OP_SUB_ASSIGN expression
4914           {
4915                 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4916                 lbag.AddLocation ($$, GetLocation ($2));
4917           }
4918         | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4919           {
4920                 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4921                 lbag.AddLocation ($$, GetLocation ($2));
4922           }
4923         | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4924           {
4925                 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4926                 lbag.AddLocation ($$, GetLocation ($2));
4927           }
4928         | prefixed_unary_expression OP_AND_ASSIGN expression
4929           {
4930                 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4931                 lbag.AddLocation ($$, GetLocation ($2));
4932           }
4933         | prefixed_unary_expression OP_OR_ASSIGN expression
4934           {
4935                 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4936                 lbag.AddLocation ($$, GetLocation ($2));
4937           }
4938         | prefixed_unary_expression OP_XOR_ASSIGN expression
4939           {
4940                 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4941                 lbag.AddLocation ($$, GetLocation ($2));
4942           }
4943         ;
4944
4945 lambda_parameter_list
4946         : lambda_parameter
4947           {
4948                 var pars = new List<Parameter> (4);
4949                 pars.Add ((Parameter) $1);
4950
4951                 $$ = pars;
4952           }
4953         | lambda_parameter_list COMMA lambda_parameter
4954           {
4955                 var pars = (List<Parameter>) $1;
4956                 Parameter p = (Parameter)$3;
4957                 if (pars[0].GetType () != p.GetType ()) {
4958                         report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4959                 }
4960                 
4961                 pars.Add (p);
4962                 $$ = pars;
4963           }
4964         ;
4965
4966 lambda_parameter
4967         : parameter_modifier parameter_type identifier_inside_body
4968           {
4969                 var lt = (LocatedToken) $3;
4970
4971                 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4972           }
4973         | parameter_type identifier_inside_body
4974           {
4975                 var lt = (LocatedToken) $2;
4976
4977                 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4978           }
4979         | IDENTIFIER
4980           {
4981                 var lt = (LocatedToken) $1;
4982                 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4983           }
4984         | AWAIT
4985           {
4986                 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4987                 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4988           }
4989         ;
4990
4991 opt_lambda_parameter_list
4992         : /* empty */                   { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4993         | lambda_parameter_list         { 
4994                 var pars_list = (List<Parameter>) $1;
4995                 $$ = new ParametersCompiled (pars_list.ToArray ());
4996           }
4997         ;
4998
4999 lambda_expression_body
5000         : {
5001                 start_block (Location.Null);
5002           }
5003           expression    // All expressions must handle error or current block won't be restored and breaking ast completely
5004           {
5005                 Block b = end_block (Location.Null);
5006                 b.IsCompilerGenerated = true;
5007                 b.AddStatement (new ContextualReturn ((Expression) $2));
5008                 $$ = b;
5009           } 
5010         | block
5011         | error
5012           {
5013                 // Handles only cases like foo = x.FirstOrDefault (l => );
5014                 // where we must restore current_variable
5015                 Block b = end_block (Location.Null);
5016                 b.IsCompilerGenerated = true;
5017
5018                 Error_SyntaxError (yyToken);
5019                 $$ = null;
5020           }
5021         ;
5022
5023 expression_or_error
5024         : expression
5025         | error
5026           {
5027                 Error_SyntaxError (yyToken);
5028                 $$ = null;
5029           }
5030         ;
5031         
5032 lambda_expression
5033         : IDENTIFIER ARROW 
5034           {
5035                 var lt = (LocatedToken) $1;     
5036                 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5037                 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5038           }
5039           lambda_expression_body
5040           {
5041                 $$ = end_anonymous ((ParametersBlock) $4);
5042                 lbag.AddLocation ($$, GetLocation ($2));
5043           }
5044         | AWAIT ARROW
5045           {
5046                 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5047                 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5048                 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5049           }
5050           lambda_expression_body
5051           {
5052                 $$ = end_anonymous ((ParametersBlock) $4);
5053                 lbag.AddLocation ($$, GetLocation ($2));
5054           }
5055         | ASYNC identifier_inside_body ARROW
5056           {
5057                 var lt = (LocatedToken) $2;
5058                 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5059                 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5060           }
5061           lambda_expression_body
5062           {
5063                 $$ = end_anonymous ((ParametersBlock) $5);
5064                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5065           }
5066         | OPEN_PARENS_LAMBDA
5067           {
5068                 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5069           }
5070           opt_lambda_parameter_list CLOSE_PARENS ARROW 
5071           {
5072                 valid_param_mod = 0;
5073                 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5074           }
5075           lambda_expression_body
5076           {
5077                 $$ = end_anonymous ((ParametersBlock) $7);
5078                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5079           }
5080         | ASYNC OPEN_PARENS_LAMBDA
5081           {
5082                 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;          
5083           }
5084           opt_lambda_parameter_list CLOSE_PARENS ARROW 
5085           {
5086                 valid_param_mod = 0;
5087                 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5088           }
5089           lambda_expression_body
5090           {
5091                 $$ = end_anonymous ((ParametersBlock) $8);
5092                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5093           }
5094         ;
5095
5096 expression
5097         : assignment_expression 
5098         | non_assignment_expression
5099         ;
5100         
5101 non_assignment_expression
5102         : conditional_expression
5103         | lambda_expression
5104         | query_expression
5105         | ARGLIST
5106           {
5107                 $$ = new ArglistAccess (GetLocation ($1));
5108           }
5109         ;
5110         
5111 undocumented_expressions
5112         : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5113           {
5114                 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5115                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5116           }
5117         | REFTYPE open_parens_any expression CLOSE_PARENS
5118           {
5119                 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5120                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5121           }
5122         | MAKEREF open_parens_any expression CLOSE_PARENS
5123           {
5124                 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5125                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));        
5126           }
5127         ;
5128
5129 constant_expression
5130         : expression
5131         ;
5132
5133 boolean_expression
5134         : expression
5135           {
5136                 $$ = new BooleanExpression ((Expression) $1);
5137           }
5138         ;
5139
5140 opt_primary_parameters
5141         : /* empty */
5142           {
5143                 $$ = null;
5144           }
5145         | primary_parameters
5146         ;
5147
5148 primary_parameters
5149         : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5150           {
5151                 $$ = $2;
5152
5153                 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5154                 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5155
5156                 if (lang_version != LanguageVersion.Experimental)
5157                         FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5158           }
5159         ;
5160
5161 opt_primary_parameters_with_class_base
5162         : /* empty */
5163           {
5164                 $$ = null;
5165           }
5166         | class_base
5167           {
5168                 $$ = null;
5169           }
5170         | primary_parameters
5171           {
5172                 $$ = $1;
5173           }
5174         | primary_parameters class_base
5175           {
5176                 $$ = $1;
5177           }
5178         | primary_parameters class_base OPEN_PARENS
5179           {
5180                 ++lexer.parsing_block;
5181                 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5182           }
5183           opt_argument_list CLOSE_PARENS
5184           {
5185                 lbag.AppendToMember (current_container, GetLocation ($6));
5186                 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5187                 --lexer.parsing_block;
5188
5189                 $$ = $1;
5190           }
5191         ;
5192
5193 //
5194 // 10 classes
5195 //
5196 class_declaration
5197         : opt_attributes
5198           opt_modifiers
5199           opt_partial
5200           CLASS
5201           {
5202           }
5203           type_declaration_name
5204           {
5205                 lexer.ConstraintsParsing = true;
5206
5207                 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5208                 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5209                         FeatureIsNotAvailable (c.Location, "static classes");
5210                 }
5211                         
5212                 push_current_container (c, $3);
5213                 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5214           }
5215           opt_primary_parameters_with_class_base
5216           opt_type_parameter_constraints_clauses
5217           {
5218                 valid_param_mod = 0;
5219                 lexer.ConstraintsParsing = false;
5220
5221                 if ($8 != null)
5222                         current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5223
5224                 if ($9 != null)
5225                         current_container.SetConstraints ((List<Constraints>) $9);
5226                 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5227
5228                 if (doc_support) {
5229                         current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5230                         Lexer.doc_state = XmlCommentState.Allowed;
5231                 }
5232                 
5233                 lexer.parsing_modifiers = true;
5234           }
5235           OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5236           {
5237                 --lexer.parsing_declaration;
5238                 if (doc_support)
5239                         Lexer.doc_state = XmlCommentState.Allowed;
5240           }
5241           opt_semicolon 
5242           {
5243                 if ($15 == null) {
5244                         lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5245                 } else {
5246                         lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5247                 }
5248                 $$ = pop_current_class ();
5249           }
5250         ;       
5251
5252 opt_partial
5253         : /* empty */
5254           { $$ = null; }
5255         | PARTIAL
5256           { $$ = $1; } // location
5257         ;
5258
5259 opt_modifiers
5260         : /* empty */
5261           {
5262             mod_locations = null;
5263                 $$ = ModifierNone;
5264                 lexer.parsing_modifiers = false;
5265           }
5266         | modifiers
5267           {
5268                 lexer.parsing_modifiers = false;                
5269           }
5270         ;
5271
5272 modifiers
5273         : modifier
5274         | modifiers modifier
5275           { 
5276                 var m1 = (Modifiers) $1;
5277                 var m2 = (Modifiers) $2;
5278
5279                 if ((m1 & m2) != 0) {
5280                         report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5281                                 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5282                 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5283                         ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5284                         report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5285                                 "More than one protection modifier specified");
5286                 }
5287                 
5288                 $$ = m1 | m2;
5289           }
5290         ;
5291
5292 modifier
5293         : NEW
5294           {
5295                 $$ = Modifiers.NEW;
5296                 StoreModifierLocation ($$, GetLocation ($1));
5297                 
5298                 if (current_container.Kind == MemberKind.Namespace)
5299                         report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5300           }
5301         | PUBLIC
5302           {
5303                 $$ = Modifiers.PUBLIC;
5304                 StoreModifierLocation ($$, GetLocation ($1));
5305           }
5306         | PROTECTED
5307           {
5308                 $$ = Modifiers.PROTECTED;
5309                 StoreModifierLocation ($$, GetLocation ($1));
5310           }
5311         | INTERNAL
5312           {
5313                 $$ = Modifiers.INTERNAL;
5314                 StoreModifierLocation ($$, GetLocation ($1));
5315           }
5316         | PRIVATE
5317           {
5318                 $$ = Modifiers.PRIVATE;
5319                 StoreModifierLocation ($$, GetLocation ($1));
5320           }
5321         | ABSTRACT
5322           {
5323                 $$ = Modifiers.ABSTRACT;
5324                 StoreModifierLocation ($$, GetLocation ($1));
5325           }
5326         | SEALED
5327           {
5328                 $$ = Modifiers.SEALED;
5329                 StoreModifierLocation ($$, GetLocation ($1));
5330           }
5331         | STATIC
5332           {
5333                 $$ = Modifiers.STATIC;
5334                 StoreModifierLocation ($$, GetLocation ($1));
5335           }
5336         | READONLY
5337           {
5338                 $$ = Modifiers.READONLY;
5339                 StoreModifierLocation ($$, GetLocation ($1));
5340           }
5341         | VIRTUAL
5342           {
5343                 $$ = Modifiers.VIRTUAL;
5344                 StoreModifierLocation ($$, GetLocation ($1));
5345           }
5346         | OVERRIDE
5347           {
5348                 $$ = Modifiers.OVERRIDE;
5349                 StoreModifierLocation ($$, GetLocation ($1));
5350           }
5351         | EXTERN
5352           {
5353                 $$ = Modifiers.EXTERN;
5354                 StoreModifierLocation ($$, GetLocation ($1));
5355           }
5356         | VOLATILE
5357           {
5358                 $$ = Modifiers.VOLATILE;
5359                 StoreModifierLocation ($$, GetLocation ($1));
5360           }
5361         | UNSAFE
5362           {
5363                 $$ = Modifiers.UNSAFE;
5364                 StoreModifierLocation ($$, GetLocation ($1));
5365                 if (!settings.Unsafe)
5366                         Error_UnsafeCodeNotAllowed (GetLocation ($1));
5367           }
5368         | ASYNC
5369           {
5370                 $$ = Modifiers.ASYNC;
5371                 StoreModifierLocation ($$, GetLocation ($1));
5372           }
5373         ;
5374         
5375 opt_class_base
5376         : /* empty */
5377         | class_base
5378         ;
5379
5380 class_base
5381         : COLON type_list
5382          {
5383                 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5384          }
5385         | COLON type_list error
5386           {
5387                 Error_SyntaxError (yyToken);
5388
5389                 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5390           }
5391         ;
5392
5393 opt_type_parameter_constraints_clauses
5394         : /* empty */
5395         | type_parameter_constraints_clauses 
5396           {
5397                 $$ = $1;
5398           }
5399         ;
5400
5401 type_parameter_constraints_clauses
5402         : type_parameter_constraints_clause
5403           {
5404                 var constraints = new List<Constraints> (1);
5405                 constraints.Add ((Constraints) $1);
5406                 $$ = constraints;
5407           }
5408         | type_parameter_constraints_clauses type_parameter_constraints_clause
5409           {
5410                 var constraints = (List<Constraints>) $1;
5411                 Constraints new_constraint = (Constraints)$2;
5412
5413                 foreach (Constraints c in constraints) {
5414                         if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5415                                 report.Error (409, new_constraint.Location,
5416                                         "A constraint clause has already been specified for type parameter `{0}'",
5417                                         new_constraint.TypeParameter.Value);
5418                         }
5419                 }
5420
5421                 constraints.Add (new_constraint);
5422                 $$ = constraints;
5423           }
5424         ; 
5425
5426 type_parameter_constraints_clause
5427         : WHERE IDENTIFIER COLON type_parameter_constraints
5428           {
5429                 var lt = (LocatedToken) $2;
5430                 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5431                 lbag.AddLocation ($$, GetLocation ($3));
5432           }
5433         | WHERE IDENTIFIER error
5434           {
5435                 Error_SyntaxError (yyToken);
5436           
5437                 var lt = (LocatedToken) $2;
5438                 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5439           }
5440         ; 
5441
5442 type_parameter_constraints
5443         : type_parameter_constraint
5444           {
5445                 var constraints = new List<FullNamedExpression> (1);
5446                 constraints.Add ((FullNamedExpression) $1);
5447                 $$ = constraints;
5448           }
5449         | type_parameter_constraints COMMA type_parameter_constraint
5450           {
5451                 var constraints = (List<FullNamedExpression>) $1;
5452                 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5453                 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {                   
5454                         report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5455                 }
5456                 
5457                 prev = $3 as SpecialContraintExpr;
5458                 if (prev != null) {
5459                         if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5460                                 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");                 
5461                         } else {
5462                                 prev = constraints [0] as SpecialContraintExpr;
5463                                 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {                        
5464                                         report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5465                                 }
5466                         }
5467                 }
5468
5469                 constraints.Add ((FullNamedExpression) $3);
5470                 $$ = constraints;
5471           }
5472         ;
5473
5474 type_parameter_constraint
5475         : type
5476           {
5477                 if ($1 is ComposedCast)
5478                         report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5479           
5480                 $$ = $1;
5481           }
5482         | NEW OPEN_PARENS CLOSE_PARENS
5483           {
5484                 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5485                 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5486           }
5487         | CLASS
5488           {
5489                 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5490           }
5491         | STRUCT
5492           {
5493                 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5494           }
5495         ;
5496
5497 opt_type_parameter_variance
5498         : /* empty */
5499           {
5500                 $$ = null;
5501           }
5502         | type_parameter_variance
5503           {
5504                 if (lang_version <= LanguageVersion.V_3)
5505                         FeatureIsNotAvailable (lexer.Location, "generic type variance");
5506                 
5507                 $$ = $1;
5508           }
5509         ;
5510
5511 type_parameter_variance
5512         : OUT
5513           {
5514                 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5515           }
5516         | IN
5517           {
5518                 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5519           }
5520         ;
5521
5522 //
5523 // Statements (8.2)
5524 //
5525
5526 //
5527 // A block is "contained" on the following places:
5528 //      method_body
5529 //      property_declaration as part of the accessor body (get/set)
5530 //      operator_declaration
5531 //      constructor_declaration
5532 //      destructor_declaration
5533 //      event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5534 //      
5535 block
5536         : OPEN_BRACE  
5537           {
5538                 ++lexer.parsing_block;
5539                 start_block (GetLocation ($1));
5540           } 
5541           opt_statement_list block_end
5542           {
5543                 $$ = $4;
5544           }
5545         ;
5546
5547 block_end 
5548         : CLOSE_BRACE 
5549           {
5550                 --lexer.parsing_block;
5551                 $$ = end_block (GetLocation ($1));
5552           }
5553         | COMPLETE_COMPLETION
5554           {
5555                 --lexer.parsing_block;
5556                 $$ = end_block (lexer.Location);
5557           }
5558         ;
5559
5560
5561 block_prepared
5562         : OPEN_BRACE
5563           {
5564                 ++lexer.parsing_block;
5565                 current_block.StartLocation = GetLocation ($1);
5566           }
5567           opt_statement_list CLOSE_BRACE 
5568           {
5569                 --lexer.parsing_block;
5570                 $$ = end_block (GetLocation ($4));
5571           }
5572         ;
5573
5574 opt_statement_list
5575         : /* empty */
5576         | statement_list 
5577         ;
5578
5579 statement_list
5580         : statement
5581         | statement_list statement
5582         ;
5583
5584 statement
5585         : block_variable_declaration
5586           {
5587                 current_block.AddStatement ((Statement) $1);
5588           }
5589         | valid_declaration_statement
5590           {
5591                 current_block.AddStatement ((Statement) $1);
5592           }
5593         | labeled_statement
5594         | error
5595           {
5596                 Error_SyntaxError (yyToken);
5597                 $$ = null;
5598           }
5599         ;
5600
5601 //
5602 // The interactive_statement and its derivatives are only 
5603 // used to provide a special version of `expression_statement'
5604 // that has a side effect of assigning the expression to
5605 // $retval
5606 //
5607 interactive_statement_list
5608         : interactive_statement
5609         | interactive_statement_list interactive_statement
5610         ;
5611
5612 interactive_statement
5613         : block_variable_declaration
5614           {
5615                 current_block.AddStatement ((Statement) $1);
5616           }
5617         | interactive_valid_declaration_statement
5618           {
5619                 current_block.AddStatement ((Statement) $1);
5620           }
5621         | labeled_statement
5622         ;
5623
5624 valid_declaration_statement
5625         : block
5626         | empty_statement
5627         | expression_statement
5628         | selection_statement
5629         | iteration_statement
5630         | jump_statement                  
5631         | try_statement
5632         | checked_statement
5633         | unchecked_statement
5634         | lock_statement
5635         | using_statement
5636         | unsafe_statement
5637         | fixed_statement
5638         ;
5639
5640 interactive_valid_declaration_statement
5641         : block
5642         | empty_statement
5643         | interactive_expression_statement
5644         | selection_statement
5645         | iteration_statement
5646         | jump_statement                  
5647         | try_statement
5648         | checked_statement
5649         | unchecked_statement
5650         | lock_statement
5651         | using_statement
5652         | unsafe_statement
5653         | fixed_statement
5654         ;
5655
5656 embedded_statement
5657         : valid_declaration_statement
5658         | block_variable_declaration
5659           {
5660                   report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5661                   $$ = null;
5662           }
5663         | labeled_statement
5664           {
5665                   report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5666                   $$ = null;
5667           }
5668         | error
5669           {
5670                 Error_SyntaxError (yyToken);
5671                 $$ = new EmptyStatement (GetLocation ($1));
5672           }
5673         ;
5674
5675 empty_statement
5676         : SEMICOLON
5677           {
5678                 // Uses lexer.Location because semicolon location is not kept in quick mode
5679                 $$ = new EmptyStatement (lexer.Location);
5680           }
5681         ;
5682
5683 labeled_statement
5684         : identifier_inside_body COLON 
5685           {
5686                 var lt = (LocatedToken) $1;
5687                 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5688                 lbag.AddLocation (labeled, GetLocation ($2));
5689                 current_block.AddLabel (labeled);
5690                 current_block.AddStatement (labeled);
5691           }
5692           statement
5693         ;
5694
5695 variable_type
5696         : variable_type_simple
5697         | variable_type_simple rank_specifiers
5698           {
5699                 if ($1 is VarExpr)
5700                         $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5701           
5702                 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5703           }
5704         ;
5705
5706 /* 
5707  * The following is from Rhys' grammar:
5708  * > Types in local variable declarations must be recognized as 
5709  * > expressions to prevent reduce/reduce errors in the grammar.
5710  * > The expressions are converted into types during semantic analysis.
5711  */
5712 variable_type_simple
5713         : type_name_expression opt_nullable
5714           { 
5715                 // Ok, the above "primary_expression" is there to get rid of
5716                 // both reduce/reduce and shift/reduces in the grammar, it should
5717                 // really just be "type_name".  If you use type_name, a reduce/reduce
5718                 // creeps up.  If you use namespace_or_type_name (which is all we need
5719                 // really) two shift/reduces appear.
5720                 // 
5721
5722                 // So the super-trick is that primary_expression
5723                 // can only be either a SimpleName or a MemberAccess. 
5724                 // The MemberAccess case arises when you have a fully qualified type-name like :
5725                 // Foo.Bar.Blah i;
5726                 // SimpleName is when you have
5727                 // Blah i;
5728                 
5729                 var expr = (ATypeNameExpression) $1;
5730                 if ($2 == null) {
5731                         if (expr.Name == "var" && expr is SimpleName)
5732                                 $$ = new VarExpr (expr.Location);
5733                         else
5734                                 $$ = $1;
5735                 } else {
5736                         $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5737                 }
5738           }
5739         | type_name_expression pointer_stars
5740           {
5741                 var expr = (ATypeNameExpression) $1;
5742                 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5743           }
5744         | builtin_type_expression
5745         | void_invalid
5746         ;
5747         
5748 pointer_stars
5749         : pointer_star
5750         | pointer_star pointer_stars
5751           {
5752                 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5753                 $$ = $1;
5754           }       
5755         ;
5756
5757 pointer_star
5758         : STAR
5759           {
5760                 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5761           }
5762         ;
5763
5764 identifier_inside_body
5765         : IDENTIFIER
5766         | AWAIT
5767           {
5768                 $$ = Error_AwaitAsIdentifier ($1);
5769           }
5770         ;
5771
5772 block_variable_declaration
5773         : variable_type identifier_inside_body
5774           {
5775                 var lt = (LocatedToken) $2;
5776                 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5777                 current_block.AddLocalName (li);
5778                 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5779           }
5780           opt_local_variable_initializer opt_variable_declarators SEMICOLON
5781           {
5782                 $$ = current_variable;
5783                 current_variable = null;
5784                 if ($4 != null)
5785                         lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5786                 else
5787                         lbag.AddLocation ($$, GetLocation ($6));
5788           }
5789         | CONST variable_type identifier_inside_body
5790           {
5791                 var lt = (LocatedToken) $3;
5792                 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5793                 current_block.AddLocalName (li);
5794                 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5795           }
5796           const_variable_initializer opt_const_declarators SEMICOLON
5797           {
5798                 $$ = current_variable;
5799                 current_variable = null;
5800                 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5801           }
5802         ;
5803
5804 opt_local_variable_initializer
5805         : /* empty */
5806         | ASSIGN block_variable_initializer
5807           {
5808                 current_variable.Initializer = (Expression) $2;
5809                 PushLocation (GetLocation ($1));
5810                 $$ = current_variable;
5811           }
5812         | error
5813           {
5814                 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5815                         report.Error (650, lexer.Location,
5816                                 "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type");
5817                 } else {
5818                         Error_SyntaxError (yyToken);
5819                 }
5820           }
5821         ;
5822
5823 opt_variable_declarators
5824         : /* empty */
5825         | variable_declarators
5826         ;
5827         
5828 opt_using_or_fixed_variable_declarators
5829         : /* empty */
5830         | variable_declarators
5831           {
5832                 foreach (var d in current_variable.Declarators) {
5833                         if (d.Initializer == null)
5834                                 Error_MissingInitializer (d.Variable.Location);
5835                 }
5836           }
5837         ;       
5838         
5839 variable_declarators
5840         : variable_declarator
5841         | variable_declarators variable_declarator
5842         ;
5843         
5844 variable_declarator
5845         : COMMA identifier_inside_body
5846           {
5847                 var lt = (LocatedToken) $2;       
5848                 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5849                 var d = new BlockVariableDeclarator (li, null);
5850                 current_variable.AddDeclarator (d);
5851                 current_block.AddLocalName (li);
5852                 lbag.AddLocation (d, GetLocation ($1));
5853           }
5854         | COMMA identifier_inside_body ASSIGN block_variable_initializer
5855           {
5856                 var lt = (LocatedToken) $2;       
5857                 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5858                 var d = new BlockVariableDeclarator (li, (Expression) $4);
5859                 current_variable.AddDeclarator (d);
5860                 current_block.AddLocalName (li);
5861                 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5862           }
5863         ;
5864         
5865 const_variable_initializer
5866         : /* empty */
5867           {
5868                 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5869           }
5870         | ASSIGN constant_initializer_expr 
5871           {
5872                 current_variable.Initializer = (Expression) $2;
5873           }
5874         ;
5875         
5876 opt_const_declarators
5877         : /* empty */
5878         | const_declarators
5879         ;
5880         
5881 const_declarators
5882         : const_declarator
5883         | const_declarators const_declarator
5884         ;
5885         
5886 const_declarator
5887         : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5888           {
5889                 var lt = (LocatedToken) $2;       
5890                 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5891                 var d = new BlockVariableDeclarator (li, (Expression) $4);
5892                 current_variable.AddDeclarator (d);
5893                 current_block.AddLocalName (li);
5894                 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5895           }
5896         ;
5897         
5898 block_variable_initializer
5899         : variable_initializer
5900         | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5901           {
5902                 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5903                 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5904           }
5905         | STACKALLOC simple_type
5906           {
5907                 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5908                 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));          
5909           }
5910         ;
5911
5912 expression_statement
5913         : statement_expression SEMICOLON
5914           {
5915                 $$ = $1;
5916                 lbag.AddStatement ($$, GetLocation ($2));
5917           }
5918         | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5919         | statement_expression CLOSE_BRACE
5920           {
5921                 $$ = $1;
5922                 report.Error (1002, GetLocation ($2), "; expected");
5923                 lexer.putback ('}');
5924           }
5925         ;
5926
5927 interactive_expression_statement
5928         : interactive_statement_expression SEMICOLON { $$ = $1; }
5929         | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5930         ;
5931
5932         //
5933         // We have to do the wrapping here and not in the case above,
5934         // because statement_expression is used for example in for_statement
5935         //
5936 statement_expression
5937         : expression
5938           {
5939                 ExpressionStatement s = $1 as ExpressionStatement;
5940                 if (s == null) {
5941                         var expr = $1 as Expression;
5942                         $$ = new StatementErrorExpression (expr);
5943                 } else {
5944                         $$ = new StatementExpression (s);
5945                 }
5946           }
5947         ;
5948
5949 interactive_statement_expression
5950         : expression
5951           {
5952                 Expression expr = (Expression) $1;
5953                 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5954           }
5955         | error
5956           {
5957                 Error_SyntaxError (yyToken);
5958                 $$ = new EmptyStatement (GetLocation ($1));
5959           }
5960         ;
5961         
5962 selection_statement
5963         : if_statement
5964         | switch_statement
5965         ; 
5966
5967 if_statement
5968         : IF open_parens_any boolean_expression CLOSE_PARENS 
5969           embedded_statement
5970           { 
5971                 if ($5 is EmptyStatement)
5972                         Warning_EmptyStatement (GetLocation ($5));
5973                 
5974                 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5975                 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5976           }
5977         | IF open_parens_any boolean_expression CLOSE_PARENS
5978           embedded_statement ELSE embedded_statement
5979           {
5980                 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5981                 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5982                 
5983                 if ($5 is EmptyStatement)
5984                         Warning_EmptyStatement (GetLocation ($5));
5985                 if ($7 is EmptyStatement)
5986                         Warning_EmptyStatement (GetLocation ($7));
5987           }
5988         | IF open_parens_any boolean_expression error
5989           {
5990                 Error_SyntaxError (yyToken);
5991                 
5992                 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5993                 lbag.AddStatement ($$, GetLocation ($2));
5994           }
5995         ;
5996
5997 switch_statement
5998         : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5999           {
6000                 start_block (GetLocation ($5));
6001           }
6002           opt_switch_sections CLOSE_BRACE
6003           {
6004                 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));    
6005                 end_block (GetLocation ($8));
6006                 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6007           }
6008         | SWITCH open_parens_any expression error
6009           {
6010                 Error_SyntaxError (yyToken);
6011           
6012                 $$ = new Switch ((Expression) $3, null, GetLocation ($1));      
6013                 lbag.AddStatement ($$, GetLocation ($2));
6014           }
6015         ;
6016
6017 opt_switch_sections
6018         : /* empty */           
6019       {
6020                 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block"); 
6021           }
6022         | switch_sections
6023         ;
6024
6025 switch_sections
6026         : switch_section 
6027         | switch_sections switch_section
6028         | error
6029           {
6030                 Error_SyntaxError (yyToken);
6031           } 
6032         ;
6033
6034 switch_section
6035         : switch_labels statement_list 
6036         ;
6037
6038 switch_labels
6039         : switch_label 
6040           {
6041                 var label = (SwitchLabel) $1;
6042                 label.SectionStart = true;
6043                 current_block.AddStatement (label);
6044           }
6045         | switch_labels switch_label 
6046           {
6047                 current_block.AddStatement ((Statement) $2);
6048           }
6049         ;
6050
6051 switch_label
6052         : CASE constant_expression COLON
6053          {
6054                 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6055                 lbag.AddLocation ($$, GetLocation ($3));
6056          }
6057         | CASE constant_expression error
6058           {
6059                 Error_SyntaxError (yyToken);
6060                 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6061           }
6062 /*        
6063         | CASE pattern_expr_invocation COLON
6064           {
6065                 if (lang_version != LanguageVersion.Experimental)
6066                         FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6067
6068                 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6069                         PatternMatching = true
6070                 };
6071                 lbag.AddLocation ($$, GetLocation ($3));
6072           }
6073 */
6074         | DEFAULT_COLON
6075           {
6076                 $$ = new SwitchLabel (null, GetLocation ($1));
6077           }
6078         ;
6079
6080 iteration_statement
6081         : while_statement
6082         | do_statement
6083         | for_statement
6084         | foreach_statement
6085         ;
6086
6087 while_statement
6088         : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6089           {
6090                 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6091                         Warning_EmptyStatement (GetLocation ($5));
6092           
6093                 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6094                 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6095           }
6096         | WHILE open_parens_any boolean_expression error
6097           {
6098                 Error_SyntaxError (yyToken);
6099                 
6100                 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6101                 lbag.AddStatement ($$, GetLocation ($2));
6102           }
6103         ;
6104
6105 do_statement
6106         : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6107           {
6108                 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6109                 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6110           }
6111         | DO embedded_statement error
6112           {
6113                 Error_SyntaxError (yyToken);
6114                 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6115           }
6116         | DO embedded_statement WHILE open_parens_any boolean_expression error
6117           {
6118                 Error_SyntaxError (yyToken);
6119           
6120                 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6121                 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6122           }
6123         ;
6124
6125 for_statement
6126         : FOR open_parens_any
6127           {
6128                 start_block (GetLocation ($2));
6129                 current_block.IsCompilerGenerated = true;
6130                 For f = new For (GetLocation ($1));
6131                 current_block.AddStatement (f);
6132                 $$ = f;
6133           }
6134           for_statement_cont
6135           {
6136                 $$ = $4;
6137           }
6138         ;
6139         
6140 // Has to use be extra rule to recover started block
6141 for_statement_cont
6142         : opt_for_initializer SEMICOLON
6143           {
6144                 ((For) $0).Initializer = (Statement) $1;
6145
6146                 // Pass the "For" object to the iterator_part4
6147                 oob_stack.Push ($0);
6148           }
6149           for_condition_and_iterator_part
6150           embedded_statement
6151           {
6152                 var locations = (Tuple<Location,Location>) $4;
6153                 oob_stack.Pop ();
6154                 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6155                         Warning_EmptyStatement (GetLocation ($5));
6156           
6157                 For f = ((For) $0);
6158                 f.Statement = (Statement) $5;
6159                 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6160
6161                 $$ = end_block (GetLocation ($2));
6162           }
6163         | error
6164           {
6165                 Error_SyntaxError (yyToken);
6166                 $$ = end_block (current_block.StartLocation);
6167           }
6168         ;
6169
6170 for_condition_and_iterator_part
6171         : opt_for_condition SEMICOLON
6172           {
6173                 For f = (For) oob_stack.Peek ();
6174                 f.Condition = (BooleanExpression) $1;
6175           }
6176           for_iterator_part {
6177                 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6178           }
6179
6180         // Handle errors in the case of opt_for_condition being followed by
6181         // a close parenthesis
6182         | opt_for_condition close_parens_close_brace {
6183                 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6184                 For f = (For) oob_stack.Peek ();
6185                 f.Condition = (BooleanExpression) $1;
6186                 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6187           }
6188         ;
6189
6190 for_iterator_part
6191         : opt_for_iterator CLOSE_PARENS {
6192                 For f = (For) oob_stack.Peek ();
6193                 f.Iterator = (Statement) $1;
6194                 $$ = GetLocation ($2);
6195           }
6196         | opt_for_iterator CLOSE_BRACE {
6197                 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6198                 For f = (For) oob_stack.Peek ();
6199                 f.Iterator = (Statement) $1;
6200                 $$ = GetLocation ($2);
6201           }
6202         ; 
6203
6204 close_parens_close_brace 
6205         : CLOSE_PARENS
6206         | CLOSE_BRACE { lexer.putback ('}'); }
6207         ;
6208
6209 opt_for_initializer
6210         : /* empty */           { $$ = new EmptyStatement (lexer.Location); }
6211         | for_initializer       
6212         ;
6213
6214 for_initializer
6215         : variable_type identifier_inside_body
6216           {
6217                 var lt = (LocatedToken) $2;
6218                 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6219                 current_block.AddLocalName (li);
6220                 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6221           }
6222           opt_local_variable_initializer opt_variable_declarators
6223           {
6224                 $$ = current_variable;
6225                 if ($4 != null)
6226                         lbag.AddLocation (current_variable, PopLocation ());
6227
6228                 current_variable = null;
6229           }
6230         | statement_expression_list
6231         ;
6232
6233 opt_for_condition
6234         : /* empty */           { $$ = null; }
6235         | boolean_expression
6236         ;
6237
6238 opt_for_iterator
6239         : /* empty */           { $$ = new EmptyStatement (lexer.Location); }
6240         | for_iterator
6241         ;
6242
6243 for_iterator
6244         : statement_expression_list
6245         ;
6246
6247 statement_expression_list
6248         : statement_expression
6249         | statement_expression_list COMMA statement_expression
6250           {
6251                 var sl = $1 as StatementList;
6252                 if (sl == null) {
6253                         sl = new StatementList ((Statement) $1, (Statement) $3);
6254                         lbag.AddStatement (sl, GetLocation ($2));
6255                 } else {
6256                         sl.Add ((Statement) $3);
6257                         lbag.AppendTo (sl, GetLocation ($2));
6258                 }
6259                         
6260                 $$ = sl;
6261           }
6262         ;
6263
6264 foreach_statement
6265         : FOREACH open_parens_any type error
6266           {
6267                 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6268
6269                 start_block (GetLocation ($2));
6270                 current_block.IsCompilerGenerated = true;
6271                 
6272                 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6273                 current_block.AddStatement (f);
6274                 
6275                 lbag.AddStatement (f, GetLocation ($2));
6276                 $$ = end_block (GetLocation ($4));
6277           }
6278         | FOREACH open_parens_any type identifier_inside_body error
6279           {
6280                 Error_SyntaxError (yyToken);
6281         
6282                 start_block (GetLocation ($2));
6283                 current_block.IsCompilerGenerated = true;
6284                 
6285                 var lt = (LocatedToken) $4;
6286                 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6287                 current_block.AddLocalName (li);
6288                 
6289                 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6290                 current_block.AddStatement (f);
6291                 
6292                 lbag.AddStatement (f, GetLocation ($2));
6293                 $$ = end_block (GetLocation ($5));
6294           }
6295         | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS 
6296           {
6297                 start_block (GetLocation ($2));
6298                 current_block.IsCompilerGenerated = true;
6299                 
6300                 var lt = (LocatedToken) $4;
6301                 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6302                 current_block.AddLocalName (li);
6303                 $$ = li;
6304           } 
6305           embedded_statement
6306           {
6307                 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6308                         Warning_EmptyStatement (GetLocation ($9));
6309                 
6310                 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6311                 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6312                 end_block (GetLocation ($7));
6313                 
6314                 $$ = f;
6315           }
6316         ;
6317
6318 jump_statement
6319         : break_statement
6320         | continue_statement
6321         | goto_statement
6322         | return_statement
6323         | throw_statement
6324         | yield_statement
6325         ;
6326
6327 break_statement
6328         : BREAK SEMICOLON
6329           {
6330                 $$ = new Break (GetLocation ($1));
6331                 lbag.AddStatement ($$, GetLocation ($2));
6332           }
6333         ;
6334
6335 continue_statement
6336         : CONTINUE SEMICOLON
6337           {
6338                 $$ = new Continue (GetLocation ($1));
6339                 lbag.AddStatement ($$, GetLocation ($2));
6340           }
6341         | CONTINUE error
6342           {
6343                 Error_SyntaxError (yyToken);
6344                 $$ = new Continue (GetLocation ($1));
6345           }
6346         ;
6347
6348 goto_statement
6349         : GOTO identifier_inside_body SEMICOLON 
6350           {
6351                 var lt = (LocatedToken) $2;
6352                 $$ = new Goto (lt.Value, GetLocation ($1));
6353                 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6354           }
6355         | GOTO CASE constant_expression SEMICOLON
6356           {
6357                 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6358                 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6359           }
6360         | GOTO DEFAULT SEMICOLON 
6361           {
6362                 $$ = new GotoDefault (GetLocation ($1));
6363                 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6364           }
6365         ; 
6366
6367 return_statement
6368         : RETURN opt_expression SEMICOLON
6369           {
6370                 $$ = new Return ((Expression) $2, GetLocation ($1));
6371                 lbag.AddStatement ($$, GetLocation ($3));
6372           }
6373         | RETURN expression error
6374           {
6375                 Error_SyntaxError (yyToken);
6376                 $$ = new Return ((Expression) $2, GetLocation ($1));
6377           }
6378         | RETURN error
6379           {
6380                 Error_SyntaxError (yyToken);
6381                 $$ = new Return (null, GetLocation ($1));
6382           }
6383         ;
6384
6385 throw_statement
6386         : THROW expression SEMICOLON
6387           {
6388                 $$ = new Throw ((Expression) $2, GetLocation ($1));
6389                 lbag.AddStatement ($$, GetLocation ($3));
6390           }
6391         | THROW SEMICOLON
6392           {
6393                 $$ = new Throw (null, GetLocation ($1));
6394                 lbag.AddStatement ($$, GetLocation ($2));
6395           }
6396         | THROW expression error
6397           {
6398                 Error_SyntaxError (yyToken);
6399                 $$ = new Throw ((Expression) $2, GetLocation ($1));
6400           }
6401         | THROW error
6402           {
6403                 Error_SyntaxError (yyToken);
6404                 $$ = new Throw (null, GetLocation ($1));
6405           }
6406         ;
6407
6408 yield_statement 
6409         : identifier_inside_body RETURN opt_expression SEMICOLON
6410           {
6411                 var lt = (LocatedToken) $1;
6412                 string s = lt.Value;
6413                 if (s != "yield"){
6414                         report.Error (1003, lt.Location, "; expected");
6415                 } else if ($3 == null) {
6416                         report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6417                 } else if (lang_version == LanguageVersion.ISO_1){
6418                         FeatureIsNotAvailable (lt.Location, "iterators");
6419                 }
6420                 
6421                 current_block.Explicit.RegisterIteratorYield ();
6422                 $$ = new Yield ((Expression) $3, lt.Location);
6423                 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6424           }
6425         | identifier_inside_body RETURN expression error
6426           {
6427                 Error_SyntaxError (yyToken);
6428
6429                 var lt = (LocatedToken) $1;
6430                 string s = lt.Value;
6431                 if (s != "yield"){
6432                         report.Error (1003, lt.Location, "; expected");
6433                 } else if ($3 == null) {
6434                         report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6435                 } else if (lang_version == LanguageVersion.ISO_1){
6436                         FeatureIsNotAvailable (lt.Location, "iterators");
6437                 }
6438                 
6439                 current_block.Explicit.RegisterIteratorYield ();
6440                 $$ = new Yield ((Expression) $3, lt.Location);
6441                 lbag.AddStatement ($$, GetLocation ($2));
6442           }
6443         | identifier_inside_body BREAK SEMICOLON
6444           {
6445                 var lt = (LocatedToken) $1;
6446                 string s = lt.Value;
6447                 if (s != "yield"){
6448                         report.Error (1003, lt.Location, "; expected");
6449                 } else if (lang_version == LanguageVersion.ISO_1){
6450                         FeatureIsNotAvailable (lt.Location, "iterators");
6451                 }
6452                 
6453                 current_block.ParametersBlock.TopBlock.IsIterator = true;
6454                 $$ = new YieldBreak (lt.Location);
6455                 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6456           }
6457         ;
6458
6459 opt_expression
6460         : /* empty */
6461         | expression
6462         ;
6463
6464 try_statement
6465         : TRY block catch_clauses
6466           {
6467                 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6468           }
6469         | TRY block FINALLY block
6470           {
6471                 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6472                 lbag.AddStatement ($$, GetLocation ($3));
6473           }
6474         | TRY block catch_clauses FINALLY block
6475           {
6476                 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6477                 lbag.AddStatement ($$, GetLocation ($4));
6478           }
6479         | TRY block error
6480           {
6481                 Error_SyntaxError (1524, yyToken);
6482                 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6483           }
6484         ;
6485
6486 catch_clauses
6487         : catch_clause 
6488           {
6489                 var l = new List<Catch> (2);
6490
6491                 l.Add ((Catch) $1);
6492                 $$ = l;
6493           }
6494         | catch_clauses catch_clause
6495           {
6496                 var l = (List<Catch>) $1;
6497                 
6498                 Catch c = (Catch) $2;
6499                 var prev_catch = l [l.Count - 1];
6500                 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6501                         report.Error (1017, c.loc, "Try statement already has an empty catch block");
6502                 }
6503                 
6504                 l.Add (c);
6505                 $$ = l;
6506           }
6507         ;
6508
6509 opt_identifier
6510         : /* empty */
6511         | identifier_inside_body
6512         ;
6513
6514 catch_clause 
6515         : CATCH opt_catch_filter block
6516           {
6517                 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6518                 c.Filter = (CatchFilterExpression) $2;
6519                 $$ = c;
6520           }
6521         | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6522           {
6523                 start_block (GetLocation ($2));
6524                 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6525                 c.TypeExpression = (FullNamedExpression) $3;
6526
6527                 if ($4 != null) {
6528                         var lt = (LocatedToken) $4;
6529                         c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6530                         current_block.AddLocalName (c.Variable);
6531                 }
6532                 
6533                 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6534                 $$ = c;
6535                 lexer.parsing_catch_when = true;
6536           }
6537           opt_catch_filter_or_error
6538           {
6539                 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6540                 $$ = $6;
6541           }
6542         | CATCH open_parens_any error
6543           {
6544                 if (yyToken == Token.CLOSE_PARENS) {
6545                         report.Error (1015, lexer.Location,
6546                                 "A type that derives from `System.Exception', `object', or `string' expected");
6547                 } else {
6548                         Error_SyntaxError (yyToken);
6549                 }
6550                 
6551                 $$ = new Catch (null, GetLocation ($1));
6552           }
6553         ;
6554
6555 opt_catch_filter_or_error
6556         : opt_catch_filter block_prepared
6557           {
6558                 $$ = $1;
6559           }
6560         | error
6561           {
6562                 end_block (Location.Null);
6563                 Error_SyntaxError (yyToken);
6564                 $$ = null;
6565           }
6566         ;
6567
6568 opt_catch_filter
6569         : {
6570                 lexer.parsing_catch_when = false;
6571           }
6572         | WHEN
6573           {
6574                 lexer.parsing_catch_when = false;
6575           }
6576           open_parens_any expression CLOSE_PARENS
6577           {
6578                 if (lang_version <= LanguageVersion.V_5)
6579                         FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6580
6581                 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6582                 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6583           }
6584         ;
6585
6586 checked_statement
6587         : CHECKED block
6588           {
6589                 $$ = new Checked ((Block) $2, GetLocation ($1));
6590           }
6591         ;
6592
6593 unchecked_statement
6594         : UNCHECKED block
6595           {
6596                 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6597           }
6598         ;
6599
6600 unsafe_statement
6601         : UNSAFE
6602           {
6603                 if (!settings.Unsafe)
6604                         Error_UnsafeCodeNotAllowed (GetLocation ($1));
6605           } block {
6606                 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6607           }
6608         ;
6609
6610 lock_statement
6611         : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6612           {
6613                 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6614                         Warning_EmptyStatement (GetLocation ($5));
6615           
6616                 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6617                 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6618           }
6619         | LOCK open_parens_any expression error
6620           {
6621                 Error_SyntaxError (yyToken);
6622
6623                 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6624                 lbag.AddStatement ($$, GetLocation ($2));
6625           }
6626         ;
6627
6628 fixed_statement
6629         : FIXED open_parens_any variable_type identifier_inside_body
6630           {
6631             start_block (GetLocation ($2));
6632             
6633                 current_block.IsCompilerGenerated = true;
6634                 var lt = (LocatedToken) $4;
6635                 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6636                 current_block.AddLocalName (li);
6637                 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6638           }
6639           using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6640           {
6641                 $$ = current_variable;
6642                 current_variable = null;
6643           }
6644           embedded_statement
6645           {
6646                 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6647                         Warning_EmptyStatement (GetLocation ($10));
6648           
6649                 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6650                 current_block.AddStatement (f);
6651                 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6652                 $$ = end_block (GetLocation ($8));
6653           }
6654         ;
6655
6656 using_statement
6657         : USING open_parens_any variable_type identifier_inside_body
6658           {
6659             start_block (GetLocation ($2));
6660             
6661                 current_block.IsCompilerGenerated = true;
6662                 var lt = (LocatedToken) $4;
6663                 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6664                 current_block.AddLocalName (li);
6665                 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6666           }
6667           using_initialization CLOSE_PARENS
6668           {
6669                 $$ = current_variable;    
6670                 current_variable = null;
6671           }
6672           embedded_statement
6673           {
6674                 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6675                         Warning_EmptyStatement (GetLocation ($9));
6676           
6677                 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6678                 current_block.AddStatement (u);
6679                 $$ = end_block (GetLocation ($7));
6680           }
6681         | USING open_parens_any expression CLOSE_PARENS embedded_statement
6682           {
6683                 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6684                         Warning_EmptyStatement (GetLocation ($5));
6685           
6686                 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6687                 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6688           }
6689         | USING open_parens_any expression error
6690           {
6691                 Error_SyntaxError (yyToken);
6692                 
6693                 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6694                 lbag.AddStatement ($$, GetLocation ($2));
6695           }
6696         ;
6697         
6698 using_initialization
6699         : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6700         | error
6701           {
6702                 // It has to be here for the parent to safely restore artificial block
6703                 Error_SyntaxError (yyToken);
6704           }
6705         ;
6706         
6707 using_or_fixed_variable_initializer
6708         : /* empty */
6709           {
6710                 Error_MissingInitializer (lexer.Location);
6711           }
6712         | ASSIGN variable_initializer
6713           {
6714                 current_variable.Initializer = (Expression) $2;
6715                 $$ = current_variable;
6716           }
6717         ;
6718
6719
6720 // LINQ
6721
6722 query_expression
6723         : first_from_clause query_body 
6724           {
6725                 lexer.query_parsing = false;
6726                         
6727                 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6728                         
6729                 from.Tail.Next = (Linq.AQueryClause)$2;
6730                 $$ = from;
6731                 
6732                 current_block.SetEndLocation (lexer.Location);
6733                 current_block = current_block.Parent;
6734           }
6735         | nested_from_clause query_body
6736           {
6737                 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6738                         
6739                 from.Tail.Next = (Linq.AQueryClause)$2;
6740                 $$ = from;
6741                 
6742                 current_block.SetEndLocation (lexer.Location);
6743                 current_block = current_block.Parent;
6744           }     
6745
6746         // Bubble up COMPLETE_COMPLETION productions
6747         | first_from_clause COMPLETE_COMPLETION {
6748                 lexer.query_parsing = false;
6749                 $$ = $1;
6750
6751                 current_block.SetEndLocation (lexer.Location);
6752                 current_block = current_block.Parent;
6753           }
6754         | nested_from_clause COMPLETE_COMPLETION {
6755                 $$ = $1;
6756                 current_block.SetEndLocation (lexer.Location);
6757                 current_block = current_block.Parent;
6758           }
6759         ;
6760         
6761 first_from_clause
6762         : FROM_FIRST identifier_inside_body IN expression
6763           {
6764                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6765           
6766                 var lt = (LocatedToken) $2;
6767                 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6768                 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6769                 lbag.AddLocation (clause, GetLocation ($3));
6770                 $$ = new Linq.QueryExpression (clause);
6771           }
6772         | FROM_FIRST type identifier_inside_body IN expression
6773           {
6774                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6775           
6776                 var lt = (LocatedToken) $3;
6777                 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6778                 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6779                                 IdentifierType = (FullNamedExpression)$2
6780                 };
6781                 lbag.AddLocation (clause, GetLocation ($4));
6782                 $$ = new Linq.QueryExpression (clause);
6783           }
6784         ;
6785
6786 nested_from_clause
6787         : FROM identifier_inside_body IN expression
6788           {
6789                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6790           
6791                 var lt = (LocatedToken) $2;
6792                 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6793                 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6794                 lbag.AddLocation (clause, GetLocation ($3));
6795                 $$ = new Linq.QueryExpression (clause);
6796           }
6797         | FROM type identifier_inside_body IN expression
6798           {
6799                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6800           
6801                 var lt = (LocatedToken) $3;
6802                 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6803                 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6804                                 IdentifierType = (FullNamedExpression)$2
6805                 };
6806                 lbag.AddLocation (clause, GetLocation ($4));
6807                 $$ = new Linq.QueryExpression (clause);
6808           }
6809         ;
6810         
6811 from_clause
6812         : FROM identifier_inside_body IN
6813           {
6814                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6815           }
6816           expression_or_error
6817           {
6818                 var lt = (LocatedToken) $2;
6819                 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6820                 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6821                 
6822                 current_block.SetEndLocation (lexer.Location);
6823                 current_block = current_block.Parent;
6824                 
6825                 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6826                 lbag.AddLocation ($$, GetLocation ($3));
6827           }       
6828         | FROM type identifier_inside_body IN
6829           {
6830                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6831           }
6832           expression_or_error
6833           {
6834                 var lt = (LocatedToken) $3;
6835                 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6836
6837                 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6838                         IdentifierType = (FullNamedExpression)$2
6839                 };
6840                 
6841                 current_block.SetEndLocation (lexer.Location);
6842                 current_block = current_block.Parent;
6843                 
6844                 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6845                 
6846                 lbag.AddLocation ($$, GetLocation ($4));
6847           }
6848         ;       
6849
6850 query_body
6851         : query_body_clauses select_or_group_clause opt_query_continuation 
6852           {
6853                 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6854                 
6855                 if ($3 != null)
6856                         head.Next = (Linq.AQueryClause)$3;
6857                                 
6858                 if ($1 != null) {
6859                         Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6860                         clause.Tail.Next = head;
6861                         head = clause;
6862                 }
6863                 
6864                 $$ = head;
6865           }
6866         | select_or_group_clause opt_query_continuation
6867           {
6868                 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6869
6870                 if ($1 != null) {
6871                         Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6872                         clause.Tail.Next = head;
6873                         head = clause;
6874                 }
6875                 
6876                 $$ = head;
6877           }
6878         | query_body_clauses COMPLETE_COMPLETION
6879         | query_body_clauses error
6880           {
6881                 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6882                 $$ = $1;
6883           }
6884         | error
6885           {
6886                 Error_SyntaxError (yyToken);
6887                 $$ = null;
6888           }
6889         ;
6890         
6891 select_or_group_clause
6892         : SELECT
6893           {
6894                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6895           }
6896           expression_or_error
6897           {
6898                 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6899
6900                 current_block.SetEndLocation (lexer.Location);
6901                 current_block = current_block.Parent;
6902           }
6903         | GROUP
6904           {
6905                 if (linq_clause_blocks == null)
6906                         linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6907                         
6908                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6909                 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6910           }
6911           expression_or_error
6912           {
6913                 current_block.SetEndLocation (lexer.Location);
6914                 current_block = current_block.Parent;
6915           
6916                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6917           }
6918           by_expression
6919           {
6920                 var obj = (object[]) $5;
6921
6922                 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6923                 lbag.AddLocation ($$, (Location) obj[1]);
6924                 
6925                 current_block.SetEndLocation (lexer.Location);
6926                 current_block = current_block.Parent;
6927           }
6928         ;
6929
6930 by_expression
6931         : BY expression_or_error
6932           {
6933                 $$ = new object[] { $2, GetLocation ($1) };
6934           }
6935         | error
6936           {
6937                 Error_SyntaxError (yyToken);
6938                 $$ = new object[2] { null, Location.Null };
6939           }
6940         ;
6941         
6942 query_body_clauses
6943         : query_body_clause
6944         | query_body_clauses query_body_clause
6945           {
6946                 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6947                 $$ = $1;
6948           }
6949         ;
6950         
6951 query_body_clause
6952         : from_clause
6953         | let_clause 
6954         | where_clause
6955         | join_clause
6956         | orderby_clause
6957         ;
6958         
6959 let_clause
6960         : LET identifier_inside_body ASSIGN 
6961           {
6962                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6963           }
6964           expression_or_error
6965           {
6966                 var lt = (LocatedToken) $2;
6967                 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6968                 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6969                 lbag.AddLocation ($$, GetLocation ($3));
6970                 
6971                 current_block.SetEndLocation (lexer.Location);
6972                 current_block = current_block.Parent;
6973                 
6974                 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6975           }
6976         ;
6977
6978 where_clause
6979         : WHERE
6980           {
6981                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6982           }
6983           expression_or_error
6984           {
6985                 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6986
6987                 current_block.SetEndLocation (lexer.Location);
6988                 current_block = current_block.Parent;
6989           }
6990         ;
6991         
6992 join_clause
6993         : JOIN identifier_inside_body IN
6994           {
6995                 if (linq_clause_blocks == null)
6996                         linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6997                         
6998                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6999                 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7000           }
7001           expression_or_error ON
7002           {
7003                 current_block.SetEndLocation (lexer.Location);
7004                 current_block = current_block.Parent;
7005
7006                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7007                 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7008           }
7009           expression_or_error EQUALS
7010           {
7011                 current_block.AddStatement (new ContextualReturn ((Expression) $8));
7012                 current_block.SetEndLocation (lexer.Location);
7013                 current_block = current_block.Parent;
7014
7015                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7016           }
7017           expression_or_error opt_join_into
7018           {
7019                 current_block.AddStatement (new ContextualReturn ((Expression) $11));
7020                 current_block.SetEndLocation (lexer.Location);
7021           
7022                 var outer_selector = linq_clause_blocks.Pop ();
7023                 var block = linq_clause_blocks.Pop ();
7024
7025                 var lt = (LocatedToken) $2;     
7026                 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7027                 Linq.RangeVariable into;
7028                 
7029                 if ($12 == null) {
7030                         into = sn;
7031                         $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
7032                         lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7033                 } else {
7034                         //
7035                         // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7036                         //
7037                         var parent = block.Parent;
7038                         while (parent is Linq.QueryBlock) {
7039                                 parent = parent.Parent;
7040                         }
7041                         current_block.Parent = parent;
7042                         
7043                         ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7044                 
7045                         lt = (LocatedToken) $12;
7046                         into = new Linq.RangeVariable (lt.Value, lt.Location);
7047
7048                         $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));   
7049                         lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7050                 }
7051
7052                 current_block = block.Parent;
7053                 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7054           }
7055         | JOIN type identifier_inside_body IN
7056           {
7057                 if (linq_clause_blocks == null)
7058                         linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7059                         
7060                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7061                 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7062           }
7063           expression_or_error ON
7064           {
7065                 current_block.SetEndLocation (lexer.Location);
7066                 current_block = current_block.Parent;
7067
7068                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7069                 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7070           }
7071           expression_or_error EQUALS
7072           {
7073                 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7074                 current_block.SetEndLocation (lexer.Location);
7075                 current_block = current_block.Parent;
7076
7077                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7078           }
7079           expression_or_error opt_join_into
7080           {
7081                 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7082                 current_block.SetEndLocation (lexer.Location);
7083           
7084                 var outer_selector = linq_clause_blocks.Pop ();
7085                 var block = linq_clause_blocks.Pop ();
7086                 
7087                 var lt = (LocatedToken) $3;
7088                 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7089                 Linq.RangeVariable into;
7090                 
7091                 if ($13 == null) {
7092                         into = sn;              
7093                         $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7094                                 IdentifierType = (FullNamedExpression)$2
7095                         };
7096                         lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7097                 } else {
7098                         //
7099                         // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7100                         //
7101                         var parent = block.Parent;
7102                         while (parent is Linq.QueryBlock) {
7103                                 parent = parent.Parent;
7104                         }
7105                         current_block.Parent = parent;
7106                 
7107                         ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7108                 
7109                         lt = (LocatedToken) $13;
7110                         into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7111                         
7112                         $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7113                                 IdentifierType = (FullNamedExpression)$2
7114                         };                      
7115                 }
7116                 
7117                 current_block = block.Parent;
7118                 ((Linq.QueryBlock)current_block).AddRangeVariable (into);               
7119           }
7120         ;
7121         
7122 opt_join_into
7123         : /* empty */
7124         | INTO identifier_inside_body
7125           {
7126                 $$ = $2;
7127           }
7128         ;
7129         
7130 orderby_clause
7131         : ORDERBY
7132           {
7133                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7134           }
7135           orderings
7136           {
7137                 current_block.SetEndLocation (lexer.Location);
7138                 current_block = current_block.Parent;
7139           
7140                 $$ = $3;
7141           }
7142         ;
7143         
7144 orderings
7145         : order_by
7146         | order_by COMMA
7147           {
7148                 current_block.SetEndLocation (lexer.Location);
7149                 current_block = current_block.Parent;
7150           
7151                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7152           }
7153           orderings_then_by
7154           {
7155                 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7156                 $$ = $1;
7157           }
7158         ;
7159         
7160 orderings_then_by
7161         : then_by
7162         | orderings_then_by COMMA
7163          {
7164                 current_block.SetEndLocation (lexer.Location);
7165                 current_block = current_block.Parent;
7166           
7167                 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);   
7168          }
7169          then_by
7170          {
7171                 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7172                 $$ = $1;
7173          }
7174         ;       
7175         
7176 order_by
7177         : expression
7178           {
7179                 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);       
7180           }
7181         | expression ASCENDING
7182           {
7183                 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);       
7184                 lbag.AddLocation ($$, GetLocation ($2));
7185           }
7186         | expression DESCENDING
7187           {
7188                 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);      
7189                 lbag.AddLocation ($$, GetLocation ($2));
7190           }
7191         ;
7192
7193 then_by
7194         : expression
7195           {
7196                 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);        
7197           }
7198         | expression ASCENDING
7199           {
7200                 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);        
7201                 lbag.AddLocation ($$, GetLocation ($2));
7202           }
7203         | expression DESCENDING
7204           {
7205                 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);       
7206                 lbag.AddLocation ($$, GetLocation ($2));
7207           }     
7208         ;
7209
7210
7211 opt_query_continuation
7212         : /* empty */
7213         | INTO identifier_inside_body
7214           {
7215                 // query continuation block is not linked with query block but with block
7216                 // before. This means each query can use same range variable names for
7217                 // different identifiers.
7218
7219                 current_block.SetEndLocation (GetLocation ($1));
7220                 current_block = current_block.Parent;
7221         
7222                 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7223                 
7224                 if (linq_clause_blocks == null)
7225                         linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7226                         
7227                 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);              
7228           }
7229           query_body
7230           {
7231                 var current_block = linq_clause_blocks.Pop ();    
7232                 var lt = (LocatedToken) $2;
7233                 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7234                 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7235                         next = (Linq.AQueryClause)$4
7236                 };
7237           }
7238         ;
7239         
7240 //
7241 // Support for using the compiler as an interactive parser
7242 //
7243 // The INTERACTIVE_PARSER token is first sent to parse our
7244 // productions;  If the result is a Statement, the parsing
7245 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7246 // to setup the blocks in advance.
7247 //
7248 // This setup is here so that in the future we can add 
7249 // support for other constructs (type parsing, namespaces, etc)
7250 // that do not require a block to be setup in advance
7251 //
7252
7253 interactive_parsing
7254         : EVAL_STATEMENT_PARSER EOF 
7255         | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7256         | EVAL_STATEMENT_PARSER
7257          { 
7258                 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7259
7260                 // (ref object retval)
7261                 Parameter [] mpar = new Parameter [1];
7262                 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7263
7264                 ParametersCompiled pars = new ParametersCompiled (mpar);
7265                 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7266                 if (settings.Unsafe)
7267                         mods |= Modifiers.UNSAFE;
7268
7269                 current_local_parameters = pars;
7270                 var method = new InteractiveMethod (
7271                         current_type,
7272                         new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7273                         mods,
7274                         pars);
7275                         
7276                 current_type.AddMember (method);                        
7277                 oob_stack.Push (method);
7278
7279                 interactive_async = false;
7280
7281                 ++lexer.parsing_block;
7282                 start_block (lexer.Location);
7283           }             
7284           interactive_statement_list opt_COMPLETE_COMPLETION
7285           {
7286                 --lexer.parsing_block;
7287                 var method = (InteractiveMethod) oob_stack.Pop ();
7288                 method.Block = (ToplevelBlock) end_block(lexer.Location);
7289
7290                 if (interactive_async == true) {
7291                         method.ChangeToAsync ();
7292                 }
7293
7294                 InteractiveResult = (Class) pop_current_class ();
7295                 current_local_parameters = null;
7296           } 
7297         | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7298         ;
7299
7300 interactive_compilation_unit
7301         : opt_extern_alias_directives opt_using_directives
7302         | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7303         ;
7304
7305 opt_COMPLETE_COMPLETION
7306         : /* nothing */
7307         | COMPLETE_COMPLETION
7308         ;
7309
7310 close_brace_or_complete_completion
7311         : CLOSE_BRACE
7312         | COMPLETE_COMPLETION
7313         ;
7314         
7315 //
7316 // XML documentation code references micro parser
7317 //
7318 documentation_parsing
7319         : DOC_SEE doc_cref
7320           {
7321                 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7322           }
7323         ;
7324
7325 doc_cref
7326         : doc_type_declaration_name opt_doc_method_sig
7327           {
7328                 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7329           }
7330         | builtin_types opt_doc_method_sig
7331           {
7332                 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7333                 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7334                 $$ = null;
7335           }
7336         | VOID opt_doc_method_sig
7337           {
7338                 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7339                 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7340                 $$ = null;
7341           }
7342         | builtin_types DOT IDENTIFIER opt_doc_method_sig
7343           {
7344                 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7345                 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7346                 var lt = (LocatedToken) $3;
7347                 $$ = new MemberName (lt.Value);
7348           }
7349         | doc_type_declaration_name DOT THIS
7350           {
7351                 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7352           }
7353         | doc_type_declaration_name DOT THIS OPEN_BRACKET
7354           {
7355                 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7356           }
7357           opt_doc_parameters CLOSE_BRACKET
7358           {
7359                 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7360                 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7361           }
7362         | EXPLICIT OPERATOR type opt_doc_method_sig
7363           {
7364                 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7365                 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7366                 module.DocumentationBuilder.ParsedParameters = p;
7367                 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7368                 $$ = null;
7369           }
7370         | IMPLICIT OPERATOR type opt_doc_method_sig
7371           {
7372                 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7373                 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7374                 module.DocumentationBuilder.ParsedParameters = p;
7375                 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7376                 $$ = null;
7377           }       
7378         | OPERATOR overloadable_operator opt_doc_method_sig
7379           {
7380                 var p = (List<DocumentationParameter>)$3;
7381                 module.DocumentationBuilder.ParsedParameters = p;
7382                 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7383                 $$ = null;
7384           }
7385         ;
7386         
7387 doc_type_declaration_name
7388         : type_declaration_name
7389         | doc_type_declaration_name DOT type_declaration_name
7390           {
7391                 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7392           }
7393         ;
7394         
7395 opt_doc_method_sig
7396         : /* empty */
7397         | OPEN_PARENS
7398           {
7399                 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7400           }
7401           opt_doc_parameters CLOSE_PARENS
7402           {
7403                 $$ = $3;
7404           }
7405         ;
7406         
7407 opt_doc_parameters
7408         : /* empty */
7409           {
7410                 $$ = new List<DocumentationParameter> (0);
7411           }
7412         | doc_parameters
7413         ;
7414         
7415 doc_parameters
7416         : doc_parameter
7417           {
7418                 var parameters = new List<DocumentationParameter> ();
7419                 parameters.Add ((DocumentationParameter) $1);
7420                 $$ = parameters;
7421           }
7422         | doc_parameters COMMA doc_parameter
7423           {
7424                 var parameters = $1 as List<DocumentationParameter>;
7425                 parameters.Add ((DocumentationParameter) $3);
7426                 $$ = parameters;
7427           }
7428         ;
7429         
7430 doc_parameter
7431         : opt_parameter_modifier parameter_type
7432           {
7433                 if ($1 != null)
7434                         $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7435                 else
7436                         $$ = new DocumentationParameter ((FullNamedExpression) $2);
7437           }
7438         ;
7439         
7440 %%
7441
7442 // <summary>
7443 //  A class used to hold info about an operator declarator
7444 // </summary>
7445 class OperatorDeclaration {
7446         public readonly Operator.OpType optype;
7447         public readonly FullNamedExpression ret_type;
7448         public readonly Location location;
7449
7450         public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7451         {
7452                 optype = op;
7453                 this.ret_type = ret_type;
7454                 this.location = location;
7455         }
7456 }
7457
7458 void Error_ExpectingTypeName (Expression expr)
7459 {
7460         if (expr is Invocation){
7461                 report.Error (1002, expr.Location, "Expecting `;'");
7462         } else {
7463                 expr.Error_InvalidExpressionStatement (report);
7464         }
7465 }
7466
7467 void Error_ParameterModifierNotValid (string modifier, Location loc)
7468 {
7469         report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7470                                       modifier);
7471 }
7472
7473 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7474 {
7475         report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7476                 Parameter.GetModifierSignature (mod));
7477 }
7478
7479 void Error_TypeExpected (Location loc)
7480 {
7481         report.Error (1031, loc, "Type expected");
7482 }
7483
7484 void Error_UnsafeCodeNotAllowed (Location loc)
7485 {
7486         report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7487 }
7488
7489 void Warning_EmptyStatement (Location loc)
7490 {
7491         report.Warning (642, 3, loc, "Possible mistaken empty statement");
7492 }
7493
7494 void Error_NamedArgumentExpected (NamedArgument a)
7495 {
7496         report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7497 }
7498
7499 void Error_MissingInitializer (Location loc)
7500 {
7501         report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7502 }
7503
7504 object Error_AwaitAsIdentifier (object token)
7505 {
7506         if (async_block) {
7507                 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7508                 return new LocatedToken ("await", GetLocation (token));
7509         }
7510
7511         return token;
7512 }
7513
7514 void push_current_container (TypeDefinition tc, object partial_token)
7515 {
7516         if (module.Evaluator != null){
7517                 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7518                 if (undo == null)
7519                         undo = new Undo ();
7520
7521                 undo.AddTypeContainer (current_container, tc);
7522         }
7523         
7524         if (partial_token != null)
7525                 current_container.AddPartial (tc);
7526         else
7527                 current_container.AddTypeContainer (tc);
7528                 
7529         ++lexer.parsing_declaration;
7530         current_container = tc;
7531         current_type = tc;
7532 }
7533
7534 TypeContainer pop_current_class ()
7535 {
7536         var retval = current_container;
7537
7538         current_container = current_container.Parent;
7539         current_type = current_type.Parent as TypeDefinition;
7540
7541         return retval;
7542 }
7543
7544 [System.Diagnostics.Conditional ("FULL_AST")]
7545 void StoreModifierLocation (object token, Location loc)
7546 {
7547         if (lbag == null)
7548                 return;
7549
7550         if (mod_locations == null)
7551                 mod_locations = new List<Tuple<Modifiers, Location>> ();
7552
7553         mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7554 }
7555
7556 [System.Diagnostics.Conditional ("FULL_AST")]
7557 void PushLocation (Location loc)
7558 {
7559         if (location_stack == null)
7560                 location_stack = new Stack<Location> ();
7561
7562         location_stack.Push (loc);
7563 }
7564
7565 Location PopLocation ()
7566 {
7567         if (location_stack == null)
7568                 return Location.Null;
7569
7570         return location_stack.Pop ();
7571 }
7572
7573 string CheckAttributeTarget (int token, string a, Location l)
7574 {
7575         switch (a) {
7576         case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7577                         return a;
7578         }
7579
7580         if (!Tokenizer.IsValidIdentifier (a)) {
7581                 Error_SyntaxError (token);
7582         } else {
7583                 report.Warning (658, 1, l,
7584                          "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7585         }
7586
7587         return string.Empty;
7588 }
7589
7590 static bool IsUnaryOperator (Operator.OpType op)
7591 {
7592         switch (op) {
7593                 
7594         case Operator.OpType.LogicalNot: 
7595         case Operator.OpType.OnesComplement: 
7596         case Operator.OpType.Increment:
7597         case Operator.OpType.Decrement:
7598         case Operator.OpType.True: 
7599         case Operator.OpType.False: 
7600         case Operator.OpType.UnaryPlus: 
7601         case Operator.OpType.UnaryNegation:
7602                 return true;
7603         }
7604         return false;
7605 }
7606
7607 void syntax_error (Location l, string msg)
7608 {
7609         report.Error (1003, l, "Syntax error, " + msg);
7610 }
7611
7612 Tokenizer lexer;
7613
7614 public Tokenizer Lexer {
7615         get {
7616                 return lexer;
7617         }
7618 }                  
7619
7620 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7621         : this (reader, file, file.Compiler.Report, session)
7622 {
7623 }
7624
7625 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7626 {
7627         this.file = file;
7628         current_container = current_namespace = file;
7629         
7630         this.module = file.Module;
7631         this.compiler = file.Compiler;
7632         this.settings = compiler.Settings;
7633         this.report = report;
7634         
7635         lang_version = settings.Version;
7636         yacc_verbose_flag = settings.VerboseParserFlag;
7637         doc_support = settings.DocumentationFile != null;
7638         lexer = new Tokenizer (reader, file, session, report);
7639         oob_stack = new Stack<object> ();
7640         lbag = session.LocationsBag;
7641         use_global_stacks = session.UseJayGlobalArrays;
7642         parameters_bucket = session.ParametersStack;
7643 }
7644
7645 public void parse ()
7646 {
7647         eof_token = Token.EOF;
7648         
7649         try {
7650                 if (yacc_verbose_flag > 1)
7651                         yyparse (lexer, new yydebug.yyDebugSimple ());
7652                 else
7653                         yyparse (lexer);
7654                         
7655                 Tokenizer tokenizer = lexer as Tokenizer;
7656                 tokenizer.cleanup ();           
7657         } catch (Exception e){
7658                 if (e is yyParser.yyUnexpectedEof) {
7659                         Error_SyntaxError (yyToken);
7660                         UnexpectedEOF = true;
7661                         return;
7662                 }
7663                         
7664                 if (e is yyParser.yyException) {
7665                         if (report.Errors == 0)
7666                                 report.Error (-25, lexer.Location, "Parsing error");
7667                 } else {
7668                         // Used by compiler-tester to test internal errors
7669                         if (yacc_verbose_flag > 0 || e is FatalException)
7670                                 throw;
7671                 
7672                         report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7673                 }
7674         }
7675 }
7676
7677 void CheckToken (int error, int yyToken, string msg, Location loc)
7678 {
7679         if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7680                 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7681         else
7682                 report.Error (error, loc, msg);
7683 }
7684
7685 string ConsumeStoredComment ()
7686 {
7687         string s = tmpComment;
7688         tmpComment = null;
7689         Lexer.doc_state = XmlCommentState.Allowed;
7690         return s;
7691 }
7692
7693 void FeatureIsNotAvailable (Location loc, string feature)
7694 {
7695         report.FeatureIsNotAvailable (compiler, loc, feature);
7696 }
7697
7698 Location GetLocation (object obj)
7699 {
7700         var lt = obj as LocatedToken;
7701         if (lt != null)
7702                 return lt.Location;
7703                 
7704         var mn = obj as MemberName;
7705         if (mn != null)
7706                 return mn.Location;
7707                 
7708         var expr = obj as Expression;
7709         if (expr != null)
7710                 return expr.Location;
7711
7712         return lexer.Location;
7713 }
7714
7715 void start_block (Location loc)
7716 {
7717         if (current_block == null) {
7718                 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7719                 parsing_anonymous_method = false;
7720         } else if (parsing_anonymous_method) {
7721                 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7722                 parsing_anonymous_method = false;
7723         } else {
7724                 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7725         }
7726 }
7727
7728 Block
7729 end_block (Location loc)
7730 {
7731         Block retval = current_block.Explicit;
7732         retval.SetEndLocation (loc);
7733         current_block = retval.Parent;
7734         return retval;
7735 }
7736
7737 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7738 {
7739         oob_stack.Push (current_anonymous_method);
7740         oob_stack.Push (current_local_parameters);
7741         oob_stack.Push (current_variable);
7742         oob_stack.Push (async_block);
7743
7744         current_local_parameters = parameters;
7745         if (isLambda) {
7746                 if (lang_version <= LanguageVersion.ISO_2)
7747                         FeatureIsNotAvailable (loc, "lambda expressions");
7748
7749                 current_anonymous_method = new LambdaExpression (loc);
7750         } else {
7751                 if (lang_version == LanguageVersion.ISO_1)
7752                         FeatureIsNotAvailable (loc, "anonymous methods");
7753                         
7754                 current_anonymous_method = new AnonymousMethodExpression (loc);
7755         }
7756
7757         async_block = isAsync;
7758         // Force the next block to be created as a ToplevelBlock
7759         parsing_anonymous_method = true;
7760 }
7761
7762 /*
7763  * Completes the anonymous method processing, if lambda_expr is null, this
7764  * means that we have a Statement instead of an Expression embedded 
7765  */
7766 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7767 {
7768         AnonymousMethodExpression retval;
7769
7770         if (async_block)
7771                 anon_block.IsAsync = true;
7772
7773         current_anonymous_method.Block = anon_block;
7774         retval = current_anonymous_method;
7775
7776         async_block = (bool) oob_stack.Pop ();
7777         current_variable = (BlockVariable) oob_stack.Pop ();
7778         current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7779         current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7780
7781         return retval;
7782 }
7783
7784 void Error_SyntaxError (int token)
7785 {
7786         Error_SyntaxError (0, token);
7787 }
7788
7789 void Error_SyntaxError (int error_code, int token)
7790 {
7791         Error_SyntaxError (error_code, token, "Unexpected symbol");
7792 }
7793
7794 void Error_SyntaxError (int error_code, int token, string msg)
7795 {
7796         Lexer.CompleteOnEOF = false;
7797
7798         // An error message has been reported by tokenizer
7799         if (token == Token.ERROR)
7800                 return;
7801         
7802         // Avoid duplicit error message after unterminated string literals
7803         if (token == Token.LITERAL && lexer.Location.Column == 0)
7804                 return;
7805
7806         string symbol = GetSymbolName (token);
7807         string expecting = GetExpecting ();
7808         var loc = lexer.Location - symbol.Length;
7809         
7810         if (error_code == 0) {
7811                 if (expecting == "`identifier'") {
7812                         if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7813                                 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7814                                 return;
7815                         }
7816                         
7817                         error_code = 1001;
7818                         expecting = "identifier";
7819                 } else if (expecting == "`)'") {
7820                         error_code = 1026;
7821                 } else {
7822                         error_code = 1525;
7823                 }
7824         }
7825         
7826         if (string.IsNullOrEmpty (expecting))
7827                 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7828         else
7829                 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);       
7830 }
7831
7832 string GetExpecting ()
7833 {
7834         int [] tokens = yyExpectingTokens (yyExpectingState);
7835         var names = new List<string> (tokens.Length);
7836         bool has_type = false;
7837         bool has_identifier = false;
7838         for (int i = 0; i < tokens.Length; i++){
7839                 int token = tokens [i];
7840                 has_identifier |= token == Token.IDENTIFIER;
7841                 
7842                 string name = GetTokenName (token);
7843                 if (name == "<internal>")
7844                         continue;
7845                         
7846                 has_type |= name == "type";
7847                 if (names.Contains (name))
7848                         continue;
7849                 
7850                 names.Add (name);
7851         }
7852
7853         //
7854         // Too many tokens to enumerate
7855         //
7856         if (names.Count > 8)
7857                 return null;
7858
7859         if (has_type && has_identifier)
7860                 names.Remove ("identifier");
7861
7862         if (names.Count == 1)
7863                 return "`" + GetTokenName (tokens [0]) + "'";
7864         
7865         StringBuilder sb = new StringBuilder ();
7866         names.Sort ();
7867         int count = names.Count;
7868         for (int i = 0; i < count; i++){
7869                 bool last = i + 1 == count;
7870                 if (last)
7871                         sb.Append ("or ");
7872                 sb.Append ('`');
7873                 sb.Append (names [i]);
7874                 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7875         }
7876         return sb.ToString ();
7877 }
7878
7879
7880 string GetSymbolName (int token)
7881 {
7882         switch (token){
7883         case Token.LITERAL:
7884                 return ((Constant)lexer.Value).GetValue ().ToString ();
7885         case Token.IDENTIFIER:
7886                 return ((LocatedToken)lexer.Value).Value;
7887
7888         case Token.BOOL:
7889                 return "bool";
7890         case Token.BYTE:
7891                 return "byte";
7892         case Token.CHAR:
7893                 return "char";
7894         case Token.VOID:
7895                 return "void";
7896         case Token.DECIMAL:
7897                 return "decimal";
7898         case Token.DOUBLE:
7899                 return "double";
7900         case Token.FLOAT:
7901                 return "float";
7902         case Token.INT:
7903                 return "int";
7904         case Token.LONG:
7905                 return "long";
7906         case Token.SBYTE:
7907                 return "sbyte";
7908         case Token.SHORT:
7909                 return "short";
7910         case Token.STRING:
7911                 return "string";
7912         case Token.UINT:
7913                 return "uint";
7914         case Token.ULONG:
7915                 return "ulong";
7916         case Token.USHORT:
7917                 return "ushort";
7918         case Token.OBJECT:
7919                 return "object";
7920                 
7921         case Token.PLUS:
7922                 return "+";
7923         case Token.UMINUS:
7924         case Token.MINUS:
7925                 return "-";
7926         case Token.BANG:
7927                 return "!";
7928         case Token.BITWISE_AND:
7929                 return "&";
7930         case Token.BITWISE_OR:
7931                 return "|";
7932         case Token.STAR:
7933                 return "*";
7934         case Token.PERCENT:
7935                 return "%";
7936         case Token.DIV:
7937                 return "/";
7938         case Token.CARRET:
7939                 return "^";
7940         case Token.OP_INC:
7941                 return "++";
7942         case Token.OP_DEC:
7943                 return "--";
7944         case Token.OP_SHIFT_LEFT:
7945                 return "<<";
7946         case Token.OP_SHIFT_RIGHT:
7947                 return ">>";
7948         case Token.OP_LT:
7949                 return "<";
7950         case Token.OP_GT:
7951                 return ">";
7952         case Token.OP_LE:
7953                 return "<=";
7954         case Token.OP_GE:
7955                 return ">=";
7956         case Token.OP_EQ:
7957                 return "==";
7958         case Token.OP_NE:
7959                 return "!=";
7960         case Token.OP_AND:
7961                 return "&&";
7962         case Token.OP_OR:
7963                 return "||";
7964         case Token.OP_PTR:
7965                 return "->";
7966         case Token.OP_COALESCING:       
7967                 return "??";
7968         case Token.OP_MULT_ASSIGN:
7969                 return "*=";
7970         case Token.OP_DIV_ASSIGN:
7971                 return "/=";
7972         case Token.OP_MOD_ASSIGN:
7973                 return "%=";
7974         case Token.OP_ADD_ASSIGN:
7975                 return "+=";
7976         case Token.OP_SUB_ASSIGN:
7977                 return "-=";
7978         case Token.OP_SHIFT_LEFT_ASSIGN:
7979                 return "<<=";
7980         case Token.OP_SHIFT_RIGHT_ASSIGN:
7981                 return ">>=";
7982         case Token.OP_AND_ASSIGN:
7983                 return "&=";
7984         case Token.OP_XOR_ASSIGN:
7985                 return "^=";
7986         case Token.OP_OR_ASSIGN:
7987                 return "|=";
7988         }
7989
7990         return GetTokenName (token);
7991 }
7992
7993 static string GetTokenName (int token)
7994 {
7995         switch (token){
7996         case Token.ABSTRACT:
7997                 return "abstract";
7998         case Token.AS:
7999                 return "as";
8000         case Token.ADD:
8001                 return "add";
8002         case Token.ASYNC:
8003                 return "async";
8004         case Token.BASE:
8005                 return "base";
8006         case Token.BREAK:
8007                 return "break";
8008         case Token.CASE:
8009                 return "case";
8010         case Token.CATCH:
8011                 return "catch";
8012         case Token.CHECKED:
8013                 return "checked";
8014         case Token.CLASS:
8015                 return "class";
8016         case Token.CONST:
8017                 return "const";
8018         case Token.CONTINUE:
8019                 return "continue";
8020         case Token.DEFAULT:
8021                 return "default";
8022         case Token.DELEGATE:
8023                 return "delegate";
8024         case Token.DO:
8025                 return "do";
8026         case Token.ELSE:
8027                 return "else";
8028         case Token.ENUM:
8029                 return "enum";
8030         case Token.EVENT:
8031                 return "event";
8032         case Token.EXPLICIT:
8033                 return "explicit";
8034         case Token.EXTERN:
8035         case Token.EXTERN_ALIAS:
8036                 return "extern";
8037         case Token.FALSE:
8038                 return "false";
8039         case Token.FINALLY:
8040                 return "finally";
8041         case Token.FIXED:
8042                 return "fixed";
8043         case Token.FOR:
8044                 return "for";
8045         case Token.FOREACH:
8046                 return "foreach";
8047         case Token.GOTO:
8048                 return "goto";
8049         case Token.IF:
8050                 return "if";
8051         case Token.IMPLICIT:
8052                 return "implicit";
8053         case Token.IN:
8054                 return "in";
8055         case Token.INTERFACE:
8056                 return "interface";
8057         case Token.INTERNAL:
8058                 return "internal";
8059         case Token.IS:
8060                 return "is";
8061         case Token.LOCK:
8062                 return "lock";
8063         case Token.NAMESPACE:
8064                 return "namespace";
8065         case Token.NEW:
8066                 return "new";
8067         case Token.NULL:
8068                 return "null";
8069         case Token.OPERATOR:
8070                 return "operator";
8071         case Token.OUT:
8072                 return "out";
8073         case Token.OVERRIDE:
8074                 return "override";
8075         case Token.PARAMS:
8076                 return "params";
8077         case Token.PRIVATE:
8078                 return "private";
8079         case Token.PROTECTED:
8080                 return "protected";
8081         case Token.PUBLIC:
8082                 return "public";
8083         case Token.READONLY:
8084                 return "readonly";
8085         case Token.REF:
8086                 return "ref";
8087         case Token.RETURN:
8088                 return "return";
8089         case Token.REMOVE:
8090                 return "remove";
8091         case Token.SEALED:
8092                 return "sealed";
8093         case Token.SIZEOF:
8094                 return "sizeof";
8095         case Token.STACKALLOC:
8096                 return "stackalloc";
8097         case Token.STATIC:
8098                 return "static";
8099         case Token.STRUCT:
8100                 return "struct";
8101         case Token.SWITCH:
8102                 return "switch";
8103         case Token.THIS:
8104                 return "this";
8105         case Token.THROW:
8106         case Token.THROW_EXPR:
8107                 return "throw";
8108         case Token.TRUE:
8109                 return "true";
8110         case Token.TRY:
8111                 return "try";
8112         case Token.TYPEOF:
8113                 return "typeof";
8114         case Token.UNCHECKED:
8115                 return "unchecked";
8116         case Token.UNSAFE:
8117                 return "unsafe";
8118         case Token.USING:
8119                 return "using";
8120         case Token.VIRTUAL:
8121                 return "virtual";
8122         case Token.VOLATILE:
8123                 return "volatile";
8124         case Token.WHERE:
8125                 return "where";
8126         case Token.WHILE:
8127                 return "while";
8128         case Token.ARGLIST:
8129                 return "__arglist";
8130         case Token.REFVALUE:
8131                 return "__refvalue";
8132         case Token.REFTYPE:
8133                 return "__reftype";
8134         case Token.MAKEREF:
8135                 return "__makeref";
8136         case Token.PARTIAL:
8137                 return "partial";
8138         case Token.ARROW:
8139                 return "=>";
8140         case Token.FROM:
8141         case Token.FROM_FIRST:
8142                 return "from";
8143         case Token.JOIN:
8144                 return "join";
8145         case Token.ON:
8146                 return "on";
8147         case Token.EQUALS:
8148                 return "equals";
8149         case Token.SELECT:
8150                 return "select";
8151         case Token.GROUP:
8152                 return "group";
8153         case Token.BY:
8154                 return "by";
8155         case Token.LET:
8156                 return "let";
8157         case Token.ORDERBY:
8158                 return "orderby";
8159         case Token.ASCENDING:
8160                 return "ascending";
8161         case Token.DESCENDING:
8162                 return "descending";
8163         case Token.INTO:
8164                 return "into";
8165         case Token.GET:
8166                 return "get";
8167         case Token.SET:
8168                 return "set";
8169         case Token.OPEN_BRACE:
8170                 return "{";
8171         case Token.CLOSE_BRACE:
8172                 return "}";
8173         case Token.OPEN_BRACKET:
8174         case Token.OPEN_BRACKET_EXPR:
8175                 return "[";
8176         case Token.CLOSE_BRACKET:
8177                 return "]";
8178         case Token.OPEN_PARENS_CAST:
8179         case Token.OPEN_PARENS_LAMBDA:
8180         case Token.OPEN_PARENS:
8181                 return "(";
8182         case Token.CLOSE_PARENS:
8183                 return ")";
8184         case Token.DOT:
8185                 return ".";
8186         case Token.COMMA:
8187                 return ",";
8188         case Token.DEFAULT_COLON:
8189                 return "default:";
8190         case Token.COLON:
8191                 return ":";
8192         case Token.SEMICOLON:
8193                 return ";";
8194         case Token.TILDE:
8195                 return "~";
8196         case Token.WHEN:
8197                 return "when";
8198         case Token.INTERPOLATED_STRING_END:
8199                 return "}";
8200         case Token.INTERPOLATED_STRING:
8201                 return "${";
8202
8203         case Token.PLUS:
8204         case Token.UMINUS:
8205         case Token.MINUS:
8206         case Token.BANG:
8207         case Token.OP_LT:
8208         case Token.OP_GT:
8209         case Token.BITWISE_AND:
8210         case Token.BITWISE_OR:
8211         case Token.STAR:
8212         case Token.PERCENT:
8213         case Token.DIV:
8214         case Token.CARRET:
8215         case Token.OP_INC:
8216         case Token.OP_DEC:
8217         case Token.OP_SHIFT_LEFT:
8218         case Token.OP_SHIFT_RIGHT:
8219         case Token.OP_LE:
8220         case Token.OP_GE:
8221         case Token.OP_EQ:
8222         case Token.OP_NE:
8223         case Token.OP_AND:
8224         case Token.OP_OR:
8225         case Token.OP_PTR:
8226         case Token.OP_COALESCING:       
8227         case Token.OP_MULT_ASSIGN:
8228         case Token.OP_DIV_ASSIGN:
8229         case Token.OP_MOD_ASSIGN:
8230         case Token.OP_ADD_ASSIGN:
8231         case Token.OP_SUB_ASSIGN:
8232         case Token.OP_SHIFT_LEFT_ASSIGN:
8233         case Token.OP_SHIFT_RIGHT_ASSIGN:
8234         case Token.OP_AND_ASSIGN:
8235         case Token.OP_XOR_ASSIGN:
8236         case Token.OP_OR_ASSIGN:
8237         case Token.INTERR_OPERATOR:
8238                 return "<operator>";
8239
8240         case Token.BOOL:
8241         case Token.BYTE:
8242         case Token.CHAR:
8243         case Token.VOID:
8244         case Token.DECIMAL:
8245         case Token.DOUBLE:
8246         case Token.FLOAT:
8247         case Token.INT:
8248         case Token.LONG:
8249         case Token.SBYTE:
8250         case Token.SHORT:
8251         case Token.STRING:
8252         case Token.UINT:
8253         case Token.ULONG:
8254         case Token.USHORT:
8255         case Token.OBJECT:
8256                 return "type";
8257         
8258         case Token.ASSIGN:
8259                 return "=";
8260         case Token.OP_GENERICS_LT:
8261         case Token.GENERIC_DIMENSION:
8262                 return "<";
8263         case Token.OP_GENERICS_GT:
8264                 return ">";
8265         case Token.INTERR:
8266         case Token.INTERR_NULLABLE:
8267                 return "?";
8268         case Token.DOUBLE_COLON:
8269                 return "::";
8270         case Token.LITERAL:
8271                 return "value";
8272         case Token.IDENTIFIER:
8273         case Token.AWAIT:
8274                 return "identifier";
8275
8276         case Token.EOF:
8277                 return "end-of-file";
8278
8279                 // All of these are internal.
8280         case Token.NONE:
8281         case Token.ERROR:
8282         case Token.FIRST_KEYWORD:
8283         case Token.EVAL_COMPILATION_UNIT_PARSER:
8284         case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8285         case Token.EVAL_STATEMENT_PARSER:
8286         case Token.LAST_KEYWORD:
8287         case Token.GENERATE_COMPLETION:
8288         case Token.COMPLETE_COMPLETION:
8289                 return "<internal>";
8290
8291                 // A bit more robust.
8292         default:
8293                 return yyNames [token];
8294         }
8295 }
8296
8297 /* end end end */
8298 }