Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cbatt!ihnp4!ptsfa!lll-lcc!styx!ames!ucbcad!ucbvax!decvax!decwrl!pyramid!prls!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP Newsgroups: comp.lang.misc Subject: Re: The simplest way I know to PrettyPrint Message-ID: <667@mcgill-vision.UUCP> Date: Sat, 28-Feb-87 02:34:43 EST Article-I.D.: mcgill-v.667 Posted: Sat Feb 28 02:34:43 1987 Date-Received: Tue, 3-Mar-87 19:48:18 EST References: <366@esunix.UUCP> Organization: McGill University, Montreal Lines: 27 In article <366@esunix.UUCP>, bpendlet@esunix.UUCP (Bob Pendleton) writes: > The trouble with most pretty printers is that they try to get too > fancy. There is a fairly simple way to write a "programmable" pretty > printer. The trick is to use the keywords and punctuation symbols of > the language to trigger a set of actions in the pretty printer. > [basically, scan tokens and do things as you get them] > For instance the entry for "IF" might be something like. > NextLine; > Indent; > WriteToken; > IncrementIndent( 2 ); Except that this technique loses comments and formatting in the input. Doing the right thing with comments can be difficult. Doing the right thing when breaking expressions over multiple lines can be very difficult and in some cases impossible (eg, "len1+len2 + extra+1" versus "len1 + len2+extra + 1" - how do you tell which + signs should have spaces around them? It depends on how they group conceptually.). der Mouse USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!musocs!mcgill-vision!mouse think!mosart!mcgill-vision!mouse Europe: mcvax!decvax!utcsri!musocs!mcgill-vision!mouse ARPAnet: think!mosart!mcgill-vision!mouse@harvard.harvard.edu