A simple interpreter for the 🐒 Monkey Language (described in the book Writing an Interpreter in Go by Thorsten Ball
) written in 🐍 Python.
You can install the interpreter through pip
by:
pip install -U prymate
You can also get the latest version through this git repo, and building the package yourself through poetry.
Tests are included in the tests subfolder in this repository.
You can run the said tests by cloning the repo, and executing the run_tests.bat
file on Windows, and run_tests.sh
on Linux/Mac OS.
You can start the Monkey Language REPL through the command prymate
with no arguments.
$ prymate
Prymate 0.4.1 [Running on Windows]
Type exit() to exit from the REPL.
>>> puts("Hello, World!")
Hello, World!
null
Or, you can run a file by specifying the file path through the -f
or --file
argument.
$ prymate -f <path to file>
...
Prymate interprets the canon monkey language without any hitch and adds on top of it. All the features in the canon monkey language can be used with prymate.
Additions:
-
Additional Inbuilt Functions like
help, exit, type, gets, sumarr, zip, int, str, and more.
-
String
!=
and==
operations are supported. -
Modulo
%
for determining the remainder of the expressiona / b
. -
Floating point literals (type
FLOAT
in the interpreter). -
Variable mutability (Reassign an already declared variable, a value).
-
While Loops.
-
Constants
I plan to add support for more things in the future. Examples for the above additions coming soon.
v0.4.1
- Massively improve typing.
mypy
is relatively quiet now.
This interpreter wouldn't be possible without the excellent Writing an Interpreter in Go
by Thorsten Ball
.
I highly recommend you to read it, and build your own monkey interpreter!
The source code is licensed under the MIT license.