home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / TEXDISK / WEB.ZIP / EMTEX / TEXINPUT / WEBMAN.TEX (.txt) < prev   
LaTeX Document  |  1990-03-27  |  91KB  |  1,508 lines

  1. % WEB user manual -- last updated by D E Knuth on 4 Dec 89
  2. \input webmac
  3. \parskip 0pt plus 1pt
  4. \def\RA{\char'31 } % right arrow
  5. \def\hang{\hangindent 4em\ignorespaces}
  6. \font\ninerm=cmr9
  7. \font\ninett=cmtt9
  8. \font\eighttt=cmtt8
  9. \let\mc=\ninerm % medium caps for names like SAIL
  10. \def\PASCAL{Pascal}
  11. \font\quoterm=cmssq8
  12. \font\quoteit=cmssqi8
  13. \def\pb{\.{|...|}}
  14. \def\lpile{\def\cr{\hfill\endline}\matrix} % I only use \lpile by itself
  15. \outer\def\section #1.{\penalty-50\vskip 12pt plus 3pt minus 3pt
  16.   \noindent{\bf #1.}\quad\ignorespaces}
  17. \def\titlepage{T}
  18. \def\lheader{\mainfont\the\pageno\hfill\sc\runninghead\hfill}
  19. \def\rheader{\hfill\sc\runninghead\hfill\mainfont\the\pageno}
  20. \def\runninghead{{\tentt WEB} USER MANUAL}
  21. % This verbatim mode assumes that no ? appears in the text being copied.
  22. \def\verbatim{\begingroup
  23.   \def\do##1{\catcode`##1=12 } \dospecials
  24.   \parskip 0pt \parindent 0pt
  25.   \catcode`\ =13 \catcode`\^^M=13
  26.   \tt \catcode`\?=0 \verbatimdefs \verbatimgobble}
  27. {\catcode`\^^M=13{\catcode`\ =13\gdef\verbatimdefs{\def^^M{\ \par}\let =\ }} %
  28.   \gdef\verbatimgobble#1^^M{}}
  29. \centerline{\titlefont The {\ttitlefont WEB} System
  30.   of Structured Documentation}
  31. \vskip 15pt plus 3pt minus 3pt
  32. \noindent This memo describes how to write programs in the
  33. \.{WEB} language; and it also includes the full \.{WEB} documentation for
  34. \.{WEAVE} and \.{TANGLE}, the programs that read \.{WEB} input and produce
  35. \TeX\ and \PASCAL\ output, respectively. The philosophy behind \.{WEB} is
  36. that an experienced system programmer, who wants to provide the best
  37. possible documentation of his or her software products, needs two things
  38. simultaneously:  a language like \TeX\ for formatting, and a language like
  39. \PASCAL\ for programming. Neither type of language can provide the best
  40. documentation by itself; but when both are appropriately combined, we
  41. obtain a system that is much more useful than either language separately.
  42. The structure of a software program may be thought of as a ``web'' that is
  43. made up of many interconnected pieces. To document such a program, we want
  44. to explain each individual part of the web and how it relates to its
  45. neighbors. The typographic tools provided by \TeX\ give us an opportunity
  46. to explain the local structure of each part by making that structure
  47. visible, and the programming tools provided by \PASCAL\ make it possible
  48. for us to specify the algorithms formally and unambiguously. By combining
  49. the two, we can develop a style of programming that maximizes our ability
  50. to perceive the structure of a complex piece of software, and at the same
  51. time the documented programs can be mechanically translated into a working
  52. software system that matches the documentation.
  53. Since \.{WEB} is an experimental system developed for internal use within
  54. the \TeX\ project at Stanford, this report is rather terse, and it assumes
  55. that the reader is an experienced programmer who is highly motivated to
  56. read a detailed description of \.{WEB}'s rules. Furthermore, even if a
  57. less terse manual were to be written, the reader would have to be warned
  58. in advance that \.{WEB} is not for beginners and it never will be: The
  59. user of \.{WEB} must be familiar with both \TeX\ and \PASCAL. When one
  60. writes a \.{WEB} description of a software system, it is possible to make
  61. mistakes by breaking the rules of \.{WEB} and/or the rules of \TeX\ and/or
  62. the rules of \PASCAL. In practice, all three types of errors will occur,
  63. and you will get different error messages from the different language
  64. processors. In compensation for the sophisticated expertise needed to cope
  65. with such a variety of languages, however, experience has shown that
  66. reliable software can be created quite rapidly by working entirely in
  67. \.{WEB} from the beginning; and the documentation of such programs seems
  68. to be better than the documentation obtained by any other known method.
  69. Thus, \.{WEB} users need to be highly qualified, but they can get some
  70. satisfaction and perhaps even a special feeling of accomplishment when
  71. they have successfully created a software system with this method.
  72. To use \.{WEB}, you prepare a file called \.{COB.WEB} (say), and then you
  73. apply a system program called \.{WEAVE} to this file, obtaining an output
  74. file called \.{COB.TEX}.  When \TeX\ processes \.{COB.TEX}, your output
  75. will be a ``pretty printed'' version of \.{COB.WEB} that takes appropriate
  76. care of typographic details like page layout and the use of indentation,
  77. italics, boldface, etc.; this output will contain extensive cross-index
  78. information that is gathered automatically. You can also submit the same
  79. file \.{COB.WEB} to another system program called \.{TANGLE}, which will
  80. produce a file \.{COB.PAS} that contains the \PASCAL\ code of your \.{COB}
  81. program. The \PASCAL\ compiler will convert \.{COB.PAS} into
  82. machine-language instructions corresponding to the algorithms that were so
  83. nicely formatted by \.{WEAVE} and \TeX. Finally, you can (and should)
  84. delete the files \.{COB.TEX} and \.{COB.PAS}, because \.{COB.WEB} contains
  85. the definitive source code. Examples of the behavior of \.{WEAVE} and
  86. \.{TANGLE} are appended to this manual.
  87. Besides providing a documentation tool, \.{WEB} enhances the \PASCAL\
  88. language by providing a rudimentary macro capability together with the
  89. ability to permute pieces of the program text, so that a large system can
  90. be understood entirely in terms of small modules and their local
  91. interrelationships.  The \.{TANGLE} program is so named because it takes a
  92. given web and moves the modules from their web structure into the order
  93. required by \PASCAL; the advantage of programming in \.{WEB} is that the
  94. algorithms can be expressed in ``untangled'' form, with each module
  95. explained separately.  The \.{WEAVE} program is so named because it takes
  96. a given web and intertwines the \TeX\ and \PASCAL\ portions contained in
  97. each module, then it knits the whole fabric into a structured document.
  98. (Get it? Wow.)  Perhaps there is some deep connection here with the fact
  99. that the German word for ``weave'' is ``{\it web\/}'', and the
  100. corresponding Latin imperative is ``{\it texe\/}''!
  101. It is impossible to list all of the related work that has influenced the
  102. design of \.{WEB}, but the key contributions should be mentioned
  103. here.\quad (1)~Myrtle Kellington, as executive editor for ACM
  104. publications, developed excellent typographic standards for the
  105. typesetting of Algol programs during the 1960s, based on the original
  106. designs of Peter Naur; the subtlety and quality of this influential work
  107. can be appreciated only by people who have seen what happens when other
  108. printers try to typeset Algol without the advice of ACM's copy
  109. editors.\quad(2)~Bill McKeeman introduced a program intended to automate
  110. some of this task [Algorithm 268, ``Algol~60 reference language editor,''
  111. {\sl CACM \bf8} (1965), 667--668]; and a considerable flowering of such
  112. programs has occurred in recent years [see especially Derek Oppen,
  113. ``Prettyprinting,'' {\sl ACM TOPLAS \bf2} (1980), 465--483; G.~A. Rose and
  114. J. Welsh, ``Formatted programming languages,'' {\sl SOFTWARE Practice
  115. \char`\&\ Exper.\ \bf11} (1981), 651--669].\quad(3)~The top-down style of
  116. exposition encouraged by \.{WEB} was of course chiefly influenced by Edsger
  117. Dijkstra's essays on structured programming in the late 1960s. The less
  118. well known work of Pierre-Arnoul de Marneffe [``Holon programming: A
  119. survey,'' Univ.\ de Liege, Service Informatique, Liege, Belgium, 1973; 135
  120. pp.\null] also had a significant influence on the author as \.{WEB} was
  121. being formulated.\quad(4)~Edwin Towster has proposed a similar style of
  122. documentation in which the programmer is supposed to specify the relevant
  123. data structure environment in the name of each submodule [``A convention
  124. for explicit declaration of environments and top-down refinement of
  125. data,'' {\sl IEEE Trans.\ on Software Eng.\ \bf SE--5} (1979), 374--386];
  126. this requirement seems to make the documentation a bit too verbose,
  127. although experience with \.{WEB} has shown that any unusual control
  128. structure or data structure should definitely be incorporated into the
  129. module names on psychological grounds.\quad(5)~Discussions with Luis
  130. Trabb~Pardo in the spring of 1979 were extremely helpful for setting up a
  131. prototype version of \.{WEB} that was called \.{DOC}.\quad (6)~Ignacio
  132. Zabala's extensive experience with \.{DOC}, in which he created a full
  133. implementation of \TeX\ in \PASCAL\ that was successfully transported to
  134. many different computers, was of immense value while \.{WEB} was taking
  135. its present form.\quad(7)~David~R. Fuchs made several crucial suggestions
  136. about how to make \.{WEB} more portable; he and Arthur~L. Samuel
  137. coordinated the initial installations of \.{WEB} on dozens of computer
  138. systems, making changes to the code so that it would be acceptable to
  139. a wide variety of \PASCAL\ compilers.\quad(8)~The name \.{WEB} itself
  140. was chosen in honor of my wife's mother, Wilda Ernestine Bates.
  141. The appendices to this report contain complete \.{WEB} programs for the
  142. \.{WEAVE} and \.{TANGLE} processors. A study of these examples, together
  143. with an attempt to write \.{WEB} programs by yourself, is the best way
  144. to understand why \.{WEB} has come to be like it is.
  145. \section General rules.
  146. A \.{WEB} file is a long string of text that has been divided into
  147. individual lines. The exact line boundaries are not terribly crucial, and
  148. a programmer can pretty much chop up the \.{WEB} file in whatever way seems
  149. to look best as the file is being edited; but string constants and control
  150. texts must end on the same line on which they begin, since this convention
  151. helps to keep errors from propagating.  The end of a line means
  152. the same thing as a blank space.
  153. Two kinds of material go into \.{WEB} files: \TeX\ text and \PASCAL\ text.
  154. A programmer writing in \.{WEB} should be thinking both of the
  155. documentation and of the \PASCAL\ program that he or she is creating;
  156. i.e., the programmer should be instinctively aware of the different
  157. actions that \.{WEAVE} and \.{TANGLE} will perform on the \.{WEB} file.
  158. \TeX\ text is essentially copied without change by \.{WEAVE}, and it is
  159. entirely deleted by \.{TANGLE}, since the \TeX\ text is ``pure
  160. documentation.'' \PASCAL\ text, on the other hand, is formatted by
  161. \.{WEAVE} and it is shuffled around by \.{TANGLE}, according to rules that
  162. will become clear later. For now the important point to keep in mind is
  163. that there are two kinds of text. Writing \.{WEB} programs is something
  164. like writing \TeX\ documents, but with an additional ``\PASCAL\ mode''
  165. that is added to \TeX's horizontal mode, vertical mode, and math mode.
  166. A \.{WEB} file is built up from units called {\sl modules\/} that are more
  167. or less self-contained.  Each module has three parts:
  168. \yskip\item{1)} A \TeX\ part, containing explanatory material about what
  169. is going on in the module.
  170. \item{2)} A definition part, containing macro definitions that serve as
  171. abbreviations for \PASCAL\ constructions that would be less comprehensible
  172. if written out in full each time.
  173. \item{3)} A \PASCAL\ part, containing a piece of the program that
  174. \.{TANGLE} will produce. This \PASCAL\ code should ideally be about a
  175. dozen lines long, so that it is easily comprehensible as a unit and so
  176. that its structure is readily perceived.
  177. \yskip\noindent The three parts of each module must appear in this order;
  178. i.e., the \TeX\ commentary must come first, then the definitions, and
  179. finally the \PASCAL\ code. Any of the parts may be empty.
  180. \eject % page break inserted Dec 88
  181. A module begins with the pair of symbols `\.{@\ }' or `\.{@*}', where
  182. `\.{\ }' denotes a blank space. A module ends
  183. at the beginning of the next module (i.e., at the next
  184. `\.{@\ }' or `\.{@*}'), or at the end of the file, whichever comes first.
  185. The \.{WEB} file may also contain material that is not part of any module
  186. at all, namely the text (if any) that occurs before the first module.
  187. Such text is said to be ``in limbo''; it is ignored by \.{TANGLE}
  188. and copied essentially verbatim by \.{WEAVE}, so its function is to
  189. provide any additional formatting instructions that may be desired in the
  190. \TeX\ output. Indeed, it is customary to begin a \.{WEB} file with
  191. \TeX\ code in limbo that loads special fonts, defines special macros,
  192. changes the page sizes, and/or produces a title page.
  193. Modules are numbered consecutively, starting with 1; these numbers appear
  194. at the beginning of each module of the \TeX\ documentation, and they appear
  195. as bracketed comments at the beginning of the code generated by that
  196. module in the \PASCAL\ program.
  197. Fortunately, you never mention these numbers yourself when you are writing
  198. in \.{WEB}. You just say `\.{@\ }' or `\.{@*}' at the beginning of each
  199. new module, and the numbers are supplied automatically by \.{WEAVE} and
  200. \.{TANGLE}. As far as you are concerned, a module has a
  201. name instead of a number; such a name is specified by writing
  202. `\.{@<}' followed by \TeX\ text followed by `\.{@>}'. When \.{WEAVE}
  203. outputs a module name, it replaces the `\.{@<}' and `\.{@>}' by
  204. angle brackets and inserts the module number in small type. Thus, when you
  205. read the output of \.{WEAVE} it is easy to locate any module that is
  206. referred to in another module.
  207. For expository purposes, a module name should be a good description of the
  208. contents of that module, i.e., it should stand for the abstraction
  209. represented by the module; then the module can be ``plugged into'' one or
  210. more other modules so that the unimportant details of its inner workings
  211. are suppressed.  A module name therefore ought to be long enough to convey
  212. the necessary meaning. Unfortunately, however, it is laborious to type
  213. such long names over and over again, and it is also difficult to specify a
  214. long name twice in exactly the same way so that \.{WEAVE} and \.{TANGLE}
  215. will be able to match the names to the modules. Therefore a module name
  216. can be abbreviated after its first appearance in the \.{WEB} file, by
  217. typing `\.{@<$\alpha$...@>}', where $\alpha$ is any string that is a prefix of
  218. exactly one module name that appears in the file. For example, `\.{@<Clear
  219. the arrays@>}' can be abbreviated to `\.{@<Clear...@>}' if no other module
  220. name begins with the five letters `\.{Clear}'. Module names must otherwise
  221. match character for character, except that consecutive blank spaces and/or
  222. tab marks are treated as equivalent to single spaces, and such spaces are
  223. deleted at the beginning and end of the name. Thus, `\.{@< Clear { }the
  224. arrays @>}' will also match the name in the previous example.
  225. We have said that a module begins with `\.{@\ }' or `\.{@*}', but we
  226. didn't say how it gets divided up into a \TeX\ part, a definition part,
  227. and a \PASCAL\ part. The definition part begins with the first appearance
  228. of `\.{@d}' or `\.{@f}' in the module, and the \PASCAL\ part begins with
  229. the first appearance of `\.{@p}' or `\.{@<}'. The latter option `\.{@<}'
  230. stands for the beginning of a module name, which is the name of the module
  231. itself. An equals sign (\.=) must follow the `\.{@>}' at the end of this
  232. module name; you are saying, in effect, that the module name stands for
  233. the \PASCAL\ text that follows, so you say `$\langle\,$module
  234. name$\,\rangle=\null$\PASCAL\ text'. Alternatively, if the \PASCAL\ part
  235. begins with `\.{@p}' instead of a module name, the current module is said
  236. to be {\sl unnamed}. Note that module names cannot appear in the
  237. definition part of a module, because the first `\.{@<}' in a module
  238. signals the beginning of its \PASCAL\ part.  Any number of module names
  239. might appear in the \PASCAL\ part, however, once it has started.
  240. The general idea of \.{TANGLE} is to make a \PASCAL\ program out of these
  241. modules in the following way: First all the \PASCAL\ parts of unnamed
  242. modules are copied down, in order; this constitutes the initial
  243. approximation $T_0$ to the text of the program. (There should be at least
  244. one unnamed module, otherwise there will be no program.) Then all module
  245. names that appear in the initial text $T_0$ are replaced by the \PASCAL\
  246. parts of the corresponding modules, and this substitution process
  247. continues until no module names remain. Then all defined macros are
  248. replaced by their equivalents, according to certain rules that are
  249. explained later. The resulting \PASCAL\ code is ``sanitized'' so that it
  250. will be acceptable to an average garden-variety \PASCAL\ compiler; i.e.,
  251. lowercase letters are converted to uppercase, long identifiers are
  252. chopped, and the lines of the output file are constrained to be at most 72
  253. characters long.  All comments will have been removed from this \PASCAL\
  254. program except for the meta-comments delimited by `\.{@\{}' and
  255. `\.{@\}}', as explained below, and except for the module-number comments
  256. that point to the source location where each piece of the program text
  257. originated in the \.{WEB} file.
  258. If the same name has been given to more than one module, the \PASCAL\ text
  259. for that name is obtained by putting together all of the \PASCAL\ parts in
  260. the corresponding modules. This feature is useful, for example, in a
  261. module named `Global variables in the outer block', since one can then
  262. declare global variables in whatever modules those variables are
  263. introduced. When several modules have the same name, \.{WEAVE} assigns the
  264. first module number as the number corresponding to that name, and it
  265. inserts a note at the bottom of that module telling the reader to `See
  266. also sections so-and-so'; this footnote gives the numbers of all the other
  267. modules having the same name as the present one. The \PASCAL\ text
  268. corresponding to a module is usually formatted by \.{WEAVE} so that the
  269. output has an equivalence sign in place of the equals sign in the \.{WEB}
  270. file; i.e., the output says `$\langle\,$module
  271. name$\,\rangle\equiv\null$\PASCAL\ text'. However, in the case of the second
  272. and subsequent appearances of a module with the same name, this `$\equiv$'
  273. sign is replaced by `$\mathrel+\equiv$', as an indication that the \PASCAL\
  274. text that follows is being appended to the \PASCAL\ text of another
  275. module.
  276. The general idea of \.{WEAVE} is to make a \.{TEX} file from the \.{WEB}
  277. file in the following way: The first line of the \.{TEX} file will be
  278. `\.{\\input webmac}'; this will cause \TeX\ to read in the macros that
  279. define \.{WEB}'s documentation conventions. The next lines of the file
  280. will be copied from whatever \TeX\ text is in limbo before the first
  281. module.  Then comes the output for each module in turn, possibly
  282. interspersed with end-of-page marks.  Finally, \.{WEAVE} will generate a
  283. cross-reference index that lists each module number in which each \PASCAL\
  284. identifier appears, and it will also generate an alphabetized list
  285. of the module names, as well as a table of contents that
  286. shows the page and module numbers for each ``starred'' module.
  287. What is a ``starred'' module, you ask? A module that begins with `\.{@*}'
  288. instead of `\.{@\ }' is slightly special in that it denotes a new major
  289. group of modules. The `\.{@*}' should be followed by the title of this
  290. group, followed by a period. Such modules will always start on a new page
  291. in the \TeX\ output, and the group title will appear as a running headline
  292. on all subsequent pages until the next starred module. The title will also
  293. appear in the table of contents, and in boldface type at the beginning of
  294. its module. Caution:  Do not use \TeX\ control sequences in such titles,
  295. unless you know that the \.{webmac} macros will do the right thing with
  296. them. The reason is that these titles are converted to uppercase when
  297. they appear as running heads, and they are converted to boldface when they
  298. appear at the beginning of their modules, and they are also written out to
  299. a table-of-contents file used for temporary storage while \TeX\ is
  300. working; whatever control sequences you use must be meaningful in all
  301. three of these modes.
  302. The \TeX\ output produced by \.{WEAVE} for each module consists of
  303. the following: First comes the module number (e.g., `\.{\\M123.}'
  304. at the beginning of module 123, except that `\.{\\N}' appears in place of
  305. `\.{\\M}' at the beginning of a starred module). Then comes the
  306. \TeX\ part of the module, copied almost verbatim except as noted
  307. below. Then comes the definition part and the \PASCAL\ part, formatted
  308. so that there will be a little extra space between them if both are
  309. nonempty. The definition and \PASCAL\ parts are obtained by inserting
  310. a bunch of funny looking \TeX\ macros into the \PASCAL\ program; these
  311. macros handle typographic details about fonts and proper math spacing,
  312. as well as line breaks and indentation.
  313. When you are typing \TeX\ text, you will probably want to make frequent
  314. reference to variables and other quantities in your \PASCAL\ code, and you
  315. will want those variables to have the same typographic treatment
  316. when they appear in your text as when they appear in your
  317. program.  Therefore the \.{WEB} language allows you to get the effect of
  318. \PASCAL\ editing within \TeX\ text, if you place `\.|' marks before and
  319. after the \PASCAL\ material. For example, suppose you want to say something
  320. like this:
  321. $$\hbox{The characters are placed into \\{buffer}, which is a
  322. \&{packed} \&{array} $[1\to\|n]$ \&{of} \\{char}.}$$
  323. The \TeX\ text would look like this in your \.{WEB} file:
  324. $$\.{The characters are placed into |buffer|, which is a |packed
  325. array [1..n] of char|.}$$
  326. And \.{WEAVE} translates this into something you are glad you didn't have
  327. to type:
  328. $$\lpile{\.{The characters are placed into \\\\\{buffer\},}\cr
  329.   \.{which is a \\\&\{packed\}{ }\\\&\{array\}{ }\$
  330.     [1\\to\\|n]\${ }\\\&\{of\}{ }\\\\\{char\}.}\cr}$$
  331. Incidentally, the cross-reference index that \.{WEAVE} would make, in
  332. the presence of a comment like this, would include
  333. the current module number as one of the index entries for \\{buffer}
  334. \vadjust{\eject}% page break inserted Dec 88
  335. and \\{char}, even though \\{buffer} and \\{char}
  336. might not appear in the \PASCAL\ part of
  337. this module. Thus, the index covers references to identifiers in
  338. the explanatory comments as well as in the program itself; you will
  339. soon learn to appreciate this feature. However, the identifiers
  340. \&{packed} and \&{array} and \|n\ and \&{of\/} would not be indexed,
  341. because \.{WEAVE} does not make index entries for reserved words or
  342. single-letter identifiers. Such identifiers are felt to be so ubiquitous
  343. that it would be pointless to mention every place where they occur.
  344. Speaking of identifiers, the author of \.{WEB} thinks that
  345. \\{IdentifiersSeveralWordsLong} look terribly ugly when they mix
  346. uppercase and lowercase letters. He recommends that
  347. \\{identifiers\_several\_words\_long} be written with underline characters
  348. to get a much better effect. The actual identifiers sent to the \PASCAL\
  349. compiler by \.{TANGLE} will have such underlines removed, and \.{TANGLE}
  350. will check to make sure that two different identifiers do not become
  351. identical when this happens. (In fact, \.{TANGLE} even checks that
  352. the first seven characters of identifiers are unique, when lowercase
  353. letters have been converted to uppercase; the number seven in this
  354. constraint is more strict than \PASCAL's eight, and it can
  355. be changed if desired.) The \.{WEAVE} processor will properly
  356. alphabetize identifiers that have embedded underlines
  357. when it makes the index.
  358. Although a module begins with \TeX\ text and ends with \PASCAL\ text, we
  359. have noted that the dividing line isn't sharp, since \PASCAL\ text can be
  360. included in \TeX\ text if it is enclosed in `\pb'.  Conversely, \TeX\ text
  361. also appears frequently within \PASCAL\ text, because everything in
  362. comments (i.e., between left and right braces) is treated as \TeX\ text.
  363. Furthermore, a module name consists of \TeX\ text; thus, a \.{WEB} file
  364. typically involves constructions like `\.{if} \.x \.= \.0 \.{then}
  365. \.{@<Empty} \.{the} \.{|buffer|} \.{array@>}' where we go back and forth
  366. between \PASCAL\ and \TeX\ conventions in a natural way.
  367. \section Macros.
  368. A \.{WEB} programmer can define three kinds of macros to make the programs
  369. shorter and more readable:
  370. \yskip\hang`\.{@d} \\{identifier} \.= \\{constant}' defines a {\sl numeric\/}
  371. macro, allowing \.{TANGLE} to do rudimentary arithmetic.
  372. \yskip\hang`\.{@d} \\{identifier} \.{==} \PASCAL\ text' defines a {\sl
  373. simple\/} macro, where the identifier will be replaced by the \PASCAL\ text
  374. when \.{TANGLE} produces its output.
  375. \yskip\hang`\.{@d} \\{identifier}\.{(\#) ==} \PASCAL\ text' defines a
  376. {\sl parametric\/} macro, where the identifier will be replaced by the \PASCAL\
  377. text and where occurrences of \.{\#} in that \PASCAL\ text will be
  378. replaced by an argument.
  379. \yskip\noindent In all three cases, the identifier must have length greater
  380. than one; it must not be a single letter.
  381. Numeric macros are subject to the following restrictions:\quad
  382. (1)~The identifier must
  383. be making its first appearance in the \.{WEB} file;
  384. a numeric macro must be defined before it is used.\quad
  385. (2)~The right-hand side of the numeric definition must be made entirely from
  386. integer constants, numeric macros, preprocessed strings (see below), and
  387. plus~signs or minus signs.  No other operations or symbols are allowed,
  388. not even parentheses, except that \PASCAL-like comments (enclosed in
  389. braces) can appear. Indeed, comments are recommended, since it is usually
  390. wise to give a brief explanation of the significance of each identifier as
  391. it is defined.\quad
  392. (3)~The numeric value must be less than $2^{15}=32768$ in absolute value.
  393. (For larger values, you can use `\.{==}' in place of~`\.=', thus making use
  394. of a simple macro instead of a numeric one. Note, however, that simple
  395. macros sometimes have a different effect. For example, consider the three
  396. definitions `\.{@d n1=2 @d n2=2+n1 @d n3==2+n1}'; then `\.{x-n2}' will
  397. expand into `\.{x-4}', while `\.{x-n3}' will expand into `\.{x-2+2}' which
  398. is quite different! It is wise to include parentheses in non-numeric
  399. macros, e.g., `\.{@d n3==(2+n1)}', to avoid such errors.)
  400. When constants are connected by plus signs or minus
  401. signs in a \PASCAL\ program, \.{TANGLE} does the arithmetic before putting
  402. the constant into the output file. Therefore it is permissible to say, for
  403. example, `\&{array} $[0\,.\,.\,\\{size}-1]$' if \\{size} has been declared
  404. as a macro; note that \PASCAL\ doesn't allow this kind of compile-time
  405. arithmetic if \\{size} is a \&{constant} quantity in the program. Another
  406. use of \.{TANGLE}'s arithmetic is to make \&{case} statement labels such
  407. as `$\\{flag}+1$' legitimate. Of course, it is improper to change \.{2+2}
  408. into \.4 without looking at the surrounding context; many counterexamples
  409. exist, such as the phrases `\.{-2+2}', `\.{x/2+2}', and `\.{2+2E5}'.  The
  410. program for \.{TANGLE}, in the appendix, gives precise details about this
  411. conversion, which \.{TANGLE} does only when it is safe.
  412. The right-hand sides of simple and parametric macros
  413. are required to have balanced parentheses, and the \PASCAL\ texts of
  414. modules must have balanced parentheses too. Therefore when the argument
  415. to a para\-metric macro appears in parentheses, both parentheses
  416. will belong to the same \PASCAL\ text.
  417. The appendices to this report contain hundreds of typical examples of the
  418. usefulness of \.{WEB} macros, so it is not necessary to dwell on the
  419. subject here. However, the reader should know that \.{WEB}'s apparently
  420. primitive macro capabilities can actually do a lot of rather surprising
  421. things. Here is a construction that sheds further light on what is
  422. possible: After making the definitions
  423. $$\catcode`\#=12
  424. \lpile{\.{@d two\_cases(#)==case j of 1:#(1); 2:#(2); end}\cr
  425. \.{@d reset\_file(#)==reset(input\_file@\&#)}\cr}$$
  426. one can write `\.{two\_cases(reset\_file)}' and the resulting \PASCAL\
  427. output will be
  428. $$\.{case j of 1:reset(input\_file1); 2:reset(input\_file2); end}$$
  429. (but in uppercase letters and with \.\_'s removed).
  430. The `\.{@\&}' operation used here joins together two adjacent tokens
  431. into a single token, as explained later; otherwise the \PASCAL\ file would
  432. contain a space between \.{input\_file} and the digit that followed it.
  433. This trick can be used to provide the effect of an array of files, if you
  434. are unfortunate enough to have a \PASCAL\ compiler that doesn't allow such
  435. arrays.  Incidentally, the cross-reference index made by \.{WEAVE} from
  436. this example would contain the identifier \\{input\_file} but it would not
  437. contain \\{input\_file1} or \\{input\_file2}. Furthermore, \.{TANGLE}
  438. would not catch the error that \.{INPUTFILE1} and \.{INPUTFILE2} both
  439. begin with the same nine letters; one should be more careful when using
  440. `\.{@\&}'! But such aspects of the construction in this trick are
  441. peripheral to our main point, which is that a parametric macro name without
  442. arguments can be used as an argument to another parametric macro.
  443. Although \.{WEB}'s macros are allowed to have at most one parameter, the
  444. following example shows that this is not as much of a restriction as it
  445. may seem at first. Let \\{amac} and \\{bmac} be any parametric macros, and
  446. suppose that we want to get the effect of
  447. $$\catcode`\#=12
  448. \.{@d cmac(#1,#2) == amac(#1) bmac(#2)}$$
  449. which \.{WEB} doesn't permit. The solution is to make the definitions
  450. $$\catcode`\#=12
  451. \lpile{\.{@d cmac(#) == amac(#) dmac}\cr
  452. \.{@d dmac(#) == bmac(#)}\cr}$$
  453. and then to say `\.{cmac(x)(y)}'.
  454. There is one restriction in the generality of \.{WEB}'s parametric
  455. macros, however: the argument to a para\-metric macro must not come from
  456. the expansion of a macro that has not already been ``started.'' For
  457. example, here is one of the things \.{WEB} cannot handle:
  458. $$\catcode`\#=12
  459. \lpile{\.{@d arg == (p)}\cr
  460. \.{@d identity(#) == #}\cr
  461. \.{@p identity arg}\cr}$$
  462. In this case \.{TANGLE} will complain that the \.{identity} macro is not
  463. followed by an argument in parentheses.
  464. The \.{WEB} language has another feature that is somewhat similar to a
  465. numeric macro. A {\sl preprocessed string\/} is a string that is like
  466. a \PASCAL\ string but delimited by double-quote marks (\.") instead of
  467. single-quotes. Double-quote marks inside of such strings are indicated by
  468. giving two double-quotes in a row. If a preprocessed string is
  469. of length one (e.g., \.{"A"} or \.{""""}), it will be treated by \.{TANGLE}
  470. as equivalent to the corresponding ASCII-code integer (e.g., \.{65} or
  471. \.{34}). And if a preprocessed string is not of length one, it will be
  472. converted into an integer equal to 256 or more. A {\sl string pool\/}
  473. containing all such strings will be written out by the \.{TANGLE}
  474. processor; this string pool file consists of string 256, then string 257,
  475. etc., where each string is followed by an end-of-line and prefixed by two
  476. decimal digits that define its length.  Thus, for example, the empty string
  477. \.{""} would be represented in the string pool file by a line containing
  478. the two characters `\.{00}', while the string \.{"""String"""} would be
  479. represented by `\.{08"String"}'.  A given string appears at most once in
  480. the string pool; the use of such a pool makes it easier to cope with
  481. \PASCAL's restrictions on string manipulation. The string pool ends with
  482. `\.{*nnnnnnnnn}', where \.{nnnnnnnnn} is a decimal number
  483. called the {\sl string pool check sum}. If any string changes, the check
  484. sum almost surely changes too; thus, the `\.{@\$}' feature
  485. described below makes it possible for a program to assure itself that it
  486. is reading its own string pool.
  487. Here is a simple example that combines numeric macros with preprocessed
  488. strings of length one:
  489. $$\lpile{\.{@d upper\_case\_Y = "Y"}\cr
  490. \.{@d case\_difference = -"y"+upper\_case\_Y}\cr}$$
  491. The result is to define
  492. $\\{upper\_case\_Y}=89$, $\\{case\_difference}=-32$.
  493. \section Control codes.
  494. We have seen several magic uses of `\.{@}' signs in \.{WEB} files, and it
  495. is time to make a systematic study of
  496. these special features. A \.{WEB} {\sl control code\/}
  497. is a two-character combination of which the first is `\.@'.
  498. Here is a complete list of the legal control codes. The letters $L$, $T$,
  499. $P$, $M$, $C$, and/or $S$ following each code indicate whether or not that
  500. code is allowable in limbo, in \TeX\ text, in \PASCAL\ text, in module
  501. names, in comments, and/or in strings.  A bar over such a letter means
  502. that the control code terminates the present part of the \.{WEB} file; for
  503. example, $\overline L$ means that this control code ends the limbo material
  504. before the first module.
  505. \def\@#1[#2] {\yskip\hangindent 2em\noindent\.{@#1\unskip
  506.   \spacefactor1000{ }}$[#2]$\quad}
  507. \def\oP{\overline P}
  508. \def\oT{\overline T}
  509. \@@ [C,L,M,P,S,T] A double \.@ denotes the single character `\.@'. This is
  510. the only control code that is legal in limbo, in comments, and in strings.
  511. \@\ [\overline L,\oP,\oT] This denotes the beginning of a new
  512. (unstarred) module. A tab mark or end-of-line (carriage return)
  513. is equivalent to a space when it follows an \.@ sign.
  514. \@* [\overline L,\oP,\oT] This denotes the beginning of a new starred
  515. module, i.e., a module that begins a new major group. The title of the new
  516. group should appear after the \.{@*}, followed by a period. As explained
  517. above, \TeX\ control sequences should be avoided in such titles unless
  518. they are quite simple. When \.{WEAVE} and \.{TANGLE} read a \.{@*}, they
  519. print an asterisk followed by the current module number, so that the user
  520. can see some indication of progress. The very first module should be starred.
  521. \@d [\oP,\oT] Macro definitions begin with \.{@d} (or \.{@D}), followed by
  522. the \PASCAL\ text for one of the three kinds of macros, as explained
  523. earlier.
  524. \@f [\oP,\oT] Format definitions begin with \.{@f} (or \.{@F}); they cause
  525. \.{WEAVE} to treat identifiers in a special way when they appear in
  526. \PASCAL\ text. The general form of a format definition is `\.{@f} \|l \.{==}
  527. \|r', followed by an optional comment enclosed in braces, where \|l and \|r
  528. are identifiers; \.{WEAVE} will subsequently treat identifier \|l as it
  529. currently treats \|r. This feature allows a \.{WEB} programmer to invent
  530. new reserved words and/or to unreserve some of \PASCAL's reserved
  531. identifiers. The definition part of each module consists of any number of
  532. macro definitions (beginning with \.{@d}) and format definitions (beginning
  533. with \.{@f}), intermixed in any order.
  534. \@p [\oP,\oT] The \PASCAL\ part of an unnamed module begins with \.{@p}
  535. (or \.{@P}). This causes \.{TANGLE} to append the following \PASCAL\ code
  536. to the initial program text $T_0$ as explained above. The \.{WEAVE}
  537. processor does not cause a `\.{@p}' to appear explicitly in the \TeX\
  538. output, so if you are creating a \.{WEB} file based on a \TeX-printed
  539. \.{WEB} documentation you have to remember to insert \.{@p} in the
  540. appropriate places of the unnamed modules.
  541. \@< [P,\oT] A module name begins with \.{@<} followed by \TeX\ text followed
  542. by \.{@>}; the \TeX\ text should not contain any \.{WEB} control sequences
  543. except \.{@@}, unless these control sequences appear in \PASCAL\ text that
  544. is delimited by \pb. The module name may be abbreviated, after its first
  545. appearance in a \.{WEB} file, by giving any unique prefix followed by \.{...},
  546. where the three dots immediately precede the closing \.{@>}. No module name
  547. should be a prefix of another. Module names may not appear in \PASCAL\
  548. text that is enclosed in \pb, nor may they appear in the definition part
  549. of a module (since the appearance of a module name ends the definition
  550. part and begins the \PASCAL\ part).
  551. \@\' [P,T] This denotes an octal constant, to be formed from the
  552. succeeding digits. For example, if the \.{WEB} file contains `\.{@\'100}',
  553. the \.{TANGLE} processor will treat this an equivalent to `\.{64}';
  554. the constant will be formatted as ``\O{100}'' in the \TeX\ output
  555. produced via \.{WEAVE}. You should use octal notation only for positive
  556. constants; don't try to get, e.g., $-1$ by saying `\.{@\'777777777777}'.
  557. \@" [P,T] A hexadecimal constant; `\.{@"D0D0}' tangles to \.{53456} and
  558. weaves to `\H{D0D0}'.
  559. \@\$ [P] This denotes the string pool check sum.
  560. \@\{ [P] The beginning of a ``meta comment,'' i.e., a comment
  561. that is supposed to appear in the \PASCAL\ code, is indicated by
  562. \.{@\{} in the \.{WEB} file. Such delimiters can be used as
  563. isolated symbols in macros or modules, but they should be properly nested
  564. in the final \PASCAL\ program. The \.{TANGLE} processor will convert
  565. `\.{@\{}' into `\.\{' in the \PASCAL\ output file, unless
  566. the output is already part of a meta-comment; in the latter case
  567. `\.{@\{}' is converted into `\.[', since \PASCAL\ does not allow
  568. nested comments. Incidentally, module numbers are automatically inserted
  569. as meta-comments into the \PASCAL\ program, in order to help correlate the
  570. outputs of \.{WEAVE} and \.{TANGLE} (see Appendix~C\null). Meta-comments
  571. can be used to put conditional text into a \PASCAL\ program; this helps to
  572. overcome one of the limitations of \.{WEB}, since the simple macro
  573. processing routines of \.{TANGLE} do not include the dynamic evaluation of
  574. boolean expressions.
  575. \@\} [P] The end of a ``meta comment'' is indicated by `\.{@\}}'; this is
  576. converted either into `\.\}' or `\.{]}' in the \PASCAL\ output, according
  577. to the conventions explained for \.{@\{} above.
  578. \@\& [P] The \.{@\&} operation causes whatever is on its left to be
  579. adjacent to whatever is on its right, in the \PASCAL\ output. No spaces or
  580. line breaks will separate these two items. However, the thing on the left
  581. should not be a semicolon, since a line break might occur after a semicolon.
  582. \@\^ [P,T] The ``control text'' that follows, up to the next
  583. `\.{@>}', will be entered into the index together with the identifiers of
  584. the \PASCAL\ program; this text will appear in roman type. For example, to
  585. put the phrase ``system dependencies'' into the index, you can type
  586. `\.{@\^system dependencies@>}' in each module
  587. that you want to index as system dependent. A control text, like a string,
  588. must end on the same line of the \.{WEB} file as it began.  Furthermore,
  589. no \.{WEB} control sequences are allowed in a control text, not even
  590. \.{@@}. (If you need an \.{@} sign you can get around this restriction by
  591. typing `\.{\\AT!}'.)
  592. \@. [P,T] The ``control text'' that follows will be entered into the index
  593. in \.{typewriter} \.{type}; see the rules for `\.{@\^}', which is analogous.
  594. \@: [P,T] The ``control text'' that follows will be entered into the index
  595. in a format controlled by the \TeX\ macro `\.{\\9}', which the user
  596. should define as desired; see the rules for `\.{@\^}', which is analogous.
  597. \@t [P] The ``control text'' that follows, up to the next `\.{@>}', will
  598. be put into a \TeX\ \.{\\hbox} and formatted along with the neighboring
  599. \PASCAL\ program. This text is ignored by \.{TANGLE}, but it can be used
  600. for various purposes within \.{WEAVE}. For example, you can make comments
  601. that mix \PASCAL\ and classical mathematics, as in `$\\{size}<2^{15}$', by
  602. typing `\.{|size < @t\$2\^\{15\}\$@>|}'.  A control text must end on the
  603. same line of the \.{WEB} file as it began, and it may not contain any
  604. \.{WEB} control codes.
  605. \@= [P] The ``control text'' that follows, up to the next `\.{@>}', will
  606. be passed verbatim to the \PASCAL\ program.
  607. \@\\ [P] Force end-of-line here in the \PASCAL\ program file.
  608. \@! [P,T] The module number in an index entry will be underlined if `\.{@!}'
  609. immediately precedes the identifier or control text being indexed. This
  610. convention is used to distinguish the modules where an identifier is
  611. defined, or where it is explained in some special way, from the modules
  612. where it is used. A~reserved word or an identifier of length one will not
  613. be indexed except for underlined entries. An `\.{@!}' is implicitly inserted
  614. by \.{WEAVE} just after the reserved words \&{function}, \&{procedure},
  615. \&{program}, and \&{var}, and just after \.{@d} and \.{@f}. But you should
  616. insert your own `\.{@!}' before the definitions of types, constants,
  617. variables, parameters, and components of records and enumerated types that
  618. are not covered by this implicit convention, if you want to improve the
  619. quality of the index that you get.
  620. \@? [P,T] This cancels an implicit (or explicit) `\.{@!}', so that the next
  621. index entry will not be underlined.
  622. \@, [P] This control code inserts a thin space in \.{WEAVE}'s output; it is
  623. ignored by \.{TANGLE}. Sometimes you need this extra space if you are using
  624. macros in an unusual way, e.g., if two identifiers are adjacent.
  625. \@/ [P] This control code causes a line break to occur within a \PASCAL\
  626. program formatted by \.{WEAVE}; it is ignored by \.{TANGLE}. Line breaks
  627. are chosen automatically by \TeX\ according to a scheme that works 99\%\
  628. of the time, but sometimes you will prefer to force a line break so that
  629. the program is segmented according to logical rather than visual criteria.
  630. Caution: `\.{@/}' should be used only after statements or clauses, not in
  631. the middle of an expression; use \.{@|} in the middle of expressions, in
  632. order to keep \.{WEAVE}'s parser happy.
  633. \@| [P] This control code specifies an optional line break in the midst of
  634. an expression. For example, if you have a long condition between \&{if} and
  635. \&{then}, or a long expression on the right-hand side of an assignment
  636. statement, you can use `\.{@|}' to specify breakpoints more logical than
  637. the ones that \TeX\ might choose on visual grounds.
  638. \@\# [P] This control code forces a line break, like \.{@/} does,
  639. and it also causes a little extra white space to appear between the lines at
  640. this break. You might use it, for example, between procedure definitions or
  641. between groups of macro definitions that are logically separate but within
  642. the same module.
  643. \@+ [P] This control code cancels a line break that might otherwise be
  644. inserted by \.{WEAVE}, e.g., before the word `\&{else}', if you want to
  645. put a short if-then-else construction on a single line. It is ignored by
  646. \.{TANGLE}.
  647. \@; [P] This control code is treated like a semicolon, for formatting
  648. purposes, except that it is invisible. You can use it, for example, after
  649. a module name when the \PASCAL\ text represented by that module name ends
  650. with a semicolon.
  651. \yskip\noindent
  652. The last six control codes (namely `\.{@,}', `\.{@/}', `\.{@|}',
  653. `\.{@\#}', `\.{@+}', and `\.{@;}') have no effect on the \PASCAL\
  654. program output by \.{TANGLE}; they merely help to improve the readability
  655. of the \TeX-formatted \PASCAL\ that is output by \.{WEAVE}, in unusual
  656. circumstances. \.{WEAVE}'s built-in formatting method is fairly good, but
  657. it is incapable of handling all possible cases, because it must deal with
  658. fragments of text involving macros and module names; these fragments do
  659. not necessarily obey \PASCAL's syntax. Although \.{WEB} allows you to
  660. override the automatic formatting, your best strategy is not to worry
  661. about such things until you have seen what \.{WEAVE} produces automatically,
  662. since you will probably need to make only a few corrections when you are
  663. touching up your documentation.
  664. Because of the rules by which every module is broken into three parts,
  665. the control codes `\.{@d}', `\.{@f}', and `\.{@p}' are not allowed to occur
  666. once the \PASCAL\ part of a module has begun.
  667. \section Additional features and caveats.
  668. 1. The character pairs `\.{(*}', `\.{*)}', `\.{(.}', and `\.{.)}' are
  669. converted automatically in \PASCAL\ text as though they were
  670. `\.{@\{}', `\.{@\}}', `\.[', and `\.]', respectively, except
  671. of course in strings. Furthermore in certain installations of \.{WEB} that
  672. {\def\\#1#2{`{\tentex\char'#1#2}'}%
  673. have an extended character set, the characters \\32, \\34, \\35, \\30,
  674. \\36, \\04, \\37, \\05, and \\06}
  675. can be used as abbreviations for
  676. `\.{<>}', `\.{<=}', `\.{>=}', `\.{:=}', `\.{==}', `\.{and}', `\.{or}',
  677. `\.{not}', and `\.{in}', respectively. However, the latter abbreviations
  678. are not used in the standard versions of \.{WEAVE.WEB} and \.{TANGLE.WEB}
  679. that are distributed to people who are installing \.{WEB} on other
  680. computers, and the programs are designed to produce only standard ASCII
  681. characters as output if the input consists entirely of ASCII characters.
  682. 2. If you have an extended character set, all of the characters listed
  683. in Appendix C of {\sl The \TeX book\/} can be used in strings. But you should
  684. stick to standard ASCII characters if you want to write programs that will
  685. be useful to the all the poor souls out there who don't have extended
  686. character sets.
  687. 3. The \TeX\ file output by \.{WEAVE} is broken into lines having at most
  688. 80 characters each. The algorithm that does this line breaking is unaware
  689. of \TeX's convention about comments following `\.\%' signs on a line. When
  690. \TeX\ text is being copied, the existing line breaks are copied as well,
  691. so there is no problem with `\.\%' signs unless the original \.{WEB} file
  692. contains a line more than eighty characters long or a line with \PASCAL\
  693. text in \pb\ that expands to more than eighty characters long. Such lines
  694. should not have `\.\%' signs.
  695. 4. \PASCAL\ text is translated by a ``bottom up'' procedure that
  696. identifies each token as a ``part of speech'' and combines parts of speech
  697. into larger and larger phrases as much as possible according to a special
  698. grammar that is explained in the documentation of \.{WEAVE}. It is easy to
  699. learn the translation scheme for simple constructions like single
  700. identifiers and short expressions, just by looking at a few examples of
  701. what \.{WEAVE} does, but the general mechanism is somewhat complex because
  702. it must handle much more than \PASCAL\ itself. Furthermore the output
  703. contains embedded codes that cause \TeX\ to indent and break lines as
  704. necessary, depending on the fonts used and the desired page width. For
  705. best results it is wise to adhere to the following restrictions:
  706. \yskip\itemitem{a)}Comments in \PASCAL\ text should appear only after
  707. statements or clauses; i.e., after semicolons, after reserved words like
  708. \&{then} and \&{do}, or before reserved words like \&{end} and \&{else}.
  709. Otherwise \.{WEAVE}'s parsing method may well get mixed up.
  710. \itemitem{b)}Don't enclose long \PASCAL\ texts in \pb, since the
  711. indentation and line breaking codes are omitted when the \pb\ text is
  712. translated from \PASCAL\ to \TeX. Stick to simple expressions or
  713. statements.
  714. \yskip
  715. 5. Comments and module names are not permitted in \pb\ text. After a `\.|'
  716. signals the change from \TeX\ text to \PASCAL\ text, the next `\.|' that is
  717. not part of a string or control text ends the \PASCAL\ text.
  718. 6. A comment must have properly nested occurrences of left and right
  719. braces, otherwise \.{WEAVE} and \.{TANGLE} will not know where the comment
  720. ends. However, the character pairs `\.{\\\{}' and `\.{\\\}}' do not count
  721. as left and right braces in comments, and the character pair `\.{\\|}'
  722. does not count as a delimiter that begins \PASCAL\ text. (The actual rule
  723. is that a character after `\.\\' is ignored; hence in `\.{\\\\\{}' the
  724. left brace {\sl does\/} count.) At present, \.{TANGLE} and \.{WEAVE} treat
  725. comments in slightly different ways, and it is necessary to satisfy both
  726. conventions: \.{TANGLE} ignores `\.|' characters entirely, while \.{WEAVE}
  727. uses them to switch between \TeX\ text and \PASCAL\ text. Therefore, a
  728. comment that includes a brace in a string in \pb---e.g., `\.{\{{ }look at
  729. this |"\{"| \}}'---will be handled correctly by \.{WEAVE}, but \.{TANGLE}
  730. will think there is an unmatched left brace. In order to satisfy both
  731. processors, one can write `\.{\{{ }look at this \\leftbrace\\{ }\}}', after
  732. setting up`\.{\\def\\leftbrace\{|"\{"|\}}'.
  733. 7. Reserved words of \PASCAL\ must appear entirely in lowercase letters
  734. in the \.{WEB} file; otherwise their special nature will not be recognized
  735. by \.{WEAVE}. You could, for example, have a macro named \\{END} and it
  736. would not be confused with \PASCAL's \&{end}.
  737. However, you may not want to capitalize macro names just to distinguish them
  738. from other identifiers.  Here is a way to unreserve \PASCAL's reserved word
  739. `\&{type}' and to substitute another word `\&{mtype}' in the \.{WEB} file.
  740. $$\vbox{\halign{\tt #\hfil\cr
  741. @d type(\char'43) == mem[\char'43].t\cr
  742. @d mtype == t \char'100\char'46{} y \char'100\char'46{} p
  743.   \char'100\char'46{} e\cr
  744. @f mtype == type\cr
  745. @f type == true\cr}}$$
  746. In the output of \.{TANGLE}, the macro \.{mtype} now produces `\.{TYPE}'
  747. and the macro \.{type(x)} now produces `\.{MEM[X].T}'. In the output of
  748. \.{WEAVE}, these same inputs produce \&{mtype} and \\{type}(\|x),
  749. respectively.
  750. 8. The \.{@f} feature allows you to define one identifier to act like
  751. another, and these format definitions are carried out sequentially, as the
  752. example above indicates. However, a given identifier has only one printed format
  753. throughout the entire document (and this format will even be used before
  754. the \.{@f} that defines it). The reason is that \.{WEAVE} operates in two
  755. passes; it processes \.{@f}'s and cross-references on the first pass and
  756. does the output on the second.
  757. 9. You may want some \.{@f} formatting that doesn't correspond to any
  758. existing reserved word. In that case, \.{WEAVE} could be extended in a
  759. fairly obvious way to include new ``reserved words'' in its vocabulary.
  760. The identifier `\&{xclause}' has in fact been included already as a
  761. reserved word, so that it can be used to format the `\&{loop}' macro,
  762. where `\&{loop}' is defined to be equivalent to `\&{while \\{true} do}'.
  763. 10. Sometimes it is desirable to insert spacing into \PASCAL\ code that is
  764. more general than the thin space provided by `\.{@,}'. The \.{@t} feature
  765. can be used for this purpose; e.g., `\.{@t\\hskip 1in@>}' will
  766. leave one inch of blank space. Furthermore, `\.{@t\\4@>}' can be
  767. used to backspace by one unit of indentation, since the control sequence
  768. \.{\\4} is defined in \.{webmac} to be such a backspace. (This
  769. control sequence is used, for example, at the beginning of lines that
  770. contain labeled statements, so that the label will stick out a little at
  771. the left.)
  772. 11. \.{WEAVE} and \.{TANGLE} are designed to work with two input files,
  773. called \\{web\_file} and \\{change\_file}, where \\{change\_file} contains
  774. data that overrides selected portions of \\{web\_file}. The resulting merged
  775. text is actually what has been called the \.{WEB} file elsewhere in this
  776. report.
  777. Here's how it works: The change file consists of zero or more ``changes,''
  778. where a change has the form `\.{@x}$\langle$old lines$\rangle$\.{@y}$\langle$%
  779. new lines$\rangle$\.{@z}'. The special control codes \.{@x}, \.{@y}, \.{@z},
  780. which are allowed only in change files, must appear at the beginning of a line;
  781. the remainder of such a line is ignored.
  782. The $\langle$old lines$\rangle$ represent material that exactly matches
  783. consecutive lines of the \\{web\_file}; the $\langle$new lines$\rangle$
  784. represent zero or more lines that are supposed to replace the old. Whenever
  785. the first ``old line'' of a change is found to match a line in the
  786. \\{web\_file}, all the other lines in that change must match too.
  787. Between changes, before the first change, and after the last change,
  788. the change file can have any number of lines that do not begin with
  789. `\.{@x}', `\.{@y}', or~`\.{@z}'. Such lines are bypassed and not used for
  790. matching purposes.
  791. This dual-input feature is useful when working with a master \.{WEB} file
  792. that has been received from elsewhere (e.g., \.{TANGLE.WEB} or
  793. \.{WEAVE.WEB} or \.{TEX.WEB}), when changes are desirable to customize the
  794. program for your local computer system. You will be able to debug your
  795. system-dependent changes without clobbering the master web file; and once
  796. your changes are working, you will be able to incorporate them readily
  797. into new releases of the master web file that you might receive from time
  798. to time.
  799. \section Appendices.
  800. The basic ideas of \.{WEB} can be understood most easily by looking at
  801. examples of ``real'' programs. Appendix~A shows the \.{WEB} input that
  802. generated modules 55--59 of the \.{WEAVE} program; Appendix~B shows the
  803. corresponding \TeX\ code output by \.{WEAVE}; and Appendix~C shows excerpts
  804. from the corresponding \PASCAL\ code output by \.{TANGLE}.
  805. The complete webs for \.{WEAVE} and \.{TANGLE} appear as the bulk of this
  806. report, in Appendices D and~E. The reader should first compare Appendix~A
  807. to the corresponding portion of Appendix~D; then the same material should
  808. be compared to Appendices B and~C. Finally, if time permits, the reader may
  809. enjoy studying the complete programs in Appendices D and~E, since \.{WEAVE}
  810. and \.{TANGLE} contain several interesting aspects, and since an attempt
  811. has been made in these appendices to evolve a style of programming that
  812. makes good use of the \.{WEB} language.
  813. Finally, Appendix F is the `\.{webmac}' file that sets \TeX\ up to accept
  814. the output of \.{WEAVE}; Appendix~G discusses how to use some of its macros
  815. to vary the output formats; and Appendix~H discusses what needs to be done
  816. when \.{WEAVE} and \.{TANGLE} are installed in a new operating environment.
  817. \section Performance statistics.
  818. The programs in Appendices D and E will optionally keep statistics on
  819. how much memory they require. Here is what they once printed out when
  820. processing themselves:
  821. \def\pstat#1#2#3
  822. #4{\yskip\noindent\.{#1} applied to \.{#2} (cpu time #3 sec)\par
  823. \halign{\quad\tt##\hfil\cr#4}}
  824. \pstat{TANGLE}{TANGLE}{15}
  825. {Memory usage statistics:\cr
  826. 456 names, 215 replacement texts;\cr
  827. 3396+3361 bytes, 6685+7329+5805 tokens.\cr}
  828. \pstat{TANGLE}{WEAVE}{30}
  829. {Memory usage statistics:\cr
  830. 692 names, 339 replacement texts;\cr
  831. 4576+4294 bytes, 10184+9875+9150 tokens.\cr}
  832. \pstat{WEAVE}{TANGLE}{45}
  833. {Memory usage statistics: 478 names, 2045 cross references, 4159+3729 bytes;\cr
  834. parsing required 684 scraps, 1300 texts, 3766 tokens, 119 levels;\cr
  835. sorting required 34 levels.\cr}
  836. \pstat{WEAVE}{WEAVE}{65}
  837. {Memory usage statistics: 737 names, 3306 cross references, 4896+4962 bytes;\cr
  838. parsing required 684 scraps, 1300 texts, 3766 tokens, 119 levels;\cr
  839. sorting required 73 levels.\cr}
  840. \yskip\noindent The cpu time for \PASCAL\ to process \.{TANGLE.PAS} was
  841. approximately 13 seconds, and \.{WEAVE.PAS} took approximately 26 seconds;
  842. thus the tangling time was slightly more than the compiling time.  The cpu
  843. time for \TeX\ to process \.{TANGLE.TEX} was approximately 500 seconds,
  844. and \.{WEAVE.TEX} took approximately 750 seconds (i.e., about 7
  845. seconds per printed page, where these pages are substantially larger than
  846. the pages in a normal book). All cpu times quoted are for a DECsystem-10.
  847. \def\K{{\mc K}}
  848. The file \.{TANGLE.WEB} is about 125\K\ characters long; \.{TANGLE}
  849. reduces it to a file \.{TANGLE.PAS} whose size is about 42\K\ characters,
  850. while \.{WEAVE} expands it to a file \.{TANGLE.TEX} of about 185\K\null.
  851. The corresponding file sizes for \.{WEAVE.WEB}, \.{WEAVE.PAS}, and
  852. \.{WEAVE.TEX} are 180\K, 89\K, and 265\K.
  853. The much larger file \.{TEX.WEB} led to the following numbers:
  854. \pstat{TANGLE}{TEX}{110}
  855. {Memory usage statistics:\cr
  856. 3750 names, 1768 replacement texts;\cr
  857. 41895+41053 bytes, 42378+45074+41091 tokens.\cr}
  858. \pstat{WEAVE}{TEX}{270}
  859. {Memory usage statistics: 3412 names, 19699 cross references,
  860.   37900+40232 bytes;\cr
  861. parsing required 685 scraps, 1303 texts, 3784 tokens, 104 levels;\cr
  862. sorting required 52 levels.\cr}
  863. \yskip\noindent
  864. \PASCAL\ did \.{TEX.PAS} in about 75 seconds; \TeX\ did \.{TEX.TEX}
  865. in about 3600.
  866. % Here is a quotation that could not really be omitted
  867. \vfill
  868. {\baselineskip9pt
  869. \halign to\hsize{\hfil\quoteit#\tabskip 0pt plus 100pt&
  870.   \hfil\quoteit#\tabskip 0pt\cr
  871. O, what a tangled web we weave&
  872.   O, what a tangled WEB we weave\cr
  873. When first we practise to deceive!&
  874.   When \TeX\ we practise to conceive!\cr
  875. \noalign{\vskip 2pt}
  876. \quoterm ---SIR WALTER SCOTT, {\quoteit Marmion} 6:17 (1808)&
  877.   \quoterm ---RICHARD PALAIS (1982)\cr
  878. \eject
  879. \def\runninghead{APPENDIX A --- {\tentt WEB} FILE FORMAT}
  880. \section Appendix A.
  881. This excerpt from \.{WEAVE.WEB} produced modules 55--59 in Appendix~D.
  882. Note that some of the lines are indented to show the program structure.
  883. The indentation is ignored by \.{WEAVE} and \.{TANGLE}, but users find
  884. that \.{WEB} files are quite readable if they have some such indentation.
  885. \vskip 6pt
  886. \begingroup \def\tt{\eighttt} \baselineskip9pt
  887. % Note to myself: I had to remove SAIL characters from the file here!
  888. % Also tabs replaced by double-space. The changes were made in WEAVE source.
  889. \verbatim
  890. @* Searching for identifiers.
  891. The hash table described above is updated by the |id_lookup| procedure,
  892. which finds a given identifier and returns a pointer to its index in
  893. |byte_start|. The identifier is supposed to match character by character
  894. and it is also supposed to have a given |ilk| code; the same name may be
  895. present more than once if it is supposed to appear in the index with
  896. different typesetting conventions.
  897. If the identifier was not already present, it is inserted into the table.
  898. Because of the way \.{WEAVE}'s scanning mechanism works, it is most convenient
  899. to let |id_lookup| search for an identifier that is present in the |buffer|
  900. array. Two other global variables specify its position in the buffer: the
  901. first character is |buffer[id_first]|, and the last is |buffer[id_loc-1]|.
  902. @<Glob...@>=
  903. @!id_first:0..long_buf_size; {where the current identifier begins in the buffer}
  904. @!id_loc:0..long_buf_size; {just after the current identifier in the buffer}
  905. @!hash:array [0..hash_size] of sixteen_bits; {heads of hash lists}
  906. @ Initially all the hash lists are empty.
  907. @<Local variables for init...@>=
  908. @!h:0..hash_size; {index into hash-head array}
  909. @ @<Set init...@>=
  910. for h:=0 to hash_size-1 do hash[h]:=0;
  911. @ Here now is the main procedure for finding identifiers (and index
  912. entries).  The parameter |t| is set to the desired |ilk| code. The
  913. identifier must either have |ilk=t|, or we must have
  914. |t=normal| and the identifier must be a reserved word.
  915. @p function id_lookup(@!t:eight_bits):name_pointer; {finds current identifier}
  916. label found;
  917. var i:0..long_buf_size; {index into |buffer|}
  918. @!h:0..hash_size; {hash code}
  919. @!k:0..max_bytes; {index into |byte_mem|}
  920. @!w:0..ww-1; {row of |byte_mem|}
  921. @!l:0..long_buf_size; {length of the given identifier}
  922. @!p:name_pointer; {where the identifier is being sought}
  923. begin l:=id_loc-id_first; {compute the length}
  924. @<Compute the hash code |h|@>;
  925. @<Compute the name location |p|@>;
  926. if p=name_ptr then @<Enter a new name into the table at position |p|@>;
  927. id_lookup:=p;
  928. @ A simple hash code is used: If the sequence of
  929. ASCII codes is $c_1c_2\ldots c_m$, its hash value will be
  930. $$(2^{n-1}c_1+2^{n-2}c_2+\cdots+c_n)\,\bmod\,|hash_size|.$$
  931. @<Compute the hash...@>=
  932. h:=buffer[id_first]; i:=id_first+1;
  933. while i<id_loc do
  934.   begin h:=(h+h+buffer[i]) mod hash_size; incr(i);
  935.   end
  936. ?endgroup % end of verbatim mode
  937. \endgroup
  938. \vfill\eject
  939. \def\runninghead{APPENDIX B --- TRANSLATION BY {\tentt WEAVE}}
  940. \section Appendix B.
  941. This excerpt from \.{WEAVE.TEX} corresponds to Appendix A.
  942. % I've inserted \vfill's here at the blank lines, to squeeze this on one page!
  943. \begingroup \def\tt{\eighttt} \baselineskip9pt
  944. \verbatim
  945. ?vfill?verbatimgobble
  946. \N55.  Searching for identifiers.
  947. The hash table described above is updated by the \\{id\_lookup} procedure,
  948. which finds a given identifier and returns a pointer to its index in
  949. \\{byte\_start}. The identifier is supposed to match character by character
  950. and it is also supposed to have a given \\{ilk} code; the same name may be
  951. present more than once if it is supposed to appear in the index with
  952. different typesetting conventions.
  953. If the identifier was not already present, it is inserted into the table.
  954. ?vfill?verbatimgobble
  955. Because of the way \.{WEAVE}'s scanning mechanism works, it is most convenient
  956. to let \\{id\_lookup} search for an identifier that is present in the %
  957. \\{buffer}
  958. array. Two other global variables specify its position in the buffer: the
  959. first character is $\\{buffer}[\\{id\_first}]$, and the last is $\\{buffer}[%
  960. \\{id\_loc}-1]$.
  961. ?vfill?verbatimgobble
  962. \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  963. \4\\{id\_first}: \37$0\to\\{long\_buf\_size}$;\C{where the current identifier
  964. begins in the buffer}\6
  965. \4\\{id\_loc}: \37$0\to\\{long\_buf\_size}$;\C{just after the current
  966. identifier in the buffer}\7
  967. \4\\{hash}: \37\&{array} $[0\to\\{hash\_size}]$ \1\&{of}\5
  968. \\{sixteen\_bits};\C{heads of hash lists}\2\par
  969. ?vfill?verbatimgobble
  970. \M56. Initially all the hash lists are empty.
  971. ?vfill?verbatimgobble
  972. \Y\P$\4\X16:Local variables for initialization\X\mathrel{+}\S$\6
  973. \4\|h: \37$0\to\\{hash\_size}$;\C{index into hash-head array}\par
  974. ?vfill?verbatimgobble
  975. \M57. \P$\X10:Set initial values\X\mathrel{+}\S$\6
  976. \&{for} $\|h\K0\mathrel{\&{to}}\\{hash\_size}-1$ \1\&{do}\5
  977. $\\{hash}[\|h]\K0$;\2\par
  978. ?vfill?verbatimgobble
  979. \M58. Here now is the main procedure for finding identifiers (and index
  980. entries).  The parameter \|t is set to the desired \\{ilk} code. The
  981. identifier must either have $\\{ilk}=\|t$, or we must have
  982. $\|t=\\{normal}$ and the identifier must be a reserved word.
  983. ?vfill?verbatimgobble
  984. \Y\P\4\&{function}\1\  \37$\\{id\_lookup}(\|t:\\{eight\_bits})$: \37\\{name%
  985. \_pointer};\C{finds current identifier}\6
  986. \4\&{label} \37\\{found};\6
  987. \4\&{var} \37\|i: \37$0\to\\{long\_buf\_size}$;\C{index into \\{buffer}}\6
  988. \|h: \37$0\to\\{hash\_size}$;\C{hash code}\6
  989. \|k: \37$0\to\\{max\_bytes}$;\C{index into \\{byte\_mem}}\6
  990. \|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\_mem}}\6
  991. \|l: \37$0\to\\{long\_buf\_size}$;\C{length of the given identifier}\6
  992. \|p: \37\\{name\_pointer};\C{where the identifier is being sought}\2\6
  993. \&{begin} \37$\|l\K\\{id\_loc}-\\{id\_first}$;\C{compute the length}\6
  994. \X59:Compute the hash code \|h\X;\6
  995. \X60:Compute the name location \|p\X;\6
  996. \&{if} $\|p=\\{name\_ptr}$ \1\&{then}\5
  997. \X62:Enter a new name into the table at position \|p\X;\2\6
  998. $\\{id\_lookup}\K\|p$;\6
  999. \&{end};\par
  1000. ?vfill?verbatimgobble
  1001. \M59. A simple hash code is used: If the sequence of
  1002. ASCII codes is $c_1c_2\ldots c_m$, its hash value will be
  1003. $$(2^{n-1}c_1+2^{n-2}c_2+\cdots+c_n)\,\bmod\,\\{hash\_size}.$$
  1004. ?vfill?verbatimgobble
  1005. \Y\P$\4\X59:Compute the hash code \|h\X\S$\6
  1006. $\|h\K\\{buffer}[\\{id\_first}]$;\5
  1007. $\|i\K\\{id\_first}+1$;\6
  1008. \&{while} $\|i<\\{id\_loc}$ \1\&{do}\6
  1009. \&{begin} \37$\|h\K(\|h+\|h+\\{buffer}[\|i])\mathbin{\&{mod}}\\{hash\_size}$;\5
  1010. $\\{incr}(\|i)$;\6
  1011. \&{end}\2\par
  1012. \U section~58.\fi
  1013. ?endgroup
  1014. \endgroup
  1015. \eject
  1016. \def\runninghead{APPENDIX C --- TRANSLATION BY {\tentt TANGLE}}
  1017. \section Appendix C.
  1018. The \.{TANGLE} processor converts \.{WEAVE.WEB} into a syntactically
  1019. correct (but not very pretty) \PASCAL\ program \.{WEAVE.PAS}.
  1020. The first three and last two lines of output are shown here, together with the
  1021. lines of code generated by modules 55--62 and the environments of
  1022. those lines. There are 1559 lines in all; the notation
  1023. `\.. \\. \\.' stands for portions that are not shown.
  1024. Note that, for example, the code corresponding to
  1025. module 55 begins with `\.{\{55:\}}' and ends with `\.{\{:55\}}';
  1026. the code from modules 59--62 has been tangled into the code from module 58.
  1027. \vskip6pt
  1028. \verbatim
  1029. {2:}{4:}{$C-,A+,D-}{[$C+,D+]}{:4}
  1030. PROGRAM WEAVE(WEBFILE,CHANGEFILE,TEXFILE);LABEL 9999;CONST{8:}
  1031. MAXBYTES=45000;MAXNAMES=5000;MAXMODULES=2000;HASHSIZE=353;BUFSIZE=100;
  1032.      . . .
  1033. TOKPTR:0..MAXTOKS;{MAXTOKPTR,MAXTXTPTR:0..MAXTOKS;}{:53}{55:}
  1034. IDFIRST:0..LONGBUFSIZE;IDLOC:0..LONGBUFSIZE;
  1035. HASH:ARRAY[0..HASHSIZE]OF SIXTEENBITS;{:55}{63:}CURNAME:NAMEPOINTER;
  1036.      . . .
  1037. PROCEDURE INITIALIZE;VAR{16:}I:0..127;{:16}{40:}WI:0..1;{:40}{56:}
  1038. H:0..HASHSIZE;{:56}{247:}C:ASCIICODE;{:247}BEGIN{10:}HISTORY:=0;{:10}
  1039.      . . .
  1040. TOKPTR:=1;TEXTPTR:=1;TOKSTART[0]:=1;TOKSTART[1]:=1;{MAXTOKPTR:=1;
  1041. MAXTXTPTR:=1;}{:54}{57:}FOR H:=0 TO HASHSIZE-1 DO HASH[H]:=0;{:57}{94:}
  1042. SCANNINGHEX:=FALSE;{:94}{102:}MODTEXT[0]:=32;{:102}{124:}OUTPTR:=1;
  1043.      . . .
  1044. IF R=0 THEN XREF[P]:=XREFPTR ELSE XMEM[R].XLINKFIELD:=XREFPTR;END;{:51}
  1045. {58:}FUNCTION IDLOOKUP(T:EIGHTBITS):NAMEPOINTER;LABEL 31;
  1046. VAR I:0..LONGBUFSIZE;H:0..HASHSIZE;K:0..MAXBYTES;W:0..1;
  1047. L:0..LONGBUFSIZE;P:NAMEPOINTER;BEGIN L:=IDLOC-IDFIRST;{59:}
  1048. H:=BUFFER[IDFIRST];I:=IDFIRST+1;
  1049. WHILE I<IDLOC DO BEGIN H:=(H+H+BUFFER[I])MOD HASHSIZE;I:=I+1;END{:59};
  1050. {60:}P:=HASH[H];
  1051. WHILE P<>0 DO BEGIN IF(BYTESTART[P+2]-BYTESTART[P]=L)AND((ILK[P]=T)OR((T
  1052. =0)AND(ILK[P]>3)))THEN{61:}BEGIN I:=IDFIRST;K:=BYTESTART[P];W:=P MOD 2;
  1053. WHILE(I<IDLOC)AND(BUFFER[I]=BYTEMEM[W,K])DO BEGIN I:=I+1;K:=K+1;END;
  1054. IF I=IDLOC THEN GOTO 31;END{:61};P:=LINK[P];END;P:=NAMEPTR;
  1055. LINK[P]:=HASH[H];HASH[H]:=P;31:{:60};IF P=NAMEPTR THEN{62:}
  1056. BEGIN W:=NAMEPTR MOD 2;
  1057. IF BYTEPTR[W]+L>MAXBYTES THEN BEGIN WRITELN(TERMOUT);
  1058. WRITE(TERMOUT,'! Sorry, ','byte memory',' capacity exceeded');ERROR;
  1059. HISTORY:=3;JUMPOUT;END;
  1060. IF NAMEPTR+2>MAXNAMES THEN BEGIN WRITELN(TERMOUT);
  1061. WRITE(TERMOUT,'! Sorry, ','name',' capacity exceeded');ERROR;HISTORY:=3;
  1062. JUMPOUT;END;I:=IDFIRST;K:=BYTEPTR[W];
  1063. WHILE I<IDLOC DO BEGIN BYTEMEM[W,K]:=BUFFER[I];K:=K+1;I:=I+1;END;
  1064. BYTEPTR[W]:=K;BYTESTART[NAMEPTR+2]:=K;NAMEPTR:=NAMEPTR+1;ILK[P]:=T;
  1065. XREF[P]:=0;END{:62};IDLOOKUP:=P;END;{:58}{66:}
  1066. FUNCTION MODLOOKUP(L:SIXTEENBITS):NAMEPOINTER;LABEL 31;VAR C:0..4;
  1067.      . . .
  1068. WRITE(TERMOUT,'(That was a fatal error, my friend.)');END;END{:263};
  1069. END.{:261}
  1070. ?endgroup
  1071. \vfill\eject
  1072. \pageno=197 % take account of the page numbers for App's D and E.
  1073. \def\runninghead{APPENDIX F --- MACROS FOR FORMATTING}
  1074. \section Appendix F: The \.{webmac.tex} file.
  1075. This is the file that extends ``plain \TeX'' format in order to support the
  1076. features needed by the output of \.{WEAVE}.
  1077. \vskip6pt
  1078. \verbatim
  1079. % standard macros for WEB listings (in addition to PLAIN.TEX)
  1080. \xdef\fmtversion{\fmtversion+WEBMAC4.0} % identifies current set of macros
  1081. \parskip 0pt % no stretch between paragraphs
  1082. \parindent 1em % for paragraphs and for the first line of Pascal text
  1083. \font\eightrm=cmr8
  1084. \let\sc=\eightrm \let\mainfont=\tenrm
  1085. \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
  1086. \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
  1087. \font\tentex=cmtex10 % TeX extended character set (used in strings)
  1088. \def\\#1{\hbox{\it#1\/\kern.05em}} % italic type for identifiers
  1089. \def\|#1{\hbox{$#1$}} % one-letter identifiers look a bit better this way
  1090. \def\{\hbox{\bf#1\/}} % boldface type for reserved words
  1091. \def\.#1{\hbox{\tentex % typewriter type for strings
  1092.   \let\\=\BS % backslash in a string
  1093.   \let\'=\RQ % right quote in a string
  1094.   \let\`=\LQ % left quote in a string
  1095.   \let\{=\LB % left brace in a string
  1096.   \let\}=\RB % right brace in a string
  1097.   \let\~=\TL % tilde in a string
  1098.   \let\ =\SP % space in a string
  1099.   \let\_=\UL % underline in a string
  1100.   \let\&=\AM % ampersand in a string
  1101.   #1}}
  1102. \def\#{\hbox{\tt\char`\#}} % parameter sign
  1103. \def\${\hbox{\tt\char`\$}} % dollar sign
  1104. \def\%{\hbox{\tt\char`\%}} % percent sign
  1105. \def\^{\ifmmode\mathchar"222 \else\char`^ \fi} % pointer or hat
  1106. % circumflex accents can be obtained from \^^D instead of \^
  1107. \def\AT!{@} % at sign for control text
  1108. \chardef\AM=`\& % ampersand character in a string
  1109. \chardef\BS=`\\ % backslash in a string
  1110. \chardef\LB=`\{ % left brace in a string
  1111. \def\LQ{{\tt\char'22}} % left quote in a string
  1112. \chardef\RB=`\} % right brace in a string
  1113. \def\RQ{{\tt\char'23}} % right quote in a string
  1114. \def\SP{{\tt\char`\ }} % (visible) space in a string
  1115. \chardef\TL=`\~ % tilde in a string
  1116. \chardef\UL=`\_ % underline character in a string
  1117. \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
  1118. \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
  1119. \newcount\ind % current indentation in ems
  1120. \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
  1121. \def\2{\global\advance\ind by-1} % indent one less notch
  1122. \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
  1123. \def\4{\copy\bak} % backspace one notch
  1124. \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
  1125. \def\6{\ifmmode\else\par % forced break
  1126.   \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
  1127. \def\7{\Y\6} % forced break and a little extra space
  1128. \let\yskip=\smallskip
  1129. \def\to{\mathrel{.\,.}} % double dot, used only in math mode
  1130. \def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt\eightrm#1~#2.\par}}
  1131. \def\lapstar{\rlap{*}}
  1132. \def\startsection{\Q\noindent{\let\*=\lapstar\bf\modstar.\quad}}
  1133. \def\defin#1{\global\advance\ind by 2 \1\&{#1 }} % begin `define' or `format'
  1134. \def\A{\note{See also section}} % crossref for doubly defined section name
  1135. \def\As{\note{See also sections}} % crossref for multiply defined section name
  1136. \def\B{\mathopen{\.{@\{}}} % begin controlled comment
  1137. \def\C#1{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % Pascal comments
  1138.   \XX\hfil\penalty-1\hfilneg\quad$\{\,$#1$\,\}$\XX}
  1139. \def\D{\defin{define}} % macro definition
  1140. \def\E{\cdot10^} % exponent in floating point constant
  1141. \def\ET{ and~} % conjunction between two section numbers
  1142. \def\ETs{, and~} % conjunction between the last two of several section numbers
  1143. \def\F{\defin{format}} % format definition
  1144. \let\G=\ge % greater than or equal sign
  1145. \def\H#1{\hbox{\rm\char"7D\tt#1}} % hexadecimal constant
  1146. \let\I=\ne % unequal sign
  1147. \def\J{\.{@\&}} % TANGLE's join operation
  1148. \let\K=\gets % left arrow
  1149. \let\L=\le % less than or equal sign
  1150. \outer\def\M#1.{\MN#1.\ifon\vfil\penalty-100\vfilneg % beginning of section
  1151.   \vskip12ptminus3pt\startsection\ignorespaces}
  1152. \outer\def\N#1.#2.{\MN#1.\vfil\eject % beginning of starred section
  1153.   \def\rhead{\uppercase{\ignorespaces#2}} % define running headline
  1154.   \message{*\modno} % progress report
  1155.   \edef\next{\write\cont{\Z{#2}{\modno}{\the\pageno}}}\next % to contents file
  1156.   \ifon\startsection{\bf\ignorespaces#2.\quad}\ignorespaces}
  1157. \def\MN#1.{\par % common code for \M, \N
  1158.   {\xdef\modstar{#1}\let\*=\empty\xdef\modno{#1}}
  1159.   \ifx\modno\modstar \onmaybe \else\ontrue \fi \mark{\modno}}
  1160. \def\O#1{\hbox{\rm\char'23\kern-.2em\it#1\/\kern.05em}} % octal constant
  1161. \def\P{\rightskip=0pt plus 100pt minus 10pt % go into Pascal mode
  1162.   \sfcode`;=3000
  1163.   \pretolerance 10000
  1164.   \hyphenpenalty 10000 \exhyphenpenalty 10000
  1165.   \global\ind=2 \1\ \unskip}
  1166. \def\Q{\rightskip=0pt % get out of Pascal mode
  1167.   \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 }
  1168. \let\R=\lnot % logical not
  1169. \let\S=\equiv % equivalence sign
  1170. \def\T{\mathclose{\.{@\}}}} % terminate controlled comment
  1171. \def\U{\note{This code is used in section}} % crossref for use of a section
  1172. \def\Us{\note{This code is used in sections}} % crossref for uses of a section
  1173. \let\V=\lor % logical or
  1174. \let\W=\land % logical and
  1175. \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % section name
  1176.   \XX$\langle\,$#2{\eightrm\kern.5em#1}$\,\rangle$\XX}
  1177. \def\Y{\par\yskip}
  1178. \let\Z=\let % now you can \send the control sequence \Z
  1179. \def\){\hbox{\.{@\$}}} % sign for string pool check sum
  1180. \def\]{\hbox{\.{@\\}}} % sign for forced line break
  1181. \def\=#1{\kern2pt\hbox{\vrule\vtop{\vbox{\hrule
  1182.         \hbox{\strut\kern2pt\.{#1}\kern2pt}}
  1183.       \hrule}\vrule}\kern2pt} % verbatim string
  1184. \let\~=\ignorespaces
  1185. \let\*=*
  1186. \def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
  1187. \newif\ifon \newif\iftitle \newif\ifpagesaved
  1188. \def\lheader{\mainfont\the\pageno\eightrm\qquad\rhead\hfill\title\qquad
  1189.   \tensy x\mainfont\topmark} % top line on left-hand pages
  1190. \def\rheader{\tensy x\mainfont\topmark\eightrm\qquad\title\hfill\rhead
  1191.   \qquad\mainfont\the\pageno} % top line on right-hand pages
  1192. \def\page{\box255 }
  1193. \def\normaloutput#1#2#3{\ifodd\pageno\hoffset=\pageshift\fi
  1194.   \shipout\vbox{
  1195.     \vbox to\fullpageheight{
  1196.       \iftitle\global\titlefalse
  1197.       \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
  1198.       \vfill#1}} % parameter #1 is the page itself
  1199.   \global\advance\pageno by1}
  1200. \def\rhead{\.{WEB} OUTPUT} % this running head is reset by starred sections
  1201. \def\title{} % an optional title can be set by the user
  1202. \def\topofcontents{\centerline{\titlefont\title}
  1203.   \vfill} % this material will start the table of contents page
  1204. \def\botofcontents{\vfill} % this material will end the table of contents page
  1205. \def\contentspagenumber{0} % default page number for table of contents
  1206. \newdimen\pagewidth \pagewidth=6.5in % the width of each page
  1207. \newdimen\pageheight \pageheight=8.7in % the height of each page
  1208. \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
  1209. \newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
  1210. \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
  1211.   \fullpageheight=9truein\setpage}
  1212. \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
  1213. \def\contentsfile{CONTENTS} % file that gets table of contents info
  1214. \def\readcontents{\input CONTENTS}
  1215. \newwrite\cont
  1216. \output{\setbox0=\page % the first page is garbage
  1217.   \openout\cont=\contentsfile
  1218.   \global\output{\normaloutput\page\lheader\rheader}}
  1219. \setpage
  1220. \vbox to \vsize{} % the first \topmark won't be null
  1221. \def\ch{\note{The following sections were changed by the change file:}
  1222.   \let\*=\relax}
  1223. \newbox\sbox % saved box preceding the index
  1224. \newbox\lbox % lefthand column in the index
  1225. \def\inx{\par\vskip6pt plus 1fil % we are beginning the index
  1226.   \write\cont{} % ensure that the contents file isn't empty
  1227.   \closeout\cont % the contents information has been fully gathered
  1228.   \output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
  1229.     \global\setbox\sbox=\page \global\pagesavedtrue}
  1230.   \pagesavedfalse \eject % eject the page-so-far and predecessors
  1231.   \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
  1232.   \vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
  1233.   \hsize=.5\pagewidth \advance\hsize by -10pt
  1234.     % column width for the index (20pt between cols)
  1235.   \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
  1236.   \def\lr{L} % this tells whether the left or right column is next
  1237.   \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
  1238.     \else\normaloutput{\vbox to\pageheight{\box\sbox\vss
  1239.         \hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
  1240.     \global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
  1241.   \message{Index:}
  1242.   \parskip 0pt plus .5pt
  1243.   \outer\def\:##1, {\par\hangindent2em\noindent##1:\kern1em} % index entry
  1244.   \let\ttentry=\. \def\.##1{\ttentry{##1\kern.2em}} % give \tt a little room
  1245.   \def\[##1]{$\underline{##1}$} % underlined index item
  1246.   \rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
  1247.   \hyphenpenalty 10000 \parindent0pt}
  1248. \def\fin{\par\vfill\eject % this is done when we are ending the index
  1249.   \ifpagesaved\null\vfill\eject\fi % output a null index column
  1250.   \if L\lr\else\null\vfill\eject\fi % finish the current page
  1251.   \parfillskip 0pt plus 1fil
  1252.   \def\rhead{NAMES OF THE SECTIONS}
  1253.   \message{Section names:}
  1254.   \output{\normaloutput\page\lheader\rheader}
  1255.   \setpage
  1256.   \def\note##1##2.{\hfil\penalty-1\hfilneg\quad{\eightrm##1 ##2.}}
  1257.   \linepenalty=10 % try to conserve lines
  1258.   \def\U{\note{Used in section}} % crossref for use of a section
  1259.   \def\Us{\note{Used in sections}} % crossref for uses of a section
  1260.   \def\:{\par\hangindent 2em}\let\*=*\let\.=\ttentry}
  1261. \def\con{\par\vfill\eject % finish the section names
  1262.   \rightskip 0pt \hyphenpenalty 50 \tolerance 200
  1263.   \setpage
  1264.   \output{\normaloutput\page\lheader\rheader}
  1265.   \titletrue % prepare to output the table of contents
  1266.   \pageno=\contentspagenumber \def\rhead{TABLE OF CONTENTS}
  1267.   \message{Table of contents:}
  1268.   \topofcontents
  1269.   \line{\hfil Section\hbox to3em{\hss Page}}
  1270.   \def\Z##1##2##3{\line{\ignorespaces##1
  1271.     \leaders\hbox to .5em{.\hfil}\hfil\ ##2\hbox to3em{\hss##3}}}
  1272.   \readcontents\relax % read the contents info
  1273.   \botofcontents \end} % print the contents page(s) and terminate
  1274. ?endgroup
  1275. \vfill\eject
  1276. \def\runninghead{APPENDIX G --- NOTES ON FORMATTING}
  1277. \section Appendix G: How to use \.{WEB} macros.
  1278. The macros in \.{webmac} make it possible to produce a variety of formats
  1279. without editing the output of \.{WEAVE}, and the purpose of this appendix
  1280. is to explain some of the possibilities.
  1281. \def\point#1.{\yskip\indent#1.\quad\ignorespaces}
  1282. \point 1. Three fonts have been declared in addition to the standard fonts of
  1283. \.{PLAIN} format: You can say `\.{\{\\sc stuff\}}' to get {\sc STUFF}
  1284. in small caps; and you can select the largish fonts \.{\\titlefont}
  1285. and \.{\\ttitlefont} in the title of your document, where \.{\\ttitlefont}
  1286. is a typewriter style of type.
  1287. \point 2. When you mention an identifier in \TeX\ text, you normally call
  1288. it `\.{|identifier|}'. But you can also say `\.{\\\\\{identifier\}}'. The
  1289. output will look the same in both cases, but the second alternative
  1290. doesn't put \\{identifier} into the index, since
  1291. it bypasses \.{WEAVE}'s translation from \PASCAL\ mode.
  1292. \point 3. To get typewriter-like type, as when referring to `\.{WEB}', you
  1293. can use the `\.{\\.}' macro (e.g., `\.{\\.\{WEB\}}'). In the argument to
  1294. this macro you should insert an additional backslash before the symbols
  1295. listed as `special string characters' in the index to \.{WEAVE}, i.e.,
  1296. before backslashes and dollar signs and the like.
  1297. A `\.{\\\ }' here will result in the visible space symbol; to get an
  1298. invisible space following a control sequence you can say `\.{\{\ \}}'.
  1299. \point 4. The three control sequences \.{\\pagewidth}, \.{\\pageheight},
  1300. and \.{\\fullpageheight} can be redefined in the limbo section at the
  1301. beginning of your \.{WEB} file, to change the dimensions of each page.
  1302. The standard settings
  1303. $$\lpile{\.{\\pagewidth=6.5in}\cr
  1304.   \.{\\pageheight=8.7in}\cr
  1305.   \.{\\fullpageheight=9in}\cr}$$
  1306. were used to prepare the present report; \.{\\fullpageheight} is
  1307. \.{\\pageheight} plus room for the additional heading and page numbers at
  1308. the top of each page. If you change any of these quantities, you should
  1309. call the macro \.{\\setpage} immediately after making the change.
  1310. \point 5. The \.{\\pageshift} macro defines an amount by which right-hand
  1311. pages (i.e., odd-numbered pages) are shifted right with respect to
  1312. left-hand (even-numbered) ones. By adjusting this amount you may be
  1313. able to get two-sided output in which the page numbers line up on
  1314. opposite sides of each sheet.
  1315. \point 6. The \.{\\title} macro will appear at the top of each page
  1316. in small caps. For example, Appendix~D was produced after saying
  1317. `\.{\\def\\title\{WEAVE\}}'.
  1318. \point 7. The first page usually is number 1; if you want some other
  1319. starting page, just set \.{\\pageno} to the desired number. For example,
  1320. the initial limbo section for Appendix~D included the command
  1321. `\.{\\pageno=16}'.
  1322. \point 8. The macro \.{\\iftitle} will suppress the header line if it is
  1323. defined by `\.{\\titletrue}'. The normal value is \.{\\titlefalse}
  1324. except for the table of contents; thus, the contents
  1325. page is usually unnumbered. If your program is so long that the table of
  1326. contents doesn't fit on a single page, or if you want a number to appear
  1327. on the contents page, you should reset \.{\\pageno} when you begin the
  1328. table of contents.
  1329. Two macros are provided to give flexibility to the table of
  1330. contents: \.{\\topofcontents} is invoked just before the contents
  1331. info is read, and \.{\\botofcontents} is invoked just after.
  1332. For example, Appendix~D was produced with the following definitions:
  1333. $$\lpile{\.{\\def\\topofcontents\{\\null\\vfill}\cr
  1334.   \.{ { }\\titlefalse \% include headline on the contents page}\cr
  1335.   \.{ { }\\def\\rheader\{\\mainfont Appendix D\\hfil 15\}}\cr
  1336.   \.{ { }\\centerline\{\\titlefont The \{\\ttitlefont WEAVE\}{ }processor\}}\cr
  1337.   \.{ { }\\vskip 15pt \\centerline\{(Version 4)\}{ }\\vfill\}}\cr}$$
  1338. Redefining \.{\\rheader}, which is the headline for right-hand pages,
  1339. suffices in this case to put the desired information at the top of the page.
  1340. \point 9. Data for the table of contents is written to a file that
  1341. is read after the indexes have been \TeX ed; there's one line of data
  1342. for every starred module. For example, when Appendix~D was being generated,
  1343. a file \.{CONTENTS.TEX} containing
  1344. $$\lpile{\.{\\Z \{{ }Introduction\}\{1\}\{16\}}\cr
  1345.   \.{\\Z \{{ }The character set\}\{11\}\{19\}}\cr}$$
  1346. and similar lines was created. The \.{\\topofcontents} macro could
  1347. redefine \.{\\Z} so that the information appears in another format.
  1348. \point 10. Sometimes it is necessary or desirable to divide the output of
  1349. \.{WEAVE} into subfiles that can be processed separately. For example,
  1350. the listing of \TeX\ runs to more than 500 pages, and that is enough to
  1351. exceed the capacity of many printing devices and/or their software.
  1352. When an extremely large job isn't cut into smaller pieces, the entire
  1353. process might be spoiled by a single error of some sort, making it
  1354. necessary to start everything over.
  1355. Here's a safe way to break a woven file into three parts:
  1356. Say the pieces are $\alpha$,
  1357. $\beta$, and $\gamma$, where each piece begins with a starred module.
  1358. All macros should be defined in the opening limbo section of $\alpha$,
  1359. and copies of this \TeX\ code should be placed at the
  1360. beginning of $\beta$ and of $\gamma$. In order to process the parts
  1361. separately, we need to take care of two things: The starting page
  1362. numbers of $\beta$ and $\gamma$ need to be set up properly, and
  1363. the table of contents data from all three runs needs to be
  1364. accumulated.
  1365. The \.{webmac} macros include two control sequences \.{\\contentsfile} and
  1366. \.{\\readcontents} that facilitate the necessary processing.  We include
  1367. `\.{\\def\\contentsfile\{CONT1\}}' in the limbo section of $\alpha$, and
  1368. we include `\.{\\def\\contentsfile\{CONT2\}}' in the limbo section of
  1369. $\beta$; this causes \TeX\ to write the contents data for $\alpha$ and $\beta$
  1370. into \.{CONT1.TEX} and \.{CONT2.TEX}. Now in $\gamma$ we say
  1371. $$\.{\\def\\readcontents\{\\input CONT1 \\input CONT2 \\input CONTENTS\}};$$
  1372. this brings in the data from all three pieces, in the proper order.
  1373. However, we still need to solve the page-numbering problem. One way to
  1374. do it is to include the following in the limbo material for $\beta$:
  1375. $$\lpile{\.{\\message\{Please type the last page number of part 1: \}}\cr
  1376.   \.{\\read-1to\\\\ \\pageno=\\\\ \\advance\\pageno by 1}\cr}$$
  1377. Then you simply provide the necessary data when \TeX\ requests
  1378. it; a similar construction is used at the beginning of $\gamma$.
  1379. This method can, of course, be used to divide a woven file into
  1380. any number of pieces.
  1381. \point 11. Sometimes it is nice to include things in the index that are
  1382. typeset in a special way. For example, we might want to have an
  1383. index entry for `\TeX'. \.{WEAVE} provides only two standard ways to
  1384. typeset an index entry (unless the entry is an identifier or a reserved word):
  1385. `\.{@\^}' gives roman type, and `\.{@.}' gives typewriter type.
  1386. But if we try to typeset `\TeX' in roman type by saying, e.g.,
  1387. `\.{@\^\\TeX@>}', the backslash character gets in the way,
  1388. and this entry wouldn't appear in the index with the T's.
  1389. The solution is to use the `\.{@:}' feature, declaring a macro that
  1390. simply removes a sort key as follows:
  1391. $$\.{\\def\\9\#1\{\}}$$
  1392. Now you can say, e.g., `\.{@:TeX\}\{\\TeX@>}' in your \.{WEB} file; \.{WEAVE}
  1393. puts it into the index alphabetically, based on the sort key, and
  1394. produces the macro call `\.{\\9\{TeX\}\{\\TeX\}}' which will ensure that
  1395. the sort key isn't printed.
  1396. A similar idea can be used to insert hidden material into module
  1397. names so that they are alphabetized in whatever way you might wish.
  1398. Some people call these tricks ``special refinements''; others call
  1399. them ``kludges''.
  1400. \point 12. The control sequence \.{\\modno} is set to the number of the
  1401. module being typeset.
  1402. \point 13. If you want to list only the modules that have changed,
  1403. together with the index, put the command `\.{\\let\\maybe=\\iffalse}' in
  1404. the limbo section before the first module of your \.{WEB} file. It's
  1405. customary to make this the first change in your change file.
  1406. \point 14. To get output in languages other than English, redefine the
  1407. macros \.{\\A}, \.{\\As}, \.{\\ET}, \.{\\ETs}, \.{\\U}, \.{\\Us},
  1408. \.{\\ch}, \.{\\fin}, and \.{\\con}.
  1409. \vfill\eject
  1410. \def\runninghead{APPENDIX H --- GETTING STARTED}
  1411. \section Appendix H: Installing the \.{WEB} system.
  1412. Suppose you want to use the \.{WEB} programs on your computer, and suppose
  1413. that you can't simply borrow them from somebody else who has the same
  1414. kind of machine. Here's what to do:
  1415. \yskip
  1416. \def\step(#1){\par\hangindent 2em\noindent\hbox to 2em{\hfil(#1) }\ignorespaces}
  1417. \step(1) Get a tape that contains the files \.{WEAVE.WEB}, \.{TANGLE.WEB},
  1418. \.{TANGLE.PAS}, and \.{WEBMAC.TEX}. The tape will probably also contain an
  1419. example change file \.{TANGLE.CH}.
  1420. \step(2) Look at the sections of \.{TANGLE} that are listed under ``system
  1421. dependencies'' in the index of Appendix~E above, and figure out what changes
  1422. (if any) will be needed for your system.
  1423. \step(3) Make a change file \.{TANGLE.CH} that contains the changes of~(2);
  1424. do not change your copy of \.{TANGLE.WEB}, leave it intact. (The
  1425. rules for change files are explained at the end of the manual just before
  1426. the appendices; you may want to look at the example change file that
  1427. arrived with your copy of \.{TANGLE.WEB}. It's also a good idea to
  1428. define all the ``switches'' like \&{debug} and \&{gubed} to be null in your
  1429. first change files; then you can sure that your compiler will handle
  1430. all of the code.)
  1431. \step(4) Make the changes of (2) in your copy of \.{TANGLE.PAS}. (If these
  1432. changes are extensive, you might be better off finding some computer that
  1433. that already has \.{TANGLE} running, and making the new \.{TANGLE.PAS}
  1434. from \.{TANGLE.WEB} and your \.{TANGLE.CH}.)
  1435. \step(5) Use your \PASCAL\ compiler to convert your copy of \.{TANGLE.PAS}
  1436. to a running program \.{TANGLE}.
  1437. \step(6) Check your changes as follows: Run \.{TANGLE} on \.{TANGLE.WEB}
  1438. and your \.{TANGLE.CH}, yielding $\.{TANGLE.PAS}'$; make a running
  1439. program $\.{TANGLE}'$ by applying \PASCAL\ to
  1440. $\.{TANGLE.PAS}'$; run $\.{TANGLE}'$ on \.{TANGLE.WEB} and
  1441. your \.{TANGLE.CH}, yielding $\.{TANGLE.PAS}''$; and check
  1442. that $\.{TANGLE.PAS}''$ is identical to
  1443. $\.{TANGLE.PAS}'$. Once this test has been passed, you have got a
  1444. working \.{TANGLE} program.
  1445. \step(7) Make a change file \.{WEAVE.CH} analogous to (3), but this time
  1446. consider the system-dependent parts of \.{WEAVE} that are listed in
  1447. the index to Appendix~D.
  1448. \step(8) Run \.{TANGLE} on \.{WEAVE.WEB} and your \.{WEAVE.CH}, obtaining
  1449. \.{WEAVE.PAS}.
  1450. \step(9) Use \PASCAL\ on \.{WEAVE.PAS} to make a running \.{WEAVE} program.
  1451. \step(10) Run \.{WEAVE} on \.{TANGLE.WEB} and \.{TANGLE.CH} to produce
  1452. \.{TANGLE.TEX}.
  1453. \step(11) Run \TeX\ on \.{TANGLE.TEX}, obtaining a listing analogous to
  1454. Appendix~E. This listing will incorporate your changes.
  1455. \step(12) Run \.{WEAVE} on \.{WEAVE.WEB} and your \.{WEAVE.CH} to produce
  1456. \.{WEAVE.TEX}.
  1457. \step(13) Run \TeX\ on \.{WEAVE.TEX}, obtaining a listing analogous to
  1458. Appendix~D that incorporates your changes.
  1459. \yskip\noindent
  1460. This description assumes that you already have a working \TeX82 system.
  1461. But what if you don't have \TeX82? Then you start with a tape that also
  1462. contains \.{TEX.WEB} and \.{plain.tex}, and you refer to a hardcopy
  1463. listing of the \TeX82 program corresponding to \.{TEX.WEB}. Between steps
  1464. (10) and (11) you do the following:
  1465. \yskip
  1466. \def\substep(10.#1){\par\hangindent 4em\noindent
  1467.   \hbox to 4em{\hfil(10.#1) }\ignorespaces}
  1468. \substep(10.1) Make a change file \.{TEX.CH} to fix the system dependent
  1469. portions of \.{TEX.WEB}, in a manner analogous to step~(2). Since \TeX\ is
  1470. a much more complex program than \.{WEAVE} or \.{TANGLE}, there are more
  1471. system-dependent features to think about, but by now you will be good at
  1472. making such modifications. Do not make any changes to \.{TEX.WEB}.
  1473. \substep(10.2) Make an almost-copy of your \.{TEX.CH} called \.{INITEX.CH};
  1474. this one will have the `\&{init}' and `\&{tini}' macros redefined in order
  1475. to make the initialization version of \TeX. It also might have smaller
  1476. font memory and dynamic memory areas, since \.{INITEX} doesn't need as
  1477. much memory for such things; by setting the memory smaller in \.{INITEX},
  1478. you guarantee that the production system will have a ``cushion.''
  1479. \substep(10.3) Run \.{TANGLE} on \.{TEX.WEB} and \.{INITEX.CH}, obtaining
  1480. \.{INITEX.PAS} and \.{TEX.POOL}.
  1481. \substep(10.4) Run \PASCAL\ on \.{INITEX.PAS}, obtaining \.{INITEX}.
  1482. \substep(10.5) Run \.{INITEX} on \.{TEX.POOL}, during which run you type
  1483. `\.{plain}' and `\.{\\dump}'. This will produce a file \.{plain.fmt}
  1484. containing the data needed to initialize \TeX's memory.
  1485. \substep(10.6) Run \.{TANGLE} on \.{TEX.WEB} and the \.{TEX.CH} of (10.1),
  1486. obtaining \.{TEX.PAS}.
  1487. \substep(10.7) Run \PASCAL\ on \.{TEX.PAS}, obtaining \.{VIRTEX}.
  1488. \substep(10.8) If your operating system supports programs whose core images
  1489. have been saved, run \.{VIRTEX}, type `\.{\&plain}', then save the core image
  1490. and call it \TeX. Otherwise, \.{VIRTEX} will be your \TeX, and it will
  1491. read `\.{plain.fmt}' (or some other \.{fmt} file) each time you run.
  1492. \yskip
  1493. This 21-step process may seem long, but it is actually an oversimplification,
  1494. since you also need fonts and a way to print the device-independent files
  1495. that \TeX\ spews out. On the other hand, the total number of steps is not
  1496. quite so large when you consider that \.{TANGLE}-followed-by-\PASCAL\ and
  1497. \.{WEAVE}-followed-by-\TeX\ may be regarded as single operations.
  1498. If you have only the present report, not a tape, you will have to prepare
  1499. files \.{WEAVE.WEB} and \.{TANGLE.WEB} by hand, typing them into the
  1500. computer by following Appendices D and E. Then you have to simulate the
  1501. behavior of \.{TANGLE} by converting \.{TANGLE.WEB} manually into
  1502. \.{TANGLE.PAS}; with a good text editor this takes about six hours. Then
  1503. you have to correct errors that were made in all this hand work; but still
  1504. the whole project is not impossibly difficult, because in fact the entire
  1505. development of \.{WEAVE} and \.{TANGLE} (including the writing of the
  1506. programs and this manual) took less than two months of work.
  1507. \vfill\end
  1508.