3.4.0 Statements
A statement is an executable unit inside a member's body. Every statement node derives
StatementNode, which implements
IExecutableNode — its Inputs are the
expressions evaluated immediately before the statement executes. A block statement's nested statements
are held in a StatementBlock, independent
of Inputs.
Note
This page catalogs the AST shape the parser produces — it does not describe static or runtime semantics (coercion, error conditions, control flow). Those belong to the resolver and the interpreter, and are out of scope here.
3.4.1 Block Statements
Every block statement follows the same shape: its header condition(s)/expression(s) are named
properties, and its nested statements are a Body: StatementBlock — a deliberate consistency across
the whole family (MS-VBAL §5.4.2's block-statement group), rather than an undifferentiated children
list.
| Statement | Node type(s) | MS-VBAL |
|---|---|---|
If...Then...ElseIf...Else...End If |
IfBlockStatementNode, ElseIfBlockStatementNode, ElseBlockStatementNode | §5.4.2.8 |
While...Wend |
WhileWendStatementNode | §5.4.2.2 |
For...Next |
ForStatementNode | §5.4.2.3 |
For Each...Next |
ForEachStatementNode | §5.4.2.4 |
Do...Loop (5 header shapes: bare, Do While/Loop, Do Until/Loop, Do/Loop While, Do/Loop Until) |
DoLoopStatementNode, DoWhileLoopStatementNode, DoUntilLoopStatementNode, DoLoopWhileStatementNode, DoLoopUntilStatementNode | §5.4.2.6 |
Select Case...End Select |
SelectCaseStatementNode, CaseExpressionStatementNode, CaseElseClauseStatementNode | §5.4.2.10 |
With...End With |
WithStatementNode | §5.4.2.21 |
Single-line If...Then...Else |
InlineIfStatementNode — ThenBody/ElseBody may hold several colon-separated statements instead of a full block |
§5.4.2.9 |
Each Case line's comma-separated conditions are its own small hierarchy under the abstract
CaseRangeClauseNode: a single value
(CaseValueRangeClauseNode, e.g.
Case 5), a comparison
(CaseComparisonRangeClauseNode,
e.g. Case Is > 5), or an inclusive range
(CaseToRangeClauseNode, e.g.
Case 1 To 10) — all three independently, per MS-VBAL §5.4.2.10.
Tip
A bare line-number target in either branch (If x Then 100) is not modeled as its own shape — MS-VBAL
specifies it as equivalent to a GoTo statement targeting that line, so the parser synthesizes a real
GoToStatementNode as that branch's
(typically only) statement instead.
3.4.2 Simple Statements
| Statement | Node type | MS-VBAL |
|---|---|---|
Call / bare call |
CallStatementNode | §5.4.2.1 |
Let assignment ([Let] lExpression = expression) |
AssignmentStatementNode (Kind: ImplicitLet/ExplicitLet) |
§5.4.3.8 |
Set assignment |
AssignmentStatementNode (Kind: Set) |
§5.4.3.9 |
ReDim [Preserve] |
RedimDeclarationNode — modeled as a declaration, not a statement, since it declares/resizes storage | §5.4.3.3 |
Erase |
KeywordStatementNode (Token: Erase) |
§5.4.3.4 |
Name...As |
KeywordStatementNode (Token: Name) |
— (not a MS-VBAL-numbered statement) |
RaiseEvent |
KeywordStatementNode (Token: RaiseEvent) |
§5.4.2.20 |
Stop |
KeywordStatementNode (Token: Stop) |
§5.4.2.11 |
End |
KeywordStatementNode (Token: End) |
— (not a MS-VBAL-numbered statement) |
Exit Do/Exit For/Exit Sub/Exit Function/Exit Property |
KeywordStatementNode (Token: "Exit Do"/"Exit For"/"Exit Sub"/"Exit Function"/"Exit Property") |
§5.4.2.7/.5/.17/.18/.19 |
GoTo |
GoToStatementNode | §5.4.2.12 |
GoSub |
GoSubStatementNode | §5.4.2.14 |
Return |
ReturnStatementNode | §5.4.2.15 |
On Error GoTo <label> |
OnErrorGoToStatementNode | §5.4.4.1 |
On Error Resume Next |
OnErrorResumeStatementNode — the same grammar rule as On Error GoTo, disambiguated by which keyword follows |
§5.4.4.1 |
Bare Resume, Resume <label> |
ResumeStatementNode (LabelExpression nullable) |
§5.4.4.2 |
Resume Next |
ResumeNextStatementNode — its own node, not ResumeStatementNode with a "Next" label |
§5.4.4.2 |
Error # |
ErrorStatementNode | §5.4.4.3 |
Assignment's Target is always an lExpression — see RD-VBAL §3.0.2
for the shared expression family it draws from (member access, index, dictionary access, a bare name).
Statement labels and line numbers themselves are captured separately
(LineLabelNode/
LineNumberNode) — a GoTo/GoSub's own
target is just an expression naming or numbering one, with no static link between the two.
Note
Computed On...GoTo/On...GoSub (§5.4.2.13/.16) have no node type at all yet — not yet requested.
Note
Mid/Mid$/LSet/RSet (§5.4.3.5/.6/.7) are assignment-shaped statements with no node type yet —
unblocked now that a real lExpression exists as their left-hand side, but not yet built.
3.4.3 File Statements
MS-VBAL groups file I/O under one umbrella, §5.4.5 File Statements.
| Statement | Node type | MS-VBAL |
|---|---|---|
Open |
OpenStatementNode — Mode/Access/Lock are keyword choices (VBFileMode, VBFileAccessMode, VBFileLockMode), not expressions |
§5.4.5.1 |
Close, Reset |
KeywordStatementNode (Token: Close/Reset) |
§5.4.5.2 |
Seek |
KeywordStatementNode (Token: Seek) |
§5.4.5.3 |
Lock, Unlock |
KeywordStatementNode (Token: Lock/Unlock) |
§5.4.5.4/.5 |
Line Input # |
KeywordStatementNode (Token: LineInput) |
§5.4.5.6 |
Width # |
KeywordStatementNode (Token: Width) |
§5.4.5.7 |
Print #, Debug.Print |
PrintStatementNode (Token: Print) for the file-number form, ObjectPrintExpressionNode for the object-qualified form (Owner.Print, e.g. Debug.Print) |
§5.4.5.8 |
Write # |
PrintStatementNode (Token: Write) |
§5.4.5.9 |
Input # |
KeywordStatementNode (Token: Input) |
§5.4.5.10 |
Put # |
KeywordStatementNode (Token: Put) |
§5.4.5.11 |
Get # |
KeywordStatementNode (Token: Get) |
§5.4.5.12 |
PrintStatementNode/ObjectPrintExpressionNode share an output-list shape:
PrintOutputItemNode (a value and/or
a ;/, separator), PrintSpcClauseNode,
PrintTabClauseNode.
Tip
A value and its trailing separator are always two separate, alternating PrintOutputItemNodes (one
value-only, one separator-only) — MS-VBAL's outputItem grammar rule admits combining them into one
node, but the generated parser never actually takes that alternative. Any consumer of Items should
walk the alternating list rather than assume (value, separator) pairs.
Note
The ? shorthand for Print has no lexer/grammar token at all in the current grammar — adding it
is a lexer-level change, riskier and different in kind from AST/listener work, and is deliberately
deferred.
⏮️ RD-VBAL §3.3 Operators | ⏭️ RD-VBAL §4.0 Program Structure