aboutsummaryrefslogtreecommitdiff
path: root/include/cps/Operator.h
blob: acf5483bd2c7041534e4f2a0cb4eea0928784eb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#pragma once
#include "cps/Lexer.h"
#include <string>

namespace cps {

inline std::string operatorSpelling(int Op) {
    switch (Op) {
    case '+': case '-': case '*': case '/': case '&': case '<': case '>':
        return std::string(1, static_cast<char>(Op));
    case tok_assign: return "<-";
    case tok_div: return "DIV";
    case tok_mod: return "MOD";
    case tok_eq: return "=";
    case tok_ne: return "<>";
    case tok_le: return "<=";
    case tok_ge: return ">=";
    case tok_and: return "AND";
    case tok_or: return "OR";
    case tok_not: return "NOT";
    default: return {};
    }
}

inline std::string operatorName(int Op) {
    return "OPERATOR " + operatorSpelling(Op);
}

} // namespace cps