// returns a string of the infix expression in postfix form std::string InfixCalculator::toPostfix(std::string infix){ std::string p = ""; for (unsigned int i = 0; i < infix.size(); i++){ if (isVal(infix[i])){ p += infix[i]; } if (isOp(infix[i])){ while (!opStack.isEmpty() && precedence(infix[i]) <= precedence(opStack.peek())){ p += opStack.peek(); opStack.pop(); } opStack.push(infix[i]); } if (infix[i] == '('){ opStack.push(infix[i]); } if (infix[i] == ')'){ while (opStack.peek() != '('){ p += opStack.peek(); opStack.pop(); } opStack.pop(); } } while (!opStack.isEmpty()){ p += opStack.peek(); opStack.pop(); } return p; }
// make infix expression into postfix expression // based off algorithm from book int InfixCalculator::evaluate(std::string infix){ int result; for (unsigned int i = 0; i < infix.size(); i++){ if (isVal(infix[i])){ valStack.push(infix[i] - 48); } if (isOp(infix[i])){ if (opStack.isEmpty() || precedence(infix[i]) > precedence(opStack.peek())){ opStack.push(infix[i]); } else { while (!opStack.isEmpty() && precedence(infix[i]) <= precedence(opStack.peek())){ execute(); } opStack.push(infix[i]); } } if (infix[i] == '('){ opStack.push(infix[i]); } if (infix[i] == ')'){ while (opStack.peek() != '('){ execute(); } opStack.pop(); } } while (!opStack.isEmpty()){ execute(); } result = valStack.peek(); return result; }
asynStatus ecSdoAsyn::writeInt32(asynUser *pasynUser, epicsInt32 value) { int cmd = pasynUser->reason; if(isTrig(cmd)) { EC_SDO_ENTRY * sdoentry = getSdoentry(cmd); SDO_REQ_MESSAGE request; request.tag = MSG_SDO_REQ; request.device = parent->device->position; request.index = sdoentry->parent->index; request.subindex = sdoentry->subindex; request.bits = sdoentry->bits; rtMessageQueueSend(parent->writeq, &request, sizeof(SDO_REQ_MESSAGE)); return asynSuccess; } else if(isVal(cmd)) { EC_SDO_ENTRY * sdoentry = getSdoentry(cmd); SDO_WRITE_MESSAGE write; write.tag = MSG_SDO_WRITE; write.device = parent->device->position; write.index = sdoentry->parent->index; write.subindex = sdoentry->subindex; write.bits = sdoentry->bits; write.value.ivalue = value; rtMessageQueueSend(parent->writeq, &write, sizeof(SDO_WRITE_MESSAGE)); return asynSuccess; } return asynError; }
bool NDLocalXmlString::parseLines( vector<string>& vecLines ) { if (vecLines.size() < 2) return false; m_kMapData.clear(); bool bOK = true; int index = 0; while (index < vecLines.size() - 1) { const string& keyLine = vecLines[ index ]; const string& valLine = vecLines[ index + 1 ]; if (isKey(keyLine.c_str()) && isVal(valLine.c_str())) { index += 2; bOK &= addKeyValue( keyLine, valLine ); } else { index++; //bad line! logErr( keyLine, valLine ); bOK = false; } } return bOK; }
unsigned int next(unsigned long mask, unsigned int toIdx, unsigned int fromIdx) { copy(mask, toIdx, fromIdx); unsigned int i; for (i= fromIdx+1; i<sDigiCount; i++) { if(isVal(mask, sDigiTime[i])) { return i; // advance index to the next value of this category } } return IDX_NOT_FOUND; }
EC_SDO_ENTRY * ecSdoAsyn::getSdoentry(int param) { // "normalize" to value params if (isStat(param)) { param -= 1; } if (isTrig(param)) { param -= 2; } assert(isVal(param)); for (int n = 0; n < parent->sdos; n ++) { if (paramrecords[n]->param_val == param) return paramrecords[n]->sdoentry; } assert( false ); // paramrecord not found return NULL; }
static OBJ parse(FILE *f, HASHTAB t, OBJ *ep){ OBJ d; int shared; d = read_obj(f,ep); if (*ep) return NIL; if (isVal(d)) { return d; } else if (isRefToCell(d)) { WORD lab = getLabel(d); int i; HASHENTRY e; i = lab % HASHSIZE; for (e = t->tab[i]; e; e = e->next) { if (e->label == lab) { /* increment RC of refered cell and return it. */ _incRc(_header(e->obj),1); return e->obj; } } /* Format error. */ copy_some(__ABinFile_AinvalidFormat,1); *ep = __ABinFile_AinvalidFormat; return NIL; } else if ((shared = isSharedCell(d)) || isExclCell(d)) { int sz = getSize(d), fs = getFlags(d), i; intptr_t flds; OBJ * data; OBJ ob; WORD lab; if (shared) { lab = (WORD)read_obj(f,ep); if (*ep) return NIL; if (!isRefToCell(lab)){ copy_some(__ABinFile_AinvalidFormat,1); *ep = __ABinFile_AinvalidFormat; return NIL; } } if (sz % flat_offset_ssize == big_escape_ssize){ flds = (intptr_t)read_obj(f,ep); if (*ep) return NIL; ob = _bigAlloc(flds); _mkHeader(_header(ob),sz,1); ((BCELL)ob)->size = pack_word(flds); data = _bdata(ob); } else { flds = sz % flat_offset_ssize; _alloc(flds,ob); _mkHeader(_header(ob),sz,1); data = _data(ob); } _flags(_header(ob)) = fs; if (shared){ HASHENTRY e; lab = getLabel(lab); e = newEntry(); e->label = lab; e->obj = ob; i = lab % HASHSIZE; e->next = t->tab[i]; t->tab[i] = e; } if (sz >= flat_offset_ssize) { if (fs & (1 << byte_flat_sflag)){ /* read two words and rest as char stream */ /* (UPDATE STRING FORMAT) */ unsigned char * cdata = (unsigned char*)(data+2); int ch, cflds = (flds-2) * sizeof(OBJ); data[0] = read_obj(f,ep); data[1] = read_obj(f,ep); for (i = 0; i < cflds && !*ep; i++) { if ((ch = getc(f)) != EOF){ cdata[i] = ch; } else get_unix_failure(errno,*ep); } } else { /* read contents of unstructured cell. */ for (i = 0; i < flds && !*ep; i++) { data[i] = read_obj(f,ep); } } } else { /* recursivly parse structured cell. */ for (i = 0; i < flds && !*ep; i++) { data[i] = parse(f,t,ep); } } /* process closures */ if (tst_sflag(ob, closure_sflag)){ char msgbuf[128]; char * msg = link_closure(ob); if (msg){ strcpy(msgbuf, (char*) data_denotation(__ABinFile_AlinkErrorPrefix)); strcat(msgbuf, (char*) data_denotation(((CLOSURE)ob)->symbolid)); strcat(msgbuf,"': "); strcat(msgbuf,msg); *ep = declare_failure_answer(msgbuf); return NIL; } } return ob; } else { copy_some(__ABinFile_AinvalidFormat,1); *ep = __ABinFile_AinvalidFormat; return NIL; } }