开源数学表达式解析器? [英] Open source mathematical expression parser?

查看:379
本文介绍了开源数学表达式解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我GOOGLE了,来到空白 - 所以它的时间在SO再次测试好乡亲! :?)

I googled and came up blank - so it's time to test the good folks at SO again! :)

任何人都可以建议分析和计算数学表达式的开源库(PREF为.NET)

Can anyone recommend an open source library (pref for .NET) that parses and calculates mathematical expressions?

例如:输入表达式= 2 +(N-1)* 4,参数的键/值 N = 2 ,输出= 6

e.g. input expression = "2+(n-1)*4", parameter key/value n=2, output = 6.

推荐答案

我会看看的 NCalc 。下面是该项目的描述:

I would take a look at NCalc. Here is a description of the project:

NCalc在.NET中的数学表达式求值。 NCalc可以解析任何言论和评价结果,包括静态或动态参数和自定义函数。有关该技术的更多信息,我们用来建立这个框架,请阅读这篇文章:的http:// www.codeproject.com/KB/recipes/sota_expression_evaluator.aspx

NCalc is a mathematical expressions evaluator in .NET. NCalc can parse any expression and evaluate the result, including static or dynamic parameters and custom functions. For additional information on the technique we used to create this framework please read this article: http://www.codeproject.com/KB/recipes/sota_expression_evaluator.aspx

如果这是你的目的过于复杂,你可以看看在任何解析器生成为C#。这些工具允许您指定表达式的语法和生成的代码,将解析它。写作NUMERICA表达式解析器应该是相当简单的。例如,见

If this is too complex for your purpose, you can take a look at any "parser generator" for C#. These tools allow you to specify the grammar of your expression and generate code that will parse it. Writing parser for numerica expressions should be pretty straightforward. See for example

这篇关于开源数学表达式解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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