Skip to content

An implementation of the monkey programming language (from the book, "Writing an Interpreter in Go")

License

Notifications You must be signed in to change notification settings

anthonyabeo/monkeylang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

THE MONKEY PROGRAMMING LANGUAGE

This project is my implementation of the monkey programming language (monkeylang) in D. monkeylang is interpreted programming language from the books "Writing an Interpreter in Go" and "Writing a compiler in Go" by Thorsten Ball.

SETUP

The tools needed to test and run this project are:

TESTING AND RUNNING

With dub installed run the unit tests using dub test from the root directory. You should get an output similar to the one below.

$ dub test
Generating test runner configuration 'monkey-test-library' for 'library' (library).
Performing "unittest" build using /usr/local/bin/ldc2 for x86_64.
monkey ~master: building configuration "monkey-test-library"...
Linking...
Running ./monkey-test-library 
All unit tests have been run successfully.

Then run with dub like so:

$ dub
Hello! This is the Monkey programming language!
Feel free to type in commands

>>> puts("Hello World!")
Hello World!
>>> 

PERFORMANCE BENCHMARKS

The Fibonacci(35) is run on using the Compiler/VM combo VS the interpreter;

Compiler/VM

$ dub run --compiler=ldc2 --build=release-nobounds -- --engine=vm

result=9227465, 
duration=9 secs, 914 ms, and 704 μs

Interpreter

$ dub run --compiler=ldc2 --build=release-nobounds -- --engine=eval

result=9227465, 
duration=2 minutes, 49 secs, 647 ms, and 426 μs

MONKEYLANG IN ACTION

// Integers & arithmetic expressions
let version = 1 + (50 / 2) - (8 * 3);

// Strings
let name = "The Monkey programming language";

// Booleans
let isMonkeyFastNow = true;

// Arrays & Hashes
let people = [{"name": "Anna", "age": 24}, {"name": "Bob", "age": 99}];

// Functions
let getName = fn(person) { person["name"]; };
getName(people[0]); // => "Anna"
getName(people[1]); // => "Bob"

// `newAdder` returns a closure that makes use of the free variables `a` and `b`:
let newAdder = fn(a, b) {
    fn(c) { a + b + c };
};
// This constructs a new `adder` function:
let adder = newAdder(1, 2);

adder(8); // => 11

About

An implementation of the monkey programming language (from the book, "Writing an Interpreter in Go")

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages