Xelis is an interpreted language developed in Rust. It supports constants, functions, while/foreach loops, arrays and structures. The syntax is strongly inspired by Rust and Golang.
All the verifications are mainly made at the level of the Parser to check the conformity of the code to be interpreted.
The different primitive types are:
byte
(unsigned 8-bytes integer)short
(unsigned 16-bytes integer)int
(unsigned 64-bytes integer)long
(unsigned 128-bytes integer)bool
string
struct
File extension is .xel
the semicolon is not mandatory, but can be added if desired without any difference in the code.
Recursive functions are allowed, but limited to a configurable depth.
An error will be returned by the interpreter if an overflow is detected without causing a panic.
- The value must be greater than or equal to
0
. - You can put
_
(underscore) for a better readability. - If no type is specified on the value, then
int
will be the default.
let my_byte: byte = 10
let my_short: short = 70
let my_int: int = 25655
let my_long: long = 100_000_000L
for constant variable, it must be declared outside a function, with const
keyword.
- Every variable must be declared with
let
orconst
keyword. - Variable name must alphanumeric characters.
- Must provide value type.
- If no value is set,
null
is set by default.
const hello: string = "hello"
...
let world: string = "world"
entry
function is a "public callable" function and must return a int
value.
- Must starts with
func
orentry
keyword. - Signature is based on function name and parameters.
- For type functions, the type must not be primitive.
- Recursive functions are allowed.
entry foo() { ... }
func foo() { ... }
func foo(): int { ... }
func foo(a: int, b: int) { ... }
func (f Foo) bar() { ... }
A structure can contain other structures.
- The name must be unique.
- Name should start with a uppercase letter.
- Only letters are allowed in name.
- The last field does not need a comma.
struct MyStruct {
message: string,
value: int
}
- A
bool
condition is required. - The two values that can be returned must be of the same type.
let score: int = is_winner() ? 20 : 0
- A
bool
condition is required after it.
let negative: bool = !condition
- All values must be of the same specified type.
let array: int[] = [10, 20, 30, 40]
...
let dim: int[][] = [[34, 17], [8, 14], [0, 69]]
- Have a
bool
condition.
if condition {
...
}
if (i > 20 && i != 25) || i == 0 {
...
}
- It must be preceded by an
if
condition.
else {
...
}
- It must be preceded by an
if
or anelse if
condition. - Have a boolean condition.
else if condition {
...
}
else if my_struct != null {
...
}
- Have a boolean condition.
while condition {
...
}
- Have the name of a variable.
- Have an array to go through
foreach val in values {
...
}
- Have the name of a variable.
- Have a boolean condition.
- Have an assign operator.
for i: int = 0; i < 10; i += 1 {
...
}
- Must be in a loop (
foreach
,for
,while
).
while condition {
if i % 10 == 0 {
break;
}
...
}
- Must be in a loop (
foreach
,for
,while
).
while condition {
if i % 10 == 0 {
continue;
}
...
}
- Must not have any code after.
- If the function returns a value, the return must return a value.
func foo(): string {
return "Hello World!"
}
func bar() {
if condition {
return
}
foo()
}
Allows you to isolate a part of the code / variables created.
- No specific rules.
{
...
}