Say I have a string, an equation, with a variable, X, that I want to compute with varying values of X. The most obvious and straight forward way to do this would be to parse the equation every time, inserting the value of X every time. The problem is that this is very inefficient to re-parse the whole string when the only change will be the value of X. Is there a "standard" solution to this problem?

I've thought of a few solutions, some more complex to code than others.

Solution 1, the easiest(other than re-parsing): Tokenize everything, make a way to encode the equation in predetermined control codes, then encode the equation in a way that sequentially(from one instruction to the next) follows order of operations that should be used in the original equation.

Solution 2, definitely not the way I want to go, but also definitely the most efficient: Translate the equation into a machine code way to compute it(basically, translate to asm, then assemble it on the fly), making any reference to X a pointer to a variable I could change in between runnings of the code that symbolizes the equation.