What I'd do, is handle this recursivly. Basicly, to parse parenthesis, do this:

scan until you find a (
call the recursive function from that point, to return the final value of what is in the parenthesis.

You do this by extracting everything from the matching closing )
Every time you encounter another (, you call the recursive function. Every time you encounter a ), you apply your math to the contents of the ( ), and return it.