lexer
- lexer for C-like syntaxparser
- parser for C-like syntaxyuck
- optimised YUCK compiler (c-to-mips)ast
- structure of Abstract Syntax Tree (AST)
This repository includes a makefile
to build the program via the following commands:
# build all the targets
make all
# To build the lexer file
make lexer
# To build the parser file
make parser
# To build the compiler
make yuck
# To clear output files
make clean
Invoked using the flag --translate
, with the source file and output file specified on the command line:
bin/c_compiler --translate [source-file.c] -o [dest-file.py]
Invoked using the flag -S
, with the source file and output file specified on the command line:
bin/c_compiler -S [source-file.c] -o [dest-file.s]
The tests cases can be found in the folder: test_deliverable
A bash
script that runs the tests. It will build your program, then apply it to each input in turn to produce a file containing the generated output.
You can run the program via the commands:
# Testing the translator
./test_translator.sh
# Testing the compiler
./test_compiler.sh
# Testing translator formative
./c_translator_formative.sh
# Testing c test deliverables
./test_deliverable.sh
NB: for test_compiler.sh, you MUST download Mars 4.5 - a MIPS assembly simulator - and include it in the test folder.
NB: the unix execute permissions may have been lost, in which case you can indicate the script should be executable with:
# eg.
chmod u+x ./test_compiler.sh
To keep track of progress and key milestones, we've included the following files to log the progress of this project.
-
milestones
a list of defined milestones, including the dependencies that each milestone has, which team member is responsible for leading it, and the completion status of each, -
week-log
a week-by-week view of planned effort (hours to be spent) going into the project (taking into account other deadlines that you expect to have from other courses), and -
effort-log
a log of actual effort spent on each milestone (including an assessment of whether the estimates were optimistic or pessimistic, and whether you need to reduce the scope of certain deliverables).
The YUCK is able to compile the following:
- functions without arguments
-
int
type variables - local variables
- arithmetic expressions
- logical expressions
- if-then-else statements
- while loops
- scope
- functions with parameters (up to 4)
- for loops
- do-while loops
- local arrays
- global arrays
- reading and writing elements of an array
- recursive function calls
-
enum
keyword -
switch
statements -
break
keyword -
continue
keyword
-
double
,float
,char
,unsigned
,structs
, andpointer
type variables - calling externally-defined functions
- mutually recursive function calls
- locally scoped variable declarations
-
typedef
keyword -
sizeof
keyword - address of variable via
&
operator - derefercing a pointer-variable via
*
operator - pointer arithmetic
- character literals (including escape sequences eg.
\n
) - strings (as NULL-terminated character arrays)
- declaration and use of structs
In order to run YUCK on a personal machine, use VirtualBox together with Vagrant; The target environment and required dependencies: make bison flex python3 g++-mips-linux-gnu qemu tidy
will be installed via Vagrant.
This repository contains a Vagrantfile, which is a script that sets up a blank Ubuntu 16.04 environment, and then installs all the necessary tools.
-
Open a shell in this directory.
-
Run
vagrant up
to download, install, and configure the VM. -
Run
vagrant ssh
to log into the VM. -
Run
cd /vagrant
: This will put you in the same directory, with your host files shared with the VM.
You can then use command line build tools in the VM, while editing the source files in your host editor.
If you want to stop the machine,
-
Run
exit
to exit the session, -
Run
vagrant halt
to shut down the virtual machine.
If you later run vagrant up
again, it will not need to download the VM from scratch.
The tests and builds can then be run from there.