2.1. Lexical Structure
2.1.1. Identifiers
Identifiers start with an alphabetic character (and not the symbol ‘_’) followed by any number of alphabetic characters, ‘_’ or digits ([0-9]). Daslang is a case sensitive language meaning that the lowercase and uppercase representation of the same alphabetic character are considered different characters. For instance, “foo”, “Foo” and “fOo” are treated as 3 distinct identifiers.
2.1.2. Keywords
The following words are reserved as keywords and cannot be used as identifiers:
struct |
class |
let |
def |
while |
if |
static_if |
else |
for |
recover |
true |
false |
new |
typeinfo |
type |
in |
is |
as |
elif |
static_elif |
array |
return |
null |
break |
try |
options |
table |
expect |
const |
require |
operator |
enum |
finally |
delete |
deref |
aka |
typedef |
with |
cast |
override |
abstract |
upcast |
iterator |
var |
addr |
continue |
where |
pass |
reinterpret |
module |
public |
label |
goto |
implicit |
shared |
private |
smart_ptr |
generator |
yield |
unsafe |
assume |
explicit |
sealed |
static |
inscope |
fixed_array |
typedecl |
capture |
default |
uninitialized |
template |
The following words are reserved as type names and cannot be used as identifiers:
bool |
void |
string |
auto |
int |
int2 |
int3 |
int4 |
uint |
bitfield |
uint2 |
uint3 |
uint4 |
float |
float2 |
float3 |
float4 |
range |
urange |
block |
int64 |
uint64 |
double |
function |
lambda |
int8 |
uint8 |
int16 |
uint16 |
tuple |
variant |
range64 |
urange64 |
Keywords and types are covered in detail later in this document.
2.1.3. Operators
Daslang recognizes the following operators:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2.1.5. Literals
Daslang accepts integer numbers, unsigned integers, floating and double point numbers and string literals.
|
Integer number(base 10) |
|
Unsigned Integer number(base 16) |
13l |
Long Integer number(base 10) |
|
Long Unsigned Integer number(base 16) |
32u8 |
Unsigned 8-byte integer |
|
Integer number |
|
Floating point number |
|
Floating point number |
|
Floating point number |
|
Double point number |
|
Double point number |
|
Double point number |
|
String |
|
String |
Pseudo BNF:
IntegerLiteral ::= [1-9][0-9]* | '0x' [0-9A-Fa-f]+ | ''' [.]+ ''' | 0[0-7]+ FloatLiteral ::= [0-9]+ '.' [0-9]+ FloatLiteral ::= [0-9]+ '.' 'e'|'E' '+'|'-' [0-9]+ StringLiteral ::= '"'[.]* '"' VerbatimStringLiteral ::= '@''"'[.]* '"'
2.1.6. Comments
A comment is text that the compiler ignores, but is useful for programmers. Comments are normally used to embed annotations in the code. The compiler treats them as white space.
A comment can be /*
(slash, asterisk) characters, followed by any
sequence of characters (including new lines),
followed by the */
characters. This syntax is the same as ANSI C:
/*
This is
a multiline comment.
This lines will be ignored by the compiler.
*/
A comment can also be //
(two slash) characters, followed by any sequence of
characters. A new line not immediately preceded by a backslash terminates this form of
comment. It is commonly called a “single-line comment”:
// This is a single line comment. This line will be ignored by the compiler.
2.1.7. Semantic Indenting and Significant White Space
Daslang in gen2 automatically places semicolumns inside the code, enclosed with a curly bracers; unless its also enclosed in any type of brackets:
def foo {
var a = 0 // das lang will add ; here
var b = 1; // redundant ;
var c = ( 1 // no automatic ; here
+ 2 ) * 3; // redundant ;
}
Daslang in gen1 sytnax follows semantic indenting (much like Python). That means that logical blocks are arranged with the same indenting, and if a control statement requires the nesting of a block (such as the body of a function, block, if, for, etc.), it has to be indented one step more. The indenting step is part of the options of the program. It is either 2, 4 or 8, but always the same for whole file. The default indenting is 4, but can be globally overridden per project.