13 std::vector<symbol_table const*> symbol_tables;
18 variables[
"pi"] =
node(3.141592653589792);
19 variables[
"e"] =
node(2.718281828459);
20 symbol_tables.push_back(&variables);
28 symbol_tables.push_back(&locals);
33 symbol_tables.pop_back();
38 for (
auto iter(symbol_tables.rbegin()), end(symbol_tables.rend()); iter != end; ++iter) {
40 symbol_table::const_iterator entry{ table.find(name) };
41 if (entry != table.end()) {
42 value = entry->second;
54 else if (result.get_parameters().empty())
62 variables[name] = value;
81 std::ofstream stream{filename.c_str()};
85 stream.precision(std::numeric_limits<double>::digits10);
86 stream <<
":library:\n";
87 for (
auto const& symbol : variables)
89 stream << symbol.first <<
' ';
90 symbol.second.save(stream);
102 std::ifstream stream{filename.c_str()};
106 if (not std::getline(stream, token))
108 if (token !=
":library:")
109 throw calc_error{filename +
": is not a calculator library file"};
110 while (stream >> token) {
void load_library(std::string const &filename)
node get_function(std::string const &name)
bool find_symbol(std::string const &name, node &value)
void save_library(std::string const &filename)
void set_variable(std::string const &name, node value)
void set_function(std::string const &name, node value)
set_symbol_table(symbol_table const &symtab)
node get_variable(std::string const &name)
std::map< std::string, node > symbol_table