Yard is an funny programming language compiler written in pure Rust
Go to file
Sven Vogel 5a3c4bffd6 relative include paths now get resolved properly 2024-04-17 22:31:32 +02:00
.gitea/workflows cleaned up repository 2023-09-03 14:28:48 +02:00
.vscode added shunting yard expr parser 2022-10-03 14:11:49 +02:00
selib finished yard 2023-01-02 12:06:30 +01:00
src relative include paths now get resolved properly 2024-04-17 22:31:32 +02:00
tests added example files for @include 2023-09-14 14:50:31 +02:00
.gitignore updated crate name to lowercase 2023-09-14 10:10:17 +02:00
Cargo.toml updated crate name to lowercase 2023-09-14 10:10:17 +02:00
README.md fixed runtime stack missalignment 2023-01-02 12:56:53 +01:00

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 iwht maybe
  • int a 8 byte two's complement signed integer with 64-bit of storage space
  • rat a 8 byte IEEE-754 double precision floating point value
  • str 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

SyntaxDescriptionExample
despiteInverted if. Only executes the following block if the expression is false
despite 3 > 4 {
    // code block
}
loopWhile(true)-Loop. Loops forever until either yield, ret, break are used.
Loop take no boolean expression.
loop {
    // code block
}
contShort form for “continue”. Jumps to the next iteration of a loop
loop {
    cont;
}
breakExits a loop immediately
loop {
    break;
}
yieldReturns from a function with an argument as return value
foo() = int {
    yield 4
}
retShort 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.
foo() {
    ret    // exit function
}
pleaseDecides on runtime wether a block should be executed or not.
please {
    // code
}
unlessWorks like a while loop except inverted. it will only run if the condition is false.
unless x > 5 {
    // code
}
gotojumps to a specified label
'label
// code
goto 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;
}