评估来自字符​​串数学函数 [英] Evaluate Mathematical Function from String

查看:98
本文介绍了评估来自字符​​串数学函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能给我说说怎样才能让一个简单的数学EX pression用C解析器的一些想法?
用户在串入一个数学函数,并从字符串我想创建的
在功能C.
例如。 X +罪(2 * X)

Can you give me some ideas about how can i make a simple mathematical expression parser in C? User enters a mathematical function in a string and from the string i want to create the function in C. eg. "x + sin(2*x)"

- >返回X +罪(2个);

-> return x + sin(2x);

先谢谢了。

推荐答案

您可以分析基于调度场算法恩pression <一个href=\"http://en.wikipedia.org/wiki/Shunting-yard_algorithm\">http://en.wikipedia.org/wiki/Shunting-yard_algorithm.您将需要延伸到处理函数调用,如正弦,余弦等...

You can parse the expression based "Shunting-Yard Algorithm" http://en.wikipedia.org/wiki/Shunting-yard_algorithm. You will need to extend to handle the function calls such as sin, cos etc...

这篇关于评估来自字符​​串数学函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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