I run an expression evaluation program like. My problem is that I cannot figure out how to handle operation priorities. I used recursion to find the innermost pair of parentheses and, when I found, resolve the expression inside them, for example:
Evaluate("2 + (3 * 5)")
will repeat the call this way:
Evaluate("3 * 5")
now, since there are no brackets, it calculates the result and calls itself at another time:
Evaluate("2 + 15")
Well, the return value is 17, as expected. But if I call Evaluate("2 + 3 * 5"), the result will be as follows:
Evaluate("2 + 3 * 5")
Evaluate("5 * 5")
.
. , ? , .
, , ?