Stan  2.14.0
probability, sampling & optimization
statement_2_grammar_def.hpp
Go to the documentation of this file.
1 #ifndef STAN_LANG_GRAMMARS_STATEMENT_2_GRAMMAR_DEF_HPP
2 #define STAN_LANG_GRAMMARS_STATEMENT_2_GRAMMAR_DEF_HPP
3 
4 #include <stan/lang/ast.hpp>
9 #include <boost/spirit/include/qi.hpp>
10 #include <boost/spirit/include/phoenix_core.hpp>
11 #include <sstream>
12 
13 namespace stan {
14 
15  namespace lang {
16 
17  template <typename Iterator>
19  std::stringstream& error_msgs,
21  : statement_2_grammar::base_type(statement_2_r),
22  var_map_(var_map),
23  error_msgs_(error_msgs),
24  expression_g(var_map, error_msgs),
25  statement_g(sg) {
26  using boost::spirit::qi::_1;
27  using boost::spirit::qi::char_;
28  using boost::spirit::qi::lit;
29  using boost::spirit::qi::no_skip;
30  using boost::spirit::qi::_pass;
31  using boost::spirit::qi::_val;
32  using boost::spirit::qi::labels::_r1;
33  using boost::spirit::qi::labels::_r2;
34  using boost::spirit::qi::labels::_r3;
35  using boost::spirit::qi::labels::_r4;
36 
37  // _r1 true if sample_r allowed (inherited)
38  // _r2 source of variables allowed for assignments
39  // set to true if sample_r are allowed
40  statement_2_r.name("statement");
41  statement_2_r %= conditional_statement_r(_r1, _r2, _r3, _r4);
42 
43  conditional_statement_r.name("if-else statement");
45  = (lit("if") >> no_skip[!char_("a-zA-Z0-9_")])
46  > lit('(')
47  > expression_g(_r2)
48  [add_conditional_condition_f(_val, _1, _pass,
49  boost::phoenix::ref(error_msgs_))]
50  > lit(')')
51  > statement_g(_r1, _r2, _r3, _r4)
52  [add_conditional_body_f(_val, _1)]
53  > * (((lit("else") >> no_skip[!char_("a-zA-Z0-9_")])
54  >> (lit("if") >> no_skip[!char_("a-zA-Z0-9_")]))
55  > lit('(')
56  > expression_g(_r2)
57  [add_conditional_condition_f(_val, _1, _pass,
58  boost::phoenix::ref(error_msgs_))]
59  > lit(')')
60  > statement_g(_r1, _r2, _r3, _r4)
61  [add_conditional_body_f(_val, _1)])
62  > -((lit("else") >> no_skip[!char_("a-zA-Z0-9_")])
63  > statement_g(_r1, _r2, _r3, _r4)
64  [add_conditional_body_f(_val, _1)]);
65  }
66 
67  }
68 }
69 #endif
Probability, optimization and sampling library.
A map from function names to their base declarations and their origin.
boost::phoenix::function< add_conditional_condition > add_conditional_condition_f
boost::spirit::qi::rule< Iterator, statement(bool, var_origin, bool, bool), whitespace_grammar< Iterator > > statement_2_r
boost::phoenix::function< add_conditional_body > add_conditional_body_f
statement_2_grammar(variable_map &var_map, std::stringstream &error_msgs, statement_grammar< Iterator > &sg)
statement_grammar< Iterator > & statement_g
expression_grammar< Iterator > expression_g
boost::spirit::qi::rule< Iterator, conditional_statement(bool, var_origin, bool, bool), whitespace_grammar< Iterator > > conditional_statement_r

     [ Stan Home Page ] © 2011–2016, Stan Development Team.