#ifndef __NASAL_IMPORT_H__ #define __NASAL_IMPORT_H__ class nasal_import { private: nasal_lexer import_lex; nasal_parse import_par; nasal_ast import_ast; std::vector filename_table; int error; void die(std::string,std::string); bool check_import(nasal_ast&); bool check_exist(std::string); void linker(nasal_ast&,nasal_ast&); nasal_ast file_import(nasal_ast&); nasal_ast load(nasal_ast&); public: int get_error(); void link(nasal_ast&); nasal_ast& get_root(); }; void nasal_import::die(std::string filename,std::string error_stage) { ++error; std::cout<<">> [import] in <\""<: error(s) occurred in "<& ref_vec=node.get_children(); if(ref_vec.size()!=2) return false; if(ref_vec[0].get_str()!="import") return false; if(ref_vec[1].get_type()!=ast_callf) return false; if(ref_vec[1].get_children().size()!=1 || ref_vec[1].get_children()[0].get_type()!=ast_str) return false; return true; } bool nasal_import::check_exist(std::string filename) { // avoid importing the same file int size=filename_table.size(); for(int i=0;i& ref_vec=add_root.get_children(); int size=ref_vec.size(); for(int i=0;idie(filename,"lexer"); return tmp; } import_par.set_toklist(import_lex.get_token_list()); import_par.main_process(); if(import_par.get_error()) { this->die(filename,"parser"); return tmp; } tmp=import_par.get_root(); // check if tmp has 'import' return load(tmp); } nasal_ast nasal_import::load(nasal_ast& root) { nasal_ast new_root(0,ast_root); std::vector& ref_vec=root.get_children(); int size=ref_vec.size(); for(int i=0;i