202608290036

This commit is contained in:
starcells committed 2026-08-29 00:36:39 +08:00
1 parent ff470cf677
commit fa6566b0e8
1 file changed
+17 -15
+17 -15
View File
@@ -624,15 +624,16 @@ r8asm::token_stream::lex(const std::string &char_stream) {
const std::map<std::string, std::string> 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> token_buffer = {};
bool start_of_line = true;
bool lquote_appeared = false;
std::string token_val;
do {
for (std::string token_val = r8asm_strtools::peel(str_buffer);
token_val != ""; token_val = r8asm_strtools::peel(str_buffer)) {
token_val = r8asm_strtools::peel(str_buffer);
if (lquote_appeared && token_val[0] != '\"')
token_buffer.push_back({r8asm::token_t::STRING, token_val});
@@ -641,11 +642,11 @@ r8asm::token_stream::lex(const std::string &char_stream) {
start_of_line = false;
if (token_val[0] == '.') // builtin
token_buffer.push_back(
{r8asm::token_t::BUILTIN, "builtin_" + token_val.substr(0, 1)});
{r8asm::token_t::BUILTIN, "builtin_" + token_val.substr(1)});
// e.g. .var -> builtin_var
else if (token_val[0] == '%') // directive
token_buffer.push_back(
{r8asm::token_t::DIRECTIVE, token_val.substr(0, 1)});
{r8asm::token_t::DIRECTIVE, token_val.substr(1)});
// e.g. %macro -> macro
else if (token_val[0] == ';') // remark
next_will_be_remark = true;
@@ -658,18 +659,19 @@ 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.substr(0,1)});
token_buffer.push_back(
{r8asm::token_t::PARAMETER, token_val.substr(1)});
else if (token_val[0] == '"') { // quote(filename)
if (!lquote_appeared) {
lquote_appeared = true; // only %include will use quotes, they
// won't appear again
token_buffer.push_back({r8asm::token_t::LQUOTE});
token_buffer.push_back({r8asm::token_t::LQUOTE, token_val});
} else
token_buffer.push_back({r8asm::token_t::RQUOTE});
token_buffer.push_back({r8asm::token_t::RQUOTE, token_val});
} else if (token_val[0] == '(')
token_buffer.push_back({r8asm::token_t::LPAREN});
token_buffer.push_back({r8asm::token_t::LPAREN,token_val});
else if (token_val[0] == ')')
token_buffer.push_back({r8asm::token_t::RPAREN});
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(
@@ -679,11 +681,11 @@ r8asm::token_stream::lex(const std::string &char_stream) {
}
}
}
num++;
if (!token_buffer.empty())
to_return.push_back({num, token_buffer});
next_will_be_remark = false;
} while (token_val != "");
}
num++;
if (!token_buffer.empty())
to_return.push_back({num, token_buffer});
next_will_be_remark = false;
}
return to_return;
}