The Shunting-Yard Algorithm, thats what you want to use