评估来自字符串数学函数 [英] Evaluate Mathematical Function from String
问题描述
你能给我说说怎样才能让一个简单的数学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屋!