From fd128c3758482d03bd6c76649c8a3708ff4ca4aa Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Mon, 12 Oct 2020 09:00:36 -0700 Subject: [PATCH] update --- version3.0/main.cpp | 60 +++++++++++- version3.0/nasal_codegen.h | 184 ++++++++++++++++++++----------------- version3.0/nasal_enum.h | 1 + 3 files changed, 158 insertions(+), 87 deletions(-) diff --git a/version3.0/main.cpp b/version3.0/main.cpp index 52eabba..e08d29c 100644 --- a/version3.0/main.cpp +++ b/version3.0/main.cpp @@ -13,12 +13,13 @@ void help() { std::cout<<">> [\"file\"] input a file."<> [clear ] clear the screen."<> [del ] clear the source code."<> [del ] clear the input filename."<> [rs ] print source code."<> [lex ] use lexer to turn code into tokens."<> [ast ] do parsing and check the abstract syntax tree."<> [run ] run code."<> [run ] run abstract syntax tree."<> [exec ] generate byte code."<> [erun ] run byte code."<> [logo ] print logo of nasal ."<> [exit ] quit nasal interpreter."<> [file] cannot open file \""< 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&); + void output_root(nasal_ast&,std::ofstream&); + unsigned int input_int(std::ifstream&); + void input_root(nasal_ast&,std::ifstream&); public: nasal_codegen(); - void main_progress(std::string,nasal_ast&); -}; - -class nasal_bytecode_runtime -{ -private: -public: + int get_error(); + void output_exec(std::string,nasal_ast&); + void load_exec(std::string,nasal_ast&); }; nasal_codegen::nasal_codegen() @@ -46,11 +32,9 @@ nasal_codegen::nasal_codegen() return; } -void nasal_codegen::die(std::string info) +int nasal_codegen::get_error() { - ++error; - std::cout<<">> [code] "<& 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()) { + ++error; std::cout<<">> [code] cannot generate file \""<> [code] file format error: without ast_begin."<> [code] file format error: without ast_end."<> [code] cannot open file\""<> [code] \""<