2
using System.Collections;
3
using System.Collections.Generic;
4
using System.Collections.Specialized;
6
using ICSharpCode.NRefactory.Parser.AST;
7
using ICSharpCode.NRefactory.Parser.VB;
8
using ASTAttribute = ICSharpCode.NRefactory.Parser.AST.Attribute;
12
private string assemblyName = null;
13
private Stack withStatements;
14
private StringBuilder qualidentBuilder = new StringBuilder();
16
public string ContainingAssembly
18
set { assemblyName = value; }
29
return lexer.LookAhead;
33
/* Return the n-th token after the current lookahead token */
55
public void Error(string s)
57
if (errDist >= minErrDist) {
58
errors.Error(la.line, la.col, s);
63
public override Expression ParseExpression()
73
int peek = Peek(1).kind;
74
return Tokens.BlockSucc[la.kind] && (la.kind != Tokens.End || peek == Tokens.EOL || peek == Tokens.Colon);
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);
85
int peek = Peek(1).kind;
86
return la.kind == Tokens.End && (peek == Tokens.EOL || peek == Tokens.Colon);
89
bool IsNotClosingParenthesis() {
90
return la.kind != Tokens.CloseParenthesis;
94
True, if ident is followed by "="
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;
105
True, if ident is followed by "=" or by ":" and "="
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;
113
bool IsObjectCreation() {
114
return la.kind == Tokens.As && Peek(1).kind == Tokens.New;
118
True, if "<" is followed by the ident "assembly" or "module"
120
bool IsGlobalAttrTarget () {
122
return la.kind == Tokens.LessThan && ( string.Equals(pt.val, "assembly", StringComparison.InvariantCultureIgnoreCase) || string.Equals(pt.val, "module", StringComparison.InvariantCultureIgnoreCase));
126
True if the next token is a "(" and is followed by "," or ")"
130
int peek = Peek(1).kind;
131
return la.kind == Tokens.OpenParenthesis
132
&& (peek == Tokens.Comma || peek == Tokens.CloseParenthesis);
137
return la.kind == Tokens.OpenParenthesis;
141
True, if the comma is not a trailing one,
142
like the last one in: a, b, c,
144
bool NotFinalComma() {
145
int peek = Peek(1).kind;
146
return la.kind == Tokens.Comma &&
147
peek != Tokens.CloseCurlyBrace;
151
True, if the next token is "Else" and this one
156
int peek = Peek(1).kind;
157
return la.kind == Tokens.Else && peek == Tokens.If;
161
True if the next token is goto and this one is
162
followed by minus ("-") (this is allowd in in
165
bool IsNegativeLabelName()
167
int peek = Peek(1).kind;
168
return la.kind == Tokens.GoTo && peek == Tokens.Minus;
172
True if the next statement is a "Resume next" statement
176
int peek = Peek(1).kind;
177
return la.kind == Tokens.Resume && peek == Tokens.Next;
181
True, if ident/literal integer is followed by ":"
185
return (la.kind == Tokens.Identifier || la.kind == Tokens.LiteralInteger)
186
&& Peek(1).kind == Tokens.Colon;
189
bool IsNotStatementSeparator()
191
return la.kind == Tokens.Colon && Peek(1).kind == Tokens.EOL;
196
return IdentAndAsgn();
199
bool IsMustOverride(Modifiers m)
201
return m.Contains(Modifier.Abstract);
204
TypeReferenceExpression GetTypeReferenceExpression(Expression expr, List<TypeReference> genericTypes)
206
TypeReferenceExpression tre = expr as TypeReferenceExpression;
208
return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes));
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;
216
tre = expr as TypeReferenceExpression;
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);
224
typeRef = new InnerClassTypeReference(typeRef, b.ToString(), genericTypes);
226
return new TypeReferenceExpression(typeRef);
229
return new TypeReferenceExpression(new TypeReference(b.ToString(), 0, null, genericTypes));
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)
237
FieldReferenceExpression fre = expr as FieldReferenceExpression;
239
bool result = WriteFullTypeName(b, fre.TargetObject);
240
if (b.Length > 0) b.Append('.');
241
b.Append(fre.FieldName);
243
} else if (expr is IdentifierExpression) {
244
b.Append(((IdentifierExpression)expr).Identifier);
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"
256
bool IsLocalAttrTarget() {
261
/* START AUTOGENERATED TOKENS SECTION */
263
/* ----- terminal classes ----- */
275
/* ----- special character ----- */
309
/* ----- keywords ----- */
473
/* END AUTOGENERATED TOKENS SECTION */
480
lexer.NextToken(); // get the first token
481
compilationUnit = new CompilationUnit();
482
withStatements = new Stack();
487
{ IF (IsGlobalAttrTarget()) GlobalAttributeSection }
488
{ NamespaceMemberDecl }
492
OptionStmt (. INode node = null; bool val = true; .) =
493
"Option" (. Point startPos = t.Location; .)
495
"Explicit" [ OptionValue<ref val> ]
496
(. node = new OptionDeclaration(OptionType.Explicit, val); .)
498
"Strict" [ OptionValue<ref val> ]
499
(. node = new OptionDeclaration(OptionType.Strict, val); .)
501
"Compare" ( "Binary" (. node = new OptionDeclaration(OptionType.CompareBinary, val); .)
502
| "Text" (. node = new OptionDeclaration(OptionType.CompareText, val); .)
508
node.StartLocation = startPos;
509
node.EndLocation = t.Location;
510
compilationUnit.AddChild(node);
515
OptionValue<ref bool val> =
517
"On" (. val = true; .)
519
"Off" (. val = false; .)
530
(.List<Using> usings = new List<Using>();
534
Point startPos = t.Location;
537
ImportClause<out u> (. if (u != null) { usings.Add(u); } .)
539
"," ImportClause<out u> (. if (u != null) { usings.Add(u); } .)
543
UsingDeclaration usingDeclaration = new UsingDeclaration(usings);
544
usingDeclaration.StartLocation = startPos;
545
usingDeclaration.EndLocation = t.Location;
546
compilationUnit.AddChild(usingDeclaration);
550
ImportClause<out Using u>
552
string qualident = null;
553
TypeReference aliasedType = null;
556
Qualident<out qualident>
557
[ "=" TypeName<out aliasedType> ]
559
if (qualident != null && qualident.Length > 0) {
560
if (aliasedType != null) {
561
u = new Using(qualident, aliasedType);
563
u = new Using(qualident);
572
Modifiers m = new Modifiers();
573
AttributeSection section;
574
List<AttributeSection> attributes = new List<AttributeSection>();
579
Point startPos = t.Location;
581
Qualident<out qualident>
583
INode node = new NamespaceDeclaration(qualident);
584
node.StartLocation = startPos;
585
compilationUnit.AddChild(node);
586
compilationUnit.BlockStart(node);
591
node.EndLocation = t.Location;
592
compilationUnit.BlockEnd();
595
{ AttributeSection<out section> (. attributes.Add(section); .) }
596
{ TypeModifier<m> } NonModuleDeclaration<m, attributes>
600
TypeParameterList<List<TemplateDefinition> templates>
602
TemplateDefinition template;
605
IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
606
"(" "Of" TypeParameter<out template>
608
if (template != null) templates.Add(template);
611
"," TypeParameter<out template>
613
if (template != null) templates.Add(template);
621
TypeParameter<out TemplateDefinition template>
623
Identifier (. template = new TemplateDefinition(t.val, null); .)
624
[TypeParameterConstraints<template>]
628
TypeParameterConstraints<TemplateDefinition template>
630
TypeReference constraint;
636
TypeName<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
639
TypeName<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
642
| TypeName<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
647
NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
649
TypeReference typeRef = null;
650
List<TypeReference> baseInterfaces = null;
652
(. m.Check(Modifier.Classes); .)
655
(. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
656
newType.StartLocation = t.Location;
657
compilationUnit.AddChild(newType);
658
compilationUnit.BlockStart(newType);
660
newType.Type = ClassType.Class;
662
Identifier (. newType.Name = t.val; .)
663
TypeParameterList<newType.Templates>
665
(. newType.BodyStartLocation = t.Location; .)
666
[ ClassBaseType<out typeRef> (. newType.BaseTypes.Add(typeRef); .) ]
667
{ TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
670
compilationUnit.BlockEnd();
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;
681
Identifier (. newType.Name = t.val; .)
683
(. newType.BodyStartLocation = t.Location; .)
686
compilationUnit.BlockEnd();
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;
697
Identifier (. newType.Name = t.val; .)
698
TypeParameterList<newType.Templates>
700
(. newType.BodyStartLocation = t.Location; .)
701
{ TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces);.) }
702
StructureBody<newType>
704
compilationUnit.BlockEnd();
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);
715
newType.Type = ClassType.Enum;
717
Identifier (. newType.Name = t.val; .)
718
[ "As" NonArrayTypeName<out typeRef, false> (. newType.BaseTypes.Add(typeRef); .) ]
720
(. newType.BodyStartLocation = t.Location; .)
723
compilationUnit.BlockEnd();
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;
735
Identifier (. newType.Name = t.val; .)
736
TypeParameterList<newType.Templates>
738
(. newType.BodyStartLocation = t.Location; .)
739
{ InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
740
InterfaceBody<newType>
742
compilationUnit.BlockEnd();
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>();
754
"Sub" Identifier (. delegateDeclr.Name = t.val; .)
755
TypeParameterList<delegateDeclr.Templates>
756
[ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ]
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; .)]
763
(. delegateDeclr.EndLocation = t.EndLocation; .)
766
compilationUnit.AddChild(delegateDeclr);
771
{ NamespaceMemberDecl }
776
ClassBody<TypeDeclaration newType>
777
(. AttributeSection section; .) =
779
(.List<AttributeSection> attributes = new List<AttributeSection>();
780
Modifiers m = new Modifiers();
782
{ AttributeSection<out section> (. attributes.Add(section); .) }
783
{ MemberModifier<m> }
784
ClassMemberDecl<m, attributes>
786
"End" "Class" (. newType.EndLocation = t.EndLocation; .)
790
StructureBody<TypeDeclaration newType>
791
(. AttributeSection section; .) =
793
(.List<AttributeSection> attributes = new List<AttributeSection>();
794
Modifiers m = new Modifiers();
796
{ AttributeSection<out section> (. attributes.Add(section); .) }
797
{ MemberModifier<m> }
798
StructureMemberDecl<m, attributes>
800
"End" "Structure" (. newType.EndLocation = t.EndLocation; .)
805
ModuleBody<TypeDeclaration newType>
806
(. AttributeSection section; .) =
808
(.List<AttributeSection> attributes = new List<AttributeSection>();
809
Modifiers m = new Modifiers();
811
{ AttributeSection<out section> (. attributes.Add(section); .) }
812
{ MemberModifier<m> }
813
ClassMemberDecl<m, attributes>
815
"End" "Module" (. newType.EndLocation = t.EndLocation; .)
819
EnumBody<TypeDeclaration newType>
820
(. FieldDeclaration f; .) =
822
EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
824
"End" "Enum" (. newType.EndLocation = t.EndLocation; .)
828
InterfaceBody<TypeDeclaration newType> =
829
{ InterfaceMemberDecl }
830
"End" "Interface" (. newType.EndLocation = t.EndLocation; .)
834
/* The information provided in the spec about */
835
/* interface declarations is wrong */
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>();
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> }
852
(. mod.Check(Modifier.VBInterfaceEvents); .)
853
Identifier (. name = t.val; .)
854
[ "(" [ FormalParameterList<p> ] ")" ]
855
[ "As" TypeName<out type> ]
858
EventDeclaration ed = new EventDeclaration(type, mod.Modifier, p, attributes, name, null);
859
compilationUnit.AddChild(ed);
860
ed.EndLocation = t.EndLocation;
864
(. mod.Check(Modifier.VBInterfaceMethods); .)
865
Identifier (. name = t.val; .)
866
TypeParameterList<templates>
867
[ "(" [ FormalParameterList<p> ] ")" ]
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);
878
(. mod.Check(Modifier.VBInterfaceMethods); .)
879
Identifier (. name = t.val; .)
880
TypeParameterList<templates>
881
[ "(" [ FormalParameterList<p> ] ")" ]
882
[ "As" { AttributeSection<out returnTypeAttributeSection> } TypeName<out type> ]
885
type = new TypeReference("System.Object");
887
MethodDeclaration md = new MethodDeclaration(name, mod.Modifier, type, p, attributes);
888
if (returnTypeAttributeSection != null) {
889
returnTypeAttributeSection.AttributeTarget = "return";
890
md.Attributes.Add(returnTypeAttributeSection);
892
md.EndLocation = t.EndLocation;
893
md.Templates = templates;
894
compilationUnit.AddChild(md);
899
(. mod.Check(Modifier.VBInterfaceProperties); .)
900
Identifier (. name = t.val; .)
901
[ "(" [ FormalParameterList<p> ] ")" ]
902
[ "As" TypeName<out type> ]
905
type = new TypeReference("System.Object");
910
PropertyDeclaration pd = new PropertyDeclaration(name, type, mod.Modifier, attributes);
912
pd.EndLocation = t.EndLocation;
913
compilationUnit.AddChild(pd);
916
| /* inner type declarations */
917
NonModuleDeclaration<mod, attributes>
921
EnumMemberDecl<out FieldDeclaration f>
923
Expression expr = null;List<AttributeSection> attributes = new List<AttributeSection>();
924
AttributeSection section = null;
925
VariableDeclaration varDecl = null;
927
{ AttributeSection<out section> (. attributes.Add(section); .) }
930
f = new FieldDeclaration(attributes);
931
varDecl = new VariableDeclaration(t.val);
932
f.Fields.Add(varDecl);
933
f.StartLocation = t.Location;
935
[ "=" Expr<out expr> (. varDecl.Initializer = expr; .) ]
939
ClassMemberDecl<Modifiers m, List<AttributeSection> attributes> =
940
StructureMemberDecl<m, attributes>
943
ClassBaseType<out TypeReference typeRef>
948
TypeName<out typeRef>
953
StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
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>();
961
NonModuleDeclaration<m, attributes>
965
Point startPos = t.Location;
969
string name = String.Empty;
970
MethodDeclaration methodDeclaration; List<string> handlesClause = null;
971
List<InterfaceImplementation> implementsClause = null;
976
m.Check(Modifier.VBMethods);
978
TypeParameterList<templates>
979
[ "(" [ FormalParameterList<p> ] ")" ]
982
ImplementsClause<out implementsClause>
984
HandlesClause<out handlesClause>
987
(. Point endLocation = t.EndLocation; .)
990
/* abstract methods without a body */
991
IF(IsMustOverride(m))
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");
998
methodDeclaration.Templates = templates;
999
methodDeclaration.HandlesClause = handlesClause;
1000
methodDeclaration.InterfaceImplementations = implementsClause;
1002
compilationUnit.AddChild(methodDeclaration);
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");
1011
methodDeclaration.Templates = templates;
1012
methodDeclaration.HandlesClause = handlesClause;
1013
methodDeclaration.InterfaceImplementations = implementsClause;
1015
compilationUnit.AddChild(methodDeclaration);
1016
compilationUnit.BlockStart(methodDeclaration);
1020
compilationUnit.BlockEnd();
1021
methodDeclaration.Body = (BlockStatement)stmt;
1023
"End" "Sub" (. methodDeclaration.Body.EndLocation = t.EndLocation; .) EOL
1026
| "New" [ "(" [ FormalParameterList<p> ] ")" ]
1027
(. m.Check(Modifier.Constructors); .)
1028
(. Point constructorEndLocation = t.EndLocation; .)
1031
"End" "Sub" (. Point endLocation = t.EndLocation; .) EOL
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);
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;
1052
Identifier (. name = t.val; .)
1053
TypeParameterList<templates>
1054
[ "(" [ FormalParameterList<p> ] ")" ]
1055
["As" { AttributeSection<out returnTypeAttributeSection> } TypeName<out type> ]
1058
type = new TypeReference("System.Object");
1063
ImplementsClause<out implementsClause>
1065
HandlesClause<out handlesClause>
1070
/* abstract methods without a body */
1071
IF(IsMustOverride(m))
1073
methodDeclaration = new MethodDeclaration(name, m.Modifier, type, p, attributes);
1074
methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
1075
methodDeclaration.EndLocation = t.EndLocation;
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);
1084
compilationUnit.AddChild(methodDeclaration);
1088
methodDeclaration = new MethodDeclaration(name, m.Modifier, type, p, attributes);
1089
methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
1090
methodDeclaration.EndLocation = t.EndLocation;
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);
1100
compilationUnit.AddChild(methodDeclaration);
1101
compilationUnit.BlockStart(methodDeclaration);
1105
compilationUnit.BlockEnd();
1106
methodDeclaration.Body = (BlockStatement)stmt;
1110
methodDeclaration.Body.StartLocation = methodDeclaration.EndLocation;
1111
methodDeclaration.Body.EndLocation = t.EndLocation;
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;
1126
[Charset<out charsetModifer> ]
1129
Identifier (. name = t.val; .)
1130
"Lib" LiteralString (. library = t.literalValue.ToString(); .)
1131
["Alias" LiteralString (. alias = t.literalValue.ToString(); .)]
1132
[ "(" [ FormalParameterList<p> ] ")" ]
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);
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> ]
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);
1159
m.Check(Modifier.VBEvents);
1160
Point startPos = t.Location;
1161
EventDeclaration eventDeclaration;
1162
string name = String.Empty;
1163
List<InterfaceImplementation> implementsClause = null;
1165
Identifier (. name= t.val; .)
1167
"As" TypeName<out type>
1169
[ "(" [ FormalParameterList<p> ] ")" ]
1171
[ ImplementsClause<out implementsClause> ]
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);
1180
(. Point startPos = t.Location; .)
1182
m.Check(Modifier.Fields);
1183
FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
1184
fd.StartLocation = m.GetDeclarationLocation(startPos);
1186
VariableDeclarator<variableDeclarators>
1187
{ "," VariableDeclarator<variableDeclarators> }
1190
fd.EndLocation = t.EndLocation;
1191
fd.Fields = variableDeclarators;
1192
compilationUnit.AddChild(fd);
1195
(. m.Check(Modifier.Fields); .)
1196
"Const" (. m.Add(Modifier.Const, t.Location); .)
1198
FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
1199
fd.StartLocation = m.GetDeclarationLocation(t.Location);
1200
List<VariableDeclaration> constantDeclarators = new List<VariableDeclaration>();
1202
ConstantDeclarator<constantDeclarators>
1203
{ "," ConstantDeclarator<constantDeclarators> }
1205
fd.Fields = constantDeclarators;
1206
fd.EndLocation = t.Location;
1210
fd.EndLocation = t.EndLocation;
1211
compilationUnit.AddChild(fd);
1216
m.Check(Modifier.VBProperties);
1217
Point startPos = t.Location;
1218
List<InterfaceImplementation> implementsClause = null;
1220
Identifier (. string propertyName = t.val; .)
1221
[ "(" [ FormalParameterList<p> ] ")" ]
1222
[ "As" TypeName<out type> ]
1225
type = new TypeReference("System.Object");
1228
[ ImplementsClause<out implementsClause> ]
1231
/* abstract properties without a body */
1232
IF(IsMustOverride(m))
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);
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;
1254
AccessorDecls<out getRegion, out setRegion>
1258
pDecl.GetRegion = getRegion;
1259
pDecl.SetRegion = setRegion;
1260
pDecl.BodyEnd = t.EndLocation;
1261
compilationUnit.AddChild(pDecl);
1265
"Custom" (. Point startPos = t.Location; .) "Event"
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;
1274
Identifier (. string customEventName = t.val; .)
1275
"As" TypeName<out type>
1276
[ ImplementsClause<out implementsClause> ]
1279
EventAccessorDeclaration<out eventAccessorDeclaration>
1281
if(eventAccessorDeclaration is EventAddRegion)
1283
addHandlerAccessorDeclaration = (EventAddRegion)eventAccessorDeclaration;
1285
else if(eventAccessorDeclaration is EventRemoveRegion)
1287
removeHandlerAccessorDeclaration = (EventRemoveRegion)eventAccessorDeclaration;
1289
else if(eventAccessorDeclaration is EventRaiseRegion)
1291
raiseEventAccessorDeclaration = (EventRaiseRegion)eventAccessorDeclaration;
1297
if(addHandlerAccessorDeclaration == null)
1299
Error("Need to provide AddHandler accessor.");
1302
if(removeHandlerAccessorDeclaration == null)
1304
Error("Need to provide RemoveHandler accessor.");
1307
if(raiseEventAccessorDeclaration == null)
1309
Error("Need to provide RaiseEvent accessor.");
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);
1323
m.Check(Modifier.VBOperators);
1324
Point startPos = t.Location;
1325
TypeReference returnType = NullTypeReference.Instance;
1326
TypeReference operandType = NullTypeReference.Instance;
1328
OverloadableOperatorType operatorType;
1329
AttributeSection section;
1330
List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
1331
List<AttributeSection> returnTypeAttributes = new List<AttributeSection>();
1333
OverloadableOperator<out operatorType>
1334
"(" [ "ByVal" ] Identifier (. operandName = t.val; .)
1335
[ "As" TypeName<out operandType> ]
1336
(. parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParamModifier.In)); .)
1340
[ "ByVal" ] Identifier (. operandName = t.val; .)
1341
[ "As" TypeName<out operandType> ]
1342
(. parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParamModifier.In)); .)
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
1349
OperatorDeclaration operatorDeclaration = new OperatorDeclaration(m.Modifier,
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);
1365
OverloadableOperator<out OverloadableOperatorType operatorType>
1366
(. operatorType = OverloadableOperatorType.None; .)
1368
"+" (. operatorType = OverloadableOperatorType.Add; .)
1370
"-" (. operatorType = OverloadableOperatorType.Subtract; .)
1372
"*" (. operatorType = OverloadableOperatorType.Multiply; .)
1374
"/" (. operatorType = OverloadableOperatorType.Divide; .)
1376
"\\" (. operatorType = OverloadableOperatorType.DivideInteger; .)
1378
"&" (. operatorType = OverloadableOperatorType.Concat; .)
1380
"Like" (. operatorType = OverloadableOperatorType.Like; .)
1382
"Mod" (. operatorType = OverloadableOperatorType.Modulus; .)
1384
"And" (. operatorType = OverloadableOperatorType.BitwiseAnd; .)
1386
"Or" (. operatorType = OverloadableOperatorType.BitwiseOr; .)
1388
"Xor" (. operatorType = OverloadableOperatorType.ExclusiveOr; .)
1390
"^" (. operatorType = OverloadableOperatorType.Power; .)
1392
"<<" (. operatorType = OverloadableOperatorType.ShiftLeft; .)
1394
">>" (. operatorType = OverloadableOperatorType.ShiftRight; .)
1396
"=" (. operatorType = OverloadableOperatorType.Equality; .)
1398
"<>" (. operatorType = OverloadableOperatorType.InEquality; .)
1400
"<" (. operatorType = OverloadableOperatorType.LessThan; .)
1402
"<=" (. operatorType = OverloadableOperatorType.LessThanOrEqual; .)
1404
">" (. operatorType = OverloadableOperatorType.GreaterThan; .)
1406
">=" (. operatorType = OverloadableOperatorType.GreaterThanOrEqual; .)
1408
"CType" (. operatorType = OverloadableOperatorType.CType; .)
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;
1418
Error("Invalid operator. Possible operators are '+', '-', 'Not', 'IsTrue', 'IsFalse'.");
1423
EventAccessorDeclaration<out EventAddRemoveRegion eventAccessorDeclaration>
1425
Statement stmt = null;
1426
List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
1427
AttributeSection section;
1428
List<AttributeSection> attributes = new List<AttributeSection>();
1429
eventAccessorDeclaration = null;
1431
{ AttributeSection<out section> (. attributes.Add(section); .) }
1433
"AddHandler" [ "(" [ FormalParameterList<p> ] ")" ] EOL
1434
Block<out stmt> "End" "AddHandler" EOL
1436
eventAccessorDeclaration = new EventAddRegion(attributes);
1437
eventAccessorDeclaration.Block = (BlockStatement)stmt;
1438
eventAccessorDeclaration.Parameters = p;
1441
"RemoveHandler" [ "(" [ FormalParameterList<p> ] ")" ] EOL
1442
Block<out stmt> "End" "RemoveHandler" EOL
1444
eventAccessorDeclaration = new EventRemoveRegion(attributes);
1445
eventAccessorDeclaration.Block = (BlockStatement)stmt;
1446
eventAccessorDeclaration.Parameters = p;
1449
"RaiseEvent" [ "(" [ FormalParameterList<p> ] ")" ] EOL
1450
Block<out stmt> "End" "RaiseEvent" EOL
1452
eventAccessorDeclaration = new EventRaiseRegion(attributes);
1453
eventAccessorDeclaration.Block = (BlockStatement)stmt;
1454
eventAccessorDeclaration.Parameters = p;
1460
AccessorDecls<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
1462
List<AttributeSection> attributes = new List<AttributeSection>();
1463
AttributeSection section;
1467
{ AttributeSection<out section> (. attributes.Add(section); .) }
1469
GetAccessorDecl<out getBlock, attributes>
1471
(. attributes = new List<AttributeSection>(); .)
1472
{ AttributeSection<out section> (. attributes.Add(section); .) }
1473
SetAccessorDecl<out setBlock, attributes>
1476
SetAccessorDecl<out setBlock, attributes>
1478
(. attributes = new List<AttributeSection>(); .)
1479
{ AttributeSection<out section> (. attributes.Add(section); .) }
1480
GetAccessorDecl<out getBlock, attributes>
1486
GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attributes>
1487
(. Statement stmt = null; .) =
1489
(. Point startLocation = t.Location; .)
1492
(. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .)
1494
(. getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; .)
1499
SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attributes>
1501
Statement stmt = null; List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
1504
(. Point startLocation = t.Location; .)
1505
[ "(" [ FormalParameterList<p> ] ")" ]
1509
setBlock = new PropertySetRegion((BlockStatement)stmt, attributes);
1510
setBlock.Parameters = p;
1513
(. setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; .)
1518
ConstantDeclarator<List<VariableDeclaration> constantDeclaration>
1520
Expression expr = null;
1521
TypeReference type = null;
1522
string name = String.Empty;
1524
Identifier (. name = t.val; .)
1525
["As" TypeName<out type> ]
1528
VariableDeclaration f = new VariableDeclaration(name, expr);
1529
f.TypeReference = type;
1530
constantDeclaration.Add(f);
1535
VariableDeclarator<List<VariableDeclaration> fieldDeclaration>
1537
Expression expr = null;
1538
TypeReference type = null;
1539
ArrayList rank = null;
1540
List<Expression> dimension = null;
1542
Identifier (. string name = t.val; .)
1543
[ IF(IsSize() && !IsDims()) ArrayInitializationModifier<out dimension> ]
1544
[ IF(IsDims()) ArrayNameModifier<out rank> ]
1546
IF (IsObjectCreation()) "As" ObjectCreateExpression<out expr>
1548
if (expr is ObjectCreateExpression) {
1549
type = ((ObjectCreateExpression)expr).CreateType;
1551
type = ((ArrayCreateExpression)expr).CreateType;
1555
[ "As" TypeName<out type> ]
1557
if (type != null && dimension != null) {
1558
if(type.RankSpecifier != null) {
1559
Error("array rank only allowed one time");
1561
for (int i = 0; i < dimension.Count; i++)
1562
dimension[i] = Expression.AddInteger(dimension[i], 1);
1564
type.RankSpecifier = new int[] { dimension.Count - 1 };
1566
rank.Insert(0, dimension.Count - 1);
1567
type.RankSpecifier = (int[])rank.ToArray(typeof(int));
1569
expr = new ArrayCreateExpression(type, dimension);
1571
} else if (type != null && rank != null) {
1572
if(type.RankSpecifier != null) {
1573
Error("array rank only allowed one time");
1575
type.RankSpecifier = (int[])rank.ToArray(typeof(int));
1579
[ "=" VariableInitializer<out expr> ]
1581
(. fieldDeclaration.Add(new VariableDeclaration(name, expr, type)); .)
1585
ArrayInitializationModifier<out List<Expression> arrayModifiers>
1587
arrayModifiers = null;
1589
"(" InitializationRankList<out arrayModifiers> ")"
1593
InitializationRankList<out List<Expression> rank>
1595
rank = new List<Expression>();
1596
Expression expr = null;
1600
(. if (!(expr is PrimitiveExpression) || (expr as PrimitiveExpression).StringValue != "0")
1601
Error("lower bound of array must be zero");
1605
(. if (expr != null) { rank.Add(expr); } .)
1609
(. if (!(expr is PrimitiveExpression) || (expr as PrimitiveExpression).StringValue != "0")
1610
Error("lower bound of array must be zero");
1614
(. if (expr != null) { rank.Add(expr); } .)
1619
VariableInitializer<out Expression initializerExpression>
1621
initializerExpression = null;
1623
Expr<out initializerExpression>
1624
| ArrayInitializer<out initializerExpression>
1628
ArrayInitializer<out Expression outExpr>
1630
Expression expr = null;
1631
ArrayInitializerExpression initializer = new ArrayInitializerExpression();
1635
VariableInitializer<out expr>
1637
if (expr != null) { initializer.CreateExpressions.Add(expr); }
1640
IF (NotFinalComma()) "," VariableInitializer<out expr>
1641
(. if (expr != null) { initializer.CreateExpressions.Add(expr); } .)
1644
"}" (. outExpr = initializer; .)
1647
Charset<out CharsetModifier charsetModifier>
1648
(. charsetModifier = CharsetModifier.None; .) =
1649
| "Ansi" (. charsetModifier = CharsetModifier.ANSI; .)
1650
| "Auto" (. charsetModifier = CharsetModifier.Auto; .)
1651
| "Unicode" (. charsetModifier = CharsetModifier.Unicode; .)
1655
HandlesClause<out List<string> handlesClause>
1657
handlesClause = new List<string>();
1660
"Handles" EventMemberSpecifier<out name> (. handlesClause.Add(name); .)
1661
{ "," EventMemberSpecifier<out name> (. handlesClause.Add(name); .) }
1665
InterfaceBase <out List<TypeReference> bases>
1668
bases = new List<TypeReference>();
1671
TypeName<out type> (. bases.Add(type); .)
1674
TypeName<out type> (. bases.Add(type); .)
1680
TypeImplementsClause<out List<TypeReference> baseInterfaces>
1682
baseInterfaces = new List<TypeReference>();
1683
TypeReference type = null;
1685
"Implements" TypeName<out type>
1687
baseInterfaces.Add(type);
1690
"," TypeName<out type>
1691
(. baseInterfaces.Add(type); .)
1697
ImplementsClause<out List<InterfaceImplementation> baseInterfaces>
1699
baseInterfaces = new List<InterfaceImplementation>();
1700
TypeReference type = null;
1701
string memberName = null;
1704
NonArrayTypeName<out type, false>
1705
(. if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); .)
1706
(. baseInterfaces.Add(new InterfaceImplementation(type, memberName)); .)
1708
NonArrayTypeName<out type, false>
1709
(. if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); .)
1710
(. baseInterfaces.Add(new InterfaceImplementation(type, memberName)); .)
1714
EventMemberSpecifier<out string name>
1715
(. string type; name = String.Empty; .) =
1716
Identifier (. type = t.val; .)
1718
Identifier (. name = type + "." + t.val; .)
1721
Identifier (. name = "MyBase." + t.val; .)
1722
| "Error" (. name = "MyBase.Error"; .)
1726
Expr<out Expression expr>
1728
DisjunctionExpr<out expr>
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; .)
1746
SimpleExpr<out Expression pexpr>
1749
TypeReference type = null;
1750
string name = String.Empty;
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(); .)
1777
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(retExpr, name); .)
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; .)
1787
| "CType" (. castType = CastType.Conversion; .)
1788
| "TryCast" (. castType = CastType.TryCast; .)
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); .)
1797
{ InvocationOrMemberReferenceExpression<ref pexpr> }
1799
/* this form only occurs in WithStatements*/
1800
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(pexpr, name);.)
1801
{ InvocationOrMemberReferenceExpression<ref pexpr> }
1805
InvocationOrMemberReferenceExpression<ref Expression pexpr>
1808
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(pexpr, name); .)
1809
| InvocationExpression<ref pexpr>
1812
InvocationExpression<ref Expression pexpr>
1813
(. List<TypeReference> typeParameters = new List<TypeReference>();
1814
List<Expression> parameters = null;
1815
TypeReference type; .)
1817
"(" (. Point start = t.Location; .)
1819
TypeName<out type> (. if (type != null) typeParameters.Add(type); .)
1823
(. pexpr = new FieldReferenceExpression(GetTypeReferenceExpression(pexpr, typeParameters), t.val); .)
1825
ArgumentList<out parameters>
1827
(. pexpr = new InvocationExpression(pexpr, parameters, typeParameters); .)
1829
| ArgumentList<out parameters>
1831
(. pexpr = new InvocationExpression(pexpr, parameters, typeParameters); .)
1833
(. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .)
1838
CastTarget<out TypeReference type>
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"); .)
1860
DisjunctionExpr<out Expression outExpr>
1863
BinaryOperatorType op = BinaryOperatorType.None;
1865
ConjunctionExpr<out outExpr>
1868
"Or" (. op = BinaryOperatorType.BitwiseOr; .)
1869
| "OrElse" (. op = BinaryOperatorType.LogicalOr; .)
1870
| "Xor" (. op = BinaryOperatorType.ExclusiveOr; .)
1872
ConjunctionExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
1876
ConjunctionExpr<out Expression outExpr>
1879
BinaryOperatorType op = BinaryOperatorType.None;
1881
NotExpr<out outExpr>
1884
"And" (. op = BinaryOperatorType.BitwiseAnd; .)
1885
| "AndAlso" (. op = BinaryOperatorType.LogicalAnd; .)
1887
NotExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
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);
1900
ComparisonExpr<out Expression outExpr>
1903
BinaryOperatorType op = BinaryOperatorType.None;
1905
ShiftExpr<out outExpr>
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; .)
1918
ShiftExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
1922
ShiftExpr<out Expression outExpr>
1925
BinaryOperatorType op = BinaryOperatorType.None;
1927
ConcatenationExpr<out outExpr>
1930
"<<" (. op = BinaryOperatorType.ShiftLeft; .)
1931
| ">>" (. op = BinaryOperatorType.ShiftRight; .)
1933
ConcatenationExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
1937
ConcatenationExpr<out Expression outExpr>
1938
(. Expression expr; .)
1940
AdditiveExpr<out outExpr> { "&" AdditiveExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Concat, expr); .) }
1943
AdditiveExpr<out Expression outExpr>
1946
BinaryOperatorType op = BinaryOperatorType.None;
1948
ModuloExpr<out outExpr>
1951
"+" (. op = BinaryOperatorType.Add; .)
1952
| "-" (. op = BinaryOperatorType.Subtract; .)
1954
ModuloExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
1958
ModuloExpr<out Expression outExpr>
1959
(. Expression expr; .)
1961
IntegerDivisionExpr<out outExpr> { "Mod" IntegerDivisionExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Modulus, expr); .) }
1964
IntegerDivisionExpr<out Expression outExpr>
1965
(. Expression expr; .)
1967
MultiplicativeExpr<out outExpr> { "\\" MultiplicativeExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.DivideInteger, expr); .) }
1970
MultiplicativeExpr<out Expression outExpr>
1973
BinaryOperatorType op = BinaryOperatorType.None;
1975
UnaryExpr<out outExpr>
1978
"*" (. op = BinaryOperatorType.Multiply; .)
1979
| "/" (. op = BinaryOperatorType.Divide; .)
1981
UnaryExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
1985
UnaryExpr<out Expression uExpr>
1988
UnaryOperatorType uop = UnaryOperatorType.None;
1991
{ "+" (. uop = UnaryOperatorType.Plus; isUOp = true; .)
1992
| "-" (. uop = UnaryOperatorType.Minus; isUOp = true; .)
1993
| "*" (. uop = UnaryOperatorType.Star; isUOp = true;.)
1995
ExponentiationExpr<out expr>
1998
uExpr = new UnaryOperatorExpression(expr, uop);
2005
ExponentiationExpr<out Expression outExpr>
2006
(. Expression expr; .)
2008
SimpleExpr<out outExpr> { "^" SimpleExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Power, expr); .) }
2011
ObjectCreateExpression<out Expression oce>
2013
TypeReference type = null;
2014
Expression initializer = null;
2015
List<Expression> arguments = null;
2016
ArrayList dimensions = null;
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> ]
2026
if (initializer == null) {
2027
oce = new ObjectCreateExpression(type, arguments);
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;
2040
ArgumentList<out List<Expression> arguments>
2042
arguments = new List<Expression>();
2043
Expression expr = null;
2046
Argument<out expr> (. if (expr != null) { arguments.Add(expr); } .)
2049
Argument<out expr> (. if (expr != null) { arguments.Add(expr); } .)
2055
Argument<out Expression argumentexpr>
2058
argumentexpr = null;
2061
IF(IsNamedAssign()) Identifier (. name = t.val; .) ":" "=" Expr<out expr>
2063
argumentexpr = new NamedArgumentExpression(name, expr);
2066
Expr<out argumentexpr>
2070
TypeName<out TypeReference typeref>
2071
(. ArrayList rank = null; .)
2073
NonArrayTypeName<out typeref, false>
2074
ArrayTypeModifiers<out rank>
2075
(. if (rank != null && typeref != null) {
2076
typeref.RankSpecifier = (int[])rank.ToArray(typeof(int));
2081
GetTypeTypeName<out TypeReference typeref>
2082
(. ArrayList rank = null; .)
2084
NonArrayTypeName<out typeref, true>
2085
ArrayTypeModifiers<out rank>
2086
(. if (rank != null && typeref != null) {
2087
typeref.RankSpecifier = (int[])rank.ToArray(typeof(int));
2093
NonArrayTypeName<out TypeReference typeref, bool canBeUnbound>
2097
bool isGlobal = false;
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); .)
2108
| "Object" (. typeref = new TypeReference("System.Object"); .)
2109
| PrimitiveTypeName<out name> (. typeref = new TypeReference(name); .)
2112
QualIdentAndTypeArguments<out TypeReference typeref, bool canBeUnbound>
2113
(. string name; typeref = null; .)
2116
(. typeref = new TypeReference(name); .)
2117
[IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.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>
2129
ArrayNameModifier<out ArrayList arrayModifiers>
2131
arrayModifiers = null;
2133
ArrayTypeModifiers<out arrayModifiers>
2138
ArrayTypeModifiers<out ArrayList arrayModifiers>
2140
arrayModifiers = new ArrayList();
2147
arrayModifiers.Add(i);
2152
if(arrayModifiers.Count == 0) {
2153
arrayModifiers = null;
2165
TypeArgumentList<List<TypeReference> typeArguments>
2167
TypeReference typeref;
2169
TypeName<out typeref> (. if (typeref != null) typeArguments.Add(typeref); .)
2172
TypeName<out typeref> (. if (typeref != null) typeArguments.Add(typeref); .)
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;
2183
":" Attribute<out attribute> (. attributes.Add(attribute); .)
2184
{ IF (NotFinalComma()) ["," ("Assembly" | "Module") ":"] Attribute<out attribute> (. attributes.Add(attribute); .)}
2189
AttributeSection section = new AttributeSection(attributeTarget, attributes);
2190
section.StartLocation = startPos;
2191
section.EndLocation = t.EndLocation;
2192
compilationUnit.AddChild(section);
2197
Attribute<out ICSharpCode.NRefactory.Parser.AST.Attribute attribute>
2199
List<Expression> positional = new List<Expression>();
2200
List<NamedArgumentExpression> named = new List<NamedArgumentExpression>();
2204
[ AttributeArguments<positional, named> ]
2205
(. attribute = new ICSharpCode.NRefactory.Parser.AST.Attribute(name, positional, named); .)
2209
AttributeArguments<List<Expression> positional, List<NamedArgumentExpression> named>
2211
bool nameFound = false;
2217
IF (IsNotClosingParenthesis()) (
2219
IF (IsNamedAssign()) (. nameFound = true; .)
2220
IdentifierOrKeyword<out name>
2224
if (expr != null) { if(name == "") positional.Add(expr);
2225
else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
2231
IF (IsNamedAssign()) (. nameFound = true; .)
2232
IdentifierOrKeyword<out name>
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 = ""; }
2246
AttributeSection<out AttributeSection section>
2248
string attributeTarget = "";List<ASTAttribute> attributes = new List<ASTAttribute>();
2249
ASTAttribute attribute;
2252
"<" (. Point startPos = t.Location; .)
2253
[ IF (IsLocalAttrTarget())
2254
( "Event" (. attributeTarget = "event";.)
2255
| "Return" (. attributeTarget = "return";.)
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;
2268
Attribute<out attribute> (. attributes.Add(attribute); .)
2269
{ IF (NotFinalComma()) "," Attribute<out attribute> (. attributes.Add(attribute); .) }
2273
section = new AttributeSection(attributeTarget, attributes);
2274
section.StartLocation = startPos;
2275
section.EndLocation = t.EndLocation;
2280
FormalParameterList<List<ParameterDeclarationExpression> parameter>
2282
ParameterDeclarationExpression p;
2283
AttributeSection section;
2284
List<AttributeSection> attributes = new List<AttributeSection>();
2286
{ AttributeSection<out section> (.attributes.Add(section); .) }
2288
FormalParameter<out p>
2290
bool paramsFound = false;
2291
p.Attributes = attributes;
2295
"," (. if (paramsFound) Error("params array must be at end of parameter list"); .)
2296
{ AttributeSection<out section> (.attributes.Add(section); .) }
2298
FormalParameter <out p> (. p.Attributes = attributes; parameter.Add(p); .)
2304
FormalParameter<out ParameterDeclarationExpression p>
2306
TypeReference type = null;
2307
ParamModifiers mod = new ParamModifiers(this);
2308
Expression expr = null;
2309
p = null;ArrayList arrayModifiers = null;
2311
{ ParameterModifier<mod> }
2312
Identifier (. string parameterName = t.val; .)
2313
[ IF(IsDims()) ArrayTypeModifiers<out arrayModifiers> ]
2314
[ "As" TypeName<out type> ]
2317
if (arrayModifiers != null) {
2318
if (type.RankSpecifier != null) {
2319
Error("array rank only allowed one time");
2321
type.RankSpecifier = (int[])arrayModifiers.ToArray(typeof(int));
2325
type = new TypeReference("System.Object", arrayModifiers == null ? null : (int[])arrayModifiers.ToArray(typeof(int)));
2328
[ "=" Expr<out expr> ]
2331
p = new ParameterDeclarationExpression(type, parameterName, mod.Modifier, expr);
2336
Block<out Statement stmt>
2339
BlockStatement blockStmt = new BlockStatement();
2340
blockStmt.StartLocation = t.Location;
2341
compilationUnit.BlockStart(blockStmt);
2344
IF (IsEndStmtAhead()) "End" EndOfStmt (. compilationUnit.AddChild(new EndStatement()); .)
2345
| Statement EndOfStmt
2346
/* IF (!LeaveBlock()) { }*/
2350
blockStmt.EndLocation = t.EndLocation;
2351
compilationUnit.BlockEnd();
2357
Statement stmt = null;
2358
Point startPos = la.Location;
2359
string label = String.Empty;
2363
| IF (IsLabel()) LabelName<out label>
2365
compilationUnit.AddChild(new LabelStatement(t.val));
2368
| EmbeddedStatement<out stmt> (. compilationUnit.AddChild(stmt); .)
2369
| LocalDeclarationStatement<out stmt> (. compilationUnit.AddChild(stmt); .)
2373
stmt.StartLocation = startPos;
2374
stmt.EndLocation = t.Location;
2380
LocalDeclarationStatement<out Statement statement>
2382
Modifiers m = new Modifiers();
2383
LocalVariableDeclaration localVariableDeclaration;
2384
bool dimfound = false;
2386
/* this differs from the spec: dim static x compiles with vbc. */
2388
"Const" (. m.Add(Modifier.Const, t.Location); .)
2389
| "Static" (. m.Add(Modifier.Static, t.Location); .)
2390
| "Dim" (. dimfound = true; .)
2393
if(dimfound && (m.Modifier & Modifier.Const) != 0) {
2394
Error("Dim is not allowed on constants.");
2397
if(m.isNone && dimfound == false) {
2398
Error("Const, Dim or Static expected");
2401
localVariableDeclaration = new LocalVariableDeclaration(m.Modifier);
2402
localVariableDeclaration.StartLocation = t.Location;
2404
VariableDeclarator<localVariableDeclaration.Variables>
2405
{ "," VariableDeclarator<localVariableDeclaration.Variables> }
2407
statement = localVariableDeclaration;
2411
EmbeddedStatement<out Statement statement>
2413
Statement embeddedStatement = null;
2415
Expression expr = null;
2416
string name = String.Empty;
2417
List<Expression> p = null;
2419
"Exit" (. ExitType exitType = ExitType.None; .)
2421
"Sub" (. exitType = ExitType.Sub; .)
2423
"Function" (. exitType = ExitType.Function; .)
2425
"Property" (. exitType = ExitType.Property; .)
2427
"Do" (. exitType = ExitType.Do; .)
2429
"For" (. exitType = ExitType.For; .)
2431
"Try" (. exitType = ExitType.Try; .)
2433
"While" (. exitType = ExitType.While; .)
2435
"Select" (. exitType = ExitType.Select; .)
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); .)
2441
"Throw" [ Expr<out expr> ] (. statement = new ThrowStatement(expr); .)
2443
"Return" [ Expr<out expr> ] (. statement = new ReturnStatement(expr); .)
2445
"SyncLock" Expr<out expr> EndOfStmt Block<out embeddedStatement>
2446
"End" "SyncLock" (. statement = new LockStatement(expr, embeddedStatement); .)
2448
"RaiseEvent" Identifier (. name = t.val; .)
2449
[ "(" [ ArgumentList<out p> ] ")" ]
2450
(. statement = new RaiseEventStatement(name, p); .)
2452
WithStatement<out statement>
2454
"AddHandler" (. Expression handlerExpr = null; .)
2455
Expr<out expr> "," Expr<out handlerExpr>
2457
statement = new AddHandlerStatement(expr, handlerExpr);
2460
"RemoveHandler" (. Expression handlerExpr = null; .)
2461
Expr<out expr> "," Expr<out handlerExpr>
2463
statement = new RemoveHandlerStatement(expr, handlerExpr);
2466
"While" Expr<out expr> EndOfStmt
2467
Block<out embeddedStatement> "End" "While"
2469
statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);
2474
ConditionType conditionType = ConditionType.None;
2477
WhileOrUntil<out conditionType> Expr<out expr> EndOfStmt
2478
Block<out embeddedStatement>
2481
statement = new DoLoopStatement(expr,
2483
conditionType == ConditionType.While ? ConditionType.DoWhile : conditionType,
2484
ConditionPosition.Start);
2488
Block<out embeddedStatement>
2489
"Loop" [WhileOrUntil<out conditionType> Expr<out expr>]
2491
statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End);
2496
Expression group = null;
2497
TypeReference typeReference;
2499
Point startLocation = t.Location;
2503
"Each" LoopControlVariable<out typeReference, out typeName>
2504
"In" Expr<out group> EndOfStmt
2505
Block<out embeddedStatement>
2506
"Next" [ Expr<out expr> ]
2508
statement = new ForeachStatement(typeReference,
2513
statement.StartLocation = startLocation;
2514
statement.EndLocation = t.EndLocation;
2519
Expression start = null;
2520
Expression end = null;
2521
Expression step = null;
2522
Expression nextExpr = null;List<Expression> nextExpressions = null;
2524
LoopControlVariable<out typeReference, out typeName>
2525
"=" Expr<out start> "To" Expr<out end> [ "Step" Expr<out step> ]
2526
EndOfStmt Block<out embeddedStatement>
2529
Expr<out nextExpr> (. nextExpressions = new List<Expression>(); nextExpressions.Add(nextExpr); .)
2530
{ "," Expr<out nextExpr> (. nextExpressions.Add(nextExpr); .) }
2533
statement = new ForNextStatement(typeReference, typeName, start, end, step, embeddedStatement, nextExpressions);
2537
"Error" Expr<out expr> (. statement = new ErrorStatement(expr); .)
2539
"ReDim" (. bool isPreserve = false; .) [ "Preserve" (. isPreserve = true; .) ]
2542
ReDimStatement reDimStatement = new ReDimStatement(isPreserve);
2543
statement = reDimStatement;
2544
InvocationExpression redimClause = expr as InvocationExpression;
2545
if (redimClause != null) { reDimStatement.ReDimClauses.Add(redimClause); }
2547
{ "," Expr<out expr>
2548
(. redimClause = expr as InvocationExpression; .)
2549
(. if (redimClause != null) { reDimStatement.ReDimClauses.Add(redimClause); } .)
2554
(.List<Expression> arrays = new List<Expression>();
2555
if (expr != null) { arrays.Add(expr);}
2556
EraseStatement eraseStatement = new EraseStatement(arrays);
2559
{ "," Expr<out expr> (. if (expr != null) { arrays.Add(expr); }.) }
2560
(. statement = eraseStatement; .)
2562
"Stop" (. statement = new StopStatement(); .)
2564
"If" Expr<out expr> [ "Then" ]
2566
IF (IsEndStmtAhead()) "End" (. statement = new IfElseStatement(expr, new EndStatement()); .)
2568
/* multiline if statement */
2569
EndOfStmt Block<out embeddedStatement>
2571
IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement);
2575
IF(IsElseIf()) "Else" "If"
2578
(. Expression condition = null; Statement block = null; .)
2579
Expr<out condition> [ "Then"] EndOfStmt
2582
ifStatement.ElseIfSections.Add(new ElseIfSection(condition, block));
2587
Block<out embeddedStatement>
2589
ifStatement.FalseStatement.Add(embeddedStatement);
2593
statement = ifStatement;
2595
| /* singleline if statement */
2596
EmbeddedStatement<out embeddedStatement>
2598
IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement);
2600
{ ":" EmbeddedStatement<out embeddedStatement> (. ifStatement.TrueStatement.Add(embeddedStatement); .) }
2602
"Else" [ EmbeddedStatement<out embeddedStatement> ]
2604
ifStatement.FalseStatement.Add(embeddedStatement);
2607
":" EmbeddedStatement<out embeddedStatement>
2608
(. ifStatement.FalseStatement.Add(embeddedStatement); .)
2611
(. statement = ifStatement; .)
2614
"Select" [ "Case" ] Expr<out expr> EndOfStmt
2615
(.List<SwitchSection> selectSections = new List<SwitchSection>();
2616
Statement block = null;
2619
(.List<CaseLabel> caseClauses = null; .)
2620
"Case" CaseClauses<out caseClauses> [ IF(IsNotStatementSeparator()) ":" ] EndOfStmt
2622
SwitchSection selectSection = new SwitchSection(caseClauses);
2626
selectSection.Children = block.Children;
2627
selectSections.Add(selectSection);
2630
(. statement = new SwitchStatement(expr, selectSections); .)
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 */
2640
Expression val = null;
2641
AssignmentOperatorType op;
2643
bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus ||
2644
la.kind == Tokens.Not || la.kind == Tokens.Times;
2646
SimpleExpr<out expr>
2648
AssignmentOperator<out op> Expr<out val> (. expr = new AssignmentExpression(expr, op, val); .)
2649
| (. if (mustBeAssignment) Error("error in assignment."); .)
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);
2657
statement = new StatementExpression(expr);
2659
| "Call" SimpleExpr<out expr> (. statement = new StatementExpression(expr); .)
2660
| "Using" Identifier (.
2661
string resourcename = t.val, typeName;
2662
Statement resourceAquisition = null, block = null;
2664
"New" Qualident<out typeName>
2665
(. List<Expression> initializer = null; .)
2666
["(" [ ArgumentList<out initializer> ] ")" ]
2668
resourceAquisition = new LocalVariableDeclaration(new VariableDeclaration(resourcename, new ArrayInitializerExpression(initializer), new TypeReference(typeName)));
2671
Qualident<out typeName> "=" Expr<out expr>
2673
resourceAquisition = new LocalVariableDeclaration(new VariableDeclaration(resourcename, expr, new TypeReference(typeName)));
2678
(. statement = new UsingStatement(resourceAquisition, block); .)
2683
LoopControlVariable<out TypeReference type, out string name>
2684
(.ArrayList arrayModifiers = null;
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."); } .) ]
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));
2699
if (arrayModifiers != null) {
2700
type = new TypeReference("Integer", (int[])arrayModifiers.ToArray(typeof(int)));
2702
type = new TypeReference("Integer");
2709
OnErrorStatement<out OnErrorStatement stmt>
2712
GotoStatement goToStatement = null;
2717
IF(IsNegativeLabelName())"GoTo" "-" LiteralInteger
2719
long intLabel = Int64.Parse(t.val);
2721
Error("invalid label in on error statement.");
2723
stmt = new OnErrorStatement(new GotoStatement((intLabel * -1).ToString()));
2725
| GotoStatement<out goToStatement>
2727
string val = goToStatement.Label;
2729
// if value is numeric, make sure that is 0
2731
long intLabel = Int64.Parse(val);
2733
Error("invalid label in on error statement.");
2737
stmt = new OnErrorStatement(goToStatement);
2741
stmt = new OnErrorStatement(new ResumeStatement(true));
2747
GotoStatement<out ICSharpCode.NRefactory.Parser.AST.GotoStatement goToStatement>
2749
string label = String.Empty;
2752
"GoTo" LabelName<out label>
2754
goToStatement = new ICSharpCode.NRefactory.Parser.AST.GotoStatement(label);
2759
LabelName<out string name>
2761
name = String.Empty;
2763
Identifier (. name = t.val; .)
2764
| LiteralInteger (. name = t.val; .)
2769
ReDimClause<out ReDimClause clause>
2771
Expression initializer = null;
2772
Expression arrayInitializer = null;
2775
[Expr<out initializer> "." ]
2778
clause = new ReDimClause(name);
2780
"(" Expr<out initializer>
2782
clause.Initializers.Add(initializer);
2784
{ "," Expr<out initializer> (. clause.Initializers.Add(initializer); .) }
2786
[ ArrayInitializer<out arrayInitializer> ]
2791
ResumeStatement<out ResumeStatement resumeStatement>
2793
resumeStatement = null;
2794
string label = String.Empty;
2797
"Resume" "Next" (. resumeStatement = new ResumeStatement(true); .)
2798
| "Resume" [ LabelName<out label> ] (. resumeStatement = new ResumeStatement(label); .)
2802
CaseClauses<out List<CaseLabel> caseClauses>
2804
caseClauses = new List<CaseLabel>();
2805
CaseLabel caseClause = null;
2807
CaseClause<out caseClause> (. if (caseClause != null) { caseClauses.Add(caseClause); } .)
2808
{ "," CaseClause<out caseClause> (. if (caseClause != null) { caseClauses.Add(caseClause); } .) }
2812
CaseClause<out CaseLabel caseClause>
2814
Expression expr = null;
2815
Expression sexpr = null;
2816
BinaryOperatorType op = BinaryOperatorType.None;
2820
(. caseClause = new CaseLabel(); .)
2824
"<" (. op = BinaryOperatorType.LessThan; .)
2825
| ">" (. op = BinaryOperatorType.GreaterThan; .)
2826
| "<=" (. op = BinaryOperatorType.LessThanOrEqual; .)
2827
| ">=" (. op = BinaryOperatorType.GreaterThanOrEqual; .)
2828
| "=" (. op = BinaryOperatorType.Equality; .)
2829
| "<>" (. op = BinaryOperatorType.InEquality; .)
2833
caseClause = new CaseLabel(op, expr);
2835
| Expr<out expr> [ "To" Expr<out sexpr> ]
2837
caseClause = new CaseLabel(expr, sexpr);
2842
WhileOrUntil<out ConditionType conditionType>
2843
(. conditionType = ConditionType.None; .) =
2844
"While" (. conditionType = ConditionType.While; .)
2845
| "Until" (. conditionType = ConditionType.Until; .)
2849
WithStatement<out Statement withStatement>
2851
Statement blockStmt = null;
2852
Expression expr = null;
2854
"With" (. Point start = t.Location; .)
2855
Expr<out expr> EndOfStmt
2857
withStatement = new WithStatement(expr);
2858
withStatement.StartLocation = start;
2859
withStatements.Push(withStatement);
2861
Block<out blockStmt>
2863
((WithStatement)withStatement).Body = (BlockStatement)blockStmt;
2864
withStatements.Pop();
2867
(. withStatement.EndLocation = t.Location; .)
2871
TryStatement<out Statement tryStatement>
2873
Statement blockStmt = null, finallyStmt = null;List<CatchClause> catchClauses = null;
2876
Block<out blockStmt>
2877
[CatchClauses<out catchClauses>]
2878
["Finally" EndOfStmt Block<out finallyStmt> ]
2881
tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt);
2886
CatchClauses<out List<CatchClause> catchClauses>
2888
catchClauses = new List<CatchClause>();
2889
TypeReference type = null;
2890
Statement blockStmt = null;
2891
Expression expr = null;
2892
string name = String.Empty;
2896
[ Identifier (. name = t.val; .) ["As" TypeName<out type>] ]
2897
[ "When" Expr<out expr> ]
2899
Block<out blockStmt>
2900
(. catchClauses.Add(new CatchClause(type, name, blockStmt, expr)); .)
2905
Qualident<out string qualident>
2908
qualidentBuilder.Length = 0;
2911
Identifier (. qualidentBuilder.Append(t.val); .)
2912
{ IF (DotAndIdentOrKw()) "." IdentifierOrKeyword<out name> (. qualidentBuilder.Append('.'); qualidentBuilder.Append(name); .) }
2914
(. qualident = qualidentBuilder.ToString(); .)
2917
/* This production handles pseudo keywords that are needed in the grammar */
2933
IdentifierOrKeyword<out string name>
2935
(. lexer.NextToken(); name = t.val; .)
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"; .)
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); .)
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); .)
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);.)