Code Monkey home page Code Monkey logo

yuck-compiler's Introduction

YUCK Compiler

Program Organisation

  • lexer - lexer for C-like syntax
  • parser - parser for C-like syntax
  • yuck - optimised YUCK compiler (c-to-mips)
  • ast - structure of Abstract Syntax Tree (AST)

Environment

Makefile

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

Translator Function

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]

Compilation Function

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]

C Test Suite

The tests cases can be found in the folder: test_deliverable

Testing YUCK

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

Project Management

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).

Features

The YUCK is able to compile the following:

Basic

  • functions without arguments
  • int type variables
  • local variables
  • arithmetic expressions
  • logical expressions
  • if-then-else statements
  • while loops

Intermediate

  • 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

Advanced

  • double, float, char, unsigned, structs, and pointer 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

Vagrant

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.

yuck-compiler's People

Contributors

zenasgram avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.