ids.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #if !defined(BOOST_SPIRIT_CONJURE_IDS_HPP)
  8. #define BOOST_SPIRIT_CONJURE_IDS_HPP
  9. namespace client
  10. {
  11. struct op_type
  12. {
  13. enum type
  14. {
  15. binary = 0x20000,
  16. unary = 0x40000,
  17. postfix_unary = 0x80000,
  18. assign = 0x100000
  19. };
  20. };
  21. struct op
  22. {
  23. enum type
  24. {
  25. // binary
  26. comma,
  27. assign,
  28. plus_assign,
  29. minus_assign,
  30. times_assign,
  31. divide_assign,
  32. mod_assign,
  33. bit_and_assign,
  34. bit_xor_assign,
  35. bit_or_assign,
  36. shift_left_assign,
  37. shift_right_assign,
  38. logical_or,
  39. logical_and,
  40. bit_or,
  41. bit_xor,
  42. bit_and,
  43. equal,
  44. not_equal,
  45. less,
  46. less_equal,
  47. greater,
  48. greater_equal,
  49. shift_left,
  50. shift_right,
  51. plus,
  52. minus,
  53. times,
  54. divide,
  55. mod,
  56. // unary
  57. plus_plus,
  58. minus_minus,
  59. compl_,
  60. not_,
  61. };
  62. };
  63. template <int type, int op>
  64. struct make_op
  65. {
  66. static int const value = type + op;
  67. };
  68. template <op::type op>
  69. struct unary_op : make_op<op_type::unary, op> {};
  70. template <op::type op>
  71. struct binary_op
  72. : make_op<op_type::binary, op> {};
  73. template <op::type op>
  74. struct assign_op
  75. : make_op<op_type::assign, op> {};
  76. template <op::type op>
  77. struct binary_or_unary_op
  78. : make_op<op_type::unary | op_type::binary, op> {};
  79. struct token_ids
  80. {
  81. enum type
  82. {
  83. // pseudo tags
  84. invalid = -1,
  85. op_binary = op_type::binary,
  86. op_unary = op_type::unary,
  87. op_assign = op_type::assign,
  88. // binary / unary operators with common tokens
  89. // '+' and '-' can be binary or unary
  90. // (the lexer cannot distinguish which)
  91. plus = binary_or_unary_op<op::plus>::value,
  92. minus = binary_or_unary_op<op::minus>::value,
  93. // binary operators
  94. comma = binary_op<op::comma>::value,
  95. assign = assign_op<op::assign>::value,
  96. plus_assign = assign_op<op::plus_assign>::value,
  97. minus_assign = assign_op<op::minus_assign>::value,
  98. times_assign = assign_op<op::times_assign>::value,
  99. divide_assign = assign_op<op::divide_assign>::value,
  100. mod_assign = assign_op<op::mod_assign>::value,
  101. bit_and_assign = assign_op<op::bit_and_assign>::value,
  102. bit_xor_assign = assign_op<op::bit_xor_assign>::value,
  103. bit_or_assign = assign_op<op::bit_or_assign>::value,
  104. shift_left_assign = assign_op<op::shift_left_assign>::value,
  105. shift_right_assign = assign_op<op::shift_right_assign>::value,
  106. logical_or = binary_op<op::logical_or>::value,
  107. logical_and = binary_op<op::logical_and>::value,
  108. bit_or = binary_op<op::bit_or>::value,
  109. bit_xor = binary_op<op::bit_xor>::value,
  110. bit_and = binary_op<op::bit_and>::value,
  111. equal = binary_op<op::equal>::value,
  112. not_equal = binary_op<op::not_equal>::value,
  113. less = binary_op<op::less>::value,
  114. less_equal = binary_op<op::less_equal>::value,
  115. greater = binary_op<op::greater>::value,
  116. greater_equal = binary_op<op::greater_equal>::value,
  117. shift_left = binary_op<op::shift_left>::value,
  118. shift_right = binary_op<op::shift_right>::value,
  119. times = binary_op<op::times>::value,
  120. divide = binary_op<op::divide>::value,
  121. mod = binary_op<op::mod>::value,
  122. // unary operators with overlaps
  123. // '++' and '--' can be prefix or postfix
  124. // (the lexer cannot distinguish which)
  125. plus_plus = make_op<
  126. op_type::unary
  127. | op_type::postfix_unary, op::plus_plus>::value,
  128. minus_minus = make_op<
  129. op_type::unary
  130. | op_type::postfix_unary, op::minus_minus>::value,
  131. // unary operators
  132. compl_ = unary_op<op::compl_>::value,
  133. not_ = unary_op<op::not_>::value,
  134. // misc tags
  135. identifier = op::not_ + 1,
  136. comment,
  137. whitespace,
  138. lit_uint,
  139. true_or_false
  140. };
  141. };
  142. }
  143. #endif