In this project, we will create a compiler from scratch.
This compiler is capable of compiling C language code.
It will be made in Python.
This project is made for the course Compilers at the University of Antwerp.
- Project 1
- Project 2
- Project 3
- Project 4
- For loops
- While loops
- Break
- Continue
- Project 5
- Function declarations
- Function definitions
- Function calls
- Return
- Return values and type checking / **void type**
- No dead code after **return, break, continue**
- Project 6
- Arrays
- Declarations
- Access
- Printf
- Scanf
- Includes
- LLVM
- Project 1
- Project 2
- Project 3
- Project 4
- Project 5
- Project 6 - **Half implemented**
- MIPS
- Project 1
- Project 2
- Project 3
- Project 4
- Project 5
- Project 6
Guide on how to test our Compiler, the guide is meant for Pycharm users.
Check if the following path is set right. You could do this by running it on Pycharm, or Terminal, or by script. If you do it in the terminal, match the "parameters" option of pycharm with the parameters in the Terminal.
There are two ways to run it via terminal Common parameter settings:
Short command | Long command | Type | Required | Description |
---|---|---|---|---|
-d | --directory | <path> | Yes | Directory of the input files |
-t | --type | <str> | Yes | File extension |
-f | --files | [str] | Exclusive. Takes priority | Files to parse |
-a | --all | NaN | Exclusive. Least priority | Parse all the files in the directory |
-i | --index | <int> | Exclusive | Parse the i-th file in the directory |
-v | --verbose | NaN | No | Print the AST |
-nw | --no-warning | NaN | No | Do not print warnings |
-e | --execute-with | No | Execute the mips code generated for the program. Can be "spim", "mars" or "both" |
|
-s | --silent | NaN | No | Do not print the output of the program |
-nd | --no-disclaimer | NaN | No | Remove the disclaimers for "spim" and "mars" from the output |
-vs | --visualise | NaN | No | Generate a dot format file and compile it to a png |
-h | --help | NaN | NaN | For help |
Example code with specified input files:
python3 -d ../input_files/ -t .c -f Project3 Project2 ...
Example code with only the input directory and file extension
python3 -d ../input_files/ -t .c -a
Example code with only the input directory and an index
python3 -d ../input_files/ -t .c -i 3
cd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -a -e mars -nd
cd src || exit &
python3 run.py -d ../input_files/SemanticErrors/fully_working/ -t .c -a -e mars -nd
cd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -f fibonacciRecursive -e mars
cd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -f Scanf1 Scanf2 -e mars
cd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -f Printf1 Printf2 Printf3 -e mars
- Go to Grammar folder using
cd
command - Execute the following command:
antlr4 -o ../src/output -listener -visitor -Dlanguage=Python3 Math.g4
Grammar: ../Grammars/Math.g4
Python scripts: ../src/
C Files: ../input_files/
The output of the scripts: ../MIPS_output/ for asm files and ../Output/graphics for png files
Antlr4 installation
Dot language reference
LLVM
LLVM ref. page
Mips syscall info
while loops mips
Unaligned address in store error, using the wrong load
Name | Student number | |
---|---|---|
Jason L. | [email protected] | 20213082 |
Orfeo T. | Orfeo.Terkuç[email protected] | 20213863 |