An instantaneous D-ary code which minimizes the average codeword length for an information source is called a compact code. It is known that for a D-ary compact code with codeword lengths lscr1,lscr2,.....,lscrn (where n is the form of n=k(D-1)+1 for some positive integer k ), we have SigmaD-lscr i = 1 . Since construction of n D-ary codewords given codeword lengths lscr1,lscr2,.....,lscrn is a straight forward task, we generate all possible codeword length sequences. In this paper, we present an algorithm which gets all compact codes with k(D-1)+1 codewords and generates all compact codes with (k+1)(D-1)+1 codewords. Based on this algorithm, ST n(D), the supertree of all D-ary compact codes, is introduced. Any node in the m-th level of ST n(D) is associated with a unique compact code with 2D-1+m(D-1) codewords. Following the proposed approach, any D-ary compact code with n codewords can be represented by lceil(n-1)/(D-1)rceil-2 bits.