This section just shows some snippets of the code I wrote, if you want to see the full project (or more), it’s open-source on github. All of this code is written in TypeScript, with the help of a few libraries.
There are 4 main modules we need to write for this:
- Parser. It takes the input you type and transforms it into a tree
- Orderer. Re-arranges the tree to follow the order of operations
- Evaluator. Takes a tree as input and evaluates/solves it as much as it can.
- Simplifier. Evaluates the expression even further (more on this later)