Example #1
0
string Parser::Expression() {

    _message.print(DBUG, "PARSER: In Expression()\n");

    //    AndExpression,
    //    { “||”, AndExpression }

    static tokenType firstSet[] = {SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1};

    static tokenType followSet[] = {SYM_ASSIGN, SYM_SEMICOLON, SYM_OPEN, SYM_SQ_OPEN, SYM_COMMA, SYM_CLOSE, (tokenType) - 1};

    string type, type1;

    if ( synchronized(firstSet, followSet, "Expected Expression") ) {

        type = AndExpression();

        while ( _lookAhead.getTokenType() == SYM_OR ) {
            match(SYM_OR);
            type = "i";
            type1 = AndExpression();
            if (!(type == "i" && type1 == "i"))
                _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Conditional statement must return either 0 or 1", _lookAhead.getRow() , _lookAhead.getCol());
        }
    }
    _message.print(DBUG, "PARSER: End of Expression()\n");
    return type;
}
Example #2
0
/*----------------------------------------------------------
 * OrExpression
 * Evaluate an OR expression
 * same input/output parameters as for Expression()
 *----------------------------------------------------------*/
static int OrExpression(s_token *token_p, bool skip)
{
   int match;
   
   NextToken(token_p, skip);
   match = AndExpression(token_p, skip);
   while (token_p->tt == T_OR) {
      NextToken(token_p, skip); /* Negative logic 0=true,  or is and */
      if (match==0) {
         AndExpression(token_p, true); /* skip other for true */
      } else {
         match = AndExpression(token_p, skip);
      }
   }
   return match;
}
Example #3
0
File: qm.hpp Project: bindung/utils
AndExpression operator&&(const BoolExpression &exp1, const BoolExpression &exp2) {
	return AndExpression(exp1, exp2);
}
string mhmakefileparser::ResolveExpression(const string &InExpr,string &Rest) const
{
  unsigned i=0;
  string Ret;
  string Expr=InExpr;

  Rest=g_EmptyString;

  while (i<Expr.length())
  {
    while (strchr(" \t\r",Expr[i])) i++;
    switch (Expr[i])
    {
    case '!':
      if (i==Expr.length()-1)
      {
        i++; // to break out of the loop
        Ret=s_TrueString; /* the input was ! which means true */
      }
      else if (Expr[i+1]!='=')
      {
        Ret=ResolveExpression(Expr.substr(i+1),Expr);
        Ret = Ret.empty() || Ret==s_FalseString ? s_TrueString : g_EmptyString;
        i=0;
      }
      else
      {
        Ret = Ret!=ResolveExpression(Expr.substr(i+2),Expr) ? s_TrueString : g_EmptyString;
        i=0;
      }
      break;
    case '&':
      #ifdef _DEBUG
      if (i==Expr.length()-1)
      {
        throw(string("Error in expression near ")+Expr[i]+": "+InExpr);
      } else
      #endif
      if (Expr[i+1]!='&')
      {
        Ret+=Expr[i++];
      }
      else
      {
        Ret=AndExpression(Ret,ResolveExpression(Expr.substr(i+2),Expr));
        i=0;
      }
      break;
    case '|':
      #ifdef _DEBUG
      if (i==Expr.length()-1)
      {
        throw(string("Error in expression near ")+Expr[i]+": "+InExpr);
      } else
      #endif
      if (Expr[i+1]!='|')
      {
        Ret+=Expr[i++];
      }
      else
      {
        Ret=OrExpression(Ret,ResolveExpression(Expr.substr(i+2),Expr));
        i=0;
      }
      break;
    case '(':
      if (Ret=="defined")
      {
        Ret=IsDefined(ResolveExpression(Expr.substr(i+1),Expr)) ? s_TrueString : g_EmptyString;
      }
      else
      {
        Ret+=ResolveExpression(Expr.substr(i+1),Expr);
      }
      i=0;
      break;
    case ')':
      Rest=Expr.substr(i+1);
      return Ret;
      break;
    case '"':
      {
        i++;
        while (i<Expr.length())
        {
          char Char=Expr[i++];
          if (Char=='"')
            break;
          Ret+=Char;
        }
      }
      break;
    case '=':
      if (i==Expr.length()-1)
      {
        i++; // To break out of the loop
      }
      else
      if (Expr[i+1]!='=')
      {
        Ret+=Expr[i++];
      }
      else
      {
        Ret = Ret==ResolveExpression(Expr.substr(i+2),Expr) ? s_TrueString : g_EmptyString;
        i=0;
      }
      break;
    default:
      Ret+=Expr[i++];
      break;
    }
  }
  return Ret;
}