Calculator demo with Addition, Subtraction, Division, Multiplication, Exponentiation, Positive and Negative Integers, Parentheses

Exponentiation is right-associative, multiplication and division are left-associative. Exponentiation happens before multiplication and division, which happens before addition or subtraction.

The input grammar:

The JavaScript code

<-- When you press this button, the evaluateExpresion function defined in the JavaScript code inside the last script tag in the source code of this page will run, which will take the grammar specified above, turn it into a parser, and then proceed to evaluate it. Type in some addition and subtraction and multiplication and division commands (5 + 7 or 5 + 5*7 -1 or 1 *2 + 3/3) and press the evaluate button to see what happens! Look in the code to find out how it works.

Grammar

Matches after pruning

Raw matches(shows parser's internal workings)