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> >;
106BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, cos_lazy, cos, 1);
107BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, sin_lazy, sin, 1);
108BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, tan_lazy, tan, 1);
110BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, log_lazy, log, 1);
111BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, exp_lazy, exp, 1);
112BOOST_PHOENIX_ADAPT_FUNCTION(std::shared_ptr<bertini::node::Node>, sqrt_lazy, sqrt, 1);
127 namespace qi = ::boost::spirit::qi;
128 namespace ascii = ::boost::spirit::ascii;
143 template<
typename Iterator>
144 struct FunctionParser : qi::grammar<Iterator, std::shared_ptr<node::Node>(), boost::spirit::ascii::space_type>
154 namespace phx = boost::phoenix;
166 root_rule_.name(
"function_");
169 root_rule_ = expression_ [ _val = _1];
173 expression_.name(
"expression_");
176 >> *( (lit(
'+') > term_ [_val += _1])
177 | (lit(
'-') > term_ [_val -= _1])
184 >> *( (lit(
'*') > factor_ [_val *= _1])
185 | (lit(
'/') > factor_ [_val /= _1])
189 factor_.name(
"factor_");
191 exp_elem_ [_val = _1]
193 > exp_elem_ [ phx::bind( []
194 (std::shared_ptr<Node> & B, std::shared_ptr<Node> P)
201 exp_elem_.name(
"exp_elem_");
208 (symbol_ >> utf8_ident_boundary_parser()) [_val = _1]
209 | (
'(' > expression_ [_val = _1] >
')' )
213 | (lit(
'-') > factor_ [_val = -_1])
214 | (lit(
'+') > factor_ [_val = _1])
215 | (lit(
"sin") >
'(' > expression_ [_val = sin_lazy(_1)] >
')' )
216 | (lit(
"cos") >
'(' > expression_ [_val = cos_lazy(_1)] >
')' )
217 | (lit(
"tan") >
'(' > expression_ [_val = tan_lazy(_1)] >
')' )
218 | (lit(
"exp") >
'(' > expression_ [_val = exp_lazy(_1)] >
')' )
219 | (lit(
"log") >
'(' > expression_ [_val = log_lazy(_1)] >
')' )
220 | (lit(
"sqrt") >
'(' > expression_ [_val = sqrt_lazy(_1)] >
')' )
230 symbol_.name(
"symbol_");
232 (*encountered_symbols)
247 number_.name(
"number_");
249 mpfr_rules_.long_number_string_ [ _val = make_shared_<Complex>()(_1) ]
251 mpfr_rules_.integer_string_ [ _val = make_shared_<Integer>()(_1) ];
260 qi::on_error<qi::fail>(
287 qi::rule<Iterator, std::shared_ptr<Node>(), ascii::space_type > root_rule_;
290 qi::rule<Iterator, std::shared_ptr<Node>(), ascii::space_type> expression_, term_, factor_, exp_elem_;
295 qi::rule<Iterator, std::shared_ptr<Node>(), ascii::space_type > symbol_;
298 qi::rule<Iterator, std::shared_ptr<Node>(), ascii::space_type > variable_;
301 qi::rule<Iterator, std::shared_ptr<Node>(), ascii::space_type > number_;
303 parsing::rules::LongNum<Iterator> mpfr_rules_;
Provides the artithmetic Node types, such as Sum and Power.
A complex-number literal node in an expression tree.
Definition number.hpp:254
Signed real Integer storage in an expression tree.
Definition number.hpp:143
An interface for all nodes in a function tree, and for a function object as well.
Definition node.hpp:114
The Rational number type for Bertini2 expression trees.
Definition number.hpp:379
A user-named expression node: prints as its name, evaluates to its expression.
Definition classic_utilities.hpp:41
void ReportParseError(std::string::const_iterator begin, std::string::const_iterator end, std::string::const_iterator err_pos, boost::spirit::info const &what, std::string const &parser_name)
Report a parse error (via FormatParseError) to the log, for use in a Spirit on_error handler.
Definition qi_files.hpp:199
Definition classic_utilities.hpp:40
Definition algorithm_builder.hpp:36
complex_dbl pow(const complex_dbl &z, int power)
Compute +,- integral powers of a std::complex<double> number.
Definition double_extensions.hpp:92
Defines the abstract Node base class.
Provides the Number Node types, including Rational, Complex, 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.
node::Complex Complex
The complex-number node type.
Definition function_rules.hpp:147
FunctionParser(qi::symbols< char, std::shared_ptr< Node > > *encountered_symbols)
Construct the function parser, given the table of already-encountered symbols.
Definition function_rules.hpp:152
node::Integer Integer
The integer node type.
Definition function_rules.hpp:148
node::Node Node
The generic expression-tree node type.
Definition function_rules.hpp:146
node::Rational Rational
The rational-number node type.
Definition function_rules.hpp:149
Provides the abstract TrigOperator, and the concrete types such as SinOperator.
Provides the Variable Node class.