I made this compiler in typescript, i imagine building it in Rust or C, right now am learning Rust, I might consider remaking the compiler in it maybe in the future.
To print "hello world" in ExpressL, use the print()
function:
print("hello world")
Variables in ExpressL are declared using the let
and const
keyword followed by the variable name and its initial value: Variables declared with const cannot be redefined:
let foo = 45;
const bar = 56;
let foobar = foo + bar;
print(foobar)
Functions in ExpressL are defined using the @fn
keyword followed by the function name and its body enclosed in curly braces {}. You can call the function by using its name followed by parentheses ().
@fn hello() {
print("my new function")
}
hello()
Error handling in ExpressL uses attempt...rescue syntax. You can wrap code in an attempt block and catch errors with a rescue block.
@fn try(x, y) {
attempt {
let result = x + y;
print(result)
} rescue {
print(error)
}
}
print(try(10, 5))
Conditions in ExpressL use when...otherwise syntax. provide conditions using when
keyword and provide an alternative using the otherwise
keyword. In this example, the nested when...otherwise
block acts as an else if
structure
when (x > 10) {
print("x is greater than 10")
} otherwise {
when (x < 10) {
print("x is less than 10")
} otherwise {
print("x is equal to 10")
}
}