Esempio n. 1
0
// * && /
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;
}
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
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;
}
Esempio n. 4
0
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;
}
Esempio n. 5
0
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;
}
Esempio n. 6
0
File: plsub.c Progetto: EQ4/SPTK
void factor(double fx, double fy)
{
   _factor((int) (fx * SCALE + 0.5), (int) (fy * SCALE + 0.5), SCALE);
}