Servostar / Yard

Yard is an funny programming language compiler written in pure Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yard

NOTE: Repository has been moved to: https://git.teridax.de/teridax/Yard Due to that, this repository is no longer maintained

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;
}

About

Yard is an funny programming language compiler written in pure Rust


Languages

Language:Rust 100.0%