toylang is an interpreted programming language created for the purpose of learning about grammar parsing, abstract syntax trees, and other things related to the implementation of programming languages.
Basic assignment and printing:
let some_string = "Hello, world";
println some_string;
Fizzbuzz:
func print_fizzbuzz(n: num) {
if n % 15 == 0 {
println "FizzBuzz";
} elif n % 3 == 0 {
println "Fizz";
} elif n % 5 == 0 {
println "Buzz";
} else {
println n;
}
}
let i = 1;
while i <= 100 {
print_fizzbuzz(i);
i += 1;
}
Functions can be higher-order, so you can do this:
func inc(x: num) {
return x + 1;
}
func twice(f: func(num), x: num) {
return f(f(x));
}
println twice(inc, 40); // Prints 42
if
/ elif
/ else
statementswhile
loopsread
builtin)for
loops