Interactive computer music is comparable to improvisation because it includes elements of real-time composition performed by the computer. This process of real-time composition often incorporates stochastic techniques that remap a predetermined fundamental structure to a surface of sound processing. The hierarchical structure is used to pose restrictions on the stochastic processes, but, in most cases, the hierarchical structure in itself is not created in real time. This article describes how existing musical analysis methods can be converted into generative compositional tools that allow composers to generate musical structures in real time. It proposes a compositional method based on generative grammars derived from Pierre Schaeffer's TARTYP, and describes the development of a compositional tool for real-time generation of Klumpenhouwer networks. The approach is based on the intersection of musical ideas with fundamental concepts in computer science including generative grammars, predicate logic, concepts of structural representation, and various methods of categorization.