Table of Contents

3.2.0 Literal Expressions

LiteralExpressionNode is the AST node for MS-VBAL §5.6.5 Literal Expressions (RD-VBAL §5.6.5 Literal Expressions). A LiteralExpressionNode represents a value that is statically resolved to a VBTypedValue.

The parser resolves a literal's declared type from the source token. A LiteralExpressionNode already carries a fully-typed VBTypedValue when the parser produces it. That value includes the effect of any type-declaration character.

3.2.0.1 Numeric Literal Types

The declared type of a numeric literal follows MS-VBAL §3.3.2 Number Tokens. A numeric literal's type is fixed by the literal's own form (a type-declaration suffix, the presence of a decimal point or exponent, or a radix prefix) before any context is considered. Because of this, overflow is a property of the literal alone, and is caught while the syntax tree is built (VBC00042 Numeric literal overflow).

The declared type of a numeric literal is determined as follows:

  1. An explicit type-declaration character suffix, if present, forces the literal's declared type. A literal whose value does not fit its suffix-forced type is a syntax error, NumericLiteralOverflow (VBC00042), located at the literal. For example, the % suffix denotes Integer, whose maximum is 32767.

    Suffix Declared type
    % Integer
    & Long
    ^ LongLong
    ! Single
    # Double
    @ Currency
  2. Otherwise, an unsuffixed decimal integer literal (no fractional part, no exponent) takes the smallest of Integer, Long, Double that can hold its value.

  3. Otherwise, a floating-point literal (a literal with a fractional part or an exponent) is Double.

    • The exponent letter is one of [DEde].
    • D is the legacy double-precision marker. It produces the same value as E.
    • A floating-point literal that overflows to infinity is a NumericLiteralOverflow syntax error.
  4. A &H… hexadecimal or &O… octal (radix) literal is typed by bit width, not by the decimal rule (rule 2). Its radix digits are interpreted as a two's-complement value at the literal's bit width.

Radix Literals

An unsuffixed &H… / &O… literal is the narrowest of Integer (16-bit) or Long (32-bit) that the value's bit width fits:

Literal Declared type Value
&HFFFF Integer -1
&H8000 Integer -32768
&H10000 Long 65536
&HFFFFFFFF Long -1

&HFFFFFFFF is the largest unsuffixed radix literal. An unsuffixed radix literal beyond 32 bits, such as &HFFFFFFFFF, is a NumericLiteralOverflow syntax error. A 64-bit LongLong radix literal requires the ^ suffix.

A suffix sets a radix literal's width:

Suffix Width
% 16 bits
& 32 bits
^ 64 bits

A radix literal is never Double.

Note

LongLong is only produced by the ^ suffix. An unsuffixed integer literal that exceeds Long range widens to Double, never LongLong.

String and $-suffixed identifiers are covered by the declared-type rules for String, not by the numeric literal type rules.

3.2.0.2 Static Symbols

The environment host defines a number of globally defined static symbols (StaticSymbol). They are defined on top of the global IStdConstantsModule.

Literal (token) Type Value
True, False VBBooleanType VBBooleanValue
VBEmptyString VBStringType VBStringValue
Null VBNullType VBNullValue
Empty VBVariantType VBEmptyValue
Nothing VBObjectType VBNothingValue

The parser resolves the Null literal keyword to a LiteralExpressionNode carrying a VBNullValue, so a Null value can be written as a literal, for example as a Select Case selector (RD-VBAL §5.4.2.10 Select Case Statement).

3.2.0.2.1 Instance Expressions

See RD-VBAL §5.6.11 Instance Expressions.


⏮️ RD-VBAL §3.1.1 Attributes | ⏭️ RD-VBAL §3.3.0 Operator Expressions