void insert_element(string s, Cell* map_cell) { //check if there is any local symbol table if (!(AR_vector.empty())) { symbol_map curr_map = AR_vector.back(); AR_vector.pop_back(); symbol_map::iterator curr_map_it = curr_map.find(s); //check if it is defined before if (curr_map_it != curr_map.end()) { AR_vector.push_back(curr_map); throw runtime_error(s + " cannot be redefined."); } curr_map[s] = map_cell; AR_vector.push_back(curr_map); } else { SMap_it = SMap.find(s); //check if it is defined before if (SMap_it != SMap.end()) throw runtime_error(s + " cannot be redefined."); SMap.insert( pair< string, Cell*>(s,map_cell)); } }
void StdLib::Initialize(symbol_map& symbols) { { auto_ptr<Object> object(new Object()); symbols.insert(OBJECT, object); } symbol_iter object = symbols.find(OBJECT); { auto_ptr<Object> function(new Object(*object->second)); symbols.insert(FUNCTION, function); } symbol_iter function = symbols.find(FUNCTION); { auto_ptr<Object> int_(new Object(*object->second)); symbols.insert(INTEGER, int_); } //symbol_iter int_ = symbols.find(INTEGER); { auto_ptr<Object> str(new Object(*object->second)); symbols.insert(STRING, str); } //symbol_iter str = symbols.find(STRING); { auto_ptr<Object> print(new Object(*function->second)); symbols.insert("print", print); } { symbol_mod_iter print = symbols.find("print"); auto_ptr<function_vec> function(new function_vec()); Cmd c; Variable arg(".arg1"); c.exps.push_back(arg); c.cmd = "echo {}"; function->push_back(c); print->second->insertFunction(function); } }