Minipy is a lightweight Python-like interpreter implemented in C using Flex and Bison. It supports a core subset of Python syntax, including arithmetic, control flow, functions, and list structures. This project has been tested on Linux (e.g., Ubuntu, Debian). It may or may not work on other operating systems.
- CMake (version 3.10 or higher)
- Flex
- Bison
- A C compiler (GCC or Clang recommended)
- Python 3 (Optional) for running benchmarks
On many Linux distributions, you can install these dependencies using:
sudo apt-get update
sudo apt-get install cmake flex bison gcc python3To compile the interpreter:
cmake ./
make
This will build the minipy binary in the project root.
Once compiled, you can run a .py script using:
./minipy file-name.py
Try running:
./minipy benchmark/mandelbrot.py
Automated tests compare output from minipy with CPython for a suite of Python files.
To run all tests:
bash tests/run_test.sh
Tests are stored under tests/inputs/ and their outputs along with expected results in tests/outputs/.
To benchmark Minipy against CPython and PyPy (if on the PATH) on selected algorithms:
-
Install dependencies (using a virtual environment is recommended):
pip3 install -r benchmark/requirements.txt -
Make sure you're in the project root directory.
-
Run the benchmark suite:
python3 benchmark/benchmark.py
This will time the interpreter against CPython and PyPy on a few algorithm-heavy examples and report the results.
The result will be saved in benchmark/benchmark_results.csv.
parser.y: Bison grammarlexer.l: Flex scannerastgen.c/h: AST node creationastexec.c/h: AST execution logicobject.c/h: Object representationsymbol_table.c/h: Variable storagebuiltin.c/h: Built-in functionstests/: Test inputs and expected outputsbenchmark/: Benchmark runner and examples
This project uses Flex and Bison which are licensed under permissive open source licenses. See individual source headers for details.