ftNode *ftParser::getOrOperand(void) { static OperatorType operatorType[] = { { '&', AndType }, { '\0' } }; ftNode *lhs = getAndOperand(); if (lhs == NULL) { return NULL; // error already reported } for (;;) { ftNode *op = getOperator(operatorType); if (op == NULL) { // not AND operator? // let caller decide what to do with next character return lhs; // return what was parsed so far } ftNode *rhs = getAndOperand(); if (rhs == NULL) { delete op; delete lhs; return NULL; // error already reported } op->op.lhs = lhs; op->op.rhs = rhs; lhs = op; } }
int calcExpression(char * p) { // if p = #: return atoi(p) // // else: // L = P.LeftSide // O = P.Op // R = P.RightSide // return PerformOp(calcExpression(L), calcExpression(R), O) // ACTUAL FUNCTION // if p is a number, return it if (isNumber(p)) return atoi(p); // Get Left, Right and Op from p. char leftOperand[256] = ""; char rightOperand[256]= ""; char op; int leftOpIndex = getLeftOperand(p, leftOperand); int operatorIndex = getOperator(p, leftOpIndex, &op); int rightOpIndex = getRightOperand(p+operatorIndex, rightOperand); printf("%s, %c, %s", leftOperand, op, rightOperand); getchar(); if (isEmpty(rightOperand)) return calcExpression(leftOperand); return performOperator( calcExpression(leftOperand), calcExpression(rightOperand), op ); }
int PhoneMonitorVoiceInterface::start( PhoneMonitorVoiceReportBase *reportHandle ) { m_phoneStatus =PHONE_STATUS_NOT_INIT; m_callStatus =CALL_IDLE; m_pCallback =reportHandle; if(m_pPhoneConnection->openDev("/dev/ttyUSB2")<0) return -1; QThread::start(); #ifdef PHONE_MODULE_ZTEMF5200_AUTH if(authentication() < 0) { printf("AUTH fail!!!\n"); //m_pPhoneConnection->closeDev("/dev/ttyUSB2"); return -1; } #endif m_phoneStatus =PHONE_STATUS_INITTING; m_pInitThread->startInit(this); m_pWorkThread->init(this); m_ptcpThread->init(this); // m_videoPhone->init(reportHandle); getOperator(); return PHONE_MONITOR_SUCCESS; }
void ExprParser::close() { while (getOperator()!='(') pop(); popOperator(); }
/** * This method builds a ModificationRequest srv * For stop operator, the path can be retreived from srv * */ void Modifier::buildModificationRequest(const Population& pop, bool imminent_collision, ramp_msgs::ModificationRequest& result) { // Push the target paths onto the modification request std::vector<int> targets; if(!imminent_collision || (move_dist_ > 100 && move_dir_ > 100)) { ////ROS_INFO("Modifier: No IC"); result.request.op = getOperator(); targets = getTargets(result.request.op, pop); } else { ////ROS_INFO("Modifier: Calling Move because IC exists"); result.request.op = "move"; targets.push_back(pop.calcBestIndex()); } //////ROS_INFO("targets.size(): %i", (int)targets.size()); for(unsigned int i=0;i<targets.size();i++) { //std::cout<<"\nTarget index: "<<targets.at(i); //std::cout<<"\nPath "<<targets.at(i)<<" size: "<<pop.paths_.at(targets.at(i)).size()<<"\n"; result.request.paths.push_back( pop.paths_.at(targets.at(i)).buildPathMsg()); } result.request.move_dir = move_dir_; result.request.move_dist = move_dist_; } // End buildModificationRequest
std::string SubtractionNode::getString(void) const { bool zero = false; IntegerNode* in; if ((in = dynamic_cast<IntegerNode*>(a.get())) != 0) { if (in->getValue() == 0) zero = true; } if (dynamic_cast<PlusMinus*> (b.get()) != 0) { return (!zero ? (a->getString() + " ") : "") + getOperator() + (zero ? "" : " ") + "(" + b->getString() + ")"; } else return (!zero ? (a->getString() + " ") : "") + getOperator() + (zero ? "" : " ") + b->getString(); }
bool SingularPart::fillSigma(double* sigma) const { // Set up the variables. int nTheta = basis->getRank(); const double* u = basis->getAbscissas(); double* theta = new double[nTheta]; for (int i = 0; i < nTheta; i++) theta[i] = acos(-1.)*0.5*(u[i] + 1.); double* beta = curvature.getBeta(theta, nTheta); double p = getRegularityPower(); // Set sigma to the solution if beta were constant. for (int i = 0; i < nTheta; i++) sigma[i] = p < 1. ? pow(beta[i]*0.125/(p*(1.-p)), 0.125) : pow(beta[i]*0.125/(p*(p - 1.)), 0.125) ; double* lap = getOperator(theta); bool converged = newtonRaphson(sigma, beta, lap); if (!converged) { std::clog << "Newton-Raphson did not converge.\n"; } delete[] lap; delete[] theta; delete[] beta; return converged; }
ParseResult* Parser::parse(string expr){ if (expr.size() == 0) return nullptr; int lowPriorityToken = tokens.size(); // Track the minimum priority int lowPrPos = -1; // operator token during parsing // Remove unwanted chars expr = removeChar(expr, ' '); expr = unwrap(expr); transform(expr.begin(), expr.end(), expr.begin(), ::tolower); // Add 0 to let constants have negative sign if (expr[0] == '-') expr = '0' + expr; for (int i = 0; i < expr.size(); i++){ char currChar = expr[i]; if (currChar == '('){ i = getClosedBracketPos(expr, i); continue; } int op = getOperator(expr, i); if (op >= 0 && op < lowPriorityToken){ lowPriorityToken = op; lowPrPos = i; } } if (lowPrPos >= 0){ int opEndPos = lowPrPos + tokens[lowPriorityToken].size(); ParseResult* result = new ParseResult; result->id = static_cast<TokenId>(lowPriorityToken); result->lExpr = expr.substr(0, lowPrPos); result->rExpr = expr.substr(opEndPos, expr.size() - opEndPos); return result; } else if (lowPriorityToken == VARX || lowPriorityToken == VARX) { ParseResult* result = new ParseResult; result->id = static_cast<TokenId>(lowPriorityToken); result->lExpr = ""; result->rExpr = ""; return result; } ParseResult* result = new ParseResult; result->id = CONST; result->lExpr = expr; result->rExpr = ""; return result; }
void ExprParser::pop() { char op = getOperator(); switch (op) { case 'm': Generator::negate (mCode, getOperandType()); popOperator(); break; case '+': Generator::add (mCode, getOperandType (1), getOperandType()); popOperator(); replaceBinaryOperands(); break; case '-': Generator::sub (mCode, getOperandType (1), getOperandType()); popOperator(); replaceBinaryOperands(); break; case '*': Generator::mul (mCode, getOperandType (1), getOperandType()); popOperator(); replaceBinaryOperands(); break; case '/': Generator::div (mCode, getOperandType (1), getOperandType()); popOperator(); replaceBinaryOperands(); break; case 'e': case 'n': case 'l': case 'L': case 'g': case 'G': Generator::compare (mCode, op, getOperandType (1), getOperandType()); popOperator(); popOperand(); popOperand(); mOperands.push_back ('l'); break; default: throw std::logic_error ("unknown operator"); } }
void ExprParser::pushBinaryOperator (char c) { while (!mOperators.empty() && getPriority (getOperator())>=getPriority (c)) pop(); mOperators.push_back (c); mNextOperand = true; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ImageCalculator::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setSelectedCellArrayPath1( reader->readDataArrayPath( "SelectedCellArrayPath1", getSelectedCellArrayPath1() ) ); setOperator( reader->readValue( "Operator", getOperator() ) ); setSelectedCellArrayPath2( reader->readDataArrayPath( "SelectedCellArrayPath2", getSelectedCellArrayPath2() ) ); setNewCellArrayName( reader->readString( "NewCellArrayName", getNewCellArrayName() ) ); reader->closeFilterGroup(); }
ftNode *ftParser::getExpression(void) { static OperatorType operatorType[] = { { '|', OrType }, { ')', ParenType }, { ';', EndType }, { '\0' } }; ftNode *lhs = getOrOperand(); if (lhs == NULL) { return NULL; // error already reported } for (;;) { ftNode *op = getOperator(operatorType); if (op == NULL) { reportError("expected operator or ';'", 1); delete lhs; return NULL; // error already reported } if (m_level == 0) { if (op->type == EndType) { delete op; return lhs; } else if (op->type == ParenType) { reportError("no matching opening parentheses"); delete op; delete lhs; return NULL; } } else { // within parentheses if (op->type == EndType) { reportError("expected closing parentheses"); delete op; delete lhs; return NULL; } else if (op->type == ParenType) { delete op; return lhs; } } ftNode *rhs = getOrOperand(); if (rhs == NULL) { delete op; delete lhs; return NULL; // error already reported } op->op.lhs = lhs; op->op.rhs = rhs; lhs = op; } }
vector<COperator> Parser::getOperators() { vector<COperator> tmpOperators; while(nextOperator()) { tmpOperators.push_back(getOperator()); } return tmpOperators; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ImageMath::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setSelectedCellArrayPath( reader->readDataArrayPath( "SelectedCellArrayPath", getSelectedCellArrayPath() ) ); setOperator( reader->readValue( "Operator", getOperator() ) ); setValue( reader->readValue( "Value", getValue() ) ); setSaveAsNewArray( reader->readValue( "SaveAsNewArray", getSaveAsNewArray() ) ); setNewCellArrayName( reader->readString( "NewCellArrayName", getNewCellArrayName() ) ); reader->closeFilterGroup(); }
int InfixToPostfix::operatorPrecedence(const std::string& op) const { for (int i = 0; i < numberOfOperators(); ++i) { std::stringstream ss(getOperator(i)); std::string token; while (ss >> token) { if (token == op) { return i; } } } return -1; }
std::string MultDivMod::getString(void) const { bool addA = dynamic_cast<PlusMinus*> (&*a); bool addB = dynamic_cast<PlusMinus*> (&*b); std::string left; std::string right; if (addA) left = "(" + a->getString() + ")"; else left = a->getString(); if (addB) right = "(" + b->getString() + ")"; else right = b->getString(); return left + " " + getOperator() + " " + right; }
// makeToken {{{ int CLexer::makeToken() { //if(isEOF()) return ILexer::RET_EOF; CToken* token=NULL; int ret = ILexer::RET_NORMAL; // トークンの作成 while(token == NULL) { skipBlanks(); if(isComment()) { skipLine(); continue; } if( (token = getEOF()) != NULL){ret = ILexer::RET_EOF; break;} if( (token = getEOL()) != NULL){ret = ILexer::RET_EOL; nowLine_++;break;} // トークン取得開始 if( (token = getKeyword()) != NULL) break; if( (token = getOperator()) != NULL) break; if( (token = getIdentifier()) != NULL) break; if( (token = getLiteral('\'',false)) != NULL) break; if( (token = getLiteral('"',true)) != NULL) break; if( (token = getConstant()) != NULL) break; if( (token = getSeparator()) != NULL) break; // エラー処理 onAnalyzeError(); } topToken_ = token; makeTokenRet_ = ret; return ret; }
RValue Inst::BinaryOp(int type, RValue lhs, RValue rhs, CodeContext& context) { if (!lhs || !rhs) return RValue(); if (CastMatch(context, lhs, rhs, true)) return RValue(); switch ((lhs.stype()->isPointer() << 1) | rhs.stype()->isPointer()) { default: case 0: // no pointer { auto llvmOp = getOperator(type, lhs.stype(), context); return RValue(BinaryOperator::Create(llvmOp, lhs, rhs, "", context), lhs.stype()); } case 1: // lhs != ptr, rhs == ptr swap(lhs, rhs); case 2: // lhs == ptr, rhs != ptr return PointerMath(type, lhs, rhs, context); case 3: // both ptr context.addError("can't perform operation with two pointers"); return lhs; } }
std::string AssignmentNode::getString(void) const { return a->getString() + " " + getOperator() + " " + b->getString(); }
std::string OperationNode::getString(void) const { return a->getString() + " " + getOperator() + " " + b->getString(); }
{_log("number\r\0") //check stack, if full show errer if (! stack_isfull(sd1)) { stack_push(sd1,value); LCD_SendData(key); } else { showError(); _log(" stack full\r\0"); } } else if(getOperator(key) != -1) //operator { operator=getOperator(key); _log(" operator \0") _log1(ops[operator]) _log("\r\0") if(stack_isempty(sd1)) { showError(); _log("operator can't be the 1st input\r\0") } else { state=1; LCD_SendData(key); } } else { showError();
int Parser::parse() { std::stack<Token> stack; ast.op = OP_HLT; ast.i = 0; lastTokenId = TOK_NONE; lastOp = -1; tok = scanner.getNextToken(); while (tok.id != TOK_EOF) { bool expectUnary = lastTokenId == TOK_LPAREN || lastTokenId == TOK_NONE || canBePrefix(lastTokenId) || canBeInfix(lastTokenId); bool expectExpr = lastTokenId == TOK_NONE || lastTokenId == TOK_LPAREN || canBePrefix(lastTokenId) || canBeInfix(lastTokenId); switch (tok.id) { default: raiseError("unknown token"); return 1; case TOK_ERROR: raiseError(tok.err); return 1; case TOK_PLUS: if (expectUnary) tok.id = TOK_UN_PLUS; else tok.id = TOK_OP_ADD; continue; case TOK_MINUS: if (expectUnary) tok.id = TOK_UN_NEG; else tok.id = TOK_OP_SUB; continue; case TOK_ARG: if (canBeValue(lastTokenId)) { raiseError("unexpected primary value"); return 1; } if (tok.i > UCHAR_MAX) { raiseError("argument number out of range"); return 1; } emitOp(OP_ARG, (unsigned char)(tok.i)); break; case TOK_LIT: if (canBeValue(lastTokenId)) { raiseError("unexpected primary value"); return 1; } emitOp(OP_CONST, tok.d); break; case TOK_F_PI: if (canBeValue(lastTokenId)) { raiseError("unexpected primary value"); return 1; } emitOp(OP_PI); break; case TOK_F_E: if (canBeValue(lastTokenId)) { raiseError("unexpected primary value"); return 1; } emitOp(OP_E); break; case TOK_UN_PLUS: // unary plus is a noop break; case TOK_LPAREN: if (!canBeFunction(lastTokenId) && !expectExpr) { raiseError("unexpected open parenthesis"); return 1; } stack.push(tok); break; case TOK_F_SQRT: case TOK_F_SIN: case TOK_F_COS: case TOK_F_TAN: case TOK_F_ASIN: case TOK_F_ACOS: case TOK_F_ATAN: case TOK_F_SINH: case TOK_F_COSH: case TOK_F_TANH: case TOK_F_ASINH: case TOK_F_ACOSH: case TOK_F_ATANH: case TOK_F_EXP: case TOK_F_LOG: case TOK_F_ERF: case TOK_F_ERFC: case TOK_F_ABS: case TOK_F_FLOOR: case TOK_F_CEIL: case TOK_F_ROUND: case TOK_F_TRUNC: case TOK_F_POW: case TOK_UN_NEG: if (canBeValue(lastTokenId)) { raiseError("unexpected prefix operator"); return 1; } stack.push(tok); break; case TOK_COMMA: while (stack.size() > 0 && stack.top().id != TOK_LPAREN) { emitOp(getOperator(stack.top().id)); stack.pop(); } if (stack.size() <= 0 || stack.top().id != TOK_LPAREN) { raiseError("misplaced comma"); return 1; } break; case TOK_RPAREN: while (stack.size() > 0 && stack.top().id != TOK_LPAREN) { emitOp(getOperator(stack.top().id)); stack.pop(); } if (stack.size() <= 0 || stack.top().id != TOK_LPAREN) { raiseError("mismatched parenthesis"); return 1; } stack.pop(); while (stack.size() > 0 && canBePrefix(stack.top().id)) { emitOp(getOperator(stack.top().id)); stack.pop(); } break; case TOK_OP_ADD: case TOK_OP_SUB: case TOK_OP_MUL: case TOK_OP_DIV: case TOK_OP_POW: if (!canBeValue(lastTokenId)) { raiseError("unexpected operator"); return 1; } while (stack.size() > 0 && canBeOperation(stack.top().id)) { if (isRightAssociative(tok.id)) { if (getPrecedence(tok.id) < getPrecedence(stack.top().id)) { emitOp(getOperator(stack.top().id)); stack.pop(); } else break; } else { if (getPrecedence(tok.id) <= getPrecedence(stack.top().id)) { emitOp(getOperator(stack.top().id)); stack.pop(); } else break; } } stack.push(tok); break; } lastTokenId = tok.id; tok = scanner.getNextToken(); } if (!canBeValue(lastTokenId)) { raiseError("unexpected program end"); return 1; } while (stack.size() > 0) { if (stack.top().id == TOK_LPAREN || stack.top().id == TOK_RPAREN) { raiseError("mismatched parenthesis"); return 1; } else { emitOp(getOperator(stack.top().id)); stack.pop(); } } return 0; }
std::string InfixToPostfix::removeOperator(int index) { std::string result = getOperator(index); this->_operators.erase(this->_operators.begin() + index); return result; }
//! (static) const Operator * Operator::getOperator(const std::string & op) { return getOperator(stringToIdentifierId(op)); }