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