你会如何​​在C#中的前pression解析器? [英] How would you create an expression parser in c#?

查看:161
本文介绍了你会如何​​在C#中的前pression解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是好奇。就像在跨preTED语言,甚至声明计算器怎么办人民改由输入或文件,给予实际EX pressions琴弦?例如:输入计算:,然后你写的2 * 7/4这是一个字符串。程序如何转换字符串转换为实际的EX pression?这是很容易字符串转换为int,但你如何转换的运营商的例如 + - / , 等等。?据我所知,这几样东西通常是在 C / C ++ 执行,但有可能使在一个高层次的语言这样的事情例如 C#?而如果是的话怎么办?

I am just curious. Like in interpreted languages or even statement calculators how do people convert the strings given by input or files to actual expressions? e.g "Enter Calculation: " and you write "2*7/4" which is a string. How does the program convert the string into an actual expression? It is easy to convert a string to an int but how do you convert operators like + , - , /, etc.? I understand that these kind of things are usually implemented in C/C++ but is it possible to make such a thing in a high-level language like C#? And If yes then how?

推荐答案

下面的文章你可以检查出来。也有像回避率。或者尚未另一种技术它允许你评估C#前$使用codeDOM提供者P. $ pssions。

Here's an article you might check out. There are also tools like Flee. Or yet another technique which allows you to evaluate C# expressions using a CodeDom provider.

这篇关于你会如何​​在C#中的前pression解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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