babu-thomas / calculator-parser Goto Github PK
View Code? Open in Web Editor NEWParser for simple arithmetic calculator
License: MIT License
Parser for simple arithmetic calculator
License: MIT License
Currently to parse a string the following needs to be done -
InputStream
object from newline delimited input string.TokenStream
object from the InputStream
object.Parser
object from the TokenStream
object.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.
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.
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.