예제 #1
0
파일: EXParser.cpp 프로젝트: sukovanej/qum
void EXParser::evaluateOperator(std::string & _expression, const int index, EXOperatorSet::iterator oiter)
{
	if(oiter->first!='('){
		std::string leftVal, rightVal, strVal;
		if((leftVal = getLeftOfOperator(_expression, index-1)).empty() || (rightVal = getRightOfOperator(_expression, index+1)).empty()){
			throw EXError("operator_logic_error", ErrorIndex::OPERATOR_LOGIC_ERROR);
		}

		double value = oiter->second(strToDbl(leftVal.c_str()), strToDbl(rightVal.c_str()));
		if(isInf(value)){
			throw EXError("infinity_error", ErrorIndex::INFINITY_ERROR);
		}
		if(isNan(value)){
			throw EXError("not_a_number", ErrorIndex::NAN_ERROR);
		}
		_expression.replace(index-leftVal.length(), leftVal.length() + rightVal.length()+1, dblToStr(value));
	}
	else{
		evaluateParenthesis(_expression, index);
	}
}
예제 #2
0
bool EXParser::evaluateOperator(std::string & _expression, const int index, EXOperatorSet::iterator oiter)

{

	if(oiter->first!='('){

		std::string leftVal, rightVal, strVal;

		if((leftVal = getLeftOfOperator(_expression, index-1)).empty() || (rightVal = getRightOfOperator(_expression, index+1)).empty()){

		  mErrorStr = "operator logic error";
		  return false;
		}



		double value = oiter->second(strToDbl(leftVal.c_str()), strToDbl(rightVal.c_str()));

		if(isInf(value)){
		  mErrorStr = "infinity error";
		  return false;
		}

		if(isNan(value)){
		  mErrorStr = "not a number";
		  return false;
		}

		_expression.replace(index-leftVal.length(), leftVal.length() + rightVal.length()+1, dblToStr(value));

	}

	else{

		evaluateParenthesis(_expression, index);

	}

	return true;
}