For example, I can type into Google or WolframAlpha 6+6
, or 2+237
, which could be programmed by asking a user for a
and b
, then evaluating return a+b
. However, I might also type 5*5^(e)
or any other combination, yet the program is hard-coded to only evaluate a+b
expressions.
It's easy to represent the more complex problems in code, on any common language.
return 5*pow(5,Math.E) #pseudocode
But if I can't expect a user's input to be of a given form, then it isn't as simple as
x = Input("enter coefficient")
b = input("enter base")
p = input("enter power")
print(x*pow(b,p))
With this code, I'm locked-in to my program only able to evaluate a problem of the form x*b^p
.
How do people write the code to dynamically handle math expressions of any form?