// * && / static TreeNode * _term(void) { TreeNode *t = _factor(); while (token == TIMES || token == OVER) { TreeNode *q = new_exp_node(OpK); if (q != NULL) { q->child[0] = t; q->attr.op = token; t = q; _match(token); t->child[1] = _factor(); } } return t; }
vector<pll> factorG(long long n){ top=0; _factor(n); vector<pll> d; for(int i=0;i<top;++i)d.pb(pll(stk_p[i],stk_k[i])); return d; }
int Parser::_term() { int value = _factor(); TokenType t = _token(); while (_success && (t == TT_MULT || t == TT_DIV)) { _scanner.advance(); switch (t) { case TT_MULT: value *= _factor(); break; case TT_DIV: value /= _factor(); break; default: notifyListeners("ERROR: Unknown error"); _success = false; return 0; } t = _token(); } return value; }
double WidgetCalc::_term(const std::string& str, unsigned *idx) { double result = _factor(str, idx); double div; while (str[*idx] == '*' || str[*idx] == '/') { switch (str[*idx]) { case '*': ++*idx; result *= _factor(str, idx); break; case '/': ++*idx; div = _factor(str, idx); if (div != 0.0) { result /= div; } else { Logger::warning( "!!! WARNING: Division by zero!"); return 0; } break; } } return result; }
double WidgetCalc::_factor(const std::string& str, unsigned *idx) { double result; int sign = 1; if (str[*idx] == '-') { sign = -1; ++*idx; } if (str[*idx] == '(') { ++*idx; result = _expr(str, idx); if (str[*idx] != ')') { Logger::warning( "!!! WARNING: Brackets unbalanced!"); return 0; } ++*idx; } else result = _number(str, idx); if (str[*idx] == '^') { ++*idx; result = pow(result, _factor(str, idx)); } return sign * result; }
void factor(double fx, double fy) { _factor((int) (fx * SCALE + 0.5), (int) (fy * SCALE + 0.5), SCALE); }