Sven Vogel 5b24bd80ac | ||
---|---|---|
.vscode | ||
selib | ||
src | ||
.gitignore | ||
Cargo.lock | ||
Cargo.toml | ||
README.md | ||
prog.vsasm | ||
test.erpn | ||
test.yard |
README.md
Yard
Yard is an funny programming language compiler and interpreter written in pure Rust.
Its a functional language, having no concept of classes or inheritance. Types are static and must be known at compile time.
Primitve data types
The language has 4 primitive data types:
bool
a 1 byte boolean value which is either true or false. It can also be initalised with a random value at compile time iwhtmaybe
int
a 8 byte two's complement signed integer with 64-bit of storage spacerat
a 8 byte IEEE-754 double precision floating point valuestr
a dynamically sized immutable string wich for now can only be used with the concatonation operator..
NOTE: no custom data types such as structs or classes are supported.
Keywords
Syntax | Description | Example |
despite | Inverted if. Only executes the following block if the expression is false |
|
loop | While(true)-Loop. Loops forever until either yield, ret, break are used. Loop take no boolean expression. |
|
cont | Short form for “continue”. Jumps to the next iteration of a loop |
|
break | Exits a loop immediately |
|
yield | Returns from a function with an argument as return value |
|
ret | Short form for “return”. This keyword takes no argument and returns from a function. NOTE: if ret is used in a function with a return type, an error occurs. |
|
please | Decides on runtime wether a block should be executed or not. |
|
unless | Works like a while loop except inverted. it will only run if the condition is false. |
|
goto | jumps to a specified label |
|
Example code
-- compute the factorial
-- in a recursive and functional way
fac(x:int) = int {
despite x != 1 {
yield 1;
}
yield fac(x - 1) * x
}
number = rat 34 # this is a function without arguments and a braceless body
// main function
main = int {
result = fac(number);
println("The Factorial of " .. number .. " is: " .. result);
yield 0;
}