.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

2917 lines
82 KiB

using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.Parser.VB;
using ASTAttribute = ICSharpCode.NRefactory.Ast.Attribute;
COMPILER VBNET
/* START AUTOGENERATED TOKENS SECTION */
TOKENS
/* ----- terminal classes ----- */
/* EOF is 0 */
EOL
ident
LiteralString
LiteralCharacter
LiteralInteger
LiteralDouble
LiteralSingle
LiteralDecimal
LiteralDate
/* ----- special character ----- */
"."
"="
","
":"
"+"
"-"
"*"
"/"
"\\"
"&"
"^"
"?"
"{"
"}"
"("
")"
">"
"<"
"<>"
">="
"<="
"<<"
">>"
"+="
"^="
"-="
"*="
"/="
"\\="
"<<="
">>="
"&="
/* ----- keywords ----- */
"AddHandler"
"AddressOf"
"Alias"
"And"
"AndAlso"
"Ansi"
"As"
"Assembly"
"Auto"
"Binary"
"Boolean"
"ByRef"
"Byte"
"ByVal"
"Call"
"Case"
"Catch"
"CBool"
"CByte"
"CChar"
"CDate"
"CDbl"
"CDec"
"Char"
"CInt"
"Class"
"CLng"
"CObj"
"Compare"
"Const"
"CShort"
"CSng"
"CStr"
"CType"
"Date"
"Decimal"
"Declare"
"Default"
"Delegate"
"Dim"
"DirectCast"
"Do"
"Double"
"Each"
"Else"
"ElseIf"
"End"
"EndIf"
"Enum"
"Erase"
"Error"
"Event"
"Exit"
"Explicit"
"False"
"Finally"
"For"
"Friend"
"Function"
"Get"
"GetType"
"GoSub"
"GoTo"
"Handles"
"If"
"Implements"
"Imports"
"In"
"Inherits"
"Integer"
"Interface"
"Is"
"Let"
"Lib"
"Like"
"Long"
"Loop"
"Me"
"Mod"
"Module"
"MustInherit"
"MustOverride"
"MyBase"
"MyClass"
"Namespace"
"New"
"Next"
"Not"
"Nothing"
"NotInheritable"
"NotOverridable"
"Object"
"Off"
"On"
"Option"
"Optional"
"Or"
"OrElse"
"Overloads"
"Overridable"
"Overrides"
"ParamArray"
"Preserve"
"Private"
"Property"
"Protected"
"Public"
"RaiseEvent"
"ReadOnly"
"ReDim"
"RemoveHandler"
"Resume"
"Return"
"Select"
"Set"
"Shadows"
"Shared"
"Short"
"Single"
"Static"
"Step"
"Stop"
"Strict"
"String"
"Structure"
"Sub"
"SyncLock"
"Text"
"Then"
"Throw"
"To"
"True"
"Try"
"TypeOf"
"Unicode"
"Until"
"Variant"
"Wend"
"When"
"While"
"With"
"WithEvents"
"WriteOnly"
"Xor"
"Rem"
"Continue"
"Operator"
"Using"
"IsNot"
"SByte"
"UInteger"
"ULong"
"UShort"
"CSByte"
"CUShort"
"CUInt"
"CULng"
"Global"
"TryCast"
"Of"
"Narrowing"
"Widening"
"Partial"
"Custom"
/* END AUTOGENERATED TOKENS SECTION */
PRODUCTIONS
VBNET
(.
lexer.NextToken(); // get the first token
compilationUnit = new CompilationUnit();
.) =
{ EOL }
{ OptionStmt }
{ ImportsStmt}
{ IF (IsGlobalAttrTarget()) GlobalAttributeSection }
{ NamespaceMemberDecl }
EOF
.
OptionStmt (. INode node = null; bool val = true; .) =
"Option" (. Location startPos = t.Location; .)
(
"Explicit" [ OptionValue<ref val> ]
(. node = new OptionDeclaration(OptionType.Explicit, val); .)
|
"Strict" [ OptionValue<ref val> ]
(. node = new OptionDeclaration(OptionType.Strict, val); .)
|
"Compare" ( "Binary" (. node = new OptionDeclaration(OptionType.CompareBinary, val); .)
| "Text" (. node = new OptionDeclaration(OptionType.CompareText, val); .)
)
)
EndOfStmt
(.
if (node != null) {
node.StartLocation = startPos;
node.EndLocation = t.Location;
compilationUnit.AddChild(node);
}
.)
.
OptionValue<ref bool val> =
(
"On" (. val = true; .)
|
"Off" (. val = false; .)
)
.
EndOfStmt =
EOL
|
":" [ EOL ]
.
ImportsStmt
(.List<Using> usings = new List<Using>();
.) =
"Imports"
(.
Location startPos = t.Location;
Using u;
.)
ImportClause<out u> (. if (u != null) { usings.Add(u); } .)
{
"," ImportClause<out u> (. if (u != null) { usings.Add(u); } .)
}
EndOfStmt
(.
UsingDeclaration usingDeclaration = new UsingDeclaration(usings);
usingDeclaration.StartLocation = startPos;
usingDeclaration.EndLocation = t.Location;
compilationUnit.AddChild(usingDeclaration);
.)
.
ImportClause<out Using u>
(.
string qualident = null;
TypeReference aliasedType = null;
u = null;
.) =
Qualident<out qualident>
[ "=" TypeName<out aliasedType> ]
(.
if (qualident != null && qualident.Length > 0) {
if (aliasedType != null) {
u = new Using(qualident, aliasedType);
} else {
u = new Using(qualident);
}
}
.)
.
/* 6.4.2 */
NamespaceMemberDecl
(.
ModifierList m = new ModifierList();
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
string qualident;
.) =
"Namespace"
(.
Location startPos = t.Location;
.)
Qualident<out qualident>
(.
INode node = new NamespaceDeclaration(qualident);
node.StartLocation = startPos;
compilationUnit.AddChild(node);
compilationUnit.BlockStart(node);
.)
EOL
NamespaceBody
(.
node.EndLocation = t.Location;
compilationUnit.BlockEnd();
.)
|
{ AttributeSection<out section> (. attributes.Add(section); .) }
{ TypeModifier<m> } NonModuleDeclaration<m, attributes>
.
/* 4.9.1 */
TypeParameterList<List<TemplateDefinition> templates>
(.
TemplateDefinition template;
.) =
[
IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
"(" "Of" TypeParameter<out template>
(.
if (template != null) templates.Add(template);
.)
{
"," TypeParameter<out template>
(.
if (template != null) templates.Add(template);
.)
}
")"
]
.
/* 4.9.1 */
TypeParameter<out TemplateDefinition template>
=
Identifier (. template = new TemplateDefinition(t.val, null); .)
[TypeParameterConstraints<template>]
.
/* 4.9.2 */
TypeParameterConstraints<TemplateDefinition template>
(.
TypeReference constraint;
.)
=
"As"
(
"{"
TypeParameterConstraint<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
{
","
TypeParameterConstraint<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
}
"}"
| TypeParameterConstraint<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
)
.
TypeParameterConstraint<out TypeReference constraint>
(. constraint = null; .)
= "Class" (. constraint = TypeReference.ClassConstraint; .)
| "Structure" (. constraint = TypeReference.StructConstraint; .)
| "New" (. constraint = TypeReference.NewConstraint; .)
| TypeName<out constraint>
.
/* 6.4.2 */
NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
(.
TypeReference typeRef = null;
List<TypeReference> baseInterfaces = null;
.) =
(. m.Check(Modifiers.Classes); .)
/* Spec, 7.5 */
"Class"
(. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
newType.StartLocation = t.Location;
compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType);
newType.Type = ClassType.Class;
.)
Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates>
EndOfStmt
(. newType.BodyStartLocation = t.Location; .)
[ ClassBaseType<out typeRef> (. newType.BaseTypes.Add(typeRef); .) ]
{ TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
ClassBody<newType>
"End" "Class" (. newType.EndLocation = t.EndLocation; .)
EOL
(.
compilationUnit.BlockEnd();
.)
| "Module"
(.
m.Check(Modifiers.VBModules);
TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType);
newType.StartLocation = m.GetDeclarationLocation(t.Location);
newType.Type = ClassType.Module;
.)
Identifier (. newType.Name = t.val; .)
EOL
(. newType.BodyStartLocation = t.Location; .)
ModuleBody<newType>
(.
compilationUnit.BlockEnd();
.)
| "Structure"
(.
m.Check(Modifiers.VBStructures);
TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType);
newType.StartLocation = m.GetDeclarationLocation(t.Location);
newType.Type = ClassType.Struct;
.)
Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates>
EOL
(. newType.BodyStartLocation = t.Location; .)
{ TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces);.) }
StructureBody<newType>
(.
compilationUnit.BlockEnd();
.)
| /* 7.4 */
"Enum"
(.
m.Check(Modifiers.VBEnums);
TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
newType.StartLocation = m.GetDeclarationLocation(t.Location);
compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType);
newType.Type = ClassType.Enum;
.)
Identifier (. newType.Name = t.val; .)
[ "As" NonArrayTypeName<out typeRef, false> (. newType.BaseTypes.Add(typeRef); .) ]
EOL
(. newType.BodyStartLocation = t.Location; .)
EnumBody<newType>
(.
compilationUnit.BlockEnd();
.)
| /* 7.8 */
"Interface"
(.
m.Check(Modifiers.VBInterfacs);
TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
newType.StartLocation = m.GetDeclarationLocation(t.Location);
compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType);
newType.Type = ClassType.Interface;
.)
Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates>
EndOfStmt
(. newType.BodyStartLocation = t.Location; .)
{ InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
InterfaceBody<newType>
(.
compilationUnit.BlockEnd();
.)
| /* 7.10 */
"Delegate"
(.
m.Check(Modifiers.VBDelegates);
DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes);
delegateDeclr.ReturnType = new TypeReference("", "System.Void");
delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location);
List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
.)
(
"Sub" Identifier (. delegateDeclr.Name = t.val; .)
TypeParameterList<delegateDeclr.Templates>
[ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ]
|
"Function" Identifier (. delegateDeclr.Name = t.val; .)
TypeParameterList<delegateDeclr.Templates>
[ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ]
[ "As" (. TypeReference type; .) TypeName<out type> (. delegateDeclr.ReturnType = type; .)]
)
(. delegateDeclr.EndLocation = t.EndLocation; .)
EOL
(.
compilationUnit.AddChild(delegateDeclr);
.)
.
NamespaceBody =
{ NamespaceMemberDecl }
"End" "Namespace"
EOL
.
ClassBody<TypeDeclaration newType>
(. AttributeSection section; .) =
{
(.List<AttributeSection> attributes = new List<AttributeSection>();
ModifierList m = new ModifierList();
.)
{ AttributeSection<out section> (. attributes.Add(section); .) }
{ MemberModifier<m> }
ClassMemberDecl<m, attributes>
}
.
StructureBody<TypeDeclaration newType>
(. AttributeSection section; .) =
{
(.List<AttributeSection> attributes = new List<AttributeSection>();
ModifierList m = new ModifierList();
.)
{ AttributeSection<out section> (. attributes.Add(section); .) }
{ MemberModifier<m> }
StructureMemberDecl<m, attributes>
}
"End" "Structure" (. newType.EndLocation = t.EndLocation; .)
EOL
.
/* 7.7.1 */
ModuleBody<TypeDeclaration newType>
(. AttributeSection section; .) =
{
(.List<AttributeSection> attributes = new List<AttributeSection>();
ModifierList m = new ModifierList();
.)
{ AttributeSection<out section> (. attributes.Add(section); .) }
{ MemberModifier<m> }
ClassMemberDecl<m, attributes>
}
"End" "Module" (. newType.EndLocation = t.EndLocation; .)
EOL
.
EnumBody<TypeDeclaration newType>
(. FieldDeclaration f; .) =
{
EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
}
"End" "Enum" (. newType.EndLocation = t.EndLocation; .)
EOL
.
InterfaceBody<TypeDeclaration newType> =
{ InterfaceMemberDecl }
"End" "Interface" (. newType.EndLocation = t.EndLocation; .)
EOL
.
/* The information provided in the spec about */
/* interface declarations is wrong */
InterfaceMemberDecl
(.
TypeReference type =null;
List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
List<TemplateDefinition> templates = new List<TemplateDefinition>();
AttributeSection section, returnTypeAttributeSection = null;
ModifierList mod = new ModifierList();
List<AttributeSection> attributes = new List<AttributeSection>();
string name;
.) =
{ AttributeSection<out section> (. attributes.Add(section); .) }
/* this is different to c#: not only the Shadows modifier is allowed, */
/* also member modifiers like overloads etc. */
{ MemberModifier<mod> }
(
"Event"
(.
mod.Check(Modifiers.VBInterfaceEvents);
Location startLocation = t.Location;
.)
Identifier (. name = t.val; .)
[ "(" [ FormalParameterList<p> ] ")" ]
[ "As" TypeName<out type> ]
EOL
(.
EventDeclaration ed = new EventDeclaration {
Name = name, TypeReference = type, Modifier = mod.Modifier,
Parameters = p, Attributes = attributes,
StartLocation = startLocation, EndLocation = t.EndLocation
};
compilationUnit.AddChild(ed);
.)
|
"Sub"
(.
Location startLocation = t.Location;
mod.Check(Modifiers.VBInterfaceMethods);
.)
Identifier (. name = t.val; .)
TypeParameterList<templates>
[ "(" [ FormalParameterList<p> ] ")" ]
EOL
(.
MethodDeclaration md = new MethodDeclaration {
Name = name,
Modifier = mod.Modifier,
Parameters = p,
Attributes = attributes,
TypeReference = new TypeReference("", "System.Void"),
StartLocation = startLocation,
EndLocation = t.EndLocation,
Templates = templates
};
compilationUnit.AddChild(md);
.)
|
"Function"
(.
mod.Check(Modifiers.VBInterfaceMethods);
Location startLocation = t.Location;
.)
Identifier (. name = t.val; .)
TypeParameterList<templates>
[ "(" [ FormalParameterList<p> ] ")" ]
[ "As" { AttributeSection<out returnTypeAttributeSection> } TypeName<out type> ]
(.
if(type == null) {
type = new TypeReference("System.Object");
}
MethodDeclaration md = new MethodDeclaration {
Name = name, Modifier = mod.Modifier,
TypeReference = type, Parameters = p, Attributes = attributes
};
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
md.Attributes.Add(returnTypeAttributeSection);
}
md.StartLocation = startLocation;
md.EndLocation = t.EndLocation;
md.Templates = templates;
compilationUnit.AddChild(md);
.)
EOL
|
"Property"
(.
Location startLocation = t.Location;
mod.Check(Modifiers.VBInterfaceProperties);
.)
Identifier (. name = t.val; .)
[ "(" [ FormalParameterList<p> ] ")" ]
[ "As" TypeName<out type> ]
(.
if(type == null) {
type = new TypeReference("System.Object");
}
.)
EOL
(.
PropertyDeclaration pd = new PropertyDeclaration(name, type, mod.Modifier, attributes);
pd.Parameters = p;
pd.EndLocation = t.EndLocation;
pd.StartLocation = startLocation;
compilationUnit.AddChild(pd);
.)
)
| /* inner type declarations */
NonModuleDeclaration<mod, attributes>
.
/* 7.4.1 */
EnumMemberDecl<out FieldDeclaration f>
(.
Expression expr = null;List<AttributeSection> attributes = new List<AttributeSection>();
AttributeSection section = null;
VariableDeclaration varDecl = null;
.) =
{ AttributeSection<out section> (. attributes.Add(section); .) }
Identifier
(.
f = new FieldDeclaration(attributes);
varDecl = new VariableDeclaration(t.val);
f.Fields.Add(varDecl);
f.StartLocation = varDecl.StartLocation = t.Location;
.)
[ "=" Expr<out expr> (. varDecl.Initializer = expr; .) ]
EOL
.
ClassMemberDecl<ModifierList m, List<AttributeSection> attributes> =
StructureMemberDecl<m, attributes>
.
ClassBaseType<out TypeReference typeRef>
(.
typeRef = null;
.) =
"Inherits"
TypeName<out typeRef>
EndOfStmt
.
/* 7.6.1 */
StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
(.
TypeReference type = null;
List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
Statement stmt = null;
List<VariableDeclaration> variableDeclarators = new List<VariableDeclaration>();
List<TemplateDefinition> templates = new List<TemplateDefinition>();
.)
=
NonModuleDeclaration<m, attributes>
| /* 9.2.1 */
"Sub"
(.
Location startPos = t.Location;
.)
(
(.
string name = String.Empty;
MethodDeclaration methodDeclaration; List<string> handlesClause = null;
List<InterfaceImplementation> implementsClause = null;
.)
Identifier
(.
name = t.val;
m.Check(Modifiers.VBMethods);
.)
TypeParameterList<templates>
[ "(" [ FormalParameterList<p> ] ")" ]
[
(
ImplementsClause<out implementsClause>
|
HandlesClause<out handlesClause>
)
]
(. Location endLocation = t.EndLocation; .)
EOL
(
/* abstract methods without a body */
IF(IsMustOverride(m))
(.
methodDeclaration = new MethodDeclaration {
Name = name, Modifier = m.Modifier, Parameters = p, Attributes = attributes,
StartLocation = m.GetDeclarationLocation(startPos), EndLocation = endLocation,
TypeReference = new TypeReference("", "System.Void"),
Templates = templates,
HandlesClause = handlesClause,
InterfaceImplementations = implementsClause
};
compilationUnit.AddChild(methodDeclaration);
.)
|
(.
methodDeclaration = new MethodDeclaration {
Name = name, Modifier = m.Modifier, Parameters = p, Attributes = attributes,
StartLocation = m.GetDeclarationLocation(startPos), EndLocation = endLocation,
TypeReference = new TypeReference("", "System.Void"),
Templates = templates,
HandlesClause = handlesClause,
InterfaceImplementations = implementsClause
};
compilationUnit.AddChild(methodDeclaration);
.)
(. if (ParseMethodBodies) { .)
Block<out stmt>
"End" "Sub"
(. } else {
// don't parse method body
lexer.SkipCurrentBlock(Tokens.Sub); stmt = new BlockStatement();
}
.)
(. methodDeclaration.Body = (BlockStatement)stmt; .)
(. methodDeclaration.Body.EndLocation = t.EndLocation; .) EOL
)
/* 9.3 */
| "New" [ "(" [ FormalParameterList<p> ] ")" ]
(. m.Check(Modifiers.Constructors); .)
(. Location constructorEndLocation = t.EndLocation; .)
EOL
(. if (ParseMethodBodies) { .)
Block<out stmt>
"End" "Sub"
(. } else {
// don't parse method body
lexer.SkipCurrentBlock(Tokens.Sub); stmt = new BlockStatement();
}
.)
(. Location endLocation = t.EndLocation; .) EOL
(.
ConstructorDeclaration cd = new ConstructorDeclaration("New", m.Modifier, p, attributes);
cd.StartLocation = m.GetDeclarationLocation(startPos);
cd.EndLocation = constructorEndLocation;
cd.Body = (BlockStatement)stmt;
cd.Body.EndLocation = endLocation;
compilationUnit.AddChild(cd);
.)
)
|
/* 9.2.1 */
"Function"
(.
m.Check(Modifiers.VBMethods);
string name = String.Empty;
Location startPos = t.Location;
MethodDeclaration methodDeclaration;List<string> handlesClause = null;
List<InterfaceImplementation> implementsClause = null;
AttributeSection returnTypeAttributeSection = null;
.)
Identifier (. name = t.val; .)
TypeParameterList<templates>
[ "(" [ FormalParameterList<p> ] ")" ]
["As" { AttributeSection<out returnTypeAttributeSection> } TypeName<out type> ]
(.
if(type == null) {
type = new TypeReference("System.Object");
}
.)
[
(
ImplementsClause<out implementsClause>
|
HandlesClause<out handlesClause>
)
]
EOL
(
/* abstract methods without a body */
IF(IsMustOverride(m))
(.
methodDeclaration = new MethodDeclaration {
Name = name, Modifier = m.Modifier, TypeReference = type,
Parameters = p, Attributes = attributes,
StartLocation = m.GetDeclarationLocation(startPos),
EndLocation = t.EndLocation,
HandlesClause = handlesClause,
Templates = templates,
InterfaceImplementations = implementsClause
};
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);
}
compilationUnit.AddChild(methodDeclaration);
.)
|
(.
methodDeclaration = new MethodDeclaration {
Name = name, Modifier = m.Modifier, TypeReference = type,
Parameters = p, Attributes = attributes,
StartLocation = m.GetDeclarationLocation(startPos),
EndLocation = t.EndLocation,
Templates = templates,
HandlesClause = handlesClause,
InterfaceImplementations = implementsClause
};
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);
}
compilationUnit.AddChild(methodDeclaration);
if (ParseMethodBodies) { .)
Block<out stmt>
"End" "Function"
(. } else {
// don't parse method body
lexer.SkipCurrentBlock(Tokens.Function); stmt = new BlockStatement();
}
methodDeclaration.Body = (BlockStatement)stmt;
methodDeclaration.Body.StartLocation = methodDeclaration.EndLocation;
methodDeclaration.Body.EndLocation = t.EndLocation;
.)
EOL
)
|
/* 9.2.2. */
"Declare"
(.
m.Check(Modifiers.VBExternalMethods);
Location startPos = t.Location;
CharsetModifier charsetModifer = CharsetModifier.None;
string library = String.Empty;
string alias = null;
string name = String.Empty;
.)
[Charset<out charsetModifer> ]
(
"Sub"
Identifier (. name = t.val; .)
"Lib" LiteralString (. library = t.literalValue as string; .)
["Alias" LiteralString (. alias = t.literalValue as string; .)]
[ "(" [ FormalParameterList<p> ] ")" ]
EOL
(.
DeclareDeclaration declareDeclaration = new DeclareDeclaration(name, m.Modifier, null, p, attributes, library, alias, charsetModifer);
declareDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
declareDeclaration.EndLocation = t.EndLocation;
compilationUnit.AddChild(declareDeclaration);
.)
|
"Function"
Identifier (. name = t.val; .)
"Lib" LiteralString (. library = t.literalValue as string; .)
["Alias" LiteralString (. alias = t.literalValue as string; .)]
[ "(" [ FormalParameterList<p> ] ")" ]
["As" TypeName<out type> ]
EOL
(.
DeclareDeclaration declareDeclaration = new DeclareDeclaration(name, m.Modifier, type, p, attributes, library, alias, charsetModifer);
declareDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
declareDeclaration.EndLocation = t.EndLocation;
compilationUnit.AddChild(declareDeclaration);
.)
)
|
/* 9. 4 */
"Event"
(.
m.Check(Modifiers.VBEvents);
Location startPos = t.Location;
EventDeclaration eventDeclaration;
string name = String.Empty;
List<InterfaceImplementation> implementsClause = null;
.)
Identifier (. name= t.val; .)
(
"As" TypeName<out type>
|
[ "(" [ FormalParameterList<p> ] ")" ]
)
[ ImplementsClause<out implementsClause> ]
(.
eventDeclaration = new EventDeclaration {
Name = name, TypeReference = type, Modifier = m.Modifier,
Parameters = p, Attributes = attributes, InterfaceImplementations = implementsClause,
StartLocation = m.GetDeclarationLocation(startPos),
EndLocation = t.EndLocation
};
compilationUnit.AddChild(eventDeclaration);
.)
EOL
| /* 9.6 */
(. Location startPos = t.Location; .)
(.
m.Check(Modifiers.Fields);
FieldDeclaration fd = new FieldDeclaration(attributes, null, m.Modifier);
fd.StartLocation = m.GetDeclarationLocation(startPos);
.)
IdentifierForFieldDeclaration (. string name = t.val; .)
VariableDeclaratorPartAfterIdentifier<variableDeclarators, name>
{ "," VariableDeclarator<variableDeclarators> }
EOL
(.
fd.EndLocation = t.EndLocation;
fd.Fields = variableDeclarators;
compilationUnit.AddChild(fd);
.)
| /* 9.4 */
(. m.Check(Modifiers.Fields); .)
"Const" (. m.Add(Modifiers.Const, t.Location); .)
(.
FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
fd.StartLocation = m.GetDeclarationLocation(t.Location);
List<VariableDeclaration> constantDeclarators = new List<VariableDeclaration>();
.)
ConstantDeclarator<constantDeclarators>
{ "," ConstantDeclarator<constantDeclarators> }
(.
fd.Fields = constantDeclarators;
fd.EndLocation = t.Location;
.)
EOL
(.
fd.EndLocation = t.EndLocation;
compilationUnit.AddChild(fd);
.)
| /* 9.7 */
"Property"
(.
m.Check(Modifiers.VBProperties);
Location startPos = t.Location;
List<InterfaceImplementation> implementsClause = null;
.)
Identifier (. string propertyName = t.val; .)
[ "(" [ FormalParameterList<p> ] ")" ]
[ "As" TypeName<out type> ]
(.
if(type == null) {
type = new TypeReference("System.Object");
}
.)
[ ImplementsClause<out implementsClause> ]
EOL
(
/* abstract properties without a body */
IF(IsMustOverride(m))
(.
PropertyDeclaration pDecl = new PropertyDeclaration(propertyName, type, m.Modifier, attributes);
pDecl.StartLocation = m.GetDeclarationLocation(startPos);
pDecl.EndLocation = t.Location;
pDecl.TypeReference = type;
pDecl.InterfaceImplementations = implementsClause;
pDecl.Parameters = p;
compilationUnit.AddChild(pDecl);
.)
|
(.
PropertyDeclaration pDecl = new PropertyDeclaration(propertyName, type, m.Modifier, attributes);
pDecl.StartLocation = m.GetDeclarationLocation(startPos);
pDecl.EndLocation = t.Location;
pDecl.BodyStart = t.Location;
pDecl.TypeReference = type;
pDecl.InterfaceImplementations = implementsClause;
pDecl.Parameters = p;
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
.)
AccessorDecls<out getRegion, out setRegion>
"End" "Property"
EOL
(.
pDecl.GetRegion = getRegion;
pDecl.SetRegion = setRegion;
pDecl.BodyEnd = t.EndLocation;
compilationUnit.AddChild(pDecl);
.)
)
|
"Custom" (. Location startPos = t.Location; .) "Event"
(.
m.Check(Modifiers.VBCustomEvents);
EventAddRemoveRegion eventAccessorDeclaration;
EventAddRegion addHandlerAccessorDeclaration = null;
EventRemoveRegion removeHandlerAccessorDeclaration = null;
EventRaiseRegion raiseEventAccessorDeclaration = null;
List<InterfaceImplementation> implementsClause = null;
.)
Identifier (. string customEventName = t.val; .)
"As" TypeName<out type>
[ ImplementsClause<out implementsClause> ]
EOL
{
EventAccessorDeclaration<out eventAccessorDeclaration>
(.
if(eventAccessorDeclaration is EventAddRegion)
{
addHandlerAccessorDeclaration = (EventAddRegion)eventAccessorDeclaration;
}
else if(eventAccessorDeclaration is EventRemoveRegion)
{
removeHandlerAccessorDeclaration = (EventRemoveRegion)eventAccessorDeclaration;
}
else if(eventAccessorDeclaration is EventRaiseRegion)
{
raiseEventAccessorDeclaration = (EventRaiseRegion)eventAccessorDeclaration;
}
.)
}
"End" "Event" EOL
(.
if(addHandlerAccessorDeclaration == null)
{
Error("Need to provide AddHandler accessor.");
}
if(removeHandlerAccessorDeclaration == null)
{
Error("Need to provide RemoveHandler accessor.");
}
if(raiseEventAccessorDeclaration == null)
{
Error("Need to provide RaiseEvent accessor.");
}
EventDeclaration decl = new EventDeclaration {
TypeReference = type, Name = customEventName, Modifier = m.Modifier,
Attributes = attributes,
StartLocation = m.GetDeclarationLocation(startPos),
EndLocation = t.EndLocation,
AddRegion = addHandlerAccessorDeclaration,
RemoveRegion = removeHandlerAccessorDeclaration,
RaiseRegion = raiseEventAccessorDeclaration
};
compilationUnit.AddChild(decl);
.)
| (. ConversionType opConversionType = ConversionType.None; .)
[ "Widening" (. opConversionType = ConversionType.Implicit; .)
| "Narrowing" (. opConversionType = ConversionType.Explicit;.) ]
"Operator"
(.
m.Check(Modifiers.VBOperators);
Location startPos = t.Location;
TypeReference returnType = NullTypeReference.Instance;
TypeReference operandType = NullTypeReference.Instance;
string operandName;
OverloadableOperatorType operatorType;
AttributeSection section;
List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
List<AttributeSection> returnTypeAttributes = new List<AttributeSection>();
.)
OverloadableOperator<out operatorType>
"(" [ "ByVal" ] Identifier (. operandName = t.val; .)
[ "As" TypeName<out operandType> ]
(. parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParameterModifiers.In)); .)
{
","
[ "ByVal" ] Identifier (. operandName = t.val; .)
[ "As" TypeName<out operandType> ]
(. parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParameterModifiers.In)); .)
}
")"
(. Location endPos = t.EndLocation; .)
[ "As" { AttributeSection<out section> (. returnTypeAttributes.Add(section); .) } TypeName<out returnType> (. endPos = t.EndLocation; .) EOL ]
Block<out stmt> "End" "Operator" EOL
(.
OperatorDeclaration operatorDeclaration = new OperatorDeclaration {
Modifier = m.Modifier,
Attributes = attributes,
Parameters = parameters,
TypeReference = returnType,
OverloadableOperator = operatorType,
ConversionType = opConversionType,
ReturnTypeAttributes = returnTypeAttributes,
Body = (BlockStatement)stmt,
StartLocation = m.GetDeclarationLocation(startPos),
EndLocation = endPos
};
operatorDeclaration.Body.StartLocation = startPos;
operatorDeclaration.Body.EndLocation = t.Location;
compilationUnit.AddChild(operatorDeclaration);
.)
.
OverloadableOperator<out OverloadableOperatorType operatorType>
(. operatorType = OverloadableOperatorType.None; .)
=
"+" (. operatorType = OverloadableOperatorType.Add; .)
|
"-" (. operatorType = OverloadableOperatorType.Subtract; .)
|
"*" (. operatorType = OverloadableOperatorType.Multiply; .)
|
"/" (. operatorType = OverloadableOperatorType.Divide; .)
|
"\\" (. operatorType = OverloadableOperatorType.DivideInteger; .)
|
"&" (. operatorType = OverloadableOperatorType.Concat; .)
|
"Like" (. operatorType = OverloadableOperatorType.Like; .)
|
"Mod" (. operatorType = OverloadableOperatorType.Modulus; .)
|
"And" (. operatorType = OverloadableOperatorType.BitwiseAnd; .)
|
"Or" (. operatorType = OverloadableOperatorType.BitwiseOr; .)
|
"Xor" (. operatorType = OverloadableOperatorType.ExclusiveOr; .)
|
"^" (. operatorType = OverloadableOperatorType.Power; .)
|
"<<" (. operatorType = OverloadableOperatorType.ShiftLeft; .)
|
">>" (. operatorType = OverloadableOperatorType.ShiftRight; .)
|
"=" (. operatorType = OverloadableOperatorType.Equality; .)
|
"<>" (. operatorType = OverloadableOperatorType.InEquality; .)
|
"<" (. operatorType = OverloadableOperatorType.LessThan; .)
|
"<=" (. operatorType = OverloadableOperatorType.LessThanOrEqual; .)
|
">" (. operatorType = OverloadableOperatorType.GreaterThan; .)
|
">=" (. operatorType = OverloadableOperatorType.GreaterThanOrEqual; .)
|
"CType" (. operatorType = OverloadableOperatorType.CType; .)
|
Identifier
(.
string opName = t.val;
if (string.Equals(opName, "istrue", StringComparison.InvariantCultureIgnoreCase)) {
operatorType = OverloadableOperatorType.IsTrue;
} else if (string.Equals(opName, "isfalse", StringComparison.InvariantCultureIgnoreCase)) {
operatorType = OverloadableOperatorType.IsFalse;
} else {
Error("Invalid operator. Possible operators are '+', '-', 'Not', 'IsTrue', 'IsFalse'.");
}
.)
.
EventAccessorDeclaration<out EventAddRemoveRegion eventAccessorDeclaration>
(.
Statement stmt = null;
List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
eventAccessorDeclaration = null;
.) =
{ AttributeSection<out section> (. attributes.Add(section); .) }
(
"AddHandler" [ "(" [ FormalParameterList<p> ] ")" ] EOL
Block<out stmt> "End" "AddHandler" EOL
(.
eventAccessorDeclaration = new EventAddRegion(attributes);
eventAccessorDeclaration.Block = (BlockStatement)stmt;
eventAccessorDeclaration.Parameters = p;
.)
|
"RemoveHandler" [ "(" [ FormalParameterList<p> ] ")" ] EOL
Block<out stmt> "End" "RemoveHandler" EOL
(.
eventAccessorDeclaration = new EventRemoveRegion(attributes);
eventAccessorDeclaration.Block = (BlockStatement)stmt;
eventAccessorDeclaration.Parameters = p;
.)
|
"RaiseEvent" [ "(" [ FormalParameterList<p> ] ")" ] EOL
Block<out stmt> "End" "RaiseEvent" EOL
(.
eventAccessorDeclaration = new EventRaiseRegion(attributes);
eventAccessorDeclaration.Block = (BlockStatement)stmt;
eventAccessorDeclaration.Parameters = p;
.)
)
.
/* 9.7 */
AccessorDecls<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
(.
List<AttributeSection> attributes = new List<AttributeSection>();
AttributeSection section;
getBlock = null;
setBlock = null;
.) =
{ AttributeSection<out section> (. attributes.Add(section); .) }
(
GetAccessorDecl<out getBlock, attributes>
[
(. attributes = new List<AttributeSection>(); .)
{ AttributeSection<out section> (. attributes.Add(section); .) }
SetAccessorDecl<out setBlock, attributes>
]
|
SetAccessorDecl<out setBlock, attributes>
[
(. attributes = new List<AttributeSection>(); .)
{ AttributeSection<out section> (. attributes.Add(section); .) }
GetAccessorDecl<out getBlock, attributes>
]
)
.
/* 9.7.1 */
GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attributes>
(. Statement stmt = null; Modifiers m; .)
=
PropertyAccessorAccessModifier<out m>
"Get"
(. Location startLocation = t.Location; .)
EOL
Block<out stmt>
(. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .)
"End" "Get"
(. getBlock.Modifier = m; .)
(. getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; .)
EOL
.
/* 9.7.2 */
SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attributes>
(.
Statement stmt = null;
List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
Modifiers m;
.)
=
PropertyAccessorAccessModifier<out m>
"Set"
(. Location startLocation = t.Location; .)
[ "(" [ FormalParameterList<p> ] ")" ]
EOL
Block<out stmt>
(.
setBlock = new PropertySetRegion((BlockStatement)stmt, attributes);
setBlock.Modifier = m;
setBlock.Parameters = p;
.)
"End" "Set"
(. setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; .)
EOL
.
/* 9.5 */
ConstantDeclarator<List<VariableDeclaration> constantDeclaration>
(.
Expression expr = null;
TypeReference type = null;
string name = String.Empty;
Location location;
.) =
Identifier (. name = t.val; location = t.Location; .)
["As" TypeName<out type> ]
"=" Expr<out expr>
(.
VariableDeclaration f = new VariableDeclaration(name, expr);
f.TypeReference = type;
f.StartLocation = location;
constantDeclaration.Add(f);
.)
.
/* 9.6 */
VariableDeclarator<List<VariableDeclaration> fieldDeclaration>
=
Identifier (. string name = t.val; .)
VariableDeclaratorPartAfterIdentifier<fieldDeclaration, name>
.
VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration, string name>
(.
Expression expr = null;
TypeReference type = null;
ArrayList rank = null;
List<Expression> dimension = null;
Location startLocation = t.Location;
.) =
[ IF(IsSize() && !IsDims()) ArrayInitializationModifier<out dimension> ]
[ IF(IsDims()) ArrayNameModifier<out rank> ]
(
IF (IsObjectCreation()) "As" ObjectCreateExpression<out expr>
(.
if (expr is ObjectCreateExpression) {
type = ((ObjectCreateExpression)expr).CreateType;
} else {
type = ((ArrayCreateExpression)expr).CreateType;
}
.)
|
[ "As" TypeName<out type>
(.
if (type != null) {
for (int i = fieldDeclaration.Count - 1; i >= 0; i--) {
VariableDeclaration vd = fieldDeclaration[i];
if (vd.TypeReference.Type.Length > 0) break;
TypeReference newType = type.Clone();
newType.RankSpecifier = vd.TypeReference.RankSpecifier;
vd.TypeReference = newType;
}
}
.)
]
(.
if (type == null && (dimension != null || rank != null)) {
type = new TypeReference("");
}
if (dimension != null) {
if(type.RankSpecifier != null) {
Error("array rank only allowed one time");
} else {
if (rank == null) {
type.RankSpecifier = new int[] { dimension.Count - 1 };
} else {
rank.Insert(0, dimension.Count - 1);
type.RankSpecifier = (int[])rank.ToArray(typeof(int));
}
expr = new ArrayCreateExpression(type, dimension);
}
} else if (rank != null) {
if(type.RankSpecifier != null) {
Error("array rank only allowed one time");
} else {
type.RankSpecifier = (int[])rank.ToArray(typeof(int));
}
}
.)
[ "=" VariableInitializer<out expr> ]
)
(.
VariableDeclaration varDecl = new VariableDeclaration(name, expr, type);
varDecl.StartLocation = startLocation;
varDecl.EndLocation = t.Location;
fieldDeclaration.Add(varDecl);
.)
.
/* 6.8 */
ArrayInitializationModifier<out List<Expression> arrayModifiers>
(.
arrayModifiers = null;
.) =
"(" InitializationRankList<out arrayModifiers> ")"
.
/* 7.5.4.3 */
InitializationRankList<out List<Expression> rank>
(.
rank = new List<Expression>();
Expression expr = null;
.) =
Expr<out expr>
[ "To" (. EnsureIsZero(expr); .)
Expr<out expr>
]
(. if (expr != null) { rank.Add(expr); } .)
{ ","
Expr<out expr>
[ "To" (. EnsureIsZero(expr); .)
Expr<out expr>
]
(. if (expr != null) { rank.Add(expr); } .)
}
.
/* 9.6.3 */
VariableInitializer<out Expression initializerExpression>
(.
initializerExpression = null;
.) =
Expr<out initializerExpression>
| CollectionInitializer<out initializerExpression>
.
/* 9.6.3.4 */
CollectionInitializer<out Expression outExpr>
(.
Expression expr = null;
CollectionInitializerExpression initializer = new CollectionInitializerExpression();
.) =
"{"
[
VariableInitializer<out expr>
(.
if (expr != null) { initializer.CreateExpressions.Add(expr); }
.)
{
IF (NotFinalComma()) "," VariableInitializer<out expr>
(. if (expr != null) { initializer.CreateExpressions.Add(expr); } .)
}
]
"}" (. outExpr = initializer; .)
.
Charset<out CharsetModifier charsetModifier>
(. charsetModifier = CharsetModifier.None; .) =
| "Ansi" (. charsetModifier = CharsetModifier.Ansi; .)
| "Auto" (. charsetModifier = CharsetModifier.Auto; .)
| "Unicode" (. charsetModifier = CharsetModifier.Unicode; .)
.
/* 9.2.6 */
HandlesClause<out List<string> handlesClause>
(.
handlesClause = new List<string>();
string name;
.) =
"Handles" EventMemberSpecifier<out name> (. handlesClause.Add(name); .)
{ "," EventMemberSpecifier<out name> (. handlesClause.Add(name); .) }
.
/* 7.8. */
InterfaceBase <out List<TypeReference> bases>
(.
TypeReference type;
bases = new List<TypeReference>();
.) =
"Inherits"
TypeName<out type> (. bases.Add(type); .)
{
","
TypeName<out type> (. bases.Add(type); .)
}
EOL
.
/* 7.2 */
TypeImplementsClause<out List<TypeReference> baseInterfaces>
(.
baseInterfaces = new List<TypeReference>();
TypeReference type = null;
.) =
"Implements" TypeName<out type>
(.
baseInterfaces.Add(type);
.)
{
"," TypeName<out type>
(. baseInterfaces.Add(type); .)
}
EndOfStmt
.
/* 9.1 */
ImplementsClause<out List<InterfaceImplementation> baseInterfaces>
(.
baseInterfaces = new List<InterfaceImplementation>();
TypeReference type = null;
string memberName = null;
.) =
"Implements"
NonArrayTypeName<out type, false>
(. if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); .)
(. baseInterfaces.Add(new InterfaceImplementation(type, memberName)); .)
{ ","
NonArrayTypeName<out type, false>
(. if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); .)
(. baseInterfaces.Add(new InterfaceImplementation(type, memberName)); .)
}
.
EventMemberSpecifier<out string name>
(. string eventName; .)
=
( Identifier | "MyBase" | "Me" )
(. name = t.val; .)
"."
IdentifierOrKeyword<out eventName>
(. name = name + "." + eventName; .)
.
Expr<out Expression expr>
=
DisjunctionExpr<out expr>
.
AssignmentOperator<out AssignmentOperatorType op>
(. op = AssignmentOperatorType.None; .) =
"=" (. op = AssignmentOperatorType.Assign; .)
| "&=" (. op = AssignmentOperatorType.ConcatString; .)
| "+=" (. op = AssignmentOperatorType.Add; .)
| "-=" (. op = AssignmentOperatorType.Subtract; .)
| "*=" (. op = AssignmentOperatorType.Multiply; .)
| "/=" (. op = AssignmentOperatorType.Divide; .)
| "\\=" (. op = AssignmentOperatorType.DivideInteger; .)
| "^=" (. op = AssignmentOperatorType.Power; .)
| "<<=" (. op = AssignmentOperatorType.ShiftLeft; .)
| ">>=" (. op = AssignmentOperatorType.ShiftRight; .)
.
/* 11.4 */
SimpleExpr<out Expression pexpr>
=
SimpleNonInvocationExpression<out pexpr>
{ (. string name; .)
"." IdentifierOrKeyword<out name> (. pexpr = new MemberReferenceExpression(pexpr, name); .)
| InvocationExpression<ref pexpr>
}
.
SimpleNonInvocationExpression<out Expression pexpr>
(.
Expression expr;
TypeReference type = null;
string name = String.Empty;
pexpr = null;
.) =
(
(
/* 11.4.1 */
LiteralString (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .)
| LiteralCharacter (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .)
| LiteralSingle (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .)
| LiteralDouble (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .)
| LiteralInteger (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .)
| LiteralDate (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .)
| LiteralDecimal (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .)
/* True, False and Nothing are handled as literals in the spec */
| "True" (.pexpr = new PrimitiveExpression(true, "true"); .)
| "False" (.pexpr = new PrimitiveExpression(false, "false"); .)
| "Nothing" (.pexpr = new PrimitiveExpression(null, "null"); .)
| /* 11.4.2 */ "(" Expr<out expr> ")" (. pexpr = new ParenthesizedExpression(expr); .)
| /* 11.4.4 */ Identifier
(. pexpr = new IdentifierExpression(t.val); .)
(. pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; .)
| (. string val = String.Empty; .)
( PrimitiveTypeName<out val> | "Object" (. val = "Object"; .) )
"." (. t.val = ""; .) Identifier (. pexpr = new MemberReferenceExpression(new TypeReferenceExpression(val), t.val); .)
| "Me" (. pexpr = new ThisReferenceExpression(); .)
| (. Expression retExpr = null; .)
( "MyBase" (. retExpr = new BaseReferenceExpression(); .)
| "MyClass" (. retExpr = new ClassReferenceExpression(); .)
)
"." IdentifierOrKeyword<out name> (. pexpr = new MemberReferenceExpression(retExpr, name); .)
| "Global" "."
Identifier (. type = new TypeReference(t.val ?? ""); .)
/* fallback to "" is required if the token wasn't an identifier (->parser error but no exception) */
(. type.IsGlobal = true; .)
(. pexpr = new TypeReferenceExpression(type); .)
| ObjectCreateExpression<out expr> (. pexpr = expr; .)
| /* 11.11 : Casts */
(. CastType castType = CastType.Cast; .)
( "DirectCast"
| "CType" (. castType = CastType.Conversion; .)
| "TryCast" (. castType = CastType.TryCast; .)
)
"(" Expr<out expr> "," TypeName<out type> ")"
(. pexpr = new CastExpression(type, expr, castType); .)
| /* 11.11 */ CastTarget<out type> "(" Expr<out expr> ")" (. pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion); .)
| /* 11.4.5 */ "AddressOf" Expr<out expr> (. pexpr = new AddressOfExpression(expr); .)
| /* 11.5.1 */ "GetType" "(" GetTypeTypeName<out type> ")" (. pexpr = new TypeOfExpression(type); .)
| /* 11.5.2 */ "TypeOf" SimpleExpr<out expr> "Is" TypeName<out type> (. pexpr = new TypeOfIsExpression(expr, type); .)
)
|
/* this form only occurs in WithStatements*/
"." IdentifierOrKeyword<out name> (. pexpr = new MemberReferenceExpression(null, name);.)
)
.
InvocationExpression<ref Expression pexpr>
(. List<TypeReference> typeParameters = new List<TypeReference>();
List<Expression> parameters = null;
TypeReference type; .)
=
"(" (. Location start = t.Location; .)
( "Of"
TypeName<out type> (. if (type != null) typeParameters.Add(type); .)
{
","
TypeName<out type> (. if (type != null) typeParameters.Add(type); .)
}
")"
(
"." Identifier
(. pexpr = new MemberReferenceExpression(GetTypeReferenceExpression(pexpr, typeParameters), t.val); .)
| "("
ArgumentList<out parameters>
")"
(. pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters); .)
)
| ArgumentList<out parameters>
")"
(. pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters); .)
)
(. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .)
.
/* 11.11 */
CastTarget<out TypeReference type>
(.
type = null;
.) =
"CBool" (. type = new TypeReference("System.Boolean"); .)
| "CByte" (. type = new TypeReference("System.Byte"); .)
| "CSByte" (. type = new TypeReference("System.SByte"); .)
| "CChar" (. type = new TypeReference("System.Char"); .)
| "CDate" (. type = new TypeReference("System.DateTime"); .)
| "CDec" (. type = new TypeReference("System.Decimal"); .)
| "CDbl" (. type = new TypeReference("System.Double"); .)
| "CShort" (. type = new TypeReference("System.Int16"); .)
| "CInt" (. type = new TypeReference("System.Int32"); .)
| "CLng" (. type = new TypeReference("System.Int64"); .)
| "CUShort" (. type = new TypeReference("System.UInt16"); .)
| "CUInt" (. type = new TypeReference("System.UInt32"); .)
| "CULng" (. type = new TypeReference("System.UInt64"); .)
| "CObj" (. type = new TypeReference("System.Object"); .)
| "CSng" (. type = new TypeReference("System.Single"); .)
| "CStr" (. type = new TypeReference("System.String"); .)
.
DisjunctionExpr<out Expression outExpr>
(.
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
.) =
ConjunctionExpr<out outExpr>
{
(
"Or" (. op = BinaryOperatorType.BitwiseOr; .)
| "OrElse" (. op = BinaryOperatorType.LogicalOr; .)
| "Xor" (. op = BinaryOperatorType.ExclusiveOr; .)
)
ConjunctionExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
}
.
ConjunctionExpr<out Expression outExpr>
(.
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
.) =
NotExpr<out outExpr>
{
(
"And" (. op = BinaryOperatorType.BitwiseAnd; .)
| "AndAlso" (. op = BinaryOperatorType.LogicalAnd; .)
)
NotExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
}
.
NotExpr<out Expression outExpr>
(. UnaryOperatorType uop = UnaryOperatorType.None; .) =
{ "Not" (. uop = UnaryOperatorType.Not; .) }
ComparisonExpr<out outExpr>
(. if (uop != UnaryOperatorType.None)
outExpr = new UnaryOperatorExpression(outExpr, uop);
.)
.
ComparisonExpr<out Expression outExpr>
(.
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
.) =
ShiftExpr<out outExpr>
{
(
"<" (. op = BinaryOperatorType.LessThan; .)
| ">" (. op = BinaryOperatorType.GreaterThan; .)
| "<=" (. op = BinaryOperatorType.LessThanOrEqual; .)
| ">=" (. op = BinaryOperatorType.GreaterThanOrEqual; .)
| "<>" (. op = BinaryOperatorType.InEquality; .)
| "=" (. op = BinaryOperatorType.Equality; .)
| "Like" (. op = BinaryOperatorType.Like; .)
| "Is" (. op = BinaryOperatorType.ReferenceEquality; .)
| "IsNot" (. op = BinaryOperatorType.ReferenceInequality; .)
)
(
ShiftExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
|
"Not"
ShiftExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, new UnaryOperatorExpression(expr, UnaryOperatorType.Not)); .)
)
}
.
ShiftExpr<out Expression outExpr>
(.
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
.) =
ConcatenationExpr<out outExpr>
{
(
"<<" (. op = BinaryOperatorType.ShiftLeft; .)
| ">>" (. op = BinaryOperatorType.ShiftRight; .)
)
ConcatenationExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
}
.
ConcatenationExpr<out Expression outExpr>
(. Expression expr; .)
=
AdditiveExpr<out outExpr> { "&" AdditiveExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Concat, expr); .) }
.
AdditiveExpr<out Expression outExpr>
(.
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
.) =
ModuloExpr<out outExpr>
{
(
"+" (. op = BinaryOperatorType.Add; .)
| "-" (. op = BinaryOperatorType.Subtract; .)
)
ModuloExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
}
.
ModuloExpr<out Expression outExpr>
(. Expression expr; .)
=
IntegerDivisionExpr<out outExpr> { "Mod" IntegerDivisionExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Modulus, expr); .) }
.
IntegerDivisionExpr<out Expression outExpr>
(. Expression expr; .)
=
MultiplicativeExpr<out outExpr> { "\\" MultiplicativeExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.DivideInteger, expr); .) }
.
MultiplicativeExpr<out Expression outExpr>
(.
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
.) =
UnaryExpr<out outExpr>
{
(
"*" (. op = BinaryOperatorType.Multiply; .)
| "/" (. op = BinaryOperatorType.Divide; .)
)
UnaryExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
}
.
UnaryExpr<out Expression uExpr>
(.
Expression expr;
UnaryOperatorType uop = UnaryOperatorType.None;
bool isUOp = false;
.) =
{ "+" (. uop = UnaryOperatorType.Plus; isUOp = true; .)
| "-" (. uop = UnaryOperatorType.Minus; isUOp = true; .)
| "*" (. uop = UnaryOperatorType.Star; isUOp = true;.)
}
ExponentiationExpr<out expr>
(.
if (isUOp) {
uExpr = new UnaryOperatorExpression(expr, uop);
} else {
uExpr = expr;
}
.)
.
ExponentiationExpr<out Expression outExpr>
(. Expression expr; .)
=
SimpleExpr<out outExpr> { "^" SimpleExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Power, expr); .) }
.
ObjectCreateExpression<out Expression oce>
(.
TypeReference type = null;
Expression initializer = null;
List<Expression> arguments = null;
ArrayList dimensions = null;
oce = null;
bool canBeNormal; bool canBeReDim;
.) =
"New" NonArrayTypeName<out type, false>
["(" NormalOrReDimArgumentList<out arguments, out canBeNormal, out canBeReDim> ")"
[ IF (la.kind == Tokens.OpenParenthesis)
ArrayTypeModifiers<out dimensions>
CollectionInitializer<out initializer>
| CollectionInitializer<out initializer>
]
(. if (canBeReDim && !canBeNormal && initializer == null) initializer = new CollectionInitializerExpression(); .)
]
(.
if (type == null) type = new TypeReference("Object"); // fallback type on parser errors
if (initializer == null) {
oce = new ObjectCreateExpression(type, arguments);
} else {
if (dimensions == null) dimensions = new ArrayList();
dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0));
type.RankSpecifier = (int[])dimensions.ToArray(typeof(int));
ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as CollectionInitializerExpression);
ace.Arguments = arguments;
oce = ace;
}
.)
.
/* 9.3.2 */
ArgumentList<out List<Expression> arguments>
(.
arguments = new List<Expression>();
Expression expr = null;
.) =
[ Argument<out expr> ]
{ "," (. arguments.Add(expr ?? Expression.Null); expr = null; .)
[ Argument<out expr> ]
(. if (expr == null) expr = Expression.Null; .)
}
(. if (expr != null) arguments.Add(expr); .)
.
/* argument list that hasn't decided if it is method call or array initialisation */
NormalOrReDimArgumentList<out List<Expression> arguments, out bool canBeNormal, out bool canBeRedim>
(.
arguments = new List<Expression>();
canBeNormal = true; canBeRedim = !IsNamedAssign();
Expression expr = null;
.)
=
[ Argument<out expr>
[ "To" (. EnsureIsZero(expr); canBeNormal = false; .)
Expr<out expr>
] ]
{ ","
(. if (expr == null) canBeRedim = false; .)
(. arguments.Add(expr ?? Expression.Null); expr = null; .)
(. canBeRedim &= !IsNamedAssign(); .)
[ Argument<out expr>
[ "To" (. EnsureIsZero(expr); canBeNormal = false; .)
Expr<out expr>
] ]
(. if (expr == null) { canBeRedim = false; expr = Expression.Null; } .)
}
(. if (expr != null) arguments.Add(expr); else canBeRedim = false; .)
.
/* Spec, 11.8 */
Argument<out Expression argumentexpr>
(.
Expression expr;
argumentexpr = null;
string name;
.) =
IF(IsNamedAssign()) Identifier (. name = t.val; .) ":" "=" Expr<out expr>
(.
argumentexpr = new NamedArgumentExpression(name, expr);
.)
|
Expr<out argumentexpr>
.
/* 7.1. */
TypeName<out TypeReference typeref>
(. ArrayList rank = null; .)
=
NonArrayTypeName<out typeref, false>
ArrayTypeModifiers<out rank>
(. if (rank != null && typeref != null) {
typeref.RankSpecifier = (int[])rank.ToArray(typeof(int));
}
.)
.
GetTypeTypeName<out TypeReference typeref>
(. ArrayList rank = null; .)
=
NonArrayTypeName<out typeref, true>
ArrayTypeModifiers<out rank>
(. if (rank != null && typeref != null) {
typeref.RankSpecifier = (int[])rank.ToArray(typeof(int));
}
.)
.
/* 7.1 */
NonArrayTypeName<out TypeReference typeref, bool canBeUnbound>
(.
string name;
typeref = null;
bool isGlobal = false;
.) =
(
[ "Global" "." (. isGlobal = true; .) ]
QualIdentAndTypeArguments<out typeref, canBeUnbound>
(. typeref.IsGlobal = isGlobal; .)
{ "." (. TypeReference nestedTypeRef; .)
QualIdentAndTypeArguments<out nestedTypeRef, canBeUnbound>
(. typeref = new InnerClassTypeReference(typeref, nestedTypeRef.Type, nestedTypeRef.GenericTypes); .)
}
)
| "Object" (. typeref = new TypeReference("System.Object"); .)
| PrimitiveTypeName<out name> (. typeref = new TypeReference(name); .)
.
QualIdentAndTypeArguments<out TypeReference typeref, bool canBeUnbound>
(. string name; typeref = null; .)
=
Qualident<out name>
(. typeref = new TypeReference(name); .)
[IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
"(" "Of"
( IF (canBeUnbound && (la.kind == Tokens.CloseParenthesis || la.kind == Tokens.Comma))
(. typeref.GenericTypes.Add(NullTypeReference.Instance); .)
{ "," (. typeref.GenericTypes.Add(NullTypeReference.Instance); .) }
| TypeArgumentList<typeref.GenericTypes>
)
")"
]
.
/* 7.9 */
ArrayNameModifier<out ArrayList arrayModifiers>
(.
arrayModifiers = null;
.) =
ArrayTypeModifiers<out arrayModifiers>
.
/* 7.9 */
ArrayTypeModifiers<out ArrayList arrayModifiers>
(.
arrayModifiers = new ArrayList();
int i = 0;
.) =
{ IF (IsDims())
"("
[ RankList<out i>]
(.
arrayModifiers.Add(i);
.)
")"
}
(.
if(arrayModifiers.Count == 0) {
arrayModifiers = null;
}
.)
.
/* 7.9 */
RankList<out int i>
(. i = 0; .) =
{ "," (. ++i; .) }
.
/* 7.12 */
TypeArgumentList<List<TypeReference> typeArguments>
(.
TypeReference typeref;
.) =
TypeName<out typeref> (. if (typeref != null) typeArguments.Add(typeref); .)
{
","
TypeName<out typeref> (. if (typeref != null) typeArguments.Add(typeref); .)
}
.
GlobalAttributeSection =
"<" (. Location startPos = t.Location; .)
("Assembly" | "Module")
(. string attributeTarget = t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture);
List<ASTAttribute> attributes = new List<ASTAttribute>();
ASTAttribute attribute;
.)
":" Attribute<out attribute> (. attributes.Add(attribute); .)
{ IF (NotFinalComma()) ["," ("Assembly" | "Module") ":"] Attribute<out attribute> (. attributes.Add(attribute); .)}
[ "," ]
">"
EndOfStmt
(.
AttributeSection section = new AttributeSection {
AttributeTarget = attributeTarget,
Attributes = attributes,
StartLocation = startPos,
EndLocation = t.EndLocation
};
compilationUnit.AddChild(section);
.)
.
/* Spec, 5. */
Attribute<out ASTAttribute attribute>
(. string name;
List<Expression> positional = new List<Expression>();
List<NamedArgumentExpression> named = new List<NamedArgumentExpression>();
.) =
[ "Global" "." ]
Qualident<out name>
[ AttributeArguments<positional, named> ]
(. attribute = new ASTAttribute(name, positional, named); .)
.
/* Spec, 5.2.2 */
AttributeArguments<List<Expression> positional, List<NamedArgumentExpression> named>
(.
bool nameFound = false;
string name = "";
Expression expr;
.) =
"("
[
IF (IsNotClosingParenthesis()) (
[
IF (IsNamedAssign()) (. nameFound = true; .)
IdentifierOrKeyword<out name>
[":"] "="
] Expr<out expr>
(.
if (expr != null) {
if (string.IsNullOrEmpty(name)) { positional.Add(expr); }
else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
}
.)
{
","
(
IF (IsNamedAssign()) (. nameFound = true; .)
IdentifierOrKeyword<out name>
[ ":" ] "="
| (. if (nameFound) Error("no positional argument after named argument"); .)
) Expr<out expr> (. if (expr != null) { if(name == "") positional.Add(expr);
else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
}
.)
}
)
]
")"
.
/* Spec, 5. */
AttributeSection<out AttributeSection section>
(.
string attributeTarget = "";List<ASTAttribute> attributes = new List<ASTAttribute>();
ASTAttribute attribute;
.) =
"<" (. Location startPos = t.Location; .)
[ IF (IsLocalAttrTarget())
( "Event" (. attributeTarget = "event";.)
| "Return" (. attributeTarget = "return";.)
| Identifier
(.
string val = t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture);
if (val != "field" || val != "method" ||
val != "module" || val != "param" ||
val != "property" || val != "type")
Error("attribute target specifier (event, return, field," +
"method, module, param, property, or type) expected");
attributeTarget = t.val;
.)
) ":"
]
Attribute<out attribute> (. attributes.Add(attribute); .)
{ IF (NotFinalComma()) "," Attribute<out attribute> (. attributes.Add(attribute); .) }
[ "," ]
">"
(.
section = new AttributeSection {
AttributeTarget = attributeTarget,
Attributes = attributes,
StartLocation = startPos,
EndLocation = t.EndLocation
};
.)
.
/* 9.2.5 */
FormalParameterList<List<ParameterDeclarationExpression> parameter>
(.
ParameterDeclarationExpression p;
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
.) =
{ AttributeSection<out section> (.attributes.Add(section); .) }
(
FormalParameter<out p>
(.
bool paramsFound = false;
p.Attributes = attributes;
parameter.Add(p);
.)
{
"," (. if (paramsFound) Error("params array must be at end of parameter list"); .)
{ AttributeSection<out section> (.attributes.Add(section); .) }
(
FormalParameter <out p> (. p.Attributes = attributes; parameter.Add(p); .)
)
}
)
.
/* 9.2.5 */
FormalParameter<out ParameterDeclarationExpression p>
(.
TypeReference type = null;
ParamModifierList mod = new ParamModifierList(this);
Expression expr = null;
p = null;ArrayList arrayModifiers = null;
.) =
{ ParameterModifier<mod> }
Identifier (. string parameterName = t.val; .)
[ IF(IsDims()) ArrayTypeModifiers<out arrayModifiers> ]
[ "As" TypeName<out type> ]
(.
if(type != null) {
if (arrayModifiers != null) {
if (type.RankSpecifier != null) {
Error("array rank only allowed one time");
} else {
type.RankSpecifier = (int[])arrayModifiers.ToArray(typeof(int));
}
}
} else {
type = new TypeReference("System.Object", arrayModifiers == null ? null : (int[])arrayModifiers.ToArray(typeof(int)));
}
.)
[ "=" Expr<out expr> ]
(.
mod.Check();
p = new ParameterDeclarationExpression(type, parameterName, mod.Modifier, expr);
.)
.
/* 10.1 */
Block<out Statement stmt>
=
(.
BlockStatement blockStmt = new BlockStatement();
/* in snippet parsing mode, t might be null */
if (t != null) blockStmt.StartLocation = t.Location;
compilationUnit.BlockStart(blockStmt);
.)
{
IF (IsEndStmtAhead()) "End" EndOfStmt (. compilationUnit.AddChild(new EndStatement()); .)
| Statement EndOfStmt
/* IF (!LeaveBlock()) { }*/
}
(.
stmt = blockStmt;
if (t != null) blockStmt.EndLocation = t.EndLocation;
compilationUnit.BlockEnd();
.)
.
Statement
(.
Statement stmt = null;
Location startPos = la.Location;
string label = String.Empty;
.) =
(
| IF (IsLabel()) LabelName<out label>
(.
compilationUnit.AddChild(new LabelStatement(t.val));
.)
":" Statement
| EmbeddedStatement<out stmt> (. compilationUnit.AddChild(stmt); .)
| LocalDeclarationStatement<out stmt> (. compilationUnit.AddChild(stmt); .)
)
(.
if (stmt != null) {
stmt.StartLocation = startPos;
stmt.EndLocation = t.Location;
}
.)
.
/* 10.2 */
LocalDeclarationStatement<out Statement statement>
(.
ModifierList m = new ModifierList();
LocalVariableDeclaration localVariableDeclaration;
bool dimfound = false;
.) =
/* this differs from the spec: dim static x compiles with vbc. */
{
"Const" (. m.Add(Modifiers.Const, t.Location); .)
| "Static" (. m.Add(Modifiers.Static, t.Location); .)
| "Dim" (. dimfound = true; .)
}
(.
if(dimfound && (m.Modifier & Modifiers.Const) != 0) {
Error("Dim is not allowed on constants.");
}
if(m.isNone && dimfound == false) {
Error("Const, Dim or Static expected");
}
localVariableDeclaration = new LocalVariableDeclaration(m.Modifier);
localVariableDeclaration.StartLocation = t.Location;
.)
VariableDeclarator<localVariableDeclaration.Variables>
{ "," VariableDeclarator<localVariableDeclaration.Variables> }
(.
statement = localVariableDeclaration;
.)
.
EmbeddedStatement<out Statement statement>
(.
Statement embeddedStatement = null;
statement = null;
Expression expr = null;
string name = String.Empty;
List<Expression> p = null;
.) =
"Exit" (. ExitType exitType = ExitType.None; .)
(
"Sub" (. exitType = ExitType.Sub; .)
|
"Function" (. exitType = ExitType.Function; .)
|
"Property" (. exitType = ExitType.Property; .)
|
"Do" (. exitType = ExitType.Do; .)
|
"For" (. exitType = ExitType.For; .)
|
"Try" (. exitType = ExitType.Try; .)
|
"While" (. exitType = ExitType.While; .)
|
"Select" (. exitType = ExitType.Select; .)
)
(. statement = new ExitStatement(exitType); .)
| TryStatement<out statement>
| "Continue" (. ContinueType continueType = ContinueType.None; .) [ "Do" (. continueType = ContinueType.Do; .) | "For" (. continueType = ContinueType.For; .) | "While" (. continueType = ContinueType.While; .)] (. statement = new ContinueStatement(continueType); .)
| /* 10.10.1.3 */
"Throw" [ Expr<out expr> ] (. statement = new ThrowStatement(expr); .)
| /* 10.11 */
"Return" [ Expr<out expr> ] (. statement = new ReturnStatement(expr); .)
| /* 10.4 */
"SyncLock" Expr<out expr> EndOfStmt Block<out embeddedStatement>
"End" "SyncLock" (. statement = new LockStatement(expr, embeddedStatement); .)
| /* 10.5.1 */
"RaiseEvent" Identifier (. name = t.val; .)
[ "(" [ ArgumentList<out p> ] ")" ]
(. statement = new RaiseEventStatement(name, p); .)
| /* 10.3 */
WithStatement<out statement>
| /* 10.5.2 */
"AddHandler" (. Expression handlerExpr = null; .)
Expr<out expr> "," Expr<out handlerExpr>
(.
statement = new AddHandlerStatement(expr, handlerExpr);
.)
| /* 10.5.2 */
"RemoveHandler" (. Expression handlerExpr = null; .)
Expr<out expr> "," Expr<out handlerExpr>
(.
statement = new RemoveHandlerStatement(expr, handlerExpr);
.)
| /* 10.9.1 */
"While" Expr<out expr> EndOfStmt
Block<out embeddedStatement> "End" "While"
(.
statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);
.)
| /* 10.9.1 */
"Do"
(.
ConditionType conditionType = ConditionType.None;
.)
(
WhileOrUntil<out conditionType> Expr<out expr> EndOfStmt
Block<out embeddedStatement>
"Loop"
(.
statement = new DoLoopStatement(expr,
embeddedStatement,
conditionType == ConditionType.While ? ConditionType.DoWhile : conditionType,
ConditionPosition.Start);
.)
|
EndOfStmt
Block<out embeddedStatement>
"Loop" [WhileOrUntil<out conditionType> Expr<out expr>]
(.
statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End);
.)
)
| "For"
(.
Expression group = null;
TypeReference typeReference;
string typeName;
Location startLocation = t.Location;
.)
(
/* 10.9.3 */
"Each" LoopControlVariable<out typeReference, out typeName>
"In" Expr<out group> EndOfStmt
Block<out embeddedStatement>
"Next" [ Expr<out expr> ]
(.
statement = new ForeachStatement(typeReference,
typeName,
group,
embeddedStatement,
expr);
statement.StartLocation = startLocation;
statement.EndLocation = t.EndLocation;
.)
| /* 10.9.2 */
(.
Expression start = null;
Expression end = null;
Expression step = null;
Expression nextExpr = null;List<Expression> nextExpressions = null;
.)
LoopControlVariable<out typeReference, out typeName>
"=" Expr<out start> "To" Expr<out end> [ "Step" Expr<out step> ]
EndOfStmt Block<out embeddedStatement>
"Next"
[
Expr<out nextExpr> (. nextExpressions = new List<Expression>(); nextExpressions.Add(nextExpr); .)
{ "," Expr<out nextExpr> (. nextExpressions.Add(nextExpr); .) }
]
(.
statement = new ForNextStatement(typeReference, typeName, start, end, step, embeddedStatement, nextExpressions);
.)
)
| /* 10.10.2.1 */
"Error" Expr<out expr> (. statement = new ErrorStatement(expr); .)
| /* 10.12.1 */
"ReDim" (. bool isPreserve = false; .) [ "Preserve" (. isPreserve = true; .) ]
ReDimClause<out expr>
(.
ReDimStatement reDimStatement = new ReDimStatement(isPreserve);
statement = reDimStatement;
SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression);
.)
{ "," ReDimClause<out expr>
(. SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); .)
}
| /* 10.12.2 */
"Erase"
Expr<out expr>
(.List<Expression> arrays = new List<Expression>();
if (expr != null) { arrays.Add(expr);}
EraseStatement eraseStatement = new EraseStatement(arrays);
.)
{ "," Expr<out expr> (. if (expr != null) { arrays.Add(expr); }.) }
(. statement = eraseStatement; .)
| /* 10.11 */
"Stop" (. statement = new StopStatement(); .)
| /* 10.8.1 */
"If" (. Location ifStartLocation = t.Location; .) Expr<out expr> [ "Then" ]
(
/* multiline if statement */
EndOfStmt Block<out embeddedStatement>
(.
IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement);
ifStatement.StartLocation = ifStartLocation;
Location elseIfStart;
.)
{
(
IF(IsElseIf()) "Else" (. elseIfStart = t.Location; .) "If"
| "ElseIf" (. elseIfStart = t.Location; .)
)
(. Expression condition = null; Statement block = null; .)
Expr<out condition> [ "Then"] EndOfStmt
Block<out block>
(.
ElseIfSection elseIfSection = new ElseIfSection(condition, block);
elseIfSection.StartLocation = elseIfStart;
elseIfSection.EndLocation = t.Location;
elseIfSection.Parent = ifStatement;
ifStatement.ElseIfSections.Add(elseIfSection);
.)
}
[
"Else" EndOfStmt
Block<out embeddedStatement>
(.
ifStatement.FalseStatement.Add(embeddedStatement);
.)
] "End" "If"
(.
ifStatement.EndLocation = t.Location;
statement = ifStatement;
.)
| /* singleline if statement */
(.
IfElseStatement ifStatement = new IfElseStatement(expr);
ifStatement.StartLocation = ifStartLocation;
.)
SingleLineStatementList<ifStatement.TrueStatement>
[
"Else"
[ SingleLineStatementList<ifStatement.FalseStatement> ]
]
(. ifStatement.EndLocation = t.Location; statement = ifStatement; .)
)
| /* 10.8.2 */
"Select" [ "Case" ] Expr<out expr> EndOfStmt
(.List<SwitchSection> selectSections = new List<SwitchSection>();
Statement block = null;
.)
{
(.List<CaseLabel> caseClauses = null; Location caseLocation = la.Location; .)
"Case" CaseClauses<out caseClauses> [ IF(IsNotStatementSeparator()) ":" ] EndOfStmt
(.
SwitchSection selectSection = new SwitchSection(caseClauses);
selectSection.StartLocation = caseLocation;
.)
Block<out block>
(.
selectSection.Children = block.Children;
selectSection.EndLocation = t.EndLocation;
selectSections.Add(selectSection);
.)
}
(. statement = new SwitchStatement(expr, selectSections); .)
"End" "Select"
| (. OnErrorStatement onErrorStatement = null; .)
OnErrorStatement<out onErrorStatement> (. statement = onErrorStatement; .)
| (. GotoStatement goToStatement = null; .)
GotoStatement<out goToStatement> (. statement = goToStatement; .)
| (. ResumeStatement resumeStatement = null; .)
ResumeStatement<out resumeStatement> (. statement = resumeStatement; .)
|/* Statement expression (invocation and assignment) 10.6.1, 10.6.2, 10.6.3 */
(.
Expression val = null;
AssignmentOperatorType op;
bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus ||
la.kind == Tokens.Not || la.kind == Tokens.Times;
.)
SimpleExpr<out expr>
(
AssignmentOperator<out op> Expr<out val> (. expr = new AssignmentExpression(expr, op, val); .)
| (. if (mustBeAssignment) Error("error in assignment."); .)
)
(.
// a field reference expression that stands alone is a
// invocation expression without parantheses and arguments
if(expr is MemberReferenceExpression || expr is IdentifierExpression) {
expr = new InvocationExpression(expr);
}
statement = new ExpressionStatement(expr);
.)
| "Call" SimpleExpr<out expr> (. statement = new ExpressionStatement(expr); .)
| "Using"
(. Statement block; .)
( IF (Peek(1).kind == Tokens.As)
(. LocalVariableDeclaration resourceAquisition = new LocalVariableDeclaration(Modifiers.None); .)
VariableDeclarator<resourceAquisition.Variables>
{ ","
VariableDeclarator<resourceAquisition.Variables>
}
Block<out block>
(. statement = new UsingStatement(resourceAquisition, block); .)
| Expr<out expr>
Block<out block>
(. statement = new UsingStatement(new ExpressionStatement(expr), block); .)
)
"End" "Using"
.
SingleLineStatementList<List<Statement> list>
(. Statement embeddedStatement = null; .)
=
( "End" (. embeddedStatement = new EndStatement(); .)
| EmbeddedStatement<out embeddedStatement> )
(. if (embeddedStatement != null) list.Add(embeddedStatement); .)
{ ":" { ":" }
( "End" (. embeddedStatement = new EndStatement(); .)
| EmbeddedStatement<out embeddedStatement> )
(. if (embeddedStatement != null) list.Add(embeddedStatement); .)
}
.
/* 10.9.2 */
LoopControlVariable<out TypeReference type, out string name>
(.ArrayList arrayModifiers = null;
type = null;
.)
=
Qualident<out name>
[ IF(IsDims()) ArrayTypeModifiers<out arrayModifiers> ]
[ "As" TypeName<out type> (. if (name.IndexOf('.') > 0) { Error("No type def for 'for each' member indexer allowed."); } .) ]
(.
if (type != null) {
if(type.RankSpecifier != null && arrayModifiers != null) {
Error("array rank only allowed one time");
} else if (arrayModifiers != null) {
type.RankSpecifier = (int[])arrayModifiers.ToArray(typeof(int));
}
}
.)
.
/* 10.2.2 */
OnErrorStatement<out OnErrorStatement stmt>
(.
stmt = null;
GotoStatement goToStatement = null;
.)
=
"On" "Error"
(
IF(IsNegativeLabelName())"GoTo" "-" LiteralInteger
(.
long intLabel = Int64.Parse(t.val);
if(intLabel != 1) {
Error("invalid label in on error statement.");
}
stmt = new OnErrorStatement(new GotoStatement((intLabel * -1).ToString()));
.)
| GotoStatement<out goToStatement>
(.
string val = goToStatement.Label;
// if value is numeric, make sure that is 0
try {
long intLabel = Int64.Parse(val);
if(intLabel != 0) {
Error("invalid label in on error statement.");
}
} catch {
}
stmt = new OnErrorStatement(goToStatement);
.)
| "Resume" "Next"
(.
stmt = new OnErrorStatement(new ResumeStatement(true));
.)
)
.
/* 10.11 */
GotoStatement<out GotoStatement goToStatement>
(.
string label = String.Empty;
.)
=
"GoTo" LabelName<out label>
(.
goToStatement = new GotoStatement(label);
.)
.
/* 10.1 */
LabelName<out string name>
(.
name = String.Empty;
.) =
Identifier (. name = t.val; .)
| LiteralInteger (. name = t.val; .)
.
/* 12.12.1 */
ReDimClause<out Expression expr>
=
SimpleNonInvocationExpression<out expr>
ReDimClauseInternal<ref expr>
.
ReDimClauseInternal<ref Expression expr>
(. List<Expression> arguments; bool canBeNormal; bool canBeRedim; string name; .)
=
{ "." IdentifierOrKeyword<out name> (. expr = new MemberReferenceExpression(expr, name); .)
| IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
InvocationExpression<ref expr>
}
"("
NormalOrReDimArgumentList<out arguments, out canBeNormal, out canBeRedim>
")"
(. expr = new InvocationExpression(expr, arguments);
if (canBeRedim == false || canBeNormal && (la.kind == Tokens.Dot || la.kind == Tokens.OpenParenthesis)) {
if (this.Errors.Count == 0) {
// don't recurse on parse errors - could result in endless recursion
ReDimClauseInternal(ref expr);
}
}
.)
.
/* 10.10.2.3 */
ResumeStatement<out ResumeStatement resumeStatement>
(.
resumeStatement = null;
string label = String.Empty;
.) =
IF(IsResumeNext())
"Resume" "Next" (. resumeStatement = new ResumeStatement(true); .)
| "Resume" [ LabelName<out label> ] (. resumeStatement = new ResumeStatement(label); .)
.
/* 18.8.2 */
CaseClauses<out List<CaseLabel> caseClauses>
(.
caseClauses = new List<CaseLabel>();
CaseLabel caseClause = null;
.) =
CaseClause<out caseClause> (. if (caseClause != null) { caseClauses.Add(caseClause); } .)
{ "," CaseClause<out caseClause> (. if (caseClause != null) { caseClauses.Add(caseClause); } .) }
.
/* 19.8.2 */
CaseClause<out CaseLabel caseClause>
(.
Expression expr = null;
Expression sexpr = null;
BinaryOperatorType op = BinaryOperatorType.None;
caseClause = null;
.) =
"Else"
(. caseClause = new CaseLabel(); .)
|
[ "Is" ]
(
"<" (. op = BinaryOperatorType.LessThan; .)
| ">" (. op = BinaryOperatorType.GreaterThan; .)
| "<=" (. op = BinaryOperatorType.LessThanOrEqual; .)
| ">=" (. op = BinaryOperatorType.GreaterThanOrEqual; .)
| "=" (. op = BinaryOperatorType.Equality; .)
| "<>" (. op = BinaryOperatorType.InEquality; .)
)
Expr<out expr>
(.
caseClause = new CaseLabel(op, expr);
.)
| Expr<out expr> [ "To" Expr<out sexpr> ]
(.
caseClause = new CaseLabel(expr, sexpr);
.)
.
/* 10.9.1 */
WhileOrUntil<out ConditionType conditionType>
(. conditionType = ConditionType.None; .) =
"While" (. conditionType = ConditionType.While; .)
| "Until" (. conditionType = ConditionType.Until; .)
.
/* 10.3 */
WithStatement<out Statement withStatement>
(.
Statement blockStmt = null;
Expression expr = null;
.) =
"With" (. Location start = t.Location; .)
Expr<out expr> EndOfStmt
(.
withStatement = new WithStatement(expr);
withStatement.StartLocation = start;
.)
Block<out blockStmt>
(.
((WithStatement)withStatement).Body = (BlockStatement)blockStmt;
.)
"End" "With"
(. withStatement.EndLocation = t.Location; .)
.
/* 10.10.1 */
TryStatement<out Statement tryStatement>
(.
Statement blockStmt = null, finallyStmt = null;List<CatchClause> catchClauses = null;
.) =
"Try" EndOfStmt
Block<out blockStmt>
[CatchClauses<out catchClauses>]
["Finally" EndOfStmt Block<out finallyStmt> ]
"End" "Try"
(.
tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt);
.)
.
/* 10.10.1.2 */
CatchClauses<out List<CatchClause> catchClauses>
(.
catchClauses = new List<CatchClause>();
TypeReference type = null;
Statement blockStmt = null;
Expression expr = null;
string name = String.Empty;
.) =
{
"Catch"
[ Identifier (. name = t.val; .) ["As" TypeName<out type>] ]
[ "When" Expr<out expr> ]
EndOfStmt
Block<out blockStmt>
(. catchClauses.Add(new CatchClause(type, name, blockStmt, expr)); .)
}
.
/* 4.7 */
Qualident<out string qualident>
(.
string name;
qualidentBuilder.Length = 0;
.)
=
Identifier (. qualidentBuilder.Append(t.val); .)
{ IF (DotAndIdentOrKw()) "." IdentifierOrKeyword<out name> (. qualidentBuilder.Append('.'); qualidentBuilder.Append(name); .) }
(. qualident = qualidentBuilder.ToString(); .)
.
/* This production handles pseudo keywords that are needed in the grammar */
Identifier =
ident
| "Text"
| "Binary"
| "Compare"
| "Custom"
| "Assembly"
| "Ansi"
| "Auto"
| "Preserve"
| "Unicode"
| "Until"
| "Off"
| "Explicit"
.
IdentifierForFieldDeclaration =
ident
| "Text"
| "Binary"
| "Compare"
/*| "Custom" Custom is not valid for field declaration */
| "Assembly"
| "Ansi"
| "Auto"
| "Preserve"
| "Unicode"
| "Until"
| "Off"
| "Explicit"
.
/* 2.2 */
IdentifierOrKeyword<out string name>
=
(. lexer.NextToken(); name = t.val; .)
.
/* 7.3 */
PrimitiveTypeName<out string type>
(. type = String.Empty; .) =
"Boolean" (. type = "Boolean"; .)
| "Date" (. type = "Date"; .)
| "Char" (. type = "Char"; .)
| "String" (. type = "String"; .)
| "Decimal" (. type = "Decimal"; .)
| "Byte" (. type = "Byte"; .)
| "Short" (. type = "Short"; .)
| "Integer" (. type = "Integer"; .)
| "Long" (. type = "Long"; .)
| "Single" (. type = "Single"; .)
| "Double" (. type = "Double"; .)
| "UInteger" (. type = "UInteger"; .)
| "ULong" (. type = "ULong"; .)
| "UShort" (. type = "UShort"; .)
| "SByte" (. type = "SByte"; .)
.
ParameterModifier<ParamModifierList m>
= "ByVal" (. m.Add(ParameterModifiers.In); .)
| "ByRef" (. m.Add(ParameterModifiers.Ref); .)
| "Optional" (. m.Add(ParameterModifiers.Optional); .)
| "ParamArray" (. m.Add(ParameterModifiers.Params); .)
.
TypeModifier<ModifierList m>
= "Public" (. m.Add(Modifiers.Public, t.Location); .)
| "Protected" (. m.Add(Modifiers.Protected, t.Location); .)
| "Friend" (. m.Add(Modifiers.Internal, t.Location); .)
| "Private" (. m.Add(Modifiers.Private, t.Location); .)
| "Shared" (. m.Add(Modifiers.Static, t.Location); .)
| "Shadows" (. m.Add(Modifiers.New, t.Location); .)
| "MustInherit" (. m.Add(Modifiers.Abstract, t.Location); .)
| "NotInheritable" (. m.Add(Modifiers.Sealed, t.Location); .)
| "Partial" (. m.Add(Modifiers.Partial, t.Location); .)
.
MemberModifier<ModifierList m> =
"MustInherit" (.m.Add(Modifiers.Abstract, t.Location);.)
| "Default" (.m.Add(Modifiers.Default, t.Location);.)
| "Friend" (.m.Add(Modifiers.Internal, t.Location);.)
| "Shadows" (.m.Add(Modifiers.New, t.Location);.)
| "Overrides" (.m.Add(Modifiers.Override, t.Location);.)
| "MustOverride" (.m.Add(Modifiers.Abstract, t.Location);.)
| "Private" (.m.Add(Modifiers.Private, t.Location);.)
| "Protected" (.m.Add(Modifiers.Protected, t.Location);.)
| "Public" (.m.Add(Modifiers.Public, t.Location);.)
| "NotInheritable" (.m.Add(Modifiers.Sealed, t.Location);.)
| "NotOverridable" (.m.Add(Modifiers.Sealed, t.Location);.)
| "Shared" (.m.Add(Modifiers.Static, t.Location);.)
| "Overridable" (.m.Add(Modifiers.Virtual, t.Location);.)
| "Overloads" (.m.Add(Modifiers.Overloads, t.Location);.)
| "ReadOnly" (.m.Add(Modifiers.ReadOnly, t.Location);.)
| "WriteOnly" (.m.Add(Modifiers.WriteOnly, t.Location);.)
| "WithEvents" (.m.Add(Modifiers.WithEvents, t.Location);.)
| "Dim" (.m.Add(Modifiers.Dim, t.Location);.)
.
PropertyAccessorAccessModifier<out Modifiers m> =
(. m = Modifiers.None; .)
{(
"Public" (. m |= Modifiers.Public; .)
| "Protected" (. m |= Modifiers.Protected; .)
| "Friend" (. m |= Modifiers.Internal; .)
| "Private" (. m |= Modifiers.Private; .)
)}
.
END VBNET.