  In this work, we construct energy-efficient variable-to-fixed length (V2F),
fixed-to-variable length (F2V), and variable-to-variable length (V2V)
prefix-free codes, which are optimal (or near-optimal) in the sense that no (or
few) other codes with the size can achieve a smaller energy per code letter for
the same entropy rate. Under stringent constraints of 4096 entries or below per
codebook, the constructed codes yield an energy per code letter within a few
tenths of a dB of the unconstrained theoretic lower bound, across a wide range
of entropy rates with a very fine granularity. We also propose a framing method
that allows variable-length codes to be transmitted using a fixed-length frame.
The penalty caused by framing is studied using simulations and analysis,
showing that the energy per code letter is kept within 0.2 dB of the
unconstrained theoretic limit for some tested codes with a large frame length.
When framed prefix-free codes are used to implement probabilistic constellation
shaping (PCS) for communications in the additive white Gaussian noise channel,
simulations show that 1.1 dB and 0.65 dB of shaping gains are achieved relative
to uniform 8- and 16-quadrature amplitude modulation (QAM), respectively.
