Coder Social home page Coder Social logo

sakshidgoel / python-compiler Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 4.0 2.38 MB

All phases of a compiler for Python Language have been implemented using C language. The constructs 'if-else' and 'while' have been handled.

Python 1.05% C 84.52% Lex 1.76% Yacc 10.04% C++ 2.62%
compiler-design python c if-else while syntax-analyzer parser lexer intermediate-code-generation target-code-generation

python-compiler's Introduction

Python-Compiler

All phases of a compiler for Python Language have been implemented using C language. The constructs 'if-else' and 'while' have been handled.

Introduction

The proj.l lex file and proj1.y yacc file work together to parse the Python code in the inp.py file and generate tokens to output a symbol table and create an abstract syntax tree and hence, generate the optimised intermediate code. This optimised intermediate code is saved in the file IntermediateCode.txt which is then accessed in the TargetCodeGenerator.c file. This file converts this optimised intermediate code to the target code for a hypothetic machine model which will be discussed further.

Steps To Run

  1. Install Flex (to make lex program work)
sudo apt-get upgrade
sudo apt-get install flex
  1. Install Bison (to make yacc program work)
sudo apt-get upgrade
sudo apt-get install bison
  1. Run the lex and yacc files
lex proj.l && yacc -d -v proj1.y && gcc lex.yy.c y.tab.c -ll -lm -w
  1. Run the TargetCodeGenerator.c file
gcc -o TargetCodeGenerator .\TargetCodeGenerator.c
.\TargetCodeGenerator.exe

Implementation

Context Free Grammar

Parsing and Token Generation

Symbol Table Creation

Abstract Syntax Tree

Intermediate Code Generation

Code Optimization

Error Handling

Target Code Generation

Snapshots of Sample Input and Output

Contact

For any comments or questions, please email at [email protected] / [email protected] / [email protected]

python-compiler's People

Contributors

amoghrajesh avatar sakshidgoel avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

python-compiler's Issues

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.