A simple, dynamically typed scripting language with C-like syntax, inspired by the book "Writing An Interpreter In Go" by Thorsten Ball.
- C-like syntax with minimal punctuation
- Dynamic typing
- First-class functions and closures
- Higher-order functions
- Built-in data types: integers, booleans, strings, arrays, hashes
- Simple REPL environment
let x = 5;
let y = 10;
let name = "Monkey";
let isCool = true;
let array = [1, 2, 3, 4, 5];
let hash = {"name": "Monkey", "age": 5};
let add = fn(a, b) {
return a + b;
};
let fibonacci = fn(n) {
if (n == 0) { return 0; }
if (n == 1) { return 1; }
return fibonacci(n - 1) + fibonacci(n - 2);
};
puts("Fibonacci of 10 is:", fibonacci(10));- Go 1.13+ (for the reference implementation)
- Clone the repository:
git clone https://github.com/Neel-shetty/monkey.git
cd monkey- Build the interpreter:
go build -o monkey .REPL Mode:
./monkeyRun a script:
./monkey examples/hello.monkey- Integers:
let x = 42; - Booleans:
let flag = true; - Strings:
let name = "Monkey"; - Arrays:
let arr = [1, 2, 3]; - Hashes:
let person = {"name": "Alice", "age": 30};
Conditionals:
if (x > y) {
puts("x is greater");
} else {
puts("y is greater or equal");
}let greet = fn(name) {
return "Hello " + name + "!";
};
let applyTwice = fn(f, x) {
return f(f(x));
};puts(...): Print values to stdoutlen(x): Get length of string or arrayfirst(arr): Get first element of arrayrest(arr): Get all elements except firstpush(arr, val): Append value to array
See the examples/ directory for more code samples:
array.monkey: Array operations and higher-order functionsclosure.monkey: Demonstrates closureshashmap.monkey: Hash map data structure usagehello.monkey: Simple hello world examplemath.monkey: Basic mathematical operations
Contributions are welcome! Please open an issue or submit a pull request.
Monkey was created as part of the book "Writing An Interpreter In Go" by Thorsten Ball. This implementation is for educational purposes.