Lexical Structure
Keywords
- Directives/Declarators:
importclass,struct,enum,interface,mixin,unittest,alias,thread,function,method,operator,let,var - Access Control:
public,private,module,package - Storage Classes:
meta,ref,out,scope - Control Flow:
for,loop,break,continue,return,throw,try,catch,if,else,switch,case,default,defer - Built-In Values:
this,super,null,true,false - Basic Types:
type,void,bool,byte,ubyte,short,ushort,int,uint,long,ulong,__size,__sizediff,float,double,real,char,wchar,dchar,noreturn - Typeof Expression:
typeof - Type Qualifiers:
isolated,escape,immutable,const,shared,synchronized - Type Casting:
cast
Punctuation
- Operators:
&&,||,?,!,~,+,-,*,/,%,&,|,^,^^,<<,>>,=,+=,-=,*=,/=,%=,&=,|=,^=,~=,^^=,<<=,>>=,++,--,==,!=,<=,<,>,>=,<>,is,!is,=>,[,],.. - Delimiters:
.,:,,,;,(,),{,} - Other:
$,#,@,...
Identifiers
Identifiers must start with an alphabetic Unicode character or with an
underscore (_) and can contain any number of alpanumeric characters and
underscores. An identifier cannot be identical to one of the keywords listed
above.
Identifiers starting with two consecutive underscores (__) are reserved to
the language/runtime implementation and should not be used for user defined
symbols. Unless explicitly specified, the name of symbols starting with two
underscores is implementation defined.
Constant Literals
true: Value of typeboolequivalent to onefalse: Value of typeboolequivalent to zeronull: Value of typetypeof(null)representing a pointer to the zero address, which is equivalent to a pointer to "nothing"
Numeric Literals
The following types of numeric literals are available:
Decimal Integers:
These consist of either a single zero (
0), or a non-zero digit followed by zero or more digits.Hexadecimal Integers:
Hexadecimal integers start with a
0xsequence, followed by at least one decimal digit or an upper or lower case letter from "a" to "f".Example:
0x1FDecimal Floating-Point Numbers:
Follows the C formatting of floating-point numbers. An optional 'f' suffix can be used to force the type of the literal to
float, rather than the defaultdouble.Examples:
1.2e-3,3.1415f
String Literals
Double Quoted Strings:
Escaped strings are the default string type, delimited by double-quotes. They support C-style escape sequences, as well as Unicode escape sequences.
Example:
"This is a string\nwith two lines. Smiley: \u1F600"In addition to escape sequences, double quoted strings also support string interpolation sequences started by
$(, followed by an arbitrary expression and terminated by a matching).Example:
"The time is $(getTime())."RAW Strings:
Raw strings are arbitrary character sequences delimited by a backtick character. No escaping or string interpolation is performed on the contained character sequence.