This is an example interpreter written using PyPy. A preferred way to walk through it is to follow the history of commits. Interesting tags are
- Parser boilerplate
- First parser test
- Parser complete
- Compiler start
- Interpreter start
- Print support
- While loops
- ...
- CLI options
- Hello World!
For a full list of interesting tags/releases see: Latest Releases
Note
This is a fork of PyPy's example interpreter Kermit. You may still follow the commit history as a learning guide, however; this fork is a divergent from PyPy's version of Kermit and is not compatible.
It is recommended that you do all development using a Python Virtual Environment using virtualenv and/or using the nice virtualenvwrapper.
$ mkvirtualenv kermit
Grab the source from https://github.com/prologic/kermit and either
run python setup.py develop
or pip install -e .
$ git clone https://github.com/prologic/kermit.git $ cd kermit $ pip install -e .
To build the interpreter simply run kermit/main.py
against the RPython
Compiler. There is a Makefile
that has a default target for building
and translating the interpreter.
$ make
You can also use Docker to build the interpreter:
$ docker build -t kermit .
You can either run the interpreter using Python itself or by running the
compiled interpreter kermit
in ./bin/kermit
.
$ ./bin/kermit examples/hello.ker
Untranslated running on top of Python (CPython):
$ kermit examples/hello.ker
The grammar of kermit is currently as follows:
main: statement* [EOF]; statement: expr ";" | VARIABLE "=" expr ";" | "while" "(" expr ")" "{" statement* "}" | "if" "(" expr ")" "{" statement* "}" | "print" expr ";"; expr: atom ADD_SYMBOL expr | atom; atom: DECIMAL | FLOAT | STRING | VARIABLE;