What is it?
A simple parser for calculating arithmetic expressions, supporting the operators +-*/ and parentheses.
How to use it?
Is algebraic expressions supported?
No. This is a plain arithmetic parser.
Can I see the source code of the parser?
Sure. Here you go. parser.js
Is the source code supported in all browser?
Yes, the parser is written in pure js with no use of ES6 syntax. It should be supported in most major browsers today.
How is operator precendence kept?
The precedence is from least preceding to most the following standard:
- / Division
- () Parentheses
This is in accordance with standard operator precendence in computerized mathematics.
What syntax is supported?
The following two examples shows the syntax supported.
2+3 should evaluate to 512 * 5– + 3 should evalute to -117
The examples shows that it is easy to calculate arithmetic expressions with this simple parser.
Is it easy to extend this parser?
Yes! Just add more syntax supported to the parser. Note the precedence, and that you have a main loop starting with the plus operator and going upwards to minus, division, multiplication and if necessary doing recursive calls again to the plus operator. If you want to support another operator such as sine of a number, you can add this.
Why not just use eval ?