Code Monkey home page Code Monkey logo

odin-calculator's Introduction

odin-calculator

Calculator project for Fundamentals course of The Odin Project.

I wanted to implement order-of-operations and parentheses, and doing it as a state machine seemed like a pain, so I dug deep into my memory of computer science courses from 25-30 years ago, along with some newfound asynchronous and object-oriented techniques, and did the following:

  • A top-down parser (basically recursive descent)
    • expr := term { '+' term | 'โˆ’' term }*
    • term := factor { '*' factor | '/' factor }*
    • factor := number | '(' expr ')'
    • number := { digit }*
  • An asynchronous buffer - This is because constantly switching the event listeners was cumbersome. Plus, it's more natural in a top-down parser for the parser to ask for tokens, rather than have the data trigger the parser. So:
    • The mouse (and ToDo keyboard) events push entries to a buffer array.
    • The parser shifts items off the buffer aray asynchronously via a promise. If there is no data, the promise is resolved by the next item pushed to the buffer.
    • A class to encapsulate the operations, buffer, and the promise(s) awaiting fulfillment.

Currently on the ToDo list are:

  • Make it work repeatedly
  • Decimal input values
  • Powers
  • Keyboard shortcuts
  • Scientific notation
  • Switch to Shunting yard algorithm??? This algorithm is driven by the input data, rather than driven by the parser, alleviating the need for a buffer.

odin-calculator's People

Contributors

spirko 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.