Skip to content
A C++ version monkey language interpreter. From Write An Interpreter In Go
C++ Makefile
Branch: master
Clone or download
Latest commit 820b920 Aug 6, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode add print Jul 29, 2019
header add print Jul 29, 2019
src add print Jul 29, 2019
.gitignore Initial commit Jul 27, 2019
LICENSE Initial commit Jul 27, 2019
README.md Update README.md Aug 5, 2019
main.cpp add print Jul 29, 2019
monkey
repl.cpp add gc and fix function bug Jul 28, 2019
rlpl.cpp initial commit Jul 27, 2019
rppl add basic array Jul 28, 2019
rppl.cpp initial commit Jul 27, 2019
test.mk add print Jul 29, 2019

README.md

monkey

A C++ version monkey language interpreter. From Write An Interpreter In Go. With additional mark-and-sweep garbage collection.

Usage

You can use the vscode config to build and run the interpreter. Or

> g++ -std=c++11 main.cpp src/*.cpp -o monkey --debug
> ./monkey test.mk
hello world!
minimal prime factor for 1321231 is 487 

return: 
type:  NULL
value: NULL

The test.mk is function to get minimal prime factor.

print("hello world!");

let a = 1321231;

// find mininum factor that is greater than 1
let minFactor = fn (a) {
	let i = 2;
	while(true) {
		if (a % i == 0) { 
			return i;
		}
		let i = i + 1;
	}
}

let f = minFactor(a);

if (f == a) {
	print(a, "is a prime!");
} else {
	print("minimal prime factor for", a, "is", f);
}

And repl.cpp is the REPL(Read-Eval-Print Loop) main function, to only use parser or lexer, you can change to rppl.cpp or rlpl.cpp.

TODOs

  • Add garbage collection.
  • Add array support.
  • Add buildin functions.
  • Add dictionary support.
  • Add error handling for lexer.
You can’t perform that action at this time.