Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

JasonLiu1229/Compiler

Repository files navigation


drawing

Compiler

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.

Table Of contents

  1. Assignments.
  2. Testing.
  3. Files.
  4. Sources.
  5. Authors.

Assignments

TODO list

  • 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

Testing

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.

Jetbrains Pycharm

drawing

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

Available tests

All correct programs
cd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -a -e mars -nd
All programs with errors
cd src || exit &
python3 run.py -d ../input_files/SemanticErrors/fully_working/ -t .c -a -e mars -nd
Recursive fibonacci
cd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -f fibonacciRecursive -e mars
Scanf tests
cd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -f Scanf1 Scanf2 -e mars
Printf tests
cd src || exit &
python3 run.py -d ../input_files/CorrectCode/fully_working/ -t .c -f Printf1 Printf2 Printf3 -e mars

Compiling the grammar

  1. Go to Grammar folder using cd command
  2. Execute the following command:
antlr4 -o ../src/output -listener -visitor -Dlanguage=Python3 Math.g4  

Files

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

Sources

Antlr4 installation
Dot language reference
LLVM
LLVM ref. page

Mips syscall info
while loops mips
Unaligned address in store error, using the wrong load

Authors

Name Email Student number
Jason L. Jason.Liu@student.uantwerpen.be 20213082
Orfeo T. Orfeo.Terkuçi@student.uantwerpen.be 20213863

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published