Coder Social home page Coder Social logo

cmpe230-compiler-project's Introduction

CMPE 230 Compiler Project

This was an assignment given to us as a part of our CMPE 230 course in Boğaziçi University Computer Engineering Undergraduate Program on Spring 2018 term. Specifications of the assignment is included in the repository. Our goal was to create a simple compiler for a simple programming language called COMP. Our compiler creates an A86 assembly code for the given COMP language code.

Implementation

Implementation is explained in the code with comments in detail. In short our program follows these steps:

  • Opens up the file in the path given to the program as a parameter. Also creates an .asm file with the same name which will have the output when compilation is over.
  • Prints out the initial assembly code, like multiplication and power functions that will be used.
  • For each line categorizes the lines as assignment operations or printing operations.
  • For the assignment statements, prints out a code that will evaluate the RHS and put it into the memory location of LHS.
  • For the printing operations, prints out a code that similarly evaluates the expression then calls a function that was initialized in the beginning.
  • Finally it prints out a code that will allocate memory for the variables it used while evaluating the statements.

The way our program translates each line to assembly is as follows:

  • It first tokenizes each line.
  • Then converts this tokenized version to postfix form using a stack.
  • This postfix form is ready for translation to assembly, using the specific function for each operation the postfix form is printed out as assembly code.

It can also point out the first line that it encountered a syntax error in the .asm file (if there is one).

How to run

Our project is done in CLion using C++ language. You need cmake and make utility to run our code. After making sure you have both installed, the following code will build our program.

cmake
make

After building our program can be run on terminal with the .co file as parameter.

comp input.co

Afterwards you can run the A86 assembly code using the compiler provided here. (Using DOSBox might be needed in newer systems.)

Programs used

Authors

  • Burak Çetin
  • Merve İlik

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

cmpe230-compiler-project's People

Contributors

bcetin avatar merveilik avatar

Watchers

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