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?
Asked
Active
Viewed 2,884 times
3 Answers
3
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.

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
1
I believe this can be achieved using expression trees, which is how LINQ is implemented.

Daniel Powell
- 8,143
- 11
- 61
- 108
1
Google "parse tree". One can be written in any Turing-complete language.

jcomeau_ictx
- 37,688
- 6
- 92
- 107