Giter Site home page Giter Site logo

iamishansharma / compiler-construction-cs-f363 Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 3.14 MB

Semester Long Project: Compiler for ERPLAG (Toy Language)

C 99.91% Makefile 0.09%
compiler-construction c lexer parser symbol-table type-checker code-generation erplag

compiler-construction-cs-f363's Introduction

ERPLAG Compiler

This was my semester long project for Compiler Construction (CS F363) course at BITS Pilani, Spring 2020.

ERPLAG (Toy Language) Details

ERPLAG is a toy language made for the course. Details of which can be looked at inside Language Details folder.

Modules

Lexer (lexer.c)

  • This module reads the source code in HLL as a stream of charaters and converts sequence of characters to meaningful tokens.
  • The tokens are passed to the parser and contains information about the line of occurance, name of the token, token id etc.

Parser (parser.c)

  • Parser takes in the sequence of tokens and verifies the syntactical correctness of the source code by constructing the parse tree.
  • The Parser also has error recovery mechanism to parse the complete sequence of tokens even if a syntactical error exist.

AST Construction (ast.c)

  1. Delete all the irrelevant tokens
  2. Changes the structure of to infix notation (for proper checking and evaluation)
  3. Removes chaining in tree
  4. Removes empty non-terminals.

Symbol Table and Scoping (SymbolTable.c)

  • This module constructs the symbol-table for the corresponding AST.
  • The symbol table has a tree structure that depicts the scoping of the blocks of code.
  • Each node of the tree has a linked list of its locally defined variables.
  • It also reports the errors related to redundant declaration, no declaration of variables and modules.

Type Checker and Semantic Analyser (TypeChecker.c)

  • This module performs semantic checks on the AST for verifiying semantic correctness of the source code.
  • It also determines the correctness of the expressions.

Code Generation (CodeGen.c)

  • Generates the NASM-assembly code of the source code.

Compatibility and Pre-requisites

  • Unix (Linux / Mac)
  • gcc 5.4.0 and up
  • NASM version 2.12.01 and up

Testcases

All the testcases are present inside Testcases folder.

  • c1 - c6 and v1 - v11 pertain to Code Gen testcases specifically
  • All other testcases can be used to check different translational phases of the compiler
  • sampless.txt can be used to verify Symbol Table Creation / Visual Presentation

Execution Instructions

  • Download this repo and change directory to Code folder.
  • Run make
  • Executable compiler would be created.
  • You can use make clean to delete the old executable.

> If you don't want to run Code Gen

  • Run ./compiler {path_to_testcase/*.txt} {parseTree_file_name.txt}
  • Eg. Run ./compiler ../Testcases/t1.txt parseTree.txt

> If you want to run Code Gen

  • Run ./compiler {path_to_testcase/*.txt} {Assembly_file_name.asm}
  • Eg. Run ./compiler ../Testcases/c1.txt code.asm

Execution Instructions for Code Gen Assembly File

For Linux

  • nasm -f elf64 -o code.o {Assembly_file_name}.asm
  • gcc -no-pie code.o -o code
  • ./code

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.