main.cpp has nothing important now...Originally Posted by Evil g++
Here is the scope.h
Code:#ifndef SCOPE #define SCOPE #include<vector> #include<map> #include<sstream> namespace mm { template<typename T> class scope { std::vector< std::map<std::string,T> > data; public: T* find(const std::string& s) { for(auto m=data.rbegin();m!=data.rend();m++) { auto p = m->find(s); if(p!=m->end())return &(p->second); } return nullptr; }; void new_local(const std::map<std::string,T>& sm){data.push_back(sm);}; void exit_scope(){data.pop_back();}; }; /*Converts a string to a double * If the string is an identifier.... * it fetches the value from the scope object supplied. */ double get_num(const std::string& s, const scope<std::string>& ss) { std::string numstr; std::istringstream is(s); double d; if(is>>d) return d; else { std::string* x = ss.find(s); if(x!=nullptr)numstr=*x; else throw("NAN");//change later } is.str(numstr); if(is>>d) return d; else throw("NAN");//change later } } #endif



2Likes
LinkBack URL
About LinkBacks



