当前位置: 首页>>代码示例>>C++>>正文


C++ Evaluator类代码示例

本文整理汇总了C++中Evaluator的典型用法代码示例。如果您正苦于以下问题:C++ Evaluator类的具体用法?C++ Evaluator怎么用?C++ Evaluator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Evaluator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: theFormRange

inline bool Type_::GiveTerm(Evaluator & theEvaluator) {
	if (
		this->thisExpression.IsEmpty()
	) {
		return false;
	}
	Expression::FormRange<Form> theFormRange(this->thisExpression);
	assert(theFormRange);
	if (
		theFormRange->GetOperator().IsEmpty()
	) {
		Operand theOperand;
		{
			Form::OperandRange<Operand> theOperandRange(*theFormRange);
			assert(theOperandRange);
			theOperand.Swap(*theOperandRange);
		}
		this->thisExpression.FrontPopTerm();
		theEvaluator.TakeOperand(
			*this,
			theOperand
		);
	} else {
		Operator theOperator;
		this->thisExpression.FrontGiveTerm(theOperator);
		theEvaluator.TakeOperator(
			*this,
			theOperator
		);
	}
	return true;
}
开发者ID:sparist,项目名称:Om,代码行数:32,代码来源:evaluation.cpp

示例2: ui

void ui()
{
    Evaluator eval;
    std::string input;

    std::cout << "\ntype an expression, \"exit\" to end\n";

    while (true)
    {
        std::cout << ">>> ";
        std::getline(std::cin, input);

        if (input[0] == 'e' || input[0] == 'E')
            break;

        try
        {
            std::cout << eval.eval(input) << std::endl;
        }
        catch (std::invalid_argument err)
        {
            std::cout << "Error: " << err.what() << std::endl;
        }
    }
}
开发者ID:beauxq,项目名称:expressions,代码行数:25,代码来源:main.cpp

示例3: main

int main()
{
		Evaluator eval;
		vector<string> expression = { "1+2*3","2+2^2*3" ,"1==2", "1+3 > 2", "(4>=4) && 0", "(1+2)*3" }; //<--expressions we wish to evaluate go here
		vector<string>::iterator exprItr;

		for (exprItr = expression.begin();
		exprItr != expression.end();
			exprItr++)
		{
			try
			{
				int result = eval.eval(*exprItr);

				cout << eval.infix_expression.c_str() << " = " << result << endl << endl;
			}
			catch (Syntax_Error e)
			{
				cout << eval.infix_expression.c_str() << endl << e.what() << " " << "@ char: " << eval.position << endl << endl;
			}
		}

		system("pause");
	return 0;
}
开发者ID:troglobyter,项目名称:Infix_Expression_Eval,代码行数:25,代码来源:main.cpp

示例4: getDelegateEvaluators

bool FieldmlSession::getDelegateEvaluators( FmlObjectHandle handle, vector<FmlObjectHandle> &stack, set<FmlObjectHandle> &delegates )
{
    set<FmlObjectHandle> evaluators;
    
    if( handle == FML_INVALID_HANDLE )
    {
        //Convenience so that callers don't have to check
        return true;
    }
    
    if( FmlUtil::contains( stack, handle ) )
    {
        //Recursive dependency!
        return false;
    }
    
    //TODO: Figure out why this works even though there's no popping happening.
    stack.push_back( handle );
    
    Evaluator *evaluator = Evaluator::checkedCast( this, handle );
    
    if( evaluator != NULL )
    {
        if( evaluator->addDelegates( evaluators ) )
        {
            if( !getDelegateEvaluators( evaluators, stack, delegates ) )
            {
                return false;
            }
        }
    }
    
    return true;
}
开发者ID:b3c,项目名称:FieldML-API,代码行数:34,代码来源:FieldmlSession.cpp

示例5:

/*static*/ void
Thread::ThreadProc(void* pvoid)
{
  // Create an evaluator
  Evaluator eval;

  // Run code
  eval.Eval((Object*)pvoid);
}
开发者ID:jjfahner,项目名称:cscript,代码行数:9,代码来源:thread.cpp

示例6: main

int main(int argc, char** argv) {
  std::string expr = "w x z - +"; 
  Evaluator* sentence = new Evaluator(expr); 
  std::map<std::string, Expr*> variables = new std::map<std::string, Expr*>(); 
  variables.put("w", new Number(5)); 
  variables.put("x", new Number(10)); 
  variables.put("z", new Number(32)); 
  int result = sentence->interpret(variables); 

  std::cout << "Computation result: " << result << std::endl; 
}
开发者ID:JavaZhangYin,项目名称:coding,代码行数:11,代码来源:Interpreter.cpp

示例7: evaluate

