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
- Arrays
-
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 | [str] |
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:
python -d ../input_files/ -t .c -f Project3 Project2 ...Example code with only the input directory and file extension
python -d ../input_files/ -t .c -aExample code with only the input directory and an index
python -d ../input_files/ -t .c -i 3cd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -a -e mars -ndcd src || exit &
python3 run.py -d ../input_files/SemanticErrors/fully_working/ -t .c -a -e mars -ndcd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -f fibonacciRecursive -e marscd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -f Scanf1 Scanf2 -e marscd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -f Printf1 Printf2 Printf3 -e mars- Go to Grammar folder using
cdcommand - Execute the following command:
antlr4 -o ../src/output -listener -visitor -Dlanguage=Python3 Math.g4 Unaligned address in store error, using the wrong load
| Name | Student number | |
|---|---|---|
| Jason L. | Jason.Liu@student.uantwerpen.be | 20213082 |
| Orfeo T. | Orfeo.Terkuci@student.uantwerpen.be | 20213863 |

