  We combine the BCS self-consistency condition, a semiclassical expansion for
the spectral density and interaction matrix elements to describe analytically
how the superconducting gap depends on the size and shape of a 2d and 3d
superconducting grain. In chaotic grains mesoscopic fluctuations of the matrix
elements lead to a smooth dependence of the order parameter on the excitation
energy. In the integrable case we find shell effects i. e. for certain values
of the electron number $N$ a small change in N leads to large changes in the
energy gap. With regard to possible experimental tests we provide a detailed
analysis of the dependence of the gap on the coherence length and the
robustness of shell effects under small geometrical deformations.
