~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Core/src/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System.Drawing;
 
2
using System.Collections;
 
3
using System.Collections.Generic;
 
4
using System.Collections.Specialized;
 
5
using System.Text;
 
6
using ICSharpCode.NRefactory.Parser.AST;
 
7
using ICSharpCode.NRefactory.Parser.VB;
 
8
using ASTAttribute = ICSharpCode.NRefactory.Parser.AST.Attribute;
 
9
 
 
10
COMPILER VBNET
 
11
 
 
12
private string assemblyName = null;
 
13
private Stack withStatements;
 
14
private StringBuilder qualidentBuilder = new StringBuilder();
 
15
 
 
16
public string ContainingAssembly
 
17
{
 
18
        set { assemblyName = value; }
 
19
}
 
20
Token t
 
21
{
 
22
        get {
 
23
                return lexer.Token;
 
24
        }
 
25
}
 
26
Token la
 
27
{
 
28
        get {
 
29
                return lexer.LookAhead;
 
30
        }
 
31
}
 
32
 
 
33
/* Return the n-th token after the current lookahead token */
 
34
void StartPeek()
 
35
{
 
36
        lexer.StartPeek();
 
37
}
 
38
 
 
39
Token Peek()
 
40
{
 
41
        return lexer.Peek();
 
42
}
 
43
 
 
44
Token Peek (int n)
 
45
{
 
46
        lexer.StartPeek();
 
47
        Token x = la;
 
48
        while (n > 0) {
 
49
                x = lexer.Peek();
 
50
                n--;
 
51
        }
 
52
        return x;
 
53
}
 
54
 
 
55
public void Error(string s)
 
56
{
 
57
        if (errDist >= minErrDist) {
 
58
                errors.Error(la.line, la.col, s);
 
59
        }
 
60
        errDist = 0;
 
61
}
 
62
 
 
63
public override Expression ParseExpression()
 
64
{
 
65
        lexer.NextToken();
 
66
        Expression expr;
 
67
        Expr(out expr);
 
68
        return expr;
 
69
}
 
70
 
 
71
bool LeaveBlock()
 
72
{
 
73
  int peek = Peek(1).kind;
 
74
  return Tokens.BlockSucc[la.kind] && (la.kind != Tokens.End || peek == Tokens.EOL || peek == Tokens.Colon);
 
75
}
 
76
 
 
77
/* True, if "." is followed by an ident */
 
78
bool DotAndIdentOrKw () {
 
79
        int peek = Peek(1).kind;
 
80
        return la.kind == Tokens.Dot && (peek == Tokens.Identifier || peek >= Tokens.AddHandler);
 
81
}
 
82
 
 
83
bool IsEndStmtAhead()
 
84
{
 
85
        int peek = Peek(1).kind;
 
86
        return la.kind == Tokens.End && (peek == Tokens.EOL || peek == Tokens.Colon);
 
87
}
 
88
 
 
89
bool IsNotClosingParenthesis() {
 
90
        return la.kind != Tokens.CloseParenthesis;
 
91
}
 
92
 
 
93
/*
 
94
        True, if ident is followed by "="
 
95
*/
 
96
bool IdentAndAsgn () {
 
97
        if(la.kind == Tokens.Identifier) {
 
98
                if(Peek(1).kind == Tokens.Assign) return true;
 
99
                if(Peek(1).kind == Tokens.Colon && Peek(2).kind == Tokens.Assign) return true;
 
100
        }
 
101
        return false;
 
102
}
 
103
 
 
104
/*
 
105
        True, if ident is followed by "=" or by ":" and "="
 
106
*/
 
107
bool IsNamedAssign() {
 
108
//      if(Peek(1).kind == Tokens.Assign) return true; // removed: not in the lang spec
 
109
        if(Peek(1).kind == Tokens.Colon && Peek(2).kind == Tokens.Assign) return true;
 
110
        return false;
 
111
}
 
112
 
 
113
bool IsObjectCreation() {
 
114
        return la.kind == Tokens.As && Peek(1).kind == Tokens.New;
 
115
}
 
116
 
 
117
/*
 
118
        True, if "<" is followed by the ident "assembly" or "module"
 
119
*/
 
120
bool IsGlobalAttrTarget () {
 
121
        Token pt = Peek(1);
 
122
        return la.kind == Tokens.LessThan && ( string.Equals(pt.val, "assembly", StringComparison.InvariantCultureIgnoreCase) || string.Equals(pt.val, "module", StringComparison.InvariantCultureIgnoreCase));
 
123
}
 
124
 
 
125
/*
 
126
        True if the next token is a "(" and is followed by "," or ")"
 
127
*/
 
128
bool IsDims()
 
129
{
 
130
        int peek = Peek(1).kind;
 
131
        return la.kind == Tokens.OpenParenthesis
 
132
                                                && (peek == Tokens.Comma || peek == Tokens.CloseParenthesis);
 
133
}
 
134
 
 
135
bool IsSize()
 
136
{
 
137
        return la.kind == Tokens.OpenParenthesis;
 
138
}
 
139
 
 
140
/*
 
141
        True, if the comma is not a trailing one,
 
142
        like the last one in: a, b, c,
 
143
*/
 
144
bool NotFinalComma() {
 
145
        int peek = Peek(1).kind;
 
146
        return la.kind == Tokens.Comma &&
 
147
                   peek != Tokens.CloseCurlyBrace;
 
148
}
 
149
 
 
150
/*
 
151
        True, if the next token is "Else" and this one
 
152
        if followed by "If"
 
153
*/
 
154
bool IsElseIf()
 
155
{
 
156
        int peek = Peek(1).kind;
 
157
        return la.kind == Tokens.Else && peek == Tokens.If;
 
158
}
 
159
 
 
160
/*
 
161
        True if the next token is goto and this one is
 
162
        followed by minus ("-") (this is allowd in in
 
163
        error clauses)
 
164
*/
 
165
bool IsNegativeLabelName()
 
166
{
 
167
        int peek = Peek(1).kind;
 
168
        return la.kind == Tokens.GoTo && peek == Tokens.Minus;
 
169
}
 
170
 
 
171
/*
 
172
        True if the next statement is a "Resume next" statement
 
173
*/
 
174
bool IsResumeNext()
 
175
{
 
176
        int peek = Peek(1).kind;
 
177
        return la.kind == Tokens.Resume && peek == Tokens.Next;
 
178
}
 
179
 
 
180
/*
 
181
        True, if ident/literal integer is followed by ":"
 
182
*/
 
183
bool IsLabel()
 
184
{
 
185
        return (la.kind == Tokens.Identifier || la.kind == Tokens.LiteralInteger)
 
186
                        && Peek(1).kind == Tokens.Colon;
 
187
}
 
188
 
 
189
bool IsNotStatementSeparator()
 
190
{
 
191
        return la.kind == Tokens.Colon && Peek(1).kind == Tokens.EOL;
 
192
}
 
193
 
 
194
bool IsAssignment ()
 
195
{
 
196
        return IdentAndAsgn();
 
197
}
 
198
 
 
199
bool IsMustOverride(Modifiers m)
 
200
{
 
201
        return m.Contains(Modifier.Abstract);
 
202
}
 
203
 
 
204
TypeReferenceExpression GetTypeReferenceExpression(Expression expr, List<TypeReference> genericTypes)
 
205
{
 
206
        TypeReferenceExpression tre = expr as TypeReferenceExpression;
 
207
        if (tre != null) {
 
208
                return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes));
 
209
        }
 
210
        StringBuilder b = new StringBuilder();
 
211
        if (!WriteFullTypeName(b, expr)) {
 
212
                // there is some TypeReferenceExpression hidden in the expression
 
213
                while (expr is FieldReferenceExpression) {
 
214
                        expr = ((FieldReferenceExpression)expr).TargetObject;
 
215
                }
 
216
                tre = expr as TypeReferenceExpression;
 
217
                if (tre != null) {
 
218
                        TypeReference typeRef = tre.TypeReference;
 
219
                        if (typeRef.GenericTypes.Count == 0) {
 
220
                                typeRef = typeRef.Clone();
 
221
                                typeRef.Type += "." + b.ToString();
 
222
                                typeRef.GenericTypes.AddRange(genericTypes);
 
223
                        } else {
 
224
                                typeRef = new InnerClassTypeReference(typeRef, b.ToString(), genericTypes);
 
225
                        }
 
226
                        return new TypeReferenceExpression(typeRef);
 
227
                }
 
228
        }
 
229
        return new TypeReferenceExpression(new TypeReference(b.ToString(), 0, null, genericTypes));
 
230
}
 
231
 
 
232
/* Writes the type name represented through the expression into the string builder. */
 
233
/* Returns true when the expression was converted successfully, returns false when */
 
234
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */
 
235
bool WriteFullTypeName(StringBuilder b, Expression expr)
 
236
{
 
237
        FieldReferenceExpression fre = expr as FieldReferenceExpression;
 
238
        if (fre != null) {
 
239
                bool result = WriteFullTypeName(b, fre.TargetObject);
 
240
                if (b.Length > 0) b.Append('.');
 
241
                b.Append(fre.FieldName);
 
242
                return result;
 
243
        } else if (expr is IdentifierExpression) {
 
244
                b.Append(((IdentifierExpression)expr).Identifier);
 
245
                return true;
 
246
        } else {
 
247
                return false;
 
248
        }
 
249
}
 
250
 
 
251
/*
 
252
        True, if lookahead is a local attribute target specifier,
 
253
        i.e. one of "event", "return", "field", "method",
 
254
        "module", "param", "property", or "type"
 
255
*/
 
256
bool IsLocalAttrTarget() {
 
257
        // TODO
 
258
        return false;
 
259
}
 
260
 
 
261
/* START AUTOGENERATED TOKENS SECTION */
 
262
TOKENS
 
263
        /* ----- terminal classes ----- */
 
264
        /* EOF is 0 */
 
265
        EOL
 
266
        ident
 
267
        LiteralString
 
268
        LiteralCharacter
 
269
        LiteralInteger
 
270
        LiteralDouble
 
271
        LiteralSingle
 
272
        LiteralDecimal
 
273
        LiteralDate
 
274
 
 
275
        /* ----- special character ----- */
 
276
        "."
 
277
        "="
 
278
        ","
 
279
        ":"
 
280
        "+"
 
281
        "-"
 
282
        "*"
 
283
        "/"
 
284
        "\\"
 
285
        "&"
 
286
        "^"
 
287
        "?"
 
288
        "{"
 
289
        "}"
 
290
        "("
 
291
        ")"
 
292
        ">"
 
293
        "<"
 
294
        "<>"
 
295
        ">="
 
296
        "<="
 
297
        "<<"
 
298
        ">>"
 
299
        "+="
 
300
        "^="
 
301
        "-="
 
302
        "*="
 
303
        "/="
 
304
        "\\="
 
305
        "<<="
 
306
        ">>="
 
307
        "&="
 
308
 
 
309
        /* ----- keywords ----- */
 
310
        "AddHandler"
 
311
        "AddressOf"
 
312
        "Alias"
 
313
        "And"
 
314
        "AndAlso"
 
315
        "Ansi"
 
316
        "As"
 
317
        "Assembly"
 
318
        "Auto"
 
319
        "Binary"
 
320
        "Boolean"
 
321
        "ByRef"
 
322
        "Byte"
 
323
        "ByVal"
 
324
        "Call"
 
325
        "Case"
 
326
        "Catch"
 
327
        "CBool"
 
328
        "CByte"
 
329
        "CChar"
 
330
        "CDate"
 
331
        "CDbl"
 
332
        "CDec"
 
333
        "Char"
 
334
        "CInt"
 
335
        "Class"
 
336
        "CLng"
 
337
        "CObj"
 
338
        "Compare"
 
339
        "Const"
 
340
        "CShort"
 
341
        "CSng"
 
342
        "CStr"
 
343
        "CType"
 
344
        "Date"
 
345
        "Decimal"
 
346
        "Declare"
 
347
        "Default"
 
348
        "Delegate"
 
349
        "Dim"
 
350
        "DirectCast"
 
351
        "Do"
 
352
        "Double"
 
353
        "Each"
 
354
        "Else"
 
355
        "ElseIf"
 
356
        "End"
 
357
        "EndIf"
 
358
        "Enum"
 
359
        "Erase"
 
360
        "Error"
 
361
        "Event"
 
362
        "Exit"
 
363
        "Explicit"
 
364
        "False"
 
365
        "Finally"
 
366
        "For"
 
367
        "Friend"
 
368
        "Function"
 
369
        "Get"
 
370
        "GetType"
 
371
        "GoSub"
 
372
        "GoTo"
 
373
        "Handles"
 
374
        "If"
 
375
        "Implements"
 
376
        "Imports"
 
377
        "In"
 
378
        "Inherits"
 
379
        "Integer"
 
380
        "Interface"
 
381
        "Is"
 
382
        "Let"
 
383
        "Lib"
 
384
        "Like"
 
385
        "Long"
 
386
        "Loop"
 
387
        "Me"
 
388
        "Mod"
 
389
        "Module"
 
390
        "MustInherit"
 
391
        "MustOverride"
 
392
        "MyBase"
 
393
        "MyClass"
 
394
        "Namespace"
 
395
        "New"
 
396
        "Next"
 
397
        "Not"
 
398
        "Nothing"
 
399
        "NotInheritable"
 
400
        "NotOverridable"
 
401
        "Object"
 
402
        "Off"
 
403
        "On"
 
404
        "Option"
 
405
        "Optional"
 
406
        "Or"
 
407
        "OrElse"
 
408
        "Overloads"
 
409
        "Overridable"
 
410
        "Overrides"
 
411
        "ParamArray"
 
412
        "Preserve"
 
413
        "Private"
 
414
        "Property"
 
415
        "Protected"
 
416
        "Public"
 
417
        "RaiseEvent"
 
418
        "ReadOnly"
 
419
        "ReDim"
 
420
        "RemoveHandler"
 
421
        "Resume"
 
422
        "Return"
 
423
        "Select"
 
424
        "Set"
 
425
        "Shadows"
 
426
        "Shared"
 
427
        "Short"
 
428
        "Single"
 
429
        "Static"
 
430
        "Step"
 
431
        "Stop"
 
432
        "Strict"
 
433
        "String"
 
434
        "Structure"
 
435
        "Sub"
 
436
        "SyncLock"
 
437
        "Text"
 
438
        "Then"
 
439
        "Throw"
 
440
        "To"
 
441
        "True"
 
442
        "Try"
 
443
        "TypeOf"
 
444
        "Unicode"
 
445
        "Until"
 
446
        "Variant"
 
447
        "Wend"
 
448
        "When"
 
449
        "While"
 
450
        "With"
 
451
        "WithEvents"
 
452
        "WriteOnly"
 
453
        "Xor"
 
454
        "Continue"
 
455
        "Operator"
 
456
        "Using"
 
457
        "IsNot"
 
458
        "SByte"
 
459
        "UInteger"
 
460
        "ULong"
 
461
        "UShort"
 
462
        "CSByte"
 
463
        "CUShort"
 
464
        "CUInt"
 
465
        "CULng"
 
466
        "Global"
 
467
        "TryCast"
 
468
        "Of"
 
469
        "Narrowing"
 
470
        "Widening"
 
471
        "Partial"
 
472
        "Custom"
 
473
/* END AUTOGENERATED TOKENS SECTION */
 
474
 
 
475
 
 
476
PRODUCTIONS
 
477
 
 
478
VBNET
 
479
        (.
 
480
                lexer.NextToken(); // get the first token
 
481
                compilationUnit = new CompilationUnit();
 
482
                withStatements = new Stack();
 
483
        .) =
 
484
        { EOL }
 
485
        { OptionStmt }
 
486
        { ImportsStmt}
 
487
        { IF (IsGlobalAttrTarget()) GlobalAttributeSection }
 
488
        { NamespaceMemberDecl }
 
489
        EOF
 
490
        .
 
491
 
 
492
OptionStmt (. INode node = null; bool val = true; .) =
 
493
        "Option" (. Point startPos = t.Location; .)
 
494
        (
 
495
                "Explicit" [ OptionValue<ref val> ]
 
496
                (. node = new OptionDeclaration(OptionType.Explicit, val); .)
 
497
                |
 
498
                "Strict" [ OptionValue<ref val> ]
 
499
                (. node = new OptionDeclaration(OptionType.Strict, val); .)
 
500
                |
 
501
                "Compare" ( "Binary" (. node = new OptionDeclaration(OptionType.CompareBinary, val); .)
 
502
                                  | "Text" (. node = new OptionDeclaration(OptionType.CompareText, val); .)
 
503
                                  )
 
504
        )
 