int evaluate(T& src) {
  Evaluator e;
  try {
    e.eval(src);
    return 0;
  } catch (const Error& e) {
    std::cerr << DASHES << std::endl;
    std::cerr << "Unhandled exception!" << std::endl << std::endl;
    std::cerr << e.what() << std::endl;
    std::cerr << DASHES << std::endl;
    return 1;
  }
}
开发者ID:znation,项目名称:simplex,代码行数:13,代码来源:main.cpp

示例8: Java_com_starlon_libscriptable_UtilsEvaluator_evaluate

JNIEXPORT jstring JNICALL Java_com_starlon_libscriptable_UtilsEvaluator_evaluate(
    JNIEnv *env, jclass clazz, jobject obj, jstring str)
{
    Evaluator *eval = getObjectFromCPtr<Evaluator *>( env, obj );

    jboolean isCopy;
    const char * _str = env->GetStringUTFChars(str, &isCopy);

    std::string val = eval->Eval((std::string)_str);

    env->ReleaseStringUTFChars(str, _str);
    return env->NewStringUTF(val.c_str());
}
开发者ID:Starlon,项目名称:FroyVisuals-old,代码行数:13,代码来源:Evaluator.cpp

示例9: BeginSearch

int32 SearchAlgorithm::BeginSearch(int32 a_turn, uint32 a_depthRemain, Board &a_board, Evaluator &a_evaluator, uint32 &a_countNodes)
{
    m_bestMoves.clear();
    m_bestMoves.resize(MAX_SEARCH_DEPTH);

    a_board.ClearTakenChesses();
    a_evaluator.Evaluate(a_board);
    m_transpositionTable->InitByBoard(a_turn, a_board);

    m_currentDepth = 0;

    int32 score = Search(a_turn, a_depthRemain, a_board, a_evaluator, a_countNodes);

    if (!GetBestMoves().empty())
    {
        MovePos bestMove = *(GetBestMoves().begin());
        GetTranspositionTable()->ChangeKeyByMoving(a_board.GetTypeAt(bestMove.from), bestMove.from, a_board.GetTypeAt(bestMove.to), bestMove.to);
        m_boardLog.push_back(GetTranspositionTable()->GetCurrentKey());
        GetTranspositionTable()->ChangeKeyByMoving(a_board.GetTypeAt(bestMove.from), bestMove.from, a_board.GetTypeAt(bestMove.to), bestMove.to);
    }

    ++m_currentPlay;

    return score;
}
开发者ID:conradhuang,项目名称:Clumsy,代码行数:25,代码来源:SearchAlgorithm.cpp

示例10: center

// This method is called by the Solver object at every iteration.
bool RandomSearcher::search(const unsigned int max_dim,
			    const double delta, const double * poll_center,
			    std::vector<AugmentedPoint *> & list_of_points,
			    Evaluator & eval)
{
  if (display_factor >= 3)
    {
      cout << "\nStart of random search: " << search_pts << " points, ";
      cout << "delta = "<< delta << "\n-----------------------\nPoll center (";
      for (unsigned int i = 0; i < max_dim - 1; i++)
	cout << poll_center[i] << "  ";
      cout << poll_center[max_dim - 1] << ")\n";
      cout << "\nCurrent best iterate: ";
      eval.showIncumbent();
      cout << "\n";
    }
  // 
  createArrays(max_dim, delta, poll_center);
  /* This function call returns the number of points the random search will
     generate. */
  double nb_of_points = generateHowManyPts(max_dim);
  /* This function creates the list of points that will be sent to 'Evaluator',
     from the list of shuffled points. */
  fillTheList(max_dim, delta, poll_center, nb_of_points, list_of_points);
  // The 'complete_search' variable is returned.
  return (complete_search);
}
开发者ID:tclose,项目名称:Neurofitter,代码行数:28,代码来源:randomsearcher.cpp

示例11: main

int main(int argc, const char** argv) {
  std::unique_ptr<Expr> c1(new Constant(1.1));
  std::unique_ptr<Expr> c2(new Constant(2.2));

  std::unique_ptr<Expr> p1(new BinaryPlus(*c1, *c2));
  std::unique_ptr<Expr> p2(new BinaryPlus(*p1, *c2));

  Stringifier s;
  p2->Accept(&s);
  std::cout << s.GetStringForExpr(*p2) << "\n";

  Evaluator e;
  p2->Accept(&e);
  std::cout << e.GetValueForExpr(*p2) << "\n";

  return 0;
}
开发者ID:AssaultKoder95,项目名称:code-for-blog,代码行数:17,代码来源:visitor-dispatch-in-data.cpp

示例12: get_length

