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