505
        EndOfStmt
 
506
        (.
 
507
                if (node != null) {
 
508
                        node.StartLocation = startPos;
 
509
                        node.EndLocation   = t.Location;
 
510
                        compilationUnit.AddChild(node);
 
511
                }
 
512
        .)
 
513
        .
 
514
 
 
515
OptionValue<ref bool val> =
 
516
        (
 
517
                "On" (. val = true; .)
 
518
        |
 
519
                "Off" (. val = false; .)
 
520
        )
 
521
        .
 
522
 
 
523
EndOfStmt =
 
524
                EOL
 
525
        |
 
526
                ":" [ EOL ]
 
527
        .
 
528
 
 
529
ImportsStmt
 
530
        (.List<Using> usings = new List<Using>();
 
531
        .) =
 
532
        "Imports"
 
533
        (.
 
534
                Point startPos = t.Location;
 
535
                Using u;
 
536
        .)
 
537
        ImportClause<out u> (. if (u != null) { usings.Add(u); } .)
 
538
        {
 
539
                "," ImportClause<out u> (. if (u != null) { usings.Add(u); } .)
 
540
        }
 
541
        EndOfStmt
 
542
        (.
 
543
                UsingDeclaration usingDeclaration = new UsingDeclaration(usings);
 
544
                usingDeclaration.StartLocation = startPos;
 
545
                usingDeclaration.EndLocation   = t.Location;
 
546
                compilationUnit.AddChild(usingDeclaration);
 
547
        .)
 
548
        .
 
549
 
 
550
ImportClause<out Using u>
 
551
        (.
 
552
                string qualident  = null;
 
553
                TypeReference aliasedType = null;
 
554
                u = null;
 
555
        .) =
 
556
        Qualident<out qualident>
 
557
        [ "=" TypeName<out aliasedType> ]
 
558
        (.
 
559
                if (qualident != null && qualident.Length > 0) {
 
560
                        if (aliasedType != null) {
 
561
                                u = new Using(qualident, aliasedType);
 
562
                        } else {
 
563
                                u = new Using(qualident);
 
564
                        }
 
565
                }
 
566
        .)
 
567
        .
 
568
 
 
569
/* 6.4.2 */
 
570
NamespaceMemberDecl
 
571
        (.
 
572
                Modifiers m = new Modifiers();
 
573
                AttributeSection section;
 
574
                List<AttributeSection> attributes = new List<AttributeSection>();
 
575
                string qualident;
 
576
        .) =
 
577
        "Namespace"
 
578
        (.
 
579
                Point startPos = t.Location;
 
580
        .)
 
581
        Qualident<out qualident>
 
582
        (.
 
583
                INode node =  new NamespaceDeclaration(qualident);
 
584
                node.StartLocation = startPos;
 
585
                compilationUnit.AddChild(node);
 
586
                compilationUnit.BlockStart(node);
 
587
        .)
 
588
        EOL
 
589
        NamespaceBody
 
590
        (.
 
591
                node.EndLocation = t.Location;
 
592
                compilationUnit.BlockEnd();
 
593
        .)
 
594
        |
 
595
        { AttributeSection<out section> (. attributes.Add(section); .) }
 
596
        { TypeModifier<m> } NonModuleDeclaration<m, attributes>
 
597
        .
 
598
 
 
599
/* 4.9.1 */
 
600
TypeParameterList<List<TemplateDefinition> templates>
 
601
(.
 
602
        TemplateDefinition template;
 
603
.) =
 
604
        [
 
605
                IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
 
606
                "(" "Of" TypeParameter<out template>
 
607
                (.
 
608
                        if (template != null) templates.Add(template);
 
609
                .)
 
610
                {
 
611
                        "," TypeParameter<out template>
 
612
                        (.
 
613
                                if (template != null) templates.Add(template);
 
614
                        .)
 
615
                }
 
616
                ")"
 
617
        ]
 
618
.
 
619
 
 
620
/* 4.9.1 */
 
621
TypeParameter<out TemplateDefinition template>
 
622
=
 
623
        Identifier (. template = new TemplateDefinition(t.val, null); .)
 
624
        [TypeParameterConstraints<template>]
 
625
.
 
626
 
 
627
/* 4.9.2 */
 
628
TypeParameterConstraints<TemplateDefinition template>
 
629
(.
 
630
        TypeReference constraint;
 
631
.)
 
632
=
 
633
        "As"
 
634
        (
 
635
                "{"
 
636
                TypeName<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
 
637
                {
 
638
                        ","
 
639
                        TypeName<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
 
640
                }
 
641
                "}"
 
642
                | TypeName<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
 
643
        )
 
644
.
 
645
 
 
646
/* 6.4.2 */
 
647
NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
 
648
                        (.
 
649
                                TypeReference typeRef = null;
 
650
                                List<TypeReference> baseInterfaces = null;
 
651
                        .) =
 
652
        (. m.Check(Modifier.Classes); .)
 
653
        /* Spec, 7.5 */
 
654
        "Class"
 
655
                                        (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
 
656
                                                newType.StartLocation = t.Location;
 
657
                                                compilationUnit.AddChild(newType);
 
658
                                                compilationUnit.BlockStart(newType);
 
659
                                                
 
660
                                                newType.Type       = ClassType.Class;
 
661
                                        .)
 
662
        Identifier                       (. newType.Name = t.val; .) 
 
663
        TypeParameterList<newType.Templates>
 
664
        EndOfStmt
 
665
        (. newType.BodyStartLocation = t.Location; .)
 
666
        [ ClassBaseType<out typeRef> (. newType.BaseTypes.Add(typeRef); .) ]
 
667
        { TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
 
668
        ClassBody<newType>
 
669
        (.
 
670
                compilationUnit.BlockEnd();
 
671
        .)
 
672
        | "Module"
 
673
                (.
 
674
                        m.Check(Modifier.VBModules);
 
675
                        TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
 
676
                        compilationUnit.AddChild(newType);
 
677
                        compilationUnit.BlockStart(newType);
 
678
                        newType.StartLocation = m.GetDeclarationLocation(t.Location);
 
679
                        newType.Type = ClassType.Module;
 
680
                .)
 
681
        Identifier                       (. newType.Name = t.val; .)
 
682
        EOL
 
683
        (. newType.BodyStartLocation = t.Location; .)
 
684
        ModuleBody<newType>
 
685
        (.
 
686
                compilationUnit.BlockEnd();
 
687
        .)
 
688
        | "Structure"
 
689
                (.
 
690
                        m.Check(Modifier.VBStructures);
 
691
                        TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
 
692
                        compilationUnit.AddChild(newType);
 
693
                        compilationUnit.BlockStart(newType);
 
694
                        newType.StartLocation = m.GetDeclarationLocation(t.Location);
 
695
                        newType.Type = ClassType.Struct;
 
696
                .)
 
697
        Identifier                       (. newType.Name = t.val; .) 
 
698
        TypeParameterList<newType.Templates>
 
699
        EOL
 
700
        (. newType.BodyStartLocation = t.Location; .)
 
701
        { TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces);.) }
 
702
        StructureBody<newType>
 
703
        (.
 
704
                compilationUnit.BlockEnd();
 
705
        .)
 
706
        | /* 7.4 */
 
707
        "Enum"
 
708
                (.
 
709
                        m.Check(Modifier.VBEnums);
 
710
                        TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
 
711
                        newType.StartLocation = m.GetDeclarationLocation(t.Location);
 
712
                        compilationUnit.AddChild(newType);
 
713
                        compilationUnit.BlockStart(newType);
 
714
                        
 
715
                        newType.Type = ClassType.Enum;
 
716
                .)
 
717
        Identifier                       (. newType.Name = t.val; .) 
 
718
        [ "As" NonArrayTypeName<out typeRef, false> (. newType.BaseTypes.Add(typeRef); .) ]
 
719
        EOL
 
720
        (. newType.BodyStartLocation = t.Location; .)
 
721
        EnumBody<newType>
 
722
        (.
 
723
                compilationUnit.BlockEnd();
 
724
        .)
 
725
        | /* 7.8 */
 
726
        "Interface"
 
727
                (.
 
728
                        m.Check(Modifier.VBInterfacs);
 
729
                        TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
 
730
                        newType.StartLocation = m.GetDeclarationLocation(t.Location);
 
731
                        compilationUnit.AddChild(newType);
 
732
                        compilationUnit.BlockStart(newType);
 
733
                        newType.Type = ClassType.Interface;
 
734
                .)
 
735
        Identifier                       (. newType.Name = t.val; .) 
 
736
        TypeParameterList<newType.Templates>
 
737
        EndOfStmt
 
738
        (. newType.BodyStartLocation = t.Location; .)
 
739
        { InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
 
740
        InterfaceBody<newType>
 
741
        (.
 
742
                compilationUnit.BlockEnd();
 
743
        .)
 
744
        | /* 7.10 */
 
745
        "Delegate"
 
746
        (.
 
747
                m.Check(Modifier.VBDelegates);
 
748
                DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes);
 
749
                delegateDeclr.ReturnType = new TypeReference("", "System.Void");
 
750
                delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location);
 
751
                List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
 
752
        .)
 
753
        (
 
754
                "Sub" Identifier (. delegateDeclr.Name = t.val; .)
 
755
                TypeParameterList<delegateDeclr.Templates>
 
756
                [ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ]
 
757
                |
 
758
                "Function" Identifier (. delegateDeclr.Name = t.val; .)
 
759
                TypeParameterList<delegateDeclr.Templates>
 
760
                [ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ]
 
761
                [ "As" (. TypeReference type; .) TypeName<out type> (. delegateDeclr.ReturnType = type; .)]
 
762
        )
 
763
        (.              delegateDeclr.EndLocation = t.EndLocation; .)
 
764
        EOL
 
765
        (.
 
766
                compilationUnit.AddChild(delegateDeclr);
 
767
        .)
 
768
        .
 
769
 
 
770
NamespaceBody =
 
771
        { NamespaceMemberDecl }
 
772
        "End" "Namespace"
 
773
        EOL
 
774
        .
 
775
 
 
776
ClassBody<TypeDeclaration newType>
 
777
        (. AttributeSection section; .) =
 
778
        {
 
779
                (.List<AttributeSection> attributes = new List<AttributeSection>();
 
780
                        Modifiers m = new Modifiers();
 
781
                .)
 
782
                { AttributeSection<out section> (. attributes.Add(section); .) }
 
783
                { MemberModifier<m> }
 
784
                ClassMemberDecl<m, attributes>
 
785
        }
 
786
        "End" "Class" (. newType.EndLocation = t.EndLocation; .)
 
787
        EOL
 
788
        .
 
789
 
 
790
StructureBody<TypeDeclaration newType>
 
791
        (. AttributeSection section; .) =
 
792
        {
 
793
                (.List<AttributeSection> attributes = new List<AttributeSection>();
 
794
                        Modifiers m = new Modifiers();
 
795
                .)
 
796
                { AttributeSection<out section> (. attributes.Add(section); .) }
 
797
                { MemberModifier<m> }
 
798
                StructureMemberDecl<m, attributes>
 
799
        }
 
800
        "End" "Structure" (. newType.EndLocation = t.EndLocation; .)
 
801
        EOL
 
802
        .
 
803
 
 
804
/* 7.7.1 */
 
805
ModuleBody<TypeDeclaration newType>
 
806
        (. AttributeSection section; .) =
 
807
        {
 
808
                (.List<AttributeSection> attributes = new List<AttributeSection>();
 
809
                        Modifiers m = new Modifiers();
 
810
                .)
 
811
                { AttributeSection<out section> (. attributes.Add(section); .) }
 
812
                { MemberModifier<m> }
 
813
                ClassMemberDecl<m, attributes>
 
814
        }
 
815
        "End" "Module" (. newType.EndLocation = t.EndLocation; .)
 
816
        EOL
 
817
        .
 
818
 
 
819
EnumBody<TypeDeclaration newType>
 
820
        (. FieldDeclaration f; .) =
 
821
        {
 
822
                EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
 
823
        }
 
824
        "End" "Enum" (. newType.EndLocation = t.EndLocation; .)
 
825
        EOL
 
826
        .
 
827
 
 
828
InterfaceBody<TypeDeclaration newType> =
 
829
        { InterfaceMemberDecl }
 
830
        "End" "Interface" (. newType.EndLocation = t.EndLocation; .)
 
831
        EOL
 
832
        .
 
833
 
 
834
/* The information provided in the spec about */
 
835
/* interface declarations is wrong */
 
836
InterfaceMemberDecl
 
837
        (.
 
838
                TypeReference type =null;
 
839
                List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
 
840
                List<TemplateDefinition> templates = new List<TemplateDefinition>();
 
841
                AttributeSection section, returnTypeAttributeSection = null;
 
842
                Modifiers mod = new Modifiers();
 
843
                List<AttributeSection> attributes = new List<AttributeSection>();
 
844
                string name;
 
845
        .) =
 
846
        { AttributeSection<out section>                 (. attributes.Add(section); .) }
 
847
        /* this is different to c#: not only the Shadows modifier is allowed, */
 
848
        /*  also member modifiers like overloads etc. */
 
849
        { MemberModifier<mod> }
 
850
        (
 
851
                "Event"
 
852
                (. mod.Check(Modifier.VBInterfaceEvents); .)
 
853
                Identifier (. name = t.val; .)
 
854
                [ "(" [ FormalParameterList<p> ] ")" ]
 
855
                [ "As" TypeName<out type> ]
 
856
                EOL
 
857
                (.
 
858
                        EventDeclaration ed = new EventDeclaration(type, mod.Modifier, p, attributes, name, null);
 
859
                        compilationUnit.AddChild(ed);
 
860
                        ed.EndLocation = t.EndLocation;
 
861
                .)
 
862
                |
 
863
                "Sub"
 
864
                (. mod.Check(Modifier.VBInterfaceMethods); .)
 
865
                Identifier (. name = t.val; .)
 
866
                TypeParameterList<templates>
 
867
                [ "(" [ FormalParameterList<p> ] ")" ]
 
868
                EOL
 
869
                (.
 
870
                        MethodDeclaration md = new MethodDeclaration(name, mod.Modifier, null, p, attributes);
 
871
                        md.TypeReference = new TypeReference("", "System.Void");
 
872
                        md.EndLocation = t.EndLocation;
 
873
                        md.Templates = templates;
 
874
                        compilationUnit.AddChild(md);
 
875
                .)
 
876
                |
 
877
                "Function"
 
878
                (. mod.Check(Modifier.VBInterfaceMethods); .)
 
879
                Identifier (. name = t.val; .)
 
880
                TypeParameterList<templates>
 
881
                [ "(" [ FormalParameterList<p> ] ")" ]
 
882
                [ "As" { AttributeSection<out returnTypeAttributeSection> } TypeName<out type> ]
 
883
                (.
 
884
                        if(type == null) {
 
885
                                type = new TypeReference("System.Object");
 
886
                        }
 
887
                        MethodDeclaration md = new MethodDeclaration(name, mod.Modifier, type, p, attributes);
 
888
                        if (returnTypeAttributeSection != null) {
 
889
                                returnTypeAttributeSection.AttributeTarget = "return";
 
890
                                md.Attributes.Add(returnTypeAttributeSection);
 
891
                        }
 
892
                        md.EndLocation = t.EndLocation;
 
893
                        md.Templates = templates;
 
894
                        compilationUnit.AddChild(md);
 
895
                .)
 
896
                EOL
 
897
                |
 
898
                "Property"
 
899
                (. mod.Check(Modifier.VBInterfaceProperties); .)
 
900
                Identifier      (. name = t.val;  .)
 
901
                [ "(" [ FormalParameterList<p> ] ")" ]
 
902
                [ "As" TypeName<out type> ]
 
903
                (.
 
904
                        if(type == null) {
 
905
                                type = new TypeReference("System.Object");
 
906
                        }
 
907
                .)
 
908
                EOL
 
909
                (.
 
910
                        PropertyDeclaration pd = new PropertyDeclaration(name, type, mod.Modifier, attributes);
 
911
                        pd.Parameters = p;
 
912
                        pd.EndLocation = t.EndLocation;
 
913
                        compilationUnit.AddChild(pd);
 
914
                .)
 
915
        )
 
916
        | /* inner type declarations */
 
917
        NonModuleDeclaration<mod, attributes>
 
918
        .
 
919
 
 
920
/* 7.4.1 */
 
921
EnumMemberDecl<out FieldDeclaration f>
 
922
        (.
 
923
                Expression expr = null;List<AttributeSection> attributes = new List<AttributeSection>();
 
924
                AttributeSection section = null;
 
925
                VariableDeclaration varDecl = null;
 
926
        .) =
 
