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


C++ Expression::evaluate方法代码示例

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


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

示例1: evaluate

void If::evaluate() {
	// empty list = false
	// not empty list = true
	// Im going to receive 3 arguments, if the first argument is
	// true then evaluate and return the second one
	// if the first argument is false (empty list) the evaluate and
	// return the third one
	std::vector<Expression*> myArguments = getArguments();
	std::vector<Expression*>::iterator it = myArguments.begin();
	Expression* condition = *it;
	++it;
	Expression* trueReturn = *it;
	++it;
	Expression* falseReturn = *it;

	// Start checking conditons
	condition->evaluate();
	if (condition->getResult() == LISP_FALSE){
		falseReturn->evaluate();
		result = falseReturn->getResult();
	} else {
		trueReturn->evaluate();
		result = trueReturn->getResult();
	}
}
开发者ID:mastanca,项目名称:taller-1c-2016-lisp-interpreter,代码行数:25,代码来源:If.cpp

示例2: main

int main()
{
	const int SIZE = 256;
	Expression* expression;
	char paren, comma, line[SIZE];

	ifstream fin("input.txt");

	while (true)
	{
		symbolTable.init();
		fin.getline(line, SIZE);
		if (!fin) break;

		stringstream in(line, ios_base::in);

		in >> paren;
		cout << line << " ";

		try
		{
			expression = SubExpression::parse(in);
			in >> comma;
			parseAssignments(in);
			cout << "Value = " << expression->evaluate() << endl;
		}
		catch (exception) {
			return EXIT_FAILURE;
		}
	}
	return 0;
}
开发者ID:johnson-joshua,项目名称:ExpressionInterpreter,代码行数:32,代码来源:module3.cpp

示例3: main

int main(int argc, char** argv) {
    

    ifstream inFile;
    char inputFilename[] = "F:\\Documents\\project2input.txt";
    inFile.open(inputFilename, ios::in);

    if (!inFile) {
        cerr << "Can't open input file " << inputFilename << endl;
        exit(1);
    }
    Expression* expression;
    
    std::string token;
    std::istringstream line(token);
    char paren, comma;
    while(std::getline(inFile, token))
    {
        
        std::istringstream line(token);
        while(line >> token)
        {
            std::cout << "Token :" << token << std::endl;
            line >> paren;
            expression = SubExpression::parse();
            line >> comma;
            parseAssignments();
        }
    }
    
    
    cout << "Value = " << expression->evaluate() << endl;
    inFile.close();
    return 0;
}
开发者ID:pearcebdev,项目名称:ExpressionInterpreter,代码行数:35,代码来源:main.cpp

示例4: getVariable

Variable* Variable::getVariable(int depth, vector<Expression>& index, Function* origin)
{
	if(index.size() <= 0)
	{
		return this;
	}
	if(depth == index.size() || !origin)
	{
		return this;
	}
	else
	{	
		if(depth < index.size() && depth >= 0)
		{
			Expression a = index[depth];
			Variable v = a.evaluate(origin);
			int i = v.getValuef();
			if(i < variables.size() && i >= 0)
			{
				return variables[i].getVariable(depth+1, index, origin);	
			}
			else
			{
				return this;
			}
		}
		else
		{
			return this;
		}
	}		
	return this;
}
开发者ID:jshmrsn,项目名称:Chalkboard-for-Mac,代码行数:33,代码来源:Variable.cpp

示例5: to_element

Element* Function::to_element(ContextProtected& context) {
	ExpressionParser parser;
	Expression* expression = parser(this->sentence);
	Environment* env = expression->evaluate(context);
	delete expression;
	Element* element = env->get_elements()[0]->clone();
	delete env;
	return element;
}
开发者ID:abrden,项目名称:lisp-interpreter,代码行数:9,代码来源:Environment.cpp

示例6: evaluatePredicate

bool evaluatePredicate(const Expression& expression)
{
    Value result(expression.evaluate());

    // foo[3] means foo[position()=3]
    if (result.isNumber())
        return EqTestOp(EqTestOp::OP_EQ, Function::create(ASCIILiteral("position")), std::make_unique<Number>(result.toNumber())).evaluate().toBoolean();

    return result.toBoolean();
}
开发者ID:ZeusbaseWeb,项目名称:webkit,代码行数:10,代码来源:XPathPredicate.cpp

