variables.hpp File Reference

#include <map>
#include <string>
#include "node.hpp"

Go to the source code of this file.

Classes

class  set_symbol_table

Typedefs

typedef std::map
< std::string, node
symbol_table

Functions

node get_variable (std::string const &name)
node get_function (std::string const &name)
void set_variable (std::string const &name, node value)
void set_function (std::string const &name, node definition)


Typedef Documentation

typedef std::map<std::string, node> symbol_table

Represent a global or local symbol table, which stores variables and functions. In fact, there's no difference between a variable and a function of no arguments.

Definition at line 13 of file variables.hpp.


Function Documentation

node get_function ( std::string const &  name  ) 

Get the definition of a function.

Parameters:
name The function name
Returns:
The definition of function named name
Exceptions:
no_such_function if the function is not defined

Definition at line 61 of file variables.cpp.

References find_symbol().

00062 {
00063   node result;
00064   if (not find_symbol(name, result))
00065     throw no_such_function(name);
00066   else
00067     return result;
00068 }

node get_variable ( std::string const &  name  ) 

Get the value of a variable.

Parameters:
name The variable name
Returns:
The value of variable name or node() if the variable is undefined.

Definition at line 45 of file variables.cpp.

References find_symbol(), and node::get_parameters().

00046 {
00047   node result;
00048   if (not find_symbol(name, result))
00049     return node();
00050   else if (result.get_parameters().empty())
00051     return result;
00052   else
00053     throw function_error(name, result.get_parameters().size(), 0);
00054 }

void set_function ( std::string const &  name,
node  definition 
)

Set the definition of a function.

Parameters:
name The function name
definition The function definition

Definition at line 70 of file variables.cpp.

References set_variable().

00071 {
00072   set_variable(name, value);
00073 }

void set_variable ( std::string const &  name,
node  value 
)

Set the value of a variable.

Parameters:
name The variable name
value The value. if the variable is already defined, changes its value.

Definition at line 56 of file variables.cpp.

References variables.

00057 {
00058   variables[name] = value;
00059 }


Generated on Sun Nov 30 10:05:27 2008 for Calculator by  doxygen 1.5.3