It's weird that most of the code is in the header files.. also do you check for divide by zero?
Try to rewrite the whole thing as a single recursive function with two arguments (rest of input string, precedence of left side). You could use longjmp/setjmp to abort when there are errors.