c# - 开源数学表达式解析器?

标签 c# .net parsing open-source

<分区>

我在谷歌上搜索了一下,结果一片空白 - 所以是时候再次测试 SO 的好人了! :)

谁能推荐一个解析和计算数学表达式的开源库(pref for .NET)?

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

最佳答案

我会看一下 NCalc .以下是该项目的描述:

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# 的“解析器生成器”。这些工具允许您指定表达式的语法并生成解析它的代码。为数值表达式编写解析器应该非常简单。参见示例

关于c# - 开源数学表达式解析器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3079650/

相关文章:

.net - 使用 .Net 的 Exchange 管理 Powershell

c# - 通过 PHP 与 .net 通信

c# - PropertyInfo.GetValue 返回 int,但转换为十进制会导致 InvalidCastException

java - 无法删除我的 ip_address 中的前导零

arrays - PHP Dom 解析表到数组

c# - 用户控件之间的 WPF 通信

c# - .NET Core 2.1 Web Scraper控制台输出“HtmlAgilityPack.HtmlDocument

c# - Fody 是否在总装中留下任何引用资料/痕迹?

html - iOS 使用 Hpple 解析 HTML 属性

c# - 获取 Streamreader 的长度