Giter Club home page Giter Club logo

python-parser's Introduction

Python parser

A simple parser for python made using lex yacc / GNU's flex bison.

The stable version currently supports only certain python expressions as stated below. The code for the same is in python-expression-parser directory. A similarly made python for-loop parser can also be found in the python-loop-parser directory.

Screenshots

1 2 3

How to make

  • The following packages are required
    • gnu's lex yacc sudo apt-get install bison flex
    • make utility sudo apt-get install build-essential
  • go to source folder cd python-expression-parser
  • make clean to remove old stuff lying around
  • make to build : this will generate the usual files
  • make run to execute or simply run ./expression-parser

How to debug

  • go to source folder cd python-expression-parser
  • make clean to remove old stuff lying around
  • make debug to build with debugging flags. This will generate a lot of extra files. Browse them to know more about them.
  • run ./debug-expression-parser

Challenges

  • Program works when input in only a single line.

    • It can be made into consecutive multiple line input using BEGIN <stmt-list> END.
    • But then, when a syntax error is encountered,
      • i will have to handle the error,
      • empty the current stack
      • then recover from the error
      • and then keep the program going until statements are over
  • One program run parses only one statement.

    • It can be made for infinite statements.
    • That is, continous INPUT_OUTPUT stream until ctrl+c on terminal can be achieved.
    • This can be done by removing return 0; from the success case.
    • In this case as well, the current stack needs to be emptied.

Assumptions

  • each statement ends with semicolon

Cases Handled

  • arithmetic expressions along with brackets

    a=5;
    a=5+24;
    a=rod;
    a=5*(4+3);
  • string assignments

    var="hello";
    var='hello';
  • print statements

     print 'hello';		# single quotes handled
     print "hello";		# double quotes handled
  • keywords cant be identifiers

Cases not handled

  • Multiple Statements on a Single Line

    var=5; var2=6; var7=23;
  • multi line statements -- a single statement written in multiple lines

    var= 2+ \
        3+	\
        4
  • static array initialisation not included

    var = [3,3,23];
    days = ['Monday', 'Tuesday', 'Wednesday','Thursday', 'Friday']
  • single or multi line comments

  • triple quote print statements - multiline strings

    print """hello""";
    print '''hello''';
    
  • typecasting

    print "hello" + str(5);
  • shorthand operators not handled

    var+=3;
    var+=2;

Disclaimer

  • This assignment covers only simple cases.
  • Only to be used as a reference point.
  • This code was made in 2015. Use at your own discretion.

Reference links

python-parser's People

Contributors

jatin69 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

python-parser'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.