Expresion* Sintactico::_ParseRelationalExpression(Expresion* expr1)
{
	//Utilizamos Primeros( Relational-Operator )
	if ( proximo_token.GetTipo() == op_igual || proximo_token.GetTipo() == op_distinto || proximo_token.GetTipo() == op_menorque ||
		proximo_token.GetTipo() == op_mayorque || proximo_token.GetTipo() == op_menorigual || proximo_token.GetTipo() == op_mayorigual )
	{
		tipo_token op = ParseRelationalOperator();
		Expresion* expr2 = ParseSimpleExpression();

		switch ( op )
		{
		case op_igual:
			 return new ExprIgualQue(expr1,expr2);

		case op_distinto:
			return new ExprDistinto(expr1,expr2);

		case op_menorque:
			return new ExprMenorQue(expr1,expr2);

		case op_mayorque:
			return new ExprMayorQue(expr1,expr2);

		case op_menorigual:
			return new ExprMenorIgual(expr1,expr2);

		case op_mayorigual:
			return new ExprMayorIgual(expr1,expr2);
		}

	}

	return expr1;
}
Exemplo n.º 2
0
TPParseTreeNode CFormulaParser::ParseExpression() {
  int token_ID = _tokenizer.LookAhead();
  TPParseTreeNode expression;
  // Handle brackets before unary, because brackets are also "unary"
  if (TokenIsBracketOpen(token_ID))	{
		expression = ParseBracketExpression();
	}	else if (TokenIsUnary(token_ID))	{
		expression = ParseUnaryExpression();
	}	else if ((token_ID == kTokenIdentifier)
		  || (token_ID == kTokenNumber)) {
		expression = ParseSimpleExpression();
	}	else {
		CParseErrors::Error("Unexpected token inside expression.\n" 
      "Expecting: opening bracket, unary operator, identifier or number.\n");
		return NULL;
	}
	token_ID = _tokenizer.LookAhead();
	if (TokenIsBinary(token_ID)) {
		_tokenizer.GetToken();
    // Special handling of percentaged potsized bets,
    // that look like modulo or percentage operators,
    // but lack a 2nd operand and have "Force" instead.
    // When ... RaiseBy 60% Force
    if (token_ID == kTokenOperatorPercentage) {
      int next_token_ID = _tokenizer.LookAhead();
      if (next_token_ID == kTokenKeywordForce) {
        // Now we should pushback the *2nd last* token  (percentage)
        _tokenizer.PushBackAdditionalPercentageOperator();
        // and return the expression we got so far
        return expression;
      }
    }
		TPParseTreeNode second_expression = ParseExpression();
		TPParseTreeNode binary_node = new CParseTreeNode(_tokenizer.LineRelative());
		binary_node->MakeBinaryOperator(token_ID, 
			expression, second_expression);
		write_log(preferences.debug_parser(), 
			"[FormulaParser] Binary node %i\n", binary_node);
		return binary_node;
	} else if (token_ID == kTokenOperatorConditionalIf) {
		// Ternary condition
		TPParseTreeNode then_expression;
		TPParseTreeNode else_expression;
		ParseConditionalPartialThenElseExpressions(
			&then_expression, &else_expression);
		TPParseTreeNode ternary_node = new CParseTreeNode(_tokenizer.LineRelative());
		ternary_node->MakeTernaryOperator(token_ID,
			expression, then_expression, else_expression);
		write_log(preferences.debug_parser(), 
			"[FormulaParser] Ternary node %i\n", ternary_node);
		return ternary_node;
	}	else {
		// We got the complete expression
		// No complex binary or ternary condition
		write_log(preferences.debug_parser(), 
			"[FormulaParser] Expression %i\n", expression);
		return expression;
	}
}
Expresion* Sintactico::ParseRelationalExpression()
{
	Expresion* expr1 = ParseSimpleExpression();
	return _ParseRelationalExpression(expr1);
}