A compiler for a subset of the Rust programming language, developed in C as a team project for the Compilers course at FCUP (University of Porto) in 2019.
The compiler parses a small Rust-like language, builds an abstract syntax tree, generates an intermediate representation, and translates it into MIPS assembly.
The supported language subset includes:
- Integer arithmetic
- Boolean expressions and logical operators
- Variable declarations and assignments
if/elsestatementswhileloops- Basic input and output
- Variable validation through a symbol table
The project follows a simple compiler pipeline:
Source code
↓
Lexical analysis (Flex)
↓
Parsing (Bison)
↓
Abstract Syntax Tree
↓
Intermediate Code
↓
MIPS Assembly
The implementation uses:
- C for the compiler implementation
- Flex for lexical analysis
- Bison for parsing
- A hash-table-based symbol table
- An intermediate representation before MIPS code generation
The project requires a C compiler, Flex, Bison and Make.
makeThis generates the compiler executable.
To compile one of the example programs:
./compiler example1.txtThe generated MIPS assembly is printed to the standard output.
The included examples can also be run with:
make testThis was a collaborative university project. My contributions included work on:
- Intermediate-code generation and boolean-expression support
- Integration between intermediate code and MIPS generation
- Pseudo-register handling
- MIPS and intermediate-code bug fixes
- Intermediate-code optimisations using immediate instructions such as
addi,subi,andiandori
The original development history and commits have been kept as they were produced during the course.
This repository contains the original implementation produced for the Compilers course at the Faculty of Sciences of the University of Porto (FCUP) in 2019. It is preserved as an academic project rather than maintained as a production compiler.