927
        { AttributeSection<out section> (. attributes.Add(section); .) }
 
928
        Identifier
 
929
        (.
 
930
                f = new FieldDeclaration(attributes);
 
931
                varDecl = new VariableDeclaration(t.val);
 
932
                f.Fields.Add(varDecl);
 
933
                f.StartLocation = t.Location;
 
934
        .)
 
935
        [ "=" Expr<out expr> (. varDecl.Initializer = expr; .) ]
 
936
        EOL
 
937
        .
 
938
 
 
939
ClassMemberDecl<Modifiers m, List<AttributeSection> attributes> =
 
940
        StructureMemberDecl<m, attributes>
 
941
        .
 
942
 
 
943
ClassBaseType<out TypeReference typeRef>
 
944
(.
 
945
        typeRef = null;
 
946
.) =
 
947
        "Inherits"
 
948
        TypeName<out typeRef>
 
949
        EndOfStmt
 
950
.
 
951
 
 
952
/* 7.6.1 */
 
953
StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
 
954
        (.
 
955
                TypeReference type = null;
 
956
                List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
 
957
                Statement stmt = null;
 
958
                List<VariableDeclaration> variableDeclarators = new List<VariableDeclaration>();
 
959
                List<TemplateDefinition> templates = new List<TemplateDefinition>();
 
960
        .)=
 
961
        NonModuleDeclaration<m, attributes>
 
962
        | /* 9.2.1 */
 
963
        "Sub"
 
964
        (.
 
965
                Point startPos = t.Location;
 
966
        .)
 
967
        (
 
968
                (.
 
969
                        string name = String.Empty;
 
970
                        MethodDeclaration methodDeclaration; List<string> handlesClause = null;
 
971
                        List<InterfaceImplementation> implementsClause = null;
 
972
                .)
 
973
                Identifier
 
974
                (.
 
975
                        name = t.val;
 
976
                        m.Check(Modifier.VBMethods);
 
977
                .)
 
978
                TypeParameterList<templates>
 
979
                [ "(" [ FormalParameterList<p> ] ")" ]
 
980
                [
 
981
                        (
 
982
                                ImplementsClause<out implementsClause>
 
983
                                |
 
984
                                HandlesClause<out handlesClause>
 
985
                        )
 
986
                ]
 
987
                (. Point endLocation = t.EndLocation; .)
 
988
                EOL
 
989
                (
 
990
                        /* abstract methods without a body */
 
991
                        IF(IsMustOverride(m))
 
992
                        (.
 
993
                                methodDeclaration = new MethodDeclaration(name, m.Modifier,  null, p, attributes);
 
994
                                methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
 
995
                                methodDeclaration.EndLocation   = endLocation;
 
996
                                methodDeclaration.TypeReference = new TypeReference("", "System.Void");
 
997
                                
 
998
                                methodDeclaration.Templates = templates;
 
999
                                methodDeclaration.HandlesClause = handlesClause;
 
1000
                                methodDeclaration.InterfaceImplementations = implementsClause;
 
1001
                                
 
1002
                                compilationUnit.AddChild(methodDeclaration);
 
1003
                        .)
 
1004
                |
 
1005
                        (.
 
1006
                                methodDeclaration = new MethodDeclaration(name, m.Modifier,  null, p, attributes);
 
1007
                                methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
 
1008
                                methodDeclaration.EndLocation   = endLocation;
 
1009
                                methodDeclaration.TypeReference = new TypeReference("", "System.Void");
 
1010
                                
 
1011
                                methodDeclaration.Templates = templates;
 
1012
                                methodDeclaration.HandlesClause = handlesClause;
 
1013
                                methodDeclaration.InterfaceImplementations = implementsClause;
 
1014
                                
 
1015
                                compilationUnit.AddChild(methodDeclaration);
 
1016
                                compilationUnit.BlockStart(methodDeclaration);
 
1017
                        .)
 
1018
                        Block<out stmt>
 
1019
                        (.
 
1020
                                compilationUnit.BlockEnd();
 
1021
                                methodDeclaration.Body  = (BlockStatement)stmt;
 
1022
                        .)
 
1023
                        "End" "Sub" (. methodDeclaration.Body.EndLocation = t.EndLocation; .) EOL 
 
1024
                )
 
1025
                /* 9.3 */
 
1026
                | "New" [ "(" [ FormalParameterList<p> ] ")" ]
 
1027
                (. m.Check(Modifier.Constructors); .)
 
1028
                (. Point constructorEndLocation = t.EndLocation; .)
 
1029
                EOL
 
1030
                Block<out stmt>
 
1031
                "End" "Sub" (. Point endLocation = t.EndLocation; .) EOL
 
1032
                (.
 
1033
                        ConstructorDeclaration cd = new ConstructorDeclaration("New", m.Modifier, p, attributes); 
 
1034
                        cd.StartLocation = m.GetDeclarationLocation(startPos);
 
1035
                        cd.EndLocation   = constructorEndLocation;
 
1036
                        cd.Body = (BlockStatement)stmt;
 
1037
                        cd.Body.EndLocation   = endLocation;
 
1038
                        compilationUnit.AddChild(cd);
 
1039
                .)
 
1040
        )
 
1041
        |
 
1042
        /* 9.2.1 */
 
1043
        "Function"
 
1044
        (.
 
1045
                m.Check(Modifier.VBMethods);
 
1046
                string name = String.Empty;
 
1047
                Point startPos = t.Location;
 
1048
                MethodDeclaration methodDeclaration;List<string> handlesClause = null;
 
1049
                List<InterfaceImplementation> implementsClause = null;
 
1050
                AttributeSection returnTypeAttributeSection = null;
 
1051
        .)
 
1052
        Identifier                      (. name = t.val; .)
 
1053
        TypeParameterList<templates>
 
1054
        [ "("   [ FormalParameterList<p> ] ")" ]
 
1055
        ["As"  { AttributeSection<out returnTypeAttributeSection> } TypeName<out type> ]
 
1056
        (.
 
1057
                if(type == null) {
 
1058
                        type = new TypeReference("System.Object");
 
1059
                }
 
1060
        .)
 
1061
        [
 
1062
                (
 
1063
                        ImplementsClause<out implementsClause>
 
1064
                        |
 
1065
                        HandlesClause<out handlesClause>
 
1066
                )
 
1067
        ]
 
1068
        EOL
 
1069
        (
 
1070
                /* abstract methods without a body */
 
1071
                IF(IsMustOverride(m))
 
1072
                        (.
 
1073
                                methodDeclaration = new MethodDeclaration(name, m.Modifier,  type, p, attributes);
 
1074
                                methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
 
1075
                                methodDeclaration.EndLocation   = t.EndLocation;
 
1076
                                
 
1077
                                methodDeclaration.HandlesClause = handlesClause;
 
1078
                                methodDeclaration.Templates     = templates;
 
1079
                                methodDeclaration.InterfaceImplementations = implementsClause;
 
1080
                                if (returnTypeAttributeSection != null) {
 
1081
                                        returnTypeAttributeSection.AttributeTarget = "return";
 
1082
                                        methodDeclaration.Attributes.Add(returnTypeAttributeSection);
 
1083
                                }
 
1084
                                compilationUnit.AddChild(methodDeclaration);
 
1085
                        .)
 
1086
                |
 
1087
                        (.
 
1088
                                methodDeclaration = new MethodDeclaration(name, m.Modifier,  type, p, attributes);
 
1089
                                methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
 
1090
                                methodDeclaration.EndLocation   = t.EndLocation;
 
1091
                                
 
1092
                                methodDeclaration.Templates     = templates;
 
1093
                                methodDeclaration.HandlesClause = handlesClause;
 
1094
                                methodDeclaration.InterfaceImplementations = implementsClause;
 
1095
                                if (returnTypeAttributeSection != null) {
 
1096
                                        returnTypeAttributeSection.AttributeTarget = "return";
 
1097
                                        methodDeclaration.Attributes.Add(returnTypeAttributeSection);
 
1098
                                }
 
1099
                                
 
1100
                                compilationUnit.AddChild(methodDeclaration);
 
1101
                                compilationUnit.BlockStart(methodDeclaration);
 
1102
                        .)
 
1103
                        Block<out stmt>
 
1104
                        (.
 
1105
                                compilationUnit.BlockEnd();
 
1106
                                methodDeclaration.Body  = (BlockStatement)stmt;
 
1107
                        .)
 
1108
                        "End" "Function" 
 
1109
                        (.
 
1110
                                methodDeclaration.Body.StartLocation = methodDeclaration.EndLocation;
 
1111
                                methodDeclaration.Body.EndLocation   = t.EndLocation;
 
1112
                        .)
 
1113
                        EOL
 
1114
        )
 
1115
        |
 
1116
        /* 9.2.2. */
 
1117
        "Declare"
 
1118
        (.
 
1119
                m.Check(Modifier.VBExternalMethods);
 
1120
                Point startPos = t.Location;
 
1121
                CharsetModifier charsetModifer = CharsetModifier.None;
 
1122
                string library = String.Empty;
 
1123
                string alias = null;
 
1124
                string name = String.Empty;
 
1125
        .)
 
1126
        [Charset<out charsetModifer> ]
 
1127
        (
 
1128
                        "Sub"
 
1129
                        Identifier                              (. name = t.val; .)
 
1130
                        "Lib" LiteralString             (. library = t.literalValue.ToString(); .)
 
1131
                        ["Alias" LiteralString  (. alias = t.literalValue.ToString(); .)]
 
1132
                        [ "("   [ FormalParameterList<p> ] ")" ]
 
1133
                        EOL
 
1134
                        (.
 
1135
                                DeclareDeclaration declareDeclaration = new DeclareDeclaration(name, m.Modifier, null, p, attributes, library, alias, charsetModifer);
 
1136
                                declareDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
 
1137
                                declareDeclaration.EndLocation   = t.EndLocation;
 
1138
                                compilationUnit.AddChild(declareDeclaration);
 
1139
                        .)
 
1140
                |
 
1141
                        "Function" 
 
1142
                        Identifier                                      (. name = t.val; .)
 
1143
                        "Lib" LiteralString             (. library = t.literalValue.ToString(); .)
 
1144
                        ["Alias" LiteralString  (. alias = t.literalValue.ToString(); .)]
 
1145
                        [ "("   [ FormalParameterList<p> ] ")" ]
 
1146
                        ["As" TypeName<out type> ]
 
1147
                        EOL
 
1148
                        (.
 
1149
                                DeclareDeclaration declareDeclaration = new DeclareDeclaration(name, m.Modifier, type, p, attributes, library, alias, charsetModifer);
 
1150
                                declareDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
 
1151
                                declareDeclaration.EndLocation   = t.EndLocation;
 
1152
                                compilationUnit.AddChild(declareDeclaration);
 
1153
                        .)
 
1154
                )
 
1155
        |
 
1156
        /* 9. 4 */
 
1157
        "Event"
 
1158
        (.
 
1159
                m.Check(Modifier.VBEvents);
 
1160
                Point startPos = t.Location;
 
1161
                EventDeclaration eventDeclaration;
 
1162
                string name = String.Empty;
 
1163
                List<InterfaceImplementation> implementsClause = null;
 
1164
        .)
 
1165
        Identifier (. name= t.val; .)
 
1166
        (
 
1167
                "As" TypeName<out type>
 
1168
                |
 
1169
                [ "("   [ FormalParameterList<p> ] ")" ]
 
1170
        )
 
1171
        [ ImplementsClause<out implementsClause> ]
 
1172
        (.
 
1173
                eventDeclaration = new EventDeclaration(type, m.Modifier, p, attributes, name, implementsClause);
 
1174
                eventDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
 
1175
                eventDeclaration.EndLocation = t.EndLocation;
 
1176
                compilationUnit.AddChild(eventDeclaration);
 
1177
        .)
 
1178
        EOL
 
1179
        | /* 9.6 */
 
1180
        (. Point startPos = t.Location; .)
 
1181
        (.
 
1182
                m.Check(Modifier.Fields);
 
1183
                FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
 
1184
                fd.StartLocation = m.GetDeclarationLocation(startPos); 
 
1185
        .)
 
1186
        VariableDeclarator<variableDeclarators>
 
1187
        { "," VariableDeclarator<variableDeclarators> }
 
1188
        EOL
 
1189
        (.
 
1190
                fd.EndLocation = t.EndLocation;
 
1191
                fd.Fields = variableDeclarators;
 
1192
                compilationUnit.AddChild(fd);
 
1193
        .)
 
1194
        | /* 9.4 */
 
1195
        (. m.Check(Modifier.Fields); .)
 
1196
        "Const" (.  m.Add(Modifier.Const, t.Location);  .)
 
1197
        (.
 
1198
                FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
 
1199
                fd.StartLocation = m.GetDeclarationLocation(t.Location);
 
1200
                List<VariableDeclaration> constantDeclarators = new List<VariableDeclaration>();
 
1201
        .)
 
1202
        ConstantDeclarator<constantDeclarators>
 
1203
        { "," ConstantDeclarator<constantDeclarators> }
 
1204
        (.
 
1205
                fd.Fields = constantDeclarators;
 
1206
                fd.EndLocation = t.Location;
 
1207
        .)
 
1208
        EOL
 
1209
        (.
 
1210
                fd.EndLocation = t.EndLocation;
 
1211
                compilationUnit.AddChild(fd);
 
1212
        .)
 
1213
        | /* 9.7 */
 
1214
        "Property"
 
1215
        (.
 
1216
                m.Check(Modifier.VBProperties);
 
1217
                Point startPos = t.Location;
 
1218
                List<InterfaceImplementation> implementsClause = null;
 
1219
        .)
 
1220
        Identifier (. string propertyName = t.val; .)
 
1221
        [ "("   [ FormalParameterList<p> ] ")" ]
 
1222
        [ "As" TypeName<out type> ]
 
1223
        (.
 
1224
                if(type == null) {
 
1225
                        type = new TypeReference("System.Object");
 
1226
                }
 
1227
        .)
 
1228
        [ ImplementsClause<out implementsClause> ]
 
1229
        EOL
 
1230
        (
 
1231
        /* abstract properties without a body */
 
1232
        IF(IsMustOverride(m))
 
1233
                (.
 
1234
                        PropertyDeclaration pDecl = new PropertyDeclaration(propertyName, type, m.Modifier, attributes);
 
1235
                        pDecl.StartLocation = m.GetDeclarationLocation(startPos);
 
1236
                        pDecl.EndLocation   = t.Location;
 
1237
                        pDecl.TypeReference = type;
 
1238
                        pDecl.InterfaceImplementations = implementsClause;
 
1239
                        pDecl.Parameters = p;
 
1240
                        compilationUnit.AddChild(pDecl);
 
1241
                .)
 
1242
        |
 
1243
                (.
 
1244
                        PropertyDeclaration pDecl = new PropertyDeclaration(propertyName, type, m.Modifier, attributes);
 
1245
                        pDecl.StartLocation = m.GetDeclarationLocation(startPos);
 
1246
                        pDecl.EndLocation   = t.Location;
 
1247
                        pDecl.BodyStart   = t.Location;
 
1248
                        pDecl.TypeReference = type;
 
1249
                        pDecl.InterfaceImplementations = implementsClause;
 
1250
                        pDecl.Parameters = p;
 
1251
                        PropertyGetRegion getRegion;
 
1252
                        PropertySetRegion setRegion;
 
1253
                .)
 
1254
                AccessorDecls<out getRegion, out setRegion> 
 
1255
                "End" "Property"
 
1256
                EOL
 
1257
                (.
 
1258
                        pDecl.GetRegion = getRegion;
 
1259
                        pDecl.SetRegion = setRegion;
 
1260
                        pDecl.BodyEnd = t.EndLocation;
 
1261
                        compilationUnit.AddChild(pDecl);
 
1262
                .)
 
1263
        )
 
1264
        |
 
1265
        "Custom" (. Point startPos = t.Location; .) "Event"
 
1266
        (.
 
1267
                m.Check(Modifier.VBCustomEvents);
 
1268
                EventAddRemoveRegion eventAccessorDeclaration;
 
1269
                EventAddRegion addHandlerAccessorDeclaration = null;
 
1270
                EventRemoveRegion removeHandlerAccessorDeclaration = null;
 
1271
                EventRaiseRegion raiseEventAccessorDeclaration = null;
 
1272
                List<InterfaceImplementation> implementsClause = null;
 
1273
        .)
 
1274
        Identifier (. string customEventName = t.val; .)
 
1275
        "As" TypeName<out type>
 
1276
        [ ImplementsClause<out implementsClause> ]
 
