[comp.lang.misc] Programmable Pretty-Printer; Summary

sommar@enea.UUCP (Erland Sommarskog) (03/08/87)

A while ago I posted a request for information on programmable 
pretty-printers (PPP). I promised a summary which is the contents
of this article. My article also caused some discussion about the
concept as such. I have some comments to this which I have placed 
in a separate article.

First my thanks to all who responded. I'm extracting the most
important points from each response and adding my own comments
if I have any. General comment: I have received quite many references
to papers and articles. I haven't, this far, studied any of these.
 
Svante Lindahl (enea!ttds!zap) proposes indent, standard Unix-feature.
   He points on PASED and SIMED for Pascal and Simula. They run 
   TOPS 10/20. He also mentions (GNU)Emacs with its "electric" modes.
   Comments: It's quite clear from the man-page for indent that it is
   not sufficient. It doesn't for instance break long lines. PASED
   and SIMED are unknown to me. "Electric" are good when writing, but
   when I write I can usually format as I want. But, what can it do
   with code that already exists?
   
Anne Lomax (al@cs.nott.ac.uk) introduced me to PED, Program Editor, 
   written by her and John Wilson at Nottingham. It's works on any
   language with an EBNF-grammar (e.g. Pascal, Ada, C etc). It runs
   under Unix. If I understand her right, PED stores the programme
   in a tree-representation. For the display of the programme you 
   provide specification for the language and how to display it. This
   means you always read the programme in your own preferred style.
   Anne Lomax also refers to her thesis "PED: A Tree-Oriented Editor for 
   Programs", Nottingham, May 1983. PED is currently not marketed. 
   Comments: This sounds very useful. I just wonder how slow the editor
   is; she write nothing on that. (Also for me it's the wrong OS.)
   
Stan Shebs (shebs@utah-cs.UUCP) refers to a paper by Dick Waters, "User
   Format Control in a LISP Prettyprinter", published in the Oct 1983
   TOPLAS (vol. 5, no. 4).
   
Oliver Steele (steele@unc.cs.unc.edu) proposes vgrind, another standard
   Unix feature.
   Comment: Not even near the target. Vgrind formats for a printer. I want
   something that produces a text file for further edits. (Error corrections
   for example)
   
Fred Fish (mcdsun!fnf) have no own ideas. He wants to have the same as I,
   however he's mainly interested in C.
   Comment: Perhaps Anne Lomax could sell him a PED...
   
Lisa Rubin Neal (lisa@endor.harvard.edu) refers to a paper of her own:
   "Syntax-Directed Pretty Printing - A First Step Towards a Syntax-
   Directed Editor" published in Transactions on Software Engineering,
   March 1983. It describes a language-independent pretty-printer which
   is grammar-based.
   
Chris Henrich (cjh@petsd.UUCP) points to "Prettyprinting" in Transactions   
   on Programming Languages and Systems, October 1980.
   
Bob Devine (vianet!devine) claims to have what I need. It works for Pascal
  and runs under VMS, which was what I wanted. It comes from an old DECUS
  tape and is free. He also had an non-programmable pretty-printer for 
  Pascal which he have sent me. 
  Comment: I hope to get the first one from him too. I've looked at the code
  to the other one, and if it has formatted itself, it just confirms my
  thesis about the need of a PPP. It is really ugly from my point of view.
  (But it's good to have to look at if I ever write a PPP.)
  
Robert Garvey (blia!blic!garvey) refers to a book "PASCAL WITH STYLE:
  Programming Proverbs" by Ledgard/Hueras/Nagin, Hayden Book Company,
  ISBN 0-8104-5124-7. It has a pretty-printer in the appendix, but it
  is not programmable.
  
LSE (Language Sensitive Editor) is not a person but a product from DEC
  which they sell as layered software to VMS. Anne Lomax' PED inspired
  me to find out if this was the answer for me. I haven't read the 
  manuals, none the VAXes I have accounts have LSE. However it seems 
  to me that LSE works like the "electric" modes in Emacs. Thus, it 
  works on a text file. So the same question is valid for LSE as for 
  Emacs: Can it reformat existing code? (Well, of course they can;
  you can always write a (M)Lisp/VAXTPU programme for the task, that's
  about as much as work as write a non-PPP in a normal language.)
  
Erland Sommarskog
ENEA Data, Stockholm, Sweden
sommar@enea.UUCP