Skip to content

mmmmie/minipy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minipy Interpreter

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.


Prerequisites

  • 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 python3

Build Instructions

To compile the interpreter:

cmake ./
make

This will build the minipy binary in the project root.


Usage

Once compiled, you can run a .py script using:

./minipy file-name.py

Try running:

./minipy benchmark/mandelbrot.py 

Running Tests

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/.


Running Benchmarks

To benchmark Minipy against CPython and PyPy (if on the PATH) on selected algorithms:

  1. Install dependencies (using a virtual environment is recommended):

    pip3 install -r benchmark/requirements.txt
    
  2. Make sure you're in the project root directory.

  3. 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.


Project Structure

  • parser.y: Bison grammar
  • lexer.l: Flex scanner
  • astgen.c/h: AST node creation
  • astexec.c/h: AST execution logic
  • object.c/h: Object representation
  • symbol_table.c/h: Variable storage
  • builtin.c/h: Built-in functions
  • tests/: Test inputs and expected outputs
  • benchmark/: Benchmark runner and examples

License

This project uses Flex and Bison which are licensed under permissive open source licenses. See individual source headers for details.

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors