sector-f / toylang

The most-creatively-named toy language in the world
3 stars 3 forks source link

toylang

About

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.

Examples

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

Features

To-Do