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

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