Parse a mathematical expression. More...
#include <expression.hpp>
Public Member Functions | |
double | evaluate (std::map< std::string, double > const &st={}) |
Evaluate the abstract syntax tree for a given symbol table. More... | |
void | optimize () |
Perform constant folding onto the abstract syntax tree. More... | |
void | parse (std::string const &expr) |
Parse the mathematical expression into an abstract syntax tree. More... | |
Parser () | |
Constructor. More... | |
~Parser () | |
Destructor. More... | |
Detailed Description
Parse a mathematical expression.
This can parse and evaluate a mathematical expression for a given symbol table using Boost.Spirit X3. The templates of Boost.Spirit are very expensive to parse and instantiate, which is why we hide it behind an opaque pointer.
The drawback of this approach is that calls can no longer be inlined and because the pointer crosses translation unit boundaries, dereferencing it can also not be optimized out at compile time. We have to rely entirely on link-time optimization which might be not as good.
The pointer to the implementation is a std::unique_ptr which makes the class not copyable but only moveable. Copying shouldn't be required but is easy to implement.
Constructor & Destructor Documentation
◆ Parser()
|
inline |
Constructor.
◆ ~Parser()
|
inline |
Destructor.
Member Function Documentation
◆ evaluate()
|
inline |
Evaluate the abstract syntax tree for a given symbol table.
- Parameters
-
[in] st The symbol table
◆ optimize()
|
inline |
Perform constant folding onto the abstract syntax tree.
◆ parse()
|
inline |
Parse the mathematical expression into an abstract syntax tree.
- Parameters
-
[in] expr The expression given as a std::string
The documentation for this class was generated from the following file: