/**
 * parses and evaluates the given expression.
 * @returns
 * - On error, an error message is returned.
 * - On success, the result of the expression is either "1" or "0".
 */
bool CondParser::parse(const QString &fileName, int lineNr, const QString &expr)
{
   m_expr      = expr;
   m_tokenType = NOTHING;

   // initialize all variables
   m_e = m_expr.constData();    // let m_e point to the start of the expression

   bool answer = false;
   getToken();

   if (m_tokenType == DELIMITER && m_token.isEmpty()) {
      // empty expression: answer==false

   } else if (m_err.isEmpty()) {
      answer = parseLevel1();

   }

   if (! m_err.isEmpty()) {
      warn(fileName, lineNr, "problem evaluating expression '%s': %s", qPrintable(expr), qPrintable(m_err));
   }

   return answer;
}
示例#2
0
/**
 * parses and evaluates the given expression.
 * @returns 
 * - On error, an error message is returned.
 * - On success, the result of the expression is either "1" or "0".
 */
bool CondParser::parse(const char *fileName,int lineNr,const char *expr)
{
  m_expr      = expr;
  m_tokenType = NOTHING;

  // initialize all variables
  m_e = m_expr;    // let m_e point to the start of the expression

  bool answer=FALSE;
  getToken();
  if (m_tokenType==DELIMITER && m_token.isEmpty())
  {
    // empty expression: answer==FALSE
  }
  else if (m_err.isEmpty())
  {
    answer = parseLevel1();

#if 0
    // check for garbage at the end of the expression
    // an expression ends with a character '\0' and token_type = delimeter
    if (m_tokenType!=DELIMITER || !m_token.isEmpty())
    {
      if (m_tokenType == DELIMITER)
      {
        if (m_token=="(" || m_token==")")
        {
          m_err=QCString("Unexpected parenthesis ")+m_token+"'";
        }
        else
        {
          // user entered a not existing operator like "//"
          m_err=QCString("Unexpected operator ")+m_token+"'";
        }
      }
      else
      {
        m_err=QCString("Unexpected part '")+m_token+"'";
      }
    }
#endif
  }
  if (m_err)
  {
    warn(fileName,lineNr,"problem evaluating expression '%s': %s",
        expr,m_err.data());
  }
  //printf("expr='%s' answer=%d\n",expr,answer);
  return answer;
}
示例#3
0
/**
 * parenthesized expression or variable
 */
bool CondParser::parseLevel3() {
  // check if it is a parenthesized expression
  if (m_tokenType == DELIMITER) {
    if (m_token == "(") {
      getToken();
      int ans = parseLevel1();
      if (m_tokenType != DELIMITER || m_token != ")") {
        m_err = "Parenthesis ) missing";
        return FALSE;
      }
      getToken();
      return ans;
    }
  }

  // if not parenthesized then the expression is a variable
  return parseVar();
}