Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An interpreter for the monkey language

Based off of the Writing an Interpreter in Go book, by Thorsten Ball.

Examples:

Hello, World

puts("Hello, world");

Variable declaration

let x = 1;
let b = true;
let b = false;

Boolean expressions

let x = 1 == 1; // true
let x = 1 >= 2; // true
let x = 1 <= 2; // true
let x = 2 == 1; // false
let x = 2000 != 2000 // false

Arithmetic expressions

let x = 1 + 1; // 2
let x = -12 + 2; // -10
let x = 4 * 2 + 1; // 9
let x = 16 / 2 - 1; // 7 
let x = (2 * 2) + 3; // 7

Conditional if expressions

let x = 12;
if x > 10 {
    x = x + 1;
} else {
    x = x - 1;
}

let x = if true {
        1
    } else {
        0
    }

Functions

let adder = fn (x) {
    return fn (y) {
        return x + y
    }
}

let addOne = adder(1);
addOne(6);