The formula interpreter is relatively simple. I thought it would take three days and the result was still used for a week. It seems that I have to re-evaluate my productivity.
Question:
Principle:
1. parse the formula into a sequence of inverse Polish notation;
2. Evaluate the inverse Polish sequence;
The formula interpreter involves the following issues:
1. Type representation;
2. Type relationship and operation;
3. Expression parsing;
4. Evaluate the expression;
Therefore, we need:
1. Type System: A type system simulated by JavaScript language features;
2. operation data base type;
3. value types derived from the operation base type: Value Type, boolean type, and text type;
4. Base types of Operators;
5. Primitive operators derived from the base types of operators: unary operators, binary operators, and functions;
6. Various types of operators derived from the primitive operator type;
9. expression type;
10. expression parser;
11. expression calculator;
The class diagram is as follows:
Figure 1 Operand Class digoal
Figure 2 Operator Class digoal
Figure2 Other Class digoal
Because Visio is not installed, VSE is used to generate class diagrams. Therefore, more complex class relationships such as aggregation and future operation diagrams and sequence diagrams are not supported.