We present a quantitative theory of nonlinear frequency conversion in stacks of crystals where the phase mismatch due to dispersion is compensated by changing the sign of the nonlinear coupling coefficient in successive crystals-a method first proposed by Armstrong et al. We include pump depletion in our calculations of the second harmonic generation and sum and difference frequency generation. We start with ideal stacks in which the crystal lengths are tailored to achieve perfect phase compensation. When the conversion in each coherence length is small, all crystal lengths tend to equal the coherence lengthpi/Deltak. Frequency conversion in such stacks is well approximated by that in an equivalent phase-matched crystal with the nonlinear coupling coefficient reduced by a factor of2/pi. The effect of systematic as well as random departures in crystal lengths are studied with special attention to the evolution of the relative phase. We show that with appropriate choice of the signs of the nonlinear coupling coefficient in various crystals, high efficiency frequency conversion should be possible using practically any sufficiently large set of nonlinear crystals. The theory of second harmonic generation in periodic stacks and in rotationally twinned crystals of zinc-blend structure is described in detail.