We would like to have user defined formulas in our c++ program. e.g. The value v = x + ( y – (z – 2)) / 2. Later in the program the user would define x,y and z -> the program should return the result of the calculation.
Somewhen later the formula may get changed, so the next time the program should parse the formula and add the new values.
Any ideas / hints how to do something like this ?
So far I just came to the solution to write a parser to calculate these formulas – maybe any ideas about that ?
If it will be used frequently and if it will be extended in the future, I would almost recommend adding either Python or Lua into your code. Lua is a very lightweight scripting language which you can hook into and provide new functions, operators etc. If you want to do more robust and complicated things, use Python instead.