47 #include <Teuchos_MathExpr.hpp> 
   55   : Teuchos::Reader(Teuchos::MathExpr::ask_reader_tables()) {
 
   65     case Teuchos::MathExpr::TOK_NAME: {
 
   66       std::string& 
result = Teuchos::make_any_ref<std::string>(result_any);
 
   70     case Teuchos::MathExpr::TOK_CONST: {
 
   80     case Teuchos::MathExpr::PROD_PROGRAM: {
 
   81       swap(result, rhs.at(1));
 
   84     case Teuchos::MathExpr::PROD_NO_STATEMENTS:
 
   85     case Teuchos::MathExpr::PROD_NO_EXPR:
 
   86     case Teuchos::MathExpr::PROD_NEXT_STATEMENT: {
 
   89     case Teuchos::MathExpr::PROD_ASSIGN: {
 
   90       std::string 
const& name = Teuchos::any_ref_cast<std::string>(rhs.at(0));
 
   94     case Teuchos::MathExpr::PROD_YES_EXPR:
 
   95     case Teuchos::MathExpr::PROD_EXPR:
 
   96     case Teuchos::MathExpr::PROD_TERNARY_DECAY:
 
   97     case Teuchos::MathExpr::PROD_OR_DECAY:
 
   98     case Teuchos::MathExpr::PROD_AND_DECAY:
 
   99     case Teuchos::MathExpr::PROD_ADD_SUB_DECAY:
 
  100     case Teuchos::MathExpr::PROD_MUL_DIV_DECAY:
 
  101     case Teuchos::MathExpr::PROD_POW_DECAY:
 
  102     case Teuchos::MathExpr::PROD_NEG_DECAY:
 
  103     case Teuchos::MathExpr::PROD_SOME_ARGS:
 
  104       swap(result, rhs.at(0));
 
  106     case Teuchos::MathExpr::PROD_TERNARY:
 
  107       this->
ternary_op(result, rhs.at(0), rhs.at(3), rhs.at(6));
 
  109     case Teuchos::MathExpr::PROD_OR:
 
  112     case Teuchos::MathExpr::PROD_AND:
 
  115     case Teuchos::MathExpr::PROD_GT:
 
  118     case Teuchos::MathExpr::PROD_LT:
 
  121     case Teuchos::MathExpr::PROD_GEQ:
 
  124     case Teuchos::MathExpr::PROD_LEQ:
 
  127     case Teuchos::MathExpr::PROD_EQ:
 
  130     case Teuchos::MathExpr::PROD_BOOL_PARENS:
 
  131       swap(result, rhs.at(2));
 
  133     case Teuchos::MathExpr::PROD_ADD:
 
  136     case Teuchos::MathExpr::PROD_SUB:
 
  139     case Teuchos::MathExpr::PROD_MUL:
 
  142     case Teuchos::MathExpr::PROD_DIV:
 
  145     case Teuchos::MathExpr::PROD_POW:
 
  148     case Teuchos::MathExpr::PROD_CALL: {
 
  149       std::string 
const& name = Teuchos::any_ref_cast<std::string>(rhs.at(0));
 
  152           "symbol \"" << name << 
"\" being called doesn't exist!");
 
  154       std::vector<Teuchos::any>& args = Teuchos::any_ref_cast<std::vector<Teuchos::any>>(rhs.at(4));
 
  155       func(name, result, args);
 
  158     case Teuchos::MathExpr::PROD_NO_ARGS: {
 
  159       result = std::vector<Teuchos::any>{};
 
  162     case Teuchos::MathExpr::PROD_FIRST_ARG: {
 
  163       std::vector<Teuchos::any>& args = Teuchos::make_any_ref<std::vector<Teuchos::any>>(
result);
 
  165       swap(args.back(), rhs.at(0));
 
  168     case Teuchos::MathExpr::PROD_NEXT_ARG: {
 
  169       swap(result, rhs.at(0));
 
  170       std::vector<Teuchos::any>& args = Teuchos::any_ref_cast<std::vector<Teuchos::any>>(
result);
 
  172       swap(args.back(), rhs.at(3));
 
  175     case Teuchos::MathExpr::PROD_NEG:
 
  176       this->
neg_op(result, rhs.at(2));
 
  178     case Teuchos::MathExpr::PROD_VAL_PARENS:
 
  179       swap(result, rhs.at(2));
 
  181     case Teuchos::MathExpr::PROD_CONST:
 
  182       swap(result, rhs.at(0));
 
  184     case Teuchos::MathExpr::PROD_VAR:
 
  185       std::string 
const& name = Teuchos::any_ref_cast<std::string>(rhs.at(0));
 
  188           "symbol " << name << 
" being referenced doesn't exist!");
 
  197   this->
inspect_arg(cond, cond_is_many, cond_is_bool);
 
  199       "Ternary condition is not of boolean type!");
 
  205       "Boolean values in ternary operator not yet supported");
 
  207     auto cond_value = Teuchos::any_cast<Kokkos::View<bool const>>(cond);
 
  208     auto host_cond_value = Kokkos::create_mirror_view(cond_value);
 
  209     Kokkos::deep_copy(host_cond_value, cond_value);
 
  210     if (host_cond_value()) {
 
  216     if (!is_many[0] && !is_many[1]) {
 
  218     } 
else if (!is_many[0] && is_many[1]) {
 
  220     } 
else if (is_many[0] && !is_many[1]) {
 
  222     } 
else if (is_many[0] && is_many[1]) {
 
  253       "Left argument to '" << 
get_op_syntax(code) << 
"' is " << (is_bool[0] ? 
"" : 
"not") << 
" boolean!");
 
  255       "Right argument to '" << 
get_op_syntax(code) << 
"' is " << (is_bool[0] ? 
"" : 
"not") << 
" boolean!");
 
  256   if (!is_many[0] && !is_many[1]) {
 
  258   } 
else if (!is_many[0] && is_many[1]) {
 
  260   } 
else if (is_many[0] && !is_many[1]) {
 
  262   } 
else if (is_many[0] && is_many[1]) {
 
  272       "Can't negate a boolean");
 
virtual void many_many_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right)=0
 
virtual void make_constant(Teuchos::any &result, double const &value)=0
 
BinaryOpCode
Denotes the native binary operators in the Teuchos::MathExpr language. 
 
virtual void many_many_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right)=0
 
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
 
virtual void single_single_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right)=0
 
std::function< void(std::string const &name, Teuchos::any &, std::vector< Teuchos::any > &rhs)> Function
The type of user-defined functions which are callable in the math language. 
 
virtual void many_neg_op(Teuchos::any &result, Teuchos::any &right)=0
 
virtual void inspect_arg(Teuchos::any const &arg, bool &is_many, bool &is_bool)=0
 
void ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right)
Executes the ternary operator, e.g. (a > b) ? a : b. 
 
void at_reduce(Teuchos::any &result, int prod, std::vector< Teuchos::any > &rhs) override
Called at every reduced production in the math language. 
 
void binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right)
Executes a binary operator. 
 
void set(std::string const &name, Function const &value)
Registers an EvalBase::Function, binding it to a name and making it callable. 
 
PHX::MDField< ScalarT, panzer::Cell, panzer::IP > result
A field that will be used to build up the result of the integral we're performing. 
 
virtual void single_single_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right)=0
 
virtual void many_single_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right)=0
 
std::map< std::string, Teuchos::any > symbol_map
Stores all current symbols including variables and functions. 
 
static const char * get_op_syntax(BinaryOpCode code)
 
virtual void single_neg_op(Teuchos::any &result, Teuchos::any &right)=0
 
virtual void single_many_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right)=0
 
void neg_op(Teuchos::any &result, Teuchos::any &right)
Executes the only native unary operator in the math language, numeric negation via a minus sign...
 
void at_shift(Teuchos::any &result, int token, std::string &text) override
Called at every parsed token in the math language. 
 
virtual void many_single_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right)=0
 
virtual void single_many_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right)=0