1 #ifndef __STAN__GM__PARSER__EXPRESSION_GRAMMAR_DEF__HPP__
2 #define __STAN__GM__PARSER__EXPRESSION_GRAMMAR_DEF__HPP__
16 #include <boost/spirit/include/qi.hpp>
18 #include <boost/spirit/include/phoenix_core.hpp>
19 #include <boost/spirit/include/phoenix_function.hpp>
20 #include <boost/spirit/include/phoenix_fusion.hpp>
21 #include <boost/spirit/include/phoenix_object.hpp>
22 #include <boost/spirit/include/phoenix_operator.hpp>
23 #include <boost/spirit/include/phoenix_stl.hpp>
25 #include <boost/lexical_cast.hpp>
26 #include <boost/fusion/include/adapt_struct.hpp>
27 #include <boost/fusion/include/std_pair.hpp>
28 #include <boost/config/warning_disable.hpp>
29 #include <boost/spirit/include/qi.hpp>
30 #include <boost/spirit/include/qi_numeric.hpp>
31 #include <boost/spirit/include/classic_position_iterator.hpp>
32 #include <boost/spirit/include/phoenix_core.hpp>
33 #include <boost/spirit/include/phoenix_function.hpp>
34 #include <boost/spirit/include/phoenix_fusion.hpp>
35 #include <boost/spirit/include/phoenix_object.hpp>
36 #include <boost/spirit/include/phoenix_operator.hpp>
37 #include <boost/spirit/include/phoenix_stl.hpp>
38 #include <boost/spirit/include/support_multi_pass.hpp>
39 #include <boost/tuple/tuple.hpp>
40 #include <boost/variant/apply_visitor.hpp>
41 #include <boost/variant/recursive_variant.hpp>
55 template <
typename T1,
typename T2>
59 std::ostream& error_msgs)
const {
61 error_msgs <<
"expression is ill formed" << std::endl;
71 template <
typename T1,
typename T2>
75 std::ostream& error_msgs)
const {
76 std::vector<expr_type> arg_types;
77 for (
size_t i = 0; i < fun.
args_.size(); ++i)
78 arg_types.push_back(fun.
args_[i].expression_type());
88 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
93 const std::string& op,
94 const std::string& fun_name,
95 std::ostream& error_msgs)
const {
98 error_msgs <<
"binary infix operator "
100 <<
" with functional interpretation "
102 <<
" requires arguments or primitive type (int or real)"
107 std::vector<expression> args;
108 args.push_back(expr1);
109 args.push_back(expr2);
111 fun f(fun_name,args);
120 template <
typename T1,
typename T2,
typename T3>
125 std::ostream& error_msgs)
const {
128 return expr1 += expr2;
130 std::vector<expression> args;
131 args.push_back(expr1);
132 args.push_back(expr2);
137 return expr1 += expr2;
144 template <
typename T1,
typename T2,
typename T3>
149 std::ostream& error_msgs)
const {
152 return expr1 -= expr2;
154 std::vector<expression> args;
155 args.push_back(expr1);
156 args.push_back(expr2);
158 fun f(
"subtract",args);
167 template <
typename Iterator>
169 std::stringstream& error_msgs,
173 error_msgs_(error_msgs),
174 term_g(var_map,error_msgs,*this)
176 using boost::spirit::qi::_1;
177 using boost::spirit::qi::char_;
178 using boost::spirit::qi::double_;
179 using boost::spirit::qi::eps;
180 using boost::spirit::qi::int_;
181 using boost::spirit::qi::lexeme;
182 using boost::spirit::qi::lit;
183 using boost::spirit::qi::_pass;
184 using boost::spirit::qi::_val;
188 expression_r.name(
"expression (top level, precedence 15, binary ||");
193 boost::phoenix::ref(error_msgs))]
201 boost::phoenix::ref(error_msgs))]
209 boost::phoenix::ref(error_msgs))] )
213 boost::phoenix::ref(error_msgs))] )
216 expression09_r.name(
"expression, precedence 9, binary <, <=, >, >=");
221 boost::phoenix::ref(error_msgs))] )
225 boost::phoenix::ref(error_msgs))] )
229 boost::phoenix::ref(error_msgs))] )
233 boost::phoenix::ref(error_msgs))] )
242 [_val =
addition(_val,_1,boost::phoenix::ref(error_msgs))] )
246 [_val =
subtraction(_val,_1,boost::phoenix::ref(error_msgs))] )