示例7: evaluate

    virtual bool evaluate()
    {
        switch(_operator)
        {
        case LESS:
            return _left->value() < _right->value();
        case MORE:
            return _left->value() > _right->value();
        case EQUAL:
            return fabs(_left->value() - _right->value()) <= 0.000001;
        case AND:
            return _left->evaluate() && _right->evaluate();
        case OR:
            return _left->evaluate() || _right->evaluate();
        default:
            throw "Unknown operator";

        }
    }
开发者ID:jpazarzis,项目名称:development,代码行数:19,代码来源:gen_pro_sample.cpp

示例8: main

int main( int, char*[] )
{
    std::string code = "(test 42 ( - 44 ( + 1 1 ) ) )  ";
    Compiler compiler(code);

    Expression* program = compiler.compile();
    
    printValue( program->evaluate() );

    std::cout << std::endl << " ---DONE--- " << std::endl;
}
开发者ID:smacdo,项目名称:scottsandbox,代码行数:11,代码来源:calc.cpp

示例9: main

int main()
{
	Expression* expression;
	char paren, comma;
	cout << "Enter expression: ";
	cin >> paren;
	expression = SubExpression::parse();
	cin >> comma;
	parseAssignments();
	cout << "Value = " << expression->evaluate() << endl;
	return 0;
}
开发者ID:bknauth,项目名称:UMUC-CMSC330_Advanced_Programming_Languages,代码行数:12,代码来源:module3.cpp

示例10: evaluate

  virtual bool evaluate(SimpleCpcClient* c, const SimpleCpcClient::Process & p){
    bool run = on_empty;
    for(size_t i = 0; i<m_cond.size(); i++){
      if(m_cond[i]->evaluate(c, p)){
	run = true;
	break;
      }
    }
    if(run)
      return m_rule->evaluate(c, p);
    return false;
  }
开发者ID:4T-Shirt,项目名称:mysql,代码行数:12,代码来源:cpcc.cpp

示例11: calculate

Number Application::calculate(const std::string &input, int precision) const
{
    // tokenizujemy
    Tokenizer tok(input);
    std::vector<Token*> tokens = tok.tokenize();

    Expression *expr = 0;

    try {
        // sprawdzamy sens
        SyntaxChecker checker(tokens);
        checker.check();

        // parser
        Parser parser(tokens, m_precedence);
        expr = parser.parse();
    } catch (...) {
        // usuwanie tokenów
        for (Token *tok : tokens) {
            delete tok;
        }

        throw;
    }

    // rekurencyjnie liczymy rozwiązanie
    Number out;

    try {
        out = expr->evaluate(0, precision);
    } catch (...) {
        // usuwanie wyrażeń
        delete expr;

        // usuwanie tokenów
        for (Token *tok : tokens) {
            delete tok;
        }

        throw;
    }

    // usuwanie wyrażeń
    delete expr;

    // usuwanie tokenów
    for (Token *tok : tokens) {
        delete tok;
    }

    return out;
}
开发者ID:eplightning,项目名称:pp_calculator_cli,代码行数:52,代码来源:application.cpp

示例12: processCell

void processCell(Expression &expr, double x, double y, double xLen, double yLen, std::vector<sf::Vertex> &Curve) {
	double a, b, c, d;
	a = expr.evaluate(x, -y);
	b = expr.evaluate(x + xLen, -y);
	c = expr.evaluate(x + xLen, -y - yLen);
	d = expr.evaluate(x, -y - yLen);
	int num = ((a > 0.0) ? 1 : 0) + ((b > 0.0) ? 2 : 0) + ((c < 0.0) ? 4 : 0) + ((d > 0.0) ? 8 : 0);
	switch(num) {
		case 1: case 2: case 4: case 7: case 8: case 11: case 13: case 14: case 3: case 6: case 12: case 9:
			draw(num, x, y, xLen, yLen, a, b, c, d, Curve);
//			std::cout<<"["<<x<<","<<y<<","<<num<<"]\t";
			break;
		case 5: case 10:
			std::cout << "Recursion Happens\n";
			processCell(expr, x, y, xLen / 2, yLen / 2, Curve);
			processCell(expr, x + xLen / 2, y, xLen / 2, yLen / 2, Curve);
			processCell(expr, x + xLen / 2, y + yLen / 2, xLen / 2, yLen / 2, Curve);
			processCell(expr, x, y + xLen / 2, xLen / 2, yLen / 2, Curve);
			break;
		case 0: case 15:
			break;
	}
}
开发者ID:Suraj-Yadav,项目名称:Plotter,代码行数:23,代码来源:gridFunc.cpp

