In actual project development, if you need to parse the mathematical formula and do not need to use the interpreter mode for design, you can directly use some third-party parsing toolkit, which can be collectively referred toMath expression parser (MEP), Such as expression4j, Jep, jbcparser, symja, math
Expression string Parser (MESP) and so on replace the interpreter mode, which can easily explain some more complex grammar, powerful functions, simple use, and better efficiency.
The following describes two commonly used third-party parsing toolkit based on the Java language:
(1) expression4j
Expression4j is an open-source Java-based framework used to operate mathematical expressions. It is a mathematical formula parser. In expression4j, mathematical expressions can be stored in string objects, for example, "F (x, B) = 2 * X-cos (B)" and "g (x, y) = f (y, x) *-2. Expression4j is highly customized. Users can customize the literal method. Its main functions include basic mathematical operations of real numbers and plural numbers, and support basic mathematical functions (such as sin and COS), complex functions (such as f (x) = 2 * x + 5, g (x) = 3 * f (x + 2)-x) you can also define function directories (function sets) and support xml configuration files. It is not yet a very mature framework and is still being improved. For more information about expression4j, visit: http://expression4j.sourceforge.net /.
(2) Jep
Jep (javamathematical expression parser) is a Java class library used to parse and solve mathematical expressions. Using the pack provided by Jep, We can enter any mathematical formula represented by a string and then solve it immediately. Jep supports User-Defined variables, constants, and udfs. It also contains a large number of common mathematical functions and constants. For more information about Jep, visit the website: http://www.singularsys.com/jep /.
[Author: Liu Wei http://blog.csdn.net/lovelion]