cpy-compiler is a complete compiler for the cpy language, a small, educational programming language developed for the "Compilers" course at the University of Ioannina. It translates .cpy source files directly into RISC-V assembly, suitable for execution on simulators like RARS or actual hardware.
- Full Compilation Pipeline – From source
.cpyto executable.asmcode. - Nested Scopes – Full support for lexical scoping (static PASCAL-style) with correct handling of non‑local variables.
- Rich Feature Set – Implements
if‑elif‑else,whileloops, integer operations (including//division), boolean logic (and,or,not), and standard I/O. - Robust Error Checking – Performs lexical, syntactic, and semantic analysis, catching invalid characters, undeclared identifiers, type mismatches, and function argument count errors.
- Human‑Readable Output – Generates clean, well‑documented intermediate
.int(quadruples) and symbol table.symfiles for debugging.
- Python 3.8+
- A RISC-V Simulator: RARS (recommended) or a GCC toolchain with QEMU.
- Clone the repository
git clone https://github.com/MikeMiaris/cpy-compiler.git cd cpy-compiler - Run the compiler on a valid .cpy source file
bash python src/cpy_4735_4645.py tests/test.cpy This generates three files:
test.asm – final RISC‑V assembly output
test.int – listing of the intermediate quadruples
test.sym – dump of the symbol tables for each lexical scope
- Execute the assembly (using RARS)
Open test.asm in the RARS application
Click Assemble
Click Run or Execute
Variables – Must be declared with #int.
Global variables – Declared at the top level, then accessed inside functions via the global keyword.
Functions – Defined with def name(params):. A function’s body is enclosed within #{ ... #}.
Input / Output – x = int(input()) and print(expression).
Comments – Enclosed within ## (e.g., ## This is a comment ##).
- Michalis Miaris
- Ilias Georgiadis
Developed as a term project for the Compilers course (Spring 2024) at the Department of Computer Science & Engineering, University of Ioannina.
Instructor: Prof. G. Manis.