ids.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. assign = 0x80000
  18. };
  19. };
  20. struct op
  21. {
  22. enum type
  23. {
  24. // binary
  25. comma,
  26. assign,
  27. plus_assign,
  28. minus_assign,
  29. times_assign,
  30. divide_assign,
  31. mod_assign,
  32. bit_and_assign,
  33. bit_xor_assign,
  34. bit_or_assign,
  35. shift_left_assign,
  36. shift_right_assign,
  37. logical_or,
  38. logical_and,
  39. bit_or,
  40. bit_xor,
  41. bit_and,
  42. equal,
  43. not_equal,
  44. less,
  45. less_equal,
  46. greater,
  47. greater_equal,
  48. shift_left,
  49. shift_right,
  50. plus,
  51. minus,
  52. times,
  53. divide,
  54. mod,
  55. // unary
  56. plus_plus,
  57. minus_minus,
  58. compl_,
  59. not_,
  60. };
  61. };
  62. template <int type, int op>
  63. struct make_op
  64. {
  65. static int const value = type + op;
  66. };
  67. template <op::type op>
  68. struct unary_op : make_op<op_type::unary, op> {};
  69. template <op::type op>
  70. struct binary_op
  71. : make_op<op_type::binary, op> {};
  72. template <op::type op>
  73. struct assign_op
  74. : make_op<op_type::assign, op> {};
  75. template <op::type op>
  76. struct binary_or_unary_op
  77. : make_op<op_type::unary | op_type::binary, op> {};
  78. struct token_ids
  79. {
  80. enum type
  81. {
  82. // pseudo tags
  83. invalid = -1,
  84. op_binary = op_type::binary,
  85. op_unary = op_type::unary,
  86. op_assign = op_type::assign,
  87. // binary / unary operators with common tokens
  88. // '+' and '-' can be binary or unary
  89. // (the lexer cannot distinguish which)
  90. plus = binary_or_unary_op<op::plus>::value,
  91. minus = binary_or_unary_op<op::minus>::value,
  92. // binary operators
  93. comma = binary_op<op::comma>::value,
  94. assign = assign_op<op::assign>::value,
  95. plus_assign = assign_op<op::plus_assign>::value,
  96. minus_assign = assign_op<op::minus_assign>::value,
  97. times_assign = assign_op<op::times_assign>::value,
  98. divide_assign = assign_op<op::divide_assign>::value,
  99. mod_assign = assign_op<op::mod_assign>::value,
  100. bit_and_assign = assign_op<op::bit_and_assign>::value,
  101. bit_xor_assign = assign_op<op::bit_xor_assign>::value,
  102. bit_or_assign = assign_op<op::bit_or_assign>::value,
  103. shift_left_assign = assign_op<op::shift_left_assign>::value,
  104. shift_right_assign = assign_op<op::shift_right_assign>::value,
  105. logical_or = binary_op<op::logical_or>::value,
  106. logical_and = binary_op<op::logical_and>::value,
  107. bit_or = binary_op<op::bit_or>::value,
  108. bit_xor = binary_op<op::bit_xor>::value,
  109. bit_and = binary_op<op::bit_and>::value,
  110. equal = binary_op<op::equal>::value,
  111. not_equal = binary_op<op::not_equal>::value,
  112. less = binary_op<op::less>::value,
  113. less_equal = binary_op<op::less_equal>::value,
  114. greater = binary_op<op::greater>::value,
  115. greater_equal = binary_op<op::greater_equal>::value,
  116. shift_left = binary_op<op::shift_left>::value,
  117. shift_right = binary_op<op::shift_right>::value,
  118. times = binary_op<op::times>::value,
  119. divide = binary_op<op::divide>::value,
  120. mod = binary_op<op::mod>::value,
  121. // unary operators with overlaps
  122. // '++' and '--' can be prefix or postfix
  123. // (the lexer cannot distinguish which)
  124. plus_plus = unary_op<op::plus_plus>::value,
  125. minus_minus = unary_op<op::minus_minus>::value,
  126. // unary operators
  127. compl_ = unary_op<op::compl_>::value,
  128. not_ = unary_op<op::not_>::value,
  129. // misc tags
  130. identifier = op::not_ + 1,
  131. comment,
  132. whitespace,
  133. lit_uint,
  134. true_or_false
  135. };
  136. };
  137. }
  138. #endif