你会如何​​在C#中的前pression解析器?你会、pression

2023-09-03 07:16:33 作者:凉了时光病了心脏

我只是好奇。就像在跨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.