This paper describes research carried out to develop a parametric urban shape grammar for the Zaouiat Lakhdar quarter of the Medina of Marrakech, in Morocco. The goal is to create the basis for a system that could capture some features of the existing urban fabric and apply them in contemporary urban planning. The methodology used is described, from the initial historical analysis and fieldwork to the identification of three sub-grammars necessary to encode the complexity of the urban pre-existences: the urban grammar, the negotiation grammar, and the housing grammar. Topdown and bottom-up approaches to grammar design are analyzed and compared. The bottom-up urban grammar developed is then described, and a hand-derivation of the existing urban fabric is proposed.