Calculator
Step 3
|
#include <node.hpp>
Public Member Functions | |
node () | |
node (double number) | |
node (std::string identifier) | |
node (node identifier, node number) | |
node (char op, node operand) | |
node (node left, char op, node right) | |
~node ()=default | |
node (node const &)=default | |
node (node &&)=default | |
node & | operator= (node const &)=default |
node & | operator= (node &&)=default |
void | print (std::ostream &stream, int indent=0) const |
double | evaluate () const |
std::string | to_string () const |
Static Private Member Functions | |
static std::shared_ptr< node_impl > | make_binary_operator (node, char, node) |
Factory function to make the binary operator nodes. More... | |
Private Attributes | |
std::shared_ptr< node_impl > | pimpl_ |
Wrapper class for all parse-tree nodes. The actual parse tree nodes derive from node_impl. This class uses the pimpl idiom to make it easier to work with node objects.
node::node | ( | double | number | ) |
node::node | ( | std::string | identifier | ) |
node::node | ( | char | op, |
node | operand | ||
) |
Construct a binary operator node.
left | The left-hand parse-tree |
op | The operator character, e.g., '*' |
right | The right-hand operand |
Definition at line 40 of file node.cpp.
References make_binary_operator().
|
default |
|
default |
|
default |
double node::evaluate | ( | ) | const |
Evaluate a parse tree. Evaluate and tree and return the result.
Definition at line 50 of file node.cpp.
References pimpl_.
Referenced by BOOST_AUTO_TEST_CASE(), node_binary::evaluate_left(), node_unary::evaluate_operand(), node_binary::evaluate_right(), node_assign::evaluate_value(), and parse_loop().
|
staticprivate |
void node::print | ( | std::ostream & | stream, |
int | indent = 0 |
||
) | const |
Print a tree. For debugging, print a visual representation of the parse tree. Each level increments the indent
to make the tree structure evident.
stream | The output stream |
indent | The indentation. |
Definition at line 44 of file node.cpp.
References pimpl_.
Referenced by node_assign::print_node(), node_negate::print_node(), node_add::print_node(), node_subtract::print_node(), node_multiply::print_node(), and node_divide::print_node().
std::string node::to_string | ( | ) | const |
Return a string representation. For an identifier node, return the identifier. For all other nodes, return a string representation of the evaluated value.
Definition at line 56 of file node.cpp.
References pimpl_.
Referenced by BOOST_AUTO_TEST_CASE(), and node_assign::get_identifier().
|
private |
Definition at line 72 of file node.hpp.
Referenced by evaluate(), print(), and to_string().