Java - mathematical equation parsing and evaluating
807591Feb 22 2008 — edited Feb 28 2008I have successfully written a parser that parses out tokens that I want to use in a math equation. The ultimate goal of this project is to create a simple command-line calculator that does a wide range of tasks. The parsing results from a given equation look something like this:
equation:
(2 + 24) * 32 / sin(45) * (1 / cos(45))
tokens:
(, 2, +, 24, ), *, 32, /, sin, (, 45, ), *, (, 1, /, cos, (, 45, ), )
Now I am trying to figure out how to create logic that goes through these tokens and correctly evaluates them. Mathematically speaking, parenthetically combined elements should be evaluated first, in this case those are: (2 + 24), (45), and (1 / cos(45)).
So my question is how do I get from the tokens to the resulting equation evaluation?
Nathan