11#include < parser/tokenizer.h>
2+ #include < types/type_mapper.h>
23#include < utility>
34#include < queue>
45#include < stdexcept>
5- const std::map<string, TokenOperator>& generate_operator_map (const vector<TokenOperator>& operators) {
6- static std::map<string, TokenOperator> out;
7- for (const TokenOperator& op : operators) {
8- out[op.str_repr ] = op;
9- }
10- return out;
11- }
12-
13- bool is_operator (const string& s) {
14- static const std::map<string, TokenOperator>& m = generate_operator_map (operators);
15- return m.contains (s);
16- }
176
187TokenOperator get_operator (const string& s) {
19- static const std::map<string, TokenOperator>& m = generate_operator_map (operators);
208 if (is_number (s)) {
21- TokenOperator val = m. at (" CONSTANT" );
9+ TokenOperator val = get_token_operator (" CONSTANT" );
2210 size_t idx;
2311 const float value = std::stof (s, &idx);
2412 if (idx != s.size ()) {
@@ -27,10 +15,7 @@ TokenOperator get_operator(const string& s) {
2715 val.value = { std::stof (s),0 .0f };
2816 return val;
2917 }
30- if (!m.contains (s)) {
31- throw std::runtime_error (" Unknown token or variable '" + s + " '" );
32- }
33- return m.at (s);
18+ return get_token_operator (s);
3419}
3520
3621string handle_multicharacter (const string& s, size_t & index, const std::function<bool (const char )>& check) {
@@ -93,9 +78,6 @@ vector<TokenOperator> tokenize(const string& s) {
9378 const char c = s[i];
9479 if (c == ' ' ) continue ;
9580 if (!is_digit (c) && !is_character (c)) {
96- if (!is_operator ({c})) {
97- throw std::runtime_error (" Unknown character: '" + string (c,0 ) + " '" );
98- }
9981 tokens.push_back (get_operator ({ c }));
10082 }
10183 if (is_digit (c)) {
0 commit comments