Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
var_decls_grammar_def.hpp
Go to the documentation of this file.
1 #ifndef __STAN__GM__PARSER__VAR_DECLS_GRAMMAR_DEF__HPP__
2 #define __STAN__GM__PARSER__VAR_DECLS_GRAMMAR_DEF__HPP__
3 
4 #include <boost/spirit/include/qi.hpp>
5 // FIXME: get rid of unused include
6 #include <boost/spirit/include/phoenix_core.hpp>
7 #include <boost/spirit/include/phoenix_function.hpp>
8 #include <boost/spirit/include/phoenix_fusion.hpp>
9 #include <boost/spirit/include/phoenix_object.hpp>
10 #include <boost/spirit/include/phoenix_operator.hpp>
11 #include <boost/spirit/include/phoenix_stl.hpp>
12 
13 #include <boost/lexical_cast.hpp>
14 #include <boost/fusion/include/adapt_struct.hpp>
15 #include <boost/fusion/include/std_pair.hpp>
16 #include <boost/config/warning_disable.hpp>
17 #include <boost/spirit/include/qi_numeric.hpp>
20 
22  (stan::gm::range, range_)
23  (std::string, name_)
24  (std::vector<stan::gm::expression>, dims_) )
25 
26 BOOST_FUSION_ADAPT_STRUCT(stan::gm::double_var_decl,
27  (stan::gm::range, range_)
28  (std::string, name_)
29  (std::vector<stan::gm::expression>, dims_) )
30 
31 BOOST_FUSION_ADAPT_STRUCT(stan::gm::vector_var_decl,
32  (stan::gm::range, range_)
33  (stan::gm::expression, M_)
34  (std::string, name_)
35  (std::vector<stan::gm::expression>, dims_) )
36 
37 BOOST_FUSION_ADAPT_STRUCT(stan::gm::row_vector_var_decl,
38  (stan::gm::range, range_)
39  (stan::gm::expression, N_)
40  (std::string, name_)
41  (std::vector<stan::gm::expression>, dims_) )
42 
43 BOOST_FUSION_ADAPT_STRUCT(stan::gm::matrix_var_decl,
44  (stan::gm::range, range_)
45  (stan::gm::expression, M_)
46  (stan::gm::expression, N_)
47  (std::string, name_)
48  (std::vector<stan::gm::expression>, dims_) )
49 
50 BOOST_FUSION_ADAPT_STRUCT(stan::gm::unit_vector_var_decl,
51  (stan::gm::expression, K_)
52  (std::string, name_)
53  (std::vector<stan::gm::expression>, dims_) )
54 
55 BOOST_FUSION_ADAPT_STRUCT(stan::gm::simplex_var_decl,
56  (stan::gm::expression, K_)
57  (std::string, name_)
58  (std::vector<stan::gm::expression>, dims_) )
59 
60 BOOST_FUSION_ADAPT_STRUCT(stan::gm::ordered_var_decl,
61  (stan::gm::expression, K_)
62  (std::string, name_)
63  (std::vector<stan::gm::expression>, dims_) )
64 
65 BOOST_FUSION_ADAPT_STRUCT(stan::gm::positive_ordered_var_decl,
66  (stan::gm::expression, K_)
67  (std::string, name_)
68  (std::vector<stan::gm::expression>, dims_) )
69 
70 BOOST_FUSION_ADAPT_STRUCT(stan::gm::cov_matrix_var_decl,
71  (stan::gm::expression, K_)
72  (std::string, name_)
73  (std::vector<stan::gm::expression>, dims_) )
74 
75 BOOST_FUSION_ADAPT_STRUCT(stan::gm::corr_matrix_var_decl,
76  (stan::gm::expression, K_)
77  (std::string, name_)
78  (std::vector<stan::gm::expression>, dims_) )
79 
80 namespace stan {
81 
82  namespace gm {
83 
84  struct validate_no_constraints_vis : public boost::static_visitor<bool> {
85  std::stringstream& error_msgs_;
86  validate_no_constraints_vis(std::stringstream& error_msgs)
87  : error_msgs_(error_msgs) {
88  }
89  bool operator()(const nil& /*x*/) const {
90  error_msgs_ << "nil declarations not allowed";
91  return false; // fail if arises
92  }
93  bool operator()(const int_var_decl& x) const {
94  if (x.range_.has_low() || x.range_.has_high()) {
95  error_msgs_ << "require unconstrained."
96  << " found range constraint." << std::endl;
97  return false;
98  }
99  return true;
100  }
101  bool operator()(const double_var_decl& x) const {
102  if (x.range_.has_low() || x.range_.has_high()) {
103  error_msgs_ << "require unconstrained."
104  << " found range constraint." << std::endl;
105  return false;
106  }
107  return true;
108  }
109  bool operator()(const vector_var_decl& /*x*/) const {
110  return true;
111  }
112  bool operator()(const row_vector_var_decl& /*x*/) const {
113  return true;
114  }
115  bool operator()(const matrix_var_decl& /*x*/) const {
116  return true;
117  }
118  bool operator()(const unit_vector_var_decl& /*x*/) const {
119  error_msgs_ << "require unconstrained variable declaration."
120  << " found unit_vector." << std::endl;
121  return false;
122  }
123  bool operator()(const simplex_var_decl& /*x*/) const {
124  error_msgs_ << "require unconstrained variable declaration."
125  << " found simplex." << std::endl;
126  return false;
127  }
128  bool operator()(const ordered_var_decl& /*x*/) const {
129  error_msgs_ << "require unconstrained variable declaration."
130  << " found ordered." << std::endl;
131  return false;
132  }
133  bool operator()(const positive_ordered_var_decl& /*x*/) const {
134  error_msgs_ << "require unconstrained variable declaration."
135  << " found positive_ordered." << std::endl;
136  return false;
137  }
138  bool operator()(const cov_matrix_var_decl& /*x*/) const {
139  error_msgs_ << "require unconstrained variable declaration."
140  << " found cov_matrix." << std::endl;
141  return false;
142  }
143  bool operator()(const corr_matrix_var_decl& /*x*/) const {
144  error_msgs_ << "require unconstrained variable declaration."
145  << " found corr_matrix." << std::endl;
146  return false;
147  }
148  };
149 
150  struct data_only_expression : public boost::static_visitor<bool> {
151  std::stringstream& error_msgs_;
152  variable_map& var_map_;
153  data_only_expression(std::stringstream& error_msgs,
154  variable_map& var_map)
155  : error_msgs_(error_msgs),
156  var_map_(var_map) {
157  }
158  bool operator()(const nil& /*e*/) const {
159  return true;
160  }
161  bool operator()(const int_literal& /*x*/) const {
162  return true;
163  }
164  bool operator()(const double_literal& /*x*/) const {
165  return true;
166  }
167  bool operator()(const array_literal& x) const {
168  for (size_t i = 0; i < x.args_.size(); ++i)
169  if (!boost::apply_visitor(*this,x.args_[i].expr_))
170  return false;
171  return true;
172  }
173  bool operator()(const variable& x) const {
174  var_origin origin = var_map_.get_origin(x.name_);
175  bool is_data = (origin == data_origin) || (origin == transformed_data_origin);
176  if (!is_data) {
177  error_msgs_ << "non-data variables not allowed in dimension declarations."
178  << std::endl
179  << " found variable=" << x.name_
180  << "; declared in block=";
181  print_var_origin(error_msgs_,origin);
182  error_msgs_ << std::endl;
183  }
184  return is_data;
185  }
186  bool operator()(const fun& x) const {
187  for (size_t i = 0; i < x.args_.size(); ++i)
188  if (!boost::apply_visitor(*this,x.args_[i].expr_))
189  return false;
190  return true;
191  }
192  bool operator()(const index_op& x) const {
193  if (!boost::apply_visitor(*this,x.expr_.expr_))
194  return false;
195  for (size_t i = 0; i < x.dimss_.size(); ++i)
196  for (size_t j = 0; j < x.dimss_[i].size(); ++j)
197  if (!boost::apply_visitor(*this,x.dimss_[i][j].expr_))
198  return false;
199  return true;
200  }
201  bool operator()(const binary_op& x) const {
202  return boost::apply_visitor(*this,x.left.expr_)
203  && boost::apply_visitor(*this,x.right.expr_);
204  }
205  bool operator()(const unary_op& x) const {
206  return boost::apply_visitor(*this,x.subject.expr_);
207  }
208  };
209 
210 
211  struct add_var {
212  template <typename T1, typename T2, typename T3, typename T4, typename T5>
213  struct result { typedef T1 type; };
214  // each type derived from base_var_decl gets own instance
215  template <typename T>
216  T operator()(const T& var_decl,
217  variable_map& vm,
218  bool& pass,
219  const var_origin& vo,
220  std::ostream& error_msgs) const {
221  if (vm.exists(var_decl.name_)) {
222  // variable already exists
223  pass = false;
224  error_msgs << "variable already declared, name="
225  << var_decl.name_
226  << std::endl;
227  return var_decl;
228  }
230  && var_decl.base_type_ == INT_T) {
231  pass = false;
232  error_msgs << "integer parameters or transformed parameters are not allowed; "
233  << " found declared type int, parameter name=" << var_decl.name_
234  << std::endl;
235  return var_decl;
236  }
237  pass = true; // probably don't need to set true
238  vm.add(var_decl.name_,var_decl,vo);
239  return var_decl;
240  }
241  };
242  boost::phoenix::function<add_var> add_var_f;
243 
244 
245  struct validate_decl_constraints {
246  template <typename T1, typename T2, typename T3, typename T4>
247  struct result { typedef bool type; };
248 
249  bool operator()(const bool& allow_constraints,
250  const bool& declaration_ok,
251  const var_decl& var_decl,
252  std::stringstream& error_msgs) const {
253  if (!declaration_ok) {
254  error_msgs << "Problem with declaration." << std::endl;
255  return false; // short-circuits test of constraints
256  }
257  if (allow_constraints)
258  return true;
259  validate_no_constraints_vis vis(error_msgs);
260  bool constraints_ok = boost::apply_visitor(vis,var_decl.decl_);
261  return constraints_ok;
262  }
263  };
264  boost::phoenix::function<validate_decl_constraints>
265  validate_decl_constraints_f;
266 
267  struct validate_identifier {
268  std::set<std::string> reserved_word_set_;
269 
270  template <typename T1, typename T2>
271  struct result { typedef bool type; };
272 
273  void reserve(const std::string& w) {
274  reserved_word_set_.insert(w);
275  }
276 
277  validate_identifier() {
278  reserve("for");
279  reserve("in");
280  reserve("while");
281  reserve("repeat");
282  reserve("until");
283  reserve("if");
284  reserve("then");
285  reserve("else");
286  reserve("true");
287  reserve("false");
288 
289  reserve("int");
290  reserve("real");
291  reserve("vector");
292  reserve("unit_vector");
293  reserve("simplex");
294  reserve("ordered");
295  reserve("positive_ordered");
296  reserve("row_vector");
297  reserve("matrix");
298  reserve("corr_matrix");
299  reserve("cov_matrix");
300 
301 
302  reserve("model");
303  reserve("data");
304  reserve("parameters");
305  reserve("quantities");
306  reserve("transformed");
307  reserve("generated");
308 
309 
310  reserve("alignas");
311  reserve("alignof");
312  reserve("and");
313  reserve("and_eq");
314  reserve("asm");
315  reserve("auto");
316  reserve("bitand");
317  reserve("bitor");
318  reserve("bool");
319  reserve("break");
320  reserve("case");
321  reserve("catch");
322  reserve("char");
323  reserve("char16_t");
324  reserve("char32_t");
325  reserve("class");
326  reserve("compl");
327  reserve("const");
328  reserve("constexpr");
329  reserve("const_cast");
330  reserve("continue");
331  reserve("decltype");
332  reserve("default");
333  reserve("delete");
334  reserve("do");
335  reserve("double");
336  reserve("dynamic_cast");
337  reserve("else");
338  reserve("enum");
339  reserve("explicit");
340  reserve("export");
341  reserve("extern");
342  reserve("false");
343  reserve("float");
344  reserve("for");
345  reserve("friend");
346  reserve("goto");
347  reserve("if");
348  reserve("inline");
349  reserve("int");
350  reserve("long");
351  reserve("mutable");
352  reserve("namespace");
353  reserve("new");
354  reserve("noexcept");
355  reserve("not");
356  reserve("not_eq");
357  reserve("nullptr");
358  reserve("operator");
359  reserve("or");
360  reserve("or_eq");
361  reserve("private");
362  reserve("protected");
363  reserve("public");
364  reserve("register");
365  reserve("reinterpret_cast");
366  reserve("return");
367  reserve("short");
368  reserve("signed");
369  reserve("sizeof");
370  reserve("static");
371  reserve("static_assert");
372  reserve("static_cast");
373  reserve("struct");
374  reserve("switch");
375  reserve("template");
376  reserve("this");
377  reserve("thread_local");
378  reserve("throw");
379  reserve("true");
380  reserve("try");
381  reserve("typedef");
382  reserve("typeid");
383  reserve("typename");
384  reserve("union");
385  reserve("unsigned");
386  reserve("using");
387  reserve("virtual");
388  reserve("void");
389  reserve("volatile");
390  reserve("wchar_t");
391  reserve("while");
392  reserve("xor");
393  reserve("xor_eq");
394  }
395 
396  bool operator()(const std::string& identifier,
397  std::stringstream& error_msgs) const {
398  int len = identifier.size();
399  if (len >= 2
400  && identifier[len-1] == '_'
401  && identifier[len-2] == '_') {
402  error_msgs << "variable identifier (name) cannot end in double underscore (__)"
403  << "; found identifer=" << identifier;
404  return false;
405  }
406  if (reserved_word_set_.find(identifier) != reserved_word_set_.end()) {
407  error_msgs << "variable identifier (name) cannot be reserved word"
408  << "; found identifier=" << identifier;
409  return false;
410  }
411  return true;
412  }
413  };
414  boost::phoenix::function<validate_identifier> validate_identifier_f;
415 
416  struct empty_range {
417  template <typename T1>
418  struct result { typedef range type; };
419  range operator()(std::stringstream& /*error_msgs*/) const {
420  return range();
421  }
422  };
423  boost::phoenix::function<empty_range> empty_range_f;
424 
425  struct validate_int_expr {
426  template <typename T1, typename T2>
427  struct result { typedef bool type; };
428 
429  bool operator()(const expression& expr,
430  std::stringstream& error_msgs) const {
431  if (!expr.expression_type().is_primitive_int()) {
432  error_msgs << "expression denoting integer required; found type="
433  << expr.expression_type() << std::endl;
434  return false;
435  }
436  return true;
437  }
438  };
439  boost::phoenix::function<validate_int_expr> validate_int_expr_f;
440 
441  struct set_int_range_lower {
442  template <typename T1, typename T2, typename T3>
443  struct result { typedef bool type; };
444  bool operator()(range& range,
445  const expression& expr,
446  std::stringstream& error_msgs) const {
447  range.low_ = expr;
448  validate_int_expr validator;
449  return validator(expr,error_msgs);
450  }
451  };
452  boost::phoenix::function<set_int_range_lower> set_int_range_lower_f;
453 
454  struct set_int_range_upper {
455  template <typename T1, typename T2, typename T3>
456  struct result { typedef bool type; };
457  bool operator()(range& range,
458  const expression& expr,
459  std::stringstream& error_msgs) const {
460  range.high_ = expr;
461  validate_int_expr validator;
462  return validator(expr,error_msgs);
463  }
464  };
465  boost::phoenix::function<set_int_range_upper> set_int_range_upper_f;
466 
467 
468 
469  struct validate_int_data_expr {
470  template <typename T1, typename T2, typename T3>
471  struct result { typedef bool type; };
472 
473  bool operator()(const expression& expr,
474  variable_map& var_map,
475  std::stringstream& error_msgs) const {
476  if (!expr.expression_type().is_primitive_int()) {
477  error_msgs << "dimension declaration requires expression denoting integer;"
478  << " found type="
479  << expr.expression_type()
480  << std::endl;
481  return false;
482  }
483  data_only_expression vis(error_msgs,var_map);
484  bool only_data_dimensions = boost::apply_visitor(vis,expr.expr_);
485  return only_data_dimensions;
486  }
487  };
488  boost::phoenix::function<validate_int_data_expr> validate_int_data_expr_f;
489 
490  struct validate_double_expr {
491  template <typename T1, typename T2>
492  struct result { typedef bool type; };
493 
494  bool operator()(const expression& expr,
495  std::stringstream& error_msgs) const {
496  if (!expr.expression_type().is_primitive_double()
497  && !expr.expression_type().is_primitive_int()) {
498  error_msgs << "expression denoting double required; found type="
499  << expr.expression_type() << std::endl;
500  return false;
501  }
502  return true;
503  }
504  };
505  boost::phoenix::function<validate_double_expr> validate_double_expr_f;
506 
507 
508  struct set_double_range_lower {
509  template <typename T1, typename T2, typename T3>
510  struct result { typedef bool type; };
511  bool operator()(range& range,
512  const expression& expr,
513  std::stringstream& error_msgs) const {
514  range.low_ = expr;
515  validate_double_expr validator;
516  return validator(expr,error_msgs);
517  }
518  };
519  boost::phoenix::function<set_double_range_lower> set_double_range_lower_f;
520 
521  struct set_double_range_upper {
522  template <typename T1, typename T2, typename T3>
523  struct result { typedef bool type; };
524  bool operator()(range& range,
525  const expression& expr,
526  std::stringstream& error_msgs) const {
527  range.high_ = expr;
528  validate_double_expr validator;
529  return validator(expr,error_msgs);
530  }
531  };
532  boost::phoenix::function<set_double_range_upper> set_double_range_upper_f;
533 
534 
535  template <typename Iterator>
536  var_decls_grammar<Iterator>::var_decls_grammar(variable_map& var_map,
537  std::stringstream& error_msgs)
538  : var_decls_grammar::base_type(var_decls_r),
539  var_map_(var_map),
540  error_msgs_(error_msgs),
541  expression_g(var_map,error_msgs),
542  expression07_g(var_map,error_msgs,false)
543  {
544 
545  using boost::spirit::qi::_1;
546  using boost::spirit::qi::_3;
547  using boost::spirit::qi::char_;
548  using boost::spirit::qi::eps;
549  using boost::spirit::qi::lexeme;
550  using boost::spirit::qi::lit;
551  using boost::spirit::qi::no_skip;
552  using boost::spirit::qi::_pass;
553  using boost::spirit::qi::_val;
554  using boost::spirit::qi::labels::_a;
555  using boost::spirit::qi::labels::_r1;
556  using boost::spirit::qi::labels::_r2;
557 
558  var_decls_r.name("variable declarations");
559  var_decls_r
560  %= *var_decl_r(_r1,_r2);
561 
562  // _a = error state local,
563  // _r1 constraints allowed inherited,
564  // _r2 var_origin
565  var_decl_r.name("variable declaration");
566  var_decl_r
567  %= (int_decl_r(_r2)
568  [_val = add_var_f(_1,boost::phoenix::ref(var_map_),_a,_r2,
569  boost::phoenix::ref(error_msgs))]
570  | double_decl_r(_r2)
571  [_val = add_var_f(_1,boost::phoenix::ref(var_map_),_a,_r2,
572  boost::phoenix::ref(error_msgs_))]
573  | vector_decl_r(_r2)
574  [_val = add_var_f(_1,boost::phoenix::ref(var_map_),_a,_r2,
575  boost::phoenix::ref(error_msgs_))]
576  | row_vector_decl_r(_r2)
577  [_val = add_var_f(_1,boost::phoenix::ref(var_map_),_a,_r2,
578  boost::phoenix::ref(error_msgs_))]
579  | matrix_decl_r(_r2)
580  [_val = add_var_f(_1,boost::phoenix::ref(var_map_),_a,_r2,
581  boost::phoenix::ref(error_msgs_))]
582  | unit_vector_decl_r(_r2)
583  [_val = add_var_f(_1,boost::phoenix::ref(var_map_),_a,_r2,
584  boost::phoenix::ref(error_msgs_))]
585  | simplex_decl_r(_r2)
586  [_val = add_var_f(_1,boost::phoenix::ref(var_map_),_a,_r2,
587  boost::phoenix::ref(error_msgs_))]
588  | ordered_decl_r(_r2)
589  [_val = add_var_f(_1,boost::phoenix::ref(var_map_),_a,_r2,
590  boost::phoenix::ref(error_msgs_))]
591  | positive_ordered_decl_r(_r2)
592  [_val = add_var_f(_1,boost::phoenix::ref(var_map_),_a,_r2,
593  boost::phoenix::ref(error_msgs_))]
594  | corr_matrix_decl_r(_r2)
595  [_val = add_var_f(_1,boost::phoenix::ref(var_map_),_a,_r2,
596  boost::phoenix::ref(error_msgs_))]
597  | cov_matrix_decl_r(_r2)
598  [_val = add_var_f(_1,boost::phoenix::ref(var_map_),_a,_r2,
599  boost::phoenix::ref(error_msgs_))]
600  )
601  > eps
602  [_pass
603  = validate_decl_constraints_f(_r1,_a,_val,
604  boost::phoenix::ref(error_msgs_))]
605  ;
606 
607  int_decl_r.name("integer declaration");
608  int_decl_r
609  %= lit("int")
610  >> no_skip[!char_("a-zA-Z0-9_")]
611  > -range_brackets_int_r(_r1)
612  // >> (lit(' ') | lit('\n') | lit('\t') | lit('\r'))
613  > identifier_r
614  > opt_dims_r(_r1)
615  > lit(';');
616 
617  double_decl_r.name("real declaration");
618  double_decl_r
619  %= lit("real")
620  >> no_skip[!char_("a-zA-Z0-9_")]
621  > -range_brackets_double_r(_r1)
622  > identifier_r
623  > opt_dims_r(_r1)
624  > lit(';');
625 
626  vector_decl_r.name("vector declaration");
627  vector_decl_r
628  %= lit("vector")
629  > -range_brackets_double_r(_r1)
630  > lit('[')
631  > expression_g(_r1)
632  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))]
633  > lit(']')
634  > identifier_r
635  > opt_dims_r(_r1)
636  > lit(';');
637 
638  row_vector_decl_r.name("row vector declaration");
639  row_vector_decl_r
640  %= lit("row_vector")
641  > -range_brackets_double_r(_r1)
642  > lit('[')
643  > expression_g(_r1)
644  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))]
645  > lit(']')
646  > identifier_r
647  > opt_dims_r(_r1)
648  > lit(';');
649 
650  matrix_decl_r.name("matrix declaration");
651  matrix_decl_r
652  %= lit("matrix")
653  > -range_brackets_double_r(_r1)
654  > lit('[')
655  > expression_g(_r1)
656  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))]
657  > lit(',')
658  > expression_g(_r1)
659  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))]
660  > lit(']')
661  > identifier_r
662  > opt_dims_r(_r1)
663  > lit(';');
664 
665  unit_vector_decl_r.name("unit_vector declaration");
666  unit_vector_decl_r
667  %= lit("unit_vector")
668  > lit('[')
669  > expression_g(_r1)
670  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))]
671  > lit(']')
672  > identifier_r
673  > opt_dims_r(_r1)
674  > lit(';');
675 
676  simplex_decl_r.name("simplex declaration");
677  simplex_decl_r
678  %= lit("simplex")
679  > lit('[')
680  > expression_g(_r1)
681  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))]
682  > lit(']')
683  > identifier_r
684  > opt_dims_r(_r1)
685  > lit(';');
686 
687  ordered_decl_r.name("ordered declaration");
688  ordered_decl_r
689  %= lit("ordered")
690  > lit('[')
691  > expression_g(_r1)
692  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))]
693  > lit(']')
694  > identifier_r
695  > opt_dims_r(_r1)
696  > lit(';');
697 
698  positive_ordered_decl_r.name("positive_ordered declaration");
699  positive_ordered_decl_r
700  %= lit("positive_ordered")
701  > lit('[')
702  > expression_g(_r1)
703  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))]
704  > lit(']')
705  > identifier_r
706  > opt_dims_r(_r1)
707  > lit(';');
708 
709  corr_matrix_decl_r.name("correlation matrix declaration");
710  corr_matrix_decl_r
711  %= lit("corr_matrix")
712  > lit('[')
713  > expression_g(_r1)
714  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))]
715  > lit(']')
716  > identifier_r
717  > opt_dims_r(_r1)
718  > lit(';');
719 
720  cov_matrix_decl_r.name("covariance matrix declaration");
721  cov_matrix_decl_r
722  %= lit("cov_matrix")
723  > lit('[')
724  > expression_g(_r1)
725  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))]
726  > lit(']')
727  > identifier_r
728  > opt_dims_r(_r1)
729  > lit(';');
730 
731  opt_dims_r.name("array dimensions (optional)");
732  opt_dims_r
733  %= - dims_r(_r1);
734 
735  dims_r.name("array dimensions");
736  dims_r
737  %= lit('[')
738  > (expression_g(_r1)
739  [_pass = validate_int_data_expr_f(_1,
740  boost::phoenix::ref(var_map_),
741  boost::phoenix::ref(error_msgs_))]
742  % ',')
743  > lit(']')
744  ;
745 
746  range_brackets_int_r.name("integer range expression pair, brackets");
747  range_brackets_int_r
748  = lit('<') [_val = empty_range_f(boost::phoenix::ref(error_msgs_))]
749  >> (
750  ( (lit("lower")
751  >> lit('=')
752  >> expression07_g(_r1)
753  [ _pass = set_int_range_lower_f(_val,_1,
754  boost::phoenix::ref(error_msgs_)) ])
755  >> -( lit(',')
756  >> lit("upper")
757  >> lit('=')
758  >> expression07_g(_r1)
759  [ _pass = set_int_range_upper_f(_val,_1,
760  boost::phoenix::ref(error_msgs_)) ] ) )
761  |
762  ( lit("upper")
763  >> lit('=')
764  >> expression07_g(_r1)
765  [ _pass = set_int_range_upper_f(_val,_1,
766  boost::phoenix::ref(error_msgs_)) ])
767  )
768  >> lit('>');
769 
770  range_brackets_double_r.name("real range expression pair, brackets");
771  range_brackets_double_r
772  = lit('<') [_val = empty_range_f(boost::phoenix::ref(error_msgs_))]
773  > (
774  ( (lit("lower")
775  > lit('=')
776  > expression07_g(_r1)
777  [ _pass = set_double_range_lower_f(_val,_1,
778  boost::phoenix::ref(error_msgs_)) ])
779  > -( lit(',')
780  > lit("upper")
781  > lit('=')
782  > expression07_g(_r1)
783  [ _pass = set_double_range_upper_f(_val,_1,
784  boost::phoenix::ref(error_msgs_)) ] ) )
785  |
786  ( lit("upper")
787  > lit('=')
788  > expression07_g(_r1)
789  [ _pass = set_double_range_upper_f(_val,_1,
790  boost::phoenix::ref(error_msgs_)) ])
791  )
792  > lit('>');
793 
794  identifier_r.name("identifier");
795  identifier_r
796  %= identifier_name_r
797  [_pass = validate_identifier_f(_val,boost::phoenix::ref(error_msgs_))]
798  ;
799 
800  identifier_name_r.name("identifier subrule");
801  identifier_name_r
802  %= lexeme[char_("a-zA-Z")
803  >> *char_("a-zA-Z0-9_.")]
804  ;
805 
806 
807  range_r.name("range expression pair, colon");
808  range_r
809  %= expression_g(_r1)
810  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))]
811  >> lit(':')
812  >> expression_g(_r1)
813  [_pass = validate_int_expr_f(_1,boost::phoenix::ref(error_msgs_))];
814 
815  }
816 
817 
818  }
819 }
820 #endif

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