calculating user defined formulas (with c++)

前端 未结 8 1701
萌比男神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: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.

提交回复
热议问题