1277
        EOL
 
1278
        {
 
1279
                EventAccessorDeclaration<out eventAccessorDeclaration>
 
1280
                (.
 
1281
                        if(eventAccessorDeclaration is EventAddRegion)
 
1282
                        {
 
1283
                                addHandlerAccessorDeclaration = (EventAddRegion)eventAccessorDeclaration;
 
1284
                        }
 
1285
                        else if(eventAccessorDeclaration is EventRemoveRegion)
 
1286
                        {
 
1287
                                removeHandlerAccessorDeclaration = (EventRemoveRegion)eventAccessorDeclaration;
 
1288
                        }
 
1289
                        else if(eventAccessorDeclaration is EventRaiseRegion)
 
1290
                        {
 
1291
                                raiseEventAccessorDeclaration = (EventRaiseRegion)eventAccessorDeclaration;
 
1292
                        }
 
1293
                .)
 
1294
        }
 
1295
        "End" "Event" EOL
 
1296
        (.
 
1297
                if(addHandlerAccessorDeclaration == null)
 
1298
                {
 
1299
                        Error("Need to provide AddHandler accessor.");
 
1300
                }
 
1301
                
 
1302
                if(removeHandlerAccessorDeclaration == null)
 
1303
                {
 
1304
                        Error("Need to provide RemoveHandler accessor.");
 
1305
                }
 
1306
                
 
1307
                if(raiseEventAccessorDeclaration == null)
 
1308
                {
 
1309
                        Error("Need to provide RaiseEvent accessor.");
 
1310
                }
 
1311
        
 
1312
                EventDeclaration decl = new EventDeclaration(type, customEventName, m.Modifier, attributes, null);
 
1313
                decl.StartLocation = m.GetDeclarationLocation(startPos);
 
1314
                decl.EndLocation = t.EndLocation;
 
1315
                decl.AddRegion = addHandlerAccessorDeclaration;
 
1316
                decl.RemoveRegion = removeHandlerAccessorDeclaration;
 
1317
                decl.RaiseRegion = raiseEventAccessorDeclaration;
 
1318
                compilationUnit.AddChild(decl);
 
1319
        .)
 
1320
        |
 
1321
        "Operator"
 
1322
        (.
 
1323
                m.Check(Modifier.VBOperators);
 
1324
                Point startPos = t.Location;
 
1325
                TypeReference returnType = NullTypeReference.Instance;
 
1326
                TypeReference operandType = NullTypeReference.Instance;
 
1327
                string operandName;
 
1328
                OverloadableOperatorType operatorType;
 
1329
                AttributeSection section;
 
1330
                List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
 
1331
                List<AttributeSection> returnTypeAttributes = new List<AttributeSection>();
 
1332
        .)
 
1333
        OverloadableOperator<out operatorType>
 
1334
        "(" [ "ByVal" ] Identifier (. operandName = t.val; .)
 
1335
                [ "As" TypeName<out operandType> ]
 
1336
                (. parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParamModifier.In)); .)
 
1337
                
 
1338
                {
 
1339
                        ","
 
1340
                        [ "ByVal" ] Identifier (. operandName = t.val; .)
 
1341
                        [ "As" TypeName<out operandType> ]
 
1342
                        (. parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParamModifier.In)); .)
 
1343
                }
 
1344
        ")"
 
1345
        (. Point endPos = t.EndLocation; .)
 
1346
        [ "As" { AttributeSection<out section> (. returnTypeAttributes.Add(section); .) } TypeName<out returnType> (. endPos = t.EndLocation; .) EOL ]
 
1347
        Block<out stmt> "End" "Operator" EOL
 
1348
        (.
 
1349
                OperatorDeclaration operatorDeclaration = new OperatorDeclaration(m.Modifier, 
 
1350
                                                                                  attributes, 
 
1351
                                                                                  parameters, 
 
1352
                                                                                  returnType,
 
1353
                                                                                  operatorType
 
1354
                                                                                  );
 
1355
                operatorDeclaration.ReturnTypeAttributes = returnTypeAttributes;
 
1356
                operatorDeclaration.Body = (BlockStatement)stmt;
 
1357
                operatorDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
 
1358
                operatorDeclaration.EndLocation = endPos;
 
1359
                operatorDeclaration.Body.StartLocation = startPos;
 
1360
                operatorDeclaration.Body.EndLocation = t.Location;
 
1361
                compilationUnit.AddChild(operatorDeclaration);
 
1362
        .)
 
1363
        .
 
1364
 
 
1365
OverloadableOperator<out OverloadableOperatorType operatorType>
 
1366
        (. operatorType = OverloadableOperatorType.None; .)
 
1367
        =
 
1368
        "+"                     (. operatorType = OverloadableOperatorType.Add; .)
 
1369
        |
 
1370
        "-"                     (. operatorType = OverloadableOperatorType.Subtract; .)
 
1371
        |
 
1372
        "*"                     (. operatorType = OverloadableOperatorType.Multiply; .)
 
1373
        | 
 
1374
        "/"                     (. operatorType = OverloadableOperatorType.Divide; .)
 
1375
        | 
 
1376
        "\\"            (. operatorType = OverloadableOperatorType.DivideInteger; .)
 
1377
        | 
 
1378
        "&"                     (. operatorType = OverloadableOperatorType.Concat; .)
 
1379
        | 
 
1380
        "Like"          (. operatorType = OverloadableOperatorType.Like; .)
 
1381
        | 
 
1382
        "Mod"           (. operatorType = OverloadableOperatorType.Modulus; .)
 
1383
        | 
 
1384
        "And"           (. operatorType = OverloadableOperatorType.BitwiseAnd; .)
 
1385
        |
 
1386
        "Or"            (. operatorType = OverloadableOperatorType.BitwiseOr; .)
 
1387
        |
 
1388
        "Xor"           (. operatorType = OverloadableOperatorType.ExclusiveOr; .)
 
1389
        |
 
1390
        "^"                     (. operatorType = OverloadableOperatorType.Power; .)
 
1391
        |
 
1392
        "<<"            (. operatorType = OverloadableOperatorType.ShiftLeft; .)
 
1393
        |
 
1394
        ">>"            (. operatorType = OverloadableOperatorType.ShiftRight; .)
 
1395
        |
 
1396
        "="                     (. operatorType = OverloadableOperatorType.Equality; .)
 
1397
        |
 
1398
        "<>"            (. operatorType = OverloadableOperatorType.InEquality; .)
 
1399
        |
 
1400
        "<"                     (. operatorType = OverloadableOperatorType.LessThan; .)
 
1401
        |
 
1402
        "<="            (. operatorType = OverloadableOperatorType.LessThanOrEqual; .)
 
1403
        |
 
1404
        ">"                     (. operatorType = OverloadableOperatorType.GreaterThan; .)
 
1405
        |
 
1406
        ">="            (. operatorType = OverloadableOperatorType.GreaterThanOrEqual; .)
 
1407
        |
 
1408
        "CType"         (. operatorType = OverloadableOperatorType.CType; .)
 
1409
        |
 
1410
        Identifier
 
1411
        (.
 
1412
                string opName = t.val; 
 
1413
                if (string.Equals(opName, "istrue", StringComparison.InvariantCultureIgnoreCase)) {
 
1414
                        operatorType = OverloadableOperatorType.IsTrue;
 
1415
                } else if (string.Equals(opName, "isfalse", StringComparison.InvariantCultureIgnoreCase)) {
 
1416
                        operatorType = OverloadableOperatorType.IsFalse;
 
1417
                } else {
 
1418
                        Error("Invalid operator. Possible operators are '+', '-', 'Not', 'IsTrue', 'IsFalse'.");
 
1419
                }
 
1420
        .)
 
1421
        .
 
1422
 
 
1423
EventAccessorDeclaration<out EventAddRemoveRegion eventAccessorDeclaration>
 
1424
        (.
 
1425
                Statement stmt = null;
 
1426
                List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
 
1427
                AttributeSection section;
 
1428
                List<AttributeSection> attributes = new List<AttributeSection>();
 
1429
                eventAccessorDeclaration = null;
 
1430
        .) =
 
1431
        { AttributeSection<out section> (. attributes.Add(section); .) }
 
1432
        (
 
1433
                        "AddHandler" [ "(" [ FormalParameterList<p> ] ")" ] EOL
 
1434
                        Block<out stmt> "End" "AddHandler" EOL
 
1435
                        (.
 
1436
                                eventAccessorDeclaration = new EventAddRegion(attributes);
 
1437
                                eventAccessorDeclaration.Block = (BlockStatement)stmt;
 
1438
                                eventAccessorDeclaration.Parameters = p;
 
1439
                        .)
 
1440
                |
 
1441
                        "RemoveHandler" [ "(" [ FormalParameterList<p> ] ")" ] EOL
 
1442
                        Block<out stmt> "End" "RemoveHandler" EOL
 
1443
                        (.
 
1444
                                eventAccessorDeclaration = new EventRemoveRegion(attributes);
 
1445
                                eventAccessorDeclaration.Block = (BlockStatement)stmt;
 
1446
                                eventAccessorDeclaration.Parameters = p;
 
1447
                        .)
 
1448
                |
 
1449
                        "RaiseEvent" [ "(" [ FormalParameterList<p> ] ")" ] EOL
 
1450
                        Block<out stmt> "End" "RaiseEvent" EOL
 
1451
                        (.
 
1452
                                eventAccessorDeclaration = new EventRaiseRegion(attributes);
 
1453
                                eventAccessorDeclaration.Block = (BlockStatement)stmt;
 
1454
                                eventAccessorDeclaration.Parameters = p;
 
1455
                        .)
 
1456
        )
 
1457
        .
 
1458
 
 
1459
/* 9.7 */
 
1460
AccessorDecls<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
 
1461
        (.
 
1462
                List<AttributeSection> attributes = new List<AttributeSection>();
 
1463
                AttributeSection section;
 
1464
                getBlock = null;
 
1465
                setBlock = null; 
 
1466
        .) =
 
1467
        { AttributeSection<out section> (. attributes.Add(section); .) }
 
1468
        (
 
1469
                GetAccessorDecl<out getBlock, attributes>
 
1470
                [
 
1471
                        (. attributes = new List<AttributeSection>(); .)
 
1472
                        { AttributeSection<out section> (. attributes.Add(section); .) }
 
1473
                        SetAccessorDecl<out setBlock, attributes>
 
1474
                ]
 
1475
                |
 
1476
                SetAccessorDecl<out setBlock, attributes>
 
1477
                [
 
1478
                        (. attributes = new List<AttributeSection>(); .)
 
1479
                        { AttributeSection<out section> (. attributes.Add(section); .) }
 
1480
                        GetAccessorDecl<out getBlock, attributes>
 
1481
                ]
 
1482
        )
 
1483
        .
 
1484
 
 
1485
/* 9.7.1 */
 
1486
GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attributes>
 
1487
        (. Statement stmt = null; .) =
 
1488
        "Get"
 
1489
        (. Point startLocation = t.Location; .)
 
1490
        EOL
 
1491
        Block<out stmt>
 
1492
        (. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .)
 
1493
        "End" "Get"
 
1494
        (. getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; .)
 
1495
        EOL
 
1496
        .
 
1497
 
 
1498
/* 9.7.2 */
 
1499
SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attributes>
 
1500
        (.
 
1501
                Statement stmt = null; List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
 
1502
        .) =
 
1503
        "Set"
 
1504
        (. Point startLocation = t.Location; .)
 
1505
        [ "("   [ FormalParameterList<p> ] ")" ]
 
1506
        EOL
 
1507
        Block<out stmt>
 
1508
        (.
 
1509
                setBlock = new PropertySetRegion((BlockStatement)stmt, attributes);
 
1510
                setBlock.Parameters = p;
 
1511
        .)
 
1512
        "End" "Set"
 
1513
        (. setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; .)
 
1514
        EOL
 
1515
        .
 
1516
 
 
1517
/* 9.5 */
 
1518
ConstantDeclarator<List<VariableDeclaration> constantDeclaration>
 
1519
        (.
 
1520
                Expression expr = null;
 
1521
                TypeReference type = null;
 
1522
                string name = String.Empty;
 
1523
        .) =
 
1524
        Identifier                              (. name = t.val; .)
 
1525
        ["As" TypeName<out type> ]
 
1526
        "=" Expr<out expr>
 
1527
        (.
 
1528
                VariableDeclaration f = new VariableDeclaration(name, expr);
 
1529
                f.TypeReference = type;
 
1530
                constantDeclaration.Add(f);
 
1531
        .)
 
1532
.
 
1533
 
 
1534
/* 9.6 */
 
1535
VariableDeclarator<List<VariableDeclaration> fieldDeclaration>
 
1536
        (.
 
1537
                Expression expr = null;
 
1538
                TypeReference type = null;
 
1539
                ArrayList rank = null;
 
1540
                List<Expression> dimension = null;
 
1541
        .) =
 
1542
        Identifier (. string name = t.val; .)
 
1543
        [ IF(IsSize() && !IsDims()) ArrayInitializationModifier<out dimension> ]
 
1544
        [ IF(IsDims())              ArrayNameModifier<out rank> ]
 
1545
        (
 
1546
                IF (IsObjectCreation()) "As" ObjectCreateExpression<out expr>
 
1547
                (.
 
1548
                        if (expr is ObjectCreateExpression) {
 
1549
                                type = ((ObjectCreateExpression)expr).CreateType;
 
1550
                        } else {
 
1551
                                type = ((ArrayCreateExpression)expr).CreateType;
 
1552
                        }
 
1553
                .)
 
1554
        |
 
1555
                [ "As" TypeName<out type> ]
 
1556
                (.
 
1557
                        if (type != null && dimension != null) {
 
1558
                                if(type.RankSpecifier != null) {
 
1559
                                        Error("array rank only allowed one time");
 
1560
                                } else {
 
1561
                                        for (int i = 0; i < dimension.Count; i++)
 
1562
                                                dimension[i] = Expression.AddInteger(dimension[i], 1);
 
1563
                                        if (rank == null) {
 
1564
                                                type.RankSpecifier = new int[] { dimension.Count - 1 };
 
1565
                                        } else {
 
1566
                                                rank.Insert(0, dimension.Count - 1);
 
1567
                                                type.RankSpecifier = (int[])rank.ToArray(typeof(int));
 
1568
                                        }
 
1569
                                        expr = new ArrayCreateExpression(type, dimension);
 
1570
                                }
 
1571
                        } else if (type != null && rank != null) {
 
1572
                                if(type.RankSpecifier != null) {
 
1573
                                        Error("array rank only allowed one time");
 
1574
                                } else {
 
1575
                                        type.RankSpecifier = (int[])rank.ToArray(typeof(int));
 
1576
                                }
 
1577
                        }
 
1578
                .)
 
1579
                [ "=" VariableInitializer<out expr> ]
 
1580
        )
 
1581
        (. fieldDeclaration.Add(new VariableDeclaration(name, expr, type)); .)
 
1582
.
 
1583
 
 
1584
/* 6.8 */
 
1585
ArrayInitializationModifier<out List<Expression> arrayModifiers>
 
1586
(.
 
1587
        arrayModifiers = null;
 
1588
.) =
 
1589
        "(" InitializationRankList<out arrayModifiers> ")"
 
1590
.
 
1591
 
 
1592
/* 7.5.4.3 */
 
1593
InitializationRankList<out List<Expression> rank>
 
1594
(.
 
1595
        rank = new List<Expression>();
 
1596
        Expression expr = null;
 
1597
.) =
 
1598
        Expr<out expr>
 
1599
        [       "To"
 
1600
                (.      if (!(expr is PrimitiveExpression) || (expr as PrimitiveExpression).StringValue != "0")
 
1601
                        Error("lower bound of array must be zero");
 
1602
                .)
 
1603
                Expr<out expr>
 
1604
        ]
 
1605
        (. if (expr != null) { rank.Add(expr); } .)
 
1606
        {       ","
 
1607
                Expr<out expr>
 
1608
                [       "To"
 
1609
                        (.      if (!(expr is PrimitiveExpression) || (expr as PrimitiveExpression).StringValue != "0")
 
1610
                                Error("lower bound of array must be zero");
 
1611
                        .)
 
1612
                        Expr<out expr>
 
1613
                ]
 
1614
                (. if (expr != null) { rank.Add(expr); } .)
 
1615
        }
 
1616
.
 
1617
 
 
1618
/* 9.6.3 */
 
1619
VariableInitializer<out Expression initializerExpression>
 
1620
        (.
 
1621
                initializerExpression = null;
 
1622
        .) =
 
1623
        Expr<out initializerExpression>
 
