================================================================================ P9315 M.G.J. van den Brand "Prettyprinting without losing comments" The problem of prettyprinting in generated programming environments is addressed. A practical solution for the prettyprinting process itself as well as for the handling of comments is given. A new box-language is presented for specifying prettyprint rules in an algebraic way. Both the syntax and the semantics of this box-language are formalized. Instead of designing and implementing a formatting machinery in for example C, the transformation from box-language to (prettyprinted) text is formally specified. This specification can be executed and its performance is surprisingly good. The box-language and its formatting algorithms suggest a general mechanism to prettyprint text with comments without losing the comments in the resulting text. There are no restrictions on the form of comments and places where comments may occur in the text. The method is not based on adaptions of the abstract syntax tree, but on modifications of the intermediate box-term that is built when a program is prettyprinted.