Stan  2.10.0
probability, sampling & optimization
bare_type_grammar_def.hpp
Go to the documentation of this file.
1 #ifndef STAN_LANG_GRAMMARS_BARE_TYPE_GRAMMAR_DEF_HPP
2 #define STAN_LANG_GRAMMARS_BARE_TYPE_GRAMMAR_DEF_HPP
3 
4 #include <boost/spirit/include/qi.hpp>
5 #include <boost/spirit/include/phoenix_core.hpp>
6 #include <stan/lang/ast.hpp>
9 
11  (stan::lang::base_expr_type, base_type_)
12  (size_t, num_dims_) )
13 
14 namespace stan {
15 
16  namespace lang {
17 
18  template <typename Iterator>
19  bare_type_grammar<Iterator>::bare_type_grammar(variable_map& var_map,
20  std::stringstream& error_msgs)
21  : bare_type_grammar::base_type(bare_type_r),
22  var_map_(var_map),
23  error_msgs_(error_msgs) {
24  using boost::spirit::qi::eps;
25  using boost::spirit::qi::lit;
26  using boost::spirit::qi::_val;
27 
28  bare_type_r.name("bare type definition\n"
29  " (no dimensions or constraints, just commas,\n"
30  " e.g. real[,] for a 2D array or int for a single integer,\n"
31  " and constrained types such as cov_matrix not allowed)");
32  bare_type_r %= type_identifier_r >> array_dims_r;
33 
34  type_identifier_r.name("bare type identifier\n"
35  " legal values: void, int, real, vector, row_vector, matrix");
36  type_identifier_r
37  %= lit("void")[assign_lhs_f(_val, VOID_T)]
38  | lit("int")[assign_lhs_f(_val, INT_T)]
39  | lit("real")[assign_lhs_f(_val, DOUBLE_T)]
40  | lit("vector")[assign_lhs_f(_val, VECTOR_T)]
41  | lit("row_vector")[assign_lhs_f(_val, ROW_VECTOR_T)]
42  | lit("matrix")[assign_lhs_f(_val, MATRIX_T)];
43 
44  array_dims_r.name("array dimensions,\n"
45  " e.g., empty (not an array) [] (1D array) or [,] (2D array)");
46  array_dims_r
47  %= eps[assign_lhs_f(_val, static_cast<size_t>(0))]
48  >> -(lit('[')[assign_lhs_f(_val, static_cast<size_t>(1))]
49  > *(lit(',')[increment_size_t_f(_val)])
50  > end_bare_types_r);
51 
52  end_bare_types_r.name("comma to indicate more dimensions"
53  " or ] to end type declaration");
54  end_bare_types_r %= lit(']');
55  }
56 
57  }
58 }
59 #endif
const int ROW_VECTOR_T
Definition: ast.hpp:72
Probability, optimization and sampling library.
const int DOUBLE_T
Definition: ast.hpp:70
int base_expr_type
Definition: ast.hpp:64
BOOST_FUSION_ADAPT_STRUCT(stan::lang::expr_type,(stan::lang::base_expr_type, base_type_)(size_t, num_dims_)) namespace stan
const int VOID_T
Definition: ast.hpp:68
boost::phoenix::function< assign_lhs > assign_lhs_f
const int INT_T
Definition: ast.hpp:69
boost::phoenix::function< increment_size_t > increment_size_t_f
const int VECTOR_T
Definition: ast.hpp:71
const int MATRIX_T
Definition: ast.hpp:73

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