我需要一个快速运行的前pression解析器 [英] I need a fast runtime expression parser
问题描述
我需要找到一个快速,轻量级的前pression解析器。
I need to locate a fast, lightweight expression parser.
理想我想通过它的名称/值对(例如变量)和含恩pression来评价一个字符串列表。我需要从它后面是一个真/假值。
Ideally I want to pass it a list of name/value pairs (e.g. variables) and a string containing the expression to evaluate. All I need back from it is a true/false value.
该类型前pressions应该是大致相同的:
The types of expressions should be along the lines of:
varA == "xyz" and varB==123
基本上,只是一个简单的逻辑引擎,其前pression在运行时提供的。
Basically, just a simple logic engine whose expression is provided at runtime.
更新结果
在它至少需要支持==,=,>,> =,&LT中,<!=
UPDATE
At minimum it needs to support ==, !=, >, >=, <, <=
对于速度,我估计大约500 EX pressions为每个请求执行。我们会在某个地方看到100 /请求第二附近。我们目前的页面可能会执行下50毫秒。通常只会有涉及任何前pression 2个或3个变量。不过,我需要大约30执行之前加载到解析器。
Regarding speed, I expect roughly 5 expressions to be executed per request. We'll see somewhere in the vicinity of 100/requests a second. Our current pages tend to execute in under 50ms. Usually there will only be 2 or 3 variables involved in any expression. However, I'll need to load approximately 30 into the parser prior to execution.
更新2012年11月5日结果
更新有关的性能。我们近2年前实施nCalc。从那时起,我们已经扩大了它的使用,使得我们平均40+前pressions覆盖在背上后300多个变量。现在有成千上万的回发每秒发生的,绝对零性能下降。
UPDATE 2012/11/5
Update about performance. We implemented nCalc nearly 2 years ago. Since then we've expanded it's use such that we average 40+ expressions covering 300+ variables on post backs. There are now thousands of post backs occurring per second with absolutely zero performance degradation.
我们还没有性能损失扩大到包括附加功能了一把,再次。总之, nCalc 满足我们的所有需求,并超出我们的预期。
We've also extended it to include a handful of additional functions, again with no performance loss. In short, nCalc met all of our needs and exceeded our expectations.
推荐答案
你见过 HTTP://ncalc.$c$cplex。 COM ?
这是可扩展的,快速的(例如有自己的缓存),可以提供自定义功能和通过处理EvaluateFunction / EvaluateParameter事件在运行时varaibles。例如前pressions它可以解析:
It's extensible, fast (e.g. has its own cache) enables you to provide custom functions and varaibles at run time by handling EvaluateFunction/EvaluateParameter events. Example expressions it can parse:
Expression e = new Expression("Round(Pow(Pi, 2) + Pow([Pi2], 2) + X, 2)");
e.Parameters["Pi2"] = new Expression("Pi * Pi");
e.Parameters["X"] = 10;
e.EvaluateParameter += delegate(string name, ParameterArgs args)
{
if (name == "Pi")
args.Result = 3.14;
};
Debug.Assert(117.07 == e.Evaluate());
它也处理单code&放;许多数据本身类型。如果你想改变语法它配备了一个鹿角文件。也有支持MEF加载新功能的叉。
It also handles unicode & many data type natively. It comes with an antler file if you want to change the grammer. There is also a fork which supports MEF to load new functions.
它还支持逻辑运算符,日期/时间的字符串,如果语句。
It also supports logical operators, date/time's strings and if statements.
这篇关于我需要一个快速运行的前pression解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!