This repository contains a complete compiler construction project developed in the Compilation course (Licence Informatique, S5).
The objective is to design and implement a structured compiler using ANTLR4, progressively extending a language from simple expressions to a fully functional language supporting:
- Arithmetic, boolean, and rational expressions
- Semantic analysis and type checking
- Variables and scoped blocks
- Control flow (conditionals and loops)
- User-defined functions
- Stack-based code generation targeting the MVaP virtual machine
The project follows a classical compiler pipeline:
Grammar → Parser → Semantic Analysis → Code Generation → Virtual Machine Execution
The project evolves through the following stages:
- Lexical and syntactic analysis (ANTLR grammars)
- Attributed grammars and interpretation
- Semantic validation (type checking, scope management)
- Stack-based code generation (MVaP)
- Control flow compilation
- Function calls and activation records
Target machine: MVaP (version 3.2)
- TP1 -- Introduction to ANTLR
- TP2 -- Boolean Expressions & Evaluation
- TP3 -- Expression Integration
- TP4 -- Variables & Semantic Control
- TP5 -- MVaP Code Generation
- TP6 -- Extended Rational Features
- TP7 -- Control Flow Compilation
- TP8 -- Functions & Call Mechanism
Each TP folder contains:
.g4grammar files.rattest programs- Optional scripts
- A dedicated README
This project demonstrates:
- Formal language theory applied in practice
- Grammar ambiguity control
- Semantic analysis and type systems
- Stack machine architecture
- Activation record design
- Recursive function execution
- End-to-end compiler pipeline implementation
- Java (JDK 8+)
- ANTLR4
- MVaP Assembler and Simulator
- Bash (recommended)
Additional documentation and reference materials are available in the
docs/ directory:
- Setup instructions (ANTLR & MVaP installation guides)
- Bash command memo
- MVaP instruction cheat sheet
- Official TP subject PDFs
These documents provide the theoretical background, machine instruction reference, and environment setup required to run and understand the compiler.
This project was developed as part of the Compilation course.
Contributors:
- TP1--TP6: Fully implemented
- TP7--TP8: Advanced control flow and function mechanism implemented
- Further optimizations possible (symbol table improvements, memory model refinement)