Problem description:
There are three edit box, respectively: edit1, edit2, edit3,
A command button: for the,
1. Define a string variable: var s: a string;
2. Will the contents of the edit1 assigned to "s" variables, such as: s:=edit1. Text;
3. Input in edit2 formula such as "2 * s + 5"; (this formula is not the only, according to the need and decide)
4. Click for the formula to calculate the result of "s + 2 * 5" input to edit3. The text,
Such as: 3 in edit1 input, input in edit1 * 2 + 5 s, click for the, the output value in the edit3 "11",
CodePudding user response:
http://blog.csdn.net/simonhehe/article/details/8395610CodePudding user response:
Can also be called JS eval ()CodePudding user response:
USES the script control is OkCodePudding user response:
This is part of the compiler, arithmetic computation, the simple tell me about method, I do not know whether useful,First cut token, cut the operators and operands, into a string list or array, it is not difficult,
Then do the parse () statement analysis processing, want to use recursive algorithm, the most simple, if you have braces, algorithm is a bit complicated, no brackets, only consider the operator precedence, algorithm is relatively simple, if you still want to simple, have to limit the input rule, forced to put the high priority operator in front, in this way, the parse process is just a few lines of code,
Operand if you include function, that is complicated, too serious to write compiler,
CodePudding user response: