Inspired by the screencast by Vladimir Keleshev :
How to write an interpreter in Python.
and the source for his Mini interpreter in github :
https://github.com/keleshev/mini
This version implements the same language but uses the Python AST module to generate an AST and compile it into a Python code object. This can then be used to evaluate expressions.
Since Python makes the distinction between statements and expressions I provide a compile(source) method and an eval(source) method. See the tests (which I converted to Unittest).
It uses:
- The Python AST module
- for generating a python Abstract Syntax Tree
- parsimonious library for parsing using Parsing Expression Grammar (PEG) (See also the original PEG paper).