30 #ifndef _PFUNCTIONGRAMMAR_H_ 31 #define _PFUNCTIONGRAMMAR_H_ 35 #include <boost/version.hpp> 37 #if BOOST_VERSION >= 103800 38 # include <boost/spirit/include/classic_core.hpp> 39 # include <boost/spirit/include/classic_ast.hpp> 40 using namespace BOOST_SPIRIT_CLASSIC_NS;
42 # include <boost/spirit/core.hpp> 43 # include <boost/spirit/tree/ast.hpp> 49 typedef parse_tree_match_t::tree_iterator
iter_t;
57 static const int realID = 1;
58 static const int constPiID = 2;
59 static const int constGammaMuID = 3;
60 static const int constFieldID = 4;
61 static const int constEnergyID = 5;
62 static const int constTempID = 6;
63 static const int funLabelID = 7;
64 static const int parameterID = 8;
65 static const int mapID = 9;
66 static const int functionID = 10;
67 static const int powerID = 11;
68 static const int factorID = 12;
69 static const int termID = 13;
70 static const int expressionID = 14;
71 static const int assignmentID = 15;
73 template <
typename ScannerT>
79 real = leaf_node_d[ real_p ];
81 const_pi = leaf_node_d[ str_p(
"PI") ];
83 const_gamma_mu = leaf_node_d[ str_p(
"GAMMA_MU") ];
85 const_field = leaf_node_d[ str_p(
"B") ];
87 const_energy = leaf_node_d[ str_p(
"EN") ];
89 const_temp = leaf_node_d[ ( lexeme_d[
"T" >> +digit_p ] ) ];
91 fun_label = leaf_node_d[ ( lexeme_d[
"FUN" >> +digit_p ] ) ];
93 parameter = leaf_node_d[ ( lexeme_d[
"PAR" >> +digit_p ] ) |
94 ( lexeme_d[
"-PAR" >> +digit_p ] ) ];
96 map = leaf_node_d[ ( lexeme_d[
"MAP" >> +digit_p ] ) ];
98 function = lexeme_d[ root_node_d[ str_p(
"COS") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
99 | lexeme_d[ root_node_d[ str_p(
"SIN") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
100 | lexeme_d[ root_node_d[ str_p(
"TAN") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
101 | lexeme_d[ root_node_d[ str_p(
"COSH") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
102 | lexeme_d[ root_node_d[ str_p(
"SINH") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
103 | lexeme_d[ root_node_d[ str_p(
"TANH") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
104 | lexeme_d[ root_node_d[ str_p(
"ACOS") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
105 | lexeme_d[ root_node_d[ str_p(
"ASIN") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
106 | lexeme_d[ root_node_d[ str_p(
"ATAN") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
107 | lexeme_d[ root_node_d[ str_p(
"ACOSH") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
108 | lexeme_d[ root_node_d[ str_p(
"ASINH") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
109 | lexeme_d[ root_node_d[ str_p(
"ATANH") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
110 | lexeme_d[ root_node_d[ str_p(
"LOG") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
111 | lexeme_d[ root_node_d[ str_p(
"LN") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
112 | lexeme_d[ root_node_d[ str_p(
"EXP") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
113 | lexeme_d[ root_node_d[ str_p(
"SQRT") ] >> ch_p(
'(') ] >> expression >> ch_p(
')')
116 power = lexeme_d[ root_node_d[ str_p(
"POW") ] >> ch_p(
'(') ] >> expression >> ch_p(
',') >> expression >> ch_p(
')')
129 | inner_node_d[ch_p(
'(') >> expression >> ch_p(
')')]
133 *( (root_node_d[ch_p(
'*')] >> factor)
134 | (root_node_d[ch_p(
'/')] >> factor)
138 *( (root_node_d[ch_p(
'+')] >> term)
139 | (root_node_d[ch_p(
'-')] >> term)
142 assignment = (fun_label >> ch_p(
'=') >> expression);
146 BOOST_SPIRIT_DEBUG_RULE(real);
147 BOOST_SPIRIT_DEBUG_RULE(const_pi);
148 BOOST_SPIRIT_DEBUG_RULE(const_gamma_mu);
149 BOOST_SPIRIT_DEBUG_RULE(const_field);
150 BOOST_SPIRIT_DEBUG_RULE(const_energy);
151 BOOST_SPIRIT_DEBUG_RULE(const_temp);
152 BOOST_SPIRIT_DEBUG_RULE(fun_label);
153 BOOST_SPIRIT_DEBUG_RULE(parameter);
154 BOOST_SPIRIT_DEBUG_RULE(map);
155 BOOST_SPIRIT_DEBUG_RULE(
function);
156 BOOST_SPIRIT_DEBUG_RULE(power);
157 BOOST_SPIRIT_DEBUG_RULE(factor);
158 BOOST_SPIRIT_DEBUG_RULE(term);
159 BOOST_SPIRIT_DEBUG_RULE(expression);
160 BOOST_SPIRIT_DEBUG_RULE(assignment);
163 rule<ScannerT, parser_context<>, parser_tag<assignmentID> >
assignment;
164 rule<ScannerT, parser_context<>, parser_tag<expressionID> >
expression;
165 rule<ScannerT, parser_context<>, parser_tag<termID> >
term;
166 rule<ScannerT, parser_context<>, parser_tag<factorID> >
factor;
167 rule<ScannerT, parser_context<>, parser_tag<functionID> >
function;
168 rule<ScannerT, parser_context<>, parser_tag<powerID> >
power;
169 rule<ScannerT, parser_context<>, parser_tag<mapID> >
map;
170 rule<ScannerT, parser_context<>, parser_tag<parameterID> >
parameter;
171 rule<ScannerT, parser_context<>, parser_tag<funLabelID> >
fun_label;
172 rule<ScannerT, parser_context<>, parser_tag<constTempID> >
const_temp;
173 rule<ScannerT, parser_context<>, parser_tag<constEnergyID> >
const_energy;
174 rule<ScannerT, parser_context<>, parser_tag<constFieldID> >
const_field;
176 rule<ScannerT, parser_context<>, parser_tag<constPiID> >
const_pi;
177 rule<ScannerT, parser_context<>, parser_tag<realID> >
real;
179 rule<ScannerT, parser_context<>, parser_tag<assignmentID> >
const&
180 start()
const {
return assignment; }
184 #endif // _PFUNCTIONGRAMMAR_H_ rule< ScannerT, parser_context<>, parser_tag< mapID > > map
rule< ScannerT, parser_context<>, parser_tag< constTempID > > const_temp
rule< ScannerT, parser_context<>, parser_tag< assignmentID > > const & start() const
rule< ScannerT, parser_context<>, parser_tag< constPiID > > const_pi
rule< ScannerT, parser_context<>, parser_tag< constEnergyID > > const_energy
rule< ScannerT, parser_context<>, parser_tag< assignmentID > > assignment
definition(PFunctionGrammar const &)
rule< ScannerT, parser_context<>, parser_tag< parameterID > > parameter
rule< ScannerT, parser_context<>, parser_tag< termID > > term
parse_tree_match_t::tree_iterator iter_t
rule< ScannerT, parser_context<>, parser_tag< expressionID > > expression
rule< ScannerT, parser_context<>, parser_tag< funLabelID > > fun_label
rule< ScannerT, parser_context<>, parser_tag< powerID > > power
rule< ScannerT, parser_context<>, parser_tag< constFieldID > > const_field
rule< ScannerT, parser_context<>, parser_tag< realID > > real
tree_match< iterator_t > parse_tree_match_t
rule< ScannerT, parser_context<>, parser_tag< constGammaMuID > > const_gamma_mu
rule< ScannerT, parser_context<>, parser_tag< factorID > > factor