Well first things first
regex would be the classic. you just define a ruleset
since regular expressions are a common way to parse formal languages.
you split the language into tokens and you build the AST from it. in your case you just have to match the operator to a function
const methodMap = {
'+': (a, b) => return Number(a) + Number(b),
'-': (a, b) => return Number(a) - Number(b),
'*': (a, b) => return Number(a) * Number(b),
'/': (a, b) => return Number(a) / Number(b),
}
if (methodMap[symbol]) {
operation = methodMap[symbol];
return operation(a, b);
}
throw Error('something meaningful')
something along the line of this would be a trivial solution. as long as you stay within the single operation set.
however if you want to build more complex operations all of the sudden ordering will be important: precedence of operators :)
precedence: you basically just need to group them and execute them in order. you need to keep the correlation between operator and the operands. so you need to group the tokens.
but just to be fair ;D ... you could just skip that and use "eval" but be aware eval is evil which basically means is hackable but it will save you time :D