Skip to content

Latest commit

 

History

History
69 lines (48 loc) · 2.81 KB

File metadata and controls

69 lines (48 loc) · 2.81 KB

MiniC — Interpreter, Typechecker and (partial) Codegen

A compact compiler toolchain for the MiniC language (a small C subset). Implemented for the MIF08 compiler lab at Université Claude Bernard Lyon 1.

Author

Mohamed Hamed MOHAMED AHMED

What this project contains

  • ANTLR4-generated lexer and parser for MiniC.
  • A static type checker that validates MiniC programs.
  • An interpreter that evaluates MiniC programs.
  • Partial backend that can emit RISC‑V assembly for codegen experiments.
  • A comprehensive test-suite used for grading and development.

Quickstart (recommended: use Docker)

The repository is designed to run reproducibly inside the provided Docker image.

Run a development shell:

docker pull mmoy/riscv-latex-python:dev
docker run --rm -ti -v "$PWD":/home/compil --user $(id -u):$(id -g) -w /home/compil mmoy/riscv-latex-python:dev

Inside the container you can run the test-suite or the interpreter directly:

# Run all tests
make test

# Run the interpreter on a file
python3 MiniCC.py --mode eval TypingAndInterpret/tests/arit/multiplicative/modulo.c

# Run a subset of tests
make test FILTER='TypingAndInterpret/tests/**/*division*.c'

Testing strategy

  • test_eval: runs the project interpreter and compares output to expected annotations.
  • test_expect: compiles with GCC and checks that the annotated expected results are correct.

Some tests intentionally differ between GCC and the interpreter (e.g. undefined behaviour). In such cases the test can be marked in-source with // SKIP TEST EXPECTED so only the interpreter check runs.

RISC‑V backend

This project can emit RISC‑V assembly for a subset of MiniC. RISC‑V was chosen because it is an open, modern ISA well suited for teaching compiler construction and experimentation.

Lab references

This repository was developed as part of the MIF08 labwork. Relevant lab documents:

These PDFs describe the assignment specifications and test expectations used during development.

Project layout (high level)

  • MiniC/ — lexer/parser, interpreter, typechecker, tests, and codegen helpers.
  • TypingAndInterpret/ — typing rules and interpreter tests.
  • CodeGen/ — RISC‑V emission utilities and allocators.
  • CC1/ & TP* — smaller exercises and examples used in the course.

Refer to the repository tree for details.

Contributing & Feedback

Issues, suggestions or improvements are welcome. Please open an issue or send a patch.

License

Use and distribution details are in the repository. If none are present, contact the author for licensing terms.