diff options
| author | _ov4 <ov4@ov4.org> | 2026-09-09 09:05:21 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-09-09 09:05:21 +0000 |
| commit | c7bf5df4b1faf8493bb431bbe23e9f182153ddbb (patch) | |
| tree | 0be5cff947bee957de6daa6ead9f1c115ae4f39d /include | |
| parent | 992487d4e425db4443b6f692f349e61de78ea43e (diff) | |
symbol enum converter
Diffstat (limited to 'include')
| -rw-r--r-- | include/lexer/ast.h | 20 | ||||
| -rw-r--r-- | include/lexer/symbol_property.h | 17 |
2 files changed, 22 insertions, 15 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<string, T_property> 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<string, T_property> + + 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; +} } |
