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::ascii::space;
65 using boost::spirit::ascii::space_type;
67 using boost::spirit::ascii::alnum;
68 using boost::spirit::unused_type;
82 ParseResult() : action( KeepTPT )
88 expression.children.clear();
89 expression.type = Operator( Uninitialized );
100 template <
typename A,
typename B = unused_type,
101 typename C = unused_type,
typename D = unused_type >
102 struct result {
typedef void type; };
104 void operator()( ParseResult & parseResult, Action value )
const;
106 void operator()( ParseResult & parseResult, Subtree & value )
const;
108 void operator()( Subtree & ast, Node & node )
const;
110 void operator()( Node &
self, Node &
left, Node &
right,
111 Operator value )
const;
113 void operator()( Node &
self, Node & child, Operator value )
const;
115 void operator()( Node &
self, Node & primary )
const;
117 void operator()( Node &
self, Node & child, std::string & value )
120 void operator()( Leaf &
self, std::string &
name )
const;
122 void operator()( Leaf &
self,
int value,
size_t index )
const;
126 template <
typename Iterator >
127 struct Grammar : grammar< Iterator, ParseResult(), space_type >
131 rule< Iterator, ParseResult(), space_type > statement;
133 rule< Iterator, Action(), space_type > action;
135 rule< Iterator, Subtree(), space_type >
condition;
137 rule< Iterator, Node(), space_type > expression;
139 rule< Iterator, Node(), space_type > primary_expr;
141 rule< Iterator, Node(), space_type > function1;
143 rule< Iterator, std::string(), space_type > identifier;
145 rule< Iterator, Leaf(), space_type > leaf_operand;
147 rule< Iterator, Leaf(), space_type > constant;
149 rule< Iterator, Leaf(), space_type >
variable;
151 rule< Iterator, Node(), space_type > or_expr;
153 rule< Iterator, Node(), space_type > and_expr;
155 rule< Iterator, Node(), space_type > relation;
157 rule< Iterator, Node(), space_type > addition;
159 rule< Iterator, Node(), space_type > multiplication;
161 rule< Iterator, Node(), space_type > unary_expr;
163 rule< Iterator, Operator(), space_type > unary_op;
165 rule< Iterator, Operator(), space_type > mult_op;
167 rule< Iterator, Operator(), space_type > add_op;
169 rule< Iterator, Operator(), space_type > rel_op;
171 real_parser< double, strict_real_policies< double > > strict_double;
173 function< Compiler > op;
177 template <
typename Iterator >
178 Grammar< Iterator >::Grammar() : Grammar::base_type( statement )
180 statement = action[ op( _val, _1 ) ] >>
183 action = lit(
"keep" ) >>
184 ( lit(
"tpt" )[ _val = KeepTPT ] |
185 lit(
"edt" )[ _val = KeepEDT ] ) |
187 ( lit(
"tpt" )[ _val = DeleteTPT ] |
188 lit(
"edt" )[ _val = DeleteEDT ] );
190 condition = lit(
"if" ) >> expression[ op( _val, _1 ) ];
192 expression %= or_expr;
194 identifier %= raw[ lexeme[
alpha >> *( alnum |
'_' ) ] ];
196 primary_expr = function1[ _val = _1 ] |
197 lit(
'(' ) >> expression[ op( _val, _1 ) ] >> lit(
')' ) |
198 leaf_operand[ _val = _1 ];
200 leaf_operand %= constant |
variable;
202 constant %= strict_double | int_;
204 variable = identifier[ op( _val, _1 ) ] >>
205 -( lit(
'[' ) >> ( uint_[ op( _val, _1, 0 ) ] - lit(
'0' ) ) >>
206 -( lit(
',' ) >> ( uint_[ op( _val, _1, 1 ) ] -
207 lit(
'0' ) ) ) >> lit(
']' ) );
209 function1 = ( identifier >> lit(
'(' ) >> expression >> lit(
')' ) )
210 [ op( _val, _2, _1 ) ];
212 or_expr = ( and_expr >> lit(
'|' ) >> or_expr )
213 [ op( _val, _1, _2, Operator( Or, 1 ) ) ] |
214 and_expr[ _val = _1 ];
216 and_expr = ( relation >> lit(
'&' ) >> and_expr )
217 [ op( _val, _1, _2, Operator( And, 2 ) ) ] |
218 relation[ _val = _1 ];
220 relation = ( addition >> rel_op >> addition )
221 [ op( _val, _1, _3, _2 ) ] |
222 addition[ _val = _1 ];
224 addition = ( multiplication >> add_op >> addition )
225 [ op( _val, _1, _3, _2 ) ] |
226 multiplication[ _val = _1 ];
228 multiplication = ( unary_expr >> mult_op >> multiplication )
229 [ op( _val, _1, _3, _2 ) ] |
230 unary_expr[ _val = _1 ];
232 unary_expr = ( unary_op >> primary_expr )[ op( _val, _2, _1 ) ] |
233 primary_expr[ _val = _1 ];
235 unary_op = lit(
'-' )[ _val = Operator( UMinus, 6,
true ) ] |
236 lit(
'!' )[ _val = Operator( Not, 6,
true ) ];
238 mult_op = lit(
'*' )[ _val = Operator( Mult, 5 ) ] |
239 lit(
'/' )[ _val = Operator( Div, 5 ) ];
241 add_op = lit(
'+' )[ _val = Operator( Plus, 4 ) ] |
242 lit(
'-' )[ _val = Operator( Minus, 4 ) ];
244 rel_op = lit(
"<=" )[ _val = Operator( LessEq, 3 ) ] |
245 lit(
">=" )[ _val = Operator( MoreEq, 3 ) ] |
246 lit(
"!=" )[ _val = Operator( NotEq, 3 ) ] |
247 lit(
'<' )[ _val = Operator( Less, 3 ) ] |
248 lit(
'>' )[ _val = Operator( More, 3 ) ] |
249 lit(
'=' )[ _val = Operator( Eq, 3 ) ];
G4double condition(const G4ErrorSymMatrix &m)
static int variable(const string &name, double &result, const dic_type &dictionary)
static const G4double A[nN]
static const G4double alpha