2 #include <fridh/parser.hpp>
3 #include <fridh/symbol.hpp>
9 std::set
<binary_operator_type::type
> binary_right_to_left_operators
;
11 bool initialised_data
= false;
14 void initialise_data()
20 using namespace binary_operator_type
;
21 for(int i
= static_cast<int>(assignment
); i
<= static_cast<int>(exponentiation_assignment
); i
++)
22 binary_right_to_left_operators
.insert(static_cast<binary_operator_type::type
>(i
));
25 initialised_data
= true;
28 word
get_unary_operator_precedence(unary_operator_type::type input
)
30 using namespace unary_operator_type
;
44 throw ail::exception("Invalid unary operator type");
47 word
get_binary_operator_precedence(binary_operator_type::type input
)
49 using namespace binary_operator_type
;
63 //improvised, not from the C++ operators article as such
67 case less_than_or_equal
:
69 case greater_than_or_equal
:
99 case addition_assignment
:
100 case subtraction_assignment
:
101 case multiplication_assignment
:
102 case division_assignment
:
103 case modulo_assignment
:
104 case exponentiation_assignment
:
108 throw ail::exception("Invalid binary operator type");
111 bool get_parse_tree_node_precedence(parse_tree_node
& input
, word
& output
)
115 case parse_tree_node_type::call
:
116 case parse_tree_node_type::call_operator
:
120 case parse_tree_node_type::unary_operator_node
:
121 output
= get_unary_operator_precedence(input
.unary_operator_pointer
->type
);
124 case parse_tree_node_type::binary_operator_node
:
125 output
= get_binary_operator_precedence(input
.binary_operator_pointer
->type
);
135 bool is_right_to_left_operator(parse_tree_node
& input
)
139 if(input
.type
== parse_tree_node_type::unary_operator_node
)
144 input
.type
== parse_tree_node_type::binary_operator_node
&&
145 binary_right_to_left_operators
.find(input
.binary_operator_pointer
->type
) != binary_right_to_left_operators
.end()