44 #ifndef CEXMC_CUSTOM_FILTER_HH
45 #define CEXMC_CUSTOM_FILTER_HH
47 #ifdef CEXMC_USE_CUSTOM_FILTER
50 #include <boost/spirit/include/qi.hpp>
51 #include <boost/spirit/include/phoenix_core.hpp>
52 #include <boost/spirit/include/phoenix_operator.hpp>
53 #include <boost/spirit/include/phoenix_function.hpp>
57 namespace CexmcCustomFilter
59 using namespace boost::spirit;
60 using namespace boost::spirit::qi;
61 using namespace boost::spirit::ascii;
62 using namespace boost::phoenix;
63 using namespace CexmcAST;
64 using boost::spirit::qi::rule;
65 using boost::spirit::ascii::space;
66 using boost::spirit::ascii::space_type;
68 using boost::spirit::ascii::alnum;
69 using boost::spirit::unused_type;
83 ParseResult() : action( KeepTPT )
89 expression.children.clear();
90 expression.type = Operator( Uninitialized );
101 template <
typename A,
typename B = unused_type,
102 typename C = unused_type,
typename D = unused_type >
103 struct result {
typedef void type; };
105 void operator()( ParseResult & parseResult, Action
value )
const;
107 void operator()( ParseResult & parseResult, Subtree &
value )
const;
109 void operator()( Subtree & ast, Node & node )
const;
111 void operator()( Node &
self, Node &
left, Node &
right,
112 Operator
value )
const;
114 void operator()( Node &
self, Node & child, Operator
value )
const;
116 void operator()( Node &
self, Node & primary )
const;
118 void operator()( Node &
self, Node & child, std::string &
value )
121 void operator()( Leaf &
self, std::string &
name )
const;
123 void operator()( Leaf &
self,
int value,
size_t index )
const;
127 template <
typename Iterator >
128 struct Grammar : grammar< Iterator, ParseResult(), space_type >
132 rule< Iterator, ParseResult(), space_type > statement;
134 rule< Iterator, Action(), space_type > action;
136 rule< Iterator, Subtree(), space_type >
condition;
138 rule< Iterator, Node(), space_type > expression;
140 rule< Iterator, Node(), space_type > primary_expr;
142 rule< Iterator, Node(), space_type > function1;
144 rule< Iterator, std::string(), space_type > identifier;
146 rule< Iterator, Leaf(), space_type > leaf_operand;
148 rule< Iterator, Leaf(), space_type > constant;
150 rule< Iterator, Leaf(), space_type >
variable;
152 rule< Iterator, Node(), space_type > or_expr;
154 rule< Iterator, Node(), space_type > and_expr;
156 rule< Iterator, Node(), space_type > relation;
158 rule< Iterator, Node(), space_type > addition;
160 rule< Iterator, Node(), space_type > multiplication;
162 rule< Iterator, Node(), space_type > unary_expr;
164 rule< Iterator, Operator(), space_type > unary_op;
166 rule< Iterator, Operator(), space_type > mult_op;
168 rule< Iterator, Operator(), space_type > add_op;
170 rule< Iterator, Operator(), space_type > rel_op;
172 real_parser< double, strict_real_policies< double > > strict_double;
174 function< Compiler > op;
178 template <
typename Iterator >
179 Grammar< Iterator >::Grammar() : Grammar::base_type( statement )
181 statement = action[ op( _val, _1 ) ] >>
184 action = lit(
"keep" ) >>
185 ( lit(
"tpt" )[ _val = KeepTPT ] |
186 lit(
"edt" )[ _val = KeepEDT ] ) |
188 ( lit(
"tpt" )[ _val = DeleteTPT ] |
189 lit(
"edt" )[ _val = DeleteEDT ] );
191 condition = lit(
"if" ) >> expression[ op( _val, _1 ) ];
193 expression %= or_expr;
195 identifier %= raw[ lexeme[
alpha >> *( alnum |
'_' ) ] ];
197 primary_expr = function1[ _val = _1 ] |
198 lit(
'(' ) >> expression[ op( _val, _1 ) ] >> lit(
')' ) |
199 leaf_operand[ _val = _1 ];
201 leaf_operand %= constant |
variable;
203 constant %= strict_double | int_;
205 variable = identifier[ op( _val, _1 ) ] >>
206 -( lit(
'[' ) >> ( uint_[ op( _val, _1, 0 ) ] - lit(
'0' ) ) >>
207 -( lit(
',' ) >> ( uint_[ op( _val, _1, 1 ) ] -
208 lit(
'0' ) ) ) >> lit(
']' ) );
210 function1 = ( identifier >> lit(
'(' ) >> expression >> lit(
')' ) )
211 [ op( _val, _2, _1 ) ];
213 or_expr = ( and_expr >> lit(
'|' ) >> or_expr )
214 [ op( _val, _1, _2, Operator( Or, 1 ) ) ] |
215 and_expr[ _val = _1 ];
217 and_expr = ( relation >> lit(
'&' ) >> and_expr )
218 [ op( _val, _1, _2, Operator( And, 2 ) ) ] |
219 relation[ _val = _1 ];
221 relation = ( addition >> rel_op >> addition )
222 [ op( _val, _1, _3, _2 ) ] |
223 addition[ _val = _1 ];
225 addition = ( multiplication >> add_op >> addition )
226 [ op( _val, _1, _3, _2 ) ] |
227 multiplication[ _val = _1 ];
229 multiplication = ( unary_expr >> mult_op >> multiplication )
230 [ op( _val, _1, _3, _2 ) ] |
231 unary_expr[ _val = _1 ];
233 unary_expr = ( unary_op >> primary_expr )[ op( _val, _2, _1 ) ] |
234 primary_expr[ _val = _1 ];
236 unary_op = lit(
'-' )[ _val = Operator( UMinus, 6,
true ) ] |
237 lit(
'!' )[ _val = Operator( Not, 6,
true ) ];
239 mult_op = lit(
'*' )[ _val = Operator( Mult, 5 ) ] |
240 lit(
'/' )[ _val = Operator( Div, 5 ) ];
242 add_op = lit(
'+' )[ _val = Operator( Plus, 4 ) ] |
243 lit(
'-' )[ _val = Operator( Minus, 4 ) ];
245 rel_op = lit(
"<=" )[ _val = Operator( LessEq, 3 ) ] |
246 lit(
">=" )[ _val = Operator( MoreEq, 3 ) ] |
247 lit(
"!=" )[ _val = Operator( NotEq, 3 ) ] |
248 lit(
'<' )[ _val = Operator( Less, 3 ) ] |
249 lit(
'>' )[ _val = Operator( More, 3 ) ] |
250 lit(
'=' )[ _val = Operator( Eq, 3 ) ];
G4double condition(const G4ErrorSymMatrix &m)
const XML_Char int const XML_Char * value
static const G4double alpha
double A(double temperature)
G4double G4ParticleHPJENDLHEData::G4double result
static int variable(const string &name, double &result, const dic_type &dictionary)
double B(double temperature)