Here's a very good article on the algorithm you need:

http://en.wikipedia.org/wiki/Shunting_yard_algorithm