https://github.com/zhuzilin/monkey
A C++ version monkey language interpreter. From Write An Interpreter In Go
https://github.com/zhuzilin/monkey
interpreter lexer parser write-an-interpreter-in-go
Last synced: about 1 month ago
JSON representation
A C++ version monkey language interpreter. From Write An Interpreter In Go
- Host: GitHub
- URL: https://github.com/zhuzilin/monkey
- Owner: zhuzilin
- License: mit
- Created: 2019-07-27T07:19:49.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-14T02:21:25.000Z (almost 5 years ago)
- Last Synced: 2025-04-03T03:23:07.560Z (3 months ago)
- Topics: interpreter, lexer, parser, write-an-interpreter-in-go
- Language: C++
- Size: 3.84 MB
- Stars: 36
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# monkey
A C++ version [monkey](https://monkeylang.org/) language interpreter. From [Write An Interpreter In Go](https://interpreterbook.com/).
With additional mark-and-sweep garbage collection.
## Usage
You can use the vscode config to build and run the interpreter. Or
```bash
> g++ -std=c++11 main.cpp src/*.cpp -o monkey --debug
> ./monkey test.mk
hello world!
minimal prime factor for 1321231 is 487return:
type: NULL
value: NULL
```
The `test.mk` is function to get minimal prime factor.
```js
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
* [x] Add garbage collection.
* [x] Add array support.
* [x] Add buildin functions.
* [ ] Add dictionary support.
* [ ] Add error handling for lexer.