Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java - mathematical equation parsing and evaluating

807591Feb 22 2008 — edited Feb 28 2008
I 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 27 2008
Added on Feb 22 2008
36 comments
2,542 views