calculating user defined formulas (with c++)

前端 未结 8 1625
萌比男神i
萌比男神i 2020-12-29 12:07

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 -> t

相关标签:
8条回答
  • 2020-12-29 12:32

    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.

    0 讨论(0)
  • 2020-12-29 12:36

    If you want to write your own, search for "formal automata" and/or "finite state machine grammar"

    In general what you will do is parse the string, pushing characters on a stack as you go. Then start popping the characters off and perform tasks based on what is popped. It's easier to code if you force equations to reverse-polish notation.

    0 讨论(0)
提交回复
热议问题