从字符串计算数学函数 [英] Evaluate Mathematical Function from String

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

问题描述

你能给我一些关于如何在 C 中创建一个简单的数学表达式解析器的想法吗?

Can you give me some ideas about how can I make a simple mathematical expression parser in C?

用户在字符串中输入一个数学函数,并从字符串中输入我想在 C 中创建该函数的字符串.例如.x + sin(2*x)

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)

-> return x + sin(2x);

提前致谢.

推荐答案

您可以解析基于Shunting-Yard Algorithm"的表达式 http://en.wikipedia.org/wiki/Shunting-yard_algorithm.您将需要扩展以处理函数调用,例如 sin、cos 等...

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天全站免登陆