45 std::ostringstream stream{};
65 stream << std::setw(indent) <<
"" <<
"void\n";
94 stream << std::setw(indent) <<
"" <<
value() <<
'\n';
116 stream << std::setw(indent) <<
"" <<
"identifier:" <<
name() <<
'\n';
133 :
node_impl{}, parameters_{std::move(parameters)}, definition_{definition}
151 char const* sep =
"";
152 for (
auto const&
id : identifiers) {
162 stream << std::setw(indent) <<
"" <<
"fun\n";
182 :
node_impl{}, name_{std::move(name)}, arguments_{std::move(arguments)}
200 stream << std::setw(indent) <<
"" <<
name() <<
"(\n";
201 std::size_t index{0};
203 stream << std::setw(indent+1) <<
"" <<
"arg " << index <<
": ";
204 arg.print(stream, indent + 2);
207 stream << std::setw(indent) <<
"" <<
")\n";
216 if (parameters.size() !=
arguments().size())
222 identifier_list::const_iterator parm{parameters.begin()};
224 locals.emplace(*parm, arg);
228 return function.evaluate();
251 : left_(left), right_(right)
286 stream << std::setw(indent) <<
"" <<
"-\n";
304 stream << std::setw(indent) <<
"" <<
"+\n";
323 stream << std::setw(indent) <<
"" <<
"-\n";
342 stream << std::setw(indent) <<
"" <<
"*\n";
361 stream << std::setw(indent) <<
"" <<
"/\n";
virtual double evaluate_node() const override
node_number(double value)
double evaluate_right() const
node get_function(std::string const &name)
virtual std::string evaluate_string() const override
virtual std::string evaluate_string() const
virtual void print_node(std::ostream &stream, int indent) const override
virtual double evaluate_node() const =0
virtual double evaluate_node() const override
node_list const & arguments() const
virtual void print_node(std::ostream &stream, int indent) const override
virtual void print_node(std::ostream &stream, int indent) const override
double evaluate_left() const
node_function_call(std::string name, node_list arguments)
node_binary(node left, node right)
virtual double evaluate_node() const override
virtual double evaluate_node() const override
std::string const & name() const
virtual void print_node(std::ostream &stream, int indent) const override
virtual std::string evaluate_string() const override
node_identifier(std::string name)
virtual void print_node(std::ostream &stream, int indent) const override
virtual double evaluate_node() const override
virtual double evaluate_node() const override
void print(std::ostream &stream, int indent) const
std::vector< std::string > identifier_list
A sequence of identifiers (e.g., parameter names).
virtual void print_node(std::ostream &stream, int indent) const override
node_function(identifier_list parameters, node definition)
double evaluate_operand() const
node_multiply(node left, node right)
virtual identifier_list const & evaluate_parameters() const override
virtual void print_node(std::ostream &stream, int indent) const override
void print(std::ostream &stream, int indent=0) const
void print_identifier_list(std::ostream &stream, identifier_list const &identifiers)
virtual void print_node(std::ostream &stream, int indent) const override
virtual void print_node(std::ostream &stream, int indent) const =0
identifier_list parameters_
node_subtract(node left, node right)
virtual double evaluate_node() const override
virtual void print_node(std::ostream &stream, int indent) const override
virtual identifier_list const & evaluate_parameters() const
virtual double evaluate_node() const override
identifier_list const & get_parameters() const
identifier_list const & get_parameters() const
std::vector< node > node_list
A sequence of nodes.
std::string to_string() const
node_negate(node operand)
virtual void print_node(std::ostream &stream, int indent) const override
virtual double evaluate_node() const override
node_divide(node left, node right)
node_add(node left, node right)
identifier_list const & parameters() const
node get_variable(std::string const &name)
std::map< std::string, node > symbol_table
virtual double evaluate_node() const override