I have been doing something like that in a recent program that takes what amounts to written equations and computes them. I first tried it with strings, but that was slow and somewhat painful. I then tried it using objects. This turned out to be much cleaner, and somewhat faster.

The technique I used was to put both numbers and operators into the same type of object. One field held value, another held an identifier, etc. This leaves the entire equation represented by an array of objects.

I tranlsated this into a number by parsing through the objects, and putting the values into a temporary array based on operator precedence. The idea is that if a number is separated from a second number by either * or /, then do the calculation. If separated by +, then put the first number into the temporary array. If separated by -, then put the negative of the first number into the temporary array. Therefore, 5+6*3/9-3 would have 5,2,-3 in the temporary array. Sum the values in the temporary array to get the result. Parenthesis are handled using a recursive call to the translation function.

Reverse polish notation might improve on this, though it can be highly non-intuitive for for some people.

Hope this helps.