Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 1.04 KB

README.md

File metadata and controls

37 lines (27 loc) · 1.04 KB

Interpreter-rs

Documentation

A custom hand-written interpreter and compiler from scratch (based on "Building an interpreter in Go" by Thorsten Ball)

What is Interpreter-rs

This project is an interpreter and a compiler (these are separate language implementations that share the same parser) for an expression heavy dynamically typed language with python/rust like syntax.

What is supported

This language supports expressions, functions, assignment, recursion, closures as well as a few language built-ins. The interpreter/evaluator has a more complete implementation than the compiler currently.

Examples

Recursion Example with Fibbonacci

let fib = fn(n) {
   if n < 2 {
       n
   } else {
       fib(n-1) + fib(n-2)
   }
};
fib(25)

Closure Example

let new_adder = fn(x) { 
  fn(y) {x + y} // Implicit return of a function that adds y to the x (this is the magic of the closure)
}; 
let add_two = new_adder(2);
add_two(3) // -> returns 5