Ejemplo n.º 1
0
RC evalExpr(Record *record, Schema *schema, Expr *expr, Value **result) {
	Value *lIn;
	Value *rIn;
	MAKE_VALUE(*result, DT_INT, -1);

	switch (expr->type) {
	case EXPR_OP: {
		Operator *op = expr->expr.op;
		bool twoArgs = (op->type != OP_BOOL_NOT);
		//      lIn = (Value *) malloc(sizeof(Value));
		//    rIn = (Value *) malloc(sizeof(Value));

		CHECK(evalExpr(record, schema, op->args[0], &lIn));
		if (twoArgs)
			CHECK(evalExpr(record, schema, op->args[1], &rIn));

		switch (op->type) {
		case OP_BOOL_NOT:
			CHECK(boolNot(lIn, *result))
			;
			break;
		case OP_BOOL_AND:
			CHECK(boolAnd(lIn, rIn, *result))
			;
			break;
		case OP_BOOL_OR:
			CHECK(boolOr(lIn, rIn, *result))
			;
			break;
		case OP_COMP_EQUAL:
			CHECK(valueEquals(lIn, rIn, *result))
			;
			break;
		case OP_COMP_SMALLER:
			CHECK(valueSmaller(lIn, rIn, *result))
			;
			break;
		default:
			break;
		}

		// cleanup
		freeVal(lIn);
		if (twoArgs)
			freeVal(rIn);
	}
	break;
	case EXPR_CONST:
		CPVAL(*result, expr->expr.cons);
		break;
	case EXPR_ATTRREF:
		free(*result);
		CHECK(getAttr(record, schema, expr->expr.attrRef, result))
		;
		break;
	}

	return RC_OK;
}
Ejemplo n.º 2
0
//Produção BoolExp
ExpressionNode* boolExp(ExpressionNode* boolExprE){
       printf("BoolExp\n"); 
       ExpressionNode* boolOrVar  = boolOr(boolExprE);
       ExpressionNode* boolAndVar = boolAnd(boolOrVar);       
       return boolAndVar;
}