Giter Site home page Giter Site logo

calculator-parser's People

Contributors

babu-thomas avatar

Watchers

 avatar  avatar

calculator-parser's Issues

Only expose Parser object to parse any input

Currently to parse a string the following needs to be done -

  • Create InputStream object from newline delimited input string.
  • Create TokenStream object from the InputStream object.
  • Create Parser object from the TokenStream object.
  • Call parse() function of Parser object.

It would be better to just expose a Parser object to the caller which takes just the input string and takes care of all other object creations inside it.

Don't make the caller pass newline delimited string

Currently to correctly parse an input string it needs to be delimited with a newline character. If the caller doesn't pass a correctly delimited string, the parser fails. Take care of delimiting input string inside InputStream class instead of relying on the user.

Successive operator tokens without space is lexed as single token

Running

parser = Parser(TokenStream(InputStream('  ***  ')))
print(parser.parse())

gives

Expected token of type: num, found token: {'type': 'op', 'value': '***'} (column: 5)
None

The 3 multiplication operators are lexed as one token. Expected output is

Expected token of type: num, found token: {'type': 'op', 'value': '*'} (column: 3)
None

where the operators are lexed individually.

Add tests

Currently the parser behaviour is only tested manually by trying different inputs. Adding unit tests for different cases will ensure the parser behaves correctly and continues to do so in the future.

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.