1624
        | ArrayInitializer<out initializerExpression>
 
1625
        .
 
1626
 
 
1627
/* 9.6.3.4 */
 
1628
ArrayInitializer<out Expression outExpr>
 
1629
        (.
 
1630
                Expression expr = null;
 
1631
                ArrayInitializerExpression initializer = new ArrayInitializerExpression();
 
1632
        .) =
 
1633
        "{"
 
1634
        [
 
1635
                VariableInitializer<out expr>
 
1636
                (.
 
1637
                        if (expr != null) { initializer.CreateExpressions.Add(expr); }
 
1638
                .)
 
1639
                {
 
1640
                        IF (NotFinalComma()) "," VariableInitializer<out expr>
 
1641
                        (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .)
 
1642
                }
 
1643
        ]
 
1644
        "}" (. outExpr = initializer; .)
 
1645
        .
 
1646
 
 
1647
Charset<out CharsetModifier charsetModifier>
 
1648
        (. charsetModifier = CharsetModifier.None; .) =
 
1649
        | "Ansi"                (. charsetModifier = CharsetModifier.ANSI; .)
 
1650
        | "Auto"                (. charsetModifier = CharsetModifier.Auto; .)
 
1651
        | "Unicode"             (. charsetModifier = CharsetModifier.Unicode; .)
 
1652
        .
 
1653
 
 
1654
/* 9.2.6 */
 
1655
HandlesClause<out List<string> handlesClause>
 
1656
        (.
 
1657
                handlesClause = new List<string>();
 
1658
                string name;
 
1659
        .) =
 
1660
        "Handles" EventMemberSpecifier<out name>        (. handlesClause.Add(name); .)
 
1661
        { "," EventMemberSpecifier<out name>            (. handlesClause.Add(name); .) }
 
1662
        .
 
1663
 
 
1664
/* 7.8. */
 
1665
InterfaceBase <out List<TypeReference> bases>
 
1666
        (.
 
1667
                TypeReference type;
 
1668
                bases = new List<TypeReference>();
 
1669
        .) =
 
1670
        "Inherits"
 
1671
        TypeName<out type> (. bases.Add(type); .)
 
1672
        {
 
1673
                ","
 
1674
                TypeName<out type> (. bases.Add(type); .)
 
1675
        }
 
1676
        EOL
 
1677
        .
 
1678
 
 
1679
/* 7.2 */
 
1680
TypeImplementsClause<out List<TypeReference> baseInterfaces>
 
1681
        (.
 
1682
                baseInterfaces = new List<TypeReference>();
 
1683
                TypeReference type = null;
 
1684
        .) =
 
1685
        "Implements" TypeName<out type>
 
1686
        (.
 
1687
                baseInterfaces.Add(type);
 
1688
        .)
 
1689
        {
 
1690
                "," TypeName<out type>
 
1691
                (. baseInterfaces.Add(type); .)
 
1692
        }
 
1693
        EndOfStmt
 
1694
        .
 
1695
 
 
1696
/* 9.1 */
 
1697
ImplementsClause<out List<InterfaceImplementation> baseInterfaces>
 
1698
        (.
 
1699
                baseInterfaces = new List<InterfaceImplementation>();
 
1700
                TypeReference type = null;
 
1701
                string memberName = null;
 
1702
        .) =
 
1703
        "Implements"
 
1704
        NonArrayTypeName<out type, false>
 
1705
        (. if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); .)
 
1706
        (. baseInterfaces.Add(new InterfaceImplementation(type, memberName)); .)
 
1707
        { ","
 
1708
                NonArrayTypeName<out type, false>
 
1709
                (. if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); .)
 
1710
                (. baseInterfaces.Add(new InterfaceImplementation(type, memberName)); .)
 
1711
        }
 
1712
.
 
1713
 
 
1714
EventMemberSpecifier<out string name>
 
1715
        (. string type; name = String.Empty; .) =
 
1716
        Identifier (. type = t.val; .)
 
1717
        "."
 
1718
        Identifier (. name = type + "." + t.val; .)
 
1719
        | "MyBase" "."
 
1720
        (
 
1721
                Identifier (. name = "MyBase." + t.val; .)
 
1722
                | "Error"  (. name = "MyBase.Error"; .)
 
1723
        )
 
1724
        .
 
1725
 
 
1726
Expr<out Expression expr>
 
1727
=
 
1728
        DisjunctionExpr<out expr>
 
1729
.
 
1730
 
 
1731
AssignmentOperator<out AssignmentOperatorType op>
 
1732
        (. op = AssignmentOperatorType.None; .) =
 
1733
        "="             (. op = AssignmentOperatorType.Assign; .)
 
1734
        | "&="  (. op = AssignmentOperatorType.ConcatString; .)
 
1735
        | "+="  (. op = AssignmentOperatorType.Add; .)
 
1736
        | "-="  (. op = AssignmentOperatorType.Subtract; .)
 
1737
        | "*="  (. op = AssignmentOperatorType.Multiply; .)
 
1738
        | "/="  (. op = AssignmentOperatorType.Divide; .)
 
1739
        | "\\=" (. op = AssignmentOperatorType.DivideInteger; .)
 
1740
        | "^="  (. op = AssignmentOperatorType.Power; .)
 
1741
        | "<<=" (. op = AssignmentOperatorType.ShiftLeft; .)
 
1742
        | ">>=" (. op = AssignmentOperatorType.ShiftRight; .)
 
1743
        .
 
1744
 
 
1745
/* 11.4 */
 
1746
SimpleExpr<out Expression pexpr>
 
1747
(.
 
1748
        Expression expr;
 
1749
        TypeReference type = null;
 
1750
        string name = String.Empty;
 
1751
        pexpr = null;
 
1752
.) =
 
1753
        (
 
1754
                (
 
1755
                        /* 11.4.1 */ 
 
1756
                        LiteralString                                                   (.pexpr = new PrimitiveExpression(t.literalValue, t.val);  .)
 
1757
                |       LiteralCharacter                                                (.pexpr = new PrimitiveExpression(t.literalValue, t.val);  .)
 
1758
                |       LiteralSingle                                                   (.pexpr = new PrimitiveExpression(t.literalValue, t.val);  .)
 
1759
                |       LiteralDouble                                                   (.pexpr = new PrimitiveExpression(t.literalValue, t.val);  .)
 
1760
                |       LiteralInteger                                          (.pexpr = new PrimitiveExpression(t.literalValue, t.val);  .)
 
1761
                |       LiteralDate                                                     (.pexpr = new PrimitiveExpression(t.literalValue, t.val);  .)
 
1762
                |       LiteralDecimal                                          (.pexpr = new PrimitiveExpression(t.literalValue, t.val);  .)
 
1763
                        /* True, False and Nothing are handled as literals in the spec */
 
1764
                |       "True"                                                                                  (.pexpr = new PrimitiveExpression(true, "true");  .)
 
1765
                |       "False"                                                                                 (.pexpr = new PrimitiveExpression(false, "false"); .)
 
1766
                |       "Nothing"                                                                                       (.pexpr = new PrimitiveExpression(null, "null");  .)
 
1767
                |       /* 11.4.2 */ "(" Expr<out expr> ")"                             (. pexpr = new ParenthesizedExpression(expr); .)
 
1768
                |       /* 11.4.4 */ Identifier                                 (. pexpr = new IdentifierExpression(t.val); .)
 
1769
                |       (. string val = String.Empty; .)
 
1770
                        PrimitiveTypeName<out val>
 
1771
                        "." (. t.val = ""; .) Identifier (. pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); .)
 
1772
                |       "Me"                                                    (. pexpr = new ThisReferenceExpression(); .)
 
1773
                |       (. Expression retExpr = null; .)
 
1774
                        ( "MyBase"                                                                              (. retExpr = new BaseReferenceExpression(); .)
 
1775
                        | "MyClass"                                                                             (. retExpr = new ClassReferenceExpression(); .)
 
1776
                        )
 
1777
                        "." IdentifierOrKeyword<out name>                               (. pexpr = new FieldReferenceExpression(retExpr, name); .)
 
1778
                |       "Global" "."
 
1779
                        Identifier (. type = new TypeReference(t.val ?? ""); .)
 
1780
                        /* fallback to "" is required if the token wasn't an identifier (->parser error but no exception) */
 
1781
                        (. type.IsGlobal = true; .)
 
1782
                        (. pexpr = new TypeReferenceExpression(type); .)
 
1783
                |       ObjectCreateExpression<out expr>                                        (. pexpr = expr; .)
 
1784
                |       /* 11.11 : Casts */
 
1785
                        (. CastType castType = CastType.Cast; .)
 
1786
                        ( "DirectCast"
 
1787
                        | "CType"   (. castType = CastType.Conversion; .)
 
1788
                        | "TryCast" (. castType = CastType.TryCast; .)
 
1789
                        )
 
1790
                        "(" Expr<out expr> "," TypeName<out type> ")"
 
1791
                        (. pexpr = new CastExpression(type, expr, castType); .)
 
1792
                |       /* 11.11 */ CastTarget<out type> "(" Expr<out expr> ")" (. pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion); .)
 
1793
                |       /* 11.4.5 */ "AddressOf" Expr<out expr>                 (. pexpr = new AddressOfExpression(expr); .)
 
1794
                |       /* 11.5.1 */ "GetType" "(" GetTypeTypeName<out type> ")"        (. pexpr = new TypeOfExpression(type); .)
 
1795
                |       /* 11.5.2 */ "TypeOf" SimpleExpr<out expr> "Is" TypeName<out type> (. pexpr = new TypeOfIsExpression(expr, type); .)
 
1796
                )
 
1797
                { InvocationOrMemberReferenceExpression<ref pexpr> }
 
1798
        |
 
1799
                /* this form only occurs in WithStatements*/
 
1800
                "." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(pexpr, name);.)
 
1801
                { InvocationOrMemberReferenceExpression<ref pexpr> }
 
1802
        )
 
1803
.
 
1804
 
 
1805
InvocationOrMemberReferenceExpression<ref Expression pexpr>
 
1806
(. string name; .)
 
1807
=
 
1808
        "." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(pexpr, name); .)
 
1809
|       InvocationExpression<ref pexpr>
 
1810
.
 
1811
 
 
1812
InvocationExpression<ref Expression pexpr>
 
1813
(. List<TypeReference> typeParameters = new List<TypeReference>();
 
1814
   List<Expression> parameters = null;
 
1815
   TypeReference type; .)
 
1816
=
 
1817
        "(" (. Point start = t.Location; .)
 
1818
        (       "Of"
 
1819
                TypeName<out type> (. if (type != null) typeParameters.Add(type); .)
 
1820
                ")"
 
1821
                (
 
1822
                        "." Identifier
 
1823
                        (. pexpr = new FieldReferenceExpression(GetTypeReferenceExpression(pexpr, typeParameters), t.val); .)
 
1824
                |       "("
 
1825
                        ArgumentList<out parameters>
 
1826
                        ")"
 
1827
                        (. pexpr = new InvocationExpression(pexpr, parameters, typeParameters); .)
 
1828
                )
 
1829
        |       ArgumentList<out parameters>
 
1830
                ")"
 
1831
                (. pexpr = new InvocationExpression(pexpr, parameters, typeParameters); .)
 
1832
        )
 
1833
        (. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .)
 
1834
.
 
1835
 
 
1836
/* 11.11 */
 
1837
 
 
1838
CastTarget<out TypeReference type>
 
1839
        (.
 
1840
                type = null;
 
1841
        .) =
 
1842
        "CBool"         (. type = new TypeReference("System.Boolean"); .)
 
1843
        | "CByte"       (. type = new TypeReference("System.Byte"); .)
 
1844
        | "CSByte"      (. type = new TypeReference("System.SByte"); .)
 
1845
        | "CChar"       (. type = new TypeReference("System.Char"); .)
 
1846
        | "CDate"       (. type = new TypeReference("System.DateTime"); .)
 
1847
        | "CDec"        (. type = new TypeReference("System.Decimal"); .)
 
1848
        | "CDbl"        (. type = new TypeReference("System.Double"); .)
 
1849
        | "CShort"      (. type = new TypeReference("System.Int16"); .)
 
1850
        | "CInt"        (. type = new TypeReference("System.Int32"); .)
 
1851
        | "CLng"        (. type = new TypeReference("System.Int64"); .)
 
1852
        | "CUShort"     (. type = new TypeReference("System.UInt16"); .)
 
1853
        | "CUInt"       (. type = new TypeReference("System.UInt32"); .)
 
1854
        | "CULng"       (. type = new TypeReference("System.UInt64"); .)
 
1855
        | "CObj"        (. type = new TypeReference("System.Object"); .)
 
1856
        | "CSng"        (. type = new TypeReference("System.Single"); .)
 
1857
        | "CStr"        (. type = new TypeReference("System.String"); .)
 
1858
        .
 
1859
 
 
1860
DisjunctionExpr<out Expression outExpr>
 
1861
(.
 
1862
        Expression expr;
 
1863
        BinaryOperatorType op = BinaryOperatorType.None;
 
1864
.) =
 
1865
        ConjunctionExpr<out outExpr>
 
1866
        {
 
1867
                (
 
1868
                          "Or"     (. op = BinaryOperatorType.BitwiseOr; .)
 
1869
                        | "OrElse" (. op = BinaryOperatorType.LogicalOr; .)
 
1870
                        | "Xor"    (. op = BinaryOperatorType.ExclusiveOr; .)
 
1871
                )
 
1872
                ConjunctionExpr<out expr> (.  outExpr = new BinaryOperatorExpression(outExpr, op, expr);  .)
 
1873
        }
 
1874
.
 
1875
 
 
1876
ConjunctionExpr<out Expression outExpr>
 
1877
(.
 
1878
        Expression expr;
 
1879
        BinaryOperatorType op = BinaryOperatorType.None;
 
1880
.) =
 
1881
        NotExpr<out outExpr>
 
1882
        {
 
1883
                (
 
1884
                          "And"     (. op = BinaryOperatorType.BitwiseAnd; .)
 
1885
                        | "AndAlso" (. op = BinaryOperatorType.LogicalAnd; .)
 
1886
                )
 
1887
                NotExpr<out expr> (.  outExpr = new BinaryOperatorExpression(outExpr, op, expr);  .)
 
1888
        }
 
1889
.
 
1890
 
 
1891
NotExpr<out Expression outExpr> 
 
1892
        (. UnaryOperatorType uop = UnaryOperatorType.None; .) =
 
1893
        {       "Not" (. uop = UnaryOperatorType.Not; .) }
 
1894
        ComparisonExpr<out outExpr>
 
1895
                (. if (uop != UnaryOperatorType.None)
 
1896
                           outExpr = new UnaryOperatorExpression(outExpr, uop);
 
1897
                .)
 
1898
        .
 
1899
 
 
1900
ComparisonExpr<out Expression outExpr>
 
1901
(.
 
1902
        Expression expr;
 
1903
        BinaryOperatorType op = BinaryOperatorType.None;
 
1904
.) =
 
1905
        ShiftExpr<out outExpr>
 
1906
        {
 
1907
                (
 
1908
                        "<"    (. op = BinaryOperatorType.LessThan; .)
 
1909
                        | ">"  (. op = BinaryOperatorType.GreaterThan; .)
 
1910
                        | "<=" (. op = BinaryOperatorType.LessThanOrEqual; .)
 
1911
                        | ">=" (. op = BinaryOperatorType.GreaterThanOrEqual; .)
 
1912
                        | "<>"          (. op = BinaryOperatorType.InEquality; .)
 
1913
                        | "="           (. op = BinaryOperatorType.Equality; .)
 
1914
                        | "Like"        (. op = BinaryOperatorType.Like; .)
 
1915
                        | "Is"  (. op = BinaryOperatorType.ReferenceEquality; .)
 
1916
                        | "IsNot" (. op = BinaryOperatorType.ReferenceInequality; .)
 
1917
                )
 
1918
                ShiftExpr<out expr> (.  outExpr = new BinaryOperatorExpression(outExpr, op, expr);  .)
 
1919
        }
 
1920
.
 
1921
 
 
1922
ShiftExpr<out Expression outExpr>
 
1923
        (.
 
1924
                Expression expr;
 
1925
                BinaryOperatorType op = BinaryOperatorType.None;
 
1926
        .) =
 
1927
        ConcatenationExpr<out outExpr> 
 
1928
        {
 
1929
                (
 
1930
                        "<<"   (. op = BinaryOperatorType.ShiftLeft; .)
 
1931
                        | ">>" (. op = BinaryOperatorType.ShiftRight; .)
 
1932
                )
 
1933
                ConcatenationExpr<out expr> (.  outExpr = new BinaryOperatorExpression(outExpr, op, expr);  .) 
 
1934
        }
 
