yorkie is a toy language.
MIT License
# Top level expressions
4+5;
# Control Flow - if/then/else
if x < 3 then
1
else
2
end
# Forward declarations and calling 'C' code
extern sin(x) # Because we link against libm, we can use that function natively here!
sin(10)
# Control Flow - for loops
# (initial value), (end condition), (optional step value)
for i = 1, i < n, 1.0 in
putchard(i)
end
# User defined unary operators
def unary-(v)
0-v
end
# User defined binary operators
def binary> 10 (LHS RHS)
RHS < LHS
end
# Functions
# Compute the x'th fibonacci number.
def fib(x)
if x < 3 then
1
else
fib(x-1)+fib(x-2)
end
end
# This expression will compute the 40th number.
fib(40)
# Mutable variables
def foo()
var x = 10 in
x = 11
end
end
cmake .
make
./yorkie < examples/fib.yk 2>&1 | clang -x ir -
./a.out
cmake .
cmake --build .
ctest -VV