~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

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