From ef77c078195d21c1c25ae7a67ea5e05d371ef6d0 Mon Sep 17 00:00:00 2001 From: StarCells Date: Sat, 29 Aug 2026 01:20:03 +0800 Subject: [PATCH] 202608290119 --- include/r8asm/r8asm.hh | 16 +++++++++++++--- src/r8asm.cc | 14 +++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/r8asm/r8asm.hh b/include/r8asm/r8asm.hh index ddd84a6..85b5c01 100644 --- a/include/r8asm/r8asm.hh +++ b/include/r8asm/r8asm.hh @@ -2,8 +2,10 @@ #include #include +#include #include #include +#include #include #include @@ -54,7 +56,13 @@ private: const std::set raw_rot8_ins = {"stp", "btp", "ror", "flb", "biz", "rnz", "out", "inp"}; - token_stream(const std::string &filename); + token_stream(const std::string &filename) { + this->filename = filename; + std::ifstream file(filename); // TODO: when open failed + std::stringstream buf; + buf << file.rdbuf(); + lines = lex(buf.str()); + } std::vector lex(const std::string &char_stream); }; @@ -77,8 +85,10 @@ private: }; class ast { - private: + public: ast_node root = {r8asm::ast_node_t::CODEBLOCK, "", {}}; + + private: addr dataptr = 0; std::vector> scopes = {{}}; std::map macros; @@ -168,5 +178,5 @@ private: public: std::string export_rot8(); - bool import_file(std::string filename); + bool import_file(const std::string &filename); }; \ No newline at end of file diff --git a/src/r8asm.cc b/src/r8asm.cc index ffa2478..7f2f55e 100644 --- a/src/r8asm.cc +++ b/src/r8asm.cc @@ -1,5 +1,6 @@ #include "r8asm/r8asm.hh" #include +#include #include #include #include @@ -668,9 +669,9 @@ r8asm::token_stream::lex(const std::string &char_stream) { } else token_buffer.push_back({r8asm::token_t::RQUOTE, token_val}); } else if (token_val[0] == '(') - token_buffer.push_back({r8asm::token_t::LPAREN,token_val}); + token_buffer.push_back({r8asm::token_t::LPAREN, token_val}); else if (token_val[0] == ')') - token_buffer.push_back({r8asm::token_t::RPAREN,token_val}); + token_buffer.push_back({r8asm::token_t::RPAREN, token_val}); else if (std::string(OPERATORS).find(token_val[0]) != std::string::npos) // operator token_buffer.push_back( @@ -688,4 +689,11 @@ r8asm::token_stream::lex(const std::string &char_stream) { } return to_return; } -#undef OPERATORS \ No newline at end of file +#undef OPERATORS + +bool r8asm::import_file(const std::string &filename) { + for (const auto &token_it : parse(token_stream(filename)).children) { + main_tree.root.children.push_back(token_it); + } + return true; // TODO: ERROR CHECK +} \ No newline at end of file