5.4.5.8 Print Statement
Note
This section describes the implementation of MS-VBAL §5.4.5.8 Print Statement.
Syntax
| Form | AST node | Instruction kind(s) | Notes |
|---|---|---|---|
Print # |
PrintStatementNode | Simple |
The file-number form. Token: Print. |
Print |
PrintStatementNode | Simple |
The bare form, with no file number (FileNumber is null): Print "x". See below. |
Owner.Print |
ObjectPrintExpressionNode | — | The object-qualified form. |
Debug.Print |
DebugPrintStatementNode | Simple |
The object-qualified form whose owner is Debug. |
The output list these nodes carry is described in 5.4.5.8.1 Output Lists below. See RD-VBAL §3.4.3 File Statements.
The bare Print
Whether there is a bare Print at all is the language's to say
(SupportedLanguage.HasBarePrint):
| Language | A Print with no file number |
|---|---|
| RD-VBA | Not a statement. Print is a reserved identifier of VBA, illegal as a name and with no semantics, and it is no recognized statement inside a procedure. (Only the Immediate window accepts it, as Debug.Print; that is not procedure scope.) It is VBC09331, the same as any other name the language does not declare. |
| VB6 | Undefined, for now: it is the Print member of the form or report it is written in, and the platform has no forms yet. |
| BASIC | A statement. It writes to the session's own output - the one Debug.Print writes to - by the same output rules (5.4.5.8.1). |
In BASIC it differs from Debug.Print in one way: it is not a debug statement, and is lowered in a release build, where Debug.Print leaves no
instruction at all (RD-VBAL §3.5.1 InstructionList). It is what an interactive shell - which is written in BASIC -
writes its output with: the shell's ? shorthand expands to it.
Instruction-list lowering is told the language the body is written in (InstructionLoweringOptions.Language, from the environment's
IRuntimeEnvironmentProfile.Language) and reports the undefined form; a body lowered for no language is lowered as written.
Note
Not implemented. StatementStaticSemanticsEvaluator does not report it, having no language to ask: the language server has no live caller of it yet. A document
module (a form, a report) with a Print member of its own is not yet the target of a bare Print written in it.
The ? shorthand has no lexer or grammar token: the shell expands it before the line is parsed.
Static Semantics
Note
Reserved. This section has no content yet.
Runtime Semantics
Note
Reserved. This section has no content yet.
Implementation
Print # writes through the channel's character output surface,
IFileChannelOutput, which it shares with
Write #. Width # sets that surface's maximum line length
(RD-VBAL §5.4.5 File Statements).
5.4.5.8.1 Output Lists
Note
This section describes the implementation of MS-VBAL §5.4.5.8.1 Output Lists.
PrintStatementNode and ObjectPrintExpressionNode share one output-list shape:
| Node | Represents |
|---|---|
| PrintOutputItemNode | An output item: a value and/or a ; or , separator. |
| PrintSpcClauseNode | A Spc clause. |
| PrintTabClauseNode | A Tab clause. |
Tip
In a parsed output list, 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
a value and its separator into one output item, but the generated parser never takes that alternative. A
consumer of Items should walk the alternating list rather than assume (value, separator) pairs.
See RD-VBAL §3.4.3 File Statements.
⏮️ RD-VBAL §5.4.5.7 Width Statement | ⏭️ RD-VBAL §5.4.5.9 Write Statement