#include "Variable.h"
#include <sstream>

Variable::Variable(std::string name) : m_name(name)
{
}


Variable::~Variable(void)
{
}

int Variable::interpret(std::map<std::string,Expression*> &variables)
{
    std::map<std::string,Expression*>::iterator iter = variables.find(m_name);
	if (iter == variables.end())
    {
        if (isNumeric(m_name))
        {
            std::istringstream iss(m_name);
            int value;
            iss >> value;
            return value;
        }
        return 0;
    }
    else
        return iter->second->interpret(variables); 
}

bool Variable::isNumeric(std::string name)
{
    unsigned int i;
    for (i=0; i<name.length(); i++)
        if ((name[i]<'0')||(name[i]>'9'))
            return false;
    return true;
}
