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
- 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
-
- IdentifierStartCharacter
0
...9
Identifiers
Identifiers are a sequence of contiguous characters that must be delimited by Whitespace or non-identifier characters.
- Identifier
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
-
#region
AnyCharacter* NewLine#endRegion
AnyCharacter* NewLine
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.
Spelling | Output |
---|---|
\" | A literal " . |
\\ | A literal \ . |
\a | Byte 0x07 (BEL - bell, anachronism.) |
\b | Byte 0x08 (BS - backspace, anachronism.) |
\c | Byte 0x1c (TEXTCOLOR_ESCAPE .) |
\f | Byte 0x0c (FF - form feed, anachronism.) |
\n | Byte 0x0a (LF - new line.) |
\t | Byte 0x09 (HT - tab.) |
\r | Byte 0x0d (CR - return.) |
\v | Byte 0x0b (VT - vertical tab, anachronism.) |
\? | A literal ? (obsolete anachronism.) |
\xnn | Byte 0xnn (hexadecimal.) |
\nnn | Byte 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
-
\"
\\
\a
\b
\c
\f
\n
\t
\r
\v
\?
\
Base16Prefix Base16Character{1..2}\
Base8Character{1..3}\
NewLine
String-Like Literals
There are several types which have literals lexically the same as StringLiterals, but contextually are different.
- StringLikeLiteral
- ClassReferenceLiteral
- FontLiteral
- SoundLiteral
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
-
\'
- AnyCharacter
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
-
0
Base8Character+ IntegerSuffix{0..2}- Base10Character+ IntegerSuffix{0..2}
0
Base16Prefix Base16Character+ IntegerSuffix{0..2}
- 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
- 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