as of right now i cant think of any way to do this, except designating certain characters(such as ~ and/or some ASCII characters) which act as tags(much like html with <body> and </body>) to start and end the functions used to calculate the specified part of the equation.
or you might try making a list of all the character types and analize the list type by type(example: Numbers are their own type, and each mathematical symbol is its own types)
other than that, i dont know - as i've never processed equations like the ones you want to calculate...
normally i'd post some examples, but right now i'm bloody tired, i've been up for the last 3 days strait working...
if i have time when i wake up tomorrow morning, i'll try to get somethin' up here...but if you figured out how to calculate equations, i'm sure you can probably figure out how to use what i mentioned...
Sorry i couldnt be more of a help!
Happy Coding
(off to bed
)