Git Product home page Git Product logo

pyruc's Introduction

PyRuc (Python based Ruby Compiler)

We Implemented this as a part of the Complier Design Lab Course at PES University.The following Details are taken from PESU's Compiler Lab Mini Project Guidelines.

This repo contains an implementation of a Compiler for Ruby written in Python by making use of the PLY (i.e Pythonic Version of Lex & Yacc Tools) package. A thing to note is that this is just a Front End Compiler i.e it doesn't implement the Machine Dependent Code optimization (MDCO) Phase out of the seven standard phases of Compilation. Also it is implemented to compile a few basic constructs of Ruby only & can be extended to include more.

The Phases it Implements:

1. Lexical Analysis Phase & Symbol Table Construction:

  1. Remove Comments.
  2. Generate tokens.
  3. Preload keywords into the Symbol Table.
  4. Make an entry for the identifiers into the Symbol Table (if there exists an identifier with the same name in different scopes then construct Symbol Table per scope)
  5. Symbol Table must contain entries for predefined routines like printf, scanf etc.

2. Syntax Analysis Phase:

  1. Write CFG for the entire program using appropriate Semantic rules if you are using PLY.
  2. Else if you are implementing Parser by hand use Recursive Descent Parser (RDP) with Backtracking & Perform translation at required places in the code for each non-terminal.

3. Semantic Analysis Phase (In this Project we look at basic Semantic Constructs only):

  1. Take care of the primitive types and array types.
  2. Take care of coersions.
  3. Take care of Arithemetic Expressions.
  4. Concetrate on the looping construct choosen.
  5. Update type and storage information into the symbol table.
  6. Show Abstract Syntax tree (AST).

4. Intermediate Code Generation:

  1. Do a Three address code generation.

5. Machine Independent Code Optimization (MDCO):

  1. Perform Constant folding.
  2. Perform Constant Propogation.
  3. Perform Common subexpression elimination.
  4. Perform Dead code elimination.

These are some of the basic optimizations that are implemented in this Project.You can extend the same to add more optimizations like Reducing temporaries, Loop optimizations etc.

The remaining 2 phases that form the Backend of the Compiler are Machine Dependent Code Generation (MDCO) & Target Code Generation which are not implmented here.

Link to the PLY Package: https://www.dabeaz.com/ply/ply.html

To Understand more about the Compier's phases you can checkout the Compliers: Principles, Techniques & Tools Book (more famously known as the Dragon Book) by Aho et al. Link- https://www.amazon.in/Compilers-Alfred-V-Aho/dp/9332542457?tag=googinhydr18418-21&tag=googinkenshoo-21&ascsubtag=_k_CjwKCAjwstfkBRBoEiwADTmnEHm7nMy2Ma_kjQqmHPMuiqdM2SX5V8V11nI4GnC7hVKgrKfsH4yOnxoCJzoQAvD_BwE_k_&gclid=CjwKCAjwstfkBRBoEiwADTmnEHm7nMy2Ma_kjQqmHPMuiqdM2SX5V8V11nI4GnC7hVKgrKfsH4yOnxoCJzoQAvD_BwE

pyruc's People

Contributors

anuragc1729 avatar arunj18 avatar asmitarao avatar noblessecoder avatar

Stargazers

 avatar  avatar

Watchers

 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.