Beispiel #1
0
void Eval::evaluateInfixExpression (const std::string& e, Variant& v) const
{
  // Reduce e to a vector of tokens.
  Lexer l (e);
  l.ambiguity (_ambiguity);
  std::vector <std::pair <std::string, Lexer::Type> > tokens;
  std::string token;
  Lexer::Type type;
  while (l.token (token, type))
    tokens.push_back (std::pair <std::string, Lexer::Type> (token, type));

  // Parse for syntax checking and operator replacement.
  if (_debug)
    context.debug ("FILTER Infix        " + dump (tokens));
  infixParse (tokens);
  if (_debug)
    context.debug ("FILTER Infix parsed " + dump (tokens));

  // Convert infix --> postfix.
  infixToPostfix (tokens);
  if (_debug)
    context.debug ("FILTER Postfix      " + dump (tokens));

  // Call the postfix evaluator.
  evaluatePostfixStack (tokens, v);
}
Beispiel #2
0
void Eval::compileExpression (const std::string& e)
{
  // Reduce e to a vector of tokens.
  Lexer l (e);
  l.ambiguity (_ambiguity);
  std::string token;
  Lexer::Type type;
  while (l.token (token, type))
  {
    if (_debug)
      context.debug ("Lexer '" + token + "' " + Lexer::type_name (type));
    _compiled.push_back (std::pair <std::string, Lexer::Type> (token, type));
  }

  // Parse for syntax checking and operator replacement.
  if (_debug)
    context.debug ("FILTER Infix        " + dump (_compiled));
  infixParse (_compiled);
  if (_debug)
    context.debug ("FILTER Infix parsed " + dump (_compiled));

  // Convert infix --> postfix.
  infixToPostfix (_compiled);
  if (_debug)
    context.debug ("FILTER Postfix      " + dump (_compiled));
}
Beispiel #3
0
void Eval::compileExpression (
  const std::vector <std::pair <std::string, Lexer::Type>>& precompiled)
{
  _compiled = precompiled;

  // Parse for syntax checking and operator replacement.
  if (_debug)
    context.debug ("FILTER Infix        " + dump (_compiled));
  infixParse (_compiled);
  if (_debug)
    context.debug ("FILTER Infix parsed " + dump (_compiled));

  // Convert infix --> postfix.
  infixToPostfix (_compiled);
  if (_debug)
    context.debug ("FILTER Postfix      " + dump (_compiled));
}