本文整理汇总了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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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";
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}