diff --git a/version3.0/main.cpp b/version3.0/main.cpp index f324603..52eabba 100644 --- a/version3.0/main.cpp +++ b/version3.0/main.cpp @@ -4,6 +4,7 @@ nasal_resource resource; nasal_lexer lexer; nasal_parse parse; nasal_import preprocessor; +nasal_codegen code_generator; std::string command; std::string inputfile="null"; nasal_runtime runtime; @@ -17,6 +18,7 @@ void help() std::cout<<">> [lex ] use lexer to turn code into tokens."<> [ast ] do parsing and check the abstract syntax tree."<> [run ] run code."<> [exec ] generate byte code."<> [logo ] print logo of nasal ."<> [exit ] quit nasal interpreter."< number_list; + std::vector string_list; + std::vector symbol_list; + int error; + void die(std::string); + void init(); + void output_int(unsigned int,std::ofstream&); + void generate_root(nasal_ast&,std::ofstream&); + void generate_number_list(std::ofstream&); + void generate_string_list(std::ofstream&); + void generate_symbol_list(std::ofstream&); +public: + nasal_codegen(); + void main_progress(std::string,nasal_ast&); +}; + +class nasal_bytecode_runtime +{ +private: +public: +}; + +nasal_codegen::nasal_codegen() +{ + error=0; + number_list.clear(); + string_list.clear(); + symbol_list.clear(); + return; +} + +void nasal_codegen::die(std::string info) +{ + ++error; + std::cout<<">> [code] "<>offset); + get_byte>>=8; + offset-=8; + } + return; +} + +void nasal_codegen::generate_root(nasal_ast& root,std::ofstream& fout) +{ + std::vector& ref_vec=root.get_children(); + int root_children_size=ref_vec.size(); + for(int i=0;iinit(); + std::ofstream fout(filename,std::ios::binary); + if(fout.fail()) + { + std::cout<<">> [code] cannot generate file \""<die(filename,"resource"); return tmp; } import_lex.scanner(import_src.get_file()); if(import_lex.get_error()) { - die(filename,"lexer"); + this->die(filename,"lexer"); return tmp; } import_par.set_toklist(import_lex.get_token_list()); import_par.main_process(); if(import_par.get_error()) { - die(filename,"parser"); + this->die(filename,"parser"); return tmp; } tmp=import_par.get_root();