计算用户定义的公式(使用C ++) [英] calculating user defined formulas (with c++)

查看:81
本文介绍了计算用户定义的公式(使用C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望在我们的c ++程序中具有用户定义的公式。
例如值 v = x +(y-(z-2))/ 2 。在程序的后面,用户将定义x,y和z->程序应返回计算结果。
有时以后公式可能会更改,因此下次程序应解析公式并添加新值。

有什么想法/提示如何做这样的事情吗?

到目前为止,我只是来到解决方案中,编写一个解析器来计算这些公式-也许对此有任何想法?

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 ?

推荐答案

如果它会经常使用并且将来会扩展,我几乎建议您将Python或Lua添加到您的代码中。 Lua 是一种非常轻量级的脚本语言,您可以加入并提供新功能,运算符等。要执行更健壮和复杂的操作,请改用Python。

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.

这篇关于计算用户定义的公式(使用C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