A simple toolkit written by C++ to support the calculation of four operational strings. Inspired by Muparser.
In this gadget, I have implemented a simpler and more efficient parser. Four operations are supported: addition, subtraction, multiplication and division, and exponentiation. Of course, you can also extend other binary operators, such as logarithm. For the first time, the tool is also an expression that supports parenthesis precedence.
- root folder
- muparser_engine
- parser_qt : toolkit written by qt5.
- parser_std : toolkit written by c++ stdand.
- muparser_engine : Muparser library test api.
- examples : use gui to test the toolkit.
- common : common tools.
- test_data : some test data.
- main.cpp
Use the easy_parser_qt like follow:
// 1. include the header
#include <parser_qt/easy_parser_qt.h>
// 2. init the error info item. this is optional.
ERRORINFO_ST info = EasyParserQt::E000;
// 3. eval the math formula result.
double eparser_res = EasyParserQt::eval("1+2.2*-2*4-54^3+43", info);
Use the easy_parser_std like follow:
// 1. include the header
#include <parser_qt/easy_parser_std.h>
// 2. init the error info item. this is optional.
ZHYSTD::ERRORINFO_ST zhy_info = ZHYSTD::EasyParserStd::E000;
// 3. eval the math formula result.
double eparser_res = EPARSERSTD::EasyParserStd::eval("1+2.2*-2*4-54^3+43", info);
In this toolbox, the string is divided into two valid morphemes, one is the Operand and the other is the operator. Operands are valid numeric types, numbers that support ordinary numeric representation and scientific numeration. Operators support five types of symbols and support parentheses as precedence calculators.
In this toolkit, To speed up processing, operands are double-precision floating-point types, that is, double types, and do not do the work of distinguishing between integers and floating-point numbers.
| Operator | Function | Explain | Level |
|---|---|---|---|
| + | addition | addition two number | 0 |
| - | subtraction | subtraction two number | 0 |
| * | multiplication | multiplication two number | 1 |
| / | division | division two number | 1 |
| ^ | exponentiation | exponentiation two number | 2 |
| Operator | Function | Explain | Level |
|---|---|---|---|
| ( ) | Parenthesis | The operations are limited to calculate the data in parentheses | 3 |
- GCC (>= 4.6)
- cmake (Optional)
- qmake
- pkg-config
- Qt5 (5.7 or newer)
There are two compilation methods here: one is a package building method based on the Debian package build system, and the other is a straightforward command-line compilation method. This is the recommended approach.
first download the sources:
https://github.com/SunStorm2018/libemathparser.gitUse Debian package build system:
cd libemathparser
# install build dependencies
sudo sudo apt build-dep .
# build deb package
dpkg-buildpackage -us -uc -bBuild libemathparser step by step as follows:
Build with Qt5:
# install build dependencies
sudo apt-get install build-essential cmake pkg-config qt5-qmake qt5-default qttools5-dev-tools qttools5-dev qtbase5-dev qtbase5-dev-tools use qmake, the libemathparser will install in /usr/lib ; /usr/inclue/libemathparser/:
qmake
make
sudo make installuse cmake, , the libemathparser will install in /usr/lib ; /usr/inclue/libemathparser/
mkdir build-release
cd build-release
cmake -DCMAKE_BUILD_TYPE=Release ..
make
sudo make installUse Qt Creator to build.
