Shape grammars, a well-structured method of generating designs, are suitable for computer implementation. In this paper, a formal representation of shapes as individuals is developed; some binary operations and relations are then defined upon shapes. The formal mechanisms of shape grammars are presented, with some of the computational problems illustrated. Algorithms to solve some of these problems are given. A Prolog implementation of a generic shape grammar system is demonstrated.