Giter VIP home page Giter VIP logo

compiler-project's Introduction

Compiler-Project

This repository contains the compiler designed in C following the language specifications provided in Language Specifications.pdf , as part of the course Compiler Construction at BITS Pilani.

The compiler parses input files according to the language specifications, and if the input is syntactically and semantically correct, it is capable of generating corresponding assembly-level code. Some testcases have been provided in Compiler/testcases.

As required for the project, the code is compatible for GCC version 5.4.0. and has been tested on Ubuntu 16.04 To run it on Windows, you will have to use cygwin.

To create the compiler

  1. cd Compiler
  2. make
  3. This will create an executable file named compiler

To test the compiler on a testcase

  1. Ensure you are in the directory containing the compiler executable
  2. Run ./compiler <RELATIVE_PATH_TO_TESTCASE_FILE> <NAME_OF_ASM_FILE>
  3. Choose among the 11 options to test the feature you want.
  4. To create assembly-level code , choose option 10.
  5. Choose option 0 to exit. (Ctrl + C would result with no output in the ASM file)
  6. To run the asm file nasm -felf64 code.asm && gcc code.o && ./a.out (Using code.asm as the name of the asm file in this example)

Stages of compiling a testcase (Option 10)

Stage Details
Lexical Analysis Categorizes the contents of the input file as tokens (as per the language specifications).
Syntax Analysis Creates a Parse Tree for the tokens being returned by the lexer. If an error is encountered in any of the above 2 stages, the compiler does not proceed to semantic analsysis.
Semantic Analysis Creates an Abstract Syntax Tree for the coresponding Parse Tree and populates the Symbol Table. If an error is encountered during Semantic Analysis, the compiler does not proceed to code generation
Code generation Generates corresponding assembly-level code. As per the project requirements, code generation is restricted to only those testcases which have a single function (main) and handle only integers.

Contributors

The team members of this project were:

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.