#include <node.hpp>
Public Member Functions | |
node () | |
node (double number) | |
node (std::string const &identifier) | |
node (char op, node operand) | |
node (node left, char op, node right) | |
node (identifier_list const ¶meters, node definition) | |
node (std::string const &name, node_list const &arguments) | |
node (node const &n) | |
~node () | |
node & | operator= (node const &n) |
void | print (std::ostream &stream, int indent=0) const |
double | evaluate () const |
std::string | to_string () const |
identifier_list const & | get_parameters () const |
Static Private Member Functions | |
static node_impl * | make_binary_operator (node, char, node) |
Factory function to make the binary operator nodes. | |
Private Attributes | |
node_impl * | pimpl_ |
Definition at line 25 of file node.hpp.
node::node | ( | ) |
node::node | ( | double | number | ) |
Construct a numeric node.
number | The number |
Definition at line 30 of file node.cpp.
00031 : pimpl_(new node_number(number)) 00032 {}
node::node | ( | std::string const & | identifier | ) |
Construct an identifier node.
identifier | The identifier |
Definition at line 34 of file node.cpp.
00035 : pimpl_(new node_identifier(identifier)) 00036 {}
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 42 of file node.cpp.
00043 : pimpl_(make_binary_operator(left, op, right)) 00044 {}
node::node | ( | identifier_list const & | parameters, | |
node | definition | |||
) |
Construct a function definition node.
parameters | The list of all the parameter names | |
definition | The function definition |
Definition at line 46 of file node.cpp.
00047 : pimpl_(new node_function(parameters, definition)) 00048 {}
node::node | ( | std::string const & | name, | |
node_list const & | arguments | |||
) |
Construct a function call node.
name | The function name | |
arguments | The function arguments |
Definition at line 50 of file node.cpp.
00051 : pimpl_(new node_function_call(name, arguments)) 00052 {}
node::node | ( | node const & | n | ) |
node::~node | ( | ) |
Copy assignment operator decrements the reference count.
n | the source of the assignment |
Definition at line 59 of file node.cpp.
References node_impl::add_ref(), node_impl::del_ref(), and pimpl_.
00060 { 00061 n.pimpl_->add_ref(); 00062 pimpl_->del_ref(); 00063 pimpl_ = n.pimpl_; 00064 00065 return *this; 00066 }
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 68 of file node.cpp.
References pimpl_, and node_impl::print().
Referenced by node_divide::print_node(), node_multiply::print_node(), node_subtract::print_node(), node_add::print_node(), node_negate::print_node(), and node_function::print_node().
double node::evaluate | ( | ) | const |
Evaluate a parse tree. Evaluate and tree and return the result.
Definition at line 74 of file node.cpp.
References node_impl::evaluate(), and pimpl_.
Referenced by BOOST_AUTO_TEST_CASE(), node_binary::evaluate_left(), node_function_call::evaluate_node(), node_function::evaluate_node(), node_identifier::evaluate_node(), node_unary::evaluate_operand(), node_binary::evaluate_right(), and parser::get_statement().
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 80 of file node.cpp.
References pimpl_, and node_impl::to_string().
Referenced by BOOST_AUTO_TEST_CASE().
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 86 of file node.cpp.
References node_impl::get_parameters(), and pimpl_.
Referenced by node_function_call::evaluate_node(), and get_variable().
00088 { 00089 return pimpl_->get_parameters(); 00090 }
Factory function to make the binary operator nodes.
Definition at line 6 of file node.cpp.
00007 { 00008 if (op == '+') 00009 return new node_add(left, right); 00010 else if (op == '-') 00011 return new node_subtract(left, right); 00012 else if (op == '*') 00013 return new node_multiply(left, right); 00014 else if (op == '/') 00015 return new node_divide(left, right); 00016 else 00017 throw std::logic_error("fatal error in make_binary_opreator: unknown operator: " + op); 00018 }
node_impl* node::pimpl_ [private] |
Definition at line 99 of file node.hpp.
Referenced by evaluate(), get_parameters(), node(), operator=(), print(), to_string(), and ~node().