60 struct MakeSharedFunctor
62 template <
typename... A>
65 typedef std::shared_ptr<T> type;
68 template <
typename... A>
69 typename result<A...>::type operator()(A&&... a)
const
71 return T::Make(std::forward<A>(a)...);
76 using make_shared_ = boost::phoenix::function<MakeSharedFunctor<T> >;
105BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, cos_lazy, cos, 1);
106BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, sin_lazy, sin, 1);
107BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, tan_lazy, tan, 1);
109BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, log_lazy, log, 1);
110BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, exp_lazy, exp, 1);
111BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, sqrt_lazy, sqrt, 1);
125 namespace qi = ::boost::spirit::qi;
126 namespace ascii = ::boost::spirit::ascii;
141 template<
typename Iterator>
142 struct FunctionParser : qi::grammar<Iterator, std::shared_ptr<node::Node>(), boost::spirit::ascii::space_type>
150 FunctionParser(qi::symbols<
char,std::shared_ptr<Node> > * encountered_symbols) : FunctionParser::base_type(root_rule_,
"FunctionParser")
152 namespace phx = boost::phoenix;
164 root_rule_.name(
"function_");
165 root_rule_ = expression_ [ _val = make_shared_<Function>()(_1)];
169 expression_.name(
"expression_");
172 >> *( (lit(
'+') > term_ [_val += _1])
173 | (lit(
'-') > term_ [_val -= _1])
180 >> *( (lit(
'*') > factor_ [_val *= _1])
181 | (lit(
'/') > factor_ [_val /= _1])
185 factor_.name(
"factor_");
187 exp_elem_ [_val = _1]
189 > exp_elem_ [ phx::bind( []
190 (std::shared_ptr<Node> & B, std::shared_ptr<Node> P)
197 exp_elem_.name(
"exp_elem_");
199 (symbol_ >> !qi::alnum) [_val = _1]
200 | (
'(' > expression_ [_val = _1] >
')' )
201 | (lit(
'-') > expression_ [_val = -_1])
202 | (lit(
'+') > expression_ [_val = _1])
203 | (lit(
"sin") >
'(' > expression_ [_val = sin_lazy(_1)] >
')' )
204 | (lit(
"cos") >
'(' > expression_ [_val = cos_lazy(_1)] >
')' )
205 | (lit(
"tan") >
'(' > expression_ [_val = tan_lazy(_1)] >
')' )
206 | (lit(
"exp") >
'(' > expression_ [_val = exp_lazy(_1)] >
')' )
207 | (lit(
"log") >
'(' > expression_ [_val = log_lazy(_1)] >
')' )
208 | (lit(
"sqrt") >
'(' > expression_ [_val = sqrt_lazy(_1)] >
')' )
218 symbol_.name(
"symbol_");
220 (*encountered_symbols)
235 number_.name(
"number_");
237 mpfr_rules_.long_number_string_ [ _val = make_shared_<Float>()(_1) ]
239 mpfr_rules_.integer_string_ [ _val = make_shared_<Integer>()(_1) ];
249 using boost::phoenix::val;
250 using boost::phoenix::construct;
257 << val(
"Function parser error: expecting ")
260 << construct<std::string>(_3, _2)
286 qi::rule<Iterator, std::shared_ptr<Node>(), ascii::space_type > root_rule_;
289 qi::rule<Iterator, std::shared_ptr<Node>(), ascii::space_type> expression_, term_, factor_, exp_elem_;
294 qi::rule<Iterator, std::shared_ptr<Node>(), ascii::space_type > symbol_;
297 qi::rule<Iterator, std::shared_ptr<Node>(), ascii::space_type > variable_;
300 qi::rule<Iterator, std::shared_ptr<Node>(), ascii::space_type > number_;
302 parsing::rules::LongNum<Iterator> mpfr_rules_;
Provides the artithmetic Node types, such as Sum and Power.
Number type for storing floating point numbers within an expression tree.
Definition number.hpp:250
Formal entry point into an expression tree.
Definition function.hpp:218
Signed real Integer storage in an expression tree.
Definition number.hpp:173
Abstract base class for the Bertini hybrid-precision (double-multiple) expression tree.
Definition node.hpp:142
The Rational number type for Bertini2 expression trees.
Definition number.hpp:323
dbl pow(const dbl &z, int power)
Definition double_extensions.hpp:88
Provides the Function Node type, a NamedSymbol.
Defines the abstract Node base class.
Provides the Number Node types, including Rational, Float, and Integer.
Provides the parsersing rules for numbers in bertini2.
Provides all the include files needed to develop a parsing file that uses boost qi.
Provides the abstract TrigOperator, and the concrete types such as SinOperator.
Provides the Variable Node class.