Пример #1
0
string Parser::RelationExpression() {

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

    //    SimpleExpression,
    //    [ ( “<=” | “<” | “>=” | “>” | “==” | “!=” ),
    //     SimpleExpression ]

    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_AND, SYM_OR, SYM_ASSIGN, SYM_SEMICOLON, SYM_OPEN, SYM_SQ_OPEN, SYM_COMMA, SYM_CLOSE, (tokenType) - 1};

    static tokenType set[] = {SYM_LESS_EQ, SYM_LESS, SYM_GREATER_EQ, SYM_GREATER, SYM_EQUAL, SYM_NOT_EQ, (tokenType) -1};

    string type, type1;

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

        type = SimpleExpression();

        if ( memberOf(_lookAhead.getTokenType(), set) ) {

            //check to make sure both types of simpleexpression are numeric
            type = "i";

            if ( _lookAhead.getTokenType() == SYM_LESS_EQ ) {
                match(SYM_LESS_EQ);
            } else if( _lookAhead.getTokenType() == SYM_LESS) {
                match(SYM_LESS);
            } else if( _lookAhead.getTokenType() == SYM_GREATER_EQ ) {
                match(SYM_GREATER_EQ);
            } else if( _lookAhead.getTokenType() == SYM_GREATER ) {
                match(SYM_GREATER);
            } else if( _lookAhead.getTokenType() == SYM_EQUAL ) {
                match(SYM_EQUAL);
            } else if( _lookAhead.getTokenType() == SYM_NOT_EQ ) {
                match(SYM_NOT_EQ);
            }

            type1 = SimpleExpression();

            if(!((type == "f" && type1 == "i") ||
                    (type == "i" && type1 == "i") ||
                    (type == "f" && type1 == "f") ||
                    (type == "i" && type1 == "f"))) {
                _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Incompatible comparision", _lookAhead.getRow() , _lookAhead.getCol());
            }
        }
    }
    _message.print(DBUG, "PARSER: End of RelationExpression()\n");
    return type;
}
Пример #2
0
/*----------------------------------------------------------
 * AndExpression
 * Evaluate an AND expression
 *----------------------------------------------------------*/
static int AndExpression(s_token *token_p, bool skip)
{
   int match;
   
   match = SimpleExpression(token_p, skip);
   while (token_p->tt == T_AND) {
      NextToken(token_p, skip); /* Negative logic 0=true,  or is and */
      if (match!=0) {
         SimpleExpression(token_p, true); /* skip other for false */
      } else {
         match = SimpleExpression(token_p, skip);
      }
   }
   return match;
}
Пример #3
0
SimpleExpression Parser::simple_expression(){
	std::string field = id();
	enum Operator oper = op();
	std::string value = id_list();
	if (field == "" || oper == OP_BAD_OPERATOR || value == ""){
		std::cout << lexer->getLinenumber() << ": Error: Broken expression '" << field << "' '" << oper << "' '" << value <<"'\n"; 
		exit(1);
	}
	return SimpleExpression(field, oper, value);
}
Пример #4
0
/*----------------------------------------------------------
 * SimpleExpression
 *    Evalute a simple expression
 *    this can be a "expression"
 *         1) we can match with fnmatch()
 *         2) !expression
 *         3) (exp)
 *----------------------------------------------------------*/
static int SimpleExpression(s_token *token_p, bool skip)
{
   int match;
   if (token_p->tt==T_ERROR) {
      match = -1;
   } else if (token_p->tt == T_BRACEOPEN) {
      match = OrExpression(token_p, skip);
      if (token_p->tt != T_BRACECLOSE) {
         match = Error(token_p, T_BRACECLOSE); /*Indicate what I need? */
         return match;
      }
      NextToken(token_p, skip);
   } else if (token_p->tt == T_EXP)  {
      match=MatchPattern(token_p, skip);
      NextToken(token_p, skip);
   } else if (token_p->tt == T_NOT) {
      NextToken(token_p, skip);
      match = SimpleExpression(token_p, skip);
      match = !match;
   } else {
      match = Error(token_p, token_p->et);
   }
   return match;
}