From c7bf5df4b1faf8493bb431bbe23e9f182153ddbb Mon Sep 17 00:00:00 2001 From: _ov4 Date: Wed, 9 Sep 2026 09:05:21 +0000 Subject: symbol enum converter --- include/lexer/ast.h | 20 +++++--------------- include/lexer/symbol_property.h | 17 +++++++++++++++++ module-test/lexer_test.cc | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/lexer/ast.h b/include/lexer/ast.h index 59c1e4b..ea26d5d 100644 --- a/include/lexer/ast.h +++ b/include/lexer/ast.h @@ -45,23 +45,13 @@ size_t alloc_ast() int get_pivot_order(enum_token_type x) { - switch(x) + string s = symbol_enum2string(x); + if (s != "") { - case ASYNC: - case SEMICOLON: - return 1000; - - case LOGIC_AND: - case LOGIC_OR: - return 500; - - case PIPE: - return 100; - - default: - return 0; + return symbol_property[s].pivot_priority; } - return 0; + // not found + return -1; } bool is_operator(enum_token_type x) diff --git a/include/lexer/symbol_property.h b/include/lexer/symbol_property.h index 2e94cf7..caff263 100644 --- a/include/lexer/symbol_property.h +++ b/include/lexer/symbol_property.h @@ -40,5 +40,22 @@ unordered_map symbol_property = { {"||", {.operand_number = 1, .continuable = true, .pivot_priority = 1000, .left = EXIST, .right = EXIST, .enum_type = LOGIC_OR}}, }; + +string symbol_enum2string(enum_token_type e) +{ + for (auto &c : symbol_property) + { + // pair + + if (c.second.enum_type == e) + return c.first; + } + return ""; +} + +bool symbol_contains_enum_type(enum_token_type e) +{ + return (symbol_enum2string(e) == "") ? false : true; +} } diff --git a/module-test/lexer_test.cc b/module-test/lexer_test.cc index 036386e..def2f57 100644 --- a/module-test/lexer_test.cc +++ b/module-test/lexer_test.cc @@ -26,7 +26,7 @@ constexpr int MAXLINE = 1024; int main() { - int test_case = 10; + int test_case = 0; string s; switch (test_case) -- cgit v1.3.1-4-g156e