#include <sstream>
#include "exception.h"
-Exception::Exception(const Token& tok) throw() : std::exception(), ex_line(tok.line()), ex_column(tok.column())
+Exception::Exception() throw() : std::exception()
{
}
-Exception::Exception(int line, int column) throw() : std::exception(), ex_line(line), ex_column(column)
+Exception::Exception(const Token& tok) throw() : std::exception(), ex_line(tok.line()), ex_column(tok.column())
{
+ std::ostringstream oss;
+ oss << "(ln " << ex_line << ", col " << ex_column << "): ";
+ oss << ((Exception*)this)->message() << std::endl;
+ ex_msg = oss.str();
}
-const char* Exception::what() const throw()
+Exception::Exception(int line, int column) throw() : std::exception(), ex_line(line), ex_column(column)
{
std::ostringstream oss;
oss << "(ln " << ex_line << ", col " << ex_column << "): ";
oss << ((Exception*)this)->message() << std::endl;
- return oss.str().c_str();
+ ex_msg = oss.str();
+}
+
+const char* Exception::what() const throw()
+{
+ return ex_msg.c_str();
}
void Exception::message(const std::string& msg) throw()
#include "scopestack.h"
+#include <iostream>
using namespace std;
ScopeStack::ScopeStack()
{
+ // Initialize the stack
+ sym_table_t table;
+ scope_stack.push_front( table );
}
ScopeStack::~ScopeStack()
void ScopeStack::startScope()
{
- scope_stack.push_front( sym_table_t() );
+ sym_table_t table;
+ scope_stack.push_front( table );
}
void ScopeStack::stopScope()
bool ScopeStack::isLocal(const std::string& name) const
{
- return false;
+ bool ret = false;
+ sym_table_t::const_iterator p_val = scope_stack.front().find(name);
+ if( p_val != scope_stack.front().end())
+ {
+ ret = true;
+ }
+ return ret;
}
bool ScopeStack::isGlobal(const std::string& name) const
{
- return false;
+ bool ret = false;
+ list<sym_table_t>::const_iterator it;
+ for(it = ++(scope_stack.begin()); it != scope_stack.end(); it++)
+ {
+ sym_table_t::const_iterator p_val = (*it).find(name);
+ if( p_val != (*it).end())
+ {
+ ret = true;
+ break;
+ }
+ }
+ return ret;
}