Implemented the nullary/unary call operators
[fridhskrift.git] / lexer / operator.cpp
blob82b433c7b6e3980a70ef4420a2a23b3fe45b929e
1 #include <fridh/lexer.hpp>
2 #include <algorithm>
3 #include <ail/string.hpp>
4 #include <ail/array.hpp>
6 namespace fridh
8 bool tables_initialised = false;
10 operator_lexeme operators[] =
12 operator_lexeme(addition, "+"),
13 operator_lexeme(subtraction, "-"),
14 operator_lexeme(multiplication, "*"),
15 operator_lexeme(division, "/"),
16 operator_lexeme(modulo, "%"),
17 operator_lexeme(exponentiation, "**"),
19 operator_lexeme(assignment, "="),
20 operator_lexeme(addition_assignment, "+="),
21 operator_lexeme(subtraction_assignment, "-="),
22 operator_lexeme(multiplication_assignment, "*="),
23 operator_lexeme(division_assignment, "/="),
24 operator_lexeme(modulo_assignment, "%="),
25 operator_lexeme(exponentiation_assignment, "**="),
27 operator_lexeme(increment, "++"),
28 operator_lexeme(decrement, "--"),
30 operator_lexeme(less_than, "<"),
31 operator_lexeme(less_than_or_equal, "<="),
32 operator_lexeme(greater_than, ">"),
33 operator_lexeme(greater_than_or_equal, ">="),
34 operator_lexeme(unequal, "!="),
35 operator_lexeme(equal, "=="),
37 operator_lexeme(logical_not, "!"),
39 operator_lexeme(logical_and, "&"),
40 operator_lexeme(logical_or, "|"),
42 operator_lexeme(shift_left, "<<"),
43 operator_lexeme(shift_right, ">>"),
45 operator_lexeme(binary_and, "&&"),
46 operator_lexeme(binary_or, "||"),
47 operator_lexeme(binary_xor, "^"),
49 operator_lexeme(binary_not, "~"),
51 operator_lexeme(bracket_start, "["),
52 operator_lexeme(bracket_end, "]"),
54 operator_lexeme(array_start, "{"),
55 operator_lexeme(array_end, "}"),
57 operator_lexeme(scope_start, "("),
58 operator_lexeme(scope_end, ")"),
60 operator_lexeme(iteration, "\\"),
61 operator_lexeme(iterator, "#"),
62 operator_lexeme(function_declaration, "@"),
63 operator_lexeme(anonymous_function_declaration, "@@"),
64 operator_lexeme(class_operator, "$"),
65 operator_lexeme(selection_operator, "."),
66 operator_lexeme(scope_operator, ":"),
68 operator_lexeme(call_operator, ","),
69 operator_lexeme(spaced_call_operator, ", "),
72 std::vector<operator_lexeme> operator_lexeme_data;
74 void initialise_tables()
76 boost::mutex::scoped_lock scoped_lock(table_mutex);
78 if(tables_initialised)
79 return;
81 tables_initialised = true;
83 std::sort(operators, operators + ail::countof(operators));
85 for(std::size_t i = 0; i < ail::countof(operators); i++)
86 operator_lexeme_data.push_back(operators[i]);