1935
        .
 
1936
 
 
1937
ConcatenationExpr<out Expression outExpr>
 
1938
(. Expression expr; .)
 
1939
=
 
1940
        AdditiveExpr<out outExpr> { "&" AdditiveExpr<out expr> (.  outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Concat, expr);  .) }
 
1941
.
 
1942
 
 
1943
AdditiveExpr<out Expression outExpr>
 
1944
(.
 
1945
        Expression expr;
 
1946
        BinaryOperatorType op = BinaryOperatorType.None;
 
1947
.) =
 
1948
        ModuloExpr<out outExpr>
 
1949
        {
 
1950
                (
 
1951
                          "+"   (. op = BinaryOperatorType.Add; .)
 
1952
                        | "-" (. op = BinaryOperatorType.Subtract; .)
 
1953
                )
 
1954
                ModuloExpr<out expr> (.  outExpr = new BinaryOperatorExpression(outExpr, op, expr);  .)
 
1955
        }
 
1956
.
 
1957
 
 
1958
ModuloExpr<out Expression outExpr>
 
1959
(. Expression expr; .)
 
1960
=
 
1961
        IntegerDivisionExpr<out outExpr> { "Mod" IntegerDivisionExpr<out expr> (.  outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Modulus, expr);  .) }
 
1962
.
 
1963
 
 
1964
IntegerDivisionExpr<out Expression outExpr>
 
1965
(. Expression expr; .)
 
1966
=
 
1967
        MultiplicativeExpr<out outExpr> { "\\" MultiplicativeExpr<out expr> (.  outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.DivideInteger, expr);  .) }
 
1968
.
 
1969
 
 
1970
MultiplicativeExpr<out Expression outExpr>
 
1971
(.
 
1972
        Expression expr;
 
1973
        BinaryOperatorType op = BinaryOperatorType.None;
 
1974
.) =
 
1975
        UnaryExpr<out outExpr>
 
1976
        {
 
1977
                (
 
1978
                        "*"   (. op = BinaryOperatorType.Multiply; .)
 
1979
                        | "/" (. op = BinaryOperatorType.Divide; .)
 
1980
                ) 
 
1981
                UnaryExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .) 
 
1982
        }
 
1983
.
 
1984
 
 
1985
UnaryExpr<out Expression uExpr> 
 
1986
(.
 
1987
        Expression expr;
 
1988
        UnaryOperatorType uop = UnaryOperatorType.None;
 
1989
        bool isUOp = false;
 
1990
.) =
 
1991
        {       "+"             (. uop = UnaryOperatorType.Plus; isUOp = true; .)
 
1992
                | "-"           (. uop = UnaryOperatorType.Minus; isUOp = true; .)
 
1993
                | "*"           (. uop = UnaryOperatorType.Star;  isUOp = true;.)
 
1994
        }
 
1995
        ExponentiationExpr<out expr>
 
1996
        (.
 
1997
                if (isUOp) {
 
1998
                        uExpr = new UnaryOperatorExpression(expr, uop);
 
1999
                } else {
 
2000
                        uExpr = expr;
 
2001
                }
 
2002
        .)
 
2003
.
 
2004
 
 
2005
ExponentiationExpr<out Expression outExpr>
 
2006
(. Expression expr; .)
 
2007
=
 
2008
        SimpleExpr<out outExpr> { "^" SimpleExpr<out expr> (.  outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Power, expr);  .) }
 
2009
.
 
2010
        
 
2011
ObjectCreateExpression<out Expression oce>
 
2012
(.
 
2013
        TypeReference type = null;
 
2014
        Expression initializer = null;
 
2015
        List<Expression> arguments = null;
 
2016
        ArrayList dimensions = null;
 
2017
        oce = null;
 
2018
.) =
 
2019
        "New" NonArrayTypeName<out type, false>
 
2020
        ["(" [ ArgumentList<out arguments> ] ")" ]
 
2021
        [ IF (la.kind == Tokens.OpenParenthesis)
 
2022
          ArrayTypeModifiers<out dimensions>
 
2023
          ArrayInitializer<out initializer>
 
2024
        | ArrayInitializer<out initializer> ]
 
2025
        (.
 
2026
                if (initializer == null) {
 
2027
                        oce = new ObjectCreateExpression(type, arguments);
 
2028
                } else {
 
2029
                        if (dimensions == null) dimensions = new ArrayList();
 
2030
                        dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0));
 
2031
                        type.RankSpecifier = (int[])dimensions.ToArray(typeof(int));
 
2032
                        ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as ArrayInitializerExpression);
 
2033
                        ace.Arguments = arguments;
 
2034
                        oce = ace;
 
2035
                }
 
2036
        .)
 
2037
.
 
2038
 
 
2039
/* 9.3.2 */
 
2040
ArgumentList<out List<Expression> arguments>
 
2041
        (.
 
2042
                arguments = new List<Expression>();
 
2043
                Expression expr = null;
 
2044
        .) =
 
2045
        [
 
2046
                Argument<out expr>                      (. if (expr != null) { arguments.Add(expr); } .)
 
2047
                {
 
2048
                        ","
 
2049
                        Argument<out expr>              (. if (expr != null) { arguments.Add(expr); } .)
 
2050
                }
 
2051
        ]
 
2052
        .
 
2053
 
 
2054
/* Spec, 11.8 */
 
2055
Argument<out Expression argumentexpr>
 
2056
        (.
 
2057
                Expression expr;
 
2058
                argumentexpr = null;
 
2059
                string name;
 
2060
        .) =
 
2061
        IF(IsNamedAssign()) Identifier (. name = t.val;  .) ":" "=" Expr<out expr>
 
2062
        (.
 
2063
                argumentexpr = new NamedArgumentExpression(name, expr);
 
2064
        .)
 
2065
        |
 
2066
        Expr<out argumentexpr>
 
2067
        .
 
2068
 
 
2069
/* 7.1. */
 
2070
TypeName<out TypeReference typeref>
 
2071
(. ArrayList rank = null; .)
 
2072
=
 
2073
        NonArrayTypeName<out typeref, false>
 
2074
        ArrayTypeModifiers<out rank>
 
2075
        (.      if (rank != null && typeref != null) {
 
2076
                        typeref.RankSpecifier = (int[])rank.ToArray(typeof(int));
 
2077
                }
 
2078
        .)
 
2079
.
 
2080
 
 
2081
GetTypeTypeName<out TypeReference typeref>
 
2082
(. ArrayList rank = null; .)
 
2083
=
 
2084
        NonArrayTypeName<out typeref, true>
 
2085
        ArrayTypeModifiers<out rank>
 
2086
        (.      if (rank != null && typeref != null) {
 
2087
                        typeref.RankSpecifier = (int[])rank.ToArray(typeof(int));
 
2088
                }
 
2089
        .)
 
2090
.
 
2091
 
 
2092
/* 7.1 */
 
2093
NonArrayTypeName<out TypeReference typeref, bool canBeUnbound>
 
2094
(.
 
2095
        string name;
 
2096
        typeref = null;
 
2097
        bool isGlobal = false;
 
2098
.) =
 
2099
        (
 
2100
                [ "Global" "." (. isGlobal = true; .) ]
 
2101
                QualIdentAndTypeArguments<out typeref, canBeUnbound>
 
2102
                (. typeref.IsGlobal = isGlobal; .)
 
2103
                { "." (. TypeReference nestedTypeRef; .)
 
2104
                        QualIdentAndTypeArguments<out nestedTypeRef, canBeUnbound>
 
2105
                        (. typeref = new InnerClassTypeReference(typeref, nestedTypeRef.Type, nestedTypeRef.GenericTypes); .)
 
2106
                }
 
2107
        )
 
2108
        | "Object" (. typeref = new TypeReference("System.Object"); .)
 
2109
        | PrimitiveTypeName<out name> (. typeref = new TypeReference(name); .)
 
2110
.
 
2111
 
 
2112
QualIdentAndTypeArguments<out TypeReference typeref, bool canBeUnbound>
 
2113
(. string name; typeref = null; .)
 
2114
=
 
2115
        Qualident<out name>
 
2116
        (. typeref = new TypeReference(name); .)
 
2117
        [IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
 
2118
                "(" "Of"
 
2119
                ( IF (canBeUnbound && (la.kind == Tokens.CloseParenthesis || la.kind == Tokens.Comma))
 
2120
                        (. typeref.GenericTypes.Add(NullTypeReference.Instance); .)
 
2121
                        { "," (. typeref.GenericTypes.Add(NullTypeReference.Instance); .) }
 
2122
                  | TypeArgumentList<typeref.GenericTypes>
 
2123
                )
 
2124
                ")"
 
2125
        ]
 
2126
.
 
2127
 
 
2128
/* 7.9 */
 
2129
ArrayNameModifier<out ArrayList arrayModifiers>
 
2130
(.
 
2131
        arrayModifiers = null;
 
2132
.) =
 
2133
        ArrayTypeModifiers<out arrayModifiers>
 
2134
.
 
2135
 
 
2136
 
 
2137
/* 7.9 */
 
2138
ArrayTypeModifiers<out ArrayList arrayModifiers>
 
2139
(.
 
2140
        arrayModifiers = new ArrayList();
 
2141
        int i = 0;
 
2142
.) =
 
2143
        {       IF (IsDims())
 
2144
                "("
 
2145
                [ RankList<out i>]
 
2146
                (.
 
2147
                        arrayModifiers.Add(i);
 
2148
                .)
 
2149
                ")"
 
2150
        }
 
2151
        (.
 
2152
                if(arrayModifiers.Count == 0) {
 
2153
                         arrayModifiers = null;
 
2154
                }
 
2155
        .)
 
2156
.
 
2157
 
 
2158
/* 7.9 */
 
2159
RankList<out int i>
 
2160
(. i = 0; .) =
 
2161
        { "," (. ++i; .) }
 
2162
.
 
2163
 
 
2164
/* 7.12 */
 
2165
TypeArgumentList<List<TypeReference> typeArguments>
 
2166
(.
 
2167
        TypeReference typeref;
 
2168
.) =
 
2169
        TypeName<out typeref> (. if (typeref != null) typeArguments.Add(typeref); .)
 
2170
        {
 
2171
                ","
 
2172
                TypeName<out typeref> (. if (typeref != null) typeArguments.Add(typeref); .)
 
2173
        }
 
2174
.
 
2175
 
 
2176
GlobalAttributeSection =
 
2177
        (. Point startPos = t.Location; .)
 
2178
        "<" ("Assembly" | "Module")
 
2179
                (.  string attributeTarget = t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture);
 
2180
                        List<ASTAttribute> attributes = new List<ASTAttribute>();
 
2181
                        ASTAttribute attribute;
 
2182
                .)
 
2183
        ":" Attribute<out attribute> (. attributes.Add(attribute); .)
 
2184
        { IF (NotFinalComma()) ["," ("Assembly" | "Module") ":"] Attribute<out attribute> (. attributes.Add(attribute); .)}
 
2185
        [ "," ]
 
2186
        ">"
 
2187
        EndOfStmt
 
2188
                (.
 
2189
                        AttributeSection section = new AttributeSection(attributeTarget, attributes);
 
2190
                        section.StartLocation = startPos;
 
2191
                        section.EndLocation = t.EndLocation;
 
2192
                        compilationUnit.AddChild(section);
 
2193
                .)
 
2194
        .
 
2195
 
 
2196
/* Spec, 5. */
 
2197
Attribute<out ICSharpCode.NRefactory.Parser.AST.Attribute attribute>
 
2198
(. string name;
 
2199
   List<Expression> positional = new List<Expression>();
 
2200
   List<NamedArgumentExpression> named = new List<NamedArgumentExpression>();
 
2201
.) =
 
2202
        [ "Global" "." ]
 
2203
        Qualident<out name>
 
2204
        [ AttributeArguments<positional, named> ]
 
2205
        (. attribute  = new ICSharpCode.NRefactory.Parser.AST.Attribute(name, positional, named); .)
 
2206
.
 
2207
 
 
2208
/* Spec, 5.2.2 */
 
2209
AttributeArguments<List<Expression> positional, List<NamedArgumentExpression> named>
 
2210
        (.
 
2211
                bool nameFound = false;
 
2212
                string name = "";
 
2213
                Expression expr;
 
2214
        .) =
 
2215
        "("
 
2216
        [
 
2217
                IF (IsNotClosingParenthesis()) ( 
 
2218
                        [
 
2219
                                IF (IsNamedAssign()) (. nameFound = true; .)
 
2220
                                IdentifierOrKeyword<out name>
 
2221
                                [":"] "="
 
2222
                        ] Expr<out expr>
 
2223
                                (.
 
2224
                                        if (expr != null) { if(name == "") positional.Add(expr);
 
2225
                                        else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
 
2226
                                        }
 
2227
                                .)
 
2228
                        {
 
2229
                                ","
 
2230
                                        (
 
2231
                                                IF (IsNamedAssign())    (. nameFound = true; .)
 
2232
                                                IdentifierOrKeyword<out name>
 
2233
                                                [ ":" ] "="
 
2234
                                                | (. if (nameFound) Error("no positional argument after named argument"); .)
 
2235
                                        ) Expr<out expr>        (.      if (expr != null) { if(name == "") positional.Add(expr);
 
2236
                                                                                        else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
 
2237
                                                                                        }
 
2238
                                                                                .)
 
2239
                        }
 
2240
                )
 
2241
        ]
 
2242
        ")"
 
2243
        .
 
2244
 
 
2245
/* Spec, 5. */
 
2246
AttributeSection<out AttributeSection section>
 
2247
        (.
 
2248
                string attributeTarget = "";List<ASTAttribute> attributes = new List<ASTAttribute>();
 
2249
                ASTAttribute attribute;
 
2250
                
 
2251
        .) =
 
2252
        "<" (. Point startPos = t.Location; .)
 
2253
        [ IF (IsLocalAttrTarget())
 
2254
                ( "Event"               (. attributeTarget = "event";.)
 
2255
                | "Return"              (. attributeTarget = "return";.)
 
2256
                | Identifier
 
2257
                        (.
 
2258
                                string val = t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture);
 
2259
                                if (val != "field"      || val != "method" ||
 
2260
                                        val != "module" || val != "param"  ||
 
2261
                                        val != "property" || val != "type")
 
2262
                                Error("attribute target specifier (event, return, field," +
 
2263
                                                "method, module, param, property, or type) expected");
 
2264
                                attributeTarget = t.val;
 
2265
                        .)
 
2266
                ) ":" 
 
2267
        ]
 
2268
        Attribute<out attribute>        (. attributes.Add(attribute); .)
 
2269
        { IF (NotFinalComma()) "," Attribute<out attribute> (. attributes.Add(attribute); .) }
 
2270
        [ "," ]
 
2271
        ">"
 
2272
                (.
 
2273
                        section = new AttributeSection(attributeTarget, attributes);
 
2274
                        section.StartLocation = startPos;
 
2275
                        section.EndLocation = t.EndLocation;
 
2276
                .)
 
2277
        .
 
2278
 
 
2279
/* 9.2.5 */
 
2280
FormalParameterList<List<ParameterDeclarationExpression> parameter>
 
2281
        (.
 
2282
                ParameterDeclarationExpression p;
 
2283
                AttributeSection section;
 
2284
                List<AttributeSection> attributes = new List<AttributeSection>();
 
2285
        .) =
 
2286
        { AttributeSection<out section> (.attributes.Add(section); .) }
 
2287
        (
 
2288
                FormalParameter<out p>
 
2289
                (.
 
2290
                        bool paramsFound = false;
 
2291
                        p.Attributes = attributes;
 
2292
                        parameter.Add(p);
 
2293
                .)
 
2294
                {
 
2295
                        ","     (. if (paramsFound) Error("params array must be at end of parameter list"); .)
 
2296
                        { AttributeSection<out section> (.attributes.Add(section); .) }
 
2297
                        (
 
2298
                                FormalParameter <out p> (. p.Attributes = attributes; parameter.Add(p); .)
 
2299
                        )
 
2300
                }
 
2301
        )
 
2302
        .
 
2303
/* 9.2.5 */
 
2304
FormalParameter<out ParameterDeclarationExpression p>
 
2305
        (.
 
2306
                TypeReference type = null;
 
2307
                ParamModifiers mod = new ParamModifiers(this);
 
2308
                Expression expr = null;
 
2309
                p = null;ArrayList arrayModifiers = null;
 
2310
        .) =
 
2311
        { ParameterModifier<mod> }
 
2312
        Identifier (. string parameterName = t.val; .)
 
