🐵 Monkey programming language interpreter designed in Writing An Interpreter In Go and Writing a Compiler in Go. A step-by-step walk-through where each commit is a fully working part. Read the books…
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
James Mills afd29dcfe1 Set theme jekyll-theme-hacker 4 years ago
ast Move project to Github 4 years ago
eval Added support for UTF-8 strings in len() function. Fixes #1 4 years ago
examples Added two examples of Fibonacci (recursion and tail recursion) 4 years ago
lexer Move project to Github 4 years ago
object Move project to Github 4 years ago
parser Move project to Github 4 years ago
repl Improved build and added version support. Added support for executing files and some cli options 4 years ago
token 4.5 Hash Maps 4 years ago
.drone.yml Migrate to Drone CI, Codecov and Go11Modules 4 years ago
.gitignore Improved build and added version support. Added support for executing files and some cli options 4 years ago
LICENSE Move project to Github 4 years ago
Makefile Improved build and added version support. Added support for executing files and some cli options 4 years ago
README.md Update README.md 4 years ago
_config.yml Set theme jekyll-theme-hacker 4 years ago
go.mod Migrate to Drone CI, Codecov and Go11Modules 4 years ago
main.go Improved build and added version support. Added support for executing files and some cli options 4 years ago
version.go Improved build and added version support. Added support for executing files and some cli options 4 years ago

README.md

monkey-lang

Build Status CodeCov Go Report Card GoDoc Sourcegraph

Monkey programming language interpreter designed in Writing An Interpreter In Go. A step-by-step walk-through where each commit is a fully working part. Read the book and follow along with the commit history.

Usage

To build run make.

$ go get -u github.com/prologic/monkey-lang
$ cd $GOPATH/github.com/prologic/monkey-lang
$ make
This is the Monkey programming language!
Feel free to type in commands
>> 

To run the tests run make test

You can also execute program files by invoking monkey-lang <filename> There are also some command-line options:

$ ./monkey-lang -h
Usage: monkey-lang [options] [<filename>]  -d	enable debug mode
  -i	enable interactive mode
  -v	display version information

Monkey Language

See also: examples

Variable bindings and arithmetic expressions

>> let a = 10;
>> let b = a * 2;
>> (a + b) / 2 - 3;
12
>> let c = 2.5;
>> b + c
22.5

If expressions

>> let a = 10;
>> let b = a * 2;
>> let c = if (b > a) { 99 } else { 100 };
>> c
99

Functions and closures

>> let multiply = fn(x, y) { x * y };
>> multiply(50 / 2, 1 * 2)
50
>> fn(x) { x + 10 }(10)
20
>> let newAdder = fn(x) { fn(y) { x + y }; };
>> let addTwo = newAdder(2);
>> addTwo(3);
5
>> let sub = fn(a, b) { a - b };
>> let applyFunc = fn(a, b, func) { func(a, b) };
>> applyFunc(10, 2, sub);
8

Strings

>> let makeGreeter = fn(greeting) { fn(name) { greeting + " " + name + "!" } };
>> let hello = makeGreeter("Hello");
>> hello("skatsuta");
Hello skatsuta!

Arrays

>> let myArray = ["Thorsten", "Ball", 28, fn(x) { x * x }];
>> myArray[0]
Thorsten
>> myArray[4 - 2]
28
>> myArray[3](2);
4

Hashes

>> let myHash = {"name": "Jimmy", "age": 72, true: "yes, a boolean", 99: "correct, an integer"};
>> myHash["name"]
Jimmy
>> myHash["age"]
72
>> myHash[true]
yes, a boolean
>> myHash[99]
correct, an integer

Builtin functions

>> len("hello");
5
>> len("∑");
1
>> let myArray = ["one", "two", "three"];
>> len(myArray)
3
>> first(myArray)
one
>> rest(myArray)
[two, three]
>> last(myArray)
three
>> push(myArray, "four")
[one, two, three, four]
>> puts("Hello World")
Hello World
nil

License

This work is licensed under the terms of the MIT License.