Implements the Shunting-yard algorithm