2313
        [ IF(IsDims()) ArrayTypeModifiers<out arrayModifiers> ]
 
2314
        [ "As" TypeName<out type> ]
 
2315
        (.
 
2316
                if(type != null) {
 
2317
                        if (arrayModifiers != null) {
 
2318
                                if (type.RankSpecifier != null) {
 
2319
                                        Error("array rank only allowed one time");
 
2320
                                } else {
 
2321
                                        type.RankSpecifier = (int[])arrayModifiers.ToArray(typeof(int));
 
2322
                                }
 
2323
                        }
 
2324
                } else {
 
2325
                        type = new TypeReference("System.Object", arrayModifiers == null ? null : (int[])arrayModifiers.ToArray(typeof(int)));
 
2326
                }
 
2327
        .)
 
2328
        [ "=" Expr<out expr> ]
 
2329
        (.
 
2330
                mod.Check();
 
2331
                p = new ParameterDeclarationExpression(type, parameterName, mod.Modifier, expr);
 
2332
        .)
 
2333
        .
 
2334
 
 
2335
/* 10.1 */
 
2336
Block<out Statement stmt>
 
2337
        =
 
2338
        (.
 
2339
                BlockStatement blockStmt = new BlockStatement();
 
2340
                blockStmt.StartLocation = t.Location;
 
2341
                compilationUnit.BlockStart(blockStmt);
 
2342
        .)
 
2343
        {       
 
2344
                        IF (IsEndStmtAhead()) "End" EndOfStmt (. compilationUnit.AddChild(new EndStatement()); .)
 
2345
                        | Statement EndOfStmt
 
2346
/*              IF (!LeaveBlock()) { }*/
 
2347
        }
 
2348
        (.
 
2349
                stmt = blockStmt;
 
2350
                blockStmt.EndLocation = t.EndLocation;
 
2351
                compilationUnit.BlockEnd();
 
2352
        .)
 
2353
        .
 
2354
 
 
2355
Statement
 
2356
        (.
 
2357
                Statement stmt = null;
 
2358
                Point startPos = la.Location;
 
2359
                string label = String.Empty;
 
2360
                
 
2361
        .) =
 
2362
        (
 
2363
                | IF (IsLabel()) LabelName<out label>
 
2364
                (.
 
2365
                        compilationUnit.AddChild(new LabelStatement(t.val));
 
2366
                .)
 
2367
                ":" Statement
 
2368
                | EmbeddedStatement<out stmt>                   (. compilationUnit.AddChild(stmt); .)
 
2369
                | LocalDeclarationStatement<out stmt>   (. compilationUnit.AddChild(stmt); .)
 
2370
        )
 
2371
        (.
 
2372
                if (stmt != null) {
 
2373
                        stmt.StartLocation = startPos;
 
2374
                        stmt.EndLocation = t.Location;
 
2375
                }
 
2376
        .)
 
2377
.
 
2378
 
 
2379
/* 10.2 */
 
2380
LocalDeclarationStatement<out Statement statement>
 
2381
        (.
 
2382
                Modifiers m = new Modifiers();
 
2383
                LocalVariableDeclaration localVariableDeclaration;
 
2384
                bool dimfound = false;
 
2385
        .) =
 
2386
        /* this differs from the spec: dim static x     compiles with vbc. */
 
2387
        {
 
2388
                "Const"         (. m.Add(Modifier.Const, t.Location); .)
 
2389
                | "Static"      (. m.Add(Modifier.Static, t.Location); .)
 
2390
                | "Dim"         (. dimfound = true; .)
 
2391
        }
 
2392
        (.
 
2393
                if(dimfound && (m.Modifier & Modifier.Const) != 0) {
 
2394
                        Error("Dim is not allowed on constants.");
 
2395
                }
 
2396
                
 
2397
                if(m.isNone && dimfound == false) {
 
2398
                        Error("Const, Dim or Static expected");
 
2399
                }
 
2400
                
 
2401
                localVariableDeclaration = new LocalVariableDeclaration(m.Modifier);
 
2402
                localVariableDeclaration.StartLocation = t.Location;
 
2403
        .)
 
2404
        VariableDeclarator<localVariableDeclaration.Variables>
 
2405
        { "," VariableDeclarator<localVariableDeclaration.Variables> }
 
2406
        (.
 
2407
                statement = localVariableDeclaration;
 
2408
        .)
 
2409
        .
 
2410
 
 
2411
EmbeddedStatement<out Statement statement>
 
2412
        (.
 
2413
                Statement embeddedStatement = null;
 
2414
                statement = null;
 
2415
                Expression expr = null;
 
2416
                string name = String.Empty;
 
2417
                List<Expression> p = null;
 
2418
        .) =
 
2419
                "Exit"                          (. ExitType exitType = ExitType.None; .)
 
2420
                (
 
2421
                "Sub"                           (. exitType = ExitType.Sub; .)
 
2422
                |
 
2423
                "Function"                      (. exitType = ExitType.Function; .)
 
2424
                |
 
2425
                "Property"                      (. exitType = ExitType.Property; .)
 
2426
                |
 
2427
                "Do"                            (. exitType = ExitType.Do; .)
 
2428
                |
 
2429
                "For"                           (. exitType = ExitType.For; .)
 
2430
                |
 
2431
                "Try"                           (. exitType = ExitType.Try; .)
 
2432
                |
 
2433
                "While"                         (. exitType = ExitType.While; .)
 
2434
                |
 
2435
                "Select"                        (. exitType = ExitType.Select; .)
 
2436
                )
 
2437
        (. statement = new ExitStatement(exitType); .)
 
2438
        | TryStatement<out statement>
 
2439
        | "Continue" (. ContinueType continueType = ContinueType.None; .) [ "Do" (. continueType = ContinueType.Do; .) | "For" (. continueType = ContinueType.For; .) | "While" (. continueType = ContinueType.While; .)] (. statement = new ContinueStatement(continueType); .)
 
2440
        | /* 10.10.1.3 */
 
2441
        "Throw" [ Expr<out expr> ]                              (. statement = new ThrowStatement(expr); .)
 
2442
        | /* 10.11 */
 
2443
        "Return" [ Expr<out expr> ]                     (. statement = new ReturnStatement(expr); .)
 
2444
        | /* 10.4 */
 
2445
        "SyncLock" Expr<out expr> EndOfStmt Block<out embeddedStatement>
 
2446
        "End" "SyncLock"                                                (. statement = new LockStatement(expr, embeddedStatement); .)
 
2447
        | /* 10.5.1 */
 
2448
        "RaiseEvent" Identifier (. name = t.val; .)
 
2449
        [ "(" [ ArgumentList<out p> ] ")" ]
 
2450
        (. statement = new RaiseEventStatement(name, p); .)
 
2451
        | /* 10.3 */
 
2452
        WithStatement<out statement>
 
2453
        | /* 10.5.2 */
 
2454
        "AddHandler" (. Expression handlerExpr = null; .)
 
2455
        Expr<out expr> "," Expr<out handlerExpr>
 
2456
        (.
 
2457
                statement = new AddHandlerStatement(expr, handlerExpr);
 
2458
        .)
 
2459
        | /* 10.5.2 */
 
2460
        "RemoveHandler" (. Expression handlerExpr = null; .)
 
2461
        Expr<out expr> "," Expr<out handlerExpr>
 
2462
        (.
 
2463
                statement = new RemoveHandlerStatement(expr, handlerExpr);
 
2464
        .)
 
2465
        | /* 10.9.1 */
 
2466
        "While" Expr<out expr> EndOfStmt
 
2467
        Block<out embeddedStatement> "End" "While"
 
2468
        (.
 
2469
                statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);
 
2470
        .)
 
2471
        | /* 10.9.1 */
 
2472
        "Do"
 
2473
        (.
 
2474
                ConditionType conditionType = ConditionType.None;
 
2475
        .)
 
2476
        (
 
2477
                WhileOrUntil<out conditionType> Expr<out expr> EndOfStmt
 
2478
                Block<out embeddedStatement>
 
2479
                "Loop"
 
2480
                (.
 
2481
                        statement = new DoLoopStatement(expr, 
 
2482
                                                        embeddedStatement, 
 
2483
                                                        conditionType == ConditionType.While ? ConditionType.DoWhile : conditionType, 
 
2484
                                                        ConditionPosition.Start);
 
2485
                .)
 
2486
                |
 
2487
                EndOfStmt
 
2488
                Block<out embeddedStatement>
 
2489
                "Loop" [WhileOrUntil<out conditionType> Expr<out expr>]
 
2490
                (.
 
2491
                        statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End);
 
2492
                .)
 
2493
        )
 
2494
        | "For"
 
2495
        (.
 
2496
                        Expression group = null;
 
2497
                        TypeReference typeReference;
 
2498
                        string        typeName;
 
2499
                        Point startLocation = t.Location;
 
2500
        .)
 
2501
        (
 
2502
                /* 10.9.3  */
 
2503
                "Each" LoopControlVariable<out typeReference, out typeName>
 
2504
                "In" Expr<out group> EndOfStmt
 
2505
                Block<out embeddedStatement>
 
2506
                "Next" [ Expr<out expr> ]
 
2507
                (.
 
2508
                        statement = new ForeachStatement(typeReference, 
 
2509
                                                         typeName,
 
2510
                                                         group, 
 
2511
                                                         embeddedStatement, 
 
2512
                                                         expr);
 
2513
                        statement.StartLocation = startLocation;
 
2514
                        statement.EndLocation   = t.EndLocation;
 
2515
                        
 
2516
                .)
 
2517
                | /* 10.9.2 */
 
2518
                (.
 
2519
                        Expression start = null;
 
2520
                        Expression end = null;
 
2521
                        Expression step = null;
 
2522
                        Expression nextExpr = null;List<Expression> nextExpressions = null;
 
2523
                .)
 
2524
                LoopControlVariable<out typeReference, out typeName>
 
2525
                "=" Expr<out start> "To" Expr<out end> [ "Step" Expr<out step> ]
 
2526
                EndOfStmt Block<out embeddedStatement>
 
2527
                "Next"
 
2528
                [
 
2529
                        Expr<out nextExpr> (. nextExpressions = new List<Expression>(); nextExpressions.Add(nextExpr); .) 
 
2530
                        { "," Expr<out nextExpr> (. nextExpressions.Add(nextExpr); .) }
 
2531
                ]
 
2532
                (.
 
2533
                        statement = new ForNextStatement(typeReference, typeName, start, end, step, embeddedStatement, nextExpressions);
 
2534
                .)
 
2535
        )
 
2536
        | /* 10.10.2.1 */
 
2537
        "Error" Expr<out expr>                          (. statement = new ErrorStatement(expr); .)
 
2538
        | /* 10.12.1 */
 
2539
        "ReDim" (. bool isPreserve = false; .) [ "Preserve" (. isPreserve = true; .) ]
 
2540
        Expr<out expr>
 
2541
        (.
 
2542
                ReDimStatement reDimStatement = new ReDimStatement(isPreserve);
 
2543
                statement = reDimStatement;
 
2544
                InvocationExpression redimClause = expr as InvocationExpression;
 
2545
                if (redimClause != null) { reDimStatement.ReDimClauses.Add(redimClause); }
 
2546
        .)
 
2547
        { "," Expr<out expr>
 
2548
                (. redimClause = expr as InvocationExpression; .)
 
2549
                (. if (redimClause != null) { reDimStatement.ReDimClauses.Add(redimClause); } .)
 
2550
        }
 
2551
        | /* 10.12.2 */
 
2552
        "Erase" 
 
2553
        Expr<out expr>
 
2554
        (.List<Expression> arrays = new List<Expression>();
 
2555
                if (expr != null) { arrays.Add(expr);}
 
2556
                EraseStatement eraseStatement = new EraseStatement(arrays);
 
2557
                
 
2558
        .)
 
2559
        { "," Expr<out expr> (. if (expr != null) { arrays.Add(expr); }.) }
 
2560
        (. statement = eraseStatement; .)
 
2561
        | /* 10.11 */
 
2562
        "Stop" (. statement = new StopStatement(); .)
 
2563
        | /* 10.8.1 */
 
2564
        "If" Expr<out expr> [ "Then" ] 
 
2565
        (       
 
2566
                IF (IsEndStmtAhead()) "End" (. statement = new IfElseStatement(expr, new EndStatement()); .) 
 
2567
                |
 
2568
                /* multiline if statement */
 
2569
                EndOfStmt Block<out embeddedStatement>
 
2570
                (.
 
2571
                        IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement);
 
2572
                .)
 
2573
                {
 
2574
                        (
 
2575
                                IF(IsElseIf()) "Else" "If"
 
2576
                                | "ElseIf"
 
2577
                        )
 
2578
                        (. Expression condition = null; Statement block = null; .)
 
2579
                        Expr<out condition> [ "Then"] EndOfStmt
 
2580
                        Block<out block>
 
2581
                        (.
 
2582
                                ifStatement.ElseIfSections.Add(new ElseIfSection(condition, block));
 
2583
                        .)
 
2584
                }
 
2585
                [
 
2586
                        "Else" EndOfStmt
 
2587
                        Block<out embeddedStatement>
 
2588
                        (.
 
2589
                                ifStatement.FalseStatement.Add(embeddedStatement);
 
2590
                        .)
 
2591
                ] "End" "If"
 
2592
                (.
 
2593
                        statement = ifStatement;
 
2594
                .)
 
2595
                | /* singleline if statement */
 
2596
                EmbeddedStatement<out embeddedStatement>
 
2597
                (.
 
2598
                        IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement);
 
2599
                .)
 
2600
                { ":" EmbeddedStatement<out embeddedStatement> (. ifStatement.TrueStatement.Add(embeddedStatement); .) }
 
2601
                [
 
2602
                        "Else" [ EmbeddedStatement<out embeddedStatement> ]
 
2603
                        (.
 
2604
                                ifStatement.FalseStatement.Add(embeddedStatement);
 
2605
                        .)
 
2606
                        {
 
2607
                                ":" EmbeddedStatement<out embeddedStatement>
 
2608
                                (. ifStatement.FalseStatement.Add(embeddedStatement); .)
 
2609
                        }
 
2610
                ]
 
2611
                (. statement = ifStatement; .)
 
2612
        )
 
2613
        | /* 10.8.2 */
 
2614
        "Select" [ "Case" ] Expr<out expr> EndOfStmt
 
2615
        (.List<SwitchSection> selectSections = new List<SwitchSection>();
 
2616
                Statement block = null;
 
2617
        .)
 
2618
        {
 
2619
                (.List<CaseLabel> caseClauses = null; .)
 
2620
                "Case" CaseClauses<out caseClauses> [ IF(IsNotStatementSeparator()) ":" ] EndOfStmt
 
2621
                (.
 
2622
                        SwitchSection selectSection = new SwitchSection(caseClauses);
 
2623
                .)
 
2624
                Block<out block>
 
2625
                (.
 
2626
                        selectSection.Children = block.Children;
 
2627
                        selectSections.Add(selectSection);
 
2628
                .)
 
2629
        }
 
2630
        (. statement = new SwitchStatement(expr, selectSections); .)
 
2631
        "End" "Select"
 
2632
        | (. OnErrorStatement onErrorStatement = null; .)
 
2633
        OnErrorStatement<out onErrorStatement> (. statement = onErrorStatement; .)
 
2634
        | (. GotoStatement goToStatement = null; .)
 
2635
        GotoStatement<out goToStatement> (. statement = goToStatement; .)
 
2636
        | (. ResumeStatement resumeStatement = null; .)
 
2637
        ResumeStatement<out resumeStatement> (. statement = resumeStatement; .)
 
2638
        |/* Statement expression (invocation and assignment) 10.6.1, 10.6.2, 10.6.3 */
 
2639
        (.
 
2640
                Expression val = null;
 
2641
                AssignmentOperatorType op;
 
2642
                
 
2643
                bool mustBeAssignment = la.kind == Tokens.Plus  || la.kind == Tokens.Minus ||
 
2644
                                        la.kind == Tokens.Not   || la.kind == Tokens.Times;
 
2645
        .)
 
2646
        SimpleExpr<out expr>
 
2647
                (
 
2648
                AssignmentOperator<out op> Expr<out val>        (. expr = new AssignmentExpression(expr, op, val); .)
 
2649
                | (. if (mustBeAssignment) Error("error in assignment."); .)
 
2650
                )
 
2651
                (.
 
2652
                        // a field reference expression that stands alone is a
 
2653
                        // invocation expression without parantheses and arguments
 
2654
                        if(expr is FieldReferenceExpression || expr is IdentifierExpression) {
 
2655
                                expr = new InvocationExpression(expr);
 
2656
                        }
 
2657
                        statement = new StatementExpression(expr);
 
2658
                .)
 