Expr*
get_length(Layout_decl const* layout)
{
  Evaluator eval;

  Expr* e = 0;
  for (Decl* d : layout->fields()) {
    Type const* t1 = d->type();

    // If member is constant, just add in the constant value
    if (has_constant_length(t1))
      e = add(e, make_int(precision(t1)));

    // Otherwise, we have to form a call to the function
    // that would compute this type.
    else {
      // FIXME: Do this right!
      throw std::runtime_error("unimplemented dynamic length calc.");
      e = add(e, zero());
    }
  }


  // Compute ceil(e / 8).
  Expr* b = make_int(8); // bits per byte
  Expr* r = div(sub(add(e, b), one()), b);

  // Try folding the result. If it works, good. If not,
  // just return the previously computed expression.
  //
  // TODO: Maximally reduce the expression so that we only
  // add the constant bits to the non-constant bits. Since
  // addition is associative and commutative, we can
  // partition the sequence of terms into constants and
  // non-constants, and then sum the constant parts.
  try {
    Value v = eval.eval(r);
    if (v.is_integer())
      return make_int(v.get_integer());
    else
      throw std::runtime_error("failed to synth length");
  }
  catch(...) {
    return r;
  }
}
开发者ID:thehexia,项目名称:steve,代码行数:46,代码来源:length.cpp

示例13: binary_tournament

// Compare solution with a randomly generated opponent, return whichever
// has the higher fitness
void hill_climb::binary_tournament(Random & rand, vector<bool> & solution,
                                   float & fitness, Evaluator& evaluator) {
  auto guess = rand_vector(rand, solution.size());
  float guess_fitness = evaluator.evaluate(guess);
  if (fitness < guess_fitness) {
    solution = guess;
    fitness = guess_fitness;
  }
}
开发者ID:brianwgoldman,项目名称:Parameter-less_Population_Pyramid,代码行数:11,代码来源:HillCimb.cpp

示例14: evaluate

bool TestDocument::evaluate(Evaluator &evaluator) {
  bool rval = true;
  XMLSize_t numpass = 0;
  XMLSize_t numfail = 0;
  std::map<char *, bool, ltcstr> test_state;
  XMLCh *TEST = xercesc::XMLString::transcode("test");
  XMLCh *PREREQ = xercesc::XMLString::transcode("prereq");
  xercesc::DOMElement *root = doc->dom->getDocument()->getDocumentElement();
  xercesc::DOMNodeList *tests = root->getElementsByTagName(TEST);
  XMLSize_t numtests = tests->getLength();
  std::cout << numtests << " tests found in " << doc->path << std::endl;
  for (int i = 0; i < numtests; i++) {
    xercesc::DOMElement *e = static_cast<xercesc::DOMElement*>(tests->item(i));
    Test test(*this, e);
    bool testval = true;
    std::cout << "test " << (i+1) << " of " << numtests << ": " << test.id << "... ";
    if (e->hasAttribute(PREREQ)) {
      char *prereqs = xercesc::XMLString::transcode(e->getAttribute(PREREQ));
      char *scan = prereqs;
      std::stringstream prereq;
      while (char c = *scan++) {
        if (c == ' ' || c == ',') {
          testval = __checkPrereq(test, test_state, prereq) && testval;
          prereq.str("");
        }
        else {
          prereq << c;
        }
      }
      testval = __checkPrereq(test, test_state, prereq) && testval;
      xercesc::XMLString::release(&prereqs);
    }
    if (testval) {
      testval = evaluator.evaluate(*this, test)  && testval;
      testval = js_evaluator.evaluate(*this, test) && testval;
    }
    if (testval) {
      std::cout << "[OK]";
      numpass++;
    }
    else {
      std::cout << "[FAIL] (" << test.messages.str() << ")";
      numfail++;
    }
    std::cout << std::endl;
    test_state[xercesc::XMLString::replicate(test.id)] = testval;
    rval = testval && rval;
  }
  for (std::map<char *, bool, ltcstr>::iterator i = test_state.begin(); i != test_state.end(); i++) {
    xercesc::XMLString::release((char**)&i->first);
  }
  xercesc::XMLString::release(&TEST);
  xercesc::XMLString::release(&PREREQ);
  std::cout << numpass << " of " << numtests << " tests passed, " << numfail << " failed (" << ( ((double)numpass) / ((double)numtests) * 100.0 ) << "%)" << std::endl;
  return rval;
}
开发者ID:dfletcher,项目名称:xv8,代码行数:56,代码来源:testbase.cpp

示例15: main

void main(){
	// Construct the Context first
	map<string,int> Dict;
	Dict["一"] = 1;
	Dict["二"] = 2;
	Dict["三"] = 3;
	Dict["四"] = 4;
	Dict["五"] = 5;
	Dict["六"] = 6;
	Dict["七"] = 7;
	Dict["八"] = 8;
	Dict["九"] = 9;
	Evaluator myEvaluator = Evaluator();
	myEvaluator.Construct("五加二");
	double result = myEvaluator.Interprete(Dict);
	cout<<result<<endl;
	while(1){

	}
}
开发者ID:mjaimin,项目名称:C---Design-Patterns-Examples,代码行数:20,代码来源:main.cpp


注:本文中的Evaluator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。