methor

TypeScriptDenoParser CombinatorsMath Evaluator

This is a math evaluator / calculator, written 100% from scratch. I used my own library (djena) as the base building blocks for implementing this. They both use parser combinators for parsing the input.

It supports the following features:

  • Basic arithmetics - 5+5, 23/18, etc.
  • Support for grouping expressions (5-2)*3)
  • Consuming whitespace - 5 + 4 and 5+4 are equivalent
  • Operator precedence and left/right associativity - 50/2*2+10 gets evaluated to 60, not 22.5
  • Some useful constants - PI and TAU
  • Builtin math functions - sin, cos, abs, pow
  • Interactive REPL

The source code for this can be found on GitHub.