当前位置:网站首页>简单测试轻量级表达式计算器Flee
简单测试轻量级表达式计算器Flee
2022-06-26 22:59:00 【gc_2299】
Flee是GitHub上基于.net的轻量级数学表达式解析和计算器,它支持计算数学表达式、带变量的数学表达式、带特殊处理函数的数学表达式等。从微信公众号中看到关于Flee的介绍文章(参考文献1是百度出来的同名的博客文章),准备测试一下,使用该模块计算数学表达式及带变量的数学表达式。
使用VS2019创建Winform程序,通过NuGet查找并安装Flee包及依赖项,如下图所示:

使用Flee计算不带变量和特殊处理函数的数学表达式很简单,直接使用其官网给的示例代码即可,测试代码及运行界面如下图所示。
try
{
ExpressionContext context = new ExpressionContext();
IDynamicExpression calcResult = context.CompileDynamic(txtExpression.Text);
txtResult.Text =Convert.ToString(calcResult.Evaluate());
}
catch (ExpressionCompileException ex)
{
if (ex.Reason == CompileExceptionReason.SyntaxError)
{
txtResult.Text = "Check your expression syntax" + "\r\n" + ex.Message;
}
else
{
txtResult.Text = ex.Message;
}
}

接下来测试带变量的数学表达式,这时最重要的是ExpressionContext类,该类用于保存表达式中的变量,测试代码及运行界面如下图所示。
try
{
ExpressionContext context = new ExpressionContext();
foreach(DataGridViewRow dgvr in dgvParams.Rows)
{
decimal tmpValue = 0;
if(string.IsNullOrEmpty(Convert.ToString(dgvr.Cells[0].Value))
|| !decimal.TryParse(Convert.ToString(dgvr.Cells[1].Value),out tmpValue))
{
continue;
}
context.Variables[Convert.ToString(dgvr.Cells[0].Value)] = tmpValue;
}
IDynamicExpression calcResult = context.CompileDynamic(txtExpression.Text);
txtResult.Text =Convert.ToString(calcResult.Evaluate());
}
catch (ExpressionCompileException ex)
{
if (ex.Reason == CompileExceptionReason.SyntaxError)
{
txtResult.Text = "Check your expression syntax" + "\r\n" + ex.Message;
}
else
{
txtResult.Text = ex.Message;
}
}

Flee的功能比较强大,本文只是测试了其中的最简单的使用方式,后续还会继续学习Flee的用法。
参考文献:
[1]https://github.com/mparlak/Flee
[2]https://github.com/mparlak/Flee/wiki/Examples
边栏推荐
- How to download on selenium computer -selenium download and installation graphic tutorial [ultra detailed]
- 尚硅谷DolphinScheduler视频教程发布
- 开放世界机甲游戏-Phantom Galaxies
- 为什么我不推荐去SAP培训机构参加培训?
- [710. random numbers in the blacklist]
- Unity animation knowledge of Art
- Electronic Society C language level 1 29, alignment output
- VB. Net class library to obtain the color under the mouse in the screen (Advanced - 3)
- FPGA -VGA显示
- Unityeditor Editor Extension - table function
猜你喜欢

Redcap is ready to come out. It is indispensable to build a "meta universe"

Briefly describe the model animation function of unity

What are the test case design methods?
![leetcode:152. Product maximum subarray [consider DP of two dimensions]](/img/c8/af6a4c969affd151a5214723dffb57.png)
leetcode:152. Product maximum subarray [consider DP of two dimensions]
![[cloud native topic -51]:kubesphere cloud Governance - operation - step by step deployment of microservice based business applications - database middleware redis microservice deployment process](/img/42/c2a25bb7a9fdad8fe0a048e9af44ca.jpg)
[cloud native topic -51]:kubesphere cloud Governance - operation - step by step deployment of microservice based business applications - database middleware redis microservice deployment process
![[Old Wei makes machines] issue 090: keyboard? host? Full function keyboard host!](/img/78/ece6da9a26c9d93988dac30ce93f99.png)
[Old Wei makes machines] issue 090: keyboard? host? Full function keyboard host!

數據清洗工具flashtext,效率直接提昇了幾十倍數

Using C to operate SQLSERVER database through SQL statement tutorial

Pass note 【 dynamic planning 】

leetcode:710. 黑名单中的随机数【映射思维】
随机推荐
Leetcode - the best time to buy or sell stocks
DLA model (classification model + improved segmentation model) + deformable convolution
Comprehensive evaluation of online collaboration documents: note, flowus, WOLAI, Feishu, YuQue, Microsoft office, Google Docs, Jinshan docs, Tencent docs, graphite docs, Dropbox paper, nutcloud docs,
Wechat applet automatically generates punch in Poster
Introduction to operator
Unity3d plug-in anyportrait 2D bone animation
Electronic Society C language level 1 31. Calculate line segment length
运筹说 第66期|贝尔曼也有“演讲恐惧症”?
Système de distribution Unity Composants en tissu (y compris les dépendances d'appel dynamique)
【混合编程jni 】第十二篇 jnaerator
电子协会 C语言 1级 29 、 对齐输出
[fundamentals of image processing] GUI image curve adjustment system based on MATLAB [including Matlab source code 1923]
What are the test case design methods?
Is it safe for CICC fortune to open an account? I want to open an account to speculate in stocks.
L'outil de nettoyage des données flashtext améliore directement l'efficacité de plusieurs dizaines de fois
Centos7编译安装Redis
DAST black box vulnerability scanner part 5: vulnerability scanning engine and service capability
Are there any risks for the top ten securities companies to register and open accounts? Is it safe?
How to write test cases and a brief introduction to go unit test tool testify
JupyterLab 常用配置