If we follow Bedmas (brackets exponents division multiplication addition subtraction) we can break this down into a simple function.
First turn the equation into a list of components:
100 * 3 + 5 - 6
changes to
["100", "*", "3", "+", "5", "-", "6"]
Now evaluate every element to make sure that they are valid. ie) Each value in the list of components must be in the selection list or have the value, */+-, Also if there are n nums, then there should be n-1 syms
To get the result we can then evaluate the list,.. merging num-sym-num sections as we go, in the order of bedmas
In pseudo:
func int compute_val(ListString eqn)
while not eqn.length is 1
if "*" in eqn
index = eqn.getIndex("*")
replace eqn[index -1:index +1] with str((int) eqn[index -1] * (int)eqn[index +1])
else if "/" in eqn
index = eqn.getIndex("/")
replace eqn[index -1:index +1] with str((int) eqn[index -1] / (int)eqn[index +1])
else if "+" in eqn
index = eqn.getIndex("+")
replace eqn[index -1:index +1] with str((int) eqn[index -1] + (int)eqn[index +1])
else if "-" in eqn
index = eqn.getIndex("-")
replace eqn[index -1:index +1] with str((int) eqn[index -1] - (int)eqn[index +1])
return (int)eqn[0]
This would be the progression of the list as the equation is evaluated in the loop
["100", "*", "3", "+", "5", "-", "6"] --> ["300", "+", "5", "-", "6"] -->
["305", "-", "6"] --> ["299"]