From ff470cf67764755bd51a38d3ed7280c51cae18c1 Mon Sep 17 00:00:00 2001 From: StarCells Date: Sat, 29 Aug 2026 00:26:35 +0800 Subject: [PATCH] 202608290026 --- src/r8asm.cc | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/r8asm.cc b/src/r8asm.cc index ca9b5cc..aaafe07 100644 --- a/src/r8asm.cc +++ b/src/r8asm.cc @@ -9,7 +9,7 @@ #include #define EMPTY_CHARS (" \t\n\r\f\v") -#define OPERATORS ("+-*/^~\"()") +#define OPERATORS ("+-*/^~\"()&|") namespace r8asm_strtools { bool is_integer(const std::string &str) { @@ -611,7 +611,7 @@ r8asm::ast_node r8asm::parse_single_arg(const token_line &line) { #undef EMPTY_CODEBLOCK -#define OPERATORS ("+-*/^~") +#define OPERATORS ("+-*/^~&|") std::vector r8asm::token_stream::lex(const std::string &char_stream) { std::vector to_return; @@ -624,15 +624,16 @@ r8asm::token_stream::lex(const std::string &char_stream) { const std::map operator_map = { // without "-" {"+", "op_add"}, {"*", "op_mul"}, {"/", "op_div"}, {"^", "op_xor"}, - {"&", "op_and"}, {"|", "op_or"}, {"~", "op_not"}, {"-", "op_sub"}}; + {"&", "op_and"}, {"|", "op_or"}, {"~", "op_not"}, {"-", "op_sub"},}; while (std::getline(iss, str_buffer)) { std::vector token_buffer = {}; bool start_of_line = true; bool lquote_appeared = false; - for (std::string token_val = r8asm_strtools::peel(str_buffer); - token_val != "";) { + std::string token_val; + do { + token_val = r8asm_strtools::peel(str_buffer); if (lquote_appeared && token_val[0] != '\"') token_buffer.push_back({r8asm::token_t::STRING, token_val}); else { @@ -657,7 +658,7 @@ r8asm::token_stream::lex(const std::string &char_stream) { if (token_val[0] == ';') // remark next_will_be_remark = true; else if (token_val[0] == '%') // parameter - token_buffer.push_back({r8asm::token_t::PARAMETER, token_val}); + token_buffer.push_back({r8asm::token_t::PARAMETER, token_val.substr(0,1)}); else if (token_val[0] == '"') { // quote(filename) if (!lquote_appeared) { lquote_appeared = true; // only %include will use quotes, they @@ -671,17 +672,19 @@ r8asm::token_stream::lex(const std::string &char_stream) { token_buffer.push_back({r8asm::token_t::RPAREN}); else if (std::string(OPERATORS).find(token_val[0]) != std::string::npos) // operator - token_buffer.push_back({r8asm::token_t::OPERATOR, token_val}); + token_buffer.push_back( + {r8asm::token_t::OPERATOR, operator_map.at(token_val)}); else token_buffer.push_back({r8asm::token_t::STRING, token_val}); } } } - } - num++; - if (!token_buffer.empty()) - to_return.push_back({num, token_buffer}); - next_will_be_remark = false; + num++; + if (!token_buffer.empty()) + to_return.push_back({num, token_buffer}); + next_will_be_remark = false; + } while (token_val != ""); } return to_return; } +#undef OPERATORS \ No newline at end of file