202608290026

This commit is contained in:
starcells committed 2026-08-29 00:26:35 +08:00
1 parent 5aa4893dc6
commit ff470cf677
1 file changed
+15 -12
+15 -12
View File
@@ -9,7 +9,7 @@
#include <vector>
#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_line>
r8asm::token_stream::lex(const std::string &char_stream) {
std::vector<token_line> to_return;
@@ -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;
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