The Sparta Modeling Framework
Loading...
Searching...
No Matches
ExpressionGrammar.hpp
1// <ExpressionGrammar.hpp> -*- C++ -*-
2
3#define BOOST_SPIRIT_USE_PHOENIX_V3 0
4
5#pragma once
6
7#include <boost/config/warning_disable.hpp>
8#include <boost/spirit/include/qi.hpp>
9
10#include "sparta/statistics/Expression.hpp"
12
13#include <string>
14
15// Alias deep boost namespaces
16namespace qi = boost::spirit::qi;
17namespace ascii = boost::spirit::ascii;
18
19
20namespace sparta {
21 namespace statistics {
22 namespace expression {
23
27 namespace grammar {
28
29
31 public qi::grammar<std::string::const_iterator,
32 Expression(),
33 ascii::space_type>
34{
38 struct constants_
39 : qi::symbols<typename std::iterator_traits<std::string::const_iterator>::value_type,
40 Expression>
41 {
42 constants_();
43
44 }; // struct constants_
45
50 struct builtin_vars_
51 : qi::symbols<typename std::iterator_traits<std::string::const_iterator>::value_type,
52 std::function<Expression(void)>>
53 {
60 builtin_vars_(sparta::TreeNode* n,
61 std::vector<const TreeNode*>& used);
62
63 }; // struct builtin_vars_
64
68 struct variable_ : qi::grammar<std::string::const_iterator,
69 Expression(),
70 ascii::space_type>
71 {
79 variable_(sparta::TreeNode* n,
80 std::vector<const TreeNode*>& used,
81 const StatisticPairs & report_si);
82
83 qi::rule<std::string::const_iterator,
84 Expression(),
85 ascii::space_type> start;
86 qi::rule<std::string::const_iterator,
87 std::string(),
88 ascii::space_type> str;
89 }; // struct variable_
90
95 struct ufunc_
96 : qi::symbols<typename std::iterator_traits<std::string::const_iterator>::value_type,
97 std::function<Expression(Expression&)>>
98 {
102 typedef double(*fptr_dd_t)(double);
103
107 typedef bool(*fptr_bd_t)(long double);
108
112 ufunc_(std::vector<const TreeNode*>& already_used);
113
114 }; // ufunc_
115
120 struct bfunc_
121 : qi::symbols<typename std::iterator_traits<std::string::const_iterator>::value_type,
122 std::function<Expression(Expression&, Expression&)>>
123 {
127 typedef double(*fptr_ddd_t)(double, double);
128
133 typedef const double&(*fptr_drdrdrt)(const double&, const double&);
134
138 bfunc_(const std::vector<const TreeNode*>& already_used);
139
140 }; // bfunc_
141
146 struct tfunc_
147 : qi::symbols<typename std::iterator_traits<std::string::const_iterator>::value_type,
148 std::function<Expression(Expression&, Expression&, Expression&)>>
149 {
153 typedef double(*fptr_dddd_t)(double, double, double);
154
159 typedef const double&(*fptr_drdrdrdrt)(const double&, const double&, const double&);
160
164 tfunc_(const std::vector<const TreeNode*>& already_used);
165
166 }; // tfunc_
167
168
169 // Sub-Parsers
170
171 struct constants_ constants;
172 struct builtin_vars_ builtin_vars;
173 struct ufunc_ ufunc;
174 struct bfunc_ bfunc;
175 struct tfunc_ tfunc;
176 struct variable_ var;
177
178
179 // Configuration
180
184 sparta::TreeNode* const root_;
185
189 std::vector<const TreeNode*> already_used_;
190
191
192 // Rules
193
194 typedef qi::rule<std::string::const_iterator,
195 Expression(),
196 ascii::space_type> ExpressionRule;
197
198 ExpressionRule expression,
199 term,
200 factor,
201 primary;
202
203public:
204
216 std::vector<const TreeNode*>& already_used,
217 const StatisticPairs &report_si);
218
219
220}; // struct grammar
221
222 } // namespace grammar
223 } // namespace expression
224 } // namespace statistics
225} // namespace sparta
Basic Node framework in sparta device tree composite pattern.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
Expression container/builder. Contains a single ExpressionNode representing the root of an expression...
ExpressionGrammar(sparta::TreeNode *root, std::vector< const TreeNode * > &already_used, const StatisticPairs &report_si)
Expression Grammar constructor.
std::vector< stat_pair_t > StatisticPairs
Type for storing a list of stat_pair_t.
Macros for handling exponential backoff.