JavaScript-based formula interpreter-1 [design]

Source: Internet
Author: User

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.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.