示例13: runSilent

/* performs and outputs the choice expression in the output style */
void runSilent(std::string choice,std::string strExpr,std::string output) {
	Expression::Notation notation = Expression::NOTATION_INFIX;
	Expression* expression = NULL;
	bool isValidSelection = true;
	
	if(choice == "infix"){
		notation = Expression::NOTATION_INFIX;
	}
	else if(choice == "postfix"){
		notation = Expression::NOTATION_POSTFIX;
	}
	else if(choice == "prefix"){
		notation = Expression::NOTATION_PREFIX;
	}
	else{
		isValidSelection = false;
	}

	if(isValidSelection){
		expression = new Expression(strExpr,notation);

		if(!expression->hasError()){
			if(output == "infix")
			cout << expression->getInfix() << endl;
			else if(output == "postfix")
			cout << expression->getPostfix() << endl;
			else if(output == "prefix")
			cout << expression->getPrefix() << endl;
			else if(output == "value"){
				try{
					cout << expression->evaluate() << endl;
				}
				catch (runtime_error& e)
				{
					cout << e.what() << endl;
				}
			}
			else
				cout << "invalid output format." << endl;
		}
		else{
			cout << expression->getError() << endl;
		}
	}
	else{
		cout << "The selection you entered was not valid." << endl;
	}

	delete expression;
}
开发者ID:jmasterx,项目名称:Computer-Science-Assignments,代码行数:51,代码来源:DSAsmt02.cpp

示例14:

int
for_each(Vector<SimpleCpcClient*>& list, Expression & expr){
  for(size_t i = 0; i<list.size(); i++){
    if(list[i] == 0)
      continue;
    Properties p;
    Vector<SimpleCpcClient::Process> procs;
    if(list[i]->list_processes(procs, p) != 0){
      ndbout << "Failed to list processes on " 
	     << list[i]->getHost() << ":" << list[i]->getPort() << endl;
    }
    for(size_t j = 0; j<procs.size(); j++)
      expr.evaluate(list[i], procs[j]);
  }
  return 0;
}
开发者ID:4T-Shirt,项目名称:mysql,代码行数:16,代码来源:cpcc.cpp

示例15: main

int main()
{
    Tokenizer t;

    //adding the tokens for the tokenizer
    t.add("\\+|-",PLUSMINUS);
    t.add("\\*|/",MULTDIV);
    t.add("\\^",RAISED);
    t.add("!",FACULTY);
    //regexp matching is greedy; try sinh/cosh/tanh first
    t.add("sinh|cosh|tanh",FUNCTION);
    t.add("asin|acos|atan",FUNCTION);
    t.add("sin|cos|tan|sqrt",FUNCTION);
    t.add("log\\[[[[:digit:]]+(\\.)?[[:digit:]]*\\]|log",FUNCTION);
    t.add("\\(",OPEN_BRACKET);
    t.add("\\)",CLOSE_BRACKET);
    t.add("[[:digit:]]+(\\.)?[[:digit:]]*",NUMBER);

    string str;

    while(1) {
        cout << "=> ";

        if(!getline(cin,str)) {
          cout << endl;
          return 1;
        }

        str.erase(remove_if(str.begin(),str.end(), ::isspace),str.end());

        if(str.empty())
          continue;

        if(str == "quit")
            break;
        try{
            vector<token> a = t.tokenize(str);
            Parser p(a);
            Expression* exp = p.parse();
            cout << "\t\t== " << exp->evaluate() << endl;;
        } catch (runtime_error& e) {
            cout << "\t\tSyntax error: " << e.what() << endl;;
        }
    }

    return 0;
}
开发者ID:chrk123,项目名称:calculator,代码行数:47,代码来源:calculator.cpp


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