1 #ifndef STAN_LANG_GRAMMARS_PROGRAM_GRAMMAR_DEF_HPP 2 #define STAN_LANG_GRAMMARS_PROGRAM_GRAMMAR_DEF_HPP 7 #include <boost/format.hpp> 8 #include <boost/fusion/include/std_pair.hpp> 9 #include <boost/spirit/home/support/iterators/line_pos_iterator.hpp> 10 #include <boost/spirit/include/phoenix_core.hpp> 11 #include <boost/spirit/include/qi.hpp> 21 typedef std::pair<std::vector<stan::lang::var_decl>,
22 std::vector<stan::lang::statement> > type;
27 (std::vector<stan::lang::function_decl_def>,
29 (std::vector<stan::lang::var_decl>, data_decl_)
30 (DUMMY_STRUCT::type, derived_data_decl_)
31 (std::vector<stan::lang::var_decl>, parameter_decl_)
32 (DUMMY_STRUCT::type, derived_decl_)
34 (DUMMY_STRUCT::type, generated_decl_) )
41 template <
typename Iterator>
42 program_grammar<Iterator>::program_grammar(
const std::string& model_name,
44 : program_grammar::base_type(program_r),
45 model_name_(model_name),
48 expression_g(var_map_, error_msgs_),
49 var_decls_g(var_map_, error_msgs_),
50 statement_g(var_map_, error_msgs_),
51 functions_g(var_map_, error_msgs_, allow_undefined) {
52 using boost::spirit::qi::eps;
53 using boost::spirit::qi::lit;
54 using boost::spirit::qi::on_error;
55 using boost::spirit::qi::rethrow;
56 using boost::spirit::qi::_1;
57 using boost::spirit::qi::_2;
58 using boost::spirit::qi::_3;
59 using boost::spirit::qi::_4;
64 program_r.name(
"program");
68 > -derived_data_var_decls_r
71 > -derived_var_decls_r
74 > -generated_var_decls_r;
76 model_r.name(
"model declaration (or perhaps an earlier block)");
82 "one of the following:\n" 83 " a variable declaration, beginning with type,\n" 84 " (int, real, vector, row_vector, matrix, unit_vector,\n" 85 " simplex, ordered, positive_ordered,\n" 86 " corr_matrix, cov_matrix,\n" 87 " cholesky_corr, cholesky_cov\n" 88 " or '}' to close variable declarations");
89 end_var_decls_r %= lit(
'}');
91 end_var_decls_statements_r.name(
92 "one of the following:\n" 93 " a variable declaration, beginning with type\n" 94 " (int, real, vector, row_vector, matrix, unit_vector,\n" 95 " simplex, ordered, positive_ordered,\n" 96 " corr_matrix, cov_matrix,\n" 97 " cholesky_corr, cholesky_cov\n" 99 " or '}' to close variable declarations and definitions");
100 end_var_decls_statements_r %= lit(
'}');
102 end_var_definitions_r.name(
"expected another statement or '}'" 103 " to close declarations");
104 end_var_definitions_r %= lit(
'}');
106 data_var_decls_r.name(
"data variable declarations");
113 derived_data_var_decls_r.name(
"transformed data block");
114 derived_data_var_decls_r
115 %= ((lit(
"transformed")
121 > end_var_definitions_r)
123 > end_var_decls_statements_r));
125 param_var_decls_r.name(
"parameter variable declarations");
127 %= (lit(
"parameters")
132 derived_var_decls_r.name(
"derived variable declarations");
134 %= (lit(
"transformed")
139 > end_var_decls_statements_r;
141 generated_var_decls_r.name(
"generated variable declarations");
142 generated_var_decls_r
148 > end_var_decls_statements_r;
150 on_error<rethrow>(program_r,
152 boost::phoenix::ref(var_map_),
153 boost::phoenix::ref(error_msgs_)));
Structure to wrap the variant type of statements.
const int derived_origin
The origin of the variable is ???.
const int parameter_origin
The origin of the variable is the parameter block.
Probability, optimization and sampling library.
boost::phoenix::function< program_error > program_error_f
const int transformed_parameter_origin
The origin of the variable is the transformed parameter block.
boost::phoenix::function< remove_lp_var > remove_lp_var_f
const int model_name_origin
Origin of variable is the name of the model.
const int data_origin
The origin of the variable is the data block.
boost::phoenix::function< add_lp_var > add_lp_var_f
BOOST_FUSION_ADAPT_STRUCT(stan::lang::program,(std::vector< stan::lang::function_decl_def >, function_decl_defs_)(std::vector< stan::lang::var_decl >, data_decl_)(DUMMY_STRUCT::type, derived_data_decl_)(std::vector< stan::lang::var_decl >, parameter_decl_)(DUMMY_STRUCT::type, derived_decl_)(stan::lang::statement, statement_)(DUMMY_STRUCT::type, generated_decl_)) namespace stan
const int local_origin
The origin of the variable is as a local variable.
AST node for a complete Stan program.
const int transformed_data_origin
The origin of the variable is the transformed data block.