http://en.wikipedia.org/wiki/Shunting_yard_algorithm
This has been simplified to remove the processing of function calls / method invocations. tjr
Input 3+4*2/(1-5)^2
Read "3"
Add "3" to the output
Output: 3
Read "+"
Push "+" onto the stack
Output: 3
Stack: +
Read "4"
Add "4" to the output
Output: 3 4
Stack: +
Read "*"
Push "*" onto the stack
Output: 3 4
Stack: + *
Read "2"
Add "2" to the output
Output: 3 4 2
Stack: + *
Read "/"
Pop "*" off stack and add it to output, push "/" onto the stack
Output: 3 4 2 *
Stack: + /
Read "("
Push "(" onto the stack
Output: 3 4 2 *
Stack: + / (
Read "1"
Add "1" to output
Output: 3 4 2 * 1
Stack: + / (
Read "-"
Push "-" onto the stack
Output: 3 4 2 * 1
Stack: + / ( -
Read "5"
Add "5" to output
Output: 3 4 2 * 1 5
Stack: + / ( -
Read ")"
Pop "-" off stack and add it to the output, pop (
Output: 3 4 2 * 1 5 -
Stack: + /
Read "^"
Push "^" onto stack
Output: 3 4 2 * 1 5 -
Stack: + / ^
Read "2"
Add "2" to output
Output: 3 4 2 * 1 5 - 2
Stack: + / ^
End of Expression
Pop stack to output
Output: 3 4 2 * 1 5 - 2 ^ / +