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?

    4 answers 4

    Write a parser that converts the text entered by the user into some object model. Further, there may be options.

    1. 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.
    2. 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.
    3. 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.
    • I will try. Thank. - Jakeroid

    Through the reverse Polish entry is done.

    • In the sense of parsing a line in the SCR, and then it will be easier to add / subtract / multiply / divide? - Jakeroid
    • Yes, then elementary parsing goes) and calculation - Sergey

    vbvm, msscript for vin.

      peg-sharp :

      This library creates a C # parser for the language specified in grammars that parse expressions, as well as with additional semantic actions.