QString EventType::parsedFormula() { QString res; if (!parseFormula()) return res; for (int i=0; i<ProfileCostArray::MaxRealIndex;i++) { int c = _coefficient[i]; if (c == 0) continue; if (!res.isEmpty()) { res += ' '; if (c>0) res += "+ "; } if (c<0) { res += "- "; c = -c; } res += QString::number(c); EventType* t = _set->type(i); if (!t) continue; if (!t->name().isEmpty()) res += QString(" * %1").arg(t->name()); } return res; }
static int parseAST(Parser *p) { #ifdef LOG_PARSE info("开始解析AST\n"); #endif p->ast = parseFormula(p); return p->ast ? 0 : -1; }
Object * newFormula(Collector * c, Buffer * value) { Tokenizer tt; tokenizerInit(&tt, value); Object * result = parseFormula(c, &tt); if (tt.bp != tt.be) return NULL; return result; }
SubCost EventType::subCost(ProfileCostArray* c) { if (_realIndex != ProfileCostArray::InvalidIndex) return c->subCost(_realIndex); if (!_parsed) { if (!parseFormula()) return 0; } SubCost res = 0; int rc = _set->realCount(); for (int i = 0;i<rc;i++) if (_coefficient[i] != 0) res += _coefficient[i] * c->subCost(i); return res; }
int EventType::histCost(ProfileCostArray* c, double total, double* hist) { if (total == 0.0) return 0; if (!_parsed) { if (!parseFormula()) return 0; } int rc = _set->realCount(); for (int i = 0;i<rc;i++) { if (_coefficient[i] != 0) hist[i] = _coefficient[i] * c->subCost(i) / total; else hist[i] = 0.0; } return rc; }
std::string ReversePolandNotation::performCalculation(const std::string &formula) const { return evaluateFormula(parseFormula(formula)); }