Yard is an funny programming language compiler written in pure Rust
Go to file
Sven Vogel 5b24bd80ac fixed minor issues 2023-05-03 12:46:27 +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 fixed minor issues 2023-05-03 12:46:27 +02:00
.gitignore added loop and break keyword to vmrt 2022-12-06 22:48:52 +01:00
Cargo.lock proper error message added 2022-10-12 09:33:33 +02:00
Cargo.toml added operator typehinting 2022-12-06 15:02:03 +01:00
README.md fixed runtime stack missalignment 2023-01-02 12:56:53 +01:00
prog.vsasm fixed runtime stack missalignment 2023-01-02 12:56:53 +01:00
test.erpn fixed minor issues 2023-05-03 12:46:27 +02:00
test.yard fixed minor issues 2023-05-03 12:46:27 +02: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;
}