ast.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2021 Nikita Kaskov <nbering@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_MATH_EXPRESSION_AST_HPP
27 #define CRYPTO3_MATH_EXPRESSION_AST_HPP
28 
29 #ifndef CRYPTO3_MATH_EXPRESSION_HPP
30 #error "ast.hpp must not be included directly!"
31 #endif
32 
33 #include <boost/spirit/home/x3.hpp>
34 #include <boost/spirit/home/x3/support/ast/variant.hpp>
35 
36 #include <list>
37 #include <string>
38 
39 namespace nil {
40  namespace crypto3 {
41  namespace math {
42  namespace expressions {
43  namespace detail {
44 
45  namespace x3 = boost::spirit::x3;
46 
47  namespace ast {
48 
49  struct nil {};
50  struct unary_op;
51  struct binary_op;
52  struct expression;
53 
54  // clang-format off
55  struct operand : x3::variant<
56  nil
57  , double
58  , std::string
59  , x3::forward_ast<unary_op>
60  , x3::forward_ast<binary_op>
61  , x3::forward_ast<expression>
62  > {
63  using base_type::base_type;
64  using base_type::operator=;
65  };
66  // clang-format on
67 
68  struct unary_op {
69  double (*op)(double);
71  };
72 
73  struct binary_op {
74  double (*op)(double, double);
77  };
78 
79  struct operation {
80  double (*op)(double, double);
82  };
83 
84  struct expression {
86  std::list<operation> rhs;
87  };
88 
89  } // namespace ast
90  } // namespace detail
91  } // namespace expressions
92  } // namespace math
93  } // namespace crypto3
94 } // namespace nil
95 
96 #endif // CRYPTO3_MATH_EXPRESSION_AST_HPP
Definition: pair.hpp:31
double(* op)(double, double)
Definition: ast.hpp:74
std::list< operation > rhs
Definition: ast.hpp:86
double(* op)(double, double)
Definition: ast.hpp:80
double(* op)(double)
Definition: ast.hpp:69