我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/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: www.codeproject/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
- 的五分钟的介绍ANTLR
- 您也可以尝试使用F#,这是这种伟大的语言的问题。结果例如见的 FsLex由克里斯·史密斯
更多推荐
开源数学表达式解析器?
发布评论