I describe the task: The user enters in a text field for example: y = x + 1 + x ^ 2; The program should calculate the value of. The x value will be constant and embedded in the program. How to implement?
Write a parser that converts the text entered by the user into some object model. Further, there may be options.
- A model can be an object model of lambda expressions. In this case, you can simply use the Compile method of the LambdaExpression class to get an executable method.
- The model may be in your format, but after receiving the disassembled tree, it is converted to Expression, and the task is reduced to case 1.
- You implement a visitor pattern in your model and write a visitor that each node of your expression tree converts into a delegate. After traversing a tree, you get a delegate that executes its contents.
Through the reverse Polish entry is done.
vbvm, msscript for vin.
This library creates a C # parser for the language specified in grammars that parse expressions, as well as with additional semantic actions.