6 const char* operator_characters =
"=|^&!<>+-*/%.:~?";
14 OperatorPrecedence precedence;
15 OperatorLocation location;
22 { OT_ASSIGN,
"=", 2, 1, OP_RIGHT, OL_PREFIX },
23 { OT_ASSIGN_REF,
"=&", 2, 1, OP_RIGHT, OL_PREFIX },
24 { OT_ASSIGN_ADD,
"+=", 2, 1, OP_RIGHT, OL_PREFIX },
25 { OT_ASSIGN_SUB,
"-=", 2, 1, OP_RIGHT, OL_PREFIX },
26 { OT_ASSIGN_MUL,
"*=", 2, 1, OP_RIGHT, OL_PREFIX },
27 { OT_ASSIGN_DIV,
"/=", 2, 1, OP_RIGHT, OL_PREFIX },
28 { OT_ASSIGN_AND,
"&=", 2, 1, OP_RIGHT, OL_PREFIX },
29 { OT_ASSIGN_OR,
"|=", 2, 1, OP_RIGHT, OL_PREFIX },
30 { OT_ASSIGN_XOR,
"^=", 2, 1, OP_RIGHT, OL_PREFIX },
31 { OT_ASSIGN_LSH,
"<<=",2, 1, OP_RIGHT, OL_PREFIX },
32 { OT_ASSIGN_RSH,
">>=",2, 1, OP_RIGHT, OL_PREFIX },
34 { OT_LOG_OR,
"||", 2, 2, OP_LEFT, OL_PREFIX },
36 { OT_LOG_AND,
"&&", 2, 3, OP_LEFT, OL_PREFIX },
38 { OT_OR,
"|", 2, 4, OP_LEFT, OL_PREFIX },
40 { OT_XOR,
"^", 2, 5, OP_LEFT, OL_PREFIX },
42 { OT_AND,
"&", 2, 6, OP_LEFT, OL_PREFIX },
44 { OT_EQUAL,
"==", 2, 7, OP_LEFT, OL_PREFIX },
45 { OT_UNEQUAL,
"!=", 2, 7, OP_LEFT, OL_PREFIX },
46 { OT_EQUAL_TYPE,
"~~", 2, 7, OP_LEFT, OL_PREFIX },
47 { OT_UNEQUAL_TYPE,
"!~", 2, 7, OP_LEFT, OL_PREFIX },
49 { OT_LESS,
"<", 2, 8, OP_LEFT, OL_PREFIX },
50 { OT_GREATER,
">", 2, 8, OP_LEFT, OL_PREFIX },
51 { OT_LESS_OR_EQUAL,
"<=", 2, 8, OP_LEFT, OL_PREFIX },
52 { OT_GREATER_OR_EQUAL,
">=", 2, 8, OP_LEFT, OL_PREFIX },
54 { OT_LSH,
"<<", 2, 9, OP_LEFT, OL_PREFIX },
55 { OT_RSH,
">>", 2, 9, OP_LEFT, OL_PREFIX },
57 { OT_ADD,
"+", 2,10, OP_LEFT, OL_PREFIX },
58 { OT_SUB,
"-", 2,10, OP_LEFT, OL_PREFIX },
60 { OT_MUL,
"*", 2,11, OP_LEFT, OL_PREFIX },
61 { OT_DIV,
"/", 2,11, OP_LEFT, OL_PREFIX },
62 { OT_MOD,
"%", 2,11, OP_LEFT, OL_PREFIX },
64 { OT_NOT,
"!", 1,12, OP_RIGHT, OL_PREFIX },
65 { OT_EXISTS,
"?", 1,12, OP_RIGHT, OL_PREFIX },
66 { OT_INC,
"++", 1,12, OP_RIGHT, OL_PREFIX },
67 { OT_DEC,
"--", 1,12, OP_RIGHT, OL_PREFIX },
68 { OT_NEGATE,
"-", 1,12, OP_RIGHT, OL_PREFIX },
69 { OT_COMPL,
"~", 1,12, OP_RIGHT, OL_PREFIX },
71 { OT_DOT,
".", 2,13, OP_LEFT, OL_PREFIX },
73 { OT_MAP_UP,
":>", 1,14, OP_LEFT, OL_PREFIX },
74 { OT_MAP_DOWN,
"<:", 1,14, OP_LEFT, OL_PREFIX },
75 { OT_BINARY_MAP,
"::", 2,14, OP_LEFT, OL_PREFIX },
76 { OT_UNARY_MAP,
"::", 1,14, OP_LEFT, OL_PREFIX },
83 OperatorPrecedence get_operator_precedence(OperatorType ot)
85 return get_operator_info(ot).precedence;
88 const char* get_operator_word(OperatorType ot)
90 return get_operator_info(ot).word;
93 int get_operator_priority(OperatorType ot)
95 return get_operator_info(ot).priority;
98 int get_operator_arity(OperatorType ot)
100 return get_operator_info(ot).arity;
102 OperatorLocation get_operator_location(OperatorType ot)
104 return get_operator_info(ot).location;
106 bool get_operator_at_begin(OperatorType ot)
108 return get_operator_info(ot).arity == 1 && get_operator_location(ot) == OL_PREFIX;
113 OperatorType get_operator_type(
const std::string& s)
115 for (OperatorType ot = (OperatorType)0; ot < OT_LAST; ot = OperatorType(ot + 1))
116 if (s == get_operator_word(ot))