2659
        | "Call" SimpleExpr<out expr> (. statement = new StatementExpression(expr); .)
 
2660
        | "Using" Identifier (. 
 
2661
                string resourcename = t.val, typeName; 
 
2662
                Statement resourceAquisition = null, block = null;
 
2663
        .) "As" (
 
2664
                "New" Qualident<out typeName>
 
2665
                (. List<Expression> initializer = null; .)
 
2666
                ["(" [ ArgumentList<out initializer> ] ")" ]
 
2667
                (.  
 
2668
                        resourceAquisition =  new LocalVariableDeclaration(new VariableDeclaration(resourcename, new ArrayInitializerExpression(initializer), new TypeReference(typeName)));
 
2669
                        
 
2670
                .) |
 
2671
                Qualident<out typeName> "=" Expr<out expr> 
 
2672
                (.
 
2673
                        resourceAquisition =  new LocalVariableDeclaration(new VariableDeclaration(resourcename, expr, new TypeReference(typeName)));
 
2674
                .) )
 
2675
                
 
2676
                Block<out block>
 
2677
                "End" "Using"
 
2678
                (. statement = new UsingStatement(resourceAquisition, block); .)
 
2679
                
 
2680
        .
 
2681
 
 
2682
/* 10.9.2 */
 
2683
LoopControlVariable<out TypeReference type, out string name>
 
2684
(.ArrayList arrayModifiers = null;
 
2685
        type = null;
 
2686
.)
 
2687
=
 
2688
        Qualident<out name>
 
2689
        [ IF(IsDims()) ArrayTypeModifiers<out arrayModifiers> ]
 
2690
        [ "As" TypeName<out type> (. if (name.IndexOf('.') > 0) { Error("No type def for 'for each' member indexer allowed."); } .) ]
 
2691
        (.
 
2692
                if (type != null) {
 
2693
                        if(type.RankSpecifier != null && arrayModifiers != null) {
 
2694
                                Error("array rank only allowed one time");
 
2695
                        } else if (arrayModifiers != null) {
 
2696
                                type.RankSpecifier = (int[])arrayModifiers.ToArray(typeof(int));
 
2697
                        }
 
2698
                } else {
 
2699
                        if (arrayModifiers != null) {
 
2700
                                type = new TypeReference("Integer", (int[])arrayModifiers.ToArray(typeof(int)));
 
2701
                        } else {
 
2702
                                type = new TypeReference("Integer");
 
2703
                        }
 
2704
                }
 
2705
        .)
 
2706
.
 
2707
 
 
2708
/* 10.2.2 */
 
2709
OnErrorStatement<out OnErrorStatement stmt>
 
2710
        (.
 
2711
                stmt = null;
 
2712
                GotoStatement goToStatement = null;
 
2713
        .)
 
2714
        =
 
2715
        "On" "Error"
 
2716
        (
 
2717
                IF(IsNegativeLabelName())"GoTo" "-" LiteralInteger
 
2718
                (.
 
2719
                        long intLabel = Int64.Parse(t.val);
 
2720
                        if(intLabel != 1) {
 
2721
                                Error("invalid label in on error statement.");
 
2722
                        }
 
2723
                        stmt = new OnErrorStatement(new GotoStatement((intLabel * -1).ToString()));
 
2724
                .)
 
2725
                | GotoStatement<out goToStatement>
 
2726
                (.
 
2727
                        string val = goToStatement.Label;
 
2728
                        
 
2729
                        // if value is numeric, make sure that is 0
 
2730
                        try {
 
2731
                                long intLabel = Int64.Parse(val);
 
2732
                                if(intLabel != 0) {
 
2733
                                        Error("invalid label in on error statement.");
 
2734
                                }
 
2735
                        } catch {
 
2736
                        }
 
2737
                        stmt = new OnErrorStatement(goToStatement);
 
2738
                .)
 
2739
                | "Resume" "Next"
 
2740
                (.
 
2741
                        stmt = new OnErrorStatement(new ResumeStatement(true));
 
2742
                .)
 
2743
        )
 
2744
        .
 
2745
 
 
2746
/* 10.11 */
 
2747
GotoStatement<out ICSharpCode.NRefactory.Parser.AST.GotoStatement goToStatement>
 
2748
        (.
 
2749
                string label = String.Empty;
 
2750
        .)
 
2751
        =
 
2752
        "GoTo" LabelName<out label>
 
2753
        (.
 
2754
                goToStatement = new ICSharpCode.NRefactory.Parser.AST.GotoStatement(label);
 
2755
        .)
 
2756
        .
 
2757
 
 
2758
/* 10.1 */
 
2759
LabelName<out string name>
 
2760
        (.
 
2761
                name = String.Empty;
 
2762
        .) =
 
2763
        Identifier                              (. name = t.val; .)
 
2764
        | LiteralInteger        (. name = t.val; .)
 
2765
        .
 
2766
 
 
2767
/* 12.12.1 */
 
2768
/*
 
2769
ReDimClause<out ReDimClause clause>
 
2770
        (.
 
2771
                Expression initializer = null;
 
2772
                Expression arrayInitializer = null;
 
2773
                string name;
 
2774
        .) =
 
2775
        [Expr<out initializer> "." ]
 
2776
        Qualident<out name>
 
2777
        (.
 
2778
                clause = new ReDimClause(name);
 
2779
        .)
 
2780
        "(" Expr<out initializer>
 
2781
        (.
 
2782
                clause.Initializers.Add(initializer);
 
2783
        .)
 
2784
        { "," Expr<out initializer> (. clause.Initializers.Add(initializer); .) }
 
2785
        ")"
 
2786
        [ ArrayInitializer<out arrayInitializer> ]
 
2787
        .
 
2788
*/
 
2789
 
 
2790
/* 10.10.2.3 */
 
2791
ResumeStatement<out ResumeStatement resumeStatement>
 
2792
        (.
 
2793
                resumeStatement = null;
 
2794
                string label = String.Empty;
 
2795
        .) =
 
2796
        IF(IsResumeNext())
 
2797
        "Resume" "Next"                                         (. resumeStatement = new ResumeStatement(true); .)
 
2798
        | "Resume" [ LabelName<out label> ]     (. resumeStatement = new ResumeStatement(label); .)
 
2799
        .
 
2800
 
 
2801
/* 18.8.2 */
 
2802
CaseClauses<out List<CaseLabel> caseClauses>
 
2803
        (.
 
2804
                caseClauses = new List<CaseLabel>();
 
2805
                CaseLabel caseClause = null;
 
2806
        .) =
 
2807
        CaseClause<out caseClause> (. if (caseClause != null) { caseClauses.Add(caseClause); } .)
 
2808
        { "," CaseClause<out caseClause> (. if (caseClause != null) { caseClauses.Add(caseClause); } .) }
 
2809
        .
 
2810
 
 
2811
/* 19.8.2 */
 
2812
CaseClause<out CaseLabel caseClause>
 
2813
        (.
 
2814
                Expression expr = null;
 
2815
                Expression sexpr = null;
 
2816
                BinaryOperatorType op = BinaryOperatorType.None;
 
2817
                caseClause = null;
 
2818
        .) =
 
2819
        "Else"
 
2820
        (. caseClause = new CaseLabel(); .)
 
2821
        |
 
2822
        [ "Is" ] 
 
2823
        (
 
2824
                "<"             (. op = BinaryOperatorType.LessThan; .)
 
2825
                | ">"   (. op = BinaryOperatorType.GreaterThan; .)
 
2826
                | "<="  (. op = BinaryOperatorType.LessThanOrEqual; .)
 
2827
                | ">="  (. op = BinaryOperatorType.GreaterThanOrEqual; .)
 
2828
                | "="   (. op = BinaryOperatorType.Equality; .)
 
2829
                | "<>"  (. op = BinaryOperatorType.InEquality; .)
 
2830
        )
 
2831
        Expr<out expr>
 
2832
        (.
 
2833
                caseClause = new CaseLabel(op, expr);
 
2834
        .)
 
2835
        | Expr<out expr> [ "To" Expr<out sexpr> ]
 
2836
        (.
 
2837
                caseClause = new CaseLabel(expr, sexpr);
 
2838
        .)
 
2839
        .
 
2840
 
 
2841
/* 10.9.1 */
 
2842
WhileOrUntil<out ConditionType conditionType>
 
2843
        (. conditionType = ConditionType.None; .) =
 
2844
        "While"         (. conditionType = ConditionType.While; .)
 
2845
        | "Until"       (. conditionType = ConditionType.Until; .)
 
2846
        .
 
2847
 
 
2848
/* 10.3 */
 
2849
WithStatement<out Statement withStatement>
 
2850
        (.
 
2851
                Statement blockStmt = null;
 
2852
                Expression expr = null;
 
2853
        .) =
 
2854
        "With" (. Point start = t.Location; .)
 
2855
        Expr<out expr> EndOfStmt
 
2856
        (.
 
2857
                withStatement = new WithStatement(expr);
 
2858
                withStatement.StartLocation = start;
 
2859
                withStatements.Push(withStatement);
 
2860
        .)
 
2861
        Block<out blockStmt>
 
2862
        (.
 
2863
                ((WithStatement)withStatement).Body = (BlockStatement)blockStmt;
 
2864
                withStatements.Pop();
 
2865
        .)
 
2866
        "End" "With"
 
2867
        (. withStatement.EndLocation = t.Location; .)
 
2868
        .
 
2869
        
 
2870
/* 10.10.1 */
 
2871
TryStatement<out Statement tryStatement>
 
2872
        (.
 
2873
                Statement blockStmt = null, finallyStmt = null;List<CatchClause> catchClauses = null;
 
2874
        .) =
 
2875
        "Try" EndOfStmt
 
2876
        Block<out blockStmt>
 
2877
        [CatchClauses<out catchClauses>]
 
2878
        ["Finally" EndOfStmt Block<out finallyStmt> ]
 
2879
        "End" "Try"
 
2880
        (.
 
2881
                tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt);
 
2882
        .)
 
2883
        .
 
2884
 
 
2885
/* 10.10.1.2 */
 
2886
CatchClauses<out List<CatchClause> catchClauses>
 
2887
        (.
 
2888
                catchClauses = new List<CatchClause>();
 
2889
                TypeReference type = null;
 
2890
                Statement blockStmt = null;
 
2891
                Expression expr = null;
 
2892
                string name = String.Empty;
 
2893
        .) =
 
2894
        {
 
2895
                "Catch"
 
2896
                [ Identifier (. name = t.val; .) ["As" TypeName<out type>] ]
 
2897
                [ "When" Expr<out expr> ]
 
2898
                EndOfStmt
 
2899
                Block<out blockStmt>
 
2900
                (. catchClauses.Add(new CatchClause(type, name, blockStmt, expr)); .)
 
2901
        }
 
2902
        .
 
2903
 
 
2904
/* 4.7 */
 
2905
Qualident<out string qualident>
 
2906
(. 
 
2907
        string name;
 
2908
        qualidentBuilder.Length = 0; 
 
2909
.)
 
2910
=
 
2911
        Identifier      (. qualidentBuilder.Append(t.val); .)
 
2912
        { IF (DotAndIdentOrKw()) "." IdentifierOrKeyword<out name> (. qualidentBuilder.Append('.'); qualidentBuilder.Append(name); .) }
 
2913
        
 
2914
        (. qualident = qualidentBuilder.ToString(); .)
 
2915
.
 
2916
 
 
2917
/* This production handles pseudo keywords that are needed in the grammar */
 
2918
Identifier      =
 
2919
        ident
 
2920
        | "Text"
 
2921
        | "Binary"
 
2922
        | "Compare"
 
2923
        | "Assembly"
 
2924
        | "Ansi"
 
2925
        | "Auto"
 
2926
        | "Preserve"
 
2927
        | "Unicode"
 
2928
        | "Until"
 
2929
        .
 
2930
 
 
2931
/* 2.2 */
 
2932
 
 
2933
IdentifierOrKeyword<out string name>
 
2934
=
 
2935
        (. lexer.NextToken(); name = t.val;  .)
 
2936
.
 
2937
 
 
2938
 
 
2939
/* 7.3 */
 
2940
PrimitiveTypeName<out string type>
 
2941
        (. type = String.Empty; .) =
 
2942
        "Boolean"               (. type = "Boolean"; .)
 
2943
        | "Date"                (. type = "Date"; .)
 
2944
        | "Char"                (. type = "Char"; .)
 
2945
        | "String"              (. type = "String"; .)
 
2946
        | "Decimal"             (. type = "Decimal"; .)
 
2947
        | "Byte"                (. type = "Byte"; .)
 
2948
        | "Short"               (. type = "Short"; .)
 
2949
        | "Integer"             (. type = "Integer"; .)
 
2950
        | "Long"                (. type = "Long"; .)
 
2951
        | "Single"              (. type = "Single"; .)
 
2952
        | "Double"              (. type = "Double"; .)
 
2953
        | "UInteger"    (. type = "UInteger"; .)
 
2954
        | "ULong"               (. type = "ULong"; .)
 
2955
        | "UShort"              (. type = "UShort"; .)
 
2956
        | "SByte"               (. type = "SByte"; .)
 
2957
        .
 
2958
 
 
2959
ParameterModifier<ParamModifiers m>
 
2960
        = "ByVal"                       (. m.Add(ParamModifier.In); .)
 
2961
        | "ByRef"                       (. m.Add(ParamModifier.Ref); .)
 
2962
        | "Optional"            (. m.Add(ParamModifier.Optional); .)
 
2963
        | "ParamArray"          (. m.Add(ParamModifier.Params); .)
 
2964
        .
 
2965
 
 
2966
TypeModifier<Modifiers m>
 
2967
=         "Public"                      (. m.Add(Modifier.Public, t.Location); .)
 
2968
        | "Protected"           (. m.Add(Modifier.Protected, t.Location); .)
 
2969
        | "Friend"                      (. m.Add(Modifier.Internal, t.Location); .)
 
2970
        | "Private"                     (. m.Add(Modifier.Private, t.Location); .)
 
2971
        | "Shared"                      (. m.Add(Modifier.Static, t.Location); .)
 
2972
        | "Shadows"                     (. m.Add(Modifier.New, t.Location); .)
 
2973
        | "MustInherit"         (. m.Add(Modifier.Abstract, t.Location); .)
 
2974
        | "NotInheritable"      (. m.Add(Modifier.Sealed, t.Location); .)
 
2975
        | "Partial"                     (. m.Add(Modifier.Partial, t.Location); .)
 
2976
.
 
2977
 
 
2978
MemberModifier<Modifiers m> =
 
2979
          "MustInherit"         (.m.Add(Modifier.Abstract, t.Location);.)
 
2980
        | "Default"                     (.m.Add(Modifier.Default, t.Location);.)
 
2981
        | "Friend"                      (.m.Add(Modifier.Internal, t.Location);.)
 
2982
        | "Shadows"                     (.m.Add(Modifier.New, t.Location);.)
 
2983
        | "Overrides"           (.m.Add(Modifier.Override, t.Location);.)
 
2984
        | "MustOverride"        (.m.Add(Modifier.Abstract, t.Location);.)
 
2985
        | "Private"                     (.m.Add(Modifier.Private, t.Location);.)
 
2986
        | "Protected"           (.m.Add(Modifier.Protected, t.Location);.)
 
2987
        | "Public"                      (.m.Add(Modifier.Public, t.Location);.)
 
2988
        | "NotInheritable"      (.m.Add(Modifier.Sealed, t.Location);.)
 
2989
        | "NotOverridable"      (.m.Add(Modifier.Sealed, t.Location);.)
 
2990
        | "Shared"                      (.m.Add(Modifier.Static, t.Location);.)
 
2991
        | "Overridable"         (.m.Add(Modifier.Virtual, t.Location);.)
 
2992
        | "Overloads"           (.m.Add(Modifier.Overloads, t.Location);.)
 
2993
        | "ReadOnly"            (.m.Add(Modifier.ReadOnly, t.Location);.)
 
2994
        | "WriteOnly"           (.m.Add(Modifier.WriteOnly, t.Location);.)
 
2995
        | "WithEvents"          (.m.Add(Modifier.WithEvents, t.Location);.)
 
2996
        | "Dim"                         (.m.Add(Modifier.Dim, t.Location);.)
 
2997
        | "Widening"            (.m.Add(Modifier.Widening, t.Location);.)
 
2998
        | "Narrowing"           (.m.Add(Modifier.Narrowing, t.Location);.)
 
2999
.
 
3000
 
 
3001
END VBNET.