chapter9/s_expressions.c
lval eval_op(lval x, char* op, lval y){
	
    /* If either values is an error return it */
    if(x.type == LVAL_ERR){ return x; }
    if(y.type == LVAL_ERR){ return y; }

    if(strcmp(op,"+")==0){	return lval_num(x.num + y.num);	}
	if(strcmp(op,"-")==0){  return lval_num(x.num - y.num); }
	if(strcmp(op,"*")==0){  return lval_num(x.num * y.num); }
	if(strcmp(op,"/")==0){
    
        /* If second operand is zero return error */
        return y.num == 0 ? lval_err(LERR_DIV_ZERO):lval_num(x.num/y.num);
     }
	return lval_err(LERR_BAD_OP);
}
/* Use operator string to see which operation to perform */
Use operator string to see which operation to perform
Use operator string to see which operation to perform
lval eval_op(lval x, char* op, lval y){
    if(x.type == LVAL_ERR){ return x; }
    if(y.type == LVAL_ERR){ return y; }
    if(strcmp(op,"+")==0){	return lval_num(x.num + y.num);	}
	if(strcmp(op,"-")==0){  return lval_num(x.num - y.num); }
	if(strcmp(op,"*")==0){  return lval_num(x.num * y.num); }
	if(strcmp(op,"/")==0){
        return y.num == 0 ? lval_err(LERR_DIV_ZERO):lval_num(x.num/y.num);
     }
	return lval_err(LERR_BAD_OP);
}
lval eval_op ( lval x , char * op , lval y ) { if ( x . type == LVAL_ERR ) { return x ; } if ( y . type == LVAL_ERR ) { return y ; } if ( strcmp ( op , " " ) == 0 ) { return lval_num ( x . num + y . num ) ; } if ( strcmp ( op , " " ) == 0 ) { return lval_num ( x . num - y . num ) ; } if ( strcmp ( op , " " ) == 0 ) { return lval_num ( x . num * y . num ) ; } if ( strcmp ( op , " " ) == 0 ) { return y . num == 0 ? lval_err ( LERR_DIV_ZERO ) : lval_num ( x . num / y . num ) ; } return lval_err ( LERR_BAD_OP ) ; }
Use operator string to see which operation to perform
Use operator string to see which operation to perform
/* If either values is an error return it */ /* If second operand is zero return error */