OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
matheval::detail::eval_ast< real_t > Class Template Reference

Evaluate the Abstract Syntax Tree. More...

#include <matheval.hpp>

Collaboration diagram for matheval::detail::eval_ast< real_t >:

Public Types

using result_type = real_t
 Necessary typedef for boost::apply_visitor.
using symbol_table_t = std::map<std::string, result_type>
 Type of the symbol table.

Public Member Functions

 eval_ast (symbol_table_t sym)
 Constructor.
result_type operator() (nil) const
 Empty nodes in the tree evaluate to 0.
result_type operator() (result_type n) const
 Numbers evaluate to themselves.
result_type operator() (std::string const &c) const
 Variables evaluate to their value in the symbol table.
result_type operator() (expr_ast< real_t > const &ast) const
 Recursively evaluate the AST.
result_type operator() (binary_op< real_t > const &tree) const
 Evaluate a binary operator and optionally recurse its operands.
result_type operator() (unary_op< real_t > const &tree) const
 Evaluate a unary operator and optionally recurse its operand.

Private Attributes

symbol_table_t st

Detailed Description

template<typename real_t>
class matheval::detail::eval_ast< real_t >

Evaluate the Abstract Syntax Tree.

This visits all the variants of the AST and applies the stored operators.

Definition at line 209 of file matheval.hpp.

Member Typedef Documentation

◆ result_type

template<typename real_t>
using matheval::detail::eval_ast< real_t >::result_type = real_t

Necessary typedef for boost::apply_visitor.

Definition at line 213 of file matheval.hpp.

◆ symbol_table_t

template<typename real_t>
using matheval::detail::eval_ast< real_t >::symbol_table_t = std::map<std::string, result_type>

Type of the symbol table.

Definition at line 216 of file matheval.hpp.

Constructor & Destructor Documentation

◆ eval_ast()

template<typename real_t>
matheval::detail::eval_ast< real_t >::eval_ast ( symbol_table_t sym)
inlineexplicit

Constructor.

Saves the symbol table to apply variables.

Definition at line 222 of file matheval.hpp.

References st.

Member Function Documentation

◆ operator()() [1/6]

template<typename real_t>
result_type matheval::detail::eval_ast< real_t >::operator() ( binary_op< real_t > const & tree) const
inline

Evaluate a binary operator and optionally recurse its operands.

Definition at line 247 of file matheval.hpp.

References matheval::detail::binary_op< real_t >::lhs, matheval::detail::binary_op< real_t >::op, and matheval::detail::binary_op< real_t >::rhs.

◆ operator()() [2/6]

template<typename real_t>
result_type matheval::detail::eval_ast< real_t >::operator() ( expr_ast< real_t > const & ast) const
inline

Recursively evaluate the AST.

Definition at line 241 of file matheval.hpp.

References matheval::detail::expr_ast< real_t >::tree.

◆ operator()() [3/6]

template<typename real_t>
result_type matheval::detail::eval_ast< real_t >::operator() ( nil ) const
inline

Empty nodes in the tree evaluate to 0.

Definition at line 225 of file matheval.hpp.

◆ operator()() [4/6]

template<typename real_t>
result_type matheval::detail::eval_ast< real_t >::operator() ( result_type n) const
inline

Numbers evaluate to themselves.

Definition at line 228 of file matheval.hpp.

◆ operator()() [5/6]

template<typename real_t>
result_type matheval::detail::eval_ast< real_t >::operator() ( std::string const & c) const
inline

Variables evaluate to their value in the symbol table.

Definition at line 231 of file matheval.hpp.

References c, and st.

◆ operator()() [6/6]

template<typename real_t>
result_type matheval::detail::eval_ast< real_t >::operator() ( unary_op< real_t > const & tree) const
inline

Evaluate a unary operator and optionally recurse its operand.

Definition at line 256 of file matheval.hpp.

References matheval::detail::unary_op< real_t >::op, and matheval::detail::unary_op< real_t >::rhs.

Member Data Documentation

◆ st

template<typename real_t>
symbol_table_t matheval::detail::eval_ast< real_t >::st
private

Definition at line 264 of file matheval.hpp.

Referenced by eval_ast(), and operator()().


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