nil::crypto3::math::expressions::Parser Class Reference

Parse a mathematical expression. More...

#include <expression.hpp>

+ Collaboration diagram for nil::crypto3::math::expressions::Parser:

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()

nil::crypto3::math::expressions::Parser::Parser ( )
inline

Constructor.

◆ ~Parser()

nil::crypto3::math::expressions::Parser::~Parser ( )
inline

Destructor.

Member Function Documentation

◆ evaluate()

double nil::crypto3::math::expressions::Parser::evaluate ( std::map< std::string, double > const &  st = {})
inline

Evaluate the abstract syntax tree for a given symbol table.

Parameters
[in]stThe symbol table

◆ optimize()

void nil::crypto3::math::expressions::Parser::optimize ( )
inline

Perform constant folding onto the abstract syntax tree.

◆ parse()

void nil::crypto3::math::expressions::Parser::parse ( std::string const &  expr)
inline

Parse the mathematical expression into an abstract syntax tree.

Parameters
[in]exprThe expression given as a std::string

The documentation for this class was generated from the following file: