Calculator
Step 6
|
#include <node.hpp>
Public Member Functions | |
node () | |
node (std::istream &stream) | |
node (long x) | |
node (int x) | |
node (double x) | |
node (number num) | |
node (std::string identifier) | |
node (char op, node operand) | |
node (node left, char op, node right) | |
node (identifier_list parameters, node definition) | |
node (std::string name, node_list arguments) | |
node (node const &)=default | |
node (node &&)=default | |
node & | operator= (node const &)=default |
node & | operator= (node &&)=default |
~node ()=default | |
void | print (std::ostream &stream, int indent=0) const |
number | evaluate () const |
std::string | to_string () const |
identifier_list const & | get_parameters () const |
void | save (std::ostream &stream) 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 | ( | std::istream & | stream | ) |
Construct a node by reading from a library file.
Definition at line 27 of file node.cpp.
References node_impl::read_node().
node::node | ( | long | x | ) |
Construct an integer node.
x | The integer |
Definition at line 35 of file node.cpp.
node::node | ( | int | x | ) |
Construct an integer node.
x | The integer |
Definition at line 31 of file node.cpp.
node::node | ( | double | x | ) |
Construct a floating-point node.
x | The value |
Definition at line 39 of file node.cpp.
node::node | ( | number | num | ) |
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 55 of file node.cpp.
References make_binary_operator().
node::node | ( | identifier_list | parameters, |
node | definition | ||
) |
node::node | ( | std::string | name, |
node_list | arguments | ||
) |
|
default |
|
default |
|
default |
number node::evaluate | ( | ) | const |
Evaluate a parse tree. Evaluate and tree and return the result.
Definition at line 73 of file node.cpp.
References pimpl_.
Referenced by BOOST_AUTO_TEST_CASE(), node_binary::evaluate_left(), node_identifier::evaluate_node(), node_function::evaluate_node(), node_unary::evaluate_operand(), node_binary::evaluate_right(), and parser::get_statement().
identifier_list const & node::get_parameters | ( | ) | const |
Return a list of parameter names. Most node return a reference to a global, static, const, empty list. Only function nodes return a list of parameters.
Definition at line 85 of file node.cpp.
References pimpl_.
Referenced by node_function_call::evaluate_node().
|
staticprivate |
Factory function to make the binary operator nodes.
Definition at line 9 of file node.cpp.
Referenced by node().
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 67 of file node.cpp.
References pimpl_.
Referenced by node_function::print_node(), node_negate::print_node(), node_add::print_node(), node_subtract::print_node(), node_multiply::print_node(), and node_divide::print_node().
void node::save | ( | std::ostream & | stream | ) | const |
Save the node to a stream.
stream | The output stream |
Definition at line 91 of file node.cpp.
References pimpl_.
Referenced by node_function::save_node(), node_negate::save_node(), node_add::save_node(), node_subtract::save_node(), node_multiply::save_node(), and node_divide::save_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 79 of file node.cpp.
References pimpl_.
Referenced by BOOST_AUTO_TEST_CASE().
|
private |
Definition at line 114 of file node.hpp.
Referenced by evaluate(), get_parameters(), print(), save(), and to_string().