View Full Version : Converting a string to a command?

07-07-2009, 02:05 PM

I was wondering if it was possible to convert a string like "2x * x + 3x +5" to operators and integers so that this could actually be calculated? I'm sure there is a way but I really don't know how I would go about doing that. I have designed an algorithem before that was able to get easy functions simply by reading each character and then deciding on what to do, but that was very limited, and would be way to complex.

Anybody have a tip of how this can be achieved?


07-07-2009, 04:28 PM
You would need to parse it and then run the correct commands based on whats in the string. It wouldn't be too hard, if you want to support more complex equations that use parenthesis and brackets it would be harder but not by much. You also have to remember the order of operations in math, you can't simply execute from left to right.