Fundamentals

These are the fundamental building blocks of ZScript. Included here are basic syntax elements such as Identifiers, and atoms, also known as Literals.

Lexical Elements

Character Types

NewLine

\n

EOF

End of the file.

Whitespace

NewLine, , \t, \v, \f, \r, EOF

AnyCharacter

Any Unicode code-point.

Character

!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, 0 ... 9, :, ;, <, =, >, ?, @, A ... Z, [, \, ], ^, _, `, a ... z, {, |, }, ~

Base8Character

0 ... 7

Base10Character

0 ... 9

Base16Character

a ... f, A ... F, 0 ... 9

Base16Prefix

x, X

IdentifierStartCharacter

a ... z, A ... Z, _

IdentifierCharacter

Identifiers

Identifiers are a sequence of contiguous characters that must be delimited by Whitespace or non-identifier characters.

Identifier

IdentifierStartCharacter IdentifierCharacter*

Tokens

All text in a file is lexically scanned into tokens. Each token is delimited by either Whitespace or another Token. For instance: > >>= will parse into two tokens, but >>>= will parse into one. Inversely, ..... will parse into ... and then .., but .. ... will parse into .. and .... Identifiers and Keywords must be delimited by Whitespace or non-IdentifierCharacters.

Token

Comments

LineComment

// AnyCharacter* NewLine

BlockComment

/* AnyCharacter* */

RegionComment

Keywords

Keyword

break, case, const, continue, default, do, else, for, goto, if, return, switch, until, volatile, while, bool, float, double, char, byte, sbyte, short, ushort, int8, uint8, int16, uint16, int, uint, long, ulong, void, struct, class, mixin, enum, name, string, sound, state, color, vector2, vector3, map, array, in, sizeOf, alignOf, abstract, forEach, true, false, none, auto, property, native, var, out, static, transient, final, extend, protected, private, dot, cross, virtual, override, varArg, ui, play, clearScope, virtualScope, super, stop, null, is, replaces, states, meta, deprecated, version, action, #include, readOnly, 3.4.0+ internal, 3.7.0+ flagDef

Symbols

Symbol

.., ..., >>>=, >>=, <<=, +=, -=, *=, /=, %=, &=, ^=, |=, >>>, >>, <<, ++, --, &&, ||, <=, >=, ==, !=, ~==, <>=, **, ::, ->, ;, {, }, ,, :, =, (, ), [, ], ., &, !, ~, -, +, *, /, %, <, >, ^, |, ?, #, @

Literals

Much like C or most other programming languages, ZScript has object literals, including string literals, integer literals, float literals, name literals, boolean literals, and the null pointer.

Literal

String Literals

String literals contain text data, and are encoded in UTF-8.

String literals, like C, will be concatenated when put directly next to each other. For example, "text 1" "text 2" will be parsed as a single string literal "text 1text 2".

StringLiteral

" StringCharacter* "

StringCharacter

String Literal Escapes

String literals have character escapes, which are formed with a backslash and a sequence of characters.

SpellingOutput
\"A literal ".
\\A literal \.
\aByte 0x07 (BEL - bell, anachronism.)
\bByte 0x08 (BS - backspace, anachronism.)
\cByte 0x1c (TEXTCOLOR_ESCAPE.)
\fByte 0x0c (FF - form feed, anachronism.)
\nByte 0x0a (LF - new line.)
\tByte 0x09 (HT - tab.)
\rByte 0x0d (CR - return.)
\vByte 0x0b (VT - vertical tab, anachronism.)
\?A literal ? (obsolete anachronism.)
\xnnByte 0xnn (hexadecimal.)
\nnnByte 0nnn (octal.)

To quote cppreference, "of the octal escape sequences, \0 is the most useful because it represents the terminating null character in null-terminated strings."

StringLiteralEscape

String-Like Literals

There are several types which have literals lexically the same as StringLiterals, but contextually are different.

StringLikeLiteral
ClassReferenceLiteral

StringLiteral

FontLiteral

StringLiteral

SoundLiteral

StringLiteral

Name Literals

Name literals are similar to string literals, though they use apostrophes instead of quote marks.

They do not concatenate like string literals, and do not have character escapes.

NameLiteral

' NameCharacter '

NameCharacter

Integer Literals

Integer literals are formed similarly to C. They may take one of three forms, and are typed uint or int based on whether there is a u at the end or not.

The parser also supports an optional l/L suffix as in C, though it does not actually do anything, and it is advised you do not use it for potential forward compatibility purposes.

Integer literals can be in the basic base-10/decimal form, base-16/hexadecimal form (which may use upper- or lower-case decimals and 0x prefix,) and base-8/octal form.

IntegerLiteral
IntegerSuffix

u, U, l, L

Floating-Point Literals

Float literals, much like integer literals, are formed similarly to C, but they do not support hex-float notation. Float literals do support exponent notation.

The parser supports an optional f/F suffix as in C, though it does not actually do anything, and it is advised you do not use it for potential forward compatibility purposes.

FloatingPointLiteral
ExponentPrefix

e, E

ExponentSign

-, +

Exponent

ExponentPrefix ExponentSign? Base10Character+

FloatSuffix

f, F

Boolean Literals

The two boolean literals are spelled false and true, and much like C, can decay to the integer literals 0 and 1.

BooleanLiteral
  • false
  • true

Null Literals

The null pointer literal is spelled null and represents an object that does not exist in memory. Like C, it is not equivalent to the integer literal 0, and is more similar to C++'s nullptr.

NullLiteral

null