HTTPS SSH

Simple JavaScript Formula Calculator with REPL

Implemented with function pointer style of command pattern. I used the function pointer style of the command pattern rather than inheritance because I originally intended to use this problem as an experiment in GO and RUST where function pointers are first class citizens.
Once I started playing with ideas in JavaScript the rest just kind of fell out. I don't like the recursive descent mechanism in JavaScript due to the stack overhead but it would be great for languages that do a good job of tail recursion optimization like Scala.

  • Applies JavaScript GREP to simplify parsing
  • Uses recursive descent parser to apply operator precedence
  • function pointer operator interface makes adding new operators easy.
  • V 0.001
  • (C) Jan-2017, MIT Free Use, No promises, No Warranty

Configuration

  • Tested with Node version V4.4.1
  • Install Node JS
  • Download repository
  • CD into install directory
  • Ensure Node executable is in path
  • Run using node command line.

How to run tests

Using Windows Shell

Run Test Harness:
  calcTest.bat

Run REPL:
  calc.bat

Using Node.js

Run Test Harness:
  node calcTest.bat
Run REPL:
  node calcREPL.js

Sample Formula:

3+2 =

5 + 4 C + 8 =

-4*6/2 =

3! / 11 A + 9 =

3! / 11 =

0.4 1/x * 3 =

807 * 807 =

9999999999999.0 * 999999999999.0 =

Known improvements Needed

  • Define a more formal operator precedence syntax.
  • Define more formal support for immediate unary versus binary operators
  • Support parameterized functions.
  • Need more extensive set of tests.
  • Remove need for grep pre processor requires improving next token to handle syntax variations directly.

Who do I talk to?