modernc.org/knuth@v0.0.4/weave/testdata/weave.tex (about)

     1  \input webmac
     2  % This program by D. E. Knuth is not copyrighted and can be used freely.
     3  % Version 0 was released in December, 1981.
     4  % Version 1 was released in September, 1982, with version 0 of TeX.
     5  % Slight changes were made in October, 1982, for version 0.6 of TeX.
     6  % Version 1.1 changed "_" to "\_" if not within an identifier (November, 1982).
     7  % Version 1.2 added @= and @\ and marked changed modules (December, 1982).
     8  % Version 1.3 marked and indexed changed modules better (January, 1983).
     9  % Version 1.4 added "history" (February, 1983).
    10  % Version 1.5 conformed to TeX version 0.96 (March, 1983).
    11  % Version 1.6 conformed to TeX version 0.98 (May, 1983).
    12  % Version 1.7 introduced the new change file format (June, 1983).
    13  % Version 2 was released in July, 1983, with version 0.999 of TeX.
    14  % Version 2.1 corrected a bug in changed_module reckoning (August, 1983).
    15  % Version 2.2 corrected it better (August, 1983).
    16  % Version 2.3 starts the output with \input webmac (August, 1983).
    17  % Version 2.4 fixed a bug in compress(#) (September, 1983).
    18  % Version 2.5 cleared xrefswitch after module names (November, 1983).
    19  % Version 2.6 fixed a bug in declaration of trans array (January, 1984).
    20  % Version 2.7 fixed a bug in real constants (August, 1984).
    21  % Version 2.8 fixed a bug in change_buffer movement (August, 1985).
    22  % Version 2.9 increased max_refs and max_toks to 30000 each (January, 1987).
    23  % Version 3, for Sewell's book, fixed long-line bug in input_ln (March, 1989).
    24  % Version 3.1 fixed a bug for programs with only one module (April, 1989).
    25  % Version 4 was major change to allow 8-bit input (September, 1989).
    26  % Version 4.1, for Breitenlohner, avoids English-only output (March, 1990).
    27  % Version 4.2 conforms to ANSI standard for-loop rules (September, 1990).
    28  % Version 4.3 catches extra } in input (Breitenlohner, September, 1991).
    29  % Version 4.4 corrects changed_module logic, %-overflow (January, 1992).
    30  % Version 4.5 corrects archaic @z logic and empty change file (January, 2021).
    31  
    32  % Here is TeX material that gets inserted after \input webmac
    33  \def\hang{\hangindent 3em\indent\ignorespaces}
    34  \font\ninerm=cmr9
    35  \let\mc=\ninerm % medium caps for names like SAIL
    36  \def\PASCAL{Pascal}
    37  \def\pb{$\.|\ldots\.|$} % Pascal brackets (|...|)
    38  \def\v{\.{\char'174}} % vertical (|) in typewriter font
    39  \def\dleft{[\![} \def\dright{]\!]} % double brackets
    40  \mathchardef\RA="3221 % right arrow
    41  \mathchardef\BA="3224 % double arrow
    42  \def\({} % kludge for alphabetizing certain module names
    43  
    44  \def\title{WEAVE}
    45  \def\contentspagenumber{15} % should be odd
    46  \def\topofcontents{\null\vfill
    47    \titlefalse % include headline on the contents page
    48    \def\rheader{\mainfont Appendix D\hfil \contentspagenumber}
    49    \centerline{\titlefont The {\ttitlefont WEAVE} processor}
    50    \vskip 15pt
    51    \centerline{(Version 4.5)}
    52    \vfill}
    53  \pageno=\contentspagenumber \advance\pageno by 1
    54  
    55  
    56  \N1\*.  Introduction.
    57  This program converts a \.{WEB} file to a \TeX\ file. It was written
    58  by D. E. Knuth in October, 1981; a somewhat similar {\mc SAIL} program had
    59  been developed in March, 1979, although the earlier program used a top-down
    60  parsing method that is quite different from the present scheme.
    61  
    62  The code uses a few features of the local \PASCAL\ compiler that may need
    63  to be changed in other installations:
    64  
    65  \yskip\item{1)} Case statements have a default.
    66  \item{2)} Input-output routines may need to be adapted for use with a
    67  particular
    68  character set and/or for printing messages on the user's terminal.
    69  
    70  \yskip\noindent
    71  These features are also present in the \PASCAL\ version of \TeX, where they
    72  are used in a similar (but more complex) way. System-dependent portions
    73  of \.{WEAVE} can be identified by looking at the entries for `system
    74  dependencies' in the index below.
    75  
    76  The ``banner line'' defined here should be changed whenever \.{WEAVE}
    77  is modified.
    78  
    79  \Y\P\D \37$\\{banner}\S\.{\'This\ is\ WEAVE,\ Version\ 4.5\ (goweave\
    80  v0.0-prerelease)\'}$\par
    81  \fi
    82  
    83  \M2\*. The program begins with a fairly normal header, made up of pieces that
    84  will mostly be filled in later. The \.{WEB} input comes from files \\{web%
    85  \_file}
    86  and \\{change\_file}, and the \TeX\ output goes to file \\{tex\_file}.
    87  
    88  If it is necessary to abort the job because of a fatal error, the program
    89  calls the `\\{jump\_out}' procedure, which goes to the label \\{end\_of%
    90  \_WEAVE}.
    91  
    92  \Y\P\D \37$\\{end\_of\_WEAVE}=9999$\C{go here to wrap it up}\par
    93  \Y\P\hbox{\4}\X4:Compiler directives\X\6
    94  \4\&{program}\1\  \37$\\{WEAVE}(\\{web\_file},\39\\{change\_file},\39\\{tex%
    95  \_file})$;\6
    96  \4\&{const} \37\X8:Constants in the outer block\X\6
    97  \4\&{type} \37\X11:Types in the outer block\X\6
    98  \4\&{var} \37\X9:Globals in the outer block\X\6
    99  \X30:Error handling procedures\X\6
   100  \4\&{procedure}\1\  \37\\{initialize};\6
   101  \4\&{var} \37\X16:Local variables for initialization\X\2\6
   102  \&{begin} \37\X10:Set initial values\X\6
   103  \&{end};\par
   104  \fi
   105  
   106  \M3. Some of this code is optional for use when debugging only;
   107  such material is enclosed between the delimiters  \&{debug}  and $  \&{gubed}
   108  $.
   109  Other parts, delimited by  \&{stat}  and $  \&{tats} $, are optionally included
   110  if statistics about \.{WEAVE}'s memory usage are desired.
   111  
   112  \Y\P\D \37$\\{debug}\S\B$\C{change this to `$\\{debug}\equiv\null$' when
   113  debugging}\par
   114  \P\D \37$\\{gubed}\S\hbox{}\T$\C{change this to `$\\{gubed}\equiv\null$' when
   115  debugging}\par
   116  \P\F \37$\\{debug}\S\\{begin}$\par
   117  \P\F \37$\\{gubed}\S\\{end}$\Y\par
   118  \P\D \37$\\{stat}\S\B$\C{change this to `$\\{stat}\equiv\null$'   when
   119  gathering usage statistics}\par
   120  \P\D \37$\\{tats}\S\hbox{}\T$\C{change this to `$\\{tats}\equiv\null$'   when
   121  gathering usage statistics}\par
   122  \P\F \37$\\{stat}\S\\{begin}$\par
   123  \P\F \37$\\{tats}\S\\{end}$\par
   124  \fi
   125  
   126  \M4. The \PASCAL\ compiler used to develop this system has ``compiler
   127  directives'' that can appear in comments whose first character is a dollar
   128  sign.
   129  In production versions of \.{WEAVE} these directives tell the compiler that
   130  it is safe to avoid range checks and to leave out the extra code it inserts
   131  for the \PASCAL\ debugger's benefit, although interrupts will occur if
   132  there is arithmetic overflow.
   133  
   134  \Y\P$\4\X4:Compiler directives\X\S$\6
   135  $\B\J\$\|C-,\39\|A+,\39\|D-\T$\C{no range check, catch arithmetic overflow, no
   136  debug overhead}\6
   137  \&{debug} \37$\B\J\$\|C+,\39\|D+\T$\ \&{gubed}\C{but turn everything on when
   138  debugging}\par
   139  \U2\*.\fi
   140  
   141  \M5. Labels are given symbolic names by the following definitions. We insert
   142  the label `\\{exit}:' just before the `\ignorespaces  \&{end} \unskip' of a
   143  procedure in which we have used the `\&{return}' statement defined below;
   144  the label `\\{restart}' is occasionally used at the very beginning of a
   145  procedure; and the label `\\{reswitch}' is occasionally used just prior to
   146  a \&{case} statement in which some cases change the conditions and we wish to
   147  branch to the newly applicable case.
   148  Loops that are set up with the \&{loop} construction defined below are
   149  commonly exited by going to `\\{done}' or to `\\{found}' or to `\\{not%
   150  \_found}',
   151  and they are sometimes repeated by going to `\\{continue}'.
   152  
   153  \Y\P\D \37$\\{exit}=10$\C{go here to leave a procedure}\par
   154  \P\D \37$\\{restart}=20$\C{go here to start a procedure again}\par
   155  \P\D \37$\\{reswitch}=21$\C{go here to start a case statement again}\par
   156  \P\D \37$\\{continue}=22$\C{go here to resume a loop}\par
   157  \P\D \37$\\{done}=30$\C{go here to exit a loop}\par
   158  \P\D \37$\\{found}=31$\C{go here when you've found it}\par
   159  \P\D \37$\\{not\_found}=32$\C{go here when you've found something else}\par
   160  \fi
   161  
   162  \M6. Here are some macros for common programming idioms.
   163  
   164  \Y\P\D \37$\\{incr}(\#)\S\#\K\#+1$\C{increase a variable by unity}\par
   165  \P\D \37$\\{decr}(\#)\S\#\K\#-1$\C{decrease a variable by unity}\par
   166  \P\D \37$\\{loop}\S$\ \&{while} $\\{true}$ \1\&{do}\ \C{repeat over and over
   167  until a \&{goto}  happens}\par
   168  \P\D \37$\\{do\_nothing}\S$\C{empty statement}\par
   169  \P\D \37$\\{return}\S$\1\5
   170  \&{goto} \37\\{exit}\C{terminate a procedure call}\2\par
   171  \P\F \37$\\{return}\S\\{nil}$\par
   172  \P\F \37$\\{loop}\S\\{xclause}$\par
   173  \fi
   174  
   175  \M7\*. We assume that   \&{case}  statements may include a default case that
   176  applies
   177  if no matching label is found. Thus, we shall use constructions like
   178  $$\vbox{\halign{#\hfil\cr
   179   \&{case} $\|x$ \&{of}\cr
   180  1: $\langle\,$code for $x=1\,\rangle$;\cr
   181  3: $\langle\,$code for $x=3\,\rangle$;\cr
   182   \&{othercases}  $\langle\,$code for $\|x\I1$ and $\|x\I3$$\,\rangle$\cr
   183    \&{endcases} \cr}}$$
   184  since most \PASCAL\ compilers have plugged this hole in the language by
   185  incorporating some sort of default mechanism. For example, the compiler
   186  used to develop \.{WEB} and \TeX\ allows `\\{others}:' as a default label,
   187  and other \PASCAL s allow syntaxes like `\ignorespaces \&{else} \unskip' or
   188  `\&{otherwise}' or `\\{otherwise}:', etc. The definitions of  \&{othercases}
   189  and   \&{endcases}  should be changed to agree with local conventions.
   190  (Of course, if no default mechanism is available, the   \&{case}  statements of
   191  this program must be extended by listing all remaining cases.)
   192  
   193  \Y\P\D \37$\\{othercases}\S$\6
   194  \4\&{else} \37\C{default for cases not listed explicitly}\par
   195  \P\D \37$\\{endcases}\S$\ \&{end} \C{follows the default case in an extended   %
   196  \&{case}  statement}\par
   197  \P\F \37$\\{othercases}\S\\{else}$\par
   198  \P\F \37$\\{endcases}\S\\{end}$\par
   199  \fi
   200  
   201  \M8. The following parameters are set big enough to handle \TeX, so they
   202  should be sufficient for most applications of \.{WEAVE}.
   203  
   204  \Y\P$\4\X8:Constants in the outer block\X\S$\6
   205  $\\{max\_bytes}=45000$;\C{$1/\\{ww}$ times the number of bytes in identifiers,
   206   index entries, and module names; must be less than 65536}\6
   207  $\\{max\_names}=5000$;\C{number of identifiers, index entries, and module
   208  names;   must be less than 10240}\6
   209  $\\{max\_modules}=2000$;\C{greater than the total number of modules}\6
   210  $\\{hash\_size}=353$;\C{should be prime}\6
   211  $\\{buf\_size}=100$;\C{maximum length of input line}\6
   212  $\\{longest\_name}=400$;\C{module names shouldn't be longer than this}\6
   213  $\\{long\_buf\_size}=500$;\C{$\\{buf\_size}+\\{longest\_name}$}\6
   214  $\\{line\_length}=80$;\C{lines of \TeX\ output have at most this many
   215  characters,   should be less than 256}\6
   216  $\\{max\_refs}=30000$;\C{number of cross references; must be less than 65536}\6
   217  $\\{max\_toks}=30000$;\C{number of symbols in \PASCAL\ texts being parsed;
   218  must be less than 65536}\6
   219  $\\{max\_texts}=2000$;\C{number of phrases in \PASCAL\ texts being parsed;
   220  must be less than 10240}\6
   221  $\\{max\_scraps}=1000$;\C{number of tokens in \PASCAL\ texts being parsed}\6
   222  $\\{stack\_size}=200$;\C{number of simultaneous output levels}\par
   223  \U2\*.\fi
   224  
   225  \M9. A global variable called \\{history} will contain one of four values
   226  at the end of every run: \\{spotless} means that no unusual messages were
   227  printed; \\{harmless\_message} means that a message of possible interest
   228  was printed but no serious errors were detected; \\{error\_message} means that
   229  at least one error was found; \\{fatal\_message} means that the program
   230  terminated abnormally. The value of \\{history} does not influence the
   231  behavior of the program; it is simply computed for the convenience
   232  of systems that might want to use such information.
   233  
   234  \Y\P\D \37$\\{spotless}=0$\C{\\{history} value for normal jobs}\par
   235  \P\D \37$\\{harmless\_message}=1$\C{\\{history} value when non-serious info was
   236  printed}\par
   237  \P\D \37$\\{error\_message}=2$\C{\\{history} value when an error was noted}\par
   238  \P\D \37$\\{fatal\_message}=3$\C{\\{history} value when we had to stop
   239  prematurely}\Y\par
   240  \P\D \37$\\{mark\_harmless}\S\hbox{}$\ \&{if} $\\{history}=\\{spotless}$ \1%
   241  \&{then}\5
   242  $\\{history}\K\\{harmless\_message}$\2\par
   243  \P\D \37$\\{mark\_error}\S\\{history}\K\\{error\_message}$\par
   244  \P\D \37$\\{mark\_fatal}\S\\{history}\K\\{fatal\_message}$\par
   245  \Y\P$\4\X9:Globals in the outer block\X\S$\6
   246  \4\\{history}: \37$\\{spotless}\to\\{fatal\_message}$;\C{how bad was this run?}%
   247  \par
   248  \As13, 20\*, 23, 25, 27, 29, 37, 39, 45, 48, 53, 55, 63, 65, 71, 73, 93, 108,
   249  114, 118, 121, 129, 144, 177, 202, 219, 229, 234, 240, 242, 244, 246\ETs258.
   250  \U2\*.\fi
   251  
   252  \M10. \P$\X10:Set initial values\X\S$\6
   253  $\\{history}\K\\{spotless}$;\par
   254  \As14, 17, 18, 21\*, 26, 41, 43, 49, 54, 57, 94, 102, 124, 126, 145, 203, 245,
   255  248\ETs259.
   256  \U2\*.\fi
   257  
   258  \N11.  The character set.
   259  One of the main goals in the design of \.{WEB} has been to make it readily
   260  portable between a wide variety of computers. Yet \.{WEB} by its very
   261  nature must use a greater variety of characters than most computer
   262  programs deal with, and character encoding is one of the areas in which
   263  existing machines differ most widely from each other.
   264  
   265  To resolve this problem, all input to \.{WEAVE} and \.{TANGLE} is
   266  converted to an internal eight-bit code that is essentially standard
   267  ASCII, the ``American Standard Code for Information Interchange.''
   268  The conversion is done immediately when each character is read in.
   269  Conversely, characters are converted from ASCII to the user's external
   270  representation just before they are output. (The original ASCII code
   271  was seven bits only; \.{WEB} now allows eight bits in an attempt to
   272  keep up with modern times.)
   273  
   274  Such an internal code is relevant to users of \.{WEB} only because it is
   275  the code used for preprocessed constants like \.{"A"}. If you are writing
   276  a program in \.{WEB} that makes use of such one-character constants, you
   277  should convert your input to ASCII form, like \.{WEAVE} and \.{TANGLE} do.
   278  Otherwise \.{WEB}'s internal coding scheme does not affect you.
   279  
   280  Here is a table of the standard visible ASCII codes:
   281  $$\def\:{\char\count255\global\advance\count255 by 1}
   282  \count255='40
   283  \vbox{
   284  \hbox{\hbox to 40pt{\it\hfill0\/\hfill}%
   285  \hbox to 40pt{\it\hfill1\/\hfill}%
   286  \hbox to 40pt{\it\hfill2\/\hfill}%
   287  \hbox to 40pt{\it\hfill3\/\hfill}%
   288  \hbox to 40pt{\it\hfill4\/\hfill}%
   289  \hbox to 40pt{\it\hfill5\/\hfill}%
   290  \hbox to 40pt{\it\hfill6\/\hfill}%
   291  \hbox to 40pt{\it\hfill7\/\hfill}}
   292  \vskip 4pt
   293  \hrule
   294  \def\^{\vrule height 10.5pt depth 4.5pt}
   295  \halign{\hbox to 0pt{\hskip -24pt\O{#0}\hfill}&\^
   296  \hbox to 40pt{\tt\hfill#\hfill\^}&
   297  &\hbox to 40pt{\tt\hfill#\hfill\^}\cr
   298  04&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
   299  05&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
   300  06&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
   301  07&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
   302  10&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
   303  11&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
   304  12&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
   305  13&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
   306  14&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
   307  15&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
   308  16&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
   309  17&\:&\:&\:&\:&\:&\:&\:\cr}
   310  \hrule width 280pt}$$
   311  (Actually, of course, code \O{040} is an invisible blank space.)  Code \O{136}
   312  was once an upward arrow (\.{\char'13}), and code \O{137} was
   313  once a left arrow (\.^^X), in olden times when the first draft
   314  of ASCII code was prepared; but \.{WEB} works with today's standard
   315  ASCII in which those codes represent circumflex and underline as shown.
   316  
   317  \Y\P$\4\X11:Types in the outer block\X\S$\6
   318  $\\{ASCII\_code}=0\to255$;\C{eight-bit numbers, a subrange of the integers}\par
   319  \As12, 36, 38, 47, 52\ETs201.
   320  \U2\*.\fi
   321  
   322  \M12. The original \PASCAL\ compiler was designed in the late 60s, when six-bit
   323  character sets were common, so it did not make provision for lowercase
   324  letters. Nowadays, of course, we need to deal with both capital and small
   325  letters in a convenient way, so \.{WEB} assumes that it is being used
   326  with a \PASCAL\ whose character set contains at least the characters of
   327  standard ASCII as listed above. Some \PASCAL\ compilers use the original
   328  name \\{char} for the data type associated with the characters in text files,
   329  while other \PASCAL s consider \\{char} to be a 64-element subrange of a larger
   330  data type that has some other name.
   331  
   332  In order to accommodate this difference, we shall use the name \\{text\_char}
   333  to stand for the data type of the characters in the input and output
   334  files.  We shall also assume that \\{text\_char} consists of the elements
   335  $\\{chr}(\\{first\_text\_char})$ through $\\{chr}(\\{last\_text\_char})$,
   336  inclusive. The
   337  following definitions should be adjusted if necessary.
   338  
   339  \Y\P\D \37$\\{text\_char}\S\\{char}$\C{the data type of characters in text
   340  files}\par
   341  \P\D \37$\\{first\_text\_char}=0$\C{ordinal number of the smallest element of %
   342  \\{text\_char}}\par
   343  \P\D \37$\\{last\_text\_char}=255$\C{ordinal number of the largest element of %
   344  \\{text\_char}}\par
   345  \Y\P$\4\X11:Types in the outer block\X\mathrel{+}\S$\6
   346  $\\{text\_file}=$\1\5
   347  \&{packed} \37\&{file} \1\&{of}\5
   348  \\{text\_char};\2\2\par
   349  \fi
   350  
   351  \M13. The \.{WEAVE} and \.{TANGLE} processors convert between ASCII code and
   352  the user's external character set by means of arrays \\{xord} and \\{xchr}
   353  that are analogous to \PASCAL's \\{ord} and \\{chr} functions.
   354  
   355  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
   356  \4\\{xord}: \37\&{array} $[\\{text\_char}]$ \1\&{of}\5
   357  \\{ASCII\_code};\C{specifies conversion of input characters}\2\6
   358  \4\\{xchr}: \37\&{array} $[\\{ASCII\_code}]$ \1\&{of}\5
   359  \\{text\_char};\C{specifies conversion of output characters}\2\par
   360  \fi
   361  
   362  \M14. If we assume that every system using \.{WEB} is able to read and write
   363  the
   364  visible characters of standard ASCII (although not necessarily using the
   365  ASCII codes to represent them), the following assignment statements initialize
   366  most of the \\{xchr} array properly, without needing any system-dependent
   367  changes. For example, the statement \.{xchr[@\'101]:=\'A\'} that appears
   368  in the present \.{WEB} file might be encoded in, say, {\mc EBCDIC} code
   369  on the external medium on which it resides, but \.{TANGLE} will convert from
   370  this external code to ASCII and back again. Therefore the assignment
   371  statement \.{XCHR[65]:=\'A\'} will appear in the corresponding \PASCAL\ file,
   372  and \PASCAL\ will compile this statement so that $\\{xchr}[65]$ receives the
   373  character \.A in the external (\\{char}) code. Note that it would be quite
   374  incorrect to say \.{xchr[@\'101]:="A"}, because \.{"A"} is a constant of
   375  type \\{integer}, not \\{char}, and because we have $\.{"A"}=65$ regardless of
   376  the external character set.
   377  
   378  \Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
   379  $\\{xchr}[\O{40}]\K\.{\'\ \'}$;\5
   380  $\\{xchr}[\O{41}]\K\.{\'!\'}$;\5
   381  $\\{xchr}[\O{42}]\K\.{\'"\'}$;\5
   382  $\\{xchr}[\O{43}]\K\.{\'\#\'}$;\5
   383  $\\{xchr}[\O{44}]\K\.{\'\$\'}$;\5
   384  $\\{xchr}[\O{45}]\K\.{\'\%\'}$;\5
   385  $\\{xchr}[\O{46}]\K\.{\'\&\'}$;\5
   386  $\\{xchr}[\O{47}]\K\.{\'\'}\.{\'\'}$;\6
   387  $\\{xchr}[\O{50}]\K\.{\'(\'}$;\5
   388  $\\{xchr}[\O{51}]\K\.{\')\'}$;\5
   389  $\\{xchr}[\O{52}]\K\.{\'*\'}$;\5
   390  $\\{xchr}[\O{53}]\K\.{\'+\'}$;\5
   391  $\\{xchr}[\O{54}]\K\.{\',\'}$;\5
   392  $\\{xchr}[\O{55}]\K\.{\'-\'}$;\5
   393  $\\{xchr}[\O{56}]\K\.{\'.\'}$;\5
   394  $\\{xchr}[\O{57}]\K\.{\'/\'}$;\6
   395  $\\{xchr}[\O{60}]\K\.{\'0\'}$;\5
   396  $\\{xchr}[\O{61}]\K\.{\'1\'}$;\5
   397  $\\{xchr}[\O{62}]\K\.{\'2\'}$;\5
   398  $\\{xchr}[\O{63}]\K\.{\'3\'}$;\5
   399  $\\{xchr}[\O{64}]\K\.{\'4\'}$;\5
   400  $\\{xchr}[\O{65}]\K\.{\'5\'}$;\5
   401  $\\{xchr}[\O{66}]\K\.{\'6\'}$;\5
   402  $\\{xchr}[\O{67}]\K\.{\'7\'}$;\6
   403  $\\{xchr}[\O{70}]\K\.{\'8\'}$;\5
   404  $\\{xchr}[\O{71}]\K\.{\'9\'}$;\5
   405  $\\{xchr}[\O{72}]\K\.{\':\'}$;\5
   406  $\\{xchr}[\O{73}]\K\.{\';\'}$;\5
   407  $\\{xchr}[\O{74}]\K\.{\'<\'}$;\5
   408  $\\{xchr}[\O{75}]\K\.{\'=\'}$;\5
   409  $\\{xchr}[\O{76}]\K\.{\'>\'}$;\5
   410  $\\{xchr}[\O{77}]\K\.{\'?\'}$;\6
   411  $\\{xchr}[\O{100}]\K\.{\'@\'}$;\5
   412  $\\{xchr}[\O{101}]\K\.{\'A\'}$;\5
   413  $\\{xchr}[\O{102}]\K\.{\'B\'}$;\5
   414  $\\{xchr}[\O{103}]\K\.{\'C\'}$;\5
   415  $\\{xchr}[\O{104}]\K\.{\'D\'}$;\5
   416  $\\{xchr}[\O{105}]\K\.{\'E\'}$;\5
   417  $\\{xchr}[\O{106}]\K\.{\'F\'}$;\5
   418  $\\{xchr}[\O{107}]\K\.{\'G\'}$;\6
   419  $\\{xchr}[\O{110}]\K\.{\'H\'}$;\5
   420  $\\{xchr}[\O{111}]\K\.{\'I\'}$;\5
   421  $\\{xchr}[\O{112}]\K\.{\'J\'}$;\5
   422  $\\{xchr}[\O{113}]\K\.{\'K\'}$;\5
   423  $\\{xchr}[\O{114}]\K\.{\'L\'}$;\5
   424  $\\{xchr}[\O{115}]\K\.{\'M\'}$;\5
   425  $\\{xchr}[\O{116}]\K\.{\'N\'}$;\5
   426  $\\{xchr}[\O{117}]\K\.{\'O\'}$;\6
   427  $\\{xchr}[\O{120}]\K\.{\'P\'}$;\5
   428  $\\{xchr}[\O{121}]\K\.{\'Q\'}$;\5
   429  $\\{xchr}[\O{122}]\K\.{\'R\'}$;\5
   430  $\\{xchr}[\O{123}]\K\.{\'S\'}$;\5
   431  $\\{xchr}[\O{124}]\K\.{\'T\'}$;\5
   432  $\\{xchr}[\O{125}]\K\.{\'U\'}$;\5
   433  $\\{xchr}[\O{126}]\K\.{\'V\'}$;\5
   434  $\\{xchr}[\O{127}]\K\.{\'W\'}$;\6
   435  $\\{xchr}[\O{130}]\K\.{\'X\'}$;\5
   436  $\\{xchr}[\O{131}]\K\.{\'Y\'}$;\5
   437  $\\{xchr}[\O{132}]\K\.{\'Z\'}$;\5
   438  $\\{xchr}[\O{133}]\K\.{\'[\'}$;\5
   439  $\\{xchr}[\O{134}]\K\.{\'\\\'}$;\5
   440  $\\{xchr}[\O{135}]\K\.{\']\'}$;\5
   441  $\\{xchr}[\O{136}]\K\.{\'\^\'}$;\5
   442  $\\{xchr}[\O{137}]\K\.{\'\_\'}$;\6
   443  $\\{xchr}[\O{140}]\K\.{\'\`\'}$;\5
   444  $\\{xchr}[\O{141}]\K\.{\'a\'}$;\5
   445  $\\{xchr}[\O{142}]\K\.{\'b\'}$;\5
   446  $\\{xchr}[\O{143}]\K\.{\'c\'}$;\5
   447  $\\{xchr}[\O{144}]\K\.{\'d\'}$;\5
   448  $\\{xchr}[\O{145}]\K\.{\'e\'}$;\5
   449  $\\{xchr}[\O{146}]\K\.{\'f\'}$;\5
   450  $\\{xchr}[\O{147}]\K\.{\'g\'}$;\6
   451  $\\{xchr}[\O{150}]\K\.{\'h\'}$;\5
   452  $\\{xchr}[\O{151}]\K\.{\'i\'}$;\5
   453  $\\{xchr}[\O{152}]\K\.{\'j\'}$;\5
   454  $\\{xchr}[\O{153}]\K\.{\'k\'}$;\5
   455  $\\{xchr}[\O{154}]\K\.{\'l\'}$;\5
   456  $\\{xchr}[\O{155}]\K\.{\'m\'}$;\5
   457  $\\{xchr}[\O{156}]\K\.{\'n\'}$;\5
   458  $\\{xchr}[\O{157}]\K\.{\'o\'}$;\6
   459  $\\{xchr}[\O{160}]\K\.{\'p\'}$;\5
   460  $\\{xchr}[\O{161}]\K\.{\'q\'}$;\5
   461  $\\{xchr}[\O{162}]\K\.{\'r\'}$;\5
   462  $\\{xchr}[\O{163}]\K\.{\'s\'}$;\5
   463  $\\{xchr}[\O{164}]\K\.{\'t\'}$;\5
   464  $\\{xchr}[\O{165}]\K\.{\'u\'}$;\5
   465  $\\{xchr}[\O{166}]\K\.{\'v\'}$;\5
   466  $\\{xchr}[\O{167}]\K\.{\'w\'}$;\6
   467  $\\{xchr}[\O{170}]\K\.{\'x\'}$;\5
   468  $\\{xchr}[\O{171}]\K\.{\'y\'}$;\5
   469  $\\{xchr}[\O{172}]\K\.{\'z\'}$;\5
   470  $\\{xchr}[\O{173}]\K\.{\'\{\'}$;\5
   471  $\\{xchr}[\O{174}]\K\.{\'|\'}$;\5
   472  $\\{xchr}[\O{175}]\K\.{\'\}\'}$;\5
   473  $\\{xchr}[\O{176}]\K\.{\'\~\'}$;\6
   474  $\\{xchr}[0]\K\.{\'\ \'}$;\5
   475  $\\{xchr}[\O{177}]\K\.{\'\ \'}$;\C{these ASCII codes are not used}\par
   476  \fi
   477  
   478  \M15. Some of the ASCII codes below \O{40} have been given symbolic names in
   479  \.{WEAVE} and \.{TANGLE} because they are used with a special meaning.
   480  
   481  \Y\P\D \37$\\{and\_sign}=\O{4}$\C{equivalent to `\.{and}'}\par
   482  \P\D \37$\\{not\_sign}=\O{5}$\C{equivalent to `\.{not}'}\par
   483  \P\D \37$\\{set\_element\_sign}=\O{6}$\C{equivalent to `\.{in}'}\par
   484  \P\D \37$\\{tab\_mark}=\O{11}$\C{ASCII code used as tab-skip}\par
   485  \P\D \37$\\{line\_feed}=\O{12}$\C{ASCII code thrown away at end of line}\par
   486  \P\D \37$\\{form\_feed}=\O{14}$\C{ASCII code used at end of page}\par
   487  \P\D \37$\\{carriage\_return}=\O{15}$\C{ASCII code used at end of line}\par
   488  \P\D \37$\\{left\_arrow}=\O{30}$\C{equivalent to `\.{:=}'}\par
   489  \P\D \37$\\{not\_equal}=\O{32}$\C{equivalent to `\.{<>}'}\par
   490  \P\D \37$\\{less\_or\_equal}=\O{34}$\C{equivalent to `\.{<=}'}\par
   491  \P\D \37$\\{greater\_or\_equal}=\O{35}$\C{equivalent to `\.{>=}'}\par
   492  \P\D \37$\\{equivalence\_sign}=\O{36}$\C{equivalent to `\.{==}'}\par
   493  \P\D \37$\\{or\_sign}=\O{37}$\C{equivalent to `\.{or}'}\par
   494  \fi
   495  
   496  \M16. When we initialize the \\{xord} array and the remaining parts of %
   497  \\{xchr},
   498  it will be convenient to make use of an index variable, \|i.
   499  
   500  \Y\P$\4\X16:Local variables for initialization\X\S$\6
   501  \4\|i: \37$0\to255$;\par
   502  \As40, 56\ETs247.
   503  \U2\*.\fi
   504  
   505  \M17. Here now is the system-dependent part of the character set.
   506  If \.{WEB} is being implemented on a garden-variety \PASCAL\ for which
   507  only standard ASCII codes will appear in the input and output files, you
   508  don't need to make any changes here. But if you have, for example, an extended
   509  character set like the one in Appendix~C of {\sl The \TeX book}, the first
   510  line of code in this module should be changed to
   511  $$\hbox{ \&{for} $\|i\K1\mathrel{\&{to}}\O{37}$ \&{do} $\\{xchr}[\|i]\K\\{chr}(%
   512  \|i)$;}$$
   513  \.{WEB}'s character set is essentially identical to \TeX's, even with respect
   514  to
   515  characters less than \O{40}.
   516  
   517  Changes to the present module will make \.{WEB} more friendly on computers
   518  that have an extended character set, so that one can type things like
   519  \.^^Z\ instead of \.{<>}. If you have an extended set of characters that
   520  are easily incorporated into text files, you can assign codes arbitrarily
   521  here, giving an \\{xchr} equivalent to whatever characters the users of
   522  \.{WEB} are allowed to have in their input files, provided that unsuitable
   523  characters do not correspond to special codes like \\{carriage\_return}
   524  that are listed above.
   525  
   526  (The present file \.{WEAVE.WEB} does not contain any of the non-ASCII
   527  characters, because it is intended to be used with all implementations of
   528  \.{WEB}.  It was originally created on a Stanford system that has a
   529  convenient extended character set, then ``sanitized'' by applying another
   530  program that transliterated all of the non-standard characters into
   531  standard equivalents.)
   532  
   533  \Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
   534  \&{for} $\|i\K1\mathrel{\&{to}}\O{37}$ \1\&{do}\5
   535  $\\{xchr}[\|i]\K\.{\'\ \'}$;\2\6
   536  \&{for} $\|i\K\O{200}\mathrel{\&{to}}\O{377}$ \1\&{do}\5
   537  $\\{xchr}[\|i]\K\.{\'\ \'}$;\2\par
   538  \fi
   539  
   540  \M18. The following system-independent code makes the \\{xord} array contain a
   541  suitable inverse to the information in \\{xchr}.
   542  
   543  \Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
   544  \&{for} $\|i\K\\{first\_text\_char}\mathrel{\&{to}}\\{last\_text\_char}$ \1%
   545  \&{do}\5
   546  $\\{xord}[\\{chr}(\|i)]\K\.{"\ "}$;\2\6
   547  \&{for} $\|i\K1\mathrel{\&{to}}\O{377}$ \1\&{do}\5
   548  $\\{xord}[\\{xchr}[\|i]]\K\|i$;\2\6
   549  $\\{xord}[\.{\'\ \'}]\K\.{"\ "}$;\par
   550  \fi
   551  
   552  \N19.  Input and output.
   553  The input conventions of this program are intended to be very much like those
   554  of \TeX\ (except, of course, that they are much simpler, because much less
   555  needs to be done). Furthermore they are identical to those of \.{TANGLE}.
   556  Therefore people who need to make modifications to all three systems
   557  should be able to do so without too many headaches.
   558  
   559  We use the standard \PASCAL\ input/output procedures in several places that
   560  \TeX\ cannot, since \.{WEAVE} does not have to deal with files that are named
   561  dynamically by the user, and since there is no input from the terminal.
   562  
   563  \fi
   564  
   565  \M20\*. Terminal output is done by writing on file \\{term\_out}, which is
   566  assumed to
   567  consist of characters of type \\{text\_char}:
   568  
   569  \Y\P\D \37$\\{print}(\#)\S\\{write}(\#)$\C{`\\{print}' means write on the
   570  terminal}\par
   571  \P\D \37$\\{print\_ln}(\#)\S\\{write\_ln}(\#)$\C{`\\{print}' and then start new
   572  line}\par
   573  \P\D \37$\\{new\_line}\S\\{write\_ln}(\,)$\C{start new line}\par
   574  \P\D \37$\\{write\_ln}(\#)\S\\{writeln}(\#)$\par
   575  \P\D \37$\\{read\_ln}(\#)\S\\{readln}(\#)$\par
   576  \P\D \37$\\{print\_nl}(\#)\S$\C{print information starting on a new line}\6
   577  \&{begin} \37\\{new\_line};\5
   578  $\\{print}(\#)$;\6
   579  \&{end}\par
   580  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
   581  \C{the terminal as an output file}\par
   582  \fi
   583  
   584  \M21\*. Different systems have different ways of specifying that the output on
   585  a
   586  certain file will appear on the user's terminal. Here is one way to do this
   587  on the \PASCAL\ system that was used in \.{TANGLE}'s initial development:
   588  
   589  \Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
   590  \C{send \\{term\_out} output to the terminal}\par
   591  \fi
   592  
   593  \M22\*. The \\{update\_terminal} procedure is called when we want
   594  to make sure that everything we have output to the terminal so far has
   595  actually left the computer's internal buffers and been sent.
   596  
   597  \Y\P\D \37$\\{update\_terminal}\S$\C{empty the terminal output buffer}\par
   598  \fi
   599  
   600  \M23. The main input comes from \\{web\_file}; this input may be overridden
   601  by changes in \\{change\_file}. (If \\{change\_file} is empty, there are no
   602  changes.)
   603  
   604  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
   605  \4\\{web\_file}: \37\\{text\_file};\C{primary input}\6
   606  \4\\{change\_file}: \37\\{text\_file};\C{updates}\par
   607  \fi
   608  
   609  \M24. The following code opens the input files.  Since these files were listed
   610  in the program header, we assume that the \PASCAL\ runtime system has
   611  already checked that suitable file names have been given; therefore no
   612  additional error checking needs to be done. We will see below that
   613  \.{WEAVE} reads through the entire input twice.
   614  
   615  \Y\P\4\&{procedure}\1\  \37\\{open\_input};\C{prepare to read \\{web\_file} and
   616  \\{change\_file}}\2\6
   617  \&{begin} \37$\\{reset}(\\{web\_file})$;\5
   618  $\\{reset}(\\{change\_file})$;\6
   619  \&{end};\par
   620  \fi
   621  
   622  \M25. The main output goes to \\{tex\_file}.
   623  
   624  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
   625  \4\\{tex\_file}: \37\\{text\_file};\par
   626  \fi
   627  
   628  \M26. The following code opens \\{tex\_file}.
   629  Since this file was listed in the program header, we assume that the
   630  \PASCAL\ runtime system has checked that a suitable external file name has
   631  been given.
   632  
   633  \Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
   634  $\\{rewrite}(\\{tex\_file})$;\par
   635  \fi
   636  
   637  \M27. Input goes into an array called \\{buffer}.
   638  
   639  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
   640  \4\\{buffer}: \37\&{array} $[0\to\\{long\_buf\_size}]$ \1\&{of}\5
   641  \\{ASCII\_code};\2\par
   642  \fi
   643  
   644  \M28. The \\{input\_ln} procedure brings the next line of input from the
   645  specified
   646  file into the \\{buffer} array and returns the value \\{true}, unless the file
   647  has
   648  already been entirely read, in which case it returns \\{false}. The conventions
   649  of \TeX\ are followed; i.e., \\{ASCII\_code} numbers representing the next line
   650  of the file are input into $\\{buffer}[0]$, $\\{buffer}[1]$, \dots,
   651  $\\{buffer}[\\{limit}-1]$; trailing blanks are ignored;
   652  and the global variable \\{limit} is set to the length of the
   653  line. The value of \\{limit} must be strictly less than \\{buf\_size}.
   654  
   655  We assume that none of the \\{ASCII\_code} values
   656  of $\\{buffer}[\|j]$ for $0\L\|j<\\{limit}$ is equal to 0, \O{177}, \\{line%
   657  \_feed}, \\{form\_feed},
   658  or \\{carriage\_return}. Since \\{buf\_size} is strictly less than \\{long\_buf%
   659  \_size},
   660  some of \.{WEAVE}'s routines use the fact that it is safe to refer to
   661  $\\{buffer}[\\{limit}+2]$ without overstepping the bounds of the array.
   662  
   663  \Y\P\4\&{function}\1\  \37$\\{input\_ln}(\mathop{\&{var}}\|f:\\{text\_file})$: %
   664  \37\\{boolean};\C{inputs a line or returns \\{false}}\6
   665  \4\&{var} \37\\{final\_limit}: \37$0\to\\{buf\_size}$;\C{\\{limit} without
   666  trailing blanks}\2\6
   667  \&{begin} \37$\\{limit}\K0$;\5
   668  $\\{final\_limit}\K0$;\6
   669  \&{if} $\\{eof}(\|f)$ \1\&{then}\5
   670  $\\{input\_ln}\K\\{false}$\6
   671  \4\&{else} \&{begin} \37\&{while} $\R\\{eoln}(\|f)$ \1\&{do}\6
   672  \&{begin} \37$\\{buffer}[\\{limit}]\K\\{xord}[\|f\^]$;\5
   673  $\\{get}(\|f)$;\5
   674  $\\{incr}(\\{limit})$;\6
   675  \&{if} $\\{buffer}[\\{limit}-1]\I\.{"\ "}$ \1\&{then}\5
   676  $\\{final\_limit}\K\\{limit}$;\2\6
   677  \&{if} $\\{limit}=\\{buf\_size}$ \1\&{then}\6
   678  \&{begin} \37\&{while} $\R\\{eoln}(\|f)$ \1\&{do}\5
   679  $\\{get}(\|f)$;\2\6
   680  $\\{decr}(\\{limit})$;\C{keep $\\{buffer}[\\{buf\_size}]$ empty}\6
   681  \&{if} $\\{final\_limit}>\\{limit}$ \1\&{then}\5
   682  $\\{final\_limit}\K\\{limit}$;\2\6
   683  $\\{print\_nl}(\.{\'!\ Input\ line\ too\ long\'})$;\5
   684  $\\{loc}\K0$;\5
   685  \\{error};\6
   686  \&{end};\2\6
   687  \&{end};\2\6
   688  $\\{read\_ln}(\|f)$;\5
   689  $\\{limit}\K\\{final\_limit}$;\5
   690  $\\{input\_ln}\K\\{true}$;\6
   691  \&{end};\2\6
   692  \&{end};\par
   693  \fi
   694  
   695  \N29.  Reporting errors to the user.
   696  The \.{WEAVE} processor operates in three phases: first it inputs the source
   697  file and stores cross-reference data, then it inputs the source once again and
   698  produces the \TeX\ output file, and finally it sorts and outputs the index.
   699  
   700  The global variables \\{phase\_one} and \\{phase\_three} tell which Phase we
   701  are in.
   702  
   703  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
   704  \4\\{phase\_one}: \37\\{boolean};\C{\\{true} in Phase I, \\{false} in Phases II
   705  and III}\6
   706  \4\\{phase\_three}: \37\\{boolean};\C{\\{true} in Phase III, \\{false} in
   707  Phases I and II}\par
   708  \fi
   709  
   710  \M30. If an error is detected while we are debugging,
   711  we usually want to look at the contents of memory.
   712  A special procedure will be declared later for this purpose.
   713  
   714  \Y\P$\4\X30:Error handling procedures\X\S$\6
   715  \&{debug} \37\ \&{procedure}\1\  \37\\{debug\_help};\5
   716  \\{forward};\ \&{gubed} \par
   717  \As31\ET33\*.
   718  \U2\*.\fi
   719  
   720  \M31. The command `$\\{err\_print}(\.{\'!\ Error\ message\'})$' will report a
   721  syntax error to
   722  the user, by printing the error message at the beginning of a new line and
   723  then giving an indication of where the error was spotted in the source file.
   724  Note that no period follows the error message, since the error routine
   725  will automatically supply a period.
   726  
   727  The actual error indications are provided by a procedure called \\{error}.
   728  However, error messages are not actually reported during phase one,
   729  since errors detected on the first pass will be detected again
   730  during the second.
   731  
   732  \Y\P\D \37$\\{err\_print}(\#)\S$\1\6
   733  \&{begin} \37\&{if} $\R\\{phase\_one}$ \1\&{then}\6
   734  \&{begin} \37\\{new\_line};\5
   735  $\\{print}(\#)$;\5
   736  \\{error};\6
   737  \&{end};\2\6
   738  \&{end}\2\par
   739  \Y\P$\4\X30:Error handling procedures\X\mathrel{+}\S$\6
   740  \4\&{procedure}\1\  \37\\{error};\C{prints `\..' and location of error message}%
   741  \6
   742  \4\&{var} \37$\|k,\39\|l$: \37$0\to\\{long\_buf\_size}$;\C{indices into %
   743  \\{buffer}}\2\6
   744  \&{begin} \37\X32:Print error location based on input buffer\X;\6
   745  \\{update\_terminal};\5
   746  \\{mark\_error};\6
   747  \&{debug} \37$\\{debug\_skipped}\K\\{debug\_cycle}$;\5
   748  \\{debug\_help};\ \&{gubed}\6
   749  \&{end};\par
   750  \fi
   751  
   752  \M32. The error locations can be indicated by using the global variables
   753  \\{loc}, \\{line}, and \\{changing}, which tell respectively the first
   754  unlooked-at position in \\{buffer}, the current line number, and whether or not
   755  the current line is from \\{change\_file} or \\{web\_file}.
   756  This routine should be modified on systems whose standard text editor
   757  has special line-numbering conventions.
   758  
   759  \Y\P$\4\X32:Print error location based on input buffer\X\S$\6
   760  \&{begin} \37\&{if} $\\{changing}$ \1\&{then}\5
   761  $\\{print}(\.{\'.\ (change\ file\ \'})$\ \&{else} $\\{print}(\.{\'.\ (\'})$;\2\6
   762  $\\{print\_ln}(\.{\'l.\'},\39\\{line}:1,\39\.{\')\'})$;\6
   763  \&{if} $\\{loc}\G\\{limit}$ \1\&{then}\5
   764  $\|l\K\\{limit}$\6
   765  \4\&{else} $\|l\K\\{loc}$;\2\6
   766  \&{for} $\|k\K1\mathrel{\&{to}}\|l$ \1\&{do}\6
   767  \&{if} $\\{buffer}[\|k-1]=\\{tab\_mark}$ \1\&{then}\5
   768  $\\{print}(\.{\'\ \'})$\6
   769  \4\&{else} $\\{print}(\\{xchr}[\\{buffer}[\|k-1]])$;\C{print the characters
   770  already read}\2\2\6
   771  \\{new\_line};\6
   772  \&{for} $\|k\K1\mathrel{\&{to}}\|l$ \1\&{do}\5
   773  $\\{print}(\.{\'\ \'})$;\C{space out the next line}\2\6
   774  \&{for} $\|k\K\|l+1\mathrel{\&{to}}\\{limit}$ \1\&{do}\5
   775  $\\{print}(\\{xchr}[\\{buffer}[\|k-1]])$;\C{print the part not yet read}\2\6
   776  \&{if} $\\{buffer}[\\{limit}]=\.{"|"}$ \1\&{then}\5
   777  $\\{print}(\\{xchr}[\.{"|"}])$;\C{end of \PASCAL\ text in module names}\2\6
   778  $\\{print}(\.{\'\ \'})$;\C{this space separates the message from future
   779  asterisks}\6
   780  \&{end}\par
   781  \U31.\fi
   782  
   783  \M33\*. The \\{jump\_out} procedure just cuts across all active procedure
   784  levels
   785  and jumps out of the program. This is the only non-local \&{goto} statement
   786  in \.{WEAVE}. It is used when no recovery from a particular error has
   787  been provided.
   788  
   789  Some \PASCAL\ compilers do not implement non-local \&{goto}  statements.
   790  In such cases the code that appears at label \\{end\_of\_WEAVE} should be
   791  copied into the \\{jump\_out} procedure, followed by a call to a system
   792  procedure
   793  that terminates the program.
   794  
   795  \Y\P\D \37$\\{fatal\_error}(\#)\S$\1\6
   796  \&{begin} \37\\{new\_line};\5
   797  $\\{print}(\#)$;\5
   798  \\{error};\5
   799  \\{mark\_fatal};\5
   800  \\{jump\_out};\6
   801  \&{end}\2\par
   802  \Y\P$\4\X30:Error handling procedures\X\mathrel{+}\S$\6
   803  \4\&{procedure}\1\  \37\\{jump\_out};\2\6
   804  \&{begin} \37$\\{panic}(\\{end\_of\_WEAVE})$;\6
   805  \&{end};\par
   806  \fi
   807  
   808  \M34. Sometimes the program's behavior is far different from what it should be,
   809  and \.{WEAVE} prints an error message that is really for the \.{WEAVE}
   810  maintenance person, not the user. In such cases the program says
   811  $\\{confusion}(\.{\'indication\ of\ where\ we\ are\'})$.
   812  
   813  \Y\P\D \37$\\{confusion}(\#)\S\\{fatal\_error}(\.{\'!\ This\ can\'}\.{\'t\
   814  happen\ (\'},\39\#,\39\.{\')\'})$\par
   815  \fi
   816  
   817  \M35. An overflow stop occurs if \.{WEAVE}'s tables aren't large enough.
   818  
   819  \Y\P\D \37$\\{overflow}(\#)\S\\{fatal\_error}(\.{\'!\ Sorry,\ \'},\39\#,\39\.{%
   820  \'\ capacity\ exceeded\'})$\par
   821  \fi
   822  
   823  \N36.  Data structures.
   824  During the first phase of its processing, \.{WEAVE} puts identifier names,
   825  index entries, and module names into the large \\{byte\_mem} array, which is
   826  packed with eight-bit integers. Allocation is sequential, since names are
   827  never deleted.
   828  
   829  An auxiliary array \\{byte\_start} is used as a directory for \\{byte\_mem},
   830  and the \\{link}, \\{ilk}, and \\{xref} arrays give further information about
   831  names.
   832  These auxiliary arrays consist of sixteen-bit items.
   833  
   834  \Y\P$\4\X11:Types in the outer block\X\mathrel{+}\S$\6
   835  $\\{eight\_bits}=0\to255$;\C{unsigned one-byte quantity}\6
   836  $\\{sixteen\_bits}=0\to65535$;\C{unsigned two-byte quantity}\par
   837  \fi
   838  
   839  \M37. \.{WEAVE} has been designed to avoid the need for indices that are more
   840  than sixteen bits wide, so that it can be used on most computers. But
   841  there are programs that need more than 65536 bytes; \TeX\ is one of these.
   842  To get around this problem, a slight complication has been added to the
   843  data structures:  \\{byte\_mem} is a two-dimensional array, whose first index
   844  is either 0 or 1. (For generality, the first index is actually allowed to
   845  run between 0 and $\\{ww}-1$, where \\{ww} is defined to be 2; the program will
   846  work for any positive value of \\{ww}, and it can be simplified in obvious
   847  ways if $\\{ww}=1$.)
   848  
   849  \Y\P\D \37$\\{ww}=2$\C{we multiply the byte capacity by approximately this
   850  amount}\par
   851  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
   852  \4\\{byte\_mem}: \37\&{packed} \37\&{array} $[0\to\\{ww}-1,\390\to\\{max%
   853  \_bytes}]$ \1\&{of}\5
   854  \\{ASCII\_code};\C{characters of names}\2\6
   855  \4\\{byte\_start}: \37\&{array} $[0\to\\{max\_names}]$ \1\&{of}\5
   856  \\{sixteen\_bits};\C{directory into \\{byte\_mem}}\2\6
   857  \4\\{link}: \37\&{array} $[0\to\\{max\_names}]$ \1\&{of}\5
   858  \\{sixteen\_bits};\C{hash table or tree links}\2\6
   859  \4\\{ilk}: \37\&{array} $[0\to\\{max\_names}]$ \1\&{of}\5
   860  \\{sixteen\_bits};\C{type codes or tree links}\2\6
   861  \4\\{xref}: \37\&{array} $[0\to\\{max\_names}]$ \1\&{of}\5
   862  \\{sixteen\_bits};\C{heads of cross-reference lists}\2\par
   863  \fi
   864  
   865  \M38. The names of identifiers are found by computing a hash address \|h and
   866  then looking at strings of bytes signified by $\\{hash}[\|h]$, $\\{link}[%
   867  \\{hash}[\|h]]$,
   868  $\\{link}[\\{link}[\\{hash}[\|h]]]$, \dots, until either finding the desired
   869  name
   870  or encountering a zero.
   871  
   872  A `\\{name\_pointer}' variable, which signifies a name, is an index into
   873  \\{byte\_start}. The actual sequence of characters in the name pointed to by
   874  \|p appears in positions $\\{byte\_start}[\|p]$ to $\\{byte\_start}[\|p+%
   875  \\{ww}]-1$, inclusive,
   876  in the segment of \\{byte\_mem} whose first index is $\|p\mathbin{\&{mod}}%
   877  \\{ww}$. Thus, when
   878  $\\{ww}=2$ the even-numbered name bytes appear in $\\{byte\_mem}[0,\hbox{$*$}]$
   879  and the odd-numbered ones appear in $\\{byte\_mem}[1,\hbox{$*$}]$.
   880  The pointer 0 is used for undefined module names; we don't
   881  want to use it for the names of identifiers, since 0 stands for a null
   882  pointer in a linked list.
   883  
   884  We usually have $\\{byte\_start}[\\{name\_ptr}+\|w]=\\{byte\_ptr}[(\\{name%
   885  \_ptr}+\|w)\mathbin{\&{mod}}\\{ww}]$
   886  for $0\L\|w<\\{ww}$, since these are the starting positions for the next \\{ww}
   887  names to be stored in \\{byte\_mem}.
   888  
   889  \Y\P\D \37$\\{length}(\#)\S\\{byte\_start}[\#+\\{ww}]-\\{byte\_start}[\#]$%
   890  \C{the length of a name}\par
   891  \Y\P$\4\X11:Types in the outer block\X\mathrel{+}\S$\6
   892  $\\{name\_pointer}=0\to\\{max\_names}$;\C{identifies a name}\par
   893  \fi
   894  
   895  \M39. \P$\X9:Globals in the outer block\X\mathrel{+}\S$\6
   896  \4\\{name\_ptr}: \37\\{name\_pointer};\C{first unused position in \\{byte%
   897  \_start}}\6
   898  \4\\{byte\_ptr}: \37\&{array} $[0\to\\{ww}-1]$ \1\&{of}\5
   899  $0\to\\{max\_bytes}$;\C{first unused position in \\{byte\_mem}}\2\par
   900  \fi
   901  
   902  \M40. \P$\X16:Local variables for initialization\X\mathrel{+}\S$\6
   903  \4\\{wi}: \37$0\to\\{ww}-1$;\C{to initialize the \\{byte\_mem} indices}\par
   904  \fi
   905  
   906  \M41. \P$\X10:Set initial values\X\mathrel{+}\S$\6
   907  \&{for} $\\{wi}\K0\mathrel{\&{to}}\\{ww}-1$ \1\&{do}\6
   908  \&{begin} \37$\\{byte\_start}[\\{wi}]\K0$;\5
   909  $\\{byte\_ptr}[\\{wi}]\K0$;\6
   910  \&{end};\2\6
   911  $\\{byte\_start}[\\{ww}]\K0$;\C{this makes name 0 of length zero}\6
   912  $\\{name\_ptr}\K1$;\par
   913  \fi
   914  
   915  \M42. Several types of identifiers are distinguished by their \\{ilk}:
   916  
   917  \yskip\hang \\{normal} identifiers are part of the \PASCAL\ program and
   918  will appear in italic type.
   919  
   920  \yskip\hang \\{roman} identifiers are index entries that appear after
   921  \.{@\^} in the \.{WEB} file.
   922  
   923  \yskip\hang \\{wildcard} identifiers are index entries that appear after
   924  \.{@:} in the \.{WEB} file.
   925  
   926  \yskip\hang \\{typewriter} identifiers are index entries that appear after
   927  \.{@.} in the \.{WEB} file.
   928  
   929  \yskip\hang \\{array\_like}, \\{begin\_like}, \dots, \\{var\_like}
   930  identifiers are \PASCAL\ reserved words whose \\{ilk} explains how they are
   931  to be treated when \PASCAL\ code is being formatted.
   932  
   933  \yskip\hang Finally, if \|c is an ASCII code, an \\{ilk} equal to
   934  $\\{char\_like}+\|c$ denotes a reserved word that will be converted to
   935  character
   936  \|c.
   937  
   938  \Y\P\D \37$\\{normal}=0$\C{ordinary identifiers have \\{normal} ilk}\par
   939  \P\D \37$\\{roman}=1$\C{normal index entries have \\{roman} ilk}\par
   940  \P\D \37$\\{wildcard}=2$\C{user-formatted index entries have \\{wildcard} ilk}%
   941  \par
   942  \P\D \37$\\{typewriter}=3$\C{`typewriter type' entries have \\{typewriter} ilk}%
   943  \par
   944  \P\D \37$\\{reserved}(\#)\S(\\{ilk}[\#]>\\{typewriter})$\C{tells if a name is a
   945  reserved word}\par
   946  \P\D \37$\\{array\_like}=4$\C{\&{array}, \&{file}, \&{set}}\par
   947  \P\D \37$\\{begin\_like}=5$\C{\&{begin}}\par
   948  \P\D \37$\\{case\_like}=6$\C{\&{case}}\par
   949  \P\D \37$\\{const\_like}=7$\C{\&{const}, \&{label}, \&{type}}\par
   950  \P\D \37$\\{div\_like}=8$\C{\&{div}, \&{mod}}\par
   951  \P\D \37$\\{do\_like}=9$\C{\&{do}, \&{of}, \&{then}}\par
   952  \P\D \37$\\{else\_like}=10$\C{\&{else}}\par
   953  \P\D \37$\\{end\_like}=11$\C{\&{end}}\par
   954  \P\D \37$\\{for\_like}=12$\C{\&{for}, \&{while}, \&{with}}\par
   955  \P\D \37$\\{goto\_like}=13$\C{\&{goto}, \&{packed}}\par
   956  \P\D \37$\\{if\_like}=14$\C{\&{if}}\par
   957  \P\D \37$\\{intercal\_like}=15$\C{not used}\par
   958  \P\D \37$\\{nil\_like}=16$\C{\&{nil}}\par
   959  \P\D \37$\\{proc\_like}=17$\C{\&{function}, \&{procedure}, \&{program}}\par
   960  \P\D \37$\\{record\_like}=18$\C{\&{record}}\par
   961  \P\D \37$\\{repeat\_like}=19$\C{\&{repeat}}\par
   962  \P\D \37$\\{to\_like}=20$\C{\&{downto}, \&{to}}\par
   963  \P\D \37$\\{until\_like}=21$\C{\&{until}}\par
   964  \P\D \37$\\{var\_like}=22$\C{\&{var}}\par
   965  \P\D \37$\\{loop\_like}=23$\C{\&{loop}, \&{xclause}}\par
   966  \P\D \37$\\{char\_like}=24$\C{\&{and}, \&{or}, \&{not}, \&{in}}\par
   967  \fi
   968  
   969  \M43. The names of modules are stored in \\{byte\_mem} together
   970  with the identifier names, but a hash table is not used for them because
   971  \.{WEAVE} needs to be able to recognize a module name when given a prefix of
   972  that name. A conventional binary search tree is used to retrieve module names,
   973  with fields called \\{llink} and \\{rlink} in place of \\{link} and \\{ilk}.
   974  The
   975  root of this tree is $\\{rlink}[0]$.
   976  
   977  \Y\P\D \37$\\{llink}\S\\{link}$\C{left link in binary search tree for module
   978  names}\par
   979  \P\D \37$\\{rlink}\S\\{ilk}$\C{right link in binary search tree for module
   980  names}\par
   981  \P\D \37$\\{root}\S\\{rlink}[0]$\C{the root of the binary search tree for
   982  module names}\par
   983  \Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
   984  $\\{root}\K0$;\C{the binary search tree starts out with nothing in it}\par
   985  \fi
   986  
   987  \M44. Here is a little procedure that prints the text of a given name on the
   988  user's terminal.
   989  
   990  \Y\P\4\&{procedure}\1\  \37$\\{print\_id}(\|p:\\{name\_pointer})$;\C{print
   991  identifier or module name}\6
   992  \4\&{var} \37\|k: \37$0\to\\{max\_bytes}$;\C{index into \\{byte\_mem}}\6
   993  \|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\_mem}}\2\6
   994  \&{begin} \37\&{if} $\|p\G\\{name\_ptr}$ \1\&{then}\5
   995  $\\{print}(\.{\'IMPOSSIBLE\'})$\6
   996  \4\&{else} \&{begin} \37$\|w\K\|p\mathbin{\&{mod}}\\{ww}$;\6
   997  \&{for} $\|k\K\\{byte\_start}[\|p]\mathrel{\&{to}}\\{byte\_start}[\|p+%
   998  \\{ww}]-1$ \1\&{do}\5
   999  $\\{print}(\\{xchr}[\\{byte\_mem}[\|w,\39\|k]])$;\2\6
  1000  \&{end};\2\6
  1001  \&{end};\par
  1002  \fi
  1003  
  1004  \M45. We keep track of the current module number in
  1005  \\{module\_count}, which is the total number of modules that have started.
  1006  Modules which have been altered by a change file entry
  1007  have their \\{changed\_module} flag turned on during the first phase.
  1008  
  1009  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  1010  \4\\{module\_count}: \37$0\to\\{max\_modules}$;\C{the current module number}\6
  1011  \4\\{changed\_module}: \37\&{packed} \37\&{array} $[0\to\\{max\_modules}]$ \1%
  1012  \&{of}\5
  1013  \\{boolean};\C{is it changed?}\2\6
  1014  \4\\{change\_exists}: \37\\{boolean};\C{has any module changed?}\par
  1015  \fi
  1016  
  1017  \M46. The other large memory area in \.{WEAVE} keeps the cross-reference data.
  1018  All uses of the name \|p are recorded in a linked list beginning at
  1019  $\\{xref}[\|p]$, which points into the \\{xmem} array. Entries in \\{xmem}
  1020  consist
  1021  of two sixteen-bit items per word, called the \\{num} and \\{xlink} fields.
  1022  If \|x is an index into \\{xmem}, reached from name \|p, the value of $\\{num}(%
  1023  \|x)$
  1024  is either a module number where \|p is used, or it is \\{def\_flag} plus a
  1025  module number where \|p is defined; and $\\{xlink}(\|x)$ points to the next
  1026  such
  1027  cross reference for \|p, if any. This list of cross references is in
  1028  decreasing order by module number. The current number of cross references
  1029  is \\{xref\_ptr}.
  1030  
  1031  The global variable \\{xref\_switch} is set either to \\{def\_flag} or to zero,
  1032  depending on whether the next cross reference to an identifier is to be
  1033  underlined or not in the index. This switch is set to \\{def\_flag} when
  1034  \.{@!} or \.{@d} or \.{@f} is scanned, and it is cleared to zero when
  1035  the next identifier or index entry cross reference has been made. Similarly,
  1036  the global variable \\{mod\_xref\_switch} is either \\{def\_flag} or zero,
  1037  depending
  1038  on whether a module name is being defined or used.
  1039  
  1040  \Y\P\D \37$\\{num}(\#)\S\\{xmem}[\#].\\{num\_field}$\par
  1041  \P\D \37$\\{xlink}(\#)\S\\{xmem}[\#].\\{xlink\_field}$\par
  1042  \P\D \37$\\{def\_flag}=10240$\C{must be strictly larger than \\{max\_modules}}%
  1043  \par
  1044  \fi
  1045  
  1046  \M47. \P$\X11:Types in the outer block\X\mathrel{+}\S$\6
  1047  $\\{xref\_number}=0\to\\{max\_refs}$;\par
  1048  \fi
  1049  
  1050  \M48. \P$\X9:Globals in the outer block\X\mathrel{+}\S$\6
  1051  \4\\{xmem}: \37\&{array} $[\\{xref\_number}]$ \1\&{of}\5
  1052  \&{packed} \37\1\&{record} \37\hbox{}\6
  1053  \4\\{num\_field}: \37\\{sixteen\_bits};\C{module number plus zero or \\{def%
  1054  \_flag}}\6
  1055  \4\\{xlink\_field}: \37\\{sixteen\_bits};\C{pointer to the previous cross
  1056  reference}\2\6
  1057  \&{end};\2\6
  1058  \4\\{xref\_ptr}: \37\\{xref\_number};\C{the largest occupied position in %
  1059  \\{xmem}}\6
  1060  \4$\\{xref\_switch},\39\\{mod\_xref\_switch}$: \37$0\to\\{def\_flag}$;\C{either
  1061  zero or \\{def\_flag}}\par
  1062  \fi
  1063  
  1064  \M49. \P$\X10:Set initial values\X\mathrel{+}\S$\6
  1065  $\\{xref\_ptr}\K0$;\5
  1066  $\\{xref\_switch}\K0$;\5
  1067  $\\{mod\_xref\_switch}\K0$;\5
  1068  $\\{num}(0)\K0$;\5
  1069  $\\{xref}[0]\K0$;\C{cross references to undefined modules}\par
  1070  \fi
  1071  
  1072  \M50. A new cross reference for an identifier is formed by calling \\{new%
  1073  \_xref},
  1074  which discards duplicate entries and ignores non-underlined references
  1075  to one-letter identifiers or \PASCAL's reserved words.
  1076  
  1077  \Y\P\D \37$\\{append\_xref}(\#)\S$\1\6
  1078  \&{if} $\\{xref\_ptr}=\\{max\_refs}$ \1\&{then}\5
  1079  $\\{overflow}(\.{\'cross\ reference\'})$\6
  1080  \4\&{else} \&{begin} \37$\\{incr}(\\{xref\_ptr})$;\5
  1081  $\\{num}(\\{xref\_ptr})\K\#$;\6
  1082  \&{end}\2\2\par
  1083  \Y\P\4\&{procedure}\1\  \37$\\{new\_xref}(\|p:\\{name\_pointer})$;\6
  1084  \4\&{label} \37\\{exit};\6
  1085  \4\&{var} \37\|q: \37\\{xref\_number};\C{pointer to previous cross reference}\6
  1086  $\|m,\39\|n$: \37\\{sixteen\_bits};\C{new and previous cross-reference value}\2%
  1087  \6
  1088  \&{begin} \37\&{if} $(\\{reserved}(\|p)\V(\\{byte\_start}[\|p]+1=\\{byte%
  1089  \_start}[\|p+\\{ww}]))\W(\\{xref\_switch}=0)$ \1\&{then}\5
  1090  \&{return};\2\6
  1091  $\|m\K\\{module\_count}+\\{xref\_switch}$;\5
  1092  $\\{xref\_switch}\K0$;\5
  1093  $\|q\K\\{xref}[\|p]$;\6
  1094  \&{if} $\|q>0$ \1\&{then}\6
  1095  \&{begin} \37$\|n\K\\{num}(\|q)$;\6
  1096  \&{if} $(\|n=\|m)\V(\|n=\|m+\\{def\_flag})$ \1\&{then}\5
  1097  \&{return}\6
  1098  \4\&{else} \&{if} $\|m=\|n+\\{def\_flag}$ \1\&{then}\6
  1099  \&{begin} \37$\\{num}(\|q)\K\|m$;\5
  1100  \&{return};\6
  1101  \&{end};\2\2\6
  1102  \&{end};\2\6
  1103  $\\{append\_xref}(\|m)$;\5
  1104  $\\{xlink}(\\{xref\_ptr})\K\|q$;\5
  1105  $\\{xref}[\|p]\K\\{xref\_ptr}$;\6
  1106  \4\\{exit}: \37\&{end};\par
  1107  \fi
  1108  
  1109  \M51. The cross reference lists for module names are slightly different.
  1110  Suppose
  1111  that a module name is defined in modules $m_1$, \dots, $m_k$ and used in
  1112  modules $n_1$, \dots, $n_l$. Then its list will contain $m_1+\\{def\_flag}$,
  1113  $m_k+\\{def\_flag}$, \dots, $m_2+\\{def\_flag}$, $n_l$, \dots, $n_1$, in
  1114  this order.  After Phase II, however, the order will be
  1115  $m_1+\\{def\_flag}$, \dots, $m_k+\\{def\_flag}$, $n_1$, \dots, $n_l$.
  1116  
  1117  \Y\P\4\&{procedure}\1\  \37$\\{new\_mod\_xref}(\|p:\\{name\_pointer})$;\6
  1118  \4\&{var} \37$\|q,\39\|r$: \37\\{xref\_number};\C{pointers to previous cross
  1119  references}\2\6
  1120  \&{begin} \37$\|q\K\\{xref}[\|p]$;\5
  1121  $\|r\K0$;\6
  1122  \&{if} $\|q>0$ \1\&{then}\6
  1123  \&{begin} \37\&{if} $\\{mod\_xref\_switch}=0$ \1\&{then}\6
  1124  \&{while} $\\{num}(\|q)\G\\{def\_flag}$ \1\&{do}\6
  1125  \&{begin} \37$\|r\K\|q$;\5
  1126  $\|q\K\\{xlink}(\|q)$;\6
  1127  \&{end}\2\6
  1128  \4\&{else} \&{if} $\\{num}(\|q)\G\\{def\_flag}$ \1\&{then}\6
  1129  \&{begin} \37$\|r\K\|q$;\5
  1130  $\|q\K\\{xlink}(\|q)$;\6
  1131  \&{end};\2\2\6
  1132  \&{end};\2\6
  1133  $\\{append\_xref}(\\{module\_count}+\\{mod\_xref\_switch})$;\5
  1134  $\\{xlink}(\\{xref\_ptr})\K\|q$;\5
  1135  $\\{mod\_xref\_switch}\K0$;\6
  1136  \&{if} $\|r=0$ \1\&{then}\5
  1137  $\\{xref}[\|p]\K\\{xref\_ptr}$\6
  1138  \4\&{else} $\\{xlink}(\|r)\K\\{xref\_ptr}$;\2\6
  1139  \&{end};\par
  1140  \fi
  1141  
  1142  \M52. A third large area of memory is used for sixteen-bit `tokens', which
  1143  appear
  1144  in short lists similar to the strings of characters in \\{byte\_mem}. Token
  1145  lists
  1146  are used to contain the result of \PASCAL\ code translated into \TeX\ form;
  1147  further details about them will be explained later. A \\{text\_pointer}
  1148  variable
  1149  is an index into \\{tok\_start}.
  1150  
  1151  \Y\P$\4\X11:Types in the outer block\X\mathrel{+}\S$\6
  1152  $\\{text\_pointer}=0\to\\{max\_texts}$;\C{identifies a token list}\par
  1153  \fi
  1154  
  1155  \M53. The first position of \\{tok\_mem}
  1156  that is unoccupied by replacement text is called \\{tok\_ptr}, and the first
  1157  unused location of \\{tok\_start} is called \\{text\_ptr}.
  1158  Thus, we usually have $\\{tok\_start}[\\{text\_ptr}]=\\{tok\_ptr}$.
  1159  
  1160  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  1161  \4\hbox{\hskip1em}\\{tok\_mem}: \37\&{packed} \37\&{array} $[0\to\\{max%
  1162  \_toks}]$ \1\&{of}\5
  1163  \\{sixteen\_bits};\C{tokens}\2\6
  1164  \4\hbox{\hskip1em}\\{tok\_start}: \37\&{array} $[\\{text\_pointer}]$ \1\&{of}\5
  1165  \\{sixteen\_bits};\C{directory into \\{tok\_mem}}\2\6
  1166  \4\hbox{\hskip1em}\\{text\_ptr}: \37\\{text\_pointer};\C{first unused position
  1167  in \\{tok\_start}}\6
  1168  \4\hbox{\hskip1em}\\{tok\_ptr}: \37$0\to\\{max\_toks}$;\C{first unused position
  1169  in \\{tok\_mem}}\6
  1170  \&{stat} \37$\\{max\_tok\_ptr},\39\\{max\_txt\_ptr}$: \37$0\to\\{max\_toks}$;%
  1171  \C{largest values occurring}\6
  1172  \&{tats}\par
  1173  \fi
  1174  
  1175  \M54. \P$\X10:Set initial values\X\mathrel{+}\S$\6
  1176  $\\{tok\_ptr}\K1$;\5
  1177  $\\{text\_ptr}\K1$;\5
  1178  $\\{tok\_start}[0]\K1$;\5
  1179  $\\{tok\_start}[1]\K1$;\6
  1180  \&{stat} \37$\\{max\_tok\_ptr}\K1$;\5
  1181  $\\{max\_txt\_ptr}\K1$;\ \&{tats}\par
  1182  \fi
  1183  
  1184  \N55.  Searching for identifiers.
  1185  The hash table described above is updated by the \\{id\_lookup} procedure,
  1186  which finds a given identifier and returns a pointer to its index in
  1187  \\{byte\_start}. The identifier is supposed to match character by character
  1188  and it is also supposed to have a given \\{ilk} code; the same name may be
  1189  present more than once if it is supposed to appear in the index with
  1190  different typesetting conventions.
  1191  If the identifier was not already present, it is inserted into the table.
  1192  
  1193  Because of the way \.{WEAVE}'s scanning mechanism works, it is most convenient
  1194  to let \\{id\_lookup} search for an identifier that is present in the %
  1195  \\{buffer}
  1196  array. Two other global variables specify its position in the buffer: the
  1197  first character is $\\{buffer}[\\{id\_first}]$, and the last is $\\{buffer}[%
  1198  \\{id\_loc}-1]$.
  1199  
  1200  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  1201  \4\\{id\_first}: \37$0\to\\{long\_buf\_size}$;\C{where the current identifier
  1202  begins in the buffer}\6
  1203  \4\\{id\_loc}: \37$0\to\\{long\_buf\_size}$;\C{just after the current
  1204  identifier in the buffer}\7
  1205  \4\\{hash}: \37\&{array} $[0\to\\{hash\_size}]$ \1\&{of}\5
  1206  \\{sixteen\_bits};\C{heads of hash lists}\2\par
  1207  \fi
  1208  
  1209  \M56. Initially all the hash lists are empty.
  1210  
  1211  \Y\P$\4\X16:Local variables for initialization\X\mathrel{+}\S$\6
  1212  \4\|h: \37$0\to\\{hash\_size}$;\C{index into hash-head array}\par
  1213  \fi
  1214  
  1215  \M57. \P$\X10:Set initial values\X\mathrel{+}\S$\6
  1216  \&{for} $\|h\K0\mathrel{\&{to}}\\{hash\_size}-1$ \1\&{do}\5
  1217  $\\{hash}[\|h]\K0$;\2\par
  1218  \fi
  1219  
  1220  \M58. Here now is the main procedure for finding identifiers (and index
  1221  entries).  The parameter \|t is set to the desired \\{ilk} code. The
  1222  identifier must either have $\\{ilk}=\|t$, or we must have
  1223  $\|t=\\{normal}$ and the identifier must be a reserved word.
  1224  
  1225  \Y\P\4\&{function}\1\  \37$\\{id\_lookup}(\|t:\\{eight\_bits})$: \37\\{name%
  1226  \_pointer};\C{finds current identifier}\6
  1227  \4\&{label} \37\\{found};\6
  1228  \4\&{var} \37\|i: \37$0\to\\{long\_buf\_size}$;\C{index into \\{buffer}}\6
  1229  \|h: \37$0\to\\{hash\_size}$;\C{hash code}\6
  1230  \|k: \37$0\to\\{max\_bytes}$;\C{index into \\{byte\_mem}}\6
  1231  \|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\_mem}}\6
  1232  \|l: \37$0\to\\{long\_buf\_size}$;\C{length of the given identifier}\6
  1233  \|p: \37\\{name\_pointer};\C{where the identifier is being sought}\2\6
  1234  \&{begin} \37$\|l\K\\{id\_loc}-\\{id\_first}$;\C{compute the length}\6
  1235  \X59:Compute the hash code \|h\X;\6
  1236  \X60:Compute the name location \|p\X;\6
  1237  \&{if} $\|p=\\{name\_ptr}$ \1\&{then}\5
  1238  \X62:Enter a new name into the table at position \|p\X;\2\6
  1239  $\\{id\_lookup}\K\|p$;\6
  1240  \&{end};\par
  1241  \fi
  1242  
  1243  \M59. A simple hash code is used: If the sequence of
  1244  ASCII codes is $c_1c_2\ldots c_n$, its hash value will be
  1245  $$(2^{n-1}c_1+2^{n-2}c_2+\cdots+c_n)\,\bmod\,\\{hash\_size}.$$
  1246  
  1247  \Y\P$\4\X59:Compute the hash code \|h\X\S$\6
  1248  $\|h\K\\{buffer}[\\{id\_first}]$;\5
  1249  $\|i\K\\{id\_first}+1$;\6
  1250  \&{while} $\|i<\\{id\_loc}$ \1\&{do}\6
  1251  \&{begin} \37$\|h\K(\|h+\|h+\\{buffer}[\|i])\mathbin{\&{mod}}\\{hash\_size}$;\5
  1252  $\\{incr}(\|i)$;\6
  1253  \&{end}\2\par
  1254  \U58.\fi
  1255  
  1256  \M60. If the identifier is new, it will be placed in position $\|p=\\{name%
  1257  \_ptr}$,
  1258  otherwise \|p will point to its existing location.
  1259  
  1260  \Y\P$\4\X60:Compute the name location \|p\X\S$\6
  1261  $\|p\K\\{hash}[\|h]$;\6
  1262  \&{while} $\|p\I0$ \1\&{do}\6
  1263  \&{begin} \37\&{if} $(\\{length}(\|p)=\|l)\W((\\{ilk}[\|p]=\|t)\V((\|t=%
  1264  \\{normal})\W\\{reserved}(\|p)))$ \1\&{then}\5
  1265  \X61:Compare name \|p with current identifier, \&{goto} \\{found} if equal\X;\2%
  1266  \6
  1267  $\|p\K\\{link}[\|p]$;\6
  1268  \&{end};\2\6
  1269  $\|p\K\\{name\_ptr}$;\C{the current identifier is new}\6
  1270  $\\{link}[\|p]\K\\{hash}[\|h]$;\5
  1271  $\\{hash}[\|h]\K\|p$;\C{insert \|p at beginning of hash list}\6
  1272  \4\\{found}: \37\par
  1273  \U58.\fi
  1274  
  1275  \M61. \P$\X61:Compare name \|p with current identifier, \&{goto} \\{found} if
  1276  equal\X\S$\6
  1277  \&{begin} \37$\|i\K\\{id\_first}$;\5
  1278  $\|k\K\\{byte\_start}[\|p]$;\5
  1279  $\|w\K\|p\mathbin{\&{mod}}\\{ww}$;\6
  1280  \&{while} $(\|i<\\{id\_loc})\W(\\{buffer}[\|i]=\\{byte\_mem}[\|w,\39\|k])$ \1%
  1281  \&{do}\6
  1282  \&{begin} \37$\\{incr}(\|i)$;\5
  1283  $\\{incr}(\|k)$;\6
  1284  \&{end};\2\6
  1285  \&{if} $\|i=\\{id\_loc}$ \1\&{then}\5
  1286  \&{goto} \37\\{found};\C{all characters agree}\2\6
  1287  \&{end}\par
  1288  \U60.\fi
  1289  
  1290  \M62. When we begin the following segment of the program, $\|p=\\{name\_ptr}$.
  1291  
  1292  \Y\P$\4\X62:Enter a new name into the table at position \|p\X\S$\6
  1293  \&{begin} \37$\|w\K\\{name\_ptr}\mathbin{\&{mod}}\\{ww}$;\6
  1294  \&{if} $\\{byte\_ptr}[\|w]+\|l>\\{max\_bytes}$ \1\&{then}\5
  1295  $\\{overflow}(\.{\'byte\ memory\'})$;\2\6
  1296  \&{if} $\\{name\_ptr}+\\{ww}>\\{max\_names}$ \1\&{then}\5
  1297  $\\{overflow}(\.{\'name\'})$;\2\6
  1298  $\|i\K\\{id\_first}$;\5
  1299  $\|k\K\\{byte\_ptr}[\|w]$;\C{get ready to move the identifier into \\{byte%
  1300  \_mem}}\6
  1301  \&{while} $\|i<\\{id\_loc}$ \1\&{do}\6
  1302  \&{begin} \37$\\{byte\_mem}[\|w,\39\|k]\K\\{buffer}[\|i]$;\5
  1303  $\\{incr}(\|k)$;\5
  1304  $\\{incr}(\|i)$;\6
  1305  \&{end};\2\6
  1306  $\\{byte\_ptr}[\|w]\K\|k$;\5
  1307  $\\{byte\_start}[\\{name\_ptr}+\\{ww}]\K\|k$;\5
  1308  $\\{incr}(\\{name\_ptr})$;\5
  1309  $\\{ilk}[\|p]\K\|t$;\5
  1310  $\\{xref}[\|p]\K0$;\6
  1311  \&{end}\par
  1312  \U58.\fi
  1313  
  1314  \N63.  Initializing the table of reserved words.
  1315  We have to get \PASCAL's reserved words into the hash table, and the
  1316  simplest way to do this is to insert them every time \.{WEAVE} is run.
  1317  A few macros permit us to do the initialization with a compact program.
  1318  
  1319  \Y\P\D \37$\\{sid9}(\#)\S\\{buffer}[9]\K\#$;\5
  1320  $\\{cur\_name}\K\\{id\_lookup}$\par
  1321  \P\D \37$\\{sid8}(\#)\S\\{buffer}[8]\K\#$;\5
  1322  \\{sid9}\par
  1323  \P\D \37$\\{sid7}(\#)\S\\{buffer}[7]\K\#$;\5
  1324  \\{sid8}\par
  1325  \P\D \37$\\{sid6}(\#)\S\\{buffer}[6]\K\#$;\5
  1326  \\{sid7}\par
  1327  \P\D \37$\\{sid5}(\#)\S\\{buffer}[5]\K\#$;\5
  1328  \\{sid6}\par
  1329  \P\D \37$\\{sid4}(\#)\S\\{buffer}[4]\K\#$;\5
  1330  \\{sid5}\par
  1331  \P\D \37$\\{sid3}(\#)\S\\{buffer}[3]\K\#$;\5
  1332  \\{sid4}\par
  1333  \P\D \37$\\{sid2}(\#)\S\\{buffer}[2]\K\#$;\5
  1334  \\{sid3}\par
  1335  \P\D \37$\\{sid1}(\#)\S\\{buffer}[1]\K\#$;\5
  1336  \\{sid2}\par
  1337  \P\D \37$\\{id2}\S\\{id\_first}\K8$;\5
  1338  \\{sid8}\par
  1339  \P\D \37$\\{id3}\S\\{id\_first}\K7$;\5
  1340  \\{sid7}\par
  1341  \P\D \37$\\{id4}\S\\{id\_first}\K6$;\5
  1342  \\{sid6}\par
  1343  \P\D \37$\\{id5}\S\\{id\_first}\K5$;\5
  1344  \\{sid5}\par
  1345  \P\D \37$\\{id6}\S\\{id\_first}\K4$;\5
  1346  \\{sid4}\par
  1347  \P\D \37$\\{id7}\S\\{id\_first}\K3$;\5
  1348  \\{sid3}\par
  1349  \P\D \37$\\{id8}\S\\{id\_first}\K2$;\5
  1350  \\{sid2}\par
  1351  \P\D \37$\\{id9}\S\\{id\_first}\K1$;\5
  1352  \\{sid1}\par
  1353  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  1354  \4\\{cur\_name}: \37\\{name\_pointer};\C{points to the identifier just
  1355  inserted}\par
  1356  \fi
  1357  
  1358  \M64. The intended use of the macros above might not be immediately obvious,
  1359  but the riddle is answered by the following:
  1360  
  1361  \Y\P$\4\X64:Store all the reserved words\X\S$\6
  1362  $\\{id\_loc}\K10$;\6
  1363  $\\{id3}(\.{"a"})(\.{"n"})(\.{"d"})(\\{char\_like}+\\{and\_sign})$;\6
  1364  $\\{id5}(\.{"a"})(\.{"r"})(\.{"r"})(\.{"a"})(\.{"y"})(\\{array\_like})$;\6
  1365  $\\{id5}(\.{"b"})(\.{"e"})(\.{"g"})(\.{"i"})(\.{"n"})(\\{begin\_like})$;\6
  1366  $\\{id4}(\.{"c"})(\.{"a"})(\.{"s"})(\.{"e"})(\\{case\_like})$;\6
  1367  $\\{id5}(\.{"c"})(\.{"o"})(\.{"n"})(\.{"s"})(\.{"t"})(\\{const\_like})$;\6
  1368  $\\{id3}(\.{"d"})(\.{"i"})(\.{"v"})(\\{div\_like})$;\6
  1369  $\\{id2}(\.{"d"})(\.{"o"})(\\{do\_like})$;\6
  1370  $\\{id6}(\.{"d"})(\.{"o"})(\.{"w"})(\.{"n"})(\.{"t"})(\.{"o"})(\\{to\_like})$;\6
  1371  $\\{id4}(\.{"e"})(\.{"l"})(\.{"s"})(\.{"e"})(\\{else\_like})$;\6
  1372  $\\{id3}(\.{"e"})(\.{"n"})(\.{"d"})(\\{end\_like})$;\6
  1373  $\\{id4}(\.{"f"})(\.{"i"})(\.{"l"})(\.{"e"})(\\{array\_like})$;\6
  1374  $\\{id3}(\.{"f"})(\.{"o"})(\.{"r"})(\\{for\_like})$;\6
  1375  $\\{id8}(\.{"f"})(\.{"u"})(\.{"n"})(\.{"c"})(\.{"t"})(\.{"i"})(\.{"o"})(%
  1376  \.{"n"})(\\{proc\_like})$;\6
  1377  $\\{id4}(\.{"g"})(\.{"o"})(\.{"t"})(\.{"o"})(\\{goto\_like})$;\6
  1378  $\\{id2}(\.{"i"})(\.{"f"})(\\{if\_like})$;\6
  1379  $\\{id2}(\.{"i"})(\.{"n"})(\\{char\_like}+\\{set\_element\_sign})$;\6
  1380  $\\{id5}(\.{"l"})(\.{"a"})(\.{"b"})(\.{"e"})(\.{"l"})(\\{const\_like})$;\6
  1381  $\\{id3}(\.{"m"})(\.{"o"})(\.{"d"})(\\{div\_like})$;\6
  1382  $\\{id3}(\.{"n"})(\.{"i"})(\.{"l"})(\\{nil\_like})$;\6
  1383  $\\{id3}(\.{"n"})(\.{"o"})(\.{"t"})(\\{char\_like}+\\{not\_sign})$;\6
  1384  $\\{id2}(\.{"o"})(\.{"f"})(\\{do\_like})$;\6
  1385  $\\{id2}(\.{"o"})(\.{"r"})(\\{char\_like}+\\{or\_sign})$;\6
  1386  $\\{id6}(\.{"p"})(\.{"a"})(\.{"c"})(\.{"k"})(\.{"e"})(\.{"d"})(\\{goto%
  1387  \_like})$;\6
  1388  $\\{id9}(\.{"p"})(\.{"r"})(\.{"o"})(\.{"c"})(\.{"e"})(\.{"d"})(\.{"u"})(%
  1389  \.{"r"})(\.{"e"})(\\{proc\_like})$;\6
  1390  $\\{id7}(\.{"p"})(\.{"r"})(\.{"o"})(\.{"g"})(\.{"r"})(\.{"a"})(\.{"m"})(\\{proc%
  1391  \_like})$;\6
  1392  $\\{id6}(\.{"r"})(\.{"e"})(\.{"c"})(\.{"o"})(\.{"r"})(\.{"d"})(\\{record%
  1393  \_like})$;\6
  1394  $\\{id6}(\.{"r"})(\.{"e"})(\.{"p"})(\.{"e"})(\.{"a"})(\.{"t"})(\\{repeat%
  1395  \_like})$;\6
  1396  $\\{id3}(\.{"s"})(\.{"e"})(\.{"t"})(\\{array\_like})$;\6
  1397  $\\{id4}(\.{"t"})(\.{"h"})(\.{"e"})(\.{"n"})(\\{do\_like})$;\6
  1398  $\\{id2}(\.{"t"})(\.{"o"})(\\{to\_like})$;\6
  1399  $\\{id4}(\.{"t"})(\.{"y"})(\.{"p"})(\.{"e"})(\\{const\_like})$;\6
  1400  $\\{id5}(\.{"u"})(\.{"n"})(\.{"t"})(\.{"i"})(\.{"l"})(\\{until\_like})$;\6
  1401  $\\{id3}(\.{"v"})(\.{"a"})(\.{"r"})(\\{var\_like})$;\6
  1402  $\\{id5}(\.{"w"})(\.{"h"})(\.{"i"})(\.{"l"})(\.{"e"})(\\{for\_like})$;\6
  1403  $\\{id4}(\.{"w"})(\.{"i"})(\.{"t"})(\.{"h"})(\\{for\_like})$;\6
  1404  $\\{id7}(\.{"x"})(\.{"c"})(\.{"l"})(\.{"a"})(\.{"u"})(\.{"s"})(\.{"e"})(\\{loop%
  1405  \_like})$;\par
  1406  \U261\*.\fi
  1407  
  1408  \N65.  Searching for module names.
  1409  The \\{mod\_lookup} procedure finds the module name $\\{mod\_text}[1\to\|l]$ in
  1410  the
  1411  search tree, after inserting it if necessary, and returns a pointer to
  1412  where it was found.
  1413  
  1414  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  1415  \4\\{mod\_text}: \37\&{array} $[0\to\\{longest\_name}]$ \1\&{of}\5
  1416  \\{ASCII\_code};\C{name being sought for}\2\par
  1417  \fi
  1418  
  1419  \M66. According to the rules of \.{WEB}, no module name
  1420  should be a proper prefix of another, so a ``clean'' comparison should
  1421  occur between any two names. The result of \\{mod\_lookup} is 0 if this
  1422  prefix condition is violated. An error message is printed when such violations
  1423  are detected during phase two of \.{WEAVE}.
  1424  
  1425  \Y\P\D \37$\\{less}=0$\C{the first name is lexicographically less than the
  1426  second}\par
  1427  \P\D \37$\\{equal}=1$\C{the first name is equal to the second}\par
  1428  \P\D \37$\\{greater}=2$\C{the first name is lexicographically greater than the
  1429  second}\par
  1430  \P\D \37$\\{prefix}=3$\C{the first name is a proper prefix of the second}\par
  1431  \P\D \37$\\{extension}=4$\C{the first name is a proper extension of the second}%
  1432  \par
  1433  \Y\P\4\&{function}\1\  \37$\\{mod\_lookup}(\|l:\\{sixteen\_bits})$: \37\\{name%
  1434  \_pointer};\C{finds module name}\6
  1435  \4\&{label} \37\\{found};\6
  1436  \4\&{var} \37\|c: \37$\\{less}\to\\{extension}$;\C{comparison between two
  1437  names}\6
  1438  \|j: \37$0\to\\{longest\_name}$;\C{index into \\{mod\_text}}\6
  1439  \|k: \37$0\to\\{max\_bytes}$;\C{index into \\{byte\_mem}}\6
  1440  \|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\_mem}}\6
  1441  \|p: \37\\{name\_pointer};\C{current node of the search tree}\6
  1442  \|q: \37\\{name\_pointer};\C{father of node \|p}\2\6
  1443  \&{begin} \37$\|c\K\\{greater}$;\5
  1444  $\|q\K0$;\5
  1445  $\|p\K\\{root}$;\6
  1446  \&{while} $\|p\I0$ \1\&{do}\6
  1447  \&{begin} \37\X68:Set variable \|c to the result of comparing the given name to
  1448  name \|p\X;\6
  1449  $\|q\K\|p$;\6
  1450  \&{if} $\|c=\\{less}$ \1\&{then}\5
  1451  $\|p\K\\{llink}[\|q]$\6
  1452  \4\&{else} \&{if} $\|c=\\{greater}$ \1\&{then}\5
  1453  $\|p\K\\{rlink}[\|q]$\6
  1454  \4\&{else} \&{goto} \37\\{found};\2\2\6
  1455  \&{end};\2\6
  1456  \X67:Enter a new module name into the tree\X;\6
  1457  \4\\{found}: \37\&{if} $\|c\I\\{equal}$ \1\&{then}\6
  1458  \&{begin} \37$\\{err\_print}(\.{\'!\ Incompatible\ section\ names\'})$;\5
  1459  $\|p\K0$;\6
  1460  \&{end};\2\6
  1461  $\\{mod\_lookup}\K\|p$;\6
  1462  \&{end};\par
  1463  \fi
  1464  
  1465  \M67. \P$\X67:Enter a new module name into the tree\X\S$\6
  1466  $\|w\K\\{name\_ptr}\mathbin{\&{mod}}\\{ww}$;\5
  1467  $\|k\K\\{byte\_ptr}[\|w]$;\6
  1468  \&{if} $\|k+\|l>\\{max\_bytes}$ \1\&{then}\5
  1469  $\\{overflow}(\.{\'byte\ memory\'})$;\2\6
  1470  \&{if} $\\{name\_ptr}>\\{max\_names}-\\{ww}$ \1\&{then}\5
  1471  $\\{overflow}(\.{\'name\'})$;\2\6
  1472  $\|p\K\\{name\_ptr}$;\6
  1473  \&{if} $\|c=\\{less}$ \1\&{then}\5
  1474  $\\{llink}[\|q]\K\|p$\6
  1475  \4\&{else} $\\{rlink}[\|q]\K\|p$;\2\6
  1476  $\\{llink}[\|p]\K0$;\5
  1477  $\\{rlink}[\|p]\K0$;\5
  1478  $\\{xref}[\|p]\K0$;\5
  1479  $\|c\K\\{equal}$;\6
  1480  \&{for} $\|j\K1\mathrel{\&{to}}\|l$ \1\&{do}\5
  1481  $\\{byte\_mem}[\|w,\39\|k+\|j-1]\K\\{mod\_text}[\|j]$;\2\6
  1482  $\\{byte\_ptr}[\|w]\K\|k+\|l$;\5
  1483  $\\{byte\_start}[\\{name\_ptr}+\\{ww}]\K\|k+\|l$;\5
  1484  $\\{incr}(\\{name\_ptr})$;\par
  1485  \U66.\fi
  1486  
  1487  \M68. \P$\X68:Set variable \|c to the result of comparing the given name to
  1488  name \|p\X\S$\6
  1489  \&{begin} \37$\|k\K\\{byte\_start}[\|p]$;\5
  1490  $\|w\K\|p\mathbin{\&{mod}}\\{ww}$;\5
  1491  $\|c\K\\{equal}$;\5
  1492  $\|j\K1$;\6
  1493  \&{while} $(\|k<\\{byte\_start}[\|p+\\{ww}])\W(\|j\L\|l)\W(\\{mod\_text}[\|j]=%
  1494  \\{byte\_mem}[\|w,\39\|k])$ \1\&{do}\6
  1495  \&{begin} \37$\\{incr}(\|k)$;\5
  1496  $\\{incr}(\|j)$;\6
  1497  \&{end};\2\6
  1498  \&{if} $\|k=\\{byte\_start}[\|p+\\{ww}]$ \1\&{then}\6
  1499  \&{if} $\|j>\|l$ \1\&{then}\5
  1500  $\|c\K\\{equal}$\6
  1501  \4\&{else} $\|c\K\\{extension}$\2\6
  1502  \4\&{else} \&{if} $\|j>\|l$ \1\&{then}\5
  1503  $\|c\K\\{prefix}$\6
  1504  \4\&{else} \&{if} $\\{mod\_text}[\|j]<\\{byte\_mem}[\|w,\39\|k]$ \1\&{then}\5
  1505  $\|c\K\\{less}$\6
  1506  \4\&{else} $\|c\K\\{greater}$;\2\2\2\6
  1507  \&{end}\par
  1508  \Us66\ET69.\fi
  1509  
  1510  \M69. The \\{prefix\_lookup} procedure is supposed to find exactly one module
  1511  name that has $\\{mod\_text}[1\to\|l]$ as a prefix. Actually the algorithm
  1512  silently accepts also the situation that some module name is a prefix of
  1513  $\\{mod\_text}[1\to\|l]$, because the user who painstakingly typed in more than
  1514  necessary probably doesn't want to be told about the wasted effort.
  1515  
  1516  Recall that error messages are not printed during phase one. It is
  1517  possible that the \\{prefix\_lookup} procedure will fail on the first pass,
  1518  because there is no match, yet the second pass might detect no error if a
  1519  matching module name has occurred after the offending prefix. In such a
  1520  case the cross-reference information will be incorrect and \.{WEAVE} will
  1521  report no error. However, such a mistake will be detected by the
  1522  \.{TANGLE} processor.
  1523  
  1524  \Y\P\4\&{function}\1\  \37$\\{prefix\_lookup}(\|l:\\{sixteen\_bits})$: \37%
  1525  \\{name\_pointer};\C{finds name extension}\6
  1526  \4\&{var} \37\|c: \37$\\{less}\to\\{extension}$;\C{comparison between two
  1527  names}\6
  1528  \\{count}: \37$0\to\\{max\_names}$;\C{the number of hits}\6
  1529  \|j: \37$0\to\\{longest\_name}$;\C{index into \\{mod\_text}}\6
  1530  \|k: \37$0\to\\{max\_bytes}$;\C{index into \\{byte\_mem}}\6
  1531  \|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\_mem}}\6
  1532  \|p: \37\\{name\_pointer};\C{current node of the search tree}\6
  1533  \|q: \37\\{name\_pointer};\C{another place to resume the search after one
  1534  branch is done}\6
  1535  \|r: \37\\{name\_pointer};\C{extension found}\2\6
  1536  \&{begin} \37$\|q\K0$;\5
  1537  $\|p\K\\{root}$;\5
  1538  $\\{count}\K0$;\5
  1539  $\|r\K0$;\C{begin search at root of tree}\6
  1540  \&{while} $\|p\I0$ \1\&{do}\6
  1541  \&{begin} \37\X68:Set variable \|c to the result of comparing the given name to
  1542  name \|p\X;\6
  1543  \&{if} $\|c=\\{less}$ \1\&{then}\5
  1544  $\|p\K\\{llink}[\|p]$\6
  1545  \4\&{else} \&{if} $\|c=\\{greater}$ \1\&{then}\5
  1546  $\|p\K\\{rlink}[\|p]$\6
  1547  \4\&{else} \&{begin} \37$\|r\K\|p$;\5
  1548  $\\{incr}(\\{count})$;\5
  1549  $\|q\K\\{rlink}[\|p]$;\5
  1550  $\|p\K\\{llink}[\|p]$;\6
  1551  \&{end};\2\2\6
  1552  \&{if} $\|p=0$ \1\&{then}\6
  1553  \&{begin} \37$\|p\K\|q$;\5
  1554  $\|q\K0$;\6
  1555  \&{end};\2\6
  1556  \&{end};\2\6
  1557  \&{if} $\\{count}\I1$ \1\&{then}\6
  1558  \&{if} $\\{count}=0$ \1\&{then}\5
  1559  $\\{err\_print}(\.{\'!\ Name\ does\ not\ match\'})$\6
  1560  \4\&{else} $\\{err\_print}(\.{\'!\ Ambiguous\ prefix\'})$;\2\2\6
  1561  $\\{prefix\_lookup}\K\|r$;\C{the result will be 0 if there was no match}\6
  1562  \&{end};\par
  1563  \fi
  1564  
  1565  \N70.  Lexical scanning.
  1566  Let us now consider the subroutines that read the \.{WEB} source file
  1567  and break it into meaningful units. There are four such procedures:
  1568  One simply skips to the next `\.{@\ }' or `\.{@*}' that begins a
  1569  module; another passes over the \TeX\ text at the beginning of a
  1570  module; the third passes over the \TeX\ text in a \PASCAL\ comment;
  1571  and the last, which is the most interesting, gets the next token of
  1572  a \PASCAL\ text.
  1573  
  1574  \fi
  1575  
  1576  \M71. But first we need to consider the low-level routine \\{get\_line}
  1577  that takes care of merging \\{change\_file} into \\{web\_file}. The \\{get%
  1578  \_line}
  1579  procedure also updates the line numbers for error messages.
  1580  
  1581  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  1582  \4\\{ii}: \37\\{integer};\C{general purpose  \&{for}  loop variable in the
  1583  outer block}\6
  1584  \4\\{line}: \37\\{integer};\C{the number of the current line in the current
  1585  file}\6
  1586  \4\\{other\_line}: \37\\{integer};\C{the number of the current line in the
  1587  input file that   is not currently being read}\6
  1588  \4\\{temp\_line}: \37\\{integer};\C{used when interchanging \\{line} with %
  1589  \\{other\_line}}\6
  1590  \4\\{limit}: \37$0\to\\{long\_buf\_size}$;\C{the last character position
  1591  occupied in the buffer}\6
  1592  \4\\{loc}: \37$0\to\\{long\_buf\_size}$;\C{the next character position to be
  1593  read from the buffer}\6
  1594  \4\\{input\_has\_ended}: \37\\{boolean};\C{if \\{true}, there is no more input}%
  1595  \6
  1596  \4\\{changing}: \37\\{boolean};\C{if \\{true}, the current line is from %
  1597  \\{change\_file}}\6
  1598  \4\\{change\_pending}: \37\\{boolean};\C{if \\{true}, the current change is not
  1599  yet   recorded in $\\{changed\_module}[\\{module\_count}]$}\par
  1600  \fi
  1601  
  1602  \M72. As we change \\{changing} from \\{true} to \\{false} and back again, we
  1603  must
  1604  remember to swap the values of \\{line} and \\{other\_line} so that the \\{err%
  1605  \_print}
  1606  routine will be sure to report the correct line number.
  1607  
  1608  \Y\P\D \37$\\{change\_changing}\S\\{changing}\K\R\\{changing}$;\5
  1609  $\\{temp\_line}\K\\{other\_line}$;\5
  1610  $\\{other\_line}\K\\{line}$;\5
  1611  $\\{line}\K\\{temp\_line}$\C{\\{line}\hbox{$\null\BA\null$}\\{other\_line}}\par
  1612  \fi
  1613  
  1614  \M73. When \\{changing} is \\{false}, the next line of \\{change\_file} is kept
  1615  in
  1616  $\\{change\_buffer}[0\to\\{change\_limit}]$, for purposes of comparison with
  1617  the next
  1618  line of \\{web\_file}. After the change file has been completely input, we
  1619  set $\\{change\_limit}\K0$, so that no further matches will be made.
  1620  
  1621  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  1622  \4\\{change\_buffer}: \37\&{array} $[0\to\\{buf\_size}]$ \1\&{of}\5
  1623  \\{ASCII\_code};\2\6
  1624  \4\\{change\_limit}: \37$0\to\\{buf\_size}$;\C{the last position occupied in %
  1625  \\{change\_buffer}}\par
  1626  \fi
  1627  
  1628  \M74. Here's a simple function that checks if the two buffers are different.
  1629  
  1630  \Y\P\4\&{function}\1\  \37\\{lines\_dont\_match}: \37\\{boolean};\6
  1631  \4\&{label} \37\\{exit};\6
  1632  \4\&{var} \37\|k: \37$0\to\\{buf\_size}$;\C{index into the buffers}\2\6
  1633  \&{begin} \37$\\{lines\_dont\_match}\K\\{true}$;\6
  1634  \&{if} $\\{change\_limit}\I\\{limit}$ \1\&{then}\5
  1635  \&{return};\2\6
  1636  \&{if} $\\{limit}>0$ \1\&{then}\6
  1637  \&{for} $\|k\K0\mathrel{\&{to}}\\{limit}-1$ \1\&{do}\6
  1638  \&{if} $\\{change\_buffer}[\|k]\I\\{buffer}[\|k]$ \1\&{then}\5
  1639  \&{return};\2\2\2\6
  1640  $\\{lines\_dont\_match}\K\\{false}$;\6
  1641  \4\\{exit}: \37\&{end};\par
  1642  \fi
  1643  
  1644  \M75. Procedure \\{prime\_the\_change\_buffer} sets \\{change\_buffer} in
  1645  preparation
  1646  for the next matching operation. Since blank lines in the change file are
  1647  not used for matching, we have $(\\{change\_limit}=0)\W\R\\{changing}$ if and
  1648  only if the change file is exhausted. This procedure is called only
  1649  when \\{changing} is true; hence error messages will be reported correctly.
  1650  
  1651  \Y\P\4\&{procedure}\1\  \37\\{prime\_the\_change\_buffer};\6
  1652  \4\&{label} \37$\\{continue},\39\\{done},\39\\{exit}$;\6
  1653  \4\&{var} \37\|k: \37$0\to\\{buf\_size}$;\C{index into the buffers}\2\6
  1654  \&{begin} \37$\\{change\_limit}\K0$;\C{this value will be used if the change
  1655  file ends}\6
  1656  \X76:Skip over comment lines in the change file; \&{return} if end of file\X;\6
  1657  \X77:Skip to the next nonblank line; \&{return} if end of file\X;\6
  1658  \X78:Move \\{buffer} and \\{limit} to \\{change\_buffer} and \\{change\_limit}%
  1659  \X;\6
  1660  \4\\{exit}: \37\&{end};\par
  1661  \fi
  1662  
  1663  \M76. While looking for a line that begins with \.{@x} in the change file,
  1664  we allow lines that begin with \.{@}, as long as they don't begin with
  1665  \.{@y} or \.{@z} (which would probably indicate that the change file is
  1666  fouled up).
  1667  
  1668  \Y\P$\4\X76:Skip over comment lines in the change file; \&{return} if end of
  1669  file\X\S$\6
  1670  \~ \1\&{loop}\ \&{begin} \37$\\{incr}(\\{line})$;\6
  1671  \&{if} $\R\\{input\_ln}(\\{change\_file})$ \1\&{then}\5
  1672  \&{return};\2\6
  1673  \&{if} $\\{limit}<2$ \1\&{then}\5
  1674  \&{goto} \37\\{continue};\2\6
  1675  \&{if} $\\{buffer}[0]\I\.{"@"}$ \1\&{then}\5
  1676  \&{goto} \37\\{continue};\2\6
  1677  \&{if} $(\\{buffer}[1]\G\.{"X"})\W(\\{buffer}[1]\L\.{"Z"})$ \1\&{then}\5
  1678  $\\{buffer}[1]\K\\{buffer}[1]+\.{"z"}-\.{"Z"}$;\C{lowercasify}\2\6
  1679  \&{if} $\\{buffer}[1]=\.{"x"}$ \1\&{then}\5
  1680  \&{goto} \37\\{done};\2\6
  1681  \&{if} $(\\{buffer}[1]=\.{"y"})\V(\\{buffer}[1]=\.{"z"})$ \1\&{then}\6
  1682  \&{begin} \37$\\{loc}\K2$;\5
  1683  $\\{err\_print}(\.{\'!\ Where\ is\ the\ matching\ @x?\'})$;\6
  1684  \&{end};\2\6
  1685  \4\\{continue}: \37\&{end};\2\6
  1686  \4\\{done}: \37\par
  1687  \U75.\fi
  1688  
  1689  \M77. Here we are looking at lines following the \.{@x}.
  1690  
  1691  \Y\P$\4\X77:Skip to the next nonblank line; \&{return} if end of file\X\S$\6
  1692  \1\&{repeat} \37$\\{incr}(\\{line})$;\6
  1693  \&{if} $\R\\{input\_ln}(\\{change\_file})$ \1\&{then}\6
  1694  \&{begin} \37$\\{err\_print}(\.{\'!\ Change\ file\ ended\ after\ @x\'})$;\5
  1695  \&{return};\6
  1696  \&{end};\2\6
  1697  \4\&{until}\5
  1698  $\\{limit}>0$;\2\par
  1699  \U75.\fi
  1700  
  1701  \M78. \P$\X78:Move \\{buffer} and \\{limit} to \\{change\_buffer} and \\{change%
  1702  \_limit}\X\S$\6
  1703  \&{begin} \37$\\{change\_limit}\K\\{limit}$;\6
  1704  \&{if} $\\{limit}>0$ \1\&{then}\6
  1705  \&{for} $\|k\K0\mathrel{\&{to}}\\{limit}-1$ \1\&{do}\5
  1706  $\\{change\_buffer}[\|k]\K\\{buffer}[\|k]$;\2\2\6
  1707  \&{end}\par
  1708  \Us75\ET79.\fi
  1709  
  1710  \M79. The following procedure is used to see if the next change entry should
  1711  go into effect; it is called only when \\{changing} is false.
  1712  The idea is to test whether or not the current
  1713  contents of \\{buffer} matches the current contents of \\{change\_buffer}.
  1714  If not, there's nothing more to do; but if so, a change is called for:
  1715  All of the text down to the \.{@y} is supposed to match. An error
  1716  message is issued if any discrepancy is found. Then the procedure
  1717  prepares to read the next line from \\{change\_file}.
  1718  
  1719  When a match is found, the current module is marked as changed unless
  1720  the first line after the \.{@x} and after the \.{@y} both start with
  1721  either \.{\'@*\'} or \.{\'@\ \'} (possibly preceded by whitespace).
  1722  
  1723  \Y\P\D \37$\\{if\_module\_start\_then\_make\_change\_pending}(\#)\S\\{loc}\K0$;%
  1724  \5
  1725  $\\{buffer}[\\{limit}]\K\.{"!"}$;\6
  1726  \&{while} $(\\{buffer}[\\{loc}]=\.{"\ "})\V(\\{buffer}[\\{loc}]=\\{tab\_mark})$
  1727  \1\&{do}\5
  1728  $\\{incr}(\\{loc})$;\2\6
  1729  $\\{buffer}[\\{limit}]\K\.{"\ "}$;\6
  1730  \&{if} $\\{buffer}[\\{loc}]=\.{"@"}$ \1\&{then}\6
  1731  \&{if} $(\\{buffer}[\\{loc}+1]=\.{"*"})\V(\\{buffer}[\\{loc}+1]=\.{"\ "})\V(%
  1732  \\{buffer}[\\{loc}+1]=\\{tab\_mark})$ \1\&{then}\5
  1733  $\\{change\_pending}\K\#$\2\2\par
  1734  \Y\P\4\&{procedure}\1\  \37\\{check\_change};\C{switches to \\{change\_file} if
  1735  the buffers match}\6
  1736  \4\&{label} \37\\{exit};\6
  1737  \4\&{var} \37\|n: \37\\{integer};\C{the number of discrepancies found}\6
  1738  \|k: \37$0\to\\{buf\_size}$;\C{index into the buffers}\2\6
  1739  \&{begin} \37\&{if} $\\{lines\_dont\_match}$ \1\&{then}\5
  1740  \&{return};\2\6
  1741  $\\{change\_pending}\K\\{false}$;\6
  1742  \&{if} $\R\\{changed\_module}[\\{module\_count}]$ \1\&{then}\6
  1743  \&{begin} \37$\\{if\_module\_start\_then\_make\_change\_pending}(\\{true})$;\6
  1744  \&{if} $\R\\{change\_pending}$ \1\&{then}\5
  1745  $\\{changed\_module}[\\{module\_count}]\K\\{true}$;\2\6
  1746  \&{end};\2\6
  1747  $\|n\K0$;\6
  1748  \~ \1\&{loop}\ \&{begin} \37\\{change\_changing};\C{now it's \\{true}}\6
  1749  $\\{incr}(\\{line})$;\6
  1750  \&{if} $\R\\{input\_ln}(\\{change\_file})$ \1\&{then}\6
  1751  \&{begin} \37$\\{err\_print}(\.{\'!\ Change\ file\ ended\ before\ @y\'})$;\5
  1752  $\\{change\_limit}\K0$;\5
  1753  \\{change\_changing};\C{\\{false} again}\6
  1754  \&{return};\6
  1755  \&{end};\2\6
  1756  \X80:If the current line starts with \.{@y}, report any discrepancies and %
  1757  \&{return}\X;\6
  1758  \X78:Move \\{buffer} and \\{limit} to \\{change\_buffer} and \\{change\_limit}%
  1759  \X;\6
  1760  \\{change\_changing};\C{now it's \\{false}}\6
  1761  $\\{incr}(\\{line})$;\6
  1762  \&{if} $\R\\{input\_ln}(\\{web\_file})$ \1\&{then}\6
  1763  \&{begin} \37$\\{err\_print}(\.{\'!\ WEB\ file\ ended\ during\ a\ change\'})$;\5
  1764  $\\{input\_has\_ended}\K\\{true}$;\5
  1765  \&{return};\6
  1766  \&{end};\2\6
  1767  \&{if} $\\{lines\_dont\_match}$ \1\&{then}\5
  1768  $\\{incr}(\|n)$;\2\6
  1769  \&{end};\2\6
  1770  \4\\{exit}: \37\&{end};\par
  1771  \fi
  1772  
  1773  \M80. \P$\X80:If the current line starts with \.{@y}, report any discrepancies
  1774  and \&{return}\X\S$\6
  1775  \&{if} $\\{limit}>1$ \1\&{then}\6
  1776  \&{if} $\\{buffer}[0]=\.{"@"}$ \1\&{then}\6
  1777  \&{begin} \37\&{if} $(\\{buffer}[1]\G\.{"X"})\W(\\{buffer}[1]\L\.{"Z"})$ \1%
  1778  \&{then}\5
  1779  $\\{buffer}[1]\K\\{buffer}[1]+\.{"z"}-\.{"Z"}$;\C{lowercasify}\2\6
  1780  \&{if} $(\\{buffer}[1]=\.{"x"})\V(\\{buffer}[1]=\.{"z"})$ \1\&{then}\6
  1781  \&{begin} \37$\\{loc}\K2$;\5
  1782  $\\{err\_print}(\.{\'!\ Where\ is\ the\ matching\ @y?\'})$;\6
  1783  \&{end}\6
  1784  \4\&{else} \&{if} $\\{buffer}[1]=\.{"y"}$ \1\&{then}\6
  1785  \&{begin} \37\&{if} $\|n>0$ \1\&{then}\6
  1786  \&{begin} \37$\\{loc}\K2$;\5
  1787  $\\{err\_print}(\.{\'!\ Hmm...\ \'},\39\|n:1,\39\.{\'\ of\ the\ preceding\
  1788  lines\ failed\ to\ match\'})$;\6
  1789  \&{end};\2\6
  1790  \&{return};\6
  1791  \&{end};\2\2\6
  1792  \&{end}\2\2\par
  1793  \U79.\fi
  1794  
  1795  \M81. The \\{reset\_input} procedure, which gets \.{WEAVE} ready to read the
  1796  user's \.{WEB} input, is used at the beginning of phases one and two.
  1797  
  1798  \Y\P\4\&{procedure}\1\  \37\\{reset\_input};\2\6
  1799  \&{begin} \37\\{open\_input};\5
  1800  $\\{line}\K0$;\5
  1801  $\\{other\_line}\K0$;\6
  1802  $\\{changing}\K\\{true}$;\5
  1803  \\{prime\_the\_change\_buffer};\5
  1804  \\{change\_changing};\6
  1805  $\\{limit}\K0$;\5
  1806  $\\{loc}\K1$;\5
  1807  $\\{buffer}[0]\K\.{"\ "}$;\5
  1808  $\\{input\_has\_ended}\K\\{false}$;\6
  1809  \&{end};\par
  1810  \fi
  1811  
  1812  \M82. The \\{get\_line} procedure is called when $\\{loc}>\\{limit}$; it puts
  1813  the next
  1814  line of merged input into the buffer and updates the other variables
  1815  appropriately. A space is placed at the right end of the line.
  1816  
  1817  \Y\P\4\&{procedure}\1\  \37\\{get\_line};\C{inputs the next line}\6
  1818  \4\&{label} \37\\{restart};\2\6
  1819  \&{begin} \37\\{restart}: \37\&{if} $\\{changing}$ \1\&{then}\5
  1820  \X84:Read from \\{change\_file} and maybe turn off \\{changing}\X;\2\6
  1821  \&{if} $\R\\{changing}$ \1\&{then}\6
  1822  \&{begin} \37\X83:Read from \\{web\_file} and maybe turn on \\{changing}\X;\6
  1823  \&{if} $\\{changing}$ \1\&{then}\5
  1824  \&{goto} \37\\{restart};\2\6
  1825  \&{end};\2\6
  1826  $\\{loc}\K0$;\5
  1827  $\\{buffer}[\\{limit}]\K\.{"\ "}$;\6
  1828  \&{end};\par
  1829  \fi
  1830  
  1831  \M83. \P$\X83:Read from \\{web\_file} and maybe turn on \\{changing}\X\S$\6
  1832  \&{begin} \37$\\{incr}(\\{line})$;\6
  1833  \&{if} $\R\\{input\_ln}(\\{web\_file})$ \1\&{then}\5
  1834  $\\{input\_has\_ended}\K\\{true}$\6
  1835  \4\&{else} \&{if} $\\{change\_limit}>0$ \1\&{then}\5
  1836  \\{check\_change};\2\2\6
  1837  \&{end}\par
  1838  \U82.\fi
  1839  
  1840  \M84. \P$\X84:Read from \\{change\_file} and maybe turn off \\{changing}\X\S$\6
  1841  \&{begin} \37$\\{incr}(\\{line})$;\6
  1842  \&{if} $\R\\{input\_ln}(\\{change\_file})$ \1\&{then}\6
  1843  \&{begin} \37$\\{err\_print}(\.{\'!\ Change\ file\ ended\ without\ @z\'})$;\5
  1844  $\\{buffer}[0]\K\.{"@"}$;\5
  1845  $\\{buffer}[1]\K\.{"z"}$;\5
  1846  $\\{limit}\K2$;\6
  1847  \&{end};\2\6
  1848  \&{if} $\\{limit}>0$ \1\&{then}\C{check if the change has ended}\6
  1849  \&{begin} \37\&{if} $\\{change\_pending}$ \1\&{then}\6
  1850  \&{begin} \37$\\{if\_module\_start\_then\_make\_change\_pending}(\\{false})$;\6
  1851  \&{if} $\\{change\_pending}$ \1\&{then}\6
  1852  \&{begin} \37$\\{changed\_module}[\\{module\_count}]\K\\{true}$;\5
  1853  $\\{change\_pending}\K\\{false}$;\6
  1854  \&{end};\2\6
  1855  \&{end};\2\6
  1856  $\\{buffer}[\\{limit}]\K\.{"\ "}$;\6
  1857  \&{if} $\\{buffer}[0]=\.{"@"}$ \1\&{then}\6
  1858  \&{begin} \37\&{if} $(\\{buffer}[1]\G\.{"X"})\W(\\{buffer}[1]\L\.{"Z"})$ \1%
  1859  \&{then}\5
  1860  $\\{buffer}[1]\K\\{buffer}[1]+\.{"z"}-\.{"Z"}$;\C{lowercasify}\2\6
  1861  \&{if} $(\\{buffer}[1]=\.{"x"})\V(\\{buffer}[1]=\.{"y"})$ \1\&{then}\6
  1862  \&{begin} \37$\\{loc}\K2$;\5
  1863  $\\{err\_print}(\.{\'!\ Where\ is\ the\ matching\ @z?\'})$;\6
  1864  \&{end}\6
  1865  \4\&{else} \&{if} $\\{buffer}[1]=\.{"z"}$ \1\&{then}\6
  1866  \&{begin} \37\\{prime\_the\_change\_buffer};\5
  1867  \\{change\_changing};\6
  1868  \&{end};\2\2\6
  1869  \&{end};\2\6
  1870  \&{end};\2\6
  1871  \&{end}\par
  1872  \U82.\fi
  1873  
  1874  \M85. At the end of the program, we will tell the user if the change file
  1875  had a line that didn't match any relevant line in \\{web\_file}.
  1876  
  1877  \Y\P$\4\X85:Check that all changes have been read\X\S$\6
  1878  \&{if} $\\{change\_limit}\I0$ \1\&{then}\C{\\{changing} is false}\6
  1879  \&{begin} \37\&{for} $\\{ii}\K0\mathrel{\&{to}}\\{change\_limit}-1$ \1\&{do}\5
  1880  $\\{buffer}[\\{ii}]\K\\{change\_buffer}[\\{ii}]$;\2\6
  1881  $\\{limit}\K\\{change\_limit}$;\5
  1882  $\\{changing}\K\\{true}$;\5
  1883  $\\{line}\K\\{other\_line}$;\5
  1884  $\\{loc}\K\\{change\_limit}$;\5
  1885  $\\{err\_print}(\.{\'!\ Change\ file\ entry\ did\ not\ match\'})$;\6
  1886  \&{end}\2\par
  1887  \U261\*.\fi
  1888  
  1889  \M86. Control codes in \.{WEB}, which begin with `\.{@}', are converted
  1890  into a numeric code designed to simplify \.{WEAVE}'s logic; for example,
  1891  larger numbers are given to the control codes that denote more significant
  1892  milestones, and the code of \\{new\_module} should be the largest of
  1893  all. Some of these numeric control codes take the place of ASCII
  1894  control codes that will not otherwise appear in the output of the
  1895  scanning routines.
  1896  
  1897  \Y\P\D \37$\\{ignore}=0$\C{control code of no interest to \.{WEAVE}}\par
  1898  \P\D \37$\\{verbatim}=\O{2}$\C{extended ASCII alpha will not appear}\par
  1899  \P\D \37$\\{force\_line}=\O{3}$\C{extended ASCII beta will not appear}\par
  1900  \P\D \37$\\{begin\_comment}=\O{11}$\C{ASCII tab mark will not appear}\par
  1901  \P\D \37$\\{end\_comment}=\O{12}$\C{ASCII line feed will not appear}\par
  1902  \P\D \37$\\{octal}=\O{14}$\C{ASCII form feed will not appear}\par
  1903  \P\D \37$\\{hex}=\O{15}$\C{ASCII carriage return will not appear}\par
  1904  \P\D \37$\\{double\_dot}=\O{40}$\C{ASCII space will not appear except in
  1905  strings}\par
  1906  \P\D \37$\\{no\_underline}=\O{175}$\C{this code will be intercepted without
  1907  confusion}\par
  1908  \P\D \37$\\{underline}=\O{176}$\C{this code will be intercepted without
  1909  confusion}\par
  1910  \P\D \37$\\{param}=\O{177}$\C{ASCII delete will not appear}\par
  1911  \P\D \37$\\{xref\_roman}=\O{203}$\C{control code for `\.{@\^}'}\par
  1912  \P\D \37$\\{xref\_wildcard}=\O{204}$\C{control code for `\.{@:}'}\par
  1913  \P\D \37$\\{xref\_typewriter}=\O{205}$\C{control code for `\.{@.}'}\par
  1914  \P\D \37$\\{TeX\_string}=\O{206}$\C{control code for `\.{@t}'}\par
  1915  \P\D \37$\\{check\_sum}=\O{207}$\C{control code for `\.{@\$}'}\par
  1916  \P\D \37$\\{join}=\O{210}$\C{control code for `\.{@\&}'}\par
  1917  \P\D \37$\\{thin\_space}=\O{211}$\C{control code for `\.{@,}'}\par
  1918  \P\D \37$\\{math\_break}=\O{212}$\C{control code for `\.{@\char'174}'}\par
  1919  \P\D \37$\\{line\_break}=\O{213}$\C{control code for `\.{@/}'}\par
  1920  \P\D \37$\\{big\_line\_break}=\O{214}$\C{control code for `\.{@\#}'}\par
  1921  \P\D \37$\\{no\_line\_break}=\O{215}$\C{control code for `\.{@+}'}\par
  1922  \P\D \37$\\{pseudo\_semi}=\O{216}$\C{control code for `\.{@;}'}\par
  1923  \P\D \37$\\{format}=\O{217}$\C{control code for `\.{@f}'}\par
  1924  \P\D \37$\\{definition}=\O{220}$\C{control code for `\.{@d}'}\par
  1925  \P\D \37$\\{begin\_Pascal}=\O{221}$\C{control code for `\.{@p}'}\par
  1926  \P\D \37$\\{module\_name}=\O{222}$\C{control code for `\.{@<}'}\par
  1927  \P\D \37$\\{new\_module}=\O{223}$\C{control code for `\.{@\ }' and `\.{@*}'}\par
  1928  \fi
  1929  
  1930  \M87. Control codes are converted from ASCII to \.{WEAVE}'s internal
  1931  representation by the \\{control\_code} routine.
  1932  
  1933  \Y\P\4\&{function}\1\  \37$\\{control\_code}(\|c:\\{ASCII\_code})$: \37\\{eight%
  1934  \_bits};\C{convert \|c   after \.{@}}\2\6
  1935  \&{begin} \37\&{case} $\|c$ \1\&{of}\6
  1936  \4\.{"@"}: \37$\\{control\_code}\K\.{"@"}$;\C{`quoted' at sign}\6
  1937  \4\.{"\'"}: \37$\\{control\_code}\K\\{octal}$;\C{precedes octal constant}\6
  1938  \4\.{""}\.{""}: \37$\\{control\_code}\K\\{hex}$;\C{precedes hexadecimal
  1939  constant}\6
  1940  \4\.{"\$"}: \37$\\{control\_code}\K\\{check\_sum}$;\C{precedes check sum
  1941  constant}\6
  1942  \4$\.{"\ "},\39\\{tab\_mark},\39\.{"*"}$: \37$\\{control\_code}\K\\{new%
  1943  \_module}$;\C{beginning of a new module}\6
  1944  \4\.{"="}: \37$\\{control\_code}\K\\{verbatim}$;\6
  1945  \4\.{"\\"}: \37$\\{control\_code}\K\\{force\_line}$;\6
  1946  \4$\.{"D"},\39\.{"d"}$: \37$\\{control\_code}\K\\{definition}$;\C{macro
  1947  definition}\6
  1948  \4$\.{"F"},\39\.{"f"}$: \37$\\{control\_code}\K\\{format}$;\C{format
  1949  definition}\6
  1950  \4\.{"\{"}: \37$\\{control\_code}\K\\{begin\_comment}$;\C{begin-comment
  1951  delimiter}\6
  1952  \4\.{"\}"}: \37$\\{control\_code}\K\\{end\_comment}$;\C{end-comment delimiter}\6
  1953  \4$\.{"P"},\39\.{"p"}$: \37$\\{control\_code}\K\\{begin\_Pascal}$;\C{\PASCAL\
  1954  text in unnamed module}\6
  1955  \4\.{"\&"}: \37$\\{control\_code}\K\\{join}$;\C{concatenate two tokens}\6
  1956  \4\.{"<"}: \37$\\{control\_code}\K\\{module\_name}$;\C{beginning of a module
  1957  name}\6
  1958  \4\.{">"}: \37\&{begin} \37$\\{err\_print}(\.{\'!\ Extra\ @>\'})$;\5
  1959  $\\{control\_code}\K\\{ignore}$;\6
  1960  \&{end};\C{end of module name should not be discovered in this way}\6
  1961  \4$\.{"T"},\39\.{"t"}$: \37$\\{control\_code}\K\\{TeX\_string}$;\C{\TeX\ box
  1962  within \PASCAL}\6
  1963  \4\.{"!"}: \37$\\{control\_code}\K\\{underline}$;\C{set definition flag}\6
  1964  \4\.{"?"}: \37$\\{control\_code}\K\\{no\_underline}$;\C{reset definition flag}\6
  1965  \4\.{"\^"}: \37$\\{control\_code}\K\\{xref\_roman}$;\C{index entry to be
  1966  typeset normally}\6
  1967  \4\.{":"}: \37$\\{control\_code}\K\\{xref\_wildcard}$;\C{index entry to be in
  1968  user format}\6
  1969  \4\.{"."}: \37$\\{control\_code}\K\\{xref\_typewriter}$;\C{index entry to be in
  1970  typewriter type}\6
  1971  \4\.{","}: \37$\\{control\_code}\K\\{thin\_space}$;\C{puts extra space in %
  1972  \PASCAL\ format}\6
  1973  \4\.{"|"}: \37$\\{control\_code}\K\\{math\_break}$;\C{allows a break in a
  1974  formula}\6
  1975  \4\.{"/"}: \37$\\{control\_code}\K\\{line\_break}$;\C{forces end-of-line in %
  1976  \PASCAL\ format}\6
  1977  \4\.{"\#"}: \37$\\{control\_code}\K\\{big\_line\_break}$;\C{forces end-of-line
  1978  and some space besides}\6
  1979  \4\.{"+"}: \37$\\{control\_code}\K\\{no\_line\_break}$;\C{cancels end-of-line
  1980  down to single space}\6
  1981  \4\.{";"}: \37$\\{control\_code}\K\\{pseudo\_semi}$;\C{acts like a semicolon,
  1982  but is invisible}\6
  1983  \hbox{\4}\X88:Special control codes allowed only when debugging\X\6
  1984  \4\&{othercases} \37\&{begin} \37$\\{err\_print}(\.{\'!\ Unknown\ control\ code%
  1985  \'})$;\5
  1986  $\\{control\_code}\K\\{ignore}$;\6
  1987  \&{end}\2\6
  1988  \&{endcases};\6
  1989  \&{end};\par
  1990  \fi
  1991  
  1992  \M88. If \.{WEAVE} is compiled with debugging commands, one can write
  1993  \.{@2}, \.{@1}, and \.{@0} to turn tracing fully on, partly on,
  1994  and off, respectively.
  1995  
  1996  \Y\P$\4\X88:Special control codes allowed only when debugging\X\S$\6
  1997  \&{debug} \37\hbox{}\6
  1998  \4$\.{"0"},\39\.{"1"},\39\.{"2"}$: \37\&{begin} \37$\\{tracing}\K\|c-\.{"0"}$;\5
  1999  $\\{control\_code}\K\\{ignore}$;\6
  2000  \&{end};\6
  2001  \&{gubed}\par
  2002  \U87.\fi
  2003  
  2004  \M89. The \\{skip\_limbo} routine is used on the first pass to skip through
  2005  portions of the input that are not in any modules, i.e., that precede
  2006  the first module. After this procedure has been called, the value of
  2007  \\{input\_has\_ended} will tell whether or not a new module has
  2008  actually been found.
  2009  
  2010  \Y\P\4\&{procedure}\1\  \37\\{skip\_limbo};\C{skip to next module}\6
  2011  \4\&{label} \37\\{exit};\6
  2012  \4\&{var} \37\|c: \37\\{ASCII\_code};\C{character following \.{@}}\2\6
  2013  \&{begin} \37\~ \1\&{loop}\6
  2014  \&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
  2015  \&{begin} \37\\{get\_line};\6
  2016  \&{if} $\\{input\_has\_ended}$ \1\&{then}\5
  2017  \&{return};\2\6
  2018  \&{end}\6
  2019  \4\&{else} \&{begin} \37$\\{buffer}[\\{limit}+1]\K\.{"@"}$;\6
  2020  \&{while} $\\{buffer}[\\{loc}]\I\.{"@"}$ \1\&{do}\5
  2021  $\\{incr}(\\{loc})$;\2\6
  2022  \&{if} $\\{loc}\L\\{limit}$ \1\&{then}\6
  2023  \&{begin} \37$\\{loc}\K\\{loc}+2$;\5
  2024  $\|c\K\\{buffer}[\\{loc}-1]$;\6
  2025  \&{if} $(\|c=\.{"\ "})\V(\|c=\\{tab\_mark})\V(\|c=\.{"*"})$ \1\&{then}\5
  2026  \&{return};\2\6
  2027  \&{end};\2\6
  2028  \&{end};\2\2\6
  2029  \4\\{exit}: \37\&{end};\par
  2030  \fi
  2031  
  2032  \M90. The \\{skip\_TeX} routine is used on the first pass to skip through
  2033  the \TeX\ code at the beginning of a module. It returns the next
  2034  control code or `\v' found in the input. A \\{new\_module} is
  2035  assumed to exist at the very end of the file.
  2036  
  2037  \Y\P\4\&{function}\1\  \37\\{skip\_TeX}: \37\\{eight\_bits};\C{skip past pure %
  2038  \TeX\ code}\6
  2039  \4\&{label} \37\\{done};\6
  2040  \4\&{var} \37\|c: \37\\{eight\_bits};\C{control code found}\2\6
  2041  \&{begin} \37\~ \1\&{loop}\6
  2042  \&{begin} \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
  2043  \&{begin} \37\\{get\_line};\6
  2044  \&{if} $\\{input\_has\_ended}$ \1\&{then}\6
  2045  \&{begin} \37$\|c\K\\{new\_module}$;\5
  2046  \&{goto} \37\\{done};\6
  2047  \&{end};\2\6
  2048  \&{end};\2\6
  2049  $\\{buffer}[\\{limit}+1]\K\.{"@"}$;\6
  2050  \1\&{repeat} \37$\|c\K\\{buffer}[\\{loc}]$;\5
  2051  $\\{incr}(\\{loc})$;\6
  2052  \&{if} $\|c=\.{"|"}$ \1\&{then}\5
  2053  \&{goto} \37\\{done};\2\6
  2054  \4\&{until}\5
  2055  $\|c=\.{"@"}$;\2\6
  2056  \&{if} $\\{loc}\L\\{limit}$ \1\&{then}\6
  2057  \&{begin} \37$\|c\K\\{control\_code}(\\{buffer}[\\{loc}])$;\5
  2058  $\\{incr}(\\{loc})$;\5
  2059  \&{goto} \37\\{done};\6
  2060  \&{end};\2\6
  2061  \&{end};\2\6
  2062  \4\\{done}: \37$\\{skip\_TeX}\K\|c$;\6
  2063  \&{end};\par
  2064  \fi
  2065  
  2066  \M91. The \\{skip\_comment} routine is used on the first pass to skip
  2067  through \TeX\ code in \PASCAL\ comments. The \\{bal} parameter
  2068  tells how many left braces are assumed to have been scanned when
  2069  this routine is called, and the procedure returns a corresponding
  2070  value of \\{bal} at the point that scanning has stopped. Scanning
  2071  stops either at a `\v' that introduces \PASCAL\ text,
  2072  in which case the returned value is positive, or it stops at the
  2073  end of the comment, in which case the returned value is zero.
  2074  The scanning also stops in anomalous situations when the comment
  2075  doesn't end or when it contains an illegal use of \.{@}.
  2076  One should call $\\{skip\_comment}(1)$ when beginning to scan a comment.
  2077  
  2078  \Y\P\4\&{function}\1\  \37$\\{skip\_comment}(\\{bal}:\\{eight\_bits})$: \37%
  2079  \\{eight\_bits};\C{skips \TeX\   code in comments}\6
  2080  \4\&{label} \37\\{done};\6
  2081  \4\&{var} \37\|c: \37\\{ASCII\_code};\C{the current character}\2\6
  2082  \&{begin} \37\~ \1\&{loop}\6
  2083  \&{begin} \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
  2084  \&{begin} \37\\{get\_line};\6
  2085  \&{if} $\\{input\_has\_ended}$ \1\&{then}\6
  2086  \&{begin} \37$\\{bal}\K0$;\5
  2087  \&{goto} \37\\{done};\6
  2088  \&{end};\C{an error message will occur in phase two}\2\6
  2089  \&{end};\2\6
  2090  $\|c\K\\{buffer}[\\{loc}]$;\5
  2091  $\\{incr}(\\{loc})$;\6
  2092  \&{if} $\|c=\.{"|"}$ \1\&{then}\5
  2093  \&{goto} \37\\{done};\2\6
  2094  \X92:Do special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"\}"}$; \&{goto} %
  2095  \\{done} at end\X;\6
  2096  \&{end};\2\6
  2097  \4\\{done}: \37$\\{skip\_comment}\K\\{bal}$;\6
  2098  \&{end};\par
  2099  \fi
  2100  
  2101  \M92. \P$\X92:Do special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"\}"}$; %
  2102  \&{goto} \\{done} at end\X\S$\6
  2103  \&{if} $\|c=\.{"@"}$ \1\&{then}\6
  2104  \&{begin} \37$\|c\K\\{buffer}[\\{loc}]$;\6
  2105  \&{if} $(\|c\I\.{"\ "})\W(\|c\I\\{tab\_mark})\W(\|c\I\.{"*"})$ \1\&{then}\5
  2106  $\\{incr}(\\{loc})$\6
  2107  \4\&{else} \&{begin} \37$\\{decr}(\\{loc})$;\5
  2108  $\\{bal}\K0$;\5
  2109  \&{goto} \37\\{done};\6
  2110  \&{end}\C{an error message will occur in phase two}\2\6
  2111  \&{end}\6
  2112  \4\&{else} \&{if} $(\|c=\.{"\\"})\W(\\{buffer}[\\{loc}]\I\.{"@"})$ \1\&{then}\5
  2113  $\\{incr}(\\{loc})$\6
  2114  \4\&{else} \&{if} $\|c=\.{"\{"}$ \1\&{then}\5
  2115  $\\{incr}(\\{bal})$\6
  2116  \4\&{else} \&{if} $\|c=\.{"\}"}$ \1\&{then}\6
  2117  \&{begin} \37$\\{decr}(\\{bal})$;\6
  2118  \&{if} $\\{bal}=0$ \1\&{then}\5
  2119  \&{goto} \37\\{done};\2\6
  2120  \&{end}\2\2\2\2\par
  2121  \U91.\fi
  2122  
  2123  \N93.  Inputting the next token.
  2124  As stated above, \.{WEAVE}'s most interesting lexical scanning routine is the
  2125  \\{get\_next} function that inputs the next token of \PASCAL\ input. However,
  2126  \\{get\_next} is not especially complicated.
  2127  
  2128  The result of \\{get\_next} is either an ASCII code for some special character,
  2129  or it is a special code representing a pair of characters (e.g., `\.{:=}'
  2130  or `\.{..}'), or it is the numeric value computed by the \\{control\_code}
  2131  procedure, or it is one of the following special codes:
  2132  
  2133  \yskip\hang \\{exponent}: The `\.E' in a real constant.
  2134  
  2135  \yskip\hang \\{identifier}: In this case the global variables \\{id\_first}
  2136  and \\{id\_loc} will have been set to the appropriate values needed by the
  2137  \\{id\_lookup} routine.
  2138  
  2139  \yskip\hang \\{string}: In this case the global variables \\{id\_first} and
  2140  \\{id\_loc} will have been set to the beginning and ending-plus-one locations
  2141  in the buffer.  The string ends with the first reappearance of its initial
  2142  delimiter; thus, for example, $$\.{\'This isn\'\'t a single string\'}$$
  2143  will be treated as two consecutive strings, the first being \.{\'This
  2144  isn\'}.
  2145  
  2146  \yskip\noindent Furthermore, some of the control codes cause
  2147  \\{get\_next} to take additional actions:
  2148  
  2149  \yskip\hang \\{xref\_roman}, \\{xref\_wildcard},
  2150  \\{xref\_typewriter}, \\{TeX\_string}: The values of
  2151  \\{id\_first} and \\{id\_loc} will be set so that the string in question
  2152  appears
  2153  in $\\{buffer}[\\{id\_first}\to(\\{id\_loc}-1)]$.
  2154  
  2155  \yskip\hang \\{module\_name}: In this case the global variable \\{cur\_module}
  2156  will
  2157  point to the \\{byte\_start} entry for the module name that has just been
  2158  scanned.
  2159  
  2160  \yskip\noindent If \\{get\_next} sees `\.{@!}' or `\.{@?}',
  2161  it sets \\{xref\_switch} to \\{def\_flag} or zero and goes on to the next
  2162  token.
  2163  
  2164  A global variable called \\{scanning\_hex} is set \\{true} during the time that
  2165  the letters \.A through \.F should be treated as if they were digits.
  2166  
  2167  \Y\P\D \37$\\{exponent}=\O{200}$\C{\.E or \.e following a digit}\par
  2168  \P\D \37$\\{string}=\O{201}$\C{\PASCAL\ string or \.{WEB} precomputed string}%
  2169  \par
  2170  \P\D \37$\\{identifier}=\O{202}$\C{\PASCAL\ identifier or reserved word}\par
  2171  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  2172  \4\\{cur\_module}: \37\\{name\_pointer};\C{name of module just scanned}\6
  2173  \4\\{scanning\_hex}: \37\\{boolean};\C{are we scanning a hexadecimal constant?}%
  2174  \par
  2175  \fi
  2176  
  2177  \M94. \P$\X10:Set initial values\X\mathrel{+}\S$\6
  2178  $\\{scanning\_hex}\K\\{false}$;\par
  2179  \fi
  2180  
  2181  \M95. As one might expect, \\{get\_next} consists mostly of a big switch
  2182  that branches to the various special cases that can arise.
  2183  
  2184  \Y\P\D \37$\\{up\_to}(\#)\S\#-24,\39\#-23,\39\#-22,\39\#-21,\39\#-20,\39\#-19,%
  2185  \39\#-18,\39\#-17,\39\#-16,\39\#-15,\39\#-14,\39\#-13,\39\#-12,\39\#-11,\39%
  2186  \#-10,\39\#-9,\39\#-8,\39\#-7,\39\#-6,\39\#-5,\39\#-4,\39\#-3,\39\#-2,\39\#-1,%
  2187  \39\#$\par
  2188  \Y\P\4\&{function}\1\  \37\\{get\_next}: \37\\{eight\_bits};\C{produces the
  2189  next input token}\6
  2190  \4\&{label} \37$\\{restart},\39\\{done},\39\\{found}$;\6
  2191  \4\&{var} \37\|c: \37\\{eight\_bits};\C{the current character}\6
  2192  \|d: \37\\{eight\_bits};\C{the next character}\6
  2193  $\|j,\39\|k$: \37$0\to\\{longest\_name}$;\C{indices into \\{mod\_text}}\2\6
  2194  \&{begin} \37\\{restart}: \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
  2195  \&{begin} \37\\{get\_line};\6
  2196  \&{if} $\\{input\_has\_ended}$ \1\&{then}\6
  2197  \&{begin} \37$\|c\K\\{new\_module}$;\5
  2198  \&{goto} \37\\{found};\6
  2199  \&{end};\2\6
  2200  \&{end};\2\6
  2201  $\|c\K\\{buffer}[\\{loc}]$;\5
  2202  $\\{incr}(\\{loc})$;\6
  2203  \&{if} $\\{scanning\_hex}$ \1\&{then}\5
  2204  \X96:Go to \\{found} if \|c is a hexadecimal digit, otherwise set $\\{scanning%
  2205  \_hex}\K\\{false}$\X;\2\6
  2206  \&{case} $\|c$ \1\&{of}\6
  2207  \4$\.{"A"},\39\\{up\_to}(\.{"Z"}),\39\.{"a"},\39\\{up\_to}(\.{"z"})$: \37%
  2208  \X98:Get an identifier\X;\6
  2209  \4$\.{"\'"},\39\.{""}\.{""}$: \37\X99:Get a string\X;\6
  2210  \4\.{"@"}: \37\X100:Get control code and possible module name\X;\6
  2211  \hbox{\4}\X97:Compress two-symbol combinations like `\.{:=}'\X\6
  2212  \4$\.{"\ "},\39\\{tab\_mark}$: \37\&{goto} \37\\{restart};\C{ignore spaces and
  2213  tabs}\6
  2214  \4\.{"\}"}: \37\&{begin} \37$\\{err\_print}(\.{\'!\ Extra\ \}\'})$;\5
  2215  \&{goto} \37\\{restart};\6
  2216  \&{end};\6
  2217  \4\&{othercases} \37\&{if} $\|c\G128$ \1\&{then}\5
  2218  \&{goto} \37\\{restart}\C{ignore nonstandard characters}\6
  2219  \4\&{else} \\{do\_nothing}\2\2\6
  2220  \&{endcases};\6
  2221  \4\\{found}: \37\&{debug} \37\&{if} $\\{trouble\_shooting}$ \1\&{then}\5
  2222  \\{debug\_help};\2\ \&{gubed}\6
  2223  $\\{get\_next}\K\|c$;\6
  2224  \&{end};\par
  2225  \fi
  2226  
  2227  \M96. \P$\X96:Go to \\{found} if \|c is a hexadecimal digit, otherwise set $%
  2228  \\{scanning\_hex}\K\\{false}$\X\S$\6
  2229  \&{if} $((\|c\G\.{"0"})\W(\|c\L\.{"9"}))\V((\|c\G\.{"A"})\W(\|c\L\.{"F"}))$ \1%
  2230  \&{then}\5
  2231  \&{goto} \37\\{found}\6
  2232  \4\&{else} $\\{scanning\_hex}\K\\{false}$\2\par
  2233  \U95.\fi
  2234  
  2235  \M97. Note that the following code substitutes \.{@\{} and \.{@\}} for the
  2236  respective combinations `\.{(*}' and `\.{*)}'. Explicit braces should be used
  2237  for \TeX\ comments in \PASCAL\ text.
  2238  
  2239  \Y\P\D \37$\\{compress}(\#)\S$\1\6
  2240  \&{begin} \37\&{if} $\\{loc}\L\\{limit}$ \1\&{then}\6
  2241  \&{begin} \37$\|c\K\#$;\5
  2242  $\\{incr}(\\{loc})$;\6
  2243  \&{end};\2\6
  2244  \&{end}\2\par
  2245  \Y\P$\4\X97:Compress two-symbol combinations like `\.{:=}'\X\S$\6
  2246  \4\.{"."}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"."}$ \1\&{then}\5
  2247  $\\{compress}(\\{double\_dot})$\6
  2248  \4\&{else} \&{if} $\\{buffer}[\\{loc}]=\.{")"}$ \1\&{then}\5
  2249  $\\{compress}(\.{"]"})$;\2\2\6
  2250  \4\.{":"}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"="}$ \1\&{then}\5
  2251  $\\{compress}(\\{left\_arrow})$;\2\6
  2252  \4\.{"="}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"="}$ \1\&{then}\5
  2253  $\\{compress}(\\{equivalence\_sign})$;\2\6
  2254  \4\.{">"}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"="}$ \1\&{then}\5
  2255  $\\{compress}(\\{greater\_or\_equal})$;\2\6
  2256  \4\.{"<"}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"="}$ \1\&{then}\5
  2257  $\\{compress}(\\{less\_or\_equal})$\6
  2258  \4\&{else} \&{if} $\\{buffer}[\\{loc}]=\.{">"}$ \1\&{then}\5
  2259  $\\{compress}(\\{not\_equal})$;\2\2\6
  2260  \4\.{"("}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"*"}$ \1\&{then}\5
  2261  $\\{compress}(\\{begin\_comment})$\6
  2262  \4\&{else} \&{if} $\\{buffer}[\\{loc}]=\.{"."}$ \1\&{then}\5
  2263  $\\{compress}(\.{"["})$;\2\2\6
  2264  \4\.{"*"}: \37\&{if} $\\{buffer}[\\{loc}]=\.{")"}$ \1\&{then}\5
  2265  $\\{compress}(\\{end\_comment})$;\2\par
  2266  \U95.\fi
  2267  
  2268  \M98. \P$\X98:Get an identifier\X\S$\6
  2269  \&{begin} \37\&{if} $((\|c=\.{"E"})\V(\|c=\.{"e"}))\W(\\{loc}>1)$ \1\&{then}\6
  2270  \&{if} $(\\{buffer}[\\{loc}-2]\L\.{"9"})\W(\\{buffer}[\\{loc}-2]\G\.{"0"})$ \1%
  2271  \&{then}\5
  2272  $\|c\K\\{exponent}$;\2\2\6
  2273  \&{if} $\|c\I\\{exponent}$ \1\&{then}\6
  2274  \&{begin} \37$\\{decr}(\\{loc})$;\5
  2275  $\\{id\_first}\K\\{loc}$;\6
  2276  \1\&{repeat} \37$\\{incr}(\\{loc})$;\5
  2277  $\|d\K\\{buffer}[\\{loc}]$;\6
  2278  \4\&{until}\5
  2279  $((\|d<\.{"0"})\V((\|d>\.{"9"})\W(\|d<\.{"A"}))\V((\|d>\.{"Z"})\W(\|d<\.{"a"}))%
  2280  \V(\|d>\.{"z"}))\W(\|d\I\.{"\_"})$;\2\6
  2281  $\|c\K\\{identifier}$;\5
  2282  $\\{id\_loc}\K\\{loc}$;\6
  2283  \&{end};\2\6
  2284  \&{end}\par
  2285  \U95.\fi
  2286  
  2287  \M99. A string that starts and ends with single or double quote marks is
  2288  scanned by the following piece of the program.
  2289  
  2290  \Y\P$\4\X99:Get a string\X\S$\6
  2291  \&{begin} \37$\\{id\_first}\K\\{loc}-1$;\6
  2292  \1\&{repeat} \37$\|d\K\\{buffer}[\\{loc}]$;\5
  2293  $\\{incr}(\\{loc})$;\6
  2294  \&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
  2295  \&{begin} \37$\\{err\_print}(\.{\'!\ String\ constant\ didn\'}\.{\'t\ end\'})$;%
  2296  \5
  2297  $\\{loc}\K\\{limit}$;\5
  2298  $\|d\K\|c$;\6
  2299  \&{end};\2\6
  2300  \4\&{until}\5
  2301  $\|d=\|c$;\2\6
  2302  $\\{id\_loc}\K\\{loc}$;\5
  2303  $\|c\K\\{string}$;\6
  2304  \&{end}\par
  2305  \U95.\fi
  2306  
  2307  \M100. After an \.{@} sign has been scanned, the next character tells us
  2308  whether there is more work to do.
  2309  
  2310  \Y\P$\4\X100:Get control code and possible module name\X\S$\6
  2311  \&{begin} \37$\|c\K\\{control\_code}(\\{buffer}[\\{loc}])$;\5
  2312  $\\{incr}(\\{loc})$;\6
  2313  \&{if} $\|c=\\{underline}$ \1\&{then}\6
  2314  \&{begin} \37$\\{xref\_switch}\K\\{def\_flag}$;\5
  2315  \&{goto} \37\\{restart};\6
  2316  \&{end}\6
  2317  \4\&{else} \&{if} $\|c=\\{no\_underline}$ \1\&{then}\6
  2318  \&{begin} \37$\\{xref\_switch}\K0$;\5
  2319  \&{goto} \37\\{restart};\6
  2320  \&{end}\6
  2321  \4\&{else} \&{if} $(\|c\L\\{TeX\_string})\W(\|c\G\\{xref\_roman})$ \1\&{then}\5
  2322  \X106:Scan to the next \.{@>}\X\6
  2323  \4\&{else} \&{if} $\|c=\\{hex}$ \1\&{then}\5
  2324  $\\{scanning\_hex}\K\\{true}$\6
  2325  \4\&{else} \&{if} $\|c=\\{module\_name}$ \1\&{then}\5
  2326  \X101:Scan the module name and make \\{cur\_module} point to it\X\6
  2327  \4\&{else} \&{if} $\|c=\\{verbatim}$ \1\&{then}\5
  2328  \X107:Scan a verbatim string\X;\2\2\2\2\2\2\6
  2329  \&{end}\par
  2330  \U95.\fi
  2331  
  2332  \M101. The occurrence of a module name sets \\{xref\_switch} to zero,
  2333  because the module name might (for example) follow \&{var}.
  2334  
  2335  \Y\P$\4\X101:Scan the module name and make \\{cur\_module} point to it\X\S$\6
  2336  \&{begin} \37\X103:Put module name into $\\{mod\_text}[1\to\|k]$\X;\6
  2337  \&{if} $\|k>3$ \1\&{then}\6
  2338  \&{begin} \37\&{if} $(\\{mod\_text}[\|k]=\.{"."})\W(\\{mod\_text}[\|k-1]=%
  2339  \.{"."})\W(\\{mod\_text}[\|k-2]=\.{"."})$ \1\&{then}\5
  2340  $\\{cur\_module}\K\\{prefix\_lookup}(\|k-3)$\6
  2341  \4\&{else} $\\{cur\_module}\K\\{mod\_lookup}(\|k)$;\2\6
  2342  \&{end}\6
  2343  \4\&{else} $\\{cur\_module}\K\\{mod\_lookup}(\|k)$;\2\6
  2344  $\\{xref\_switch}\K0$;\6
  2345  \&{end}\par
  2346  \U100.\fi
  2347  
  2348  \M102. Module names are placed into the \\{mod\_text} array with consecutive
  2349  spaces,
  2350  tabs, and carriage-returns replaced by single spaces. There will be no
  2351  spaces at the beginning or the end. (We set $\\{mod\_text}[0]\K\.{"\ "}$ to
  2352  facilitate
  2353  this, since the \\{mod\_lookup} routine uses $\\{mod\_text}[1]$ as the first
  2354  character of the name.)
  2355  
  2356  \Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
  2357  $\\{mod\_text}[0]\K\.{"\ "}$;\par
  2358  \fi
  2359  
  2360  \M103. \P$\X103:Put module name into $\\{mod\_text}[1\to\|k]$\X\S$\6
  2361  $\|k\K0$;\6
  2362  \~ \1\&{loop}\ \&{begin} \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
  2363  \&{begin} \37\\{get\_line};\6
  2364  \&{if} $\\{input\_has\_ended}$ \1\&{then}\6
  2365  \&{begin} \37$\\{err\_print}(\.{\'!\ Input\ ended\ in\ section\ name\'})$;\5
  2366  $\\{loc}\K1$;\5
  2367  \&{goto} \37\\{done};\6
  2368  \&{end};\2\6
  2369  \&{end};\2\6
  2370  $\|d\K\\{buffer}[\\{loc}]$;\5
  2371  \X104:If end of name, \&{goto} \\{done}\X;\6
  2372  $\\{incr}(\\{loc})$;\6
  2373  \&{if} $\|k<\\{longest\_name}-1$ \1\&{then}\5
  2374  $\\{incr}(\|k)$;\2\6
  2375  \&{if} $(\|d=\.{"\ "})\V(\|d=\\{tab\_mark})$ \1\&{then}\6
  2376  \&{begin} \37$\|d\K\.{"\ "}$;\6
  2377  \&{if} $\\{mod\_text}[\|k-1]=\.{"\ "}$ \1\&{then}\5
  2378  $\\{decr}(\|k)$;\2\6
  2379  \&{end};\2\6
  2380  $\\{mod\_text}[\|k]\K\|d$;\6
  2381  \&{end};\2\6
  2382  \4\\{done}: \37\X105:Check for overlong name\X;\6
  2383  \&{if} $(\\{mod\_text}[\|k]=\.{"\ "})\W(\|k>0)$ \1\&{then}\5
  2384  $\\{decr}(\|k)$\2\par
  2385  \U101.\fi
  2386  
  2387  \M104. \P$\X104:If end of name, \&{goto} \\{done}\X\S$\6
  2388  \&{if} $\|d=\.{"@"}$ \1\&{then}\6
  2389  \&{begin} \37$\|d\K\\{buffer}[\\{loc}+1]$;\6
  2390  \&{if} $\|d=\.{">"}$ \1\&{then}\6
  2391  \&{begin} \37$\\{loc}\K\\{loc}+2$;\5
  2392  \&{goto} \37\\{done};\6
  2393  \&{end};\2\6
  2394  \&{if} $(\|d=\.{"\ "})\V(\|d=\\{tab\_mark})\V(\|d=\.{"*"})$ \1\&{then}\6
  2395  \&{begin} \37$\\{err\_print}(\.{\'!\ Section\ name\ didn\'}\.{\'t\ end\'})$;\5
  2396  \&{goto} \37\\{done};\6
  2397  \&{end};\2\6
  2398  $\\{incr}(\|k)$;\5
  2399  $\\{mod\_text}[\|k]\K\.{"@"}$;\5
  2400  $\\{incr}(\\{loc})$;\C{now $\|d=\\{buffer}[\\{loc}]$ again}\6
  2401  \&{end}\2\par
  2402  \U103.\fi
  2403  
  2404  \M105. \P$\X105:Check for overlong name\X\S$\6
  2405  \&{if} $\|k\G\\{longest\_name}-2$ \1\&{then}\6
  2406  \&{begin} \37$\\{print\_nl}(\.{\'!\ Section\ name\ too\ long:\ \'})$;\6
  2407  \&{for} $\|j\K1\mathrel{\&{to}}25$ \1\&{do}\5
  2408  $\\{print}(\\{xchr}[\\{mod\_text}[\|j]])$;\2\6
  2409  $\\{print}(\.{\'...\'})$;\5
  2410  \\{mark\_harmless};\6
  2411  \&{end}\2\par
  2412  \U103.\fi
  2413  
  2414  \M106. \P$\X106:Scan to the next \.{@>}\X\S$\6
  2415  \&{begin} \37$\\{id\_first}\K\\{loc}$;\5
  2416  $\\{buffer}[\\{limit}+1]\K\.{"@"}$;\6
  2417  \&{while} $\\{buffer}[\\{loc}]\I\.{"@"}$ \1\&{do}\5
  2418  $\\{incr}(\\{loc})$;\2\6
  2419  $\\{id\_loc}\K\\{loc}$;\6
  2420  \&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
  2421  \&{begin} \37$\\{err\_print}(\.{\'!\ Control\ text\ didn\'}\.{\'t\ end\'})$;\5
  2422  $\\{loc}\K\\{limit}$;\6
  2423  \&{end}\6
  2424  \4\&{else} \&{begin} \37$\\{loc}\K\\{loc}+2$;\6
  2425  \&{if} $\\{buffer}[\\{loc}-1]\I\.{">"}$ \1\&{then}\5
  2426  $\\{err\_print}(\.{\'!\ Control\ codes\ are\ forbidden\ in\ control\ text\'})$;%
  2427  \2\6
  2428  \&{end};\2\6
  2429  \&{end}\par
  2430  \U100.\fi
  2431  
  2432  \M107. A verbatim \PASCAL\ string will be treated like ordinary strings, but
  2433  with no surrounding delimiters.  At the present point in the program we
  2434  have $\\{buffer}[\\{loc}-1]=\\{verbatim}$; we must set \\{id\_first} to the
  2435  beginning
  2436  of the string itself, and \\{id\_loc} to its ending-plus-one location in the
  2437  buffer.  We also set \\{loc} to the position just after the ending delimiter.
  2438  
  2439  \Y\P$\4\X107:Scan a verbatim string\X\S$\6
  2440  \&{begin} \37$\\{id\_first}\K\\{loc}$;\5
  2441  $\\{incr}(\\{loc})$;\5
  2442  $\\{buffer}[\\{limit}+1]\K\.{"@"}$;\5
  2443  $\\{buffer}[\\{limit}+2]\K\.{">"}$;\6
  2444  \&{while} $(\\{buffer}[\\{loc}]\I\.{"@"})\V(\\{buffer}[\\{loc}+1]\I\.{">"})$ \1%
  2445  \&{do}\5
  2446  $\\{incr}(\\{loc})$;\2\6
  2447  \&{if} $\\{loc}\G\\{limit}$ \1\&{then}\5
  2448  $\\{err\_print}(\.{\'!\ Verbatim\ string\ didn\'}\.{\'t\ end\'})$;\2\6
  2449  $\\{id\_loc}\K\\{loc}$;\5
  2450  $\\{loc}\K\\{loc}+2$;\6
  2451  \&{end}\par
  2452  \U100.\fi
  2453  
  2454  \N108.  Phase one processing.
  2455  We now have accumulated enough subroutines to make it possible to carry out
  2456  \.{WEAVE}'s first pass over the source file. If everything works right,
  2457  both phase one and phase two of \.{WEAVE} will assign the same numbers to
  2458  modules, and these numbers will agree with what \.{TANGLE} does.
  2459  
  2460  The global variable \\{next\_control} often contains the most recent output of
  2461  \\{get\_next}; in interesting cases, this will be the control code that
  2462  ended a module or part of a module.
  2463  
  2464  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  2465  \4\\{next\_control}: \37\\{eight\_bits};\C{control code waiting to be acting
  2466  upon}\par
  2467  \fi
  2468  
  2469  \M109. The overall processing strategy in phase one has the following
  2470  straightforward outline.
  2471  
  2472  \Y\P$\4\X109:Phase I: Read all the user's text and store the cross references\X%
  2473  \S$\6
  2474  $\\{phase\_one}\K\\{true}$;\5
  2475  $\\{phase\_three}\K\\{false}$;\5
  2476  \\{reset\_input};\5
  2477  $\\{module\_count}\K0$;\5
  2478  $\\{changed\_module}[0]\K\\{false}$;\5
  2479  \\{skip\_limbo};\5
  2480  $\\{change\_exists}\K\\{false}$;\6
  2481  \&{while} $\R\\{input\_has\_ended}$ \1\&{do}\5
  2482  \X110:Store cross reference data for the current module\X;\2\6
  2483  $\\{changed\_module}[\\{module\_count}]\K\\{change\_exists}$;\C{the index
  2484  changes if anything does}\6
  2485  $\\{phase\_one}\K\\{false}$;\C{prepare for second phase}\6
  2486  \X120:Print error messages about unused or undefined module names\X;\par
  2487  \U261\*.\fi
  2488  
  2489  \M110. \P$\X110:Store cross reference data for the current module\X\S$\6
  2490  \&{begin} \37$\\{incr}(\\{module\_count})$;\6
  2491  \&{if} $\\{module\_count}=\\{max\_modules}$ \1\&{then}\5
  2492  $\\{overflow}(\.{\'section\ number\'})$;\2\6
  2493  $\\{changed\_module}[\\{module\_count}]\K\\{changing}$;\C{it will become %
  2494  \\{true} if any line changes}\6
  2495  \&{if} $\\{buffer}[\\{loc}-1]=\.{"*"}$ \1\&{then}\6
  2496  \&{begin} \37$\\{print}(\.{\'*\'},\39\\{module\_count}:1)$;\5
  2497  \\{update\_terminal};\C{print a progress report}\6
  2498  \&{end};\2\6
  2499  \X113:Store cross references in the \TeX\ part of a module\X;\6
  2500  \X115:Store cross references in the \(definition part of a module\X;\6
  2501  \X117:Store cross references in the \PASCAL\ part of a module\X;\6
  2502  \&{if} $\\{changed\_module}[\\{module\_count}]$ \1\&{then}\5
  2503  $\\{change\_exists}\K\\{true}$;\2\6
  2504  \&{end}\par
  2505  \U109.\fi
  2506  
  2507  \M111. The \\{Pascal\_xref} subroutine stores references to identifiers in
  2508  \PASCAL\ text material beginning with the current value of \\{next\_control}
  2509  and continuing until \\{next\_control} is `\.\{' or `\v', or until the next
  2510  ``milestone'' is passed (i.e., $\\{next\_control}\G\\{format}$). If
  2511  $\\{next\_control}\G\\{format}$ when \\{Pascal\_xref} is called, nothing will
  2512  happen;
  2513  but if $\\{next\_control}=\.{"|"}$ upon entry, the procedure assumes that this
  2514  is
  2515  the `\v' preceding \PASCAL\ text that is to be processed.
  2516  
  2517  The program uses the fact that our internal code numbers satisfy
  2518  the relations $\\{xref\_roman}=\\{identifier}+\\{roman}$ and $\\{xref%
  2519  \_wildcard}=\\{identifier}+\\{wildcard}$ and $\\{xref\_typewriter}=%
  2520  \\{identifier}+\\{typewriter}$ and $\\{normal}=0$. An implied `\.{@!}' is
  2521  inserted after
  2522  \&{function}, \&{procedure}, \&{program}, and \&{var}.
  2523  
  2524  \Y\P\4\&{procedure}\1\  \37\\{Pascal\_xref};\C{makes cross references for %
  2525  \PASCAL\ identifiers}\6
  2526  \4\&{label} \37\\{exit};\6
  2527  \4\&{var} \37\|p: \37\\{name\_pointer};\C{a referenced name}\2\6
  2528  \&{begin} \37\&{while} $\\{next\_control}<\\{format}$ \1\&{do}\6
  2529  \&{begin} \37\&{if} $(\\{next\_control}\G\\{identifier})\W(\\{next\_control}\L%
  2530  \\{xref\_typewriter})$ \1\&{then}\6
  2531  \&{begin} \37$\|p\K\\{id\_lookup}(\\{next\_control}-\\{identifier})$;\5
  2532  $\\{new\_xref}(\|p)$;\6
  2533  \&{if} $(\\{ilk}[\|p]=\\{proc\_like})\V(\\{ilk}[\|p]=\\{var\_like})$ \1\&{then}%
  2534  \5
  2535  $\\{xref\_switch}\K\\{def\_flag}$;\C{implied `\.{@!}'}\2\6
  2536  \&{end};\2\6
  2537  $\\{next\_control}\K\\{get\_next}$;\6
  2538  \&{if} $(\\{next\_control}=\.{"|"})\V(\\{next\_control}=\.{"\{"})$ \1\&{then}\5
  2539  \&{return};\2\6
  2540  \&{end};\2\6
  2541  \4\\{exit}: \37\&{end};\par
  2542  \fi
  2543  
  2544  \M112. The \\{outer\_xref} subroutine is like \\{Pascal\_xref} but it begins
  2545  with $\\{next\_control}\I\.{"|"}$ and ends with $\\{next\_control}\G%
  2546  \\{format}$. Thus, it
  2547  handles \PASCAL\ text with embedded comments.
  2548  
  2549  \Y\P\4\&{procedure}\1\  \37\\{outer\_xref};\C{extension of \\{Pascal\_xref}}\6
  2550  \4\&{var} \37\\{bal}: \37\\{eight\_bits};\C{brace level in comment}\2\6
  2551  \&{begin} \37\&{while} $\\{next\_control}<\\{format}$ \1\&{do}\6
  2552  \&{if} $\\{next\_control}\I\.{"\{"}$ \1\&{then}\5
  2553  \\{Pascal\_xref}\6
  2554  \4\&{else} \&{begin} \37$\\{bal}\K\\{skip\_comment}(1)$;\5
  2555  $\\{next\_control}\K\.{"|"}$;\6
  2556  \&{while} $\\{bal}>0$ \1\&{do}\6
  2557  \&{begin} \37\\{Pascal\_xref};\6
  2558  \&{if} $\\{next\_control}=\.{"|"}$ \1\&{then}\5
  2559  $\\{bal}\K\\{skip\_comment}(\\{bal})$\6
  2560  \4\&{else} $\\{bal}\K0$;\C{an error will be reported in phase two}\2\6
  2561  \&{end};\2\6
  2562  \&{end};\2\2\6
  2563  \&{end};\par
  2564  \fi
  2565  
  2566  \M113. In the \TeX\ part of a module, cross reference entries are made only for
  2567  the identifiers in \PASCAL\ texts enclosed in \pb, or for control texts
  2568  enclosed in \.{@\^}$\,\ldots\,$\.{@>} or \.{@.}$\,\ldots\,$\.{@>}
  2569  or \.{@:}$\,\ldots\,$\.{@>}.
  2570  
  2571  \Y\P$\4\X113:Store cross references in the \TeX\ part of a module\X\S$\6
  2572  \1\&{repeat} \37$\\{next\_control}\K\\{skip\_TeX}$;\6
  2573  \&{case} $\\{next\_control}$ \1\&{of}\6
  2574  \4\\{underline}: \37$\\{xref\_switch}\K\\{def\_flag}$;\6
  2575  \4\\{no\_underline}: \37$\\{xref\_switch}\K0$;\6
  2576  \4\.{"|"}: \37\\{Pascal\_xref};\6
  2577  \4$\\{xref\_roman},\39\\{xref\_wildcard},\39\\{xref\_typewriter},\39\\{module%
  2578  \_name}$: \37\&{begin} \37$\\{loc}\K\\{loc}-2$;\5
  2579  $\\{next\_control}\K\\{get\_next}$;\C{scan to \.{@>}}\6
  2580  \&{if} $\\{next\_control}\I\\{module\_name}$ \1\&{then}\5
  2581  $\\{new\_xref}(\\{id\_lookup}(\\{next\_control}-\\{identifier}))$;\2\6
  2582  \&{end};\6
  2583  \4\&{othercases} \37\\{do\_nothing}\2\6
  2584  \&{endcases};\6
  2585  \4\&{until}\5
  2586  $\\{next\_control}\G\\{format}$\2\par
  2587  \U110.\fi
  2588  
  2589  \M114. During the definition and \PASCAL\ parts of a module, cross references
  2590  are made for all identifiers except reserved words; however, the
  2591  identifiers in a format definition are referenced even if they are
  2592  reserved. The \TeX\ code in comments is, of course, ignored, except for
  2593  \PASCAL\ portions enclosed in \pb; the text of a module name is skipped
  2594  entirely, even if it contains \pb\ constructions.
  2595  
  2596  The variables \\{lhs} and \\{rhs} point to the respective identifiers involved
  2597  in a format definition.
  2598  
  2599  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  2600  \4$\\{lhs},\39\\{rhs}$: \37\\{name\_pointer};\C{indices into \\{byte\_start}
  2601  for format identifiers}\par
  2602  \fi
  2603  
  2604  \M115. When we get to the following code we have $\\{next\_control}\G%
  2605  \\{format}$.
  2606  
  2607  \Y\P$\4\X115:Store cross references in the \(definition part of a module\X\S$\6
  2608  \&{while} $\\{next\_control}\L\\{definition}$ \1\&{do}\C{\\{format} or %
  2609  \\{definition}}\6
  2610  \&{begin} \37$\\{xref\_switch}\K\\{def\_flag}$;\C{implied \.{@!}}\6
  2611  \&{if} $\\{next\_control}=\\{definition}$ \1\&{then}\5
  2612  $\\{next\_control}\K\\{get\_next}$\6
  2613  \4\&{else} \X116:Process a format definition\X;\2\6
  2614  \\{outer\_xref};\6
  2615  \&{end}\2\par
  2616  \U110.\fi
  2617  
  2618  \M116. Error messages for improper format definitions will be issued in phase
  2619  two. Our job in phase one is to define the \\{ilk} of a properly formatted
  2620  identifier, and to fool the \\{new\_xref} routine into thinking that the
  2621  identifier on the right-hand side of the format definition is not a
  2622  reserved word.
  2623  
  2624  \Y\P$\4\X116:Process a format definition\X\S$\6
  2625  \&{begin} \37$\\{next\_control}\K\\{get\_next}$;\6
  2626  \&{if} $\\{next\_control}=\\{identifier}$ \1\&{then}\6
  2627  \&{begin} \37$\\{lhs}\K\\{id\_lookup}(\\{normal})$;\5
  2628  $\\{ilk}[\\{lhs}]\K\\{normal}$;\5
  2629  $\\{new\_xref}(\\{lhs})$;\5
  2630  $\\{next\_control}\K\\{get\_next}$;\6
  2631  \&{if} $\\{next\_control}=\\{equivalence\_sign}$ \1\&{then}\6
  2632  \&{begin} \37$\\{next\_control}\K\\{get\_next}$;\6
  2633  \&{if} $\\{next\_control}=\\{identifier}$ \1\&{then}\6
  2634  \&{begin} \37$\\{rhs}\K\\{id\_lookup}(\\{normal})$;\5
  2635  $\\{ilk}[\\{lhs}]\K\\{ilk}[\\{rhs}]$;\5
  2636  $\\{ilk}[\\{rhs}]\K\\{normal}$;\5
  2637  $\\{new\_xref}(\\{rhs})$;\5
  2638  $\\{ilk}[\\{rhs}]\K\\{ilk}[\\{lhs}]$;\5
  2639  $\\{next\_control}\K\\{get\_next}$;\6
  2640  \&{end};\2\6
  2641  \&{end};\2\6
  2642  \&{end};\2\6
  2643  \&{end}\par
  2644  \U115.\fi
  2645  
  2646  \M117. Finally, when the \TeX\ and definition parts have been treated, we have
  2647  $\\{next\_control}\G\\{begin\_Pascal}$.
  2648  
  2649  \Y\P$\4\X117:Store cross references in the \PASCAL\ part of a module\X\S$\6
  2650  \&{if} $\\{next\_control}\L\\{module\_name}$ \1\&{then}\C{\\{begin\_Pascal} or %
  2651  \\{module\_name}}\6
  2652  \&{begin} \37\&{if} $\\{next\_control}=\\{begin\_Pascal}$ \1\&{then}\5
  2653  $\\{mod\_xref\_switch}\K0$\6
  2654  \4\&{else} $\\{mod\_xref\_switch}\K\\{def\_flag}$;\2\6
  2655  \1\&{repeat} \37\&{if} $\\{next\_control}=\\{module\_name}$ \1\&{then}\5
  2656  $\\{new\_mod\_xref}(\\{cur\_module})$;\2\6
  2657  $\\{next\_control}\K\\{get\_next}$;\5
  2658  \\{outer\_xref};\6
  2659  \4\&{until}\5
  2660  $\\{next\_control}>\\{module\_name}$;\2\6
  2661  \&{end}\2\par
  2662  \U110.\fi
  2663  
  2664  \M118. After phase one has looked at everything, we want to check that each
  2665  module name was both defined and used.
  2666  The variable \\{cur\_xref} will point to cross references for the
  2667  current module name of interest.
  2668  
  2669  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  2670  \4\\{cur\_xref}: \37\\{xref\_number};\C{temporary cross reference pointer}\par
  2671  \fi
  2672  
  2673  \M119. The following recursive procedure
  2674  walks through the tree of module names and prints out anomalies.
  2675  
  2676  \Y\P\4\&{procedure}\1\  \37$\\{mod\_check}(\|p:\\{name\_pointer})$;\C{print
  2677  anomalies in subtree \|p}\2\6
  2678  \&{begin} \37\&{if} $\|p>0$ \1\&{then}\6
  2679  \&{begin} \37$\\{mod\_check}(\\{llink}[\|p])$;\6
  2680  $\\{cur\_xref}\K\\{xref}[\|p]$;\6
  2681  \&{if} $\\{num}(\\{cur\_xref})<\\{def\_flag}$ \1\&{then}\6
  2682  \&{begin} \37$\\{print\_nl}(\.{\'!\ Never\ defined:\ <\'})$;\5
  2683  $\\{print\_id}(\|p)$;\5
  2684  $\\{print}(\.{\'>\'})$;\5
  2685  \\{mark\_harmless};\6
  2686  \&{end};\2\6
  2687  \&{while} $\\{num}(\\{cur\_xref})\G\\{def\_flag}$ \1\&{do}\5
  2688  $\\{cur\_xref}\K\\{xlink}(\\{cur\_xref})$;\2\6
  2689  \&{if} $\\{cur\_xref}=0$ \1\&{then}\6
  2690  \&{begin} \37$\\{print\_nl}(\.{\'!\ Never\ used:\ <\'})$;\5
  2691  $\\{print\_id}(\|p)$;\5
  2692  $\\{print}(\.{\'>\'})$;\5
  2693  \\{mark\_harmless};\6
  2694  \&{end};\2\6
  2695  $\\{mod\_check}(\\{rlink}[\|p])$;\6
  2696  \&{end};\2\6
  2697  \&{end};\par
  2698  \fi
  2699  
  2700  \M120. \P$\X120:Print error messages about unused or undefined module names\X%
  2701  \S$\ $\\{mod\_check}(\\{root})$\par
  2702  \U109.\fi
  2703  
  2704  \N121.  Low-level output routines.
  2705  The \TeX\ output is supposed to appear in lines at most \\{line\_length}
  2706  characters long, so we place it into an output buffer. During the output
  2707  process, \\{out\_line} will hold the current line number of the line about to
  2708  be output.
  2709  
  2710  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  2711  \4\\{out\_buf}: \37\&{array} $[0\to\\{line\_length}]$ \1\&{of}\5
  2712  \\{ASCII\_code};\C{assembled characters}\2\6
  2713  \4\\{out\_ptr}: \37$0\to\\{line\_length}$;\C{number of characters in \\{out%
  2714  \_buf}}\6
  2715  \4\\{out\_line}: \37\\{integer};\C{coordinates of next line to be output}\par
  2716  \fi
  2717  
  2718  \M122. The \\{flush\_buffer} routine empties the buffer up to a given
  2719  breakpoint,
  2720  and moves any remaining characters to the beginning of the next line.
  2721  If the \\{per\_cent} parameter is \\{true}, a \.{"\%"} is appended to the line
  2722  that is being output; in this case the breakpoint \|b should be strictly
  2723  less than \\{line\_length}. If the \\{per\_cent} parameter is \\{false},
  2724  trailing blanks are suppressed.
  2725  The characters emptied from the buffer form a new line of output;
  2726  if the \\{carryover} parameter is true, a \.{"\%"} in that line will be
  2727  carried over to the next line (so that \TeX\ will ignore the completion
  2728  of commented-out text).
  2729  
  2730  \Y\P\4\&{procedure}\1\  \37$\\{flush\_buffer}(\|b:\\{eight\_bits};\,\35\\{per%
  2731  \_cent},\39\\{carryover}:\\{boolean})$;\C{outputs $\\{out\_buf}[1\to\|b]$,
  2732  where $\|b\L\\{out\_ptr}$}\6
  2733  \4\&{label} \37$\\{done},\39\\{found}$;\6
  2734  \4\&{var} \37$\|j,\39\|k$: \37$0\to\\{line\_length}$;\2\6
  2735  \&{begin} \37$\|j\K\|b$;\6
  2736  \&{if} $\R\\{per\_cent}$ \1\&{then}\C{remove trailing blanks}\6
  2737  \~ \1\&{loop}\ \&{begin} \37\&{if} $\|j=0$ \1\&{then}\5
  2738  \&{goto} \37\\{done};\2\6
  2739  \&{if} $\\{out\_buf}[\|j]\I\.{"\ "}$ \1\&{then}\5
  2740  \&{goto} \37\\{done};\2\6
  2741  $\\{decr}(\|j)$;\6
  2742  \&{end};\2\2\6
  2743  \4\\{done}: \37\&{for} $\|k\K1\mathrel{\&{to}}\|j$ \1\&{do}\5
  2744  $\\{write}(\\{tex\_file},\39\\{xchr}[\\{out\_buf}[\|k]])$;\2\6
  2745  \&{if} $\\{per\_cent}$ \1\&{then}\5
  2746  $\\{write}(\\{tex\_file},\39\\{xchr}[\.{"\%"}])$;\2\6
  2747  $\\{write\_ln}(\\{tex\_file})$;\5
  2748  $\\{incr}(\\{out\_line})$;\6
  2749  \&{if} $\\{carryover}$ \1\&{then}\6
  2750  \&{for} $\|k\K1\mathrel{\&{to}}\|j$ \1\&{do}\6
  2751  \&{if} $\\{out\_buf}[\|k]=\.{"\%"}$ \1\&{then}\6
  2752  \&{if} $(\|k=1)\V(\\{out\_buf}[\|k-1]\I\.{"\\"})$ \1\&{then}\C{comment mode
  2753  should be preserved}\6
  2754  \&{begin} \37$\\{out\_buf}[\|b]\K\.{"\%"}$;\5
  2755  $\\{decr}(\|b)$;\5
  2756  \&{goto} \37\\{found};\6
  2757  \&{end};\2\2\2\2\6
  2758  \4\\{found}: \37\&{if} $(\|b<\\{out\_ptr})$ \1\&{then}\6
  2759  \&{for} $\|k\K\|b+1\mathrel{\&{to}}\\{out\_ptr}$ \1\&{do}\5
  2760  $\\{out\_buf}[\|k-\|b]\K\\{out\_buf}[\|k]$;\2\2\6
  2761  $\\{out\_ptr}\K\\{out\_ptr}-\|b$;\6
  2762  \&{end};\par
  2763  \fi
  2764  
  2765  \M123. When we are copying \TeX\ source material, we retain line breaks
  2766  that occur in the input, except that an empty line is not
  2767  output when the \TeX\ source line was nonempty. For example, a line
  2768  of the \TeX\ file that contains only an index cross-reference entry
  2769  will not be copied. The \\{finish\_line} routine is called just before
  2770  \\{get\_line} inputs a new line, and just after a line break token has
  2771  been emitted during the output of translated \PASCAL\ text.
  2772  
  2773  \Y\P\4\&{procedure}\1\  \37\\{finish\_line};\C{do this at the end of a line}\6
  2774  \4\&{label} \37\\{exit};\6
  2775  \4\&{var} \37\|k: \37$0\to\\{buf\_size}$;\C{index into \\{buffer}}\2\6
  2776  \&{begin} \37\&{if} $\\{out\_ptr}>0$ \1\&{then}\5
  2777  $\\{flush\_buffer}(\\{out\_ptr},\39\\{false},\39\\{false})$\6
  2778  \4\&{else} \&{begin} \37\&{for} $\|k\K0\mathrel{\&{to}}\\{limit}$ \1\&{do}\6
  2779  \&{if} $(\\{buffer}[\|k]\I\.{"\ "})\W(\\{buffer}[\|k]\I\\{tab\_mark})$ \1%
  2780  \&{then}\5
  2781  \&{return};\2\2\6
  2782  $\\{flush\_buffer}(0,\39\\{false},\39\\{false})$;\6
  2783  \&{end};\2\6
  2784  \4\\{exit}: \37\&{end};\par
  2785  \fi
  2786  
  2787  \M124. In particular, the \\{finish\_line} procedure is called near the very
  2788  beginning of phase two. We initialize the output variables in a slightly
  2789  tricky way so that the first line of the output file will be
  2790  `\.{\\input webmac}'.
  2791  
  2792  \Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
  2793  $\\{out\_ptr}\K1$;\5
  2794  $\\{out\_line}\K1$;\5
  2795  $\\{out\_buf}[1]\K\.{"c"}$;\5
  2796  $\\{write}(\\{tex\_file},\39\.{\'\\input\ webma\'})$;\par
  2797  \fi
  2798  
  2799  \M125. When we wish to append the character \|c to the output buffer, we write
  2800  `$\\{out}(c)$'; this will cause the buffer to be emptied if it was already
  2801  full. Similarly, `$\\{out2}(c_1)(c_2)$' appends a pair of characters.
  2802  A line break will occur at a space or after a single-nonletter
  2803  \TeX\ control sequence.
  2804  
  2805  \Y\P\D \37$\\{oot}(\#)\S$\6
  2806  \&{if} $\\{out\_ptr}=\\{line\_length}$ \1\&{then}\5
  2807  \\{break\_out};\2\6
  2808  $\\{incr}(\\{out\_ptr})$;\5
  2809  $\\{out\_buf}[\\{out\_ptr}]\K\#$;\par
  2810  \P\D \37$\\{oot1}(\#)\S\\{oot}(\#)$\ \&{end} \par
  2811  \P\D \37$\\{oot2}(\#)\S\\{oot}(\#)\,\\{oot1}$\par
  2812  \P\D \37$\\{oot3}(\#)\S\\{oot}(\#)\,\\{oot2}$\par
  2813  \P\D \37$\\{oot4}(\#)\S\\{oot}(\#)\,\\{oot3}$\par
  2814  \P\D \37$\\{oot5}(\#)\S\\{oot}(\#)\,\\{oot4}$\par
  2815  \P\D \37$\\{out}\S$\ \&{begin} \37\\{oot1}\par
  2816  \P\D \37$\\{out2}\S$\ \&{begin} \37\\{oot2}\par
  2817  \P\D \37$\\{out3}\S$\ \&{begin} \37\\{oot3}\par
  2818  \P\D \37$\\{out4}\S$\ \&{begin} \37\\{oot4}\par
  2819  \P\D \37$\\{out5}\S$\ \&{begin} \37\\{oot5}\par
  2820  \fi
  2821  
  2822  \M126. The \\{break\_out} routine is called just before the output buffer is
  2823  about
  2824  to overflow. To make this routine a little faster, we initialize position
  2825  0 of the output buffer to `\.\\'; this character isn't really output.
  2826  
  2827  \Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
  2828  $\\{out\_buf}[0]\K\.{"\\"}$;\par
  2829  \fi
  2830  
  2831  \M127. A long line is broken at a blank space or just before a backslash that
  2832  isn't
  2833  preceded by another backslash. In the latter case, a \.{"\%"} is output at
  2834  the break.
  2835  
  2836  \Y\P\4\&{procedure}\1\  \37\\{break\_out};\C{finds a way to break the output
  2837  line}\6
  2838  \4\&{label} \37\\{exit};\6
  2839  \4\&{var} \37\|k: \37$0\to\\{line\_length}$;\C{index into \\{out\_buf}}\6
  2840  \|d: \37\\{ASCII\_code};\C{character from the buffer}\2\6
  2841  \&{begin} \37$\|k\K\\{out\_ptr}$;\6
  2842  \~ \1\&{loop}\ \&{begin} \37\&{if} $\|k=0$ \1\&{then}\5
  2843  \X128:Print warning message, break the line, \&{return}\X;\2\6
  2844  $\|d\K\\{out\_buf}[\|k]$;\6
  2845  \&{if} $\|d=\.{"\ "}$ \1\&{then}\6
  2846  \&{begin} \37$\\{flush\_buffer}(\|k,\39\\{false},\39\\{true})$;\5
  2847  \&{return};\6
  2848  \&{end};\2\6
  2849  \&{if} $(\|d=\.{"\\"})\W(\\{out\_buf}[\|k-1]\I\.{"\\"})$ \1\&{then}\C{in this
  2850  case $\|k>1$}\6
  2851  \&{begin} \37$\\{flush\_buffer}(\|k-1,\39\\{true},\39\\{true})$;\5
  2852  \&{return};\6
  2853  \&{end};\2\6
  2854  $\\{decr}(\|k)$;\6
  2855  \&{end};\2\6
  2856  \4\\{exit}: \37\&{end};\par
  2857  \fi
  2858  
  2859  \M128. We get to this module only in unusual cases that the entire output line
  2860  consists of a string of backslashes followed by a string of nonblank
  2861  non-backslashes. In such cases it is almost always safe to break the
  2862  line by putting a \.{"\%"} just before the last character.
  2863  
  2864  \Y\P$\4\X128:Print warning message, break the line, \&{return}\X\S$\6
  2865  \&{begin} \37$\\{print\_nl}(\.{\'!\ Line\ had\ to\ be\ broken\ (output\ l.\'},%
  2866  \39\\{out\_line}:1)$;\5
  2867  $\\{print\_ln}(\.{\'):\'})$;\6
  2868  \&{for} $\|k\K1\mathrel{\&{to}}\\{out\_ptr}-1$ \1\&{do}\5
  2869  $\\{print}(\\{xchr}[\\{out\_buf}[\|k]])$;\2\6
  2870  \\{new\_line};\5
  2871  \\{mark\_harmless};\5
  2872  $\\{flush\_buffer}(\\{out\_ptr}-1,\39\\{true},\39\\{true})$;\5
  2873  \&{return};\6
  2874  \&{end}\par
  2875  \U127.\fi
  2876  
  2877  \M129. Here is a procedure that outputs a module number in decimal notation.
  2878  
  2879  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  2880  \4\\{dig}: \37\&{array} $[0\to4]$ \1\&{of}\5
  2881  $0\to9$;\C{digits to output}\2\par
  2882  \fi
  2883  
  2884  \M130. The number to be converted by \\{out\_mod} is known to be less than
  2885  \\{def\_flag}, so it cannot have more than five decimal digits.  If
  2886  the module is changed, we output `\.{\\*}' just after the number.
  2887  
  2888  \Y\P\4\&{procedure}\1\  \37$\\{out\_mod}(\|m:\\{integer})$;\C{output a module
  2889  number}\6
  2890  \4\&{var} \37\|k: \37$0\to5$;\C{index into \\{dig}}\6
  2891  \|a: \37\\{integer};\C{accumulator}\2\6
  2892  \&{begin} \37$\|k\K0$;\5
  2893  $\|a\K\|m$;\6
  2894  \1\&{repeat} \37$\\{dig}[\|k]\K\|a\mathbin{\&{mod}}10$;\5
  2895  $\|a\K\|a\mathbin{\&{div}}10$;\5
  2896  $\\{incr}(\|k)$;\6
  2897  \4\&{until}\5
  2898  $\|a=0$;\2\6
  2899  \1\&{repeat} \37$\\{decr}(\|k)$;\5
  2900  $\\{out}(\\{dig}[\|k]+\.{"0"})$;\6
  2901  \4\&{until}\5
  2902  $\|k=0$;\2\6
  2903  \&{if} $\\{changed\_module}[\|m]$ \1\&{then}\5
  2904  $\\{out2}(\.{"\\"})(\.{"*"})$;\2\6
  2905  \&{end};\par
  2906  \fi
  2907  
  2908  \M131. The \\{out\_name} subroutine is used to output an identifier or index
  2909  entry, enclosing it in braces.
  2910  
  2911  \Y\P\4\&{procedure}\1\  \37$\\{out\_name}(\|p:\\{name\_pointer})$;\C{outputs a
  2912  name}\6
  2913  \4\&{var} \37\|k: \37$0\to\\{max\_bytes}$;\C{index into \\{byte\_mem}}\6
  2914  \|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\_mem}}\2\6
  2915  \&{begin} \37$\\{out}(\.{"\{"})$;\5
  2916  $\|w\K\|p\mathbin{\&{mod}}\\{ww}$;\6
  2917  \&{for} $\|k\K\\{byte\_start}[\|p]\mathrel{\&{to}}\\{byte\_start}[\|p+%
  2918  \\{ww}]-1$ \1\&{do}\6
  2919  \&{begin} \37\&{if} $\\{byte\_mem}[\|w,\39\|k]=\.{"\_"}$ \1\&{then}\5
  2920  $\\{out}(\.{"\\"})$;\2\6
  2921  $\\{out}(\\{byte\_mem}[\|w,\39\|k])$;\6
  2922  \&{end};\2\6
  2923  $\\{out}(\.{"\}"})$;\6
  2924  \&{end};\par
  2925  \fi
  2926  
  2927  \N132.  Routines that copy \TeX\ material.
  2928  During phase two, we use the subroutines \\{copy\_limbo}, \\{copy\_TeX}, and
  2929  \\{copy\_comment} in place of the analogous \\{skip\_limbo}, \\{skip\_TeX}, and
  2930  \\{skip\_comment} that were used in phase one.
  2931  
  2932  The \\{copy\_limbo} routine, for example, takes \TeX\ material that is not
  2933  part of any module and transcribes it almost verbatim to the output file.
  2934  No `\.{@}' signs should occur in such material except in `\.{@@}'
  2935  pairs; such pairs are replaced by singletons.
  2936  
  2937  \Y\P\4\&{procedure}\1\  \37\\{copy\_limbo};\C{copy \TeX\ code until the next
  2938  module begins}\6
  2939  \4\&{label} \37\\{exit};\6
  2940  \4\&{var} \37\|c: \37\\{ASCII\_code};\C{character following \.{@} sign}\2\6
  2941  \&{begin} \37\~ \1\&{loop}\6
  2942  \&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
  2943  \&{begin} \37\\{finish\_line};\5
  2944  \\{get\_line};\6
  2945  \&{if} $\\{input\_has\_ended}$ \1\&{then}\5
  2946  \&{return};\2\6
  2947  \&{end}\6
  2948  \4\&{else} \&{begin} \37$\\{buffer}[\\{limit}+1]\K\.{"@"}$;\5
  2949  \X133:Copy up to control code, \&{return} if finished\X;\6
  2950  \&{end};\2\2\6
  2951  \4\\{exit}: \37\&{end};\par
  2952  \fi
  2953  
  2954  \M133. \P$\X133:Copy up to control code, \&{return} if finished\X\S$\6
  2955  \&{while} $\\{buffer}[\\{loc}]\I\.{"@"}$ \1\&{do}\6
  2956  \&{begin} \37$\\{out}(\\{buffer}[\\{loc}])$;\5
  2957  $\\{incr}(\\{loc})$;\6
  2958  \&{end};\2\6
  2959  \&{if} $\\{loc}\L\\{limit}$ \1\&{then}\6
  2960  \&{begin} \37$\\{loc}\K\\{loc}+2$;\5
  2961  $\|c\K\\{buffer}[\\{loc}-1]$;\6
  2962  \&{if} $(\|c=\.{"\ "})\V(\|c=\\{tab\_mark})\V(\|c=\.{"*"})$ \1\&{then}\5
  2963  \&{return};\2\6
  2964  $\\{out}(\.{"@"})$;\6
  2965  \&{if} $\|c\I\.{"@"}$ \1\&{then}\5
  2966  $\\{err\_print}(\.{\'!\ Double\ @\ required\ outside\ of\ sections\'})$;\2\6
  2967  \&{end}\2\par
  2968  \U132.\fi
  2969  
  2970  \M134. The \\{copy\_TeX} routine processes the \TeX\ code at the beginning of a
  2971  module; for example, the words you are now reading were copied in this
  2972  way. It returns the next control code or `\v' found in the input.
  2973  
  2974  \Y\P\4\&{function}\1\  \37\\{copy\_TeX}: \37\\{eight\_bits};\C{copy pure \TeX\
  2975  material}\6
  2976  \4\&{label} \37\\{done};\6
  2977  \4\&{var} \37\|c: \37\\{eight\_bits};\C{control code found}\2\6
  2978  \&{begin} \37\~ \1\&{loop}\6
  2979  \&{begin} \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
  2980  \&{begin} \37\\{finish\_line};\5
  2981  \\{get\_line};\6
  2982  \&{if} $\\{input\_has\_ended}$ \1\&{then}\6
  2983  \&{begin} \37$\|c\K\\{new\_module}$;\5
  2984  \&{goto} \37\\{done};\6
  2985  \&{end};\2\6
  2986  \&{end};\2\6
  2987  $\\{buffer}[\\{limit}+1]\K\.{"@"}$;\5
  2988  \X135:Copy up to `\v' or control code, \&{goto} \\{done} if finished\X;\6
  2989  \&{end};\2\6
  2990  \4\\{done}: \37$\\{copy\_TeX}\K\|c$;\6
  2991  \&{end};\par
  2992  \fi
  2993  
  2994  \M135. We don't copy spaces or tab marks into the beginning of a line. This
  2995  makes the test for empty lines in \\{finish\_line} work.
  2996  
  2997  \Y\P$\4\X135:Copy up to `\v' or control code, \&{goto} \\{done} if finished\X%
  2998  \S$\6
  2999  \1\&{repeat} \37$\|c\K\\{buffer}[\\{loc}]$;\5
  3000  $\\{incr}(\\{loc})$;\6
  3001  \&{if} $\|c=\.{"|"}$ \1\&{then}\5
  3002  \&{goto} \37\\{done};\2\6
  3003  \&{if} $\|c\I\.{"@"}$ \1\&{then}\6
  3004  \&{begin} \37$\\{out}(\|c)$;\6
  3005  \&{if} $(\\{out\_ptr}=1)\W((\|c=\.{"\ "})\V(\|c=\\{tab\_mark}))$ \1\&{then}\5
  3006  $\\{decr}(\\{out\_ptr})$;\2\6
  3007  \&{end};\2\6
  3008  \4\&{until}\5
  3009  $\|c=\.{"@"}$;\2\6
  3010  \&{if} $\\{loc}\L\\{limit}$ \1\&{then}\6
  3011  \&{begin} \37$\|c\K\\{control\_code}(\\{buffer}[\\{loc}])$;\5
  3012  $\\{incr}(\\{loc})$;\5
  3013  \&{goto} \37\\{done};\6
  3014  \&{end}\2\par
  3015  \U134.\fi
  3016  
  3017  \M136. The \\{copy\_comment} uses and returns a brace-balance value, following
  3018  the
  3019  conventions of \\{skip\_comment} above. Instead of copying the \TeX\ material
  3020  into the output buffer, this procedure copies it into the token memory.
  3021  The abbreviation $\\{app\_tok}(\|t)$ is used to append token \|t to the current
  3022  token list, and it also makes sure that it is possible to append at least
  3023  one further token without overflow.
  3024  
  3025  \Y\P\D \37$\\{app\_tok}(\#)\S$\1\6
  3026  \&{begin} \37\&{if} $\\{tok\_ptr}+2>\\{max\_toks}$ \1\&{then}\5
  3027  $\\{overflow}(\.{\'token\'})$;\2\6
  3028  $\\{tok\_mem}[\\{tok\_ptr}]\K\#$;\5
  3029  $\\{incr}(\\{tok\_ptr})$;\6
  3030  \&{end}\2\par
  3031  \Y\P\4\&{function}\1\  \37$\\{copy\_comment}(\\{bal}:\\{eight\_bits})$: \37%
  3032  \\{eight\_bits};\C{copies \TeX\ code in   comments}\6
  3033  \4\&{label} \37\\{done};\6
  3034  \4\&{var} \37\|c: \37\\{ASCII\_code};\C{current character being copied}\2\6
  3035  \&{begin} \37\~ \1\&{loop}\6
  3036  \&{begin} \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
  3037  \&{begin} \37\\{get\_line};\6
  3038  \&{if} $\\{input\_has\_ended}$ \1\&{then}\6
  3039  \&{begin} \37$\\{err\_print}(\.{\'!\ Input\ ended\ in\ mid-comment\'})$;\5
  3040  $\\{loc}\K1$;\5
  3041  \X138:Clear \\{bal} and \&{goto} \\{done}\X;\6
  3042  \&{end};\2\6
  3043  \&{end};\2\6
  3044  $\|c\K\\{buffer}[\\{loc}]$;\5
  3045  $\\{incr}(\\{loc})$;\6
  3046  \&{if} $\|c=\.{"|"}$ \1\&{then}\5
  3047  \&{goto} \37\\{done};\2\6
  3048  $\\{app\_tok}(\|c)$;\5
  3049  \X137:Copy special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"\}"}$; %
  3050  \&{goto} \\{done} at end\X;\6
  3051  \&{end};\2\6
  3052  \4\\{done}: \37$\\{copy\_comment}\K\\{bal}$;\6
  3053  \&{end};\par
  3054  \fi
  3055  
  3056  \M137. \P$\X137:Copy special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"%
  3057  \}"}$; \&{goto} \\{done} at end\X\S$\6
  3058  \&{if} $\|c=\.{"@"}$ \1\&{then}\6
  3059  \&{begin} \37$\\{incr}(\\{loc})$;\6
  3060  \&{if} $\\{buffer}[\\{loc}-1]\I\.{"@"}$ \1\&{then}\6
  3061  \&{begin} \37$\\{err\_print}(\.{\'!\ Illegal\ use\ of\ @\ in\ comment\'})$;\5
  3062  $\\{loc}\K\\{loc}-2$;\5
  3063  $\\{decr}(\\{tok\_ptr})$;\5
  3064  \X138:Clear \\{bal} and \&{goto} \\{done}\X;\6
  3065  \&{end};\2\6
  3066  \&{end}\6
  3067  \4\&{else} \&{if} $(\|c=\.{"\\"})\W(\\{buffer}[\\{loc}]\I\.{"@"})$ \1\&{then}\6
  3068  \&{begin} \37$\\{app\_tok}(\\{buffer}[\\{loc}])$;\5
  3069  $\\{incr}(\\{loc})$;\6
  3070  \&{end}\6
  3071  \4\&{else} \&{if} $\|c=\.{"\{"}$ \1\&{then}\5
  3072  $\\{incr}(\\{bal})$\6
  3073  \4\&{else} \&{if} $\|c=\.{"\}"}$ \1\&{then}\6
  3074  \&{begin} \37$\\{decr}(\\{bal})$;\6
  3075  \&{if} $\\{bal}=0$ \1\&{then}\5
  3076  \&{goto} \37\\{done};\2\6
  3077  \&{end}\2\2\2\2\par
  3078  \U136.\fi
  3079  
  3080  \M138. When the comment has terminated abruptly due to an error, we output
  3081  enough right braces to keep \TeX\ happy.
  3082  
  3083  \Y\P$\4\X138:Clear \\{bal} and \&{goto} \\{done}\X\S$\6
  3084  $\\{app\_tok}(\.{"\ "})$;\C{this is done in case the previous character was `\.%
  3085  \\'}\6
  3086  \1\&{repeat} \37$\\{app\_tok}(\.{"\}"})$;\5
  3087  $\\{decr}(\\{bal})$;\6
  3088  \4\&{until}\5
  3089  $\\{bal}=0$;\2\6
  3090  \&{goto} \37\\{done};\par
  3091  \Us136\ET137.\fi
  3092  
  3093  \N139.  Parsing.
  3094  The most intricate part of \.{WEAVE} is its mechanism for converting
  3095  \PASCAL-like code into \TeX\ code, and we might as well plunge into this
  3096  aspect of the program now. A ``bottom up'' approach is used to parse the
  3097  \PASCAL-like material, since \.{WEAVE} must deal with fragmentary
  3098  constructions whose overall ``part of speech'' is not known.
  3099  
  3100  At the lowest level, the input is represented as a sequence of entities
  3101  that we shall call {\it scraps}, where each scrap of information consists
  3102  of two parts, its {\it category} and its {\it translation}. The category
  3103  is essentially a syntactic class, and the translation is a token list that
  3104  represents \TeX\ code. Rules of syntax and semantics tell us how to
  3105  combine adjacent scraps into larger ones, and if we are lucky an entire
  3106  \PASCAL\ text that starts out as hundreds of small scraps will join
  3107  together into one gigantic scrap whose translation is the desired \TeX\
  3108  code. If we are unlucky, we will be left with several scraps that don't
  3109  combine; their translations will simply be output, one by one.
  3110  
  3111  The combination rules are given as context-sensitive productions that are
  3112  applied from left to right. Suppose that we are currently working on the
  3113  sequence of scraps $s_1\,s_2\ldots s_n$. We try first to find the longest
  3114  production that applies to an initial substring $s_1\,s_2\ldots\,$; but if
  3115  no such productions exist, we try to find the longest production
  3116  applicable to the next substring $s_2\,s_3\ldots\,$; and if that fails, we
  3117  try to match $s_3\,s_4\ldots\,$, etc.
  3118  
  3119  A production applies if the category codes have a given pattern. For
  3120  example, one of the productions is
  3121  $$\\{open}\;\\{math}\;\\{semi}\;\RA\;\\{open}\;\\{math}$$
  3122  and it means that three consecutive scraps whose respective categories are
  3123  \\{open}, \\{math}, and \\{semi} are con\-verted to two scraps whose categories
  3124  are \\{open} and \\{math}. This production also has an associated rule that
  3125  tells how to combine the translation parts:
  3126  $$\eqalign{O_2&=O_1\cr
  3127  M_2&=M_1\,S\,\.{\\,}\,\hbox{\\{opt}\thinspace\tt5}\cr}$$
  3128  This means that the \\{open} scrap has not changed, while the new \\{math}
  3129  scrap
  3130  has a translation $M_2$ composed of the translation $M_1$ of the original
  3131  \\{math} scrap followed by the translation \|S of the \\{semi} scrap followed
  3132  by `\.{\\,}' followed by `\\{opt}' followed by `\.5'. (In the \TeX\ file,
  3133  this will specify an additional thin space after the semicolon, followed
  3134  by an optional line break with penalty 50.) Translation rules use subscripts
  3135  to distinguish between translations of scraps whose categories have the
  3136  same initial letter; these subscripts are assigned from left to right.
  3137  
  3138  $\.{WEAVE}$ also has the production rule
  3139  $$\\{semi}\;\RA\;\\{terminator}$$
  3140  (meaning that a semicolon can terminate a \PASCAL\ statement). Since
  3141  productions are applied from left to right, this rule will be activated
  3142  only if the \\{semi} is not preceded by scraps that match other productions;
  3143  in particular, a \\{semi} that is preceded by `\\{open} \\{math}' will have
  3144  disappeared because of the production above, and such semicolons do not
  3145  act as statement terminators.  This incidentally is how \.{WEAVE} is able
  3146  to treat semicolons in two distinctly different ways, the first of which
  3147  is intended for semicolons in the parameter list of a procedure
  3148  declaration.
  3149  
  3150  The translation rule corresponding to $\\{semi}\;\RA\;\\{terminator}$ is
  3151  $$T=S$$
  3152  but we shall not mention translation rules in the common case that the
  3153  translation of the new scrap on the right-hand side is simply the
  3154  concatenation of the disappearing scraps on the left-hand side.
  3155  
  3156  \fi
  3157  
  3158  \M140. Here is a list of the category codes that scraps can have.
  3159  
  3160  \Y\P\D \37$\\{simp}=1$\C{the translation can be used both in horizontal mode
  3161  and in math mode of \TeX}\par
  3162  \P\D \37$\\{math}=2$\C{the translation should be used only in \TeX\ math mode}%
  3163  \par
  3164  \P\D \37$\\{intro}=3$\C{a statement is expected to follow this, after a space
  3165  and   an optional break}\par
  3166  \P\D \37$\\{open}=4$\C{denotes an incomplete parenthesized quantity to be used
  3167  in   math mode}\par
  3168  \P\D \37$\\{beginning}=5$\C{denotes an incomplete compound statement to be used
  3169  in   horizontal mode}\par
  3170  \P\D \37$\\{close}=6$\C{ends a parenthesis or compound statement}\par
  3171  \P\D \37$\\{alpha}=7$\C{denotes the beginning of a clause}\par
  3172  \P\D \37$\\{omega}=8$\C{denotes the ending of a clause and possible comment
  3173  following}\par
  3174  \P\D \37$\\{semi}=9$\C{denotes a semicolon and possible comment following it}%
  3175  \par
  3176  \P\D \37$\\{terminator}=10$\C{something that ends a statement or declaration}%
  3177  \par
  3178  \P\D \37$\\{stmt}=11$\C{denotes a statement or declaration including its
  3179  terminator}\par
  3180  \P\D \37$\\{cond}=12$\C{precedes an \&{if} clause that might have a matching %
  3181  \&{else}}\par
  3182  \P\D \37$\\{clause}=13$\C{precedes a statement after which indentation ends}\par
  3183  \P\D \37$\\{colon}=14$\C{denotes a colon}\par
  3184  \P\D \37$\\{exp}=15$\C{stands for the E in a floating point constant}\par
  3185  \P\D \37$\\{proc}=16$\C{denotes a procedure or program or function heading}\par
  3186  \P\D \37$\\{case\_head}=17$\C{denotes a case statement or record heading}\par
  3187  \P\D \37$\\{record\_head}=18$\C{denotes a record heading without indentation}%
  3188  \par
  3189  \P\D \37$\\{var\_head}=19$\C{denotes a variable declaration heading}\par
  3190  \P\D \37$\\{elsie}=20$\C{\&{else}}\par
  3191  \P\D \37$\\{casey}=21$\C{\&{case}}\par
  3192  \P\D \37$\\{mod\_scrap}=22$\C{denotes a module name}\par
  3193  \Y\P\&{debug} \37\&{procedure}\1\  \37$\\{print\_cat}(\|c:\\{eight\_bits})$;%
  3194  \C{symbolic printout of a category}\2\6
  3195  \&{begin} \37\&{case} $\|c$ \1\&{of}\6
  3196  \4\\{simp}: \37$\\{print}(\.{\'simp\'})$;\6
  3197  \4\\{math}: \37$\\{print}(\.{\'math\'})$;\6
  3198  \4\\{intro}: \37$\\{print}(\.{\'intro\'})$;\6
  3199  \4\\{open}: \37$\\{print}(\.{\'open\'})$;\6
  3200  \4\\{beginning}: \37$\\{print}(\.{\'beginning\'})$;\6
  3201  \4\\{close}: \37$\\{print}(\.{\'close\'})$;\6
  3202  \4\\{alpha}: \37$\\{print}(\.{\'alpha\'})$;\6
  3203  \4\\{omega}: \37$\\{print}(\.{\'omega\'})$;\6
  3204  \4\\{semi}: \37$\\{print}(\.{\'semi\'})$;\6
  3205  \4\\{terminator}: \37$\\{print}(\.{\'terminator\'})$;\6
  3206  \4\\{stmt}: \37$\\{print}(\.{\'stmt\'})$;\6
  3207  \4\\{cond}: \37$\\{print}(\.{\'cond\'})$;\6
  3208  \4\\{clause}: \37$\\{print}(\.{\'clause\'})$;\6
  3209  \4\\{colon}: \37$\\{print}(\.{\'colon\'})$;\6
  3210  \4\\{exp}: \37$\\{print}(\.{\'exp\'})$;\6
  3211  \4\\{proc}: \37$\\{print}(\.{\'proc\'})$;\6
  3212  \4\\{case\_head}: \37$\\{print}(\.{\'casehead\'})$;\6
  3213  \4\\{record\_head}: \37$\\{print}(\.{\'recordhead\'})$;\6
  3214  \4\\{var\_head}: \37$\\{print}(\.{\'varhead\'})$;\6
  3215  \4\\{elsie}: \37$\\{print}(\.{\'elsie\'})$;\6
  3216  \4\\{casey}: \37$\\{print}(\.{\'casey\'})$;\6
  3217  \4\\{mod\_scrap}: \37$\\{print}(\.{\'module\'})$;\6
  3218  \4\&{othercases} \37$\\{print}(\.{\'UNKNOWN\'})$\2\6
  3219  \&{endcases};\6
  3220  \&{end};\6
  3221  \&{gubed}\par
  3222  \fi
  3223  
  3224  \M141. The token lists for translated \TeX\ output contain some special control
  3225  symbols as well as ordinary characters. These control symbols are
  3226  interpreted by \.{WEAVE} before they are written to the output file.
  3227  
  3228  \yskip\hang \\{break\_space} denotes an optional line break or an en space;
  3229  
  3230  \yskip\hang \\{force} denotes a line break;
  3231  
  3232  \yskip\hang \\{big\_force} denotes a line break with additional vertical space;
  3233  
  3234  \yskip\hang \\{opt} denotes an optional line break (with the continuation
  3235  line indented two ems with respect to the normal starting position)---this
  3236  code is followed by an integer \|n, and the break will occur with penalty
  3237  $10n$;
  3238  
  3239  \yskip\hang \\{backup} denotes a backspace of one em;
  3240  
  3241  \yskip\hang \\{cancel} obliterates any \\{break\_space} or \\{force} or \\{big%
  3242  \_force}
  3243  tokens that immediately precede or follow it and also cancels any
  3244  \\{backup} tokens that follow it;
  3245  
  3246  \yskip\hang \\{indent} causes future lines to be indented one more em;
  3247  
  3248  \yskip\hang \\{outdent} causes future lines to be indented one less em.
  3249  
  3250  \yskip\noindent All of these tokens are removed from the \TeX\ output that
  3251  comes from \PASCAL\ text between \pb\ signs; \\{break\_space} and \\{force} and
  3252  \\{big\_force} become single spaces in this mode. The translation of other
  3253  \PASCAL\ texts results in \TeX\ control sequences \.{\\1}, \.{\\2},
  3254  \.{\\3}, \.{\\4}, \.{\\5}, \.{\\6}, \.{\\7} corresponding respectively to
  3255  \\{indent}, \\{outdent}, \\{opt}, \\{backup}, \\{break\_space}, \\{force}, and
  3256  \\{big\_force}. However, a sequence of consecutive `\.\ ', \\{break\_space},
  3257  \\{force}, and/or \\{big\_force} tokens is first replaced by a single token
  3258  (the maximum of the given ones).
  3259  
  3260  The tokens \\{math\_rel}, \\{math\_bin}, \\{math\_op} will be translated into
  3261  \.{\\mathrel\{}, \.{\\mathbin\{}, and \.{\\mathop\{}, respectively.
  3262  Other control sequences in the \TeX\ output will be `\.{\\\\\{}$\,\ldots\,$\.%
  3263  \}'
  3264  surrounding identifiers, `\.{\\\&\{}$\,\ldots\,$\.\}' surrounding
  3265  reserved words, `\.{\\.\{}$\,\ldots\,$\.\}' surrounding strings,
  3266  `\.{\\C\{}$\,\ldots\,$\.\}$\,$\\{force}' surrounding comments, and
  3267  `\.{\\X$n$:}$\,\ldots\,$\.{\\X}' surrounding module names, where
  3268  \|n is the module number.
  3269  
  3270  \Y\P\D \37$\\{math\_bin}=\O{203}$\par
  3271  \P\D \37$\\{math\_rel}=\O{204}$\par
  3272  \P\D \37$\\{math\_op}=\O{205}$\par
  3273  \P\D \37$\\{big\_cancel}=\O{206}$\C{like \\{cancel}, also overrides spaces}\par
  3274  \P\D \37$\\{cancel}=\O{207}$\C{overrides \\{backup}, \\{break\_space}, %
  3275  \\{force}, \\{big\_force}}\par
  3276  \P\D \37$\\{indent}=\\{cancel}+1$\C{one more tab (\.{\\1})}\par
  3277  \P\D \37$\\{outdent}=\\{cancel}+2$\C{one less tab (\.{\\2})}\par
  3278  \P\D \37$\\{opt}=\\{cancel}+3$\C{optional break in mid-statement (\.{\\3})}\par
  3279  \P\D \37$\\{backup}=\\{cancel}+4$\C{stick out one unit to the left (\.{\\4})}%
  3280  \par
  3281  \P\D \37$\\{break\_space}=\\{cancel}+5$\C{optional break between statements (%
  3282  \.{\\5})}\par
  3283  \P\D \37$\\{force}=\\{cancel}+6$\C{forced break between statements (\.{\\6})}%
  3284  \par
  3285  \P\D \37$\\{big\_force}=\\{cancel}+7$\C{forced break with additional space (\.{%
  3286  \\7})}\par
  3287  \P\D \37$\\{end\_translation}=\\{big\_force}+1$\C{special sentinel token at end
  3288  of list}\par
  3289  \fi
  3290  
  3291  \M142. The raw input is converted into scraps according to the following table,
  3292  which gives category codes followed by the translations. Sometimes a single
  3293  item of input produces more than one scrap.
  3294  \def\stars {\.{**}}%
  3295  (The symbol `\stars' stands for `\.{\\\&\{{\rm identifier}\}}',
  3296  i.e., the identifier itself treated as a reserved word. In a few cases the
  3297  category is given as `\\{comment}'; this is not an actual category code, it
  3298  means that the translation will be treated as a comment, as explained
  3299  below.)
  3300  
  3301  \yskip\halign{\quad#\hfil&\quad#\hfil\cr
  3302  \.{<>}& \\{math}: \.{\\I}\cr
  3303  \.{<=}& \\{math}: \.{\\L}\cr
  3304  \.{>=}& \\{math}: \.{\\G}\cr
  3305  \.{:=}& \\{math}: \.{\\K}\cr
  3306  \.{==}& \\{math}: \.{\\S}\cr
  3307  \.{(*}& \\{math}: \.{\\B}\cr
  3308  \.{*)}& \\{math}: \.{\\T}\cr
  3309  \.{(.}& \\{open}: \.[\cr
  3310  \.{.)}& \\{close}: \.]\cr
  3311  \."$\,$string$\,$\."& \\{simp}: \.{\\.\{"{\rm$\,$modified string$\,$}"\}}\cr
  3312  \.\'$\,$string$\,$\.\'& \\{simp}: \.{\\.\{\\\'{\rm$\,$modified
  3313  string$\,$}\\\'\}}\cr
  3314  \.{@=}$\,$string$\,$\.{@>}& \\{simp}: \.{\\=\{{\rm$\,$modified string$\,$}\}}%
  3315  \cr
  3316  \#& \\{math}: \.{\\\#}\cr
  3317  \.\$& \\{math}: \.{\\\$}\cr
  3318  \.\_& \\{math}: \.{\\\_}\cr
  3319  \.\%& \\{math}: \.{\\\%}\cr
  3320  \.\^& \\{math}: \.{\\\^}\cr
  3321  \.(& \\{open}: \.(\cr
  3322  \.)& \\{close}: \.)\cr
  3323  \.[& \\{open}: \.[\cr
  3324  \.]& \\{close}: \.]\cr
  3325  \.*& \\{math}: \.{\\ast}\cr
  3326  \.,& \\{math}: \.,$\,\\{opt}\,$\.9\cr
  3327  \.{..}& \\{math}: \.{\\to}\cr
  3328  \..& \\{simp}: \..\cr
  3329  \.:& \\{colon}: \.:\cr
  3330  \.;& \\{semi}: \.;\cr
  3331  identifier& \\{simp}: \.{\\\\\{{\rm$\,$identifier$\,$}\}}\cr
  3332  \.E in constant& \\{exp}: \.{\\E\{}\cr
  3333  digit $d$& \\{simp}: $d$\cr
  3334  other character $c$& \\{math}: $c$\cr
  3335  \.{and}& \\{math}: \.{\\W}\cr
  3336  \.{array}& \\{alpha}: \stars\cr
  3337  \.{begin}& \\{beginning}: $\\{force}\,\stars\,\\{cancel}$\qquad \\{intro}: \cr
  3338  \.{case}& \\{casey}: \qquad \\{alpha}: $\\{force}\,\stars$\cr
  3339  \.{const}& \\{intro}: $\\{force}\,\\{backup}\,\stars$\cr
  3340  \.{div}& \\{math}: $\\{math\_bin}\,\stars\,\.\}$\cr
  3341  \.{do}& \\{omega}: \stars\cr
  3342  \.{downto}& \\{math}: $\\{math\_rel}\,\stars\,\.\}$\cr
  3343  \.{else}& \\{terminator}: \qquad \\{elsie}: $\\{force}\,\\{backup}\,\stars$\cr
  3344  \.{end}& \\{terminator}: \qquad \\{close}: $\\{force}\,\stars$\cr
  3345  \.{file}& \\{alpha}: \stars\cr
  3346  \.{for}& \\{alpha}: $\\{force}\,\stars$\cr
  3347  \.{function}& \\{proc}: $\\{force}\,\\{backup}\,\stars\,\\{cancel}$\qquad
  3348   \\{intro}: $\\{indent}\,\.{\\\ }$\cr
  3349  \.{goto}& \\{intro}: \stars\cr
  3350  \.{if}& \\{cond}: \qquad \\{alpha}: $\\{force}\,\stars$\cr
  3351  \.{in}& \\{math}: \.{\\in}\cr
  3352  \.{label}& \\{intro}: $\\{force}\,\\{backup}\,\stars$\cr
  3353  \.{mod}& \\{math}: $\\{math\_bin}\,\stars\,\.\}$\cr
  3354  \.{nil}& \\{simp}: \stars\cr
  3355  \.{not}& \\{math}: \.{\\R}\cr
  3356  \.{of}& \\{omega}: \stars\cr
  3357  \.{or}& \\{math}: \.{\\V}\cr
  3358  \.{packed}& \\{intro}: \stars\cr
  3359  \.{procedure}& \\{proc}: $\\{force}\,\\{backup}\,\stars\,\\{cancel}$\qquad
  3360   \\{intro}: $\\{indent}\,\.{\\\ }$\cr
  3361  \.{program}& \\{proc}: $\\{force}\,\\{backup}\,\stars\,\\{cancel}$\qquad
  3362   \\{intro}: $\\{indent}\,\.{\\\ }$\cr
  3363  \.{record}& \\{record\_head}: \stars\qquad \\{intro}: \cr
  3364  \.{repeat}& \\{beginning}: $\\{force}\,\\{indent}\,\stars\,\\{cancel}$\qquad %
  3365  \\{intro}: \cr
  3366  \.{set}& \\{alpha}: \stars\cr
  3367  \.{then}& \\{omega}: \stars\cr
  3368  \.{to}& \\{math}: $\\{math\_rel}\,\stars\,\.\}$\cr
  3369  \.{type}& \\{intro}: $\\{force}\,\\{backup}\,\stars$\cr
  3370  \.{until}& \\{terminator}: \qquad \\{close}: $\\{force}\,\\{backup}\,\stars$%
  3371  \qquad
  3372   \\{clause}: \cr
  3373  \.{var}& \\{var\_head}: $\\{force}\,\\{backup}\,\stars\,\\{cancel}$\qquad %
  3374  \\{intro}: \cr
  3375  \.{while}& \\{alpha}: $\\{force}\,\stars$\cr
  3376  \.{with}& \\{alpha}: $\\{force}\,\stars$\cr
  3377  \.{xclause}& \\{alpha}: $\\{force}\,\.{\\\~}$\qquad \\{omega}: \stars\cr
  3378  \.{@\'}$\,$const& \\{simp}: \.{\\O\{}\hbox{const}\.\}\cr
  3379  \.{@"}$\,$const& \\{simp}: \.{\\H\{}\hbox{const}\.\}\cr
  3380  \.{@\$}& \\{simp}: \.{\\)}\cr
  3381  \.{@\\}& \\{simp}: \.{\\]}\cr
  3382  \.{@,}& \\{math}: \.{\\,}\cr
  3383  \.{@t}$\,$stuff$\,$\.{@>}& \\{simp}: \.{\\hbox\{{\rm$\,$stuff$\,$}\}}\cr
  3384  \.{@<}$\,$module$\,$\.{@>}& \\{mod\_scrap}: \.{\\X$n$:{\rm$\,$module$\,$}\\X}%
  3385  \cr
  3386  \.{@\#}& \\{comment}: \\{big\_force}\cr
  3387  \.{@/}& \\{comment}: \\{force}\cr
  3388  \.{@\char'174}& \\{simp}: $\\{opt}\,\.0$\cr
  3389  \.{@+}& \\{comment}: $\\{big\_cancel}\,\.{\\\ }\,\\{big\_cancel}$\cr
  3390  \.{@;}& \\{semi}: \cr
  3391  \.{@\&}& \\{math}: \.{\\J}\cr
  3392  \.{@\{}& \\{math}: \.{\\B}\cr
  3393  \.{@\}}& \\{math}: \.{\\T}\cr}
  3394  \yskip\noindent When a string is output, certain characters are preceded by
  3395  `\.\\' signs so that they will print properly.
  3396  
  3397  A comment in the input will be combined with the preceding
  3398  \\{omega} or \\{semi} scrap, or with the following \\{terminator} scrap, if
  3399  possible; otherwise it will be inserted as a separate \\{terminator} scrap.
  3400  An additional ``comment'' is effectively appended at the end of the
  3401  \PASCAL\ text, just before translation begins; this consists of a \\{cancel}
  3402  token in the case of \PASCAL\ text in \pb, otherwise it consists of a
  3403  \\{force} token.
  3404  
  3405  From this table it is evident that \.{WEAVE} will parse a lot of non-\PASCAL\
  3406  programs. For example, the reserved words `\.{for}' and `\.{array}' are
  3407  treated in an identical way by \.{WEAVE} from a syntactic standpoint,
  3408  and semantically they are equivalent except that a forced line break occurs
  3409  just before `\&{for}'; \PASCAL\ programmers may well be surprised at this
  3410  similarity. The idea is to keep \.{WEAVE}'s rules as simple as possible,
  3411  consistent with doing a reasonable job on syntactically correct \PASCAL\
  3412  programs. The production rules below have been formulated in the same
  3413  spirit of ``almost anything goes.''
  3414  
  3415  \fi
  3416  
  3417  \M143. Here is a table of all the productions. The reader can best get a feel
  3418  for
  3419  how they work by trying them out by hand on small examples; no amount of
  3420  explanation will be as effective as watching the rules in action.
  3421  Parsing can also be watched by debugging with `\.{@2}'.
  3422  
  3423  \def\[#1]{\quad$\dleft#1\dright$}
  3424  \def\sp{\.{\ }}
  3425  \yskip
  3426  \halign to\the\hsize{\hfil\it# &
  3427  #\hfil\hskip-200pt\tabskip 0pt plus 100pt&
  3428  #\hfil\tabskip0pt\cr
  3429  &Production categories\[\hbox{translations}]&Remarks\cr
  3430  \noalign{\yskip}
  3431  1&$\\{alpha}\,\\{math}\,\\{colon}$ $\RA$ $\\{alpha}\,\\{math}$&e.g.,  \&{case}
  3432  $\|v:\\{boolean}$ \&{of}\cr
  3433  2&$\\{alpha}\,\\{math}\,\\{omega}$ $\RA$ \\{clause}\[C=A\,\sp\,\.\$\,M\,\.\$\,%
  3434  \sp\,\\{indent}\,
  3435  O]&e.g.,  \&{while} $\|x>0$ \&{do}\cr
  3436  3&$\\{alpha}\,\\{omega}$ $\RA$ \\{clause}\[C=A\,\sp\,\\{indent}\,O]&e.g., %
  3437  \&{file} \&{of}\cr
  3438  4&$\\{alpha}\,\\{simp}$ $\RA$ $\\{alpha}\,\\{math}$&convert to math mode\cr
  3439  5&$\\{beginning}\,\\{close}\,(\\{terminator}\hbox{ or }\\{stmt})$ $\RA$ %
  3440  \\{stmt}&compound statement
  3441  ends\cr
  3442  6&$\\{beginning}\,\\{stmt}$ $\RA$ \\{beginning}\[B_2=B_1\,\\{break\_space}%
  3443  \,S]&compound
  3444  statement grows\cr
  3445  7&$\\{case\_head}\,\\{casey}\,\\{clause}$ $\RA$ \\{case\_head}\[C_4=C_1\,%
  3446  \\{outdent}\,C_2\,C_3]&
  3447  variant records\cr
  3448  8&$\\{case\_head}\,\\{close}\,\\{terminator}$ $\RA$ \\{stmt}\[S=C_1\,\\{cancel}%
  3449  \,\\{outdent}\,
  3450  C_2\,T]&end of case statement\cr
  3451  9&$\\{case\_head}\,\\{stmt}$ $\RA$ \\{case\_head}\[C_2=C_1\,\\{force}\,S]&case
  3452  statement
  3453  grows\cr
  3454  10&$\\{casey}\,\\{clause}$ $\RA$ \\{case\_head}&beginning of case statement\cr
  3455  11&$\\{clause}\,\\{stmt}$ $\RA$ \\{stmt}\[S_2=C\,\\{break\_space}\,S_1\,%
  3456  \\{cancel}\,\\{outdent}\,
  3457  \\{force}]&end of controlled statement\cr
  3458  12&$\\{cond}\,\\{clause}\,\\{stmt}\,\\{elsie}$ $\RA$ \\{clause}\[C_3=C_1\,C_2\,%
  3459  \\{break\_space}\,S\,
  3460  E\,\sp\,\\{cancel}]&complete conditional\cr
  3461  13&$\\{cond}\,\\{clause}\,\\{stmt}$ $\RA$ \\{stmt}\cr
  3462  &\qquad\[S_2=C_1\,C_2\,\\{break\_space}\,S_1\,
  3463  \\{cancel}\,\\{outdent}\,\\{force}]&incomplete conditional\cr
  3464  14&\\{elsie} $\RA$ \\{intro}&unmatched else\cr
  3465  15&$\\{exp}\,\\{math}\,\\{simp}$* $\RA$ \\{math}\[M_2=E\,M_1\,S\,\.\}]&signed
  3466  exponent\cr
  3467  16&$\\{exp}\,\\{simp}$* $\RA$ \\{math}\[M=E\,S\,\.\}]&unsigned exponent\cr
  3468  17&$\\{intro}\,\\{stmt}$ $\RA$ \\{stmt}\[S_2=I\,\sp\,\\{opt}\,\.7\,\\{cancel}%
  3469  \,S_1]&labeled
  3470  statement, etc.\cr
  3471  18&$\\{math}\,\\{close}$ $\RA$ $\\{stmt}\,\\{close}$\[S=\.\$\,M\,\.\$]&end of
  3472  field list\cr
  3473  19&$\\{math}\,\\{colon}$ $\RA$ \\{intro}\[I=\\{force}\,\\{backup}\,\.\$\,M\,\.%
  3474  \$\,C]&compound
  3475  label\cr
  3476  20&$\\{math}\,\\{math}$ $\RA$ \\{math}&simple concatenation\cr
  3477  21&$\\{math}\,\\{simp}$ $\RA$ \\{math}&simple concatenation\cr
  3478  22&$\\{math}\,\\{stmt}$ $\RA$ \\{stmt}\cr
  3479  &\qquad\[S_2=\.\$\,M\,\.\$\,\\{indent}\,\\{break\_space}\,
  3480  S_1\,\\{cancel}\,\\{outdent}\,\\{force}]&macro or type definition\cr
  3481  23&$\\{math}\,\\{terminator}$ $\RA$ \\{stmt}\[S=\.\$\,M\,\.\$\,T]&statement
  3482  involving
  3483  math\cr
  3484  24&$\\{mod\_scrap}\,(\\{terminator}\hbox{ or }\\{semi})$ $\RA$ \\{stmt}\[S=M\,T%
  3485  \,\\{force}]&module
  3486  like a statement\cr
  3487  25&\\{mod\_scrap} $\RA$ \\{simp}&module unlike a statement\cr
  3488  26&$\\{open}\,\\{case\_head}\,\\{close}$ $\RA$ \\{math}\[M=O\,\.\$\,\\{cancel}%
  3489  \,C_1\,
  3490  \\{cancel}\,\\{outdent}\,\.\$\,C_2]&case in field list\cr
  3491  27&$\\{open}\,\\{close}$ $\RA$ \\{math}\[M=O\,\.\\\,\.,\,C]&empty set $[\,]$\cr
  3492  28&$\\{open}\,\\{math}\,\\{case\_head}\,\\{close}$ $\RA$ \\{math}\cr
  3493  &\qquad\[M_2=O\,M_1\,\.\$\,\\{cancel}\,
  3494  C_1\,\\{cancel}\,\\{outdent}\,\.\$\,C_2]&case in field list\cr
  3495  29&$\\{open}\,\\{math}\,\\{close}$ $\RA$ \\{math}&parenthesized group\cr
  3496  30&$\\{open}\,\\{math}\,\\{colon}$ $\RA$ $\\{open}\,\\{math}$&colon in
  3497  parentheses\cr
  3498  31&$\\{open}\,\\{math}\,\\{proc}\,\\{intro}$ $\RA$ $\\{open}\,\\{math}$%
  3499  \[M_2=M_1\,\\{math\_op}\,\\{cancel}\,
  3500  P\,\.\}]& \&{procedure}\   in parentheses\cr
  3501  32&$\\{open}\,\\{math}\,\\{semi}$ $\RA$ $\\{open}\,\\{math}$\[M_2=M_1\,S\,\.%
  3502  \\\,\.,\,\\{opt}\,
  3503  \.5]&semicolon in parentheses\cr
  3504  33&$\\{open}\,\\{math}\,\\{var\_head}\,\\{intro}$ $\RA$ $\\{open}\,\\{math}$%
  3505  \[M_2=M_1\,\\{math\_op}\,
  3506  \\{cancel}\,V\,\.\}]& \&{var}  in parentheses\cr
  3507  34&$\\{open}\,\\{proc}\,\\{intro}$ $\RA$ $\\{open}\,\\{math}$\[M=\\{math\_op}\,%
  3508  \\{cancel}\,
  3509  P\,\.\}]& \&{procedure}\   in parentheses\cr
  3510  35&$\\{open}\,\\{simp}$ $\RA$ $\\{open}\,\\{math}$&convert to math mode\cr
  3511  36&$\\{open}\,\\{stmt}\,\\{close}$ $\RA$ \\{math}\[M=O\,\.\$\,\\{cancel}\,S\,%
  3512  \\{cancel}\,
  3513  \.\$\,C]&field list\cr
  3514  37&$\\{open}\,\\{var\_head}\,\\{intro}$ $\RA$ $\\{open}\,\\{math}$\[M=\\{math%
  3515  \_op}\,\\{cancel}\,V\,
  3516  \.\}]& \&{var}  in parentheses\cr
  3517  38&$\\{proc}\,\\{beginning}\,\\{close}\,\\{terminator}$ $\RA$ \\{stmt}\[S=P\,%
  3518  \\{cancel}\,
  3519  \\{outdent}\,B\,C\,T]&end of procedure declaration\cr
  3520  39&$\\{proc}\,\\{stmt}$ $\RA$ \\{proc}\[P_2=P_1\,\\{break\_space}\,S]&procedure
  3521  declaration
  3522  grows\cr
  3523  40&$\\{record\_head}\,\\{intro}\,\\{casey}$ $\RA$ \\{casey}\[C_2=R\,I\,\sp\,%
  3524  \\{cancel}\,C_1]&
  3525  \&{record case} $\ldots$\cr
  3526  41&\\{record\_head} $\RA$ \\{case\_head}\[C=\\{indent}\,R\,\\{cancel}]&other %
  3527  \&{record}
  3528  structures\cr
  3529  42&\\{semi} $\RA$ \\{terminator}&semicolon after statement\cr
  3530  43&$\\{simp}\,\\{close}$ $\RA$ $\\{stmt}\,\\{close}$&end of field list\cr
  3531  44&$\\{simp}\,\\{colon}$ $\RA$ \\{intro}\[I=\\{force}\,\\{backup}\,S\,C]&simple
  3532  label\cr
  3533  45&$\\{simp}\,\\{math}$ $\RA$ \\{math}&simple concatenation\cr
  3534  46&$\\{simp}\,\\{mod\_scrap}$ $\RA$ \\{mod\_scrap}&in emergencies\cr
  3535  47&$\\{simp}\,\\{simp}$ $\RA$ \\{simp}&simple concatenation\cr
  3536  48&$\\{simp}\,\\{terminator}$ $\RA$ \\{stmt}&simple statement\cr
  3537  49&$\\{stmt}\,\\{stmt}$ $\RA$ \\{stmt}\[S_3=S_1\,\\{break\_space}%
  3538  \,S_2]&adjacent
  3539  statements\cr
  3540  50&\\{terminator} $\RA$ \\{stmt}&empty statement\cr
  3541  51&$\\{var\_head}\,\\{beginning}$ $\RA$ $\\{stmt}\,\\{beginning}$&end of
  3542  variable
  3543  declarations\cr
  3544  52&$\\{var\_head}\,\\{math}\,\\{colon}$ $\RA$ $\\{var\_head}\,\\{intro}$\[I=\.%
  3545  \$\,M\,\.\$\,C]&
  3546  variable declaration\cr
  3547  53&$\\{var\_head}\,\\{simp}\,\\{colon}$ $\RA$ $\\{var\_head}\,%
  3548  \\{intro}$&variable declaration\cr
  3549  54&$\\{var\_head}\,\\{stmt}$ $\RA$ \\{var\_head}\[V_2=V_1\,\\{break\_space}%
  3550  \,S]&variable
  3551  declarations grow\cr}
  3552  \yskip\noindent
  3553  Translations are not specified here when they are simple concatenations
  3554  of the scraps that change. For example, the full translation of
  3555  `$\\{open}\,\\{math}\,\\{colon}$ $\RA$ $\\{open}\,\\{math}$' is $O_2=O_1$,
  3556  $M_2=M_1C$.
  3557  
  3558  The notation `\\{simp}*', in the \\{exp}-related productions above,
  3559  stands for a \\{simp} scrap that isn't followed by another \\{simp}.
  3560  
  3561  \fi
  3562  
  3563  \N144.  Implementing the productions.
  3564  When \PASCAL\ text is to be processed with the grammar above, we put its
  3565  initial scraps $s_1\ldots s_n$ into two arrays $\\{cat}[1\to\|n]$ and $%
  3566  \\{trans}[1\to\|n]$.
  3567  The value of $\\{cat}[\|k]$ is simply a category code from the list above; the
  3568  value of $\\{trans}[\|k]$ is a text pointer, i.e., an index into \\{tok%
  3569  \_start}.
  3570  Our production rules have the nice property that the right-hand side is never
  3571  longer than the left-hand side. Therefore it is convenient to use sequential
  3572  allocation for the current sequence of scraps. Five pointers are used to
  3573  manage the parsing:
  3574  
  3575  \yskip\hang \\{pp} (the parsing pointer) is such that we are trying to match
  3576  the category codes $\\{cat}[\\{pp}]\,\\{cat}[\\{pp}+1]$$\,\ldots\,$ to the
  3577  left-hand sides
  3578  of productions.
  3579  
  3580  \yskip\hang \\{scrap\_base}, \\{lo\_ptr}, \\{hi\_ptr}, and \\{scrap\_ptr} are
  3581  such that
  3582  the current sequence of scraps appears in positions \\{scrap\_base} through
  3583  \\{lo\_ptr} and \\{hi\_ptr} through \\{scrap\_ptr}, inclusive, in the \\{cat}
  3584  and
  3585  \\{trans} arrays. Scraps located between \\{scrap\_base} and \\{lo\_ptr} have
  3586  been examined, while those in positions $\G\\{hi\_ptr}$ have not yet been
  3587  looked at by the parsing process.
  3588  
  3589  \yskip\noindent Initially \\{scrap\_ptr} is set to the position of the final
  3590  scrap to be parsed, and it doesn't change its value. The parsing process
  3591  makes sure that $\\{lo\_ptr}\G\\{pp}+3$, since productions have as many as four
  3592  terms,
  3593  by moving scraps from \\{hi\_ptr} to \\{lo\_ptr}. If there are
  3594  fewer than $\\{pp}+3$ scraps left, the positions up to $\\{pp}+3$ are filled
  3595  with
  3596  blanks that will not match in any productions. Parsing stops when
  3597  $\\{pp}=\\{lo\_ptr}+1$ and $\\{hi\_ptr}=\\{scrap\_ptr}+1$.
  3598  
  3599  The \\{trans} array elements are declared to be of type $0\to10239$ instead
  3600  of type \\{text\_pointer}, because the final sorting phase of \.{WEAVE}
  3601  uses this array to contain elements of type \\{name\_pointer}. Both
  3602  of these types are subranges of $0\to10239$.
  3603  
  3604  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  3605  \4\\{cat}: \37\&{array} $[0\to\\{max\_scraps}]$ \1\&{of}\5
  3606  \\{eight\_bits};\C{category codes of scraps}\2\6
  3607  \4\\{trans}: \37\&{array} $[0\to\\{max\_scraps}]$ \1\&{of}\5
  3608  $0\to10239$;\C{translation texts of scraps}\2\6
  3609  \4\\{pp}: \37$0\to\\{max\_scraps}$;\C{current position for reducing
  3610  productions}\6
  3611  \4\\{scrap\_base}: \37$0\to\\{max\_scraps}$;\C{beginning of the current scrap
  3612  sequence}\6
  3613  \4\\{scrap\_ptr}: \37$0\to\\{max\_scraps}$;\C{ending of the current scrap
  3614  sequence}\6
  3615  \4\\{lo\_ptr}: \37$0\to\\{max\_scraps}$;\C{last scrap that has been examined}\6
  3616  \4\\{hi\_ptr}: \37$0\to\\{max\_scraps}$;\C{first scrap that has not been
  3617  examined}\6
  3618  \&{stat} \37\\{max\_scr\_ptr}: \37$0\to\\{max\_scraps}$;\C{largest value
  3619  assumed by \\{scrap\_ptr}}\6
  3620  \&{tats}\par
  3621  \fi
  3622  
  3623  \M145. \P$\X10:Set initial values\X\mathrel{+}\S$\6
  3624  $\\{scrap\_base}\K1$;\5
  3625  $\\{scrap\_ptr}\K0$;\6
  3626  \&{stat} \37$\\{max\_scr\_ptr}\K0$;\ \&{tats}\par
  3627  \fi
  3628  
  3629  \M146. Token lists in \\{tok\_mem} are composed of the following kinds of
  3630  items for \TeX\ output.
  3631  
  3632  \yskip\item{$\bullet$}ASCII codes and special codes like \\{force} and
  3633  \\{math\_rel} represent themselves;
  3634  
  3635  \item{$\bullet$}$\\{id\_flag}+\|p$ represents \.{\\\\\{{\rm identifier $p$}\}};
  3636  
  3637  \item{$\bullet$}$\\{res\_flag}+\|p$ represents \.{\\\&\{{\rm identifier $p$}%
  3638  \}};
  3639  
  3640  \item{$\bullet$}$\\{mod\_flag}+\|p$ represents module name \|p;
  3641  
  3642  \item{$\bullet$}$\\{tok\_flag}+\|p$ represents token list number \|p;
  3643  
  3644  \item{$\bullet$}$\\{inner\_tok\_flag}+\|p$ represents token list number \|p, to
  3645  be
  3646  translated without line-break controls.
  3647  
  3648  \Y\P\D \37$\\{id\_flag}=10240$\C{signifies an identifier}\par
  3649  \P\D \37$\\{res\_flag}=\\{id\_flag}+\\{id\_flag}$\C{signifies a reserved word}%
  3650  \par
  3651  \P\D \37$\\{mod\_flag}=\\{res\_flag}+\\{id\_flag}$\C{signifies a module name}%
  3652  \par
  3653  \P\D \37$\\{tok\_flag}\S\\{mod\_flag}+\\{id\_flag}$\C{signifies a token list}%
  3654  \par
  3655  \P\D \37$\\{inner\_tok\_flag}\S\\{tok\_flag}+\\{id\_flag}$\C{signifies a token
  3656  list in `\pb'}\Y\par
  3657  \P\D \37$\\{lbrace}\S\\{xchr}[\.{"\{"}]$\C{this avoids possible \PASCAL\
  3658  compiler confusion}\par
  3659  \P\D \37$\\{rbrace}\S\\{xchr}[\.{"\}"}]$\C{because these braces might occur
  3660  within comments}\par
  3661  \Y\P\&{debug} \37\&{procedure}\1\  \37$\\{print\_text}(\|p:\\{text\_pointer})$;%
  3662  \C{prints a token list}\6
  3663  \4\&{var} \37\|j: \37$0\to\\{max\_toks}$;\C{index into \\{tok\_mem}}\6
  3664  \|r: \37$0\to\\{id\_flag}-1$;\C{remainder of token after the flag has been
  3665  stripped off}\2\6
  3666  \&{begin} \37\&{if} $\|p\G\\{text\_ptr}$ \1\&{then}\5
  3667  $\\{print}(\.{\'BAD\'})$\6
  3668  \4\&{else} \&{for} $\|j\K\\{tok\_start}[\|p]\mathrel{\&{to}}\\{tok\_start}[%
  3669  \|p+1]-1$ \1\&{do}\6
  3670  \&{begin} \37$\|r\K\\{tok\_mem}[\|j]\mathbin{\&{mod}}\\{id\_flag}$;\6
  3671  \&{case} $\\{tok\_mem}[\|j]\mathbin{\&{div}}\\{id\_flag}$ \1\&{of}\6
  3672  \41: \37\&{begin} \37$\\{print}(\.{\'\\\\\'},\39\\{lbrace})$;\5
  3673  $\\{print\_id}(\|r)$;\5
  3674  $\\{print}(\\{rbrace})$;\6
  3675  \&{end};\C{\\{id\_flag}}\6
  3676  \42: \37\&{begin} \37$\\{print}(\.{\'\\\&\'},\39\\{lbrace})$;\5
  3677  $\\{print\_id}(\|r)$;\5
  3678  $\\{print}(\\{rbrace})$;\6
  3679  \&{end};\C{\\{res\_flag}}\6
  3680  \43: \37\&{begin} \37$\\{print}(\.{\'<\'})$;\5
  3681  $\\{print\_id}(\|r)$;\5
  3682  $\\{print}(\.{\'>\'})$;\6
  3683  \&{end};\C{\\{mod\_flag}}\6
  3684  \44: \37$\\{print}(\.{\'[[\'},\39\|r:1,\39\.{\']]\'})$;\C{\\{tok\_flag}}\6
  3685  \45: \37$\\{print}(\.{\'|[[\'},\39\|r:1,\39\.{\']]|\'})$;\C{\\{inner\_tok%
  3686  \_flag}}\6
  3687  \4\&{othercases} \37\X147:Print token \|r in symbolic form\X\2\6
  3688  \&{endcases};\6
  3689  \&{end};\2\2\6
  3690  \&{end};\6
  3691  \&{gubed}\par
  3692  \fi
  3693  
  3694  \M147. \P$\X147:Print token \|r in symbolic form\X\S$\6
  3695  \&{case} $\|r$ \1\&{of}\6
  3696  \4\\{math\_bin}: \37$\\{print}(\.{\'\\mathbin\'},\39\\{lbrace})$;\6
  3697  \4\\{math\_rel}: \37$\\{print}(\.{\'\\mathrel\'},\39\\{lbrace})$;\6
  3698  \4\\{math\_op}: \37$\\{print}(\.{\'\\mathop\'},\39\\{lbrace})$;\6
  3699  \4\\{big\_cancel}: \37$\\{print}(\.{\'[ccancel]\'})$;\6
  3700  \4\\{cancel}: \37$\\{print}(\.{\'[cancel]\'})$;\6
  3701  \4\\{indent}: \37$\\{print}(\.{\'[indent]\'})$;\6
  3702  \4\\{outdent}: \37$\\{print}(\.{\'[outdent]\'})$;\6
  3703  \4\\{backup}: \37$\\{print}(\.{\'[backup]\'})$;\6
  3704  \4\\{opt}: \37$\\{print}(\.{\'[opt]\'})$;\6
  3705  \4\\{break\_space}: \37$\\{print}(\.{\'[break]\'})$;\6
  3706  \4\\{force}: \37$\\{print}(\.{\'[force]\'})$;\6
  3707  \4\\{big\_force}: \37$\\{print}(\.{\'[fforce]\'})$;\6
  3708  \4\\{end\_translation}: \37$\\{print}(\.{\'[quit]\'})$;\6
  3709  \4\&{othercases} \37$\\{print}(\\{xchr}[\|r])$\2\6
  3710  \&{endcases}\par
  3711  \U146.\fi
  3712  
  3713  \M148. The production rules listed above are embedded directly into the %
  3714  \.{WEAVE}
  3715  program, since it is easier to do this than to write an interpretive system
  3716  that would handle production systems in general. Several macros are defined
  3717  here so that the program for each production is fairly short.
  3718  
  3719  All of our productions conform to the general notion that some \|k
  3720  consecutive scraps starting at some position \|j are to be replaced by a
  3721  single scrap of some category \|c whose translation is composed from the
  3722  translations of the disappearing scraps. After this production has been
  3723  applied, the production pointer \\{pp} should change by an amount \|d. Such
  3724  a production can be represented by the quadruple $(j,k,c,d)$. For example,
  3725  the production `$\\{simp}\,\\{math}$ $\RA$ \\{math}' would be represented by
  3726  `$(\\{pp},2,\\{math},-1)$'; in this case the pointer $pp$ should decrease by 1
  3727  after the production has been applied, because some productions with
  3728  \\{math} in their second positions might now match, but no productions have
  3729  \\{math} in the third or fourth position of their left-hand sides. Note that
  3730  the value of \|d is determined by the whole collection of productions, not
  3731  by an individual one. Consider the further example
  3732  `$\\{var\_head}\,\\{math}\,\\{colon}$ $\RA$ $\\{var\_head}\,\\{intro}$', which
  3733  is represented by
  3734  `$(\\{pp}+1,2,\\{intro},+1)$'; the $+1$ here is deduced by looking at the
  3735  grammar and seeing that no matches could possibly occur at positions $\L\\{pp}$
  3736  after this production has been applied. The determination of \|d has been
  3737  done by hand in each case, based on the full set of productions but not on
  3738  the grammar of \PASCAL\ or on the rules for constructing the initial
  3739  scraps.
  3740  
  3741  We also attach a serial number to each production, so that additional
  3742  information is available when debugging. For example, the program below
  3743  contains the statement `$\\{reduce}(\\{pp}+1,2,\\{intro},+1)(52)$' when it
  3744  implements
  3745  the production just mentioned.
  3746  
  3747  Before calling \\{reduce}, the program should have appended the tokens of
  3748  the new translation to the \\{tok\_mem} array. We commonly want to append
  3749  copies of several existing translations, and macros are defined to
  3750  simplify these common cases. For example, $\\{app2}(\\{pp})$ will append the
  3751  translations of two consecutive scraps, $\\{trans}[\\{pp}]$ and $\\{trans}[%
  3752  \\{pp}+1]$, to
  3753  the current token list. If the entire new translation is formed in this
  3754  way, we write `$\\{squash}(j,k,c,d)$' instead of `$\\{reduce}(j,k,c,d)$'. For
  3755  example, `$\\{squash}(\\{pp},2,\\{math},-1)$' is an abbreviation for `$%
  3756  \\{app2}(\\{pp})$; $\\{reduce}(\\{pp},2,\\{math},-1)$'.
  3757  
  3758  The code below is an exact translation of the production rules into
  3759  \PASCAL, using such macros, and the reader should have no difficulty
  3760  understanding the format by comparing the code with the symbolic
  3761  productions as they were listed earlier.
  3762  
  3763  {\sl Caution:\/} The macros \\{app}, \\{app1}, \\{app2}, and \\{app3} are
  3764  sequences of statements that are not enclosed with  \&{begin}  and $  \&{end}
  3765  $,
  3766  because such delimiters would make the \PASCAL\ program much longer. This
  3767  means that it is necessary to write  \&{begin}  and   \&{end}  explicitly when
  3768  such
  3769  a macro is used as a single statement. Several mysterious bugs in the
  3770  original programming of \.{WEAVE} were caused by a failure to remember
  3771  this fact.  Next time the author will know better.
  3772  
  3773  \Y\P\D \37$\\{production}(\#)\S$\1\6
  3774  \&{debug} \37$\\{prod}(\#)$\6
  3775  \&{gubed};\2\6
  3776  \&{goto} \37\\{found}\par
  3777  \P\D \37$\\{reduce}(\#)\S\\{red}(\#)$;\5
  3778  \\{production}\par
  3779  \P\D \37$\\{production\_end}(\#)\S$\1\6
  3780  \&{debug} \37$\\{prod}(\#)$\6
  3781  \&{gubed};\2\6
  3782  \&{goto} \37\\{found}; \6
  3783  \&{end} \par
  3784  \P\D $\\{squash}(\#)\S$ \6
  3785  \&{begin} \37$\\{sq}(\#)$;\5
  3786  \\{production\_end}\par
  3787  \P\D \37$\\{app}(\#)\S\\{tok\_mem}[\\{tok\_ptr}]\K\#$;\5
  3788  $\\{incr}(\\{tok\_ptr})$\C{this is like \\{app\_tok},   but it doesn't test for
  3789  overflow}\par
  3790  \P\D \37$\\{app1}(\#)\S\\{tok\_mem}[\\{tok\_ptr}]\K\\{tok\_flag}+\\{trans}[%
  3791  \#]$;\5
  3792  $\\{incr}(\\{tok\_ptr})$\par
  3793  \P\D \37$\\{app2}(\#)\S\\{app1}(\#)$;\5
  3794  $\\{app1}(\#+1)$\par
  3795  \P\D \37$\\{app3}(\#)\S\\{app2}(\#)$;\5
  3796  $\\{app1}(\#+2)$\par
  3797  \fi
  3798  
  3799  \M149. Let us consider the big case statement for productions now, before
  3800  looking
  3801  at its context. We want to design the program so that this case statement
  3802  works, so we might as well not keep ourselves in suspense about exactly what
  3803  code needs to be provided with a proper environment.
  3804  
  3805  The code here is more complicated than it need be, since some popular
  3806  \PASCAL\ compilers are unable to deal with procedures that contain a lot
  3807  of program text. The \\{translate} procedure, which incorporates the   \&{case}
  3808  statement here, would become too long for those compilers if we did
  3809  not do something to split the cases into parts. Therefore
  3810  a separate procedure called \\{five\_cases} has been introduced.
  3811  This auxiliary procedure contains approximately half of the program text
  3812  that \\{translate} would otherwise have had. There's also a procedure
  3813  called \\{alpha\_cases}, which turned out to be necessary because the best
  3814  two-way split wasn't good enough. The procedure could be split further
  3815  in an analogous manner, but the present scheme works on all compilers
  3816  known to the author.
  3817  
  3818  \Y\P$\4\X149:Match a production at \\{pp}, or increase \\{pp} if there is no
  3819  match\X\S$\6
  3820  \&{if} $\\{cat}[\\{pp}]\L\\{alpha}$ \1\&{then}\6
  3821  \&{if} $\\{cat}[\\{pp}]<\\{alpha}$ \1\&{then}\5
  3822  \\{five\_cases}\ \&{else} \\{alpha\_cases}\2\6
  3823  \4\&{else} \&{begin} \37\&{case} $\\{cat}[\\{pp}]$ \1\&{of}\6
  3824  \4\\{case\_head}: \37\X153:Cases for \\{case\_head}\X;\6
  3825  \4\\{casey}: \37\X154:Cases for \\{casey}\X;\6
  3826  \4\\{clause}: \37\X155:Cases for \\{clause}\X;\6
  3827  \4\\{cond}: \37\X156:Cases for \\{cond}\X;\6
  3828  \4\\{elsie}: \37\X157:Cases for \\{elsie}\X;\6
  3829  \4\\{exp}: \37\X158:Cases for \\{exp}\X;\6
  3830  \4\\{mod\_scrap}: \37\X161:Cases for \\{mod\_scrap}\X;\6
  3831  \4\\{proc}: \37\X164:Cases for \\{proc}\X;\6
  3832  \4\\{record\_head}: \37\X165:Cases for \\{record\_head}\X;\6
  3833  \4\\{semi}: \37\X166:Cases for \\{semi}\X;\6
  3834  \4\\{stmt}: \37\X168:Cases for \\{stmt}\X;\6
  3835  \4\\{terminator}: \37\X169:Cases for \\{terminator}\X;\6
  3836  \4\\{var\_head}: \37\X170:Cases for \\{var\_head}\X;\6
  3837  \4\&{othercases} \37\\{do\_nothing}\2\6
  3838  \&{endcases};\6
  3839  $\\{incr}(\\{pp})$;\C{if no match was found, we move to the right}\6
  3840  \4\\{found}: \37\&{end}\2\par
  3841  \U175.\fi
  3842  
  3843  \M150. Here are the procedures that need to be present for the reason just
  3844  explained.
  3845  
  3846  \Y\P$\4\X150:Declaration of subprocedures for \\{translate}\X\S$\6
  3847  \4\&{procedure}\1\  \37\\{five\_cases};\C{handles almost half of the syntax}\6
  3848  \4\&{label} \37\\{found};\2\6
  3849  \&{begin} \37\&{case} $\\{cat}[\\{pp}]$ \1\&{of}\6
  3850  \4\\{beginning}: \37\X152:Cases for \\{beginning}\X;\6
  3851  \4\\{intro}: \37\X159:Cases for \\{intro}\X;\6
  3852  \4\\{math}: \37\X160:Cases for \\{math}\X;\6
  3853  \4\\{open}: \37\X162:Cases for \\{open}\X;\6
  3854  \4\\{simp}: \37\X167:Cases for \\{simp}\X;\6
  3855  \4\&{othercases} \37\\{do\_nothing}\2\6
  3856  \&{endcases};\6
  3857  $\\{incr}(\\{pp})$;\C{if no match was found, we move to the right}\6
  3858  \4\\{found}: \37\&{end};\7
  3859  \4\&{procedure}\1\  \37\\{alpha\_cases};\6
  3860  \4\&{label} \37\\{found};\2\6
  3861  \&{begin} \37\X151:Cases for \\{alpha}\X;\6
  3862  $\\{incr}(\\{pp})$;\C{if no match was found, we move to the right}\6
  3863  \4\\{found}: \37\&{end};\par
  3864  \U179.\fi
  3865  
  3866  \M151. Now comes the code that tries to match each production starting
  3867  with a particular type of scrap. Whenever a match is discovered,
  3868  the \\{squash} or \\{reduce} macro will cause the appropriate action
  3869  to be performed, followed by \&{goto} \\{found}.
  3870  
  3871  \Y\P$\4\X151:Cases for \\{alpha}\X\S$\6
  3872  \&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\6
  3873  \&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{colon}$ \1\&{then}\5
  3874  $\\{squash}(\\{pp}+1,\392,\39\\{math},\390)(1)$\6
  3875  \4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{omega}$ \1\&{then}\6
  3876  \&{begin} \37$\\{app1}(\\{pp})$;\5
  3877  $\\{app}(\.{"\ "})$;\5
  3878  $\\{app}(\.{"\$"})$;\5
  3879  $\\{app1}(\\{pp}+1)$;\5
  3880  $\\{app}(\.{"\$"})$;\5
  3881  $\\{app}(\.{"\ "})$;\5
  3882  $\\{app}(\\{indent})$;\5
  3883  $\\{app1}(\\{pp}+2)$;\5
  3884  $\\{reduce}(\\{pp},\393,\39\\{clause},\39-2)(2)$;\6
  3885  \&{end};\2\2\6
  3886  \&{end}\6
  3887  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{omega}$ \1\&{then}\6
  3888  \&{begin} \37$\\{app1}(\\{pp})$;\5
  3889  $\\{app}(\.{"\ "})$;\5
  3890  $\\{app}(\\{indent})$;\5
  3891  $\\{app1}(\\{pp}+1)$;\5
  3892  $\\{reduce}(\\{pp},\392,\39\\{clause},\39-2)(3)$;\6
  3893  \&{end}\6
  3894  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\5
  3895  $\\{squash}(\\{pp}+1,\391,\39\\{math},\390)(4)$\2\2\2\par
  3896  \U150.\fi
  3897  
  3898  \M152. \P$\X152:Cases for \\{beginning}\X\S$\6
  3899  \&{if} $\\{cat}[\\{pp}+1]=\\{close}$ \1\&{then}\6
  3900  \&{begin} \37\&{if} $(\\{cat}[\\{pp}+2]=\\{terminator})\V(\\{cat}[\\{pp}+2]=%
  3901  \\{stmt})$ \1\&{then}\5
  3902  $\\{squash}(\\{pp},\393,\39\\{stmt},\39-2)(5)$;\2\6
  3903  \&{end}\6
  3904  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
  3905  \&{begin} \37$\\{app1}(\\{pp})$;\5
  3906  $\\{app}(\\{break\_space})$;\5
  3907  $\\{app1}(\\{pp}+1)$;\5
  3908  $\\{reduce}(\\{pp},\392,\39\\{beginning},\39-1)(6)$;\6
  3909  \&{end}\2\2\par
  3910  \U150.\fi
  3911  
  3912  \M153. \P$\X153:Cases for \\{case\_head}\X\S$\6
  3913  \&{if} $\\{cat}[\\{pp}+1]=\\{casey}$ \1\&{then}\6
  3914  \&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{clause}$ \1\&{then}\6
  3915  \&{begin} \37$\\{app1}(\\{pp})$;\5
  3916  $\\{app}(\\{outdent})$;\5
  3917  $\\{app2}(\\{pp}+1)$;\5
  3918  $\\{reduce}(\\{pp},\393,\39\\{case\_head},\390)(7)$;\6
  3919  \&{end};\2\6
  3920  \&{end}\6
  3921  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{close}$ \1\&{then}\6
  3922  \&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{terminator}$ \1\&{then}\6
  3923  \&{begin} \37$\\{app1}(\\{pp})$;\5
  3924  $\\{app}(\\{cancel})$;\5
  3925  $\\{app}(\\{outdent})$;\5
  3926  $\\{app2}(\\{pp}+1)$;\5
  3927  $\\{reduce}(\\{pp},\393,\39\\{stmt},\39-2)(8)$;\6
  3928  \&{end};\2\6
  3929  \&{end}\6
  3930  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
  3931  \&{begin} \37$\\{app1}(\\{pp})$;\5
  3932  $\\{app}(\\{force})$;\5
  3933  $\\{app1}(\\{pp}+1)$;\5
  3934  $\\{reduce}(\\{pp},\392,\39\\{case\_head},\390)(9)$;\6
  3935  \&{end}\2\2\2\par
  3936  \U149.\fi
  3937  
  3938  \M154. \P$\X154:Cases for \\{casey}\X\S$\6
  3939  \&{if} $\\{cat}[\\{pp}+1]=\\{clause}$ \1\&{then}\5
  3940  $\\{squash}(\\{pp},\392,\39\\{case\_head},\390)(10)$\2\par
  3941  \U149.\fi
  3942  
  3943  \M155. \P$\X155:Cases for \\{clause}\X\S$\6
  3944  \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
  3945  \&{begin} \37$\\{app1}(\\{pp})$;\5
  3946  $\\{app}(\\{break\_space})$;\5
  3947  $\\{app1}(\\{pp}+1)$;\5
  3948  $\\{app}(\\{cancel})$;\5
  3949  $\\{app}(\\{outdent})$;\5
  3950  $\\{app}(\\{force})$;\5
  3951  $\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(11)$;\6
  3952  \&{end}\2\par
  3953  \U149.\fi
  3954  
  3955  \M156. \P$\X156:Cases for \\{cond}\X\S$\6
  3956  \&{if} $(\\{cat}[\\{pp}+1]=\\{clause})\W(\\{cat}[\\{pp}+2]=\\{stmt})$ \1%
  3957  \&{then}\6
  3958  \&{if} $\\{cat}[\\{pp}+3]=\\{elsie}$ \1\&{then}\6
  3959  \&{begin} \37$\\{app2}(\\{pp})$;\5
  3960  $\\{app}(\\{break\_space})$;\5
  3961  $\\{app2}(\\{pp}+2)$;\5
  3962  $\\{app}(\.{"\ "})$;\5
  3963  $\\{app}(\\{cancel})$;\5
  3964  $\\{reduce}(\\{pp},\394,\39\\{clause},\39-2)(12)$;\6
  3965  \&{end}\6
  3966  \4\&{else} \&{begin} \37$\\{app2}(\\{pp})$;\5
  3967  $\\{app}(\\{break\_space})$;\5
  3968  $\\{app1}(\\{pp}+2)$;\5
  3969  $\\{app}(\\{cancel})$;\5
  3970  $\\{app}(\\{outdent})$;\5
  3971  $\\{app}(\\{force})$;\5
  3972  $\\{reduce}(\\{pp},\393,\39\\{stmt},\39-2)(13)$;\6
  3973  \&{end}\2\2\par
  3974  \U149.\fi
  3975  
  3976  \M157. \P$\X157:Cases for \\{elsie}\X\S$\6
  3977  $\\{squash}(\\{pp},\391,\39\\{intro},\39-3)(14)$\par
  3978  \U149.\fi
  3979  
  3980  \M158. \P$\X158:Cases for \\{exp}\X\S$\6
  3981  \&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\6
  3982  \&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{simp}$ \1\&{then}\6
  3983  \&{if} $\\{cat}[\\{pp}+3]\I\\{simp}$ \1\&{then}\6
  3984  \&{begin} \37$\\{app3}(\\{pp})$;\5
  3985  $\\{app}(\.{"\}"})$;\5
  3986  $\\{reduce}(\\{pp},\393,\39\\{math},\39-1)(15)$;\6
  3987  \&{end};\2\2\6
  3988  \&{end}\6
  3989  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\6
  3990  \&{if} $\\{cat}[\\{pp}+2]\I\\{simp}$ \1\&{then}\6
  3991  \&{begin} \37$\\{app2}(\\{pp})$;\5
  3992  $\\{app}(\.{"\}"})$;\5
  3993  $\\{reduce}(\\{pp},\392,\39\\{math},\39-1)(16)$;\6
  3994  \&{end}\2\2\2\par
  3995  \U149.\fi
  3996  
  3997  \M159. \P$\X159:Cases for \\{intro}\X\S$\6
  3998  \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
  3999  \&{begin} \37$\\{app1}(\\{pp})$;\5
  4000  $\\{app}(\.{"\ "})$;\5
  4001  $\\{app}(\\{opt})$;\5
  4002  $\\{app}(\.{"7"})$;\5
  4003  $\\{app}(\\{cancel})$;\5
  4004  $\\{app1}(\\{pp}+1)$;\5
  4005  $\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(17)$;\6
  4006  \&{end}\2\par
  4007  \U150.\fi
  4008  
  4009  \M160. \P$\X160:Cases for \\{math}\X\S$\6
  4010  \&{if} $\\{cat}[\\{pp}+1]=\\{close}$ \1\&{then}\6
  4011  \&{begin} \37$\\{app}(\.{"\$"})$;\5
  4012  $\\{app1}(\\{pp})$;\5
  4013  $\\{app}(\.{"\$"})$;\5
  4014  $\\{reduce}(\\{pp},\391,\39\\{stmt},\39-2)(18)$;\6
  4015  \&{end}\6
  4016  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{colon}$ \1\&{then}\6
  4017  \&{begin} \37$\\{app}(\\{force})$;\5
  4018  $\\{app}(\\{backup})$;\5
  4019  $\\{app}(\.{"\$"})$;\5
  4020  $\\{app1}(\\{pp})$;\5
  4021  $\\{app}(\.{"\$"})$;\5
  4022  $\\{app1}(\\{pp}+1)$;\5
  4023  $\\{reduce}(\\{pp},\392,\39\\{intro},\39-3)(19)$;\6
  4024  \&{end}\6
  4025  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\5
  4026  $\\{squash}(\\{pp},\392,\39\\{math},\39-1)(20)$\6
  4027  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\5
  4028  $\\{squash}(\\{pp},\392,\39\\{math},\39-1)(21)$\6
  4029  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
  4030  \&{begin} \37$\\{app}(\.{"\$"})$;\5
  4031  $\\{app1}(\\{pp})$;\5
  4032  $\\{app}(\.{"\$"})$;\5
  4033  $\\{app}(\\{indent})$;\5
  4034  $\\{app}(\\{break\_space})$;\5
  4035  $\\{app1}(\\{pp}+1)$;\5
  4036  $\\{app}(\\{cancel})$;\5
  4037  $\\{app}(\\{outdent})$;\5
  4038  $\\{app}(\\{force})$;\5
  4039  $\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(22)$;\6
  4040  \&{end}\6
  4041  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{terminator}$ \1\&{then}\6
  4042  \&{begin} \37$\\{app}(\.{"\$"})$;\5
  4043  $\\{app1}(\\{pp})$;\5
  4044  $\\{app}(\.{"\$"})$;\5
  4045  $\\{app1}(\\{pp}+1)$;\5
  4046  $\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(23)$;\6
  4047  \&{end}\2\2\2\2\2\2\par
  4048  \U150.\fi
  4049  
  4050  \M161. \P$\X161:Cases for \\{mod\_scrap}\X\S$\6
  4051  \&{if} $(\\{cat}[\\{pp}+1]=\\{terminator})\V(\\{cat}[\\{pp}+1]=\\{semi})$ \1%
  4052  \&{then}\6
  4053  \&{begin} \37$\\{app2}(\\{pp})$;\5
  4054  $\\{app}(\\{force})$;\5
  4055  $\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(24)$;\6
  4056  \&{end}\6
  4057  \4\&{else} $\\{squash}(\\{pp},\391,\39\\{simp},\39-2)(25)$\2\par
  4058  \U149.\fi
  4059  
  4060  \M162. \P$\X162:Cases for \\{open}\X\S$\6
  4061  \&{if} $(\\{cat}[\\{pp}+1]=\\{case\_head})\W(\\{cat}[\\{pp}+2]=\\{close})$ \1%
  4062  \&{then}\6
  4063  \&{begin} \37$\\{app1}(\\{pp})$;\5
  4064  $\\{app}(\.{"\$"})$;\5
  4065  $\\{app}(\\{cancel})$;\5
  4066  $\\{app1}(\\{pp}+1)$;\5
  4067  $\\{app}(\\{cancel})$;\5
  4068  $\\{app}(\\{outdent})$;\5
  4069  $\\{app}(\.{"\$"})$;\5
  4070  $\\{app1}(\\{pp}+2)$;\5
  4071  $\\{reduce}(\\{pp},\393,\39\\{math},\39-1)(26)$;\6
  4072  \&{end}\6
  4073  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{close}$ \1\&{then}\6
  4074  \&{begin} \37$\\{app1}(\\{pp})$;\5
  4075  $\\{app}(\.{"\\"})$;\5
  4076  $\\{app}(\.{","})$;\5
  4077  $\\{app1}(\\{pp}+1)$;\5
  4078  $\\{reduce}(\\{pp},\392,\39\\{math},\39-1)(27)$;\6
  4079  \&{end}\6
  4080  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\5
  4081  \X163:Cases for $\\{open}\,\\{math}$\X\6
  4082  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{proc}$ \1\&{then}\6
  4083  \&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{intro}$ \1\&{then}\6
  4084  \&{begin} \37$\\{app}(\\{math\_op})$;\5
  4085  $\\{app}(\\{cancel})$;\5
  4086  $\\{app1}(\\{pp}+1)$;\5
  4087  $\\{app}(\.{"\}"})$;\5
  4088  $\\{reduce}(\\{pp}+1,\392,\39\\{math},\390)(34)$;\6
  4089  \&{end};\2\6
  4090  \&{end}\6
  4091  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\5
  4092  $\\{squash}(\\{pp}+1,\391,\39\\{math},\390)(35)$\6
  4093  \4\&{else} \&{if} $(\\{cat}[\\{pp}+1]=\\{stmt})\W(\\{cat}[\\{pp}+2]=\\{close})$
  4094  \1\&{then}\6
  4095  \&{begin} \37$\\{app1}(\\{pp})$;\5
  4096  $\\{app}(\.{"\$"})$;\5
  4097  $\\{app}(\\{cancel})$;\5
  4098  $\\{app1}(\\{pp}+1)$;\5
  4099  $\\{app}(\\{cancel})$;\5
  4100  $\\{app}(\.{"\$"})$;\5
  4101  $\\{app1}(\\{pp}+2)$;\5
  4102  $\\{reduce}(\\{pp},\393,\39\\{math},\39-1)(36)$;\6
  4103  \&{end}\6
  4104  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{var\_head}$ \1\&{then}\6
  4105  \&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{intro}$ \1\&{then}\6
  4106  \&{begin} \37$\\{app}(\\{math\_op})$;\5
  4107  $\\{app}(\\{cancel})$;\5
  4108  $\\{app1}(\\{pp}+1)$;\5
  4109  $\\{app}(\.{"\}"})$;\5
  4110  $\\{reduce}(\\{pp}+1,\392,\39\\{math},\390)(37)$;\6
  4111  \&{end};\2\6
  4112  \&{end}\2\2\2\2\2\2\2\par
  4113  \U150.\fi
  4114  
  4115  \M163. \P$\X163:Cases for $\\{open}\,\\{math}$\X\S$\6
  4116  \&{begin} \37\&{if} $(\\{cat}[\\{pp}+2]=\\{case\_head})\W(\\{cat}[\\{pp}+3]=%
  4117  \\{close})$ \1\&{then}\6
  4118  \&{begin} \37$\\{app2}(\\{pp})$;\5
  4119  $\\{app}(\.{"\$"})$;\5
  4120  $\\{app}(\\{cancel})$;\5
  4121  $\\{app1}(\\{pp}+2)$;\5
  4122  $\\{app}(\\{cancel})$;\5
  4123  $\\{app}(\\{outdent})$;\5
  4124  $\\{app}(\.{"\$"})$;\5
  4125  $\\{app1}(\\{pp}+3)$;\5
  4126  $\\{reduce}(\\{pp},\394,\39\\{math},\39-1)(28)$;\6
  4127  \&{end}\6
  4128  \4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{close}$ \1\&{then}\5
  4129  $\\{squash}(\\{pp},\393,\39\\{math},\39-1)(29)$\6
  4130  \4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{colon}$ \1\&{then}\5
  4131  $\\{squash}(\\{pp}+1,\392,\39\\{math},\390)(30)$\6
  4132  \4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{proc}$ \1\&{then}\6
  4133  \&{begin} \37\&{if} $\\{cat}[\\{pp}+3]=\\{intro}$ \1\&{then}\6
  4134  \&{begin} \37$\\{app1}(\\{pp}+1)$;\5
  4135  $\\{app}(\\{math\_op})$;\5
  4136  $\\{app}(\\{cancel})$;\5
  4137  $\\{app1}(\\{pp}+2)$;\5
  4138  $\\{app}(\.{"\}"})$;\5
  4139  $\\{reduce}(\\{pp}+1,\393,\39\\{math},\390)(31)$;\6
  4140  \&{end};\2\6
  4141  \&{end}\6
  4142  \4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{semi}$ \1\&{then}\6
  4143  \&{begin} \37$\\{app2}(\\{pp}+1)$;\5
  4144  $\\{app}(\.{"\\"})$;\5
  4145  $\\{app}(\.{","})$;\5
  4146  $\\{app}(\\{opt})$;\5
  4147  $\\{app}(\.{"5"})$;\5
  4148  $\\{reduce}(\\{pp}+1,\392,\39\\{math},\390)(32)$;\6
  4149  \&{end}\6
  4150  \4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{var\_head}$ \1\&{then}\6
  4151  \&{begin} \37\&{if} $\\{cat}[\\{pp}+3]=\\{intro}$ \1\&{then}\6
  4152  \&{begin} \37$\\{app1}(\\{pp}+1)$;\5
  4153  $\\{app}(\\{math\_op})$;\5
  4154  $\\{app}(\\{cancel})$;\5
  4155  $\\{app1}(\\{pp}+2)$;\5
  4156  $\\{app}(\.{"\}"})$;\5
  4157  $\\{reduce}(\\{pp}+1,\393,\39\\{math},\390)(33)$;\6
  4158  \&{end};\2\6
  4159  \&{end};\2\2\2\2\2\2\6
  4160  \&{end}\par
  4161  \U162.\fi
  4162  
  4163  \M164. \P$\X164:Cases for \\{proc}\X\S$\6
  4164  \&{if} $\\{cat}[\\{pp}+1]=\\{beginning}$ \1\&{then}\6
  4165  \&{begin} \37\&{if} $(\\{cat}[\\{pp}+2]=\\{close})\W(\\{cat}[\\{pp}+3]=%
  4166  \\{terminator})$ \1\&{then}\6
  4167  \&{begin} \37$\\{app1}(\\{pp})$;\5
  4168  $\\{app}(\\{cancel})$;\5
  4169  $\\{app}(\\{outdent})$;\5
  4170  $\\{app3}(\\{pp}+1)$;\5
  4171  $\\{reduce}(\\{pp},\394,\39\\{stmt},\39-2)(38)$;\6
  4172  \&{end};\2\6
  4173  \&{end}\6
  4174  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
  4175  \&{begin} \37$\\{app1}(\\{pp})$;\5
  4176  $\\{app}(\\{break\_space})$;\5
  4177  $\\{app1}(\\{pp}+1)$;\5
  4178  $\\{reduce}(\\{pp},\392,\39\\{proc},\39-2)(39)$;\6
  4179  \&{end}\2\2\par
  4180  \U149.\fi
  4181  
  4182  \M165. \P$\X165:Cases for \\{record\_head}\X\S$\6
  4183  \&{if} $(\\{cat}[\\{pp}+1]=\\{intro})\W(\\{cat}[\\{pp}+2]=\\{casey})$ \1%
  4184  \&{then}\6
  4185  \&{begin} \37$\\{app2}(\\{pp})$;\5
  4186  $\\{app}(\.{"\ "})$;\5
  4187  $\\{app}(\\{cancel})$;\5
  4188  $\\{app1}(\\{pp}+2)$;\5
  4189  $\\{reduce}(\\{pp},\393,\39\\{casey},\39-2)(40)$;\6
  4190  \&{end}\6
  4191  \4\&{else} \&{begin} \37$\\{app}(\\{indent})$;\5
  4192  $\\{app1}(\\{pp})$;\5
  4193  $\\{app}(\\{cancel})$;\5
  4194  $\\{reduce}(\\{pp},\391,\39\\{case\_head},\390)(41)$;\6
  4195  \&{end}\2\par
  4196  \U149.\fi
  4197  
  4198  \M166. \P$\X166:Cases for \\{semi}\X\S$\6
  4199  $\\{squash}(\\{pp},\391,\39\\{terminator},\39-3)(42)$\par
  4200  \U149.\fi
  4201  
  4202  \M167. \P$\X167:Cases for \\{simp}\X\S$\6
  4203  \&{if} $\\{cat}[\\{pp}+1]=\\{close}$ \1\&{then}\5
  4204  $\\{squash}(\\{pp},\391,\39\\{stmt},\39-2)(43)$\6
  4205  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{colon}$ \1\&{then}\6
  4206  \&{begin} \37$\\{app}(\\{force})$;\5
  4207  $\\{app}(\\{backup})$;\5
  4208  $\\{app2}(\\{pp})$;\5
  4209  $\\{reduce}(\\{pp},\392,\39\\{intro},\39-3)(44)$;\6
  4210  \&{end}\6
  4211  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\5
  4212  $\\{squash}(\\{pp},\392,\39\\{math},\39-1)(45)$\6
  4213  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{mod\_scrap}$ \1\&{then}\5
  4214  $\\{squash}(\\{pp},\392,\39\\{mod\_scrap},\390)(46)$\6
  4215  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\5
  4216  $\\{squash}(\\{pp},\392,\39\\{simp},\39-2)(47)$\6
  4217  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{terminator}$ \1\&{then}\5
  4218  $\\{squash}(\\{pp},\392,\39\\{stmt},\39-2)(48)$\2\2\2\2\2\2\par
  4219  \U150.\fi
  4220  
  4221  \M168. \P$\X168:Cases for \\{stmt}\X\S$\6
  4222  \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
  4223  \&{begin} \37$\\{app1}(\\{pp})$;\5
  4224  $\\{app}(\\{break\_space})$;\5
  4225  $\\{app1}(\\{pp}+1)$;\5
  4226  $\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(49)$;\6
  4227  \&{end}\2\par
  4228  \U149.\fi
  4229  
  4230  \M169. \P$\X169:Cases for \\{terminator}\X\S$\6
  4231  $\\{squash}(\\{pp},\391,\39\\{stmt},\39-2)(50)$\par
  4232  \U149.\fi
  4233  
  4234  \M170. \P$\X170:Cases for \\{var\_head}\X\S$\6
  4235  \&{if} $\\{cat}[\\{pp}+1]=\\{beginning}$ \1\&{then}\5
  4236  $\\{squash}(\\{pp},\391,\39\\{stmt},\39-2)(51)$\6
  4237  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\6
  4238  \&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{colon}$ \1\&{then}\6
  4239  \&{begin} \37$\\{app}(\.{"\$"})$;\5
  4240  $\\{app1}(\\{pp}+1)$;\5
  4241  $\\{app}(\.{"\$"})$;\5
  4242  $\\{app1}(\\{pp}+2)$;\5
  4243  $\\{reduce}(\\{pp}+1,\392,\39\\{intro},\39+1)(52)$;\6
  4244  \&{end};\2\6
  4245  \&{end}\6
  4246  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\6
  4247  \&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{colon}$ \1\&{then}\5
  4248  $\\{squash}(\\{pp}+1,\392,\39\\{intro},\39+1)(53)$;\2\6
  4249  \&{end}\6
  4250  \4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
  4251  \&{begin} \37$\\{app1}(\\{pp})$;\5
  4252  $\\{app}(\\{break\_space})$;\5
  4253  $\\{app1}(\\{pp}+1)$;\5
  4254  $\\{reduce}(\\{pp},\392,\39\\{var\_head},\39-2)(54)$;\6
  4255  \&{end}\2\2\2\2\par
  4256  \U149.\fi
  4257  
  4258  \M171. The `\\{freeze\_text}' macro is used to give official status to a token
  4259  list.
  4260  Before saying \\{freeze\_text}, items are appended to the current token list,
  4261  and we know that the eventual number of this token list will be the current
  4262  value of \\{text\_ptr}. But no list of that number really exists as yet,
  4263  because no ending point for the current list has been
  4264  stored in the \\{tok\_start} array. After saying \\{freeze\_text}, the
  4265  old current token list becomes legitimate, and its number is the current
  4266  value of $\\{text\_ptr}-1$ since \\{text\_ptr} has been increased. The new
  4267  current token list is empty and ready to be appended to.
  4268  Note that \\{freeze\_text} does not check to see that \\{text\_ptr} hasn't
  4269  gotten
  4270  too large, since it is assumed that this test was done beforehand.
  4271  
  4272  \Y\P\D \37$\\{freeze\_text}\S\\{incr}(\\{text\_ptr})$;\5
  4273  $\\{tok\_start}[\\{text\_ptr}]\K\\{tok\_ptr}$\par
  4274  \fi
  4275  
  4276  \M172. The `\\{reduce}' macro used in our code for productions actually calls
  4277  on
  4278  a procedure named `\\{red}', which makes the appropriate changes to the
  4279  scrap list.
  4280  
  4281  \Y\P\4\&{procedure}\1\  \37$\\{red}(\|j:\\{sixteen\_bits};\,\35\|k:\\{eight%
  4282  \_bits};\,\35\|c:\\{eight\_bits};\,\35\|d:\\{integer})$;\6
  4283  \4\&{var} \37\|i: \37$0\to\\{max\_scraps}$;\C{index into scrap memory}\2\6
  4284  \&{begin} \37$\\{cat}[\|j]\K\|c$;\5
  4285  $\\{trans}[\|j]\K\\{text\_ptr}$;\5
  4286  \\{freeze\_text};\6
  4287  \&{if} $\|k>1$ \1\&{then}\6
  4288  \&{begin} \37\&{for} $\|i\K\|j+\|k\mathrel{\&{to}}\\{lo\_ptr}$ \1\&{do}\6
  4289  \&{begin} \37$\\{cat}[\|i-\|k+1]\K\\{cat}[\|i]$;\5
  4290  $\\{trans}[\|i-\|k+1]\K\\{trans}[\|i]$;\6
  4291  \&{end};\2\6
  4292  $\\{lo\_ptr}\K\\{lo\_ptr}-\|k+1$;\6
  4293  \&{end};\2\6
  4294  \X173:Change \\{pp} to $\max(\\{scrap\_base},$\\{pp}+\|d$)$\X;\6
  4295  \&{end};\par
  4296  \fi
  4297  
  4298  \M173. \P$\X173:Change \\{pp} to $\max(\\{scrap\_base},$\\{pp}+\|d$)$\X\S$\6
  4299  \&{if} $\\{pp}+\|d\G\\{scrap\_base}$ \1\&{then}\5
  4300  $\\{pp}\K\\{pp}+\|d$\6
  4301  \4\&{else} $\\{pp}\K\\{scrap\_base}$\2\par
  4302  \Us172\ET174.\fi
  4303  
  4304  \M174. Similarly, the `\\{squash}' macro invokes a procedure called `\\{sq}'.
  4305  This
  4306  procedure takes advantage of the simplification that occurs when $\|k=1$.
  4307  
  4308  \Y\P\4\&{procedure}\1\  \37$\\{sq}(\|j:\\{sixteen\_bits};\,\35\|k:\\{eight%
  4309  \_bits};\,\35\|c:\\{eight\_bits};\,\35\|d:\\{integer})$;\6
  4310  \4\&{var} \37\|i: \37$0\to\\{max\_scraps}$;\C{index into scrap memory}\2\6
  4311  \&{begin} \37\&{if} $\|k=1$ \1\&{then}\6
  4312  \&{begin} \37$\\{cat}[\|j]\K\|c$;\5
  4313  \X173:Change \\{pp} to $\max(\\{scrap\_base},$\\{pp}+\|d$)$\X;\6
  4314  \&{end}\6
  4315  \4\&{else} \&{begin} \37\&{for} $\|i\K\|j\mathrel{\&{to}}\|j+\|k-1$ \1\&{do}\6
  4316  \&{begin} \37$\\{app1}(\|i)$;\6
  4317  \&{end};\2\6
  4318  $\\{red}(\|j,\39\|k,\39\|c,\39\|d)$;\6
  4319  \&{end};\2\6
  4320  \&{end};\par
  4321  \fi
  4322  
  4323  \M175. Here now is the code that applies productions as long as possible. It
  4324  requires two local labels (\\{found} and \\{done}), as well as a local
  4325  variable (\|i).
  4326  
  4327  \Y\P$\4\X175:Reduce the scraps using the productions until no more rules apply%
  4328  \X\S$\6
  4329  \~ \1\&{loop}\ \&{begin} \37\X176:Make sure the entries $\\{cat}[\\{pp}\to(%
  4330  \\{pp}+3)]$ are defined\X;\6
  4331  \&{if} $(\\{tok\_ptr}+8>\\{max\_toks})\V(\\{text\_ptr}+4>\\{max\_texts})$ \1%
  4332  \&{then}\6
  4333  \&{begin} \37\&{stat} \37\&{if} $\\{tok\_ptr}>\\{max\_tok\_ptr}$ \1\&{then}\5
  4334  $\\{max\_tok\_ptr}\K\\{tok\_ptr}$;\2\6
  4335  \&{if} $\\{text\_ptr}>\\{max\_txt\_ptr}$ \1\&{then}\5
  4336  $\\{max\_txt\_ptr}\K\\{text\_ptr}$;\2\6
  4337  \&{tats}\6
  4338  $\\{overflow}(\.{\'token/text\'})$;\6
  4339  \&{end};\2\6
  4340  \&{if} $\\{pp}>\\{lo\_ptr}$ \1\&{then}\5
  4341  \&{goto} \37\\{done};\2\6
  4342  \X149:Match a production at \\{pp}, or increase \\{pp} if there is no match\X;\6
  4343  \&{end};\2\6
  4344  \4\\{done}: \37\par
  4345  \U179.\fi
  4346  
  4347  \M176. If we get to the end of the scrap list, category codes equal to zero are
  4348  stored, since zero does not match anything in a production.
  4349  
  4350  \Y\P$\4\X176:Make sure the entries $\\{cat}[\\{pp}\to(\\{pp}+3)]$ are defined\X%
  4351  \S$\6
  4352  \&{if} $\\{lo\_ptr}<\\{pp}+3$ \1\&{then}\6
  4353  \&{begin} \37\1\&{repeat} \37\&{if} $\\{hi\_ptr}\L\\{scrap\_ptr}$ \1\&{then}\6
  4354  \&{begin} \37$\\{incr}(\\{lo\_ptr})$;\6
  4355  $\\{cat}[\\{lo\_ptr}]\K\\{cat}[\\{hi\_ptr}]$;\5
  4356  $\\{trans}[\\{lo\_ptr}]\K\\{trans}[\\{hi\_ptr}]$;\6
  4357  $\\{incr}(\\{hi\_ptr})$;\6
  4358  \&{end};\2\6
  4359  \4\&{until}\5
  4360  $(\\{hi\_ptr}>\\{scrap\_ptr})\V(\\{lo\_ptr}=\\{pp}+3)$;\2\6
  4361  \&{for} $\|i\K\\{lo\_ptr}+1\mathrel{\&{to}}\\{pp}+3$ \1\&{do}\5
  4362  $\\{cat}[\|i]\K0$;\2\6
  4363  \&{end}\2\par
  4364  \U175.\fi
  4365  
  4366  \M177. If \.{WEAVE} is being run in debugging mode, the production numbers and
  4367  current stack categories will be printed out when \\{tracing} is set to 2;
  4368  a sequence of two or more irreducible scraps will be printed out when
  4369  \\{tracing} is set to 1.
  4370  
  4371  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  4372  \&{debug} \37\\{tracing}: \37$0\to2$;\C{can be used to show parsing details}\6
  4373  \&{gubed}\par
  4374  \fi
  4375  
  4376  \M178. The \\{prod} procedure is called in debugging mode just after \\{reduce}
  4377  or
  4378  \\{squash}; its parameter is the number of the production that has just
  4379  been applied.
  4380  
  4381  \Y\P\&{debug} \37\&{procedure}\1\  \37$\\{prod}(\|n:\\{eight\_bits})$;\C{shows
  4382  current categories}\6
  4383  \4\&{var} \37\|k: \37$1\to\\{max\_scraps}$;\C{index into \\{cat}}\2\6
  4384  \&{begin} \37\&{if} $\\{tracing}=2$ \1\&{then}\6
  4385  \&{begin} \37$\\{print\_nl}(\|n:1,\39\.{\':\'})$;\6
  4386  \&{for} $\|k\K\\{scrap\_base}\mathrel{\&{to}}\\{lo\_ptr}$ \1\&{do}\6
  4387  \&{begin} \37\&{if} $\|k=\\{pp}$ \1\&{then}\5
  4388  $\\{print}(\.{\'*\'})$\ \&{else} $\\{print}(\.{\'\ \'})$;\2\6
  4389  $\\{print\_cat}(\\{cat}[\|k])$;\6
  4390  \&{end};\2\6
  4391  \&{if} $\\{hi\_ptr}\L\\{scrap\_ptr}$ \1\&{then}\5
  4392  $\\{print}(\.{\'...\'})$;\C{indicate that more is coming}\2\6
  4393  \&{end};\2\6
  4394  \&{end};\6
  4395  \&{gubed}\par
  4396  \fi
  4397  
  4398  \M179. The \\{translate} function assumes that scraps have been stored in
  4399  positions \\{scrap\_base} through \\{scrap\_ptr} of \\{cat} and \\{trans}. It
  4400  appends a \\{terminator} scrap and begins to apply productions as much as
  4401  possible. The result is a token list containing the translation of
  4402  the given sequence of scraps.
  4403  
  4404  After calling \\{translate}, we will have $\\{text\_ptr}+3\L\\{max\_texts}$ and
  4405  $\\{tok\_ptr}+6\L\\{max\_toks}$, so it will be possible to create up to three
  4406  token
  4407  lists with up to six tokens without checking for overflow. Before calling
  4408  \\{translate}, we should have $\\{text\_ptr}<\\{max\_texts}$ and $\\{scrap%
  4409  \_ptr}<\\{max\_scraps}$,
  4410  since \\{translate} might add a new text and a new scrap before it checks
  4411  for overflow.
  4412  
  4413  \Y\P\X150:Declaration of subprocedures for \\{translate}\X\6
  4414  \4\&{function}\1\  \37\\{translate}: \37\\{text\_pointer};\C{converts a
  4415  sequence of scraps}\6
  4416  \4\&{label} \37$\\{done},\39\\{found}$;\6
  4417  \4\&{var} \37\|i: \37$1\to\\{max\_scraps}$;\C{index into \\{cat}}\6
  4418  \|j: \37$0\to\\{max\_scraps}$;\C{runs through final scraps}\6
  4419  \&{debug} \37\|k: \37$0\to\\{long\_buf\_size}$;\C{index into \\{buffer}}\6
  4420  \&{gubed}\6
  4421  \&{begin} \37$\\{pp}\K\\{scrap\_base}$;\5
  4422  $\\{lo\_ptr}\K\\{pp}-1$;\5
  4423  $\\{hi\_ptr}\K\\{pp}$;\5
  4424  \X182:If tracing, print an indication of where we are\X;\6
  4425  \X175:Reduce the scraps using the productions until no more rules apply\X;\6
  4426  \&{if} $(\\{lo\_ptr}=\\{scrap\_base})\W(\\{cat}[\\{lo\_ptr}]\I\\{math})$ \1%
  4427  \&{then}\5
  4428  $\\{translate}\K\\{trans}[\\{lo\_ptr}]$\6
  4429  \4\&{else} \X180:Combine the irreducible scraps that remain\X;\2\6
  4430  \&{end};\par
  4431  \fi
  4432  
  4433  \M180. If the initial sequence of scraps does not reduce to a single scrap,
  4434  we concatenate the translations of all remaining scraps, separated by
  4435  blank spaces, with dollar signs surrounding the translations of \\{math}
  4436  scraps.
  4437  
  4438  \Y\P$\4\X180:Combine the irreducible scraps that remain\X\S$\6
  4439  \&{begin} \37\X181:If semi-tracing, show the irreducible scraps\X;\6
  4440  \&{for} $\|j\K\\{scrap\_base}\mathrel{\&{to}}\\{lo\_ptr}$ \1\&{do}\6
  4441  \&{begin} \37\&{if} $\|j\I\\{scrap\_base}$ \1\&{then}\6
  4442  \&{begin} \37$\\{app}(\.{"\ "})$;\6
  4443  \&{end};\2\6
  4444  \&{if} $\\{cat}[\|j]=\\{math}$ \1\&{then}\6
  4445  \&{begin} \37$\\{app}(\.{"\$"})$;\6
  4446  \&{end};\2\6
  4447  $\\{app1}(\|j)$;\6
  4448  \&{if} $\\{cat}[\|j]=\\{math}$ \1\&{then}\6
  4449  \&{begin} \37$\\{app}(\.{"\$"})$;\6
  4450  \&{end};\2\6
  4451  \&{if} $\\{tok\_ptr}+6>\\{max\_toks}$ \1\&{then}\5
  4452  $\\{overflow}(\.{\'token\'})$;\2\6
  4453  \&{end};\2\6
  4454  \\{freeze\_text};\5
  4455  $\\{translate}\K\\{text\_ptr}-1$;\6
  4456  \&{end}\par
  4457  \U179.\fi
  4458  
  4459  \M181. \P$\X181:If semi-tracing, show the irreducible scraps\X\S$\6
  4460  \&{debug} \37\&{if} $(\\{lo\_ptr}>\\{scrap\_base})\W(\\{tracing}=1)$ \1\&{then}%
  4461  \6
  4462  \&{begin} \37$\\{print\_nl}(\.{\'Irreducible\ scrap\ sequence\ in\ section\ %
  4463  \'},\39\\{module\_count}:1)$;\5
  4464  $\\{print\_ln}(\.{\':\'})$;\5
  4465  \\{mark\_harmless};\6
  4466  \&{for} $\|j\K\\{scrap\_base}\mathrel{\&{to}}\\{lo\_ptr}$ \1\&{do}\6
  4467  \&{begin} \37$\\{print}(\.{\'\ \'})$;\5
  4468  $\\{print\_cat}(\\{cat}[\|j])$;\6
  4469  \&{end};\2\6
  4470  \&{end};\2\6
  4471  \&{gubed}\par
  4472  \U180.\fi
  4473  
  4474  \M182. \P$\X182:If tracing, print an indication of where we are\X\S$\6
  4475  \&{debug} \37\&{if} $\\{tracing}=2$ \1\&{then}\6
  4476  \&{begin} \37$\\{print\_nl}(\.{\'Tracing\ after\ l.\'},\39\\{line}:1,\39\.{\':%
  4477  \'})$;\5
  4478  \\{mark\_harmless};\6
  4479  \&{if} $\\{loc}>50$ \1\&{then}\6
  4480  \&{begin} \37$\\{print}(\.{\'...\'})$;\6
  4481  \&{for} $\|k\K\\{loc}-50\mathrel{\&{to}}\\{loc}$ \1\&{do}\5
  4482  $\\{print}(\\{xchr}[\\{buffer}[\|k-1]])$;\2\6
  4483  \&{end}\6
  4484  \4\&{else} \&{for} $\|k\K1\mathrel{\&{to}}\\{loc}$ \1\&{do}\5
  4485  $\\{print}(\\{xchr}[\\{buffer}[\|k-1]])$;\2\2\6
  4486  \&{end}\2\6
  4487  \&{gubed}\par
  4488  \U179.\fi
  4489  
  4490  \N183.  Initializing the scraps.
  4491  If we are going to use the powerful production mechanism just developed, we
  4492  must get the scraps set up in the first place, given a \PASCAL\ text. A table
  4493  of the initial scraps corresponding to \PASCAL\ tokens appeared above in the
  4494  section on parsing; our goal now is to implement that table. We shall do this
  4495  by implementing a subroutine called \\{Pascal\_parse} that is analogous to the
  4496  \\{Pascal\_xref} routine used during phase one.
  4497  
  4498  Like \\{Pascal\_xref}, the \\{Pascal\_parse} procedure starts with the current
  4499  value of \\{next\_control} and it uses the operation $\\{next\_control}\K\\{get%
  4500  \_next}$
  4501  repeatedly to read \PASCAL\ text until encountering the next `\v' or
  4502  `\.\{', or until $\\{next\_control}\G\\{format}$. The scraps corresponding to
  4503  what
  4504  it reads are appended into the \\{cat} and \\{trans} arrays, and \\{scrap\_ptr}
  4505  is advanced.
  4506  
  4507  Like \\{prod}, this procedure has to split into pieces so that each
  4508  part is short enough to be handled by \PASCAL\ compilers that discriminate
  4509  against long subroutines. This time there are two split-off routines,
  4510  called \\{easy\_cases} and \\{sub\_cases}.
  4511  
  4512  After studying \\{Pascal\_parse}, we will look at the sub-procedures
  4513  \\{app\_comment}, \\{app\_octal}, and \\{app\_hex} that are used in some of its
  4514  branches.
  4515  
  4516  \Y\P\X195:Declaration of the \\{app\_comment} procedure\X\6
  4517  \X196:Declaration of the \\{app\_octal} and \\{app\_hex} procedures\X\6
  4518  \X186:Declaration of the \\{easy\_cases} procedure\X\6
  4519  \X192:Declaration of the \\{sub\_cases} procedure\X\6
  4520  \4\&{procedure}\1\  \37\\{Pascal\_parse};\C{creates scraps from \PASCAL\
  4521  tokens}\6
  4522  \4\&{label} \37$\\{reswitch},\39\\{exit}$;\6
  4523  \4\&{var} \37\|j: \37$0\to\\{long\_buf\_size}$;\C{index into \\{buffer}}\6
  4524  \|p: \37\\{name\_pointer};\C{identifier designator}\2\6
  4525  \&{begin} \37\&{while} $\\{next\_control}<\\{format}$ \1\&{do}\6
  4526  \&{begin} \37\X185:Append the scrap appropriate to \\{next\_control}\X;\6
  4527  $\\{next\_control}\K\\{get\_next}$;\6
  4528  \&{if} $(\\{next\_control}=\.{"|"})\V(\\{next\_control}=\.{"\{"})$ \1\&{then}\5
  4529  \&{return};\2\6
  4530  \&{end};\2\6
  4531  \4\\{exit}: \37\&{end};\par
  4532  \fi
  4533  
  4534  \M184. The macros defined here are helpful abbreviations for the operations
  4535  needed when generating the scraps. A scrap of category \|c whose
  4536  translation has three tokens $t_1$, $t_2$, $t_3$ is generated by
  4537  \\{sc3}$(t_1)(t_2)(t_3)(c)$, etc.
  4538  
  4539  \Y\P\D \37$\\{s0}(\#)\S\\{incr}(\\{scrap\_ptr})$;\5
  4540  $\\{cat}[\\{scrap\_ptr}]\K\#$;\5
  4541  $\\{trans}[\\{scrap\_ptr}]\K\\{text\_ptr}$;\5
  4542  \\{freeze\_text}; \6
  4543  \&{end} \par
  4544  \P\D \37$\\{s1}(\#)\S\\{app}(\#)$;\5
  4545  \\{s0}\par
  4546  \P\D \37$\\{s2}(\#)\S\\{app}(\#)$;\5
  4547  \\{s1}\par
  4548  \P\D \37$\\{s3}(\#)\S\\{app}(\#)$;\5
  4549  \\{s2}\par
  4550  \P\D \37$\\{s4}(\#)\S\\{app}(\#)$;\5
  4551  \\{s3}\par
  4552  \P\D \37$\\{sc4}\S$\ \&{begin} \37\\{s4}\par
  4553  \P\D \37$\\{sc3}\S$\ \&{begin} \37\\{s3}\par
  4554  \P\D \37$\\{sc2}\S$\ \&{begin} \37\\{s2}\par
  4555  \P\D \37$\\{sc1}\S$\ \&{begin} \37\\{s1}\par
  4556  \P\D \37$\\{sc0}(\#)\S$\1\6
  4557  \&{begin} \37$\\{incr}(\\{scrap\_ptr})$;\5
  4558  $\\{cat}[\\{scrap\_ptr}]\K\#$;\5
  4559  $\\{trans}[\\{scrap\_ptr}]\K0$;\6
  4560  \&{end}\2\par
  4561  \P\D \37$\\{comment\_scrap}(\#)\S$\1\6
  4562  \&{begin} \37$\\{app}(\#)$;\5
  4563  \\{app\_comment};\6
  4564  \&{end}\2\par
  4565  \fi
  4566  
  4567  \M185. \P$\X185:Append the scrap appropriate to \\{next\_control}\X\S$\6
  4568  \X187:Make sure that there is room for at least four more scraps, six more
  4569  tokens, and four more texts\X;\6
  4570  \4\\{reswitch}: \37\&{case} $\\{next\_control}$ \1\&{of}\6
  4571  \4$\\{string},\39\\{verbatim}$: \37\X189:Append a \(string scrap\X;\6
  4572  \4\\{identifier}: \37\X191:Append an identifier scrap\X;\6
  4573  \4\\{TeX\_string}: \37\X190:Append a \TeX\ string scrap\X;\6
  4574  \4\&{othercases} \37\\{easy\_cases}\2\6
  4575  \&{endcases}\par
  4576  \U183.\fi
  4577  
  4578  \M186. The \\{easy\_cases} each result in straightforward scraps.
  4579  
  4580  \Y\P$\4\X186:Declaration of the \\{easy\_cases} procedure\X\S$\6
  4581  \4\&{procedure}\1\  \37\\{easy\_cases};\C{a subprocedure of \\{Pascal\_parse}}%
  4582  \2\6
  4583  \&{begin} \37\&{case} $\\{next\_control}$ \1\&{of}\6
  4584  \4\\{set\_element\_sign}: \37$\\{sc3}(\.{"\\"})(\.{"i"})(\.{"n"})(\\{math})$;\6
  4585  \4\\{double\_dot}: \37$\\{sc3}(\.{"\\"})(\.{"t"})(\.{"o"})(\\{math})$;\6
  4586  \4$\.{"\#"},\39\.{"\$"},\39\.{"\%"},\39\.{"\^"},\39\.{"\_"}$: \37$\\{sc2}(\.{"%
  4587  \\"})(\\{next\_control})(\\{math})$;\6
  4588  \4$\\{ignore},\39\.{"|"},\39\\{xref\_roman},\39\\{xref\_wildcard},\39\\{xref%
  4589  \_typewriter}$: \37\\{do\_nothing};\6
  4590  \4$\.{"("},\39\.{"["}$: \37$\\{sc1}(\\{next\_control})(\\{open})$;\6
  4591  \4$\.{")"},\39\.{"]"}$: \37$\\{sc1}(\\{next\_control})(\\{close})$;\6
  4592  \4\.{"*"}: \37$\\{sc4}(\.{"\\"})(\.{"a"})(\.{"s"})(\.{"t"})(\\{math})$;\6
  4593  \4\.{","}: \37$\\{sc3}(\.{","})(\\{opt})(\.{"9"})(\\{math})$;\6
  4594  \4$\.{"."},\39\.{"0"},\39\.{"1"},\39\.{"2"},\39\.{"3"},\39\.{"4"},\39\.{"5"},%
  4595  \39\.{"6"},\39\.{"7"},\39\.{"8"},\39\.{"9"}$: \37$\\{sc1}(\\{next\_control})(%
  4596  \\{simp})$;\6
  4597  \4\.{";"}: \37$\\{sc1}(\.{";"})(\\{semi})$;\6
  4598  \4\.{":"}: \37$\\{sc1}(\.{":"})(\\{colon})$;\6
  4599  \hbox{\4}\X188:Cases involving nonstandard ASCII characters\X\6
  4600  \4\\{exponent}: \37$\\{sc3}(\.{"\\"})(\.{"E"})(\.{"\{"})(\\{exp})$;\6
  4601  \4\\{begin\_comment}: \37$\\{sc2}(\.{"\\"})(\.{"B"})(\\{math})$;\6
  4602  \4\\{end\_comment}: \37$\\{sc2}(\.{"\\"})(\.{"T"})(\\{math})$;\6
  4603  \4\\{octal}: \37\\{app\_octal};\6
  4604  \4\\{hex}: \37\\{app\_hex};\6
  4605  \4\\{check\_sum}: \37$\\{sc2}(\.{"\\"})(\.{")"})(\\{simp})$;\6
  4606  \4\\{force\_line}: \37$\\{sc2}(\.{"\\"})(\.{"]"})(\\{simp})$;\6
  4607  \4\\{thin\_space}: \37$\\{sc2}(\.{"\\"})(\.{","})(\\{math})$;\6
  4608  \4\\{math\_break}: \37$\\{sc2}(\\{opt})(\.{"0"})(\\{simp})$;\6
  4609  \4\\{line\_break}: \37$\\{comment\_scrap}(\\{force})$;\6
  4610  \4\\{big\_line\_break}: \37$\\{comment\_scrap}(\\{big\_force})$;\6
  4611  \4\\{no\_line\_break}: \37\&{begin} \37$\\{app}(\\{big\_cancel})$;\5
  4612  $\\{app}(\.{"\\"})$;\5
  4613  $\\{app}(\.{"\ "})$;\5
  4614  $\\{comment\_scrap}(\\{big\_cancel})$;\6
  4615  \&{end};\6
  4616  \4\\{pseudo\_semi}: \37$\\{sc0}(\\{semi})$;\6
  4617  \4\\{join}: \37$\\{sc2}(\.{"\\"})(\.{"J"})(\\{math})$;\6
  4618  \4\&{othercases} \37$\\{sc1}(\\{next\_control})(\\{math})$\2\6
  4619  \&{endcases};\6
  4620  \&{end};\par
  4621  \U183.\fi
  4622  
  4623  \M187. \P$\X187:Make sure that there is room for at least four more scraps, six
  4624  more tokens, and four more texts\X\S$\6
  4625  \&{if} $(\\{scrap\_ptr}+4>\\{max\_scraps})\V(\\{tok\_ptr}+6>\\{max\_toks})\V(%
  4626  \\{text\_ptr}+4>\\{max\_texts})$ \1\&{then}\6
  4627  \&{begin} \37\&{stat} \37\&{if} $\\{scrap\_ptr}>\\{max\_scr\_ptr}$ \1\&{then}\5
  4628  $\\{max\_scr\_ptr}\K\\{scrap\_ptr}$;\2\6
  4629  \&{if} $\\{tok\_ptr}>\\{max\_tok\_ptr}$ \1\&{then}\5
  4630  $\\{max\_tok\_ptr}\K\\{tok\_ptr}$;\2\6
  4631  \&{if} $\\{text\_ptr}>\\{max\_txt\_ptr}$ \1\&{then}\5
  4632  $\\{max\_txt\_ptr}\K\\{text\_ptr}$;\2\6
  4633  \&{tats}\6
  4634  $\\{overflow}(\.{\'scrap/token/text\'})$;\6
  4635  \&{end}\2\par
  4636  \U185.\fi
  4637  
  4638  \M188. Some nonstandard ASCII characters may have entered \.{WEAVE} by means of
  4639  standard ones. They are converted to \TeX\ control sequences so that it is
  4640  possible to keep \.{WEAVE} from stepping beyond standard ASCII.
  4641  
  4642  \Y\P$\4\X188:Cases involving nonstandard ASCII characters\X\S$\6
  4643  \4\\{not\_equal}: \37$\\{sc2}(\.{"\\"})(\.{"I"})(\\{math})$;\6
  4644  \4\\{less\_or\_equal}: \37$\\{sc2}(\.{"\\"})(\.{"L"})(\\{math})$;\6
  4645  \4\\{greater\_or\_equal}: \37$\\{sc2}(\.{"\\"})(\.{"G"})(\\{math})$;\6
  4646  \4\\{equivalence\_sign}: \37$\\{sc2}(\.{"\\"})(\.{"S"})(\\{math})$;\6
  4647  \4\\{and\_sign}: \37$\\{sc2}(\.{"\\"})(\.{"W"})(\\{math})$;\6
  4648  \4\\{or\_sign}: \37$\\{sc2}(\.{"\\"})(\.{"V"})(\\{math})$;\6
  4649  \4\\{not\_sign}: \37$\\{sc2}(\.{"\\"})(\.{"R"})(\\{math})$;\6
  4650  \4\\{left\_arrow}: \37$\\{sc2}(\.{"\\"})(\.{"K"})(\\{math})$;\par
  4651  \U186.\fi
  4652  
  4653  \M189. The following code must use \\{app\_tok} instead of \\{app} in order to
  4654  protect against overflow. Note that $\\{tok\_ptr}+1\L\\{max\_toks}$ after %
  4655  \\{app\_tok}
  4656  has been used, so another \\{app} is legitimate before testing again.
  4657  
  4658  Many of the special characters in a string must be prefixed by `\.\\' so that
  4659  \TeX\ will print them properly.
  4660  
  4661  \Y\P$\4\X189:Append a \(string scrap\X\S$\6
  4662  \&{begin} \37$\\{app}(\.{"\\"})$;\6
  4663  \&{if} $\\{next\_control}=\\{verbatim}$ \1\&{then}\6
  4664  \&{begin} \37$\\{app}(\.{"="})$;\6
  4665  \&{end}\6
  4666  \4\&{else} \&{begin} \37$\\{app}(\.{"."})$;\6
  4667  \&{end};\2\6
  4668  $\\{app}(\.{"\{"})$;\5
  4669  $\|j\K\\{id\_first}$;\6
  4670  \&{while} $\|j<\\{id\_loc}$ \1\&{do}\6
  4671  \&{begin} \37\&{case} $\\{buffer}[\|j]$ \1\&{of}\6
  4672  \4$\.{"\ "},\39\.{"\\"},\39\.{"\#"},\39\.{"\%"},\39\.{"\$"},\39\.{"\^"},\39\.{"%
  4673  \'"},\39\.{"\`"},\39\.{"\{"},\39\.{"\}"},\39\.{"\~"},\39\.{"\&"},\39\.{"\_"}$: %
  4674  \37\&{begin} \37$\\{app}(\.{"\\"})$;\6
  4675  \&{end};\6
  4676  \4\.{"@"}: \37\&{if} $\\{buffer}[\|j+1]=\.{"@"}$ \1\&{then}\5
  4677  $\\{incr}(\|j)$\6
  4678  \4\&{else} $\\{err\_print}(\.{\'!\ Double\ @\ should\ be\ used\ in\ strings%
  4679  \'})$;\2\6
  4680  \4\&{othercases} \37\\{do\_nothing}\2\6
  4681  \&{endcases};\6
  4682  $\\{app\_tok}(\\{buffer}[\|j])$;\5
  4683  $\\{incr}(\|j)$;\6
  4684  \&{end};\2\6
  4685  $\\{sc1}(\.{"\}"})(\\{simp})$;\6
  4686  \&{end}\par
  4687  \U185.\fi
  4688  
  4689  \M190. \P$\X190:Append a \TeX\ string scrap\X\S$\6
  4690  \&{begin} \37$\\{app}(\.{"\\"})$;\5
  4691  $\\{app}(\.{"h"})$;\5
  4692  $\\{app}(\.{"b"})$;\5
  4693  $\\{app}(\.{"o"})$;\5
  4694  $\\{app}(\.{"x"})$;\5
  4695  $\\{app}(\.{"\{"})$;\6
  4696  \&{for} $\|j\K\\{id\_first}\mathrel{\&{to}}\\{id\_loc}-1$ \1\&{do}\5
  4697  $\\{app\_tok}(\\{buffer}[\|j])$;\2\6
  4698  $\\{sc1}(\.{"\}"})(\\{simp})$;\6
  4699  \&{end}\par
  4700  \U185.\fi
  4701  
  4702  \M191. \P$\X191:Append an identifier scrap\X\S$\6
  4703  \&{begin} \37$\|p\K\\{id\_lookup}(\\{normal})$;\6
  4704  \&{case} $\\{ilk}[\|p]$ \1\&{of}\6
  4705  \4$\\{normal},\39\\{array\_like},\39\\{const\_like},\39\\{div\_like},\39\\{do%
  4706  \_like},\39\\{for\_like},\39\\{goto\_like},\39\\{nil\_like},\39\\{to\_like}$: %
  4707  \37$\\{sub\_cases}(\|p)$;\6
  4708  \hbox{\4}\X193:Cases that generate more than one scrap\X\6
  4709  \4\&{othercases} \37\&{begin} \37$\\{next\_control}\K\\{ilk}[\|p]-\\{char%
  4710  \_like}$;\5
  4711  \&{goto} \37\\{reswitch};\6
  4712  \&{end}\C{\&{and}, \&{in}, \&{not}, \&{or}}\2\6
  4713  \&{endcases};\6
  4714  \&{end}\par
  4715  \U185.\fi
  4716  
  4717  \M192. The \\{sub\_cases} also result in straightforward scraps.
  4718  
  4719  \Y\P$\4\X192:Declaration of the \\{sub\_cases} procedure\X\S$\6
  4720  \4\&{procedure}\1\  \37$\\{sub\_cases}(\|p:\\{name\_pointer})$;\C{a
  4721  subprocedure of \\{Pascal\_parse}}\2\6
  4722  \&{begin} \37\&{case} $\\{ilk}[\|p]$ \1\&{of}\6
  4723  \4\\{normal}: \37$\\{sc1}(\\{id\_flag}+\|p)(\\{simp})$;\C{not a reserved word}\6
  4724  \4\\{array\_like}: \37$\\{sc1}(\\{res\_flag}+\|p)(\\{alpha})$;\C{\&{array}, %
  4725  \&{file}, \&{set}}\6
  4726  \4\\{const\_like}: \37$\\{sc3}(\\{force})(\\{backup})(\\{res\_flag}+\|p)(%
  4727  \\{intro})$;\C{\&{const}, \&{label}, \&{type}}\6
  4728  \4\\{div\_like}: \37$\\{sc3}(\\{math\_bin})(\\{res\_flag}+\|p)(\.{"\}"})(%
  4729  \\{math})$;\C{\&{div}, \&{mod}}\6
  4730  \4\\{do\_like}: \37$\\{sc1}(\\{res\_flag}+\|p)(\\{omega})$;\C{\&{do}, \&{of}, %
  4731  \&{then}}\6
  4732  \4\\{for\_like}: \37$\\{sc2}(\\{force})(\\{res\_flag}+\|p)(\\{alpha})$;\C{%
  4733  \&{for}, \&{while}, \&{with}}\6
  4734  \4\\{goto\_like}: \37$\\{sc1}(\\{res\_flag}+\|p)(\\{intro})$;\C{\&{goto}, %
  4735  \&{packed}}\6
  4736  \4\\{nil\_like}: \37$\\{sc1}(\\{res\_flag}+\|p)(\\{simp})$;\C{\&{nil}}\6
  4737  \4\\{to\_like}: \37$\\{sc3}(\\{math\_rel})(\\{res\_flag}+\|p)(\.{"\}"})(%
  4738  \\{math})$;\C{\&{downto}, \&{to}}\2\6
  4739  \&{end};\6
  4740  \&{end};\par
  4741  \U183.\fi
  4742  
  4743  \M193. \P$\X193:Cases that generate more than one scrap\X\S$\6
  4744  \4\\{begin\_like}: \37\&{begin} \37$\\{sc3}(\\{force})(\\{res\_flag}+\|p)(%
  4745  \\{cancel})(\\{beginning})$;\5
  4746  $\\{sc0}(\\{intro})$;\6
  4747  \&{end};\C{\&{begin}}\6
  4748  \4\\{case\_like}: \37\&{begin} \37$\\{sc0}(\\{casey})$;\5
  4749  $\\{sc2}(\\{force})(\\{res\_flag}+\|p)(\\{alpha})$;\6
  4750  \&{end};\C{\&{case}}\6
  4751  \4\\{else\_like}: \37\&{begin} \37\X194:Append \\{terminator} if not already
  4752  present\X;\6
  4753  $\\{sc3}(\\{force})(\\{backup})(\\{res\_flag}+\|p)(\\{elsie})$;\6
  4754  \&{end};\C{\&{else}}\6
  4755  \4\\{end\_like}: \37\&{begin} \37\X194:Append \\{terminator} if not already
  4756  present\X;\6
  4757  $\\{sc2}(\\{force})(\\{res\_flag}+\|p)(\\{close})$;\6
  4758  \&{end};\C{\&{end}}\6
  4759  \4\\{if\_like}: \37\&{begin} \37$\\{sc0}(\\{cond})$;\5
  4760  $\\{sc2}(\\{force})(\\{res\_flag}+\|p)(\\{alpha})$;\6
  4761  \&{end};\C{\&{if}}\6
  4762  \4\\{loop\_like}: \37\&{begin} \37$\\{sc3}(\\{force})(\.{"\\"})(\.{"\~"})(%
  4763  \\{alpha})$;\5
  4764  $\\{sc1}(\\{res\_flag}+\|p)(\\{omega})$;\6
  4765  \&{end};\C{\&{xclause}}\6
  4766  \4\\{proc\_like}: \37\&{begin} \37$\\{sc4}(\\{force})(\\{backup})(\\{res%
  4767  \_flag}+\|p)(\\{cancel})(\\{proc})$;\5
  4768  $\\{sc3}(\\{indent})(\.{"\\"})(\.{"\ "})(\\{intro})$;\6
  4769  \&{end};\C{\&{function}, \&{procedure}, \&{program}}\6
  4770  \4\\{record\_like}: \37\&{begin} \37$\\{sc1}(\\{res\_flag}+\|p)(\\{record%
  4771  \_head})$;\5
  4772  $\\{sc0}(\\{intro})$;\6
  4773  \&{end};\C{\&{record}}\6
  4774  \4\\{repeat\_like}: \37\&{begin} \37$\\{sc4}(\\{force})(\\{indent})(\\{res%
  4775  \_flag}+\|p)(\\{cancel})(\\{beginning})$;\5
  4776  $\\{sc0}(\\{intro})$;\6
  4777  \&{end};\C{\&{repeat}}\6
  4778  \4\\{until\_like}: \37\&{begin} \37\X194:Append \\{terminator} if not already
  4779  present\X;\6
  4780  $\\{sc3}(\\{force})(\\{backup})(\\{res\_flag}+\|p)(\\{close})$;\5
  4781  $\\{sc0}(\\{clause})$;\6
  4782  \&{end};\C{\&{until}}\6
  4783  \4\\{var\_like}: \37\&{begin} \37$\\{sc4}(\\{force})(\\{backup})(\\{res\_flag}+%
  4784  \|p)(\\{cancel})(\\{var\_head})$;\5
  4785  $\\{sc0}(\\{intro})$;\6
  4786  \&{end};\C{\&{var}}\par
  4787  \U191.\fi
  4788  
  4789  \M194. If a comment or semicolon appears before the reserved words \&{end},
  4790  \&{else}, or \&{until}, the \\{semi} or \\{terminator} scrap that is already
  4791  present overrides the \\{terminator} scrap belonging to this reserved word.
  4792  
  4793  \Y\P$\4\X194:Append \\{terminator} if not already present\X\S$\6
  4794  \&{if} $(\\{scrap\_ptr}<\\{scrap\_base})\V((\\{cat}[\\{scrap\_ptr}]\I%
  4795  \\{terminator})\W(\\{cat}[\\{scrap\_ptr}]\I\\{semi}))$ \1\&{then}\5
  4796  $\\{sc0}(\\{terminator})$\2\par
  4797  \Us193, 193\ETs193.\fi
  4798  
  4799  \M195. A comment is incorporated into the previous scrap if that scrap is of
  4800  type
  4801  \\{omega} or \\{semi} or \\{terminator}. (These three categories have
  4802  consecutive
  4803  category codes.) Otherwise the comment is entered as a separate scrap
  4804  of type \\{terminator}, and it will combine with a \\{terminator} scrap that
  4805  immediately follows~it.
  4806  
  4807  The \\{app\_comment} procedure takes care of placing a comment at the end of
  4808  the
  4809  current scrap list. When \\{app\_comment} is called, we assume that the current
  4810  token list is the translation of the comment involved.
  4811  
  4812  \Y\P$\4\X195:Declaration of the \\{app\_comment} procedure\X\S$\6
  4813  \4\&{procedure}\1\  \37\\{app\_comment};\C{append a comment to the scrap list}%
  4814  \2\6
  4815  \&{begin} \37\\{freeze\_text};\6
  4816  \&{if} $(\\{scrap\_ptr}<\\{scrap\_base})\V(\\{cat}[\\{scrap\_ptr}]<\\{omega})%
  4817  \V(\\{cat}[\\{scrap\_ptr}]>\\{terminator})$ \1\&{then}\5
  4818  $\\{sc0}(\\{terminator})$\6
  4819  \4\&{else} \&{begin} \37$\\{app1}(\\{scrap\_ptr})$;\C{$\\{cat}[\\{scrap\_ptr}]$
  4820  is     \\{omega} or \\{semi} or \\{terminator}}\6
  4821  \&{end};\2\6
  4822  $\\{app}(\\{text\_ptr}-1+\\{tok\_flag})$;\5
  4823  $\\{trans}[\\{scrap\_ptr}]\K\\{text\_ptr}$;\5
  4824  \\{freeze\_text};\6
  4825  \&{end};\par
  4826  \U183.\fi
  4827  
  4828  \M196. We are now finished with \\{Pascal\_parse}, except for two relatively
  4829  trivial subprocedures that convert constants into tokens.
  4830  
  4831  \Y\P$\4\X196:Declaration of the \\{app\_octal} and \\{app\_hex} procedures\X\S$%
  4832  \6
  4833  \4\&{procedure}\1\  \37\\{app\_octal};\2\6
  4834  \&{begin} \37$\\{app}(\.{"\\"})$;\5
  4835  $\\{app}(\.{"O"})$;\5
  4836  $\\{app}(\.{"\{"})$;\6
  4837  \&{while} $(\\{buffer}[\\{loc}]\G\.{"0"})\W(\\{buffer}[\\{loc}]\L\.{"7"})$ \1%
  4838  \&{do}\6
  4839  \&{begin} \37$\\{app\_tok}(\\{buffer}[\\{loc}])$;\5
  4840  $\\{incr}(\\{loc})$;\6
  4841  \&{end};\2\6
  4842  $\\{sc1}(\.{"\}"})(\\{simp})$;\6
  4843  \&{end};\7
  4844  \4\&{procedure}\1\  \37\\{app\_hex};\2\6
  4845  \&{begin} \37$\\{app}(\.{"\\"})$;\5
  4846  $\\{app}(\.{"H"})$;\5
  4847  $\\{app}(\.{"\{"})$;\6
  4848  \&{while} $((\\{buffer}[\\{loc}]\G\.{"0"})\W(\\{buffer}[\\{loc}]\L\.{"9"}))\V%
  4849  \30((\\{buffer}[\\{loc}]\G\.{"A"})\W(\\{buffer}[\\{loc}]\L\.{"F"}))$ \1\&{do}\6
  4850  \&{begin} \37$\\{app\_tok}(\\{buffer}[\\{loc}])$;\5
  4851  $\\{incr}(\\{loc})$;\6
  4852  \&{end};\2\6
  4853  $\\{sc1}(\.{"\}"})(\\{simp})$;\6
  4854  \&{end};\par
  4855  \U183.\fi
  4856  
  4857  \M197. When the `\v' that introduces \PASCAL\ text is sensed, a call on
  4858  \\{Pascal\_translate} will return a pointer to the \TeX\ translation of
  4859  that text. If scraps exist in the \\{cat} and \\{trans} arrays, they are
  4860  unaffected by this translation process.
  4861  
  4862  \Y\P\4\&{function}\1\  \37\\{Pascal\_translate}: \37\\{text\_pointer};\6
  4863  \4\&{var} \37\|p: \37\\{text\_pointer};\C{points to the translation}\6
  4864  \\{save\_base}: \37$0\to\\{max\_scraps}$;\C{holds original value of \\{scrap%
  4865  \_base}}\2\6
  4866  \&{begin} \37$\\{save\_base}\K\\{scrap\_base}$;\5
  4867  $\\{scrap\_base}\K\\{scrap\_ptr}+1$;\5
  4868  \\{Pascal\_parse};\C{get the scraps together}\6
  4869  \&{if} $\\{next\_control}\I\.{"|"}$ \1\&{then}\5
  4870  $\\{err\_print}(\.{\'!\ Missing\ "|"\ after\ Pascal\ text\'})$;\2\6
  4871  $\\{app\_tok}(\\{cancel})$;\5
  4872  \\{app\_comment};\C{place a \\{cancel} token as a final ``comment''}\6
  4873  $\|p\K\\{translate}$;\C{make the translation}\6
  4874  \&{stat} \37\&{if} $\\{scrap\_ptr}>\\{max\_scr\_ptr}$ \1\&{then}\5
  4875  $\\{max\_scr\_ptr}\K\\{scrap\_ptr}$;\2\ \&{tats}\6
  4876  $\\{scrap\_ptr}\K\\{scrap\_base}-1$;\5
  4877  $\\{scrap\_base}\K\\{save\_base}$;\C{scrap the scraps}\6
  4878  $\\{Pascal\_translate}\K\|p$;\6
  4879  \&{end};\par
  4880  \fi
  4881  
  4882  \M198. The \\{outer\_parse} routine is to \\{Pascal\_parse} as \\{outer\_xref}
  4883  is to \\{Pascal\_xref}: It constructs a sequence of scraps for \PASCAL\ text
  4884  until $\\{next\_control}\G\\{format}$. Thus, it takes care of embedded
  4885  comments.
  4886  
  4887  \Y\P\4\&{procedure}\1\  \37\\{outer\_parse};\C{makes scraps from \PASCAL\
  4888  tokens and comments}\6
  4889  \4\&{var} \37\\{bal}: \37\\{eight\_bits};\C{brace level in comment}\6
  4890  $\|p,\39\|q$: \37\\{text\_pointer};\C{partial comments}\2\6
  4891  \&{begin} \37\&{while} $\\{next\_control}<\\{format}$ \1\&{do}\6
  4892  \&{if} $\\{next\_control}\I\.{"\{"}$ \1\&{then}\5
  4893  \\{Pascal\_parse}\6
  4894  \4\&{else} \&{begin} \37\X199:Make sure that there is room for at least seven
  4895  more tokens, three more texts, and one more scrap\X;\6
  4896  $\\{app}(\.{"\\"})$;\5
  4897  $\\{app}(\.{"C"})$;\5
  4898  $\\{app}(\.{"\{"})$;\5
  4899  $\\{bal}\K\\{copy\_comment}(1)$;\5
  4900  $\\{next\_control}\K\.{"|"}$;\6
  4901  \&{while} $\\{bal}>0$ \1\&{do}\6
  4902  \&{begin} \37$\|p\K\\{text\_ptr}$;\5
  4903  \\{freeze\_text};\5
  4904  $\|q\K\\{Pascal\_translate}$;\C{at this point we have $\\{tok\_ptr}+6\L\\{max%
  4905  \_toks}$}\6
  4906  $\\{app}(\\{tok\_flag}+\|p)$;\5
  4907  $\\{app}(\\{inner\_tok\_flag}+\|q)$;\6
  4908  \&{if} $\\{next\_control}=\.{"|"}$ \1\&{then}\5
  4909  $\\{bal}\K\\{copy\_comment}(\\{bal})$\6
  4910  \4\&{else} $\\{bal}\K0$;\C{an error has been reported}\2\6
  4911  \&{end};\2\6
  4912  $\\{app}(\\{force})$;\5
  4913  \\{app\_comment};\C{the full comment becomes a scrap}\6
  4914  \&{end};\2\2\6
  4915  \&{end};\par
  4916  \fi
  4917  
  4918  \M199. \P$\X199:Make sure that there is room for at least seven more tokens,
  4919  three more texts, and one more scrap\X\S$\6
  4920  \&{if} $(\\{tok\_ptr}+7>\\{max\_toks})\V(\\{text\_ptr}+3>\\{max\_texts})\V(%
  4921  \\{scrap\_ptr}\G\\{max\_scraps})$ \1\&{then}\6
  4922  \&{begin} \37\&{stat} \37\&{if} $\\{scrap\_ptr}>\\{max\_scr\_ptr}$ \1\&{then}\5
  4923  $\\{max\_scr\_ptr}\K\\{scrap\_ptr}$;\2\6
  4924  \&{if} $\\{tok\_ptr}>\\{max\_tok\_ptr}$ \1\&{then}\5
  4925  $\\{max\_tok\_ptr}\K\\{tok\_ptr}$;\2\6
  4926  \&{if} $\\{text\_ptr}>\\{max\_txt\_ptr}$ \1\&{then}\5
  4927  $\\{max\_txt\_ptr}\K\\{text\_ptr}$;\2\6
  4928  \&{tats}\6
  4929  $\\{overflow}(\.{\'token/text/scrap\'})$;\6
  4930  \&{end}\2\par
  4931  \U198.\fi
  4932  
  4933  \N200.  Output of tokens.
  4934  So far our programs have only built up multi-layered token lists in
  4935  \.{WEAVE}'s internal memory; we have to figure out how to get them into
  4936  the desired final form. The job of converting token lists to characters in
  4937  the \TeX\ output file is not difficult, although it is an implicitly
  4938  recursive process. Four main considerations had to be kept in mind when
  4939  this part of \.{WEAVE} was designed.  (a) There are two modes of output:
  4940  \\{outer} mode, which translates tokens like \\{force} into line-breaking
  4941  control sequences, and \\{inner} mode, which ignores them except that blank
  4942  spaces take the place of line breaks. (b) The \\{cancel} instruction applies
  4943  to adjacent token or tokens that are output, and this cuts across levels
  4944  of recursion since `\\{cancel}' occurs at the beginning or end of a token
  4945  list on one level. (c) The \TeX\ output file will be semi-readable if line
  4946  breaks are inserted after the result of tokens like \\{break\_space} and
  4947  \\{force}.  (d) The final line break should be suppressed, and there should
  4948  be no \\{force} token output immediately after `\.{\\Y\\P}'.
  4949  
  4950  \fi
  4951  
  4952  \M201. The output process uses a stack to keep track of what is going on at
  4953  different ``levels'' as the token lists are being written out. Entries on
  4954  this stack have three parts:
  4955  
  4956  \yskip\hang \\{end\_field} is the \\{tok\_mem} location where the token list of
  4957  a
  4958  particular level will end;
  4959  
  4960  \yskip\hang \\{tok\_field} is the \\{tok\_mem} location from which the next
  4961  token
  4962  on a particular level will be read;
  4963  
  4964  \yskip\hang \\{mode\_field} is the current mode, either \\{inner} or \\{outer}.
  4965  
  4966  \yskip\noindent The current values of these quantities are referred to
  4967  quite frequently, so they are stored in a separate place instead of in the
  4968  \\{stack} array. We call the current values \\{cur\_end}, \\{cur\_tok}, and
  4969  \\{cur\_mode}.
  4970  
  4971  The global variable \\{stack\_ptr} tells how many levels of output are
  4972  currently in progress. The end of output occurs when an \\{end\_translation}
  4973  token is found, so the stack is never empty except when we first begin the
  4974  output process.
  4975  
  4976  \Y\P\D \37$\\{inner}=0$\C{value of \\{mode} for \PASCAL\ texts within \TeX\
  4977  texts}\par
  4978  \P\D \37$\\{outer}=1$\C{value of \\{mode} for \PASCAL\ texts in modules}\par
  4979  \Y\P$\4\X11:Types in the outer block\X\mathrel{+}\S$\6
  4980  $\\{mode}=\\{inner}\to\\{outer}$;\6
  4981  $\\{output\_state}=$\1\5
  4982  \1\&{record} \37\\{end\_field}: \37\\{sixteen\_bits};\C{ending location of
  4983  token list}\6
  4984  \4\\{tok\_field}: \37\\{sixteen\_bits};\C{present location within token list}\6
  4985  \4\\{mode\_field}: \37\\{mode};\C{interpretation of control tokens}\2\6
  4986  \&{end};\2\par
  4987  \fi
  4988  
  4989  \M202. \P\D \37$\\{cur\_end}\S\\{cur\_state}.\\{end\_field}$\C{current ending
  4990  location in \\{tok\_mem}}\par
  4991  \P\D \37$\\{cur\_tok}\S\\{cur\_state}.\\{tok\_field}$\C{location of next output
  4992  token in \\{tok\_mem}}\par
  4993  \P\D \37$\\{cur\_mode}\S\\{cur\_state}.\\{mode\_field}$\C{current mode of
  4994  interpretation}\par
  4995  \P\D \37$\\{init\_stack}\S\\{stack\_ptr}\K0$;\5
  4996  $\\{cur\_mode}\K\\{outer}$\C{do this to initialize the stack}\par
  4997  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  4998  \4\\{cur\_state}: \37\\{output\_state};\C{\\{cur\_end}, \\{cur\_tok}, \\{cur%
  4999  \_mode}}\6
  5000  \4\\{stack}: \37\&{array} $[1\to\\{stack\_size}]$ \1\&{of}\5
  5001  \\{output\_state};\C{info for non-current levels}\2\6
  5002  \4\\{stack\_ptr}: \37$0\to\\{stack\_size}$;\C{first unused location in the
  5003  output state stack}\6
  5004  \&{stat} \37\\{max\_stack\_ptr}: \37$0\to\\{stack\_size}$;\C{largest value
  5005  assumed by \\{stack\_ptr}}\6
  5006  \&{tats}\par
  5007  \fi
  5008  
  5009  \M203. \P$\X10:Set initial values\X\mathrel{+}\S$\6
  5010  \&{stat} \37$\\{max\_stack\_ptr}\K0$;\ \&{tats}\par
  5011  \fi
  5012  
  5013  \M204. To insert token-list \|p into the output, the \\{push\_level} subroutine
  5014  is called; it saves the old level of output and gets a new one going.
  5015  The value of \\{cur\_mode} is not changed.
  5016  
  5017  \Y\P\4\&{procedure}\1\  \37$\\{push\_level}(\|p:\\{text\_pointer})$;\C{suspends
  5018  the current level}\2\6
  5019  \&{begin} \37\&{if} $\\{stack\_ptr}=\\{stack\_size}$ \1\&{then}\5
  5020  $\\{overflow}(\.{\'stack\'})$\6
  5021  \4\&{else} \&{begin} \37\&{if} $\\{stack\_ptr}>0$ \1\&{then}\5
  5022  $\\{stack}[\\{stack\_ptr}]\K\\{cur\_state}$;\C{save \\{cur\_end}$\,\ldots\,$%
  5023  \\{cur\_mode}}\2\6
  5024  $\\{incr}(\\{stack\_ptr})$;\6
  5025  \&{stat} \37\&{if} $\\{stack\_ptr}>\\{max\_stack\_ptr}$ \1\&{then}\5
  5026  $\\{max\_stack\_ptr}\K\\{stack\_ptr}$;\2\ \&{tats}\6
  5027  $\\{cur\_tok}\K\\{tok\_start}[\|p]$;\5
  5028  $\\{cur\_end}\K\\{tok\_start}[\|p+1]$;\6
  5029  \&{end};\2\6
  5030  \&{end};\par
  5031  \fi
  5032  
  5033  \M205. Conversely, the \\{pop\_level} routine restores the conditions that were
  5034  in
  5035  force when the current level was begun. This subroutine will never be
  5036  called when $\\{stack\_ptr}=1$. It is so simple, we declare it as a macro:
  5037  
  5038  \Y\P\D \37$\\{pop\_level}\S$\1\6
  5039  \&{begin} \37$\\{decr}(\\{stack\_ptr})$;\5
  5040  $\\{cur\_state}\K\\{stack}[\\{stack\_ptr}]$;\6
  5041  \&{end}\C{do this when \\{cur\_tok} reaches \\{cur\_end}}\2\par
  5042  \fi
  5043  
  5044  \M206. The \\{get\_output} function returns the next byte of output that is not
  5045  a
  5046  reference to a token list. It returns the values \\{identifier} or \\{res%
  5047  \_word}
  5048  or \\{mod\_name} if the next token is to be an identifier (typeset in
  5049  italics), a reserved word (typeset in boldface) or a module name (typeset
  5050  by a complex routine that might generate additional levels of output).
  5051  In these cases \\{cur\_name} points to the identifier or module name in
  5052  question.
  5053  
  5054  \Y\P\D \37$\\{res\_word}=\O{201}$\C{returned by \\{get\_output} for reserved
  5055  words}\par
  5056  \P\D \37$\\{mod\_name}=\O{200}$\C{returned by \\{get\_output} for module names}%
  5057  \par
  5058  \Y\P\4\&{function}\1\  \37\\{get\_output}: \37\\{eight\_bits};\C{returns the
  5059  next token of output}\6
  5060  \4\&{label} \37\\{restart};\6
  5061  \4\&{var} \37\|a: \37\\{sixteen\_bits};\C{current item read from \\{tok\_mem}}%
  5062  \2\6
  5063  \&{begin} \37\\{restart}: \37\&{while} $\\{cur\_tok}=\\{cur\_end}$ \1\&{do}\5
  5064  \\{pop\_level};\2\6
  5065  $\|a\K\\{tok\_mem}[\\{cur\_tok}]$;\5
  5066  $\\{incr}(\\{cur\_tok})$;\6
  5067  \&{if} $\|a\G\O{400}$ \1\&{then}\6
  5068  \&{begin} \37$\\{cur\_name}\K\|a\mathbin{\&{mod}}\\{id\_flag}$;\6
  5069  \&{case} $\|a\mathbin{\&{div}}\\{id\_flag}$ \1\&{of}\6
  5070  \42: \37$\|a\K\\{res\_word}$;\C{$\|a=\\{res\_flag}+\\{cur\_name}$}\6
  5071  \43: \37$\|a\K\\{mod\_name}$;\C{$\|a=\\{mod\_flag}+\\{cur\_name}$}\6
  5072  \44: \37\&{begin} \37$\\{push\_level}(\\{cur\_name})$;\5
  5073  \&{goto} \37\\{restart};\6
  5074  \&{end};\C{$\|a=\\{tok\_flag}+\\{cur\_name}$}\6
  5075  \45: \37\&{begin} \37$\\{push\_level}(\\{cur\_name})$;\5
  5076  $\\{cur\_mode}\K\\{inner}$;\5
  5077  \&{goto} \37\\{restart};\6
  5078  \&{end};\C{$\|a=\\{inner\_tok\_flag}+\\{cur\_name}$}\6
  5079  \4\&{othercases} \37$\|a\K\\{identifier}$\C{$\|a=\\{id\_flag}+\\{cur\_name}$}\2%
  5080  \6
  5081  \&{endcases};\6
  5082  \&{end};\2\6
  5083  \&{debug} \37\&{if} $\\{trouble\_shooting}$ \1\&{then}\5
  5084  \\{debug\_help};\ \2\6
  5085  \&{gubed}\6
  5086  $\\{get\_output}\K\|a$;\6
  5087  \&{end};\par
  5088  \fi
  5089  
  5090  \M207. The real work associated with token output is done by \\{make\_output}.
  5091  This procedure appends an \\{end\_translation} token to the current token list,
  5092  and then it repeatedly calls \\{get\_output} and feeds characters to the output
  5093  buffer until reaching the \\{end\_translation} sentinel. It is possible for
  5094  \\{make\_output} to
  5095  be called recursively, since a module name may include embedded \PASCAL\
  5096  text; however, the depth of recursion never exceeds one level, since
  5097  module names cannot be inside of module names.
  5098  
  5099  A procedure called \\{output\_Pascal} does the scanning, translation, and
  5100  output of \PASCAL\ text within `\pb' brackets, and this procedure uses
  5101  \\{make\_output} to output the current token list. Thus, the recursive call
  5102  of \\{make\_output} actually occurs when \\{make\_output} calls \\{output%
  5103  \_Pascal}
  5104  while outputting the name of a module.
  5105  
  5106  \Y\P\4\&{procedure}\1\  \37\\{make\_output};\5
  5107  \\{forward};\5
  5108  \hbox{\2}\7
  5109  \4\&{procedure}\1\  \37\\{output\_Pascal};\C{outputs the current token list}\6
  5110  \4\&{var} \37$\\{save\_tok\_ptr},\39\\{save\_text\_ptr},\39\\{save\_next%
  5111  \_control}$: \37\\{sixteen\_bits};\C{values to be restored}\6
  5112  \|p: \37\\{text\_pointer};\C{translation of the \PASCAL\ text}\2\6
  5113  \&{begin} \37$\\{save\_tok\_ptr}\K\\{tok\_ptr}$;\5
  5114  $\\{save\_text\_ptr}\K\\{text\_ptr}$;\5
  5115  $\\{save\_next\_control}\K\\{next\_control}$;\5
  5116  $\\{next\_control}\K\.{"|"}$;\5
  5117  $\|p\K\\{Pascal\_translate}$;\5
  5118  $\\{app}(\|p+\\{inner\_tok\_flag})$;\5
  5119  \\{make\_output};\C{output the list}\6
  5120  \&{stat} \37\&{if} $\\{text\_ptr}>\\{max\_txt\_ptr}$ \1\&{then}\5
  5121  $\\{max\_txt\_ptr}\K\\{text\_ptr}$;\2\6
  5122  \&{if} $\\{tok\_ptr}>\\{max\_tok\_ptr}$ \1\&{then}\5
  5123  $\\{max\_tok\_ptr}\K\\{tok\_ptr}$;\2\ \&{tats}\6
  5124  $\\{text\_ptr}\K\\{save\_text\_ptr}$;\5
  5125  $\\{tok\_ptr}\K\\{save\_tok\_ptr}$;\C{forget the tokens}\6
  5126  $\\{next\_control}\K\\{save\_next\_control}$;\C{restore \\{next\_control} to
  5127  original state}\6
  5128  \&{end};\par
  5129  \fi
  5130  
  5131  \M208. Here is \.{WEAVE}'s major output handler.
  5132  
  5133  \Y\P\4\&{procedure}\1\  \37\\{make\_output};\C{outputs the equivalents of
  5134  tokens}\6
  5135  \4\&{label} \37$\\{reswitch},\39\\{exit},\39\\{found}$;\6
  5136  \4\&{var} \37\|a: \37\\{eight\_bits};\C{current output byte}\6
  5137  \|b: \37\\{eight\_bits};\C{next output byte}\6
  5138  $\|k,\39\\{k\_limit}$: \37$0\to\\{max\_bytes}$;\C{indices into \\{byte\_mem}}\6
  5139  \|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\_mem}}\6
  5140  \|j: \37$0\to\\{long\_buf\_size}$;\C{index into \\{buffer}}\6
  5141  \\{string\_delimiter}: \37\\{ASCII\_code};\C{first and last character of
  5142  string being copied}\6
  5143  $\\{save\_loc},\39\\{save\_limit}$: \37$0\to\\{long\_buf\_size}$;\C{\\{loc} and
  5144  \\{limit} to be restored}\6
  5145  \\{cur\_mod\_name}: \37\\{name\_pointer};\C{name of module being output}\6
  5146  \\{save\_mode}: \37\\{mode};\C{value of \\{cur\_mode} before a sequence of
  5147  breaks}\2\6
  5148  \&{begin} \37$\\{app}(\\{end\_translation})$;\C{append a sentinel}\6
  5149  \\{freeze\_text};\5
  5150  $\\{push\_level}(\\{text\_ptr}-1)$;\6
  5151  \~ \1\&{loop}\ \&{begin} \37$\|a\K\\{get\_output}$;\6
  5152  \4\\{reswitch}: \37\&{case} $\|a$ \1\&{of}\6
  5153  \4\\{end\_translation}: \37\&{return};\6
  5154  \4$\\{identifier},\39\\{res\_word}$: \37\X209:Output an identifier\X;\6
  5155  \4\\{mod\_name}: \37\X213:Output a module name\X;\6
  5156  \4$\\{math\_bin},\39\\{math\_op},\39\\{math\_rel}$: \37\X210:Output a \.{%
  5157  \\math} operator\X;\6
  5158  \4\\{cancel}: \37\&{begin} \37\1\&{repeat} \37$\|a\K\\{get\_output}$;\6
  5159  \4\&{until}\5
  5160  $(\|a<\\{backup})\V(\|a>\\{big\_force})$;\2\6
  5161  \&{goto} \37\\{reswitch};\6
  5162  \&{end};\6
  5163  \4\\{big\_cancel}: \37\&{begin} \37\1\&{repeat} \37$\|a\K\\{get\_output}$;\6
  5164  \4\&{until}\5
  5165  $((\|a<\\{backup})\W(\|a\I\.{"\ "}))\V(\|a>\\{big\_force})$;\2\6
  5166  \&{goto} \37\\{reswitch};\6
  5167  \&{end};\6
  5168  \4$\\{indent},\39\\{outdent},\39\\{opt},\39\\{backup},\39\\{break\_space},\39%
  5169  \\{force},\39\\{big\_force}$: \37\X211:Output a \(control, look ahead in case
  5170  of line breaks, possibly \&{goto} \\{reswitch}\X;\6
  5171  \4\&{othercases} \37$\\{out}(\|a)$\C{otherwise \|a is an ASCII character}\2\6
  5172  \&{endcases};\6
  5173  \&{end};\2\6
  5174  \4\\{exit}: \37\&{end};\par
  5175  \fi
  5176  
  5177  \M209. An identifier of length one does not have to be enclosed in braces, and
  5178  it
  5179  looks slightly better if set in a math-italic font instead of a (slightly
  5180  narrower) text-italic font. Thus we output `\.{\\\char'174a}' but
  5181  `\.{\\\\\{aa\}}'.
  5182  
  5183  \Y\P$\4\X209:Output an identifier\X\S$\6
  5184  \&{begin} \37$\\{out}(\.{"\\"})$;\6
  5185  \&{if} $\|a=\\{identifier}$ \1\&{then}\6
  5186  \&{if} $\\{length}(\\{cur\_name})=1$ \1\&{then}\5
  5187  $\\{out}(\.{"|"})$\6
  5188  \4\&{else} $\\{out}(\.{"\\"})$\2\6
  5189  \4\&{else} $\\{out}(\.{"\&"})$;\C{$\|a=\\{res\_word}$}\2\6
  5190  \&{if} $\\{length}(\\{cur\_name})=1$ \1\&{then}\5
  5191  $\\{out}(\\{byte\_mem}[\\{cur\_name}\mathbin{\&{mod}}\\{ww},\39\\{byte\_start}[%
  5192  \\{cur\_name}]])$\6
  5193  \4\&{else} $\\{out\_name}(\\{cur\_name})$;\2\6
  5194  \&{end}\par
  5195  \U208.\fi
  5196  
  5197  \M210. \P$\X210:Output a \.{\\math} operator\X\S$\6
  5198  \&{begin} \37$\\{out5}(\.{"\\"})(\.{"m"})(\.{"a"})(\.{"t"})(\.{"h"})$;\6
  5199  \&{if} $\|a=\\{math\_bin}$ \1\&{then}\5
  5200  $\\{out3}(\.{"b"})(\.{"i"})(\.{"n"})$\6
  5201  \4\&{else} \&{if} $\|a=\\{math\_rel}$ \1\&{then}\5
  5202  $\\{out3}(\.{"r"})(\.{"e"})(\.{"l"})$\6
  5203  \4\&{else} $\\{out2}(\.{"o"})(\.{"p"})$;\2\2\6
  5204  $\\{out}(\.{"\{"})$;\6
  5205  \&{end}\par
  5206  \U208.\fi
  5207  
  5208  \M211. The current mode does not affect the behavior of \.{WEAVE}'s output
  5209  routine
  5210  except when we are outputting control tokens.
  5211  
  5212  \Y\P$\4\X211:Output a \(control, look ahead in case of line breaks, possibly %
  5213  \&{goto} \\{reswitch}\X\S$\6
  5214  \&{if} $\|a<\\{break\_space}$ \1\&{then}\6
  5215  \&{begin} \37\&{if} $\\{cur\_mode}=\\{outer}$ \1\&{then}\6
  5216  \&{begin} \37$\\{out2}(\.{"\\"})(\|a-\\{cancel}+\.{"0"})$;\6
  5217  \&{if} $\|a=\\{opt}$ \1\&{then}\5
  5218  $\\{out}(\\{get\_output})$\C{\\{opt} is followed by a digit}\2\6
  5219  \&{end}\6
  5220  \4\&{else} \&{if} $\|a=\\{opt}$ \1\&{then}\5
  5221  $\|b\K\\{get\_output}$\C{ignore digit following \\{opt}}\2\2\6
  5222  \&{end}\6
  5223  \4\&{else} \X212:Look ahead for strongest line break, \&{goto} \\{reswitch}\X\2%
  5224  \par
  5225  \U208.\fi
  5226  
  5227  \M212. If several of the tokens \\{break\_space}, \\{force}, \\{big\_force}
  5228  occur in a
  5229  row, possibly mixed with blank spaces (which are ignored),
  5230  the largest one is used. A line break also occurs in the output file,
  5231  except at the very end of the translation. The very first line break
  5232  is suppressed (i.e., a line break that follows `\.{\\Y\\P}').
  5233  
  5234  \Y\P$\4\X212:Look ahead for strongest line break, \&{goto} \\{reswitch}\X\S$\6
  5235  \&{begin} \37$\|b\K\|a$;\5
  5236  $\\{save\_mode}\K\\{cur\_mode}$;\6
  5237  \~ \1\&{loop}\ \&{begin} \37$\|a\K\\{get\_output}$;\6
  5238  \&{if} $(\|a=\\{cancel})\V(\|a=\\{big\_cancel})$ \1\&{then}\5
  5239  \&{goto} \37\\{reswitch};\C{\\{cancel} overrides everything}\2\6
  5240  \&{if} $((\|a\I\.{"\ "})\W(\|a<\\{break\_space}))\V(\|a>\\{big\_force})$ \1%
  5241  \&{then}\6
  5242  \&{begin} \37\&{if} $\\{save\_mode}=\\{outer}$ \1\&{then}\6
  5243  \&{begin} \37\&{if} $\\{out\_ptr}>3$ \1\&{then}\6
  5244  \&{if} $(\\{out\_buf}[\\{out\_ptr}]=\.{"P"})\W(\\{out\_buf}[\\{out\_ptr}-1]=%
  5245  \.{"\\"})\W(\\{out\_buf}[\\{out\_ptr}-2]=\.{"Y"})\W(\\{out\_buf}[\\{out%
  5246  \_ptr}-3]=\.{"\\"})$ \1\&{then}\5
  5247  \&{goto} \37\\{reswitch};\2\2\6
  5248  $\\{out2}(\.{"\\"})(\|b-\\{cancel}+\.{"0"})$;\6
  5249  \&{if} $\|a\I\\{end\_translation}$ \1\&{then}\5
  5250  \\{finish\_line};\2\6
  5251  \&{end}\6
  5252  \4\&{else} \&{if} $(\|a\I\\{end\_translation})\W(\\{cur\_mode}=\\{inner})$ \1%
  5253  \&{then}\5
  5254  $\\{out}(\.{"\ "})$;\2\2\6
  5255  \&{goto} \37\\{reswitch};\6
  5256  \&{end};\2\6
  5257  \&{if} $\|a>\|b$ \1\&{then}\5
  5258  $\|b\K\|a$;\C{if $\|a=\.{"\ "}$ we have $\|a<\|b$}\2\6
  5259  \&{end};\2\6
  5260  \&{end}\par
  5261  \U211.\fi
  5262  
  5263  \M213. The remaining part of \\{make\_output} is somewhat more complicated.
  5264  When we
  5265  output a module name, we may need to enter the parsing and translation
  5266  routines, since the name may contain \PASCAL\ code embedded in
  5267  \pb\ constructions. This \PASCAL\ code is placed at the end of the active
  5268  input buffer and the translation process uses the end of the active
  5269  \\{tok\_mem} area.
  5270  
  5271  \Y\P$\4\X213:Output a module name\X\S$\6
  5272  \&{begin} \37$\\{out2}(\.{"\\"})(\.{"X"})$;\5
  5273  $\\{cur\_xref}\K\\{xref}[\\{cur\_name}]$;\6
  5274  \&{if} $\\{num}(\\{cur\_xref})\G\\{def\_flag}$ \1\&{then}\6
  5275  \&{begin} \37$\\{out\_mod}(\\{num}(\\{cur\_xref})-\\{def\_flag})$;\6
  5276  \&{if} $\\{phase\_three}$ \1\&{then}\6
  5277  \&{begin} \37$\\{cur\_xref}\K\\{xlink}(\\{cur\_xref})$;\6
  5278  \&{while} $\\{num}(\\{cur\_xref})\G\\{def\_flag}$ \1\&{do}\6
  5279  \&{begin} \37$\\{out2}(\.{","})(\.{"\ "})$;\5
  5280  $\\{out\_mod}(\\{num}(\\{cur\_xref})-\\{def\_flag})$;\5
  5281  $\\{cur\_xref}\K\\{xlink}(\\{cur\_xref})$;\6
  5282  \&{end};\2\6
  5283  \&{end};\2\6
  5284  \&{end}\6
  5285  \4\&{else} $\\{out}(\.{"0"})$;\C{output the module number, or zero if it was
  5286  undefined}\2\6
  5287  $\\{out}(\.{":"})$;\5
  5288  \X214:Output the text of the module name\X;\6
  5289  $\\{out2}(\.{"\\"})(\.{"X"})$;\6
  5290  \&{end}\par
  5291  \U208.\fi
  5292  
  5293  \M214. \P$\X214:Output the text of the module name\X\S$\6
  5294  $\|k\K\\{byte\_start}[\\{cur\_name}]$;\5
  5295  $\|w\K\\{cur\_name}\mathbin{\&{mod}}\\{ww}$;\5
  5296  $\\{k\_limit}\K\\{byte\_start}[\\{cur\_name}+\\{ww}]$;\5
  5297  $\\{cur\_mod\_name}\K\\{cur\_name}$;\6
  5298  \&{while} $\|k<\\{k\_limit}$ \1\&{do}\6
  5299  \&{begin} \37$\|b\K\\{byte\_mem}[\|w,\39\|k]$;\5
  5300  $\\{incr}(\|k)$;\6
  5301  \&{if} $\|b=\.{"@"}$ \1\&{then}\5
  5302  \X215:Skip next character, give error if not `\.{@}'\X;\2\6
  5303  \&{if} $\|b\I\.{"|"}$ \1\&{then}\5
  5304  $\\{out}(\|b)$\6
  5305  \4\&{else} \&{begin} \37\X216:Copy the \PASCAL\ text into $\\{buffer}[(%
  5306  \\{limit}+1)\to\|j]$\X;\6
  5307  $\\{save\_loc}\K\\{loc}$;\5
  5308  $\\{save\_limit}\K\\{limit}$;\5
  5309  $\\{loc}\K\\{limit}+2$;\5
  5310  $\\{limit}\K\|j+1$;\5
  5311  $\\{buffer}[\\{limit}]\K\.{"|"}$;\5
  5312  \\{output\_Pascal};\5
  5313  $\\{loc}\K\\{save\_loc}$;\5
  5314  $\\{limit}\K\\{save\_limit}$;\6
  5315  \&{end};\2\6
  5316  \&{end}\2\par
  5317  \U213.\fi
  5318  
  5319  \M215. \P$\X215:Skip next character, give error if not `\.{@}'\X\S$\6
  5320  \&{begin} \37\&{if} $\\{byte\_mem}[\|w,\39\|k]\I\.{"@"}$ \1\&{then}\6
  5321  \&{begin} \37$\\{print\_nl}(\.{\'!\ Illegal\ control\ code\ in\ section\ name:%
  5322  \'})$;\5
  5323  $\\{print\_nl}(\.{\'<\'})$;\5
  5324  $\\{print\_id}(\\{cur\_mod\_name})$;\5
  5325  $\\{print}(\.{\'>\ \'})$;\5
  5326  \\{mark\_error};\6
  5327  \&{end};\2\6
  5328  $\\{incr}(\|k)$;\6
  5329  \&{end}\par
  5330  \U214.\fi
  5331  
  5332  \M216. The \PASCAL\ text enclosed in \pb\ should not contain `\v' characters,
  5333  except within strings. We put a `\v' at the front of the buffer, so that an
  5334  error message that displays the whole buffer will look a little bit sensible.
  5335  The variable \\{string\_delimiter} is zero outside of strings, otherwise it
  5336  equals the delimiter that began the string being copied.
  5337  
  5338  \Y\P$\4\X216:Copy the \PASCAL\ text into $\\{buffer}[(\\{limit}+1)\to\|j]$\X\S$%
  5339  \6
  5340  $\|j\K\\{limit}+1$;\5
  5341  $\\{buffer}[\|j]\K\.{"|"}$;\5
  5342  $\\{string\_delimiter}\K0$;\6
  5343  \~ \1\&{loop}\ \&{begin} \37\&{if} $\|k\G\\{k\_limit}$ \1\&{then}\6
  5344  \&{begin} \37$\\{print\_nl}(\.{\'!\ Pascal\ text\ in\ section\ name\ didn\'}\.{%
  5345  \'t\ end:\'})$;\5
  5346  $\\{print\_nl}(\.{\'<\'})$;\5
  5347  $\\{print\_id}(\\{cur\_mod\_name})$;\5
  5348  $\\{print}(\.{\'>\ \'})$;\5
  5349  \\{mark\_error};\5
  5350  \&{goto} \37\\{found};\6
  5351  \&{end};\2\6
  5352  $\|b\K\\{byte\_mem}[\|w,\39\|k]$;\5
  5353  $\\{incr}(\|k)$;\6
  5354  \&{if} $\|b=\.{"@"}$ \1\&{then}\5
  5355  \X217:Copy a control code into the buffer\X\6
  5356  \4\&{else} \&{begin} \37\&{if} $(\|b=\.{""}\.{""})\V(\|b=\.{"\'"})$ \1\&{then}\6
  5357  \&{if} $\\{string\_delimiter}=0$ \1\&{then}\5
  5358  $\\{string\_delimiter}\K\|b$\6
  5359  \4\&{else} \&{if} $\\{string\_delimiter}=\|b$ \1\&{then}\5
  5360  $\\{string\_delimiter}\K0$;\2\2\2\6
  5361  \&{if} $(\|b\I\.{"|"})\V(\\{string\_delimiter}\I0)$ \1\&{then}\6
  5362  \&{begin} \37\&{if} $\|j>\\{long\_buf\_size}-3$ \1\&{then}\5
  5363  $\\{overflow}(\.{\'buffer\'})$;\2\6
  5364  $\\{incr}(\|j)$;\5
  5365  $\\{buffer}[\|j]\K\|b$;\6
  5366  \&{end}\6
  5367  \4\&{else} \&{goto} \37\\{found};\2\6
  5368  \&{end};\2\6
  5369  \&{end};\2\6
  5370  \4\\{found}: \37\par
  5371  \U214.\fi
  5372  
  5373  \M217. \P$\X217:Copy a control code into the buffer\X\S$\6
  5374  \&{begin} \37\&{if} $\|j>\\{long\_buf\_size}-4$ \1\&{then}\5
  5375  $\\{overflow}(\.{\'buffer\'})$;\2\6
  5376  $\\{buffer}[\|j+1]\K\.{"@"}$;\5
  5377  $\\{buffer}[\|j+2]\K\\{byte\_mem}[\|w,\39\|k]$;\5
  5378  $\|j\K\|j+2$;\5
  5379  $\\{incr}(\|k)$;\6
  5380  \&{end}\par
  5381  \U216.\fi
  5382  
  5383  \N218.  Phase two processing.
  5384  We have assembled enough pieces of the puzzle in order to be ready to specify
  5385  the processing in \.{WEAVE}'s main pass over the source file. Phase two
  5386  is analogous to phase one, except that more work is involved because we must
  5387  actually output the \TeX\ material instead of merely looking at the
  5388  \.{WEB} specifications.
  5389  
  5390  \Y\P$\4\X218:Phase II: Read all the text again and translate it to \TeX\ form\X%
  5391  \S$\6
  5392  \\{reset\_input};\5
  5393  $\\{print\_nl}(\.{\'Writing\ the\ output\ file...\'})$;\5
  5394  $\\{module\_count}\K0$;\5
  5395  \\{copy\_limbo};\5
  5396  \\{finish\_line};\5
  5397  $\\{flush\_buffer}(0,\39\\{false},\39\\{false})$;\C{insert a blank line, it
  5398  looks nice}\6
  5399  \&{while} $\R\\{input\_has\_ended}$ \1\&{do}\5
  5400  \X220:Translate the \(current module\X\2\par
  5401  \U261\*.\fi
  5402  
  5403  \M219. The output file will contain the control sequence \.{\\Y} between
  5404  non-null
  5405  sections of a module, e.g., between the \TeX\ and definition parts if both
  5406  are nonempty. This puts a little white space between the parts when they are
  5407  printed. However, we don't want \.{\\Y} to occur between two definitions
  5408  within a single module. The variables \\{out\_line} or \\{out\_ptr} will
  5409  change if a section is non-null, so the following macros `\\{save\_position}'
  5410  and `\\{emit\_space\_if\_needed}' are able to handle the situation:
  5411  
  5412  \Y\P\D \37$\\{save\_position}\S\\{save\_line}\K\\{out\_line}$;\5
  5413  $\\{save\_place}\K\\{out\_ptr}$\par
  5414  \P\D \37$\\{emit\_space\_if\_needed}\S$\1\6
  5415  \&{if} $(\\{save\_line}\I\\{out\_line})\V(\\{save\_place}\I\\{out\_ptr})$ \1%
  5416  \&{then}\5
  5417  $\\{out2}(\.{"\\"})(\.{"Y"})$\2\2\par
  5418  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  5419  \4\\{save\_line}: \37\\{integer};\C{former value of \\{out\_line}}\6
  5420  \4\\{save\_place}: \37\\{sixteen\_bits};\C{former value of \\{out\_ptr}}\par
  5421  \fi
  5422  
  5423  \M220. \P$\X220:Translate the \(current module\X\S$\6
  5424  \&{begin} \37$\\{incr}(\\{module\_count})$;\6
  5425  \X221:Output the code for the beginning of a new module\X;\6
  5426  \\{save\_position};\6
  5427  \X222:Translate the \TeX\ part of the current module\X;\6
  5428  \X225:Translate the \(definition part of the current module\X;\6
  5429  \X230:Translate the \PASCAL\ part of the current module\X;\6
  5430  \X233:Show cross references to this module\X;\6
  5431  \X238:Output the code for the end of a module\X;\6
  5432  \&{end}\par
  5433  \U218.\fi
  5434  
  5435  \M221. Modules beginning with the \.{WEB} control sequence `\.{@\ }' start in
  5436  the
  5437  output with the \TeX\ control sequence `\.{\\M}', followed by the module
  5438  number. Similarly, `\.{@*}' modules lead to the control sequence `\.{\\N}'.
  5439  If this is a changed module, we put \.{*} just before the module number.
  5440  
  5441  \Y\P$\4\X221:Output the code for the beginning of a new module\X\S$\6
  5442  $\\{out}(\.{"\\"})$;\6
  5443  \&{if} $\\{buffer}[\\{loc}-1]\I\.{"*"}$ \1\&{then}\5
  5444  $\\{out}(\.{"M"})$\6
  5445  \4\&{else} \&{begin} \37$\\{out}(\.{"N"})$;\5
  5446  $\\{print}(\.{\'*\'},\39\\{module\_count}:1)$;\5
  5447  \\{update\_terminal};\C{print a progress report}\6
  5448  \&{end};\2\6
  5449  $\\{out\_mod}(\\{module\_count})$;\5
  5450  $\\{out2}(\.{"."})(\.{"\ "})$\par
  5451  \U220.\fi
  5452  
  5453  \M222. In the \TeX\ part of a module, we simply copy the source text, except
  5454  that
  5455  index entries are not copied and \PASCAL\ text within \pb\ is translated.
  5456  
  5457  \Y\P$\4\X222:Translate the \TeX\ part of the current module\X\S$\6
  5458  \1\&{repeat} \37$\\{next\_control}\K\\{copy\_TeX}$;\6
  5459  \&{case} $\\{next\_control}$ \1\&{of}\6
  5460  \4\.{"|"}: \37\&{begin} \37\\{init\_stack};\5
  5461  \\{output\_Pascal};\6
  5462  \&{end};\6
  5463  \4\.{"@"}: \37$\\{out}(\.{"@"})$;\6
  5464  \4\\{octal}: \37\X223:Translate an octal constant appearing in \TeX\ text\X;\6
  5465  \4\\{hex}: \37\X224:Translate a hexadecimal constant appearing in \TeX\ text\X;%
  5466  \6
  5467  \4$\\{TeX\_string},\39\\{xref\_roman},\39\\{xref\_wildcard},\39\\{xref%
  5468  \_typewriter},\39\\{module\_name}$: \37\&{begin} \37$\\{loc}\K\\{loc}-2$;\5
  5469  $\\{next\_control}\K\\{get\_next}$;\C{skip to \.{@>}}\6
  5470  \&{if} $\\{next\_control}=\\{TeX\_string}$ \1\&{then}\5
  5471  $\\{err\_print}(\.{\'!\ TeX\ string\ should\ be\ in\ Pascal\ text\ only\'})$;\2%
  5472  \6
  5473  \&{end};\6
  5474  \4$\\{begin\_comment},\39\\{end\_comment},\39\\{check\_sum},\39\\{thin\_space},%
  5475  \39\\{math\_break},\39\\{line\_break},\39\\{big\_line\_break},\39\\{no\_line%
  5476  \_break},\39\\{join},\39\\{pseudo\_semi}$: \37$\\{err\_print}(\.{\'!\ You\ can%
  5477  \'}\.{\'t\ do\ that\ in\ TeX\ text\'})$;\6
  5478  \4\&{othercases} \37\\{do\_nothing}\2\6
  5479  \&{endcases};\6
  5480  \4\&{until}\5
  5481  $\\{next\_control}\G\\{format}$\2\par
  5482  \U220.\fi
  5483  
  5484  \M223. \P$\X223:Translate an octal constant appearing in \TeX\ text\X\S$\6
  5485  \&{begin} \37$\\{out3}(\.{"\\"})(\.{"O"})(\.{"\{"})$;\6
  5486  \&{while} $(\\{buffer}[\\{loc}]\G\.{"0"})\W(\\{buffer}[\\{loc}]\L\.{"7"})$ \1%
  5487  \&{do}\6
  5488  \&{begin} \37$\\{out}(\\{buffer}[\\{loc}])$;\5
  5489  $\\{incr}(\\{loc})$;\6
  5490  \&{end};\C{since $\\{buffer}[\\{limit}]=\.{"\ "}$, this loop will end}\2\6
  5491  $\\{out}(\.{"\}"})$;\6
  5492  \&{end}\par
  5493  \U222.\fi
  5494  
  5495  \M224. \P$\X224:Translate a hexadecimal constant appearing in \TeX\ text\X\S$\6
  5496  \&{begin} \37$\\{out3}(\.{"\\"})(\.{"H"})(\.{"\{"})$;\6
  5497  \&{while} $((\\{buffer}[\\{loc}]\G\.{"0"})\W(\\{buffer}[\\{loc}]\L\.{"9"}))\V%
  5498  \30((\\{buffer}[\\{loc}]\G\.{"A"})\W(\\{buffer}[\\{loc}]\L\.{"F"}))$ \1\&{do}\6
  5499  \&{begin} \37$\\{out}(\\{buffer}[\\{loc}])$;\5
  5500  $\\{incr}(\\{loc})$;\6
  5501  \&{end};\2\6
  5502  $\\{out}(\.{"\}"})$;\6
  5503  \&{end}\par
  5504  \U222.\fi
  5505  
  5506  \M225. When we get to the following code we have $\\{next\_control}\G%
  5507  \\{format}$, and
  5508  the token memory is in its initial empty state.
  5509  
  5510  \Y\P$\4\X225:Translate the \(definition part of the current module\X\S$\6
  5511  \&{if} $\\{next\_control}\L\\{definition}$ \1\&{then}\C{definition part
  5512  non-empty}\6
  5513  \&{begin} \37\\{emit\_space\_if\_needed};\5
  5514  \\{save\_position};\6
  5515  \&{end};\2\6
  5516  \&{while} $\\{next\_control}\L\\{definition}$ \1\&{do}\C{\\{format} or %
  5517  \\{definition}}\6
  5518  \&{begin} \37\\{init\_stack};\6
  5519  \&{if} $\\{next\_control}=\\{definition}$ \1\&{then}\5
  5520  \X227:Start a macro definition\X\6
  5521  \4\&{else} \X228:Start a format definition\X;\2\6
  5522  \\{outer\_parse};\5
  5523  \\{finish\_Pascal};\6
  5524  \&{end}\2\par
  5525  \U220.\fi
  5526  
  5527  \M226. The \\{finish\_Pascal} procedure outputs the translation of the current
  5528  scraps, preceded by the control sequence `\.{\\P}' and followed by the
  5529  control sequence `\.{\\par}'. It also restores the token and scrap
  5530  memories to their initial empty state.
  5531  
  5532  A \\{force} token is appended to the current scraps before translation
  5533  takes place, so that the translation will normally end with \.{\\6} or
  5534  \.{\\7} (the \TeX\ macros for \\{force} and \\{big\_force}). This \.{\\6} or
  5535  \.{\\7} is replaced by the concluding \.{\\par} or by \.{\\Y\\par}.
  5536  
  5537  \Y\P\4\&{procedure}\1\  \37\\{finish\_Pascal};\C{finishes a definition or a %
  5538  \PASCAL\ part}\6
  5539  \4\&{var} \37\|p: \37\\{text\_pointer};\C{translation of the scraps}\2\6
  5540  \&{begin} \37$\\{out2}(\.{"\\"})(\.{"P"})$;\5
  5541  $\\{app\_tok}(\\{force})$;\5
  5542  \\{app\_comment};\5
  5543  $\|p\K\\{translate}$;\5
  5544  $\\{app}(\|p+\\{tok\_flag})$;\5
  5545  \\{make\_output};\C{output the list}\6
  5546  \&{if} $\\{out\_ptr}>1$ \1\&{then}\6
  5547  \&{if} $\\{out\_buf}[\\{out\_ptr}-1]=\.{"\\"}$ \1\&{then}\6
  5548  \&{if} $\\{out\_buf}[\\{out\_ptr}]=\.{"6"}$ \1\&{then}\5
  5549  $\\{out\_ptr}\K\\{out\_ptr}-2$\6
  5550  \4\&{else} \&{if} $\\{out\_buf}[\\{out\_ptr}]=\.{"7"}$ \1\&{then}\5
  5551  $\\{out\_buf}[\\{out\_ptr}]\K\.{"Y"}$;\2\2\2\2\6
  5552  $\\{out4}(\.{"\\"})(\.{"p"})(\.{"a"})(\.{"r"})$;\5
  5553  \\{finish\_line};\6
  5554  \&{stat} \37\&{if} $\\{text\_ptr}>\\{max\_txt\_ptr}$ \1\&{then}\5
  5555  $\\{max\_txt\_ptr}\K\\{text\_ptr}$;\2\6
  5556  \&{if} $\\{tok\_ptr}>\\{max\_tok\_ptr}$ \1\&{then}\5
  5557  $\\{max\_tok\_ptr}\K\\{tok\_ptr}$;\2\6
  5558  \&{if} $\\{scrap\_ptr}>\\{max\_scr\_ptr}$ \1\&{then}\5
  5559  $\\{max\_scr\_ptr}\K\\{scrap\_ptr}$;\2\6
  5560  \&{tats}\6
  5561  $\\{tok\_ptr}\K1$;\5
  5562  $\\{text\_ptr}\K1$;\5
  5563  $\\{scrap\_ptr}\K0$;\C{forget the tokens and the scraps}\6
  5564  \&{end};\par
  5565  \fi
  5566  
  5567  \M227. \P$\X227:Start a macro definition\X\S$\6
  5568  \&{begin} \37$\\{sc2}(\.{"\\"})(\.{"D"})(\\{intro})$;\C{this will produce `%
  5569  \&{define }'}\6
  5570  $\\{next\_control}\K\\{get\_next}$;\6
  5571  \&{if} $\\{next\_control}\I\\{identifier}$ \1\&{then}\5
  5572  $\\{err\_print}(\.{\'!\ Improper\ macro\ definition\'})$\6
  5573  \4\&{else} $\\{sc1}(\\{id\_flag}+\\{id\_lookup}(\\{normal}))(\\{math})$;\2\6
  5574  $\\{next\_control}\K\\{get\_next}$;\6
  5575  \&{end}\par
  5576  \U225.\fi
  5577  
  5578  \M228. \P$\X228:Start a format definition\X\S$\6
  5579  \&{begin} \37$\\{sc2}(\.{"\\"})(\.{"F"})(\\{intro})$;\C{this will produce `%
  5580  \&{format }'}\6
  5581  $\\{next\_control}\K\\{get\_next}$;\6
  5582  \&{if} $\\{next\_control}=\\{identifier}$ \1\&{then}\6
  5583  \&{begin} \37$\\{sc1}(\\{id\_flag}+\\{id\_lookup}(\\{normal}))(\\{math})$;\5
  5584  $\\{next\_control}\K\\{get\_next}$;\6
  5585  \&{if} $\\{next\_control}=\\{equivalence\_sign}$ \1\&{then}\6
  5586  \&{begin} \37$\\{sc2}(\.{"\\"})(\.{"S"})(\\{math})$;\C{output an equivalence
  5587  sign}\6
  5588  $\\{next\_control}\K\\{get\_next}$;\6
  5589  \&{if} $\\{next\_control}=\\{identifier}$ \1\&{then}\6
  5590  \&{begin} \37$\\{sc1}(\\{id\_flag}+\\{id\_lookup}(\\{normal}))(\\{math})$;\5
  5591  $\\{sc0}(\\{semi})$;\C{insert an invisible semicolon}\6
  5592  $\\{next\_control}\K\\{get\_next}$;\6
  5593  \&{end};\2\6
  5594  \&{end};\2\6
  5595  \&{end};\2\6
  5596  \&{if} $\\{scrap\_ptr}\I5$ \1\&{then}\5
  5597  $\\{err\_print}(\.{\'!\ Improper\ format\ definition\'})$;\2\6
  5598  \&{end}\par
  5599  \U225.\fi
  5600  
  5601  \M229. Finally, when the \TeX\ and definition parts have been treated, we have
  5602  $\\{next\_control}\G\\{begin\_Pascal}$. We will make the global variable %
  5603  \\{this\_module}
  5604  point to the current module name, if it has a name.
  5605  
  5606  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  5607  \4\\{this\_module}: \37\\{name\_pointer};\C{the current module name, or zero}%
  5608  \par
  5609  \fi
  5610  
  5611  \M230. \P$\X230:Translate the \PASCAL\ part of the current module\X\S$\6
  5612  $\\{this\_module}\K0$;\6
  5613  \&{if} $\\{next\_control}\L\\{module\_name}$ \1\&{then}\6
  5614  \&{begin} \37\\{emit\_space\_if\_needed};\5
  5615  \\{init\_stack};\6
  5616  \&{if} $\\{next\_control}=\\{begin\_Pascal}$ \1\&{then}\5
  5617  $\\{next\_control}\K\\{get\_next}$\6
  5618  \4\&{else} \&{begin} \37$\\{this\_module}\K\\{cur\_module}$;\5
  5619  \X231:Check that $=$ or $\S$ follows this module name, and emit the scraps to
  5620  start the module definition\X;\6
  5621  \&{end};\2\6
  5622  \&{while} $\\{next\_control}\L\\{module\_name}$ \1\&{do}\6
  5623  \&{begin} \37\\{outer\_parse};\5
  5624  \X232:Emit the scrap for a module name if present\X;\6
  5625  \&{end};\2\6
  5626  \\{finish\_Pascal};\6
  5627  \&{end}\2\par
  5628  \U220.\fi
  5629  
  5630  \M231. \P$\X231:Check that $=$ or $\S$ follows this module name, and emit the
  5631  scraps to start the module definition\X\S$\6
  5632  \1\&{repeat} \37$\\{next\_control}\K\\{get\_next}$;\6
  5633  \4\&{until}\5
  5634  $\\{next\_control}\I\.{"+"}$;\C{allow optional `\.{+=}'}\2\6
  5635  \&{if} $(\\{next\_control}\I\.{"="})\W(\\{next\_control}\I\\{equivalence%
  5636  \_sign})$ \1\&{then}\5
  5637  $\\{err\_print}(\.{\'!\ You\ need\ an\ =\ sign\ after\ the\ section\ name\'})$\6
  5638  \4\&{else} $\\{next\_control}\K\\{get\_next}$;\2\6
  5639  \&{if} $\\{out\_ptr}>1$ \1\&{then}\6
  5640  \&{if} $(\\{out\_buf}[\\{out\_ptr}]=\.{"Y"})\W(\\{out\_buf}[\\{out\_ptr}-1]=%
  5641  \.{"\\"})$ \1\&{then}\6
  5642  \&{begin} \37$\\{app}(\\{backup})$;\C{the module name will be flush left}\6
  5643  \&{end};\2\2\6
  5644  $\\{sc1}(\\{mod\_flag}+\\{this\_module})(\\{mod\_scrap})$;\5
  5645  $\\{cur\_xref}\K\\{xref}[\\{this\_module}]$;\6
  5646  \&{if} $\\{num}(\\{cur\_xref})\I\\{module\_count}+\\{def\_flag}$ \1\&{then}\6
  5647  \&{begin} \37$\\{sc3}(\\{math\_rel})(\.{"+"})(\.{"\}"})(\\{math})$;\C{module
  5648  name is multiply defined}\6
  5649  $\\{this\_module}\K0$;\C{so we won't give cross-reference info here}\6
  5650  \&{end};\2\6
  5651  $\\{sc2}(\.{"\\"})(\.{"S"})(\\{math})$;\C{output an equivalence sign}\6
  5652  $\\{sc1}(\\{force})(\\{semi})$;\C{this forces a line break unless `\.{@+}'
  5653  follows}\par
  5654  \U230.\fi
  5655  
  5656  \M232. \P$\X232:Emit the scrap for a module name if present\X\S$\6
  5657  \&{if} $\\{next\_control}<\\{module\_name}$ \1\&{then}\6
  5658  \&{begin} \37$\\{err\_print}(\.{\'!\ You\ can\'}\.{\'t\ do\ that\ in\ Pascal\
  5659  text\'})$;\5
  5660  $\\{next\_control}\K\\{get\_next}$;\6
  5661  \&{end}\6
  5662  \4\&{else} \&{if} $\\{next\_control}=\\{module\_name}$ \1\&{then}\6
  5663  \&{begin} \37$\\{sc1}(\\{mod\_flag}+\\{cur\_module})(\\{mod\_scrap})$;\5
  5664  $\\{next\_control}\K\\{get\_next}$;\6
  5665  \&{end}\2\2\par
  5666  \U230.\fi
  5667  
  5668  \M233. Cross references relating to a named module are given after the module
  5669  ends.
  5670  
  5671  \Y\P$\4\X233:Show cross references to this module\X\S$\6
  5672  \&{if} $\\{this\_module}>0$ \1\&{then}\6
  5673  \&{begin} \37\X235:Rearrange the list pointed to by \\{cur\_xref}\X;\6
  5674  $\\{footnote}(\\{def\_flag})$;\5
  5675  $\\{footnote}(0)$;\6
  5676  \&{end}\2\par
  5677  \U220.\fi
  5678  
  5679  \M234. To rearrange the order of the linked list of cross references, we need
  5680  four more variables that point to cross reference entries.  We'll end up
  5681  with a list pointed to by \\{cur\_xref}.
  5682  
  5683  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  5684  \4$\\{next\_xref},\39\\{this\_xref},\39\\{first\_xref},\39\\{mid\_xref}$: \37%
  5685  \\{xref\_number};\C{pointer variables for rearranging a list}\par
  5686  \fi
  5687  
  5688  \M235. We want to rearrange the cross reference list so that all the entries
  5689  with
  5690  \\{def\_flag} come first, in ascending order; then come all the other
  5691  entries, in ascending order.  There may be no entries in either one or both
  5692  of these categories.
  5693  
  5694  \Y\P$\4\X235:Rearrange the list pointed to by \\{cur\_xref}\X\S$\6
  5695  $\\{first\_xref}\K\\{xref}[\\{this\_module}]$;\5
  5696  $\\{this\_xref}\K\\{xlink}(\\{first\_xref})$;\C{bypass current module number}\6
  5697  \&{if} $\\{num}(\\{this\_xref})>\\{def\_flag}$ \1\&{then}\6
  5698  \&{begin} \37$\\{mid\_xref}\K\\{this\_xref}$;\5
  5699  $\\{cur\_xref}\K0$;\C{this value doesn't matter}\6
  5700  \1\&{repeat} \37$\\{next\_xref}\K\\{xlink}(\\{this\_xref})$;\5
  5701  $\\{xlink}(\\{this\_xref})\K\\{cur\_xref}$;\5
  5702  $\\{cur\_xref}\K\\{this\_xref}$;\5
  5703  $\\{this\_xref}\K\\{next\_xref}$;\6
  5704  \4\&{until}\5
  5705  $\\{num}(\\{this\_xref})\L\\{def\_flag}$;\2\6
  5706  $\\{xlink}(\\{first\_xref})\K\\{cur\_xref}$;\6
  5707  \&{end}\6
  5708  \4\&{else} $\\{mid\_xref}\K0$;\C{first list null}\2\6
  5709  $\\{cur\_xref}\K0$;\6
  5710  \&{while} $\\{this\_xref}\I0$ \1\&{do}\6
  5711  \&{begin} \37$\\{next\_xref}\K\\{xlink}(\\{this\_xref})$;\5
  5712  $\\{xlink}(\\{this\_xref})\K\\{cur\_xref}$;\5
  5713  $\\{cur\_xref}\K\\{this\_xref}$;\5
  5714  $\\{this\_xref}\K\\{next\_xref}$;\6
  5715  \&{end};\2\6
  5716  \&{if} $\\{mid\_xref}>0$ \1\&{then}\5
  5717  $\\{xlink}(\\{mid\_xref})\K\\{cur\_xref}$\6
  5718  \4\&{else} $\\{xlink}(\\{first\_xref})\K\\{cur\_xref}$;\2\6
  5719  $\\{cur\_xref}\K\\{xlink}(\\{first\_xref})$\par
  5720  \U233.\fi
  5721  
  5722  \M236. The \\{footnote} procedure gives cross reference information about
  5723  multiply defined module names (if the \\{flag} parameter is \\{def\_flag}), or
  5724  about
  5725  the uses of a module name (if the \\{flag} parameter is zero). It assumes that
  5726  \\{cur\_xref} points to the first cross-reference entry of interest, and it
  5727  leaves \\{cur\_xref} pointing to the first element not printed.  Typical
  5728  outputs:
  5729  `\.{\\A101.}'; `\.{\\Us370\\ET1009.}'; `\.{\\As8, 27\\*, 51\\ETs64.}'.
  5730  
  5731  \Y\P\4\&{procedure}\1\  \37$\\{footnote}(\\{flag}:\\{sixteen\_bits})$;%
  5732  \C{outputs module cross-references}\6
  5733  \4\&{label} \37$\\{done},\39\\{exit}$;\6
  5734  \4\&{var} \37\|q: \37\\{xref\_number};\C{cross-reference pointer variable}\2\6
  5735  \&{begin} \37\&{if} $\\{num}(\\{cur\_xref})\L\\{flag}$ \1\&{then}\5
  5736  \&{return};\2\6
  5737  \\{finish\_line};\5
  5738  $\\{out}(\.{"\\"})$;\6
  5739  \&{if} $\\{flag}=0$ \1\&{then}\5
  5740  $\\{out}(\.{"U"})$\ \&{else} $\\{out}(\.{"A"})$;\2\6
  5741  \X237:Output all the module numbers on the reference list \\{cur\_xref}\X;\6
  5742  $\\{out}(\.{"."})$;\6
  5743  \4\\{exit}: \37\&{end};\par
  5744  \fi
  5745  
  5746  \M237. The following code distinguishes three cases, according as the number
  5747  of cross references is one, two, or more than two. Variable \|q points
  5748  to the first cross reference, and the last link is a zero.
  5749  
  5750  \Y\P$\4\X237:Output all the module numbers on the reference list \\{cur\_xref}%
  5751  \X\S$\6
  5752  $\|q\K\\{cur\_xref}$;\6
  5753  \&{if} $\\{num}(\\{xlink}(\|q))>\\{flag}$ \1\&{then}\5
  5754  $\\{out}(\.{"s"})$;\C{plural}\2\6
  5755  \~ \1\&{loop}\ \&{begin} \37$\\{out\_mod}(\\{num}(\\{cur\_xref})-\\{flag})$;\5
  5756  $\\{cur\_xref}\K\\{xlink}(\\{cur\_xref})$;\C{point to the next cross reference
  5757  to output}\6
  5758  \&{if} $\\{num}(\\{cur\_xref})\L\\{flag}$ \1\&{then}\5
  5759  \&{goto} \37\\{done};\2\6
  5760  \&{if} $\\{num}(\\{xlink}(\\{cur\_xref}))>\\{flag}$ \1\&{then}\5
  5761  $\\{out2}(\.{","})(\.{"\ "})$\C{not the last}\6
  5762  \4\&{else} \&{begin} \37$\\{out3}(\.{"\\"})(\.{"E"})(\.{"T"})$;\C{the last}\6
  5763  \&{if} $\\{cur\_xref}\I\\{xlink}(\|q)$ \1\&{then}\5
  5764  $\\{out}(\.{"s"})$;\C{the last of more than two}\2\6
  5765  \&{end};\2\6
  5766  \&{end};\2\6
  5767  \4\\{done}: \37\par
  5768  \U236.\fi
  5769  
  5770  \M238. \P$\X238:Output the code for the end of a module\X\S$\6
  5771  $\\{out3}(\.{"\\"})(\.{"f"})(\.{"i"})$;\5
  5772  \\{finish\_line};\5
  5773  $\\{flush\_buffer}(0,\39\\{false},\39\\{false})$;\C{insert a blank line, it
  5774  looks nice}\par
  5775  \U220.\fi
  5776  
  5777  \N239.  Phase three processing.
  5778  We are nearly finished! \.{WEAVE}'s only remaining task is to write out the
  5779  index, after sorting the identifiers and index entries.
  5780  
  5781  \Y\P$\4\X239:Phase III: Output the cross-reference index\X\S$\6
  5782  $\\{phase\_three}\K\\{true}$;\5
  5783  $\\{print\_nl}(\.{\'Writing\ the\ index...\'})$;\6
  5784  \&{if} $\\{change\_exists}$ \1\&{then}\6
  5785  \&{begin} \37\\{finish\_line};\5
  5786  \X241:Tell about changed modules\X;\6
  5787  \&{end};\2\6
  5788  \\{finish\_line};\5
  5789  $\\{out4}(\.{"\\"})(\.{"i"})(\.{"n"})(\.{"x"})$;\5
  5790  \\{finish\_line};\5
  5791  \X243:Do the first pass of sorting\X;\6
  5792  \X250:Sort and output the index\X;\6
  5793  $\\{out4}(\.{"\\"})(\.{"f"})(\.{"i"})(\.{"n"})$;\5
  5794  \\{finish\_line};\5
  5795  \X257:Output all the module names\X;\6
  5796  $\\{out4}(\.{"\\"})(\.{"c"})(\.{"o"})(\.{"n"})$;\5
  5797  \\{finish\_line};\5
  5798  $\\{print}(\.{\'Done.\'})$;\par
  5799  \U261\*.\fi
  5800  
  5801  \M240. Just before the index comes a list of all the changed modules, including
  5802  the index module itself.
  5803  
  5804  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  5805  \4\\{k\_module}: \37$0\to\\{max\_modules}$;\C{runs through the modules}\par
  5806  \fi
  5807  
  5808  \M241. \P$\X241:Tell about changed modules\X\S$\6
  5809  \&{begin} \37\C{remember that the index is already marked as changed}\6
  5810  $\\{k\_module}\K1$;\5
  5811  $\\{out4}(\.{"\\"})(\.{"c"})(\.{"h"})(\.{"\ "})$;\6
  5812  \&{while} $\\{k\_module}<\\{module\_count}$ \1\&{do}\6
  5813  \&{begin} \37\&{if} $\\{changed\_module}[\\{k\_module}]$ \1\&{then}\6
  5814  \&{begin} \37$\\{out\_mod}(\\{k\_module})$;\5
  5815  $\\{out2}(\.{","})(\.{"\ "})$;\6
  5816  \&{end};\2\6
  5817  $\\{incr}(\\{k\_module})$;\6
  5818  \&{end};\2\6
  5819  $\\{out\_mod}(\\{k\_module})$;\5
  5820  $\\{out}(\.{"."})$;\6
  5821  \&{end}\par
  5822  \U239.\fi
  5823  
  5824  \M242. A left-to-right radix sorting method is used, since this makes it easy
  5825  to
  5826  adjust the collating sequence and since the running time will be at worst
  5827  proportional to the total length of all entries in the index. We put the
  5828  identifiers into 230 different lists based on their first characters.
  5829  (Uppercase letters are put into the same list as the corresponding lowercase
  5830  letters, since we want to have `$t<\\{TeX}<\&{to}$'.) The
  5831  list for character \|c begins at location $\\{bucket}[\|c]$ and continues
  5832  through
  5833  the \\{blink} array.
  5834  
  5835  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  5836  \4\\{bucket}: \37\&{array} $[\\{ASCII\_code}]$ \1\&{of}\5
  5837  \\{name\_pointer};\2\6
  5838  \4\\{next\_name}: \37\\{name\_pointer};\C{successor of \\{cur\_name} when
  5839  sorting}\6
  5840  \4\|c: \37\\{ASCII\_code};\C{index into \\{bucket}}\6
  5841  \4\|h: \37$0\to\\{hash\_size}$;\C{index into \\{hash}}\6
  5842  \4\\{blink}: \37\&{array} $[0\to\\{max\_names}]$ \1\&{of}\5
  5843  \\{sixteen\_bits};\C{links in the buckets}\2\par
  5844  \fi
  5845  
  5846  \M243. To begin the sorting, we go through all the hash lists and put each
  5847  entry
  5848  having a nonempty cross-reference list into the proper bucket.
  5849  
  5850  \Y\P$\4\X243:Do the first pass of sorting\X\S$\6
  5851  \&{for} $\|c\K0\mathrel{\&{to}}255$ \1\&{do}\5
  5852  $\\{bucket}[\|c]\K0$;\2\6
  5853  \&{for} $\|h\K0\mathrel{\&{to}}\\{hash\_size}-1$ \1\&{do}\6
  5854  \&{begin} \37$\\{next\_name}\K\\{hash}[\|h]$;\6
  5855  \&{while} $\\{next\_name}\I0$ \1\&{do}\6
  5856  \&{begin} \37$\\{cur\_name}\K\\{next\_name}$;\5
  5857  $\\{next\_name}\K\\{link}[\\{cur\_name}]$;\6
  5858  \&{if} $\\{xref}[\\{cur\_name}]\I0$ \1\&{then}\6
  5859  \&{begin} \37$\|c\K\\{byte\_mem}[\\{cur\_name}\mathbin{\&{mod}}\\{ww},\39%
  5860  \\{byte\_start}[\\{cur\_name}]]$;\6
  5861  \&{if} $(\|c\L\.{"Z"})\W(\|c\G\.{"A"})$ \1\&{then}\5
  5862  $\|c\K\|c+\O{40}$;\2\6
  5863  $\\{blink}[\\{cur\_name}]\K\\{bucket}[\|c]$;\5
  5864  $\\{bucket}[\|c]\K\\{cur\_name}$;\6
  5865  \&{end};\2\6
  5866  \&{end};\2\6
  5867  \&{end}\2\par
  5868  \U239.\fi
  5869  
  5870  \M244. During the sorting phase we shall use the \\{cat} and \\{trans} arrays
  5871  from
  5872  \.{WEAVE}'s parsing algorithm and rename them \\{depth} and \\{head}. They now
  5873  represent a stack of identifier lists for all the index entries that have
  5874  not yet been output. The variable \\{sort\_ptr} tells how many such lists are
  5875  present; the lists are output in reverse order (first \\{sort\_ptr}, then
  5876  $\\{sort\_ptr}-1$, etc.). The \|jth list starts at $\\{head}[\|j]$, and if the
  5877  first
  5878  \|k characters of all entries on this list are known to be equal we have
  5879  $\\{depth}[\|j]=\|k$.
  5880  
  5881  \Y\P\D \37$\\{depth}\S\\{cat}$\C{reclaims memory that is no longer needed for
  5882  parsing}\par
  5883  \P\D \37$\\{head}\S\\{trans}$\C{ditto}\par
  5884  \P\D \37$\\{sort\_ptr}\S\\{scrap\_ptr}$\C{ditto}\par
  5885  \P\D \37$\\{max\_sorts}\S\\{max\_scraps}$\C{ditto}\par
  5886  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  5887  \4\\{cur\_depth}: \37\\{eight\_bits};\C{depth of current buckets}\6
  5888  \4\\{cur\_byte}: \37$0\to\\{max\_bytes}$;\C{index into \\{byte\_mem}}\6
  5889  \4\\{cur\_bank}: \37$0\to\\{ww}-1$;\C{row of \\{byte\_mem}}\6
  5890  \4\\{cur\_val}: \37\\{sixteen\_bits};\C{current cross reference number}\6
  5891  \&{stat} \37\\{max\_sort\_ptr}: \37$0\to\\{max\_sorts}$;\ \&{tats}\C{largest
  5892  value of \\{sort\_ptr}}\par
  5893  \fi
  5894  
  5895  \M245. \P$\X10:Set initial values\X\mathrel{+}\S$\6
  5896  \&{stat} \37$\\{max\_sort\_ptr}\K0$;\ \&{tats}\par
  5897  \fi
  5898  
  5899  \M246. The desired alphabetic order is specified by the \\{collate} array;
  5900  namely,
  5901  $\\{collate}[0]<\\{collate}[1]<\hbox{$\cdots$}<\\{collate}[229]$.
  5902  
  5903  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  5904  \4\\{collate}: \37\&{array} $[0\to229]$ \1\&{of}\5
  5905  \\{ASCII\_code};\C{collation order}\2\par
  5906  \fi
  5907  
  5908  \M247. \P$\X16:Local variables for initialization\X\mathrel{+}\S$\6
  5909  \4\|c: \37\\{ASCII\_code};\C{used to initialize \\{collate}}\par
  5910  \fi
  5911  
  5912  \M248. We use the order $\hbox{null}<\.\ <\hbox{other characters}<\.\_<
  5913  \.A=\.a<\cdots<\.Z=\.z<\.0<\cdots<\.9.$
  5914  
  5915  \Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
  5916  $\\{collate}[0]\K0$;\5
  5917  $\\{collate}[1]\K\.{"\ "}$;\6
  5918  \&{for} $\|c\K1\mathrel{\&{to}}\.{"\ "}-1$ \1\&{do}\5
  5919  $\\{collate}[\|c+1]\K\|c$;\2\6
  5920  \&{for} $\|c\K\.{"\ "}+1\mathrel{\&{to}}\.{"0"}-1$ \1\&{do}\5
  5921  $\\{collate}[\|c]\K\|c$;\2\6
  5922  \&{for} $\|c\K\.{"9"}+1\mathrel{\&{to}}\.{"A"}-1$ \1\&{do}\5
  5923  $\\{collate}[\|c-10]\K\|c$;\2\6
  5924  \&{for} $\|c\K\.{"Z"}+1\mathrel{\&{to}}\.{"\_"}-1$ \1\&{do}\5
  5925  $\\{collate}[\|c-36]\K\|c$;\2\6
  5926  $\\{collate}[\.{"\_"}-36]\K\.{"\_"}+1$;\6
  5927  \&{for} $\|c\K\.{"z"}+1\mathrel{\&{to}}255$ \1\&{do}\5
  5928  $\\{collate}[\|c-63]\K\|c$;\2\6
  5929  $\\{collate}[193]\K\.{"\_"}$;\6
  5930  \&{for} $\|c\K\.{"a"}\mathrel{\&{to}}\.{"z"}$ \1\&{do}\5
  5931  $\\{collate}[\|c-\.{"a"}+194]\K\|c$;\2\6
  5932  \&{for} $\|c\K\.{"0"}\mathrel{\&{to}}\.{"9"}$ \1\&{do}\5
  5933  $\\{collate}[\|c-\.{"0"}+220]\K\|c$;\2\par
  5934  \fi
  5935  
  5936  \M249. Procedure \\{unbucket} goes through the buckets and adds nonempty lists
  5937  to the stack, using the collating sequence specified in the \\{collate} array.
  5938  The parameter to \\{unbucket} tells the current depth in the buckets.
  5939  Any two sequences that agree in their first 255 character positions are
  5940  regarded as identical.
  5941  
  5942  \Y\P\D \37$\\{infinity}=255$\C{$\infty$ (approximately)}\par
  5943  \Y\P\4\&{procedure}\1\  \37$\\{unbucket}(\|d:\\{eight\_bits})$;\C{empties
  5944  buckets having depth \|d}\6
  5945  \4\&{var} \37\|c: \37\\{ASCII\_code};\C{index into \\{bucket}}\2\6
  5946  \&{begin} \37\&{for} $\|c\K229\mathrel{\&{downto}}0$ \1\&{do}\6
  5947  \&{if} $\\{bucket}[\\{collate}[\|c]]>0$ \1\&{then}\6
  5948  \&{begin} \37\&{if} $\\{sort\_ptr}>\\{max\_sorts}$ \1\&{then}\5
  5949  $\\{overflow}(\.{\'sorting\'})$;\2\6
  5950  $\\{incr}(\\{sort\_ptr})$;\6
  5951  \&{stat} \37\&{if} $\\{sort\_ptr}>\\{max\_sort\_ptr}$ \1\&{then}\5
  5952  $\\{max\_sort\_ptr}\K\\{sort\_ptr}$;\2\ \&{tats}\6
  5953  \&{if} $\|c=0$ \1\&{then}\5
  5954  $\\{depth}[\\{sort\_ptr}]\K\\{infinity}$\6
  5955  \4\&{else} $\\{depth}[\\{sort\_ptr}]\K\|d$;\2\6
  5956  $\\{head}[\\{sort\_ptr}]\K\\{bucket}[\\{collate}[\|c]]$;\5
  5957  $\\{bucket}[\\{collate}[\|c]]\K0$;\6
  5958  \&{end};\2\2\6
  5959  \&{end};\par
  5960  \fi
  5961  
  5962  \M250. \P$\X250:Sort and output the index\X\S$\6
  5963  $\\{sort\_ptr}\K0$;\5
  5964  $\\{unbucket}(1)$;\6
  5965  \&{while} $\\{sort\_ptr}>0$ \1\&{do}\6
  5966  \&{begin} \37$\\{cur\_depth}\K\\{cat}[\\{sort\_ptr}]$;\6
  5967  \&{if} $(\\{blink}[\\{head}[\\{sort\_ptr}]]=0)\V(\\{cur\_depth}=\\{infinity})$ %
  5968  \1\&{then}\5
  5969  \X252:Output index entries for the list at \\{sort\_ptr}\X\6
  5970  \4\&{else} \X251:Split the list at \\{sort\_ptr} into further lists\X;\2\6
  5971  \&{end}\2\par
  5972  \U239.\fi
  5973  
  5974  \M251. \P$\X251:Split the list at \\{sort\_ptr} into further lists\X\S$\6
  5975  \&{begin} \37$\\{next\_name}\K\\{head}[\\{sort\_ptr}]$;\6
  5976  \1\&{repeat} \37$\\{cur\_name}\K\\{next\_name}$;\5
  5977  $\\{next\_name}\K\\{blink}[\\{cur\_name}]$;\5
  5978  $\\{cur\_byte}\K\\{byte\_start}[\\{cur\_name}]+\\{cur\_depth}$;\5
  5979  $\\{cur\_bank}\K\\{cur\_name}\mathbin{\&{mod}}\\{ww}$;\6
  5980  \&{if} $\\{cur\_byte}=\\{byte\_start}[\\{cur\_name}+\\{ww}]$ \1\&{then}\5
  5981  $\|c\K0$\C{we hit the end of the name}\6
  5982  \4\&{else} \&{begin} \37$\|c\K\\{byte\_mem}[\\{cur\_bank},\39\\{cur\_byte}]$;\6
  5983  \&{if} $(\|c\L\.{"Z"})\W(\|c\G\.{"A"})$ \1\&{then}\5
  5984  $\|c\K\|c+\O{40}$;\2\6
  5985  \&{end};\2\6
  5986  $\\{blink}[\\{cur\_name}]\K\\{bucket}[\|c]$;\5
  5987  $\\{bucket}[\|c]\K\\{cur\_name}$;\6
  5988  \4\&{until}\5
  5989  $\\{next\_name}=0$;\2\6
  5990  $\\{decr}(\\{sort\_ptr})$;\5
  5991  $\\{unbucket}(\\{cur\_depth}+1)$;\6
  5992  \&{end}\par
  5993  \U250.\fi
  5994  
  5995  \M252. \P$\X252:Output index entries for the list at \\{sort\_ptr}\X\S$\6
  5996  \&{begin} \37$\\{cur\_name}\K\\{head}[\\{sort\_ptr}]$;\6
  5997  \&{debug} \37\&{if} $\\{trouble\_shooting}$ \1\&{then}\5
  5998  \\{debug\_help};\2\ \&{gubed}\6
  5999  \1\&{repeat} \37$\\{out2}(\.{"\\"})(\.{":"})$;\5
  6000  \X253:Output the name at \\{cur\_name}\X;\6
  6001  \X254:Output the cross-references at \\{cur\_name}\X;\6
  6002  $\\{cur\_name}\K\\{blink}[\\{cur\_name}]$;\6
  6003  \4\&{until}\5
  6004  $\\{cur\_name}=0$;\2\6
  6005  $\\{decr}(\\{sort\_ptr})$;\6
  6006  \&{end}\par
  6007  \U250.\fi
  6008  
  6009  \M253. \P$\X253:Output the name at \\{cur\_name}\X\S$\6
  6010  \&{case} $\\{ilk}[\\{cur\_name}]$ \1\&{of}\6
  6011  \4\\{normal}: \37\&{if} $\\{length}(\\{cur\_name})=1$ \1\&{then}\5
  6012  $\\{out2}(\.{"\\"})(\.{"|"})$\ \&{else} $\\{out2}(\.{"\\"})(\.{"\\"})$;\2\6
  6013  \4\\{roman}: \37\\{do\_nothing};\6
  6014  \4\\{wildcard}: \37$\\{out2}(\.{"\\"})(\.{"9"})$;\6
  6015  \4\\{typewriter}: \37$\\{out2}(\.{"\\"})(\.{"."})$;\6
  6016  \4\&{othercases} \37$\\{out2}(\.{"\\"})(\.{"\&"})$\2\6
  6017  \&{endcases};\6
  6018  $\\{out\_name}(\\{cur\_name})$\par
  6019  \U252.\fi
  6020  
  6021  \M254. Section numbers that are to be underlined are enclosed in
  6022  `\.{\\[}$\,\ldots\,$\.]'.
  6023  
  6024  \Y\P$\4\X254:Output the cross-references at \\{cur\_name}\X\S$\6
  6025  \X255:Invert the cross-reference list at \\{cur\_name}, making \\{cur\_xref}
  6026  the head\X;\6
  6027  \1\&{repeat} \37$\\{out2}(\.{","})(\.{"\ "})$;\5
  6028  $\\{cur\_val}\K\\{num}(\\{cur\_xref})$;\6
  6029  \&{if} $\\{cur\_val}<\\{def\_flag}$ \1\&{then}\5
  6030  $\\{out\_mod}(\\{cur\_val})$\6
  6031  \4\&{else} \&{begin} \37$\\{out2}(\.{"\\"})(\.{"["})$;\5
  6032  $\\{out\_mod}(\\{cur\_val}-\\{def\_flag})$;\5
  6033  $\\{out}(\.{"]"})$;\6
  6034  \&{end};\2\6
  6035  $\\{cur\_xref}\K\\{xlink}(\\{cur\_xref})$;\6
  6036  \4\&{until}\5
  6037  $\\{cur\_xref}=0$;\2\6
  6038  $\\{out}(\.{"."})$;\5
  6039  \\{finish\_line}\par
  6040  \U252.\fi
  6041  
  6042  \M255. List inversion is best thought of as popping elements off one stack and
  6043  pushing them onto another. In this case \\{cur\_xref} will be the head of
  6044  the stack that we push things onto.
  6045  
  6046  \Y\P$\4\X255:Invert the cross-reference list at \\{cur\_name}, making \\{cur%
  6047  \_xref} the head\X\S$\6
  6048  $\\{this\_xref}\K\\{xref}[\\{cur\_name}]$;\5
  6049  $\\{cur\_xref}\K0$;\6
  6050  \1\&{repeat} \37$\\{next\_xref}\K\\{xlink}(\\{this\_xref})$;\5
  6051  $\\{xlink}(\\{this\_xref})\K\\{cur\_xref}$;\5
  6052  $\\{cur\_xref}\K\\{this\_xref}$;\5
  6053  $\\{this\_xref}\K\\{next\_xref}$;\6
  6054  \4\&{until}\5
  6055  $\\{this\_xref}=0$\2\par
  6056  \U254.\fi
  6057  
  6058  \M256. The following recursive procedure walks through the tree of module names
  6059  and
  6060  prints them.
  6061  
  6062  \Y\P\4\&{procedure}\1\  \37$\\{mod\_print}(\|p:\\{name\_pointer})$;\C{print all
  6063  module names in subtree \|p}\2\6
  6064  \&{begin} \37\&{if} $\|p>0$ \1\&{then}\6
  6065  \&{begin} \37$\\{mod\_print}(\\{llink}[\|p])$;\6
  6066  $\\{out2}(\.{"\\"})(\.{":"})$;\6
  6067  $\\{tok\_ptr}\K1$;\5
  6068  $\\{text\_ptr}\K1$;\5
  6069  $\\{scrap\_ptr}\K0$;\5
  6070  \\{init\_stack};\5
  6071  $\\{app}(\|p+\\{mod\_flag})$;\5
  6072  \\{make\_output};\5
  6073  $\\{footnote}(0)$;\C{\\{cur\_xref} was set by \\{make\_output}}\6
  6074  \\{finish\_line};\6
  6075  $\\{mod\_print}(\\{rlink}[\|p])$;\6
  6076  \&{end};\2\6
  6077  \&{end};\par
  6078  \fi
  6079  
  6080  \M257. \P$\X257:Output all the module names\X\S$\ $\\{mod\_print}(\\{root})$\par
  6081  \U239.\fi
  6082  
  6083  \N258.  Debugging.
  6084  The \PASCAL\ debugger with which \.{WEAVE} was developed allows breakpoints
  6085  to be set, and variables can be read and changed, but procedures cannot be
  6086  executed. Therefore a `\\{debug\_help}' procedure has been inserted in the main
  6087  loops of each phase of the program; when \\{ddt} and \\{dd} are set to
  6088  appropriate
  6089  values, symbolic printouts of various tables will appear.
  6090  
  6091  The idea is to set a breakpoint inside the \\{debug\_help} routine, at the
  6092  place of `\ignorespaces \\{breakpoint}: \unskip' below.  Then when
  6093  \\{debug\_help} is to be activated, set \\{trouble\_shooting} equal to %
  6094  \\{true}.
  6095  The \\{debug\_help} routine will prompt you for values of \\{ddt} and \\{dd},
  6096  discontinuing this when $\\{ddt}\L0$; thus you type $2n+1$ integers, ending
  6097  with zero or a negative number. Then control either passes to the
  6098  breakpoint, allowing you to look at and/or change variables (if you typed
  6099  zero), or to exit the routine (if you typed a negative value).
  6100  
  6101  Another global variable, \\{debug\_cycle}, can be used to skip silently
  6102  past calls on \\{debug\_help}. If you set $\\{debug\_cycle}>1$, the program
  6103  stops
  6104  only every \\{debug\_cycle} times \\{debug\_help} is called; however,
  6105  any error stop will set \\{debug\_cycle} to zero.
  6106  
  6107  \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  6108  \&{debug} \37\\{trouble\_shooting}: \37\\{boolean};\C{is \\{debug\_help}
  6109  wanted?}\6
  6110  \4\\{ddt}: \37\\{integer};\C{operation code for the \\{debug\_help} routine}\6
  6111  \4\\{dd}: \37\\{integer};\C{operand in procedures performed by \\{debug\_help}}%
  6112  \6
  6113  \4\\{debug\_cycle}: \37\\{integer};\C{threshold for \\{debug\_help} stopping}\6
  6114  \4\\{debug\_skipped}: \37\\{integer};\C{we have skipped this many \\{debug%
  6115  \_help} calls}\6
  6116  \4\\{term\_in}: \37\\{text\_file};\C{the user's terminal as an input file}\6
  6117  \&{gubed}\par
  6118  \fi
  6119  
  6120  \M259. The debugging routine needs to read from the user's terminal.
  6121  \Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
  6122  \&{debug} \37$\\{trouble\_shooting}\K\\{true}$;\5
  6123  $\\{debug\_cycle}\K1$;\5
  6124  $\\{debug\_skipped}\K0$;\5
  6125  $\\{tracing}\K0$;\6
  6126  $\\{trouble\_shooting}\K\\{false}$;\5
  6127  $\\{debug\_cycle}\K99999$;\C{use these when it almost works}\6
  6128  $\\{reset}(\\{term\_in},\39\.{\'TTY:\'},\39\.{\'/I\'})$;\C{open \\{term\_in} as
  6129  the terminal, don't do a \\{get}}\6
  6130  \&{gubed}\par
  6131  \fi
  6132  
  6133  \M260. \P\D \37$\\{breakpoint}=888$\C{place where a breakpoint is desirable}\par
  6134  \Y\P\&{debug} \37\&{procedure}\1\  \37\\{debug\_help};\C{routine to display
  6135  various things}\6
  6136  \4\&{label} \37$\\{breakpoint},\39\\{exit}$;\6
  6137  \4\&{var} \37\|k: \37\\{integer};\C{index into various arrays}\2\6
  6138  \&{begin} \37$\\{incr}(\\{debug\_skipped})$;\6
  6139  \&{if} $\\{debug\_skipped}<\\{debug\_cycle}$ \1\&{then}\5
  6140  \&{return};\2\6
  6141  $\\{debug\_skipped}\K0$;\6
  6142  \~ \1\&{loop}\ \&{begin} \37$\\{print\_nl}(\.{\'\#\'})$;\5
  6143  \\{update\_terminal};\C{prompt}\6
  6144  $\\{read}(\\{term\_in},\39\\{ddt})$;\C{read a debug-command code}\6
  6145  \&{if} $\\{ddt}<0$ \1\&{then}\5
  6146  \&{return}\6
  6147  \4\&{else} \&{if} $\\{ddt}=0$ \1\&{then}\6
  6148  \&{begin} \37\&{goto} \37\\{breakpoint};\5
  6149  \]\C{go to every label at least once}\6
  6150  \4\\{breakpoint}: \37$\\{ddt}\K0$;\5
  6151  \]\6
  6152  \&{end}\6
  6153  \4\&{else} \&{begin} \37$\\{read}(\\{term\_in},\39\\{dd})$;\6
  6154  \&{case} $\\{ddt}$ \1\&{of}\6
  6155  \41: \37$\\{print\_id}(\\{dd})$;\6
  6156  \42: \37$\\{print\_text}(\\{dd})$;\6
  6157  \43: \37\&{for} $\|k\K1\mathrel{\&{to}}\\{dd}$ \1\&{do}\5
  6158  $\\{print}(\\{xchr}[\\{buffer}[\|k]])$;\2\6
  6159  \44: \37\&{for} $\|k\K1\mathrel{\&{to}}\\{dd}$ \1\&{do}\5
  6160  $\\{print}(\\{xchr}[\\{mod\_text}[\|k]])$;\2\6
  6161  \45: \37\&{for} $\|k\K1\mathrel{\&{to}}\\{out\_ptr}$ \1\&{do}\5
  6162  $\\{print}(\\{xchr}[\\{out\_buf}[\|k]])$;\2\6
  6163  \46: \37\&{for} $\|k\K1\mathrel{\&{to}}\\{dd}$ \1\&{do}\6
  6164  \&{begin} \37$\\{print\_cat}(\\{cat}[\|k])$;\5
  6165  $\\{print}(\.{\'\ \'})$;\6
  6166  \&{end};\2\6
  6167  \4\&{othercases} \37$\\{print}(\.{\'?\'})$\2\6
  6168  \&{endcases};\6
  6169  \&{end};\2\2\6
  6170  \&{end};\2\6
  6171  \4\\{exit}: \37\&{end};\6
  6172  \&{gubed}\par
  6173  \fi
  6174  
  6175  \N261\*.  The main program.
  6176  Let's put it all together now: \.{WEAVE} starts and ends here.
  6177  
  6178  The main procedure has been split into three sub-procedures in order to
  6179  keep certain \PASCAL\ compilers from overflowing their capacity.
  6180  
  6181  \Y\P\4\&{procedure}\1\  \37\\{Phase\_I};\2\6
  6182  \&{begin} \37\X109:Phase I: Read all the user's text and store the cross
  6183  references\X;\6
  6184  \&{end};\7
  6185  \4\&{procedure}\1\  \37\\{Phase\_II};\2\6
  6186  \&{begin} \37\X218:Phase II: Read all the text again and translate it to \TeX\
  6187  form\X;\6
  6188  \&{end};\7
  6189  \&{begin} \37\\{initialize};\C{beginning of the main program}\6
  6190  $\\{print\_ln}(\\{banner})$;\C{print a ``banner line''}\6
  6191  \X64:Store all the reserved words\X;\6
  6192  \\{Phase\_I};\5
  6193  \\{Phase\_II};\6
  6194  \X239:Phase III: Output the cross-reference index\X;\6
  6195  \X85:Check that all changes have been read\X;\6
  6196  \&{stat} \37\X262:Print statistics about memory usage\X;\ \&{tats}\6
  6197  \hbox{\4\4}\C{here files should be closed if the operating system requires it}\6
  6198  \X263\*:Print the job \\{history}\X;\6
  6199  \&{end}.\par
  6200  \fi
  6201  
  6202  \M262. \P$\X262:Print statistics about memory usage\X\S$\6
  6203  $\\{print\_nl}(\.{\'Memory\ usage\ statistics:\ \'},\39\\{name\_ptr}:1,\39\.{\'%
  6204  \ names,\ \'},\39\\{xref\_ptr}:1,\39\.{\'\ cross\ references,\ \'},\39\\{byte%
  6205  \_ptr}[0]:1)$;\6
  6206  \&{for} $\\{cur\_bank}\K1\mathrel{\&{to}}\\{ww}-1$ \1\&{do}\5
  6207  $\\{print}(\.{\'+\'},\39\\{byte\_ptr}[\\{cur\_bank}]:1)$;\2\6
  6208  $\\{print}(\.{\'\ bytes;\'})$;\5
  6209  $\\{print\_nl}(\.{\'parsing\ required\ \'},\39\\{max\_scr\_ptr}:1,\39\.{\'\
  6210  scraps,\ \'},\39\\{max\_txt\_ptr}:1,\39\.{\'\ texts,\ \'},\39\\{max\_tok%
  6211  \_ptr}:1,\39\.{\'\ tokens,\ \'},\39\\{max\_stack\_ptr}:1,\39\.{\'\ levels;%
  6212  \'})$;\5
  6213  $\\{print\_nl}(\.{\'sorting\ required\ \'},\39\\{max\_sort\_ptr}:1,\39\.{\'\
  6214  levels.\'})$\par
  6215  \U261\*.\fi
  6216  
  6217  \M263\*. Some implementations may wish to pass the \\{history} value to the
  6218  operating system so that it can be used to govern whether or not other
  6219  programs are started. Here we simply report the history to the user.
  6220  
  6221  \Y\P$\4\X263\*:Print the job \\{history}\X\S$\6
  6222  \&{case} $\\{history}$ \1\&{of}\6
  6223  \4\\{spotless}: \37$\\{print\_nl}(\.{\'(No\ errors\ were\ found.)\'})$;\6
  6224  \4\\{harmless\_message}: \37$\\{print\_nl}(\.{\'(Did\ you\ see\ the\ warning\
  6225  message\ above?)\'})$;\6
  6226  \4\\{error\_message}: \37$\\{print\_nl}(\.{\'(Pardon\ me,\ but\ I\ think\ I\
  6227  spotted\ something\ wrong.)\'})$;\6
  6228  \4\\{fatal\_message}: \37$\\{print\_nl}(\.{\'(That\ was\ a\ fatal\ error,\ my\
  6229  friend.)\'})$;\2\6
  6230  \&{end};\C{there are no other cases}\6
  6231  $\\{write\_ln}(\,)$;\par
  6232  \U261\*.\fi
  6233  
  6234  \N264.  System-dependent changes.
  6235  This module should be replaced, if necessary, by changes to the program
  6236  that are necessary to make \.{WEAVE} work at a particular installation.
  6237  It is usually best to design your change file so that all changes to
  6238  previous modules preserve the module numbering; then everybody's version
  6239  will be consistent with the printed program. More extensive changes,
  6240  which introduce new modules, can be inserted here; then only the index
  6241  itself will get a new module number.
  6242  
  6243  \fi
  6244  
  6245  \N265\*.  Index.
  6246  If you have read and understood the code for Phase III above, you know what
  6247  is in this index and how it got here. All modules in which an identifier is
  6248  used are listed with that identifier, except that reserved words are
  6249  indexed only when they appear in format definitions, and the appearances
  6250  of identifiers in module names are not indexed. Underlined entries
  6251  correspond to where the identifier was declared. Error messages, control
  6252  sequences put into the output, and a few
  6253  other things like ``recursion'' are indexed here too.
  6254  \fi
  6255  
  6256  
  6257  \ch 1\*, 2\*, 7\*, 20\*, 21\*, 22\*, 33\*, 261\*, 263\*, 265\*.
  6258  \inx
  6259  \:\.{\\)}, 186.
  6260  \:\.{\\*}, 130.
  6261  \:\.{\\,}, 162, 163, 186.
  6262  \:\.{\\.}, 189, 253.
  6263  \:\.{\\:}, 252, 256.
  6264  \:\.{\\=}, 189.
  6265  \:\.{\\[}, 254.
  6266  \:\.{\\\ }, 186, 189, 193.
  6267  \:\.{\\\#}, 186, 189.
  6268  \:\.{\\\$}, 186, 189.
  6269  \:\.{\\\%}, 186, 189.
  6270  \:\.{\\\&}, 189, 209, 253.
  6271  \:\.{\\\'}, 189.
  6272  \:\.{\\\\}, 189, 209, 253.
  6273  \:\.{\\\^}, 186, 189.
  6274  \:\.{\\\`}, 189.
  6275  \:\.{\\\{}, 189.
  6276  \:\.{\\\}}, 189.
  6277  \:\.{\\\~}, 189, 193.
  6278  \:\.{\\]}, 186.
  6279  \:\.{\\|}, 209, 253.
  6280  \:\.{\\\_}, 131, 189.
  6281  \:\.{\\A}, 236.
  6282  \:\.{\\As}, 237.
  6283  \:\.{\\ast}, 186.
  6284  \:\.{\\B}, 186.
  6285  \:\.{\\C}, 198.
  6286  \:\.{\\con}, 239.
  6287  \:\.{\\D}, 227.
  6288  \:\.{\\E}, 186.
  6289  \:\.{\\ET}, 237.
  6290  \:\.{\\ETs}, 237.
  6291  \:\.{\\F}, 228.
  6292  \:\.{\\fi}, 238.
  6293  \:\.{\\fin}, 239.
  6294  \:\.{\\G}, 188.
  6295  \:\.{\\H}, 196, 224.
  6296  \:\.{\\I}, 188.
  6297  \:\.{\\in}, 186.
  6298  \:\.{\\input webmac}, 124.
  6299  \:\.{\\inx}, 239.
  6300  \:\.{\\J}, 186.
  6301  \:\.{\\K}, 188.
  6302  \:\.{\\L}, 188.
  6303  \:\.{\\M}, 221.
  6304  \:\.{\\N}, 221.
  6305  \:\.{\\O}, 196, 223.
  6306  \:\.{\\P}, 212, 226.
  6307  \:\.{\\R}, 188.
  6308  \:\.{\\S}, 188, 228, 231.
  6309  \:\.{\\T}, 186.
  6310  \:\.{\\to}, 186.
  6311  \:\.{\\U}, 236.
  6312  \:\.{\\Us}, 237.
  6313  \:\.{\\V}, 188.
  6314  \:\.{\\W}, 188.
  6315  \:\.{\\X}, 213.
  6316  \:\.{\\Y}, 212, 219, 226, 231.
  6317  \:\.{\\1}, 211, 212.
  6318  \:\.{\\2}, 211, 212.
  6319  \:\.{\\3}, 211, 212.
  6320  \:\.{\\4}, 211, 212.
  6321  \:\.{\\5}, 211, 212.
  6322  \:\.{\\6}, 211, 212, 226.
  6323  \:\.{\\7}, 211, 212, 226.
  6324  \:\.{\\9}, 253.
  6325  \:\.{\AT!1}, 88, 177.
  6326  \:\.{\AT!2}, 88, 177.
  6327  \:\|{a}, \[130], \[206], \[208].
  6328  \:\\{alpha}, \[140], 142, 143, 149, 192, 193.
  6329  \:\\{alpha\_cases}, 149, \[150].
  6330  \:\.{Ambiguous prefix}, 69.
  6331  \:\\{and\_sign}, \[15], 64, 188.
  6332  \:\\{app}, \[148], 151, 152, 153, 155, 156, 158, 159, 160, 161, 162, 163, 164,
  6333  165, 167, 168, 170, 180, 184, 186, 189, 190, 195, 196, 198, 207, 208, 226, 231,
  6334  256.
  6335  \:\\{app\_comment}, 183, 184, \[195], 197, 198, 226.
  6336  \:\\{app\_hex}, 183, 186, \[196].
  6337  \:\\{app\_octal}, 183, 186, \[196].
  6338  \:\\{app\_tok}, \[136], 137, 138, 148, 189, 190, 196, 197, 226.
  6339  \:\\{append\_xref}, \[50], 51.
  6340  \:\\{app1}, \[148], 151, 152, 153, 155, 156, 159, 160, 162, 163, 164, 165, 168,
  6341  170, 174, 180, 195.
  6342  \:\\{app2}, \[148], 153, 156, 158, 161, 163, 165, 167.
  6343  \:\\{app3}, \[148], 158, 164.
  6344  \:\\{array\_like}, \[42], 64, 191, 192.
  6345  \:{ASCII code}, 11, 86.
  6346  \:\\{ASCII\_code}, \[11], 13, 27, 28, 37, 65, 73, 87, 89, 91, 121, 127, 132,
  6347  136, 208, 242, 246, 247, 249.
  6348  \:\|{b}, \[122], \[208].
  6349  \:\\{backup}, \[141], 142, 143, 147, 160, 167, 192, 193, 208, 231.
  6350  \:\\{bal}, \[91], 92, \[112], \[136], 137, 138, \[198].
  6351  \:\\{banner}, \[1\*], 261\*.
  6352  \:\&{begin}, 3.
  6353  \:\\{begin\_comment}, \[86], 87, 97, 186, 222.
  6354  \:\\{begin\_like}, \[42], 64, 193.
  6355  \:\\{begin\_Pascal}, \[86], 87, 117, 229, 230.
  6356  \:\\{beginning}, \[140], 142, 143, 150, 152, 164, 170, 193.
  6357  \:\\{big\_cancel}, \[141], 142, 147, 186, 208, 212.
  6358  \:\\{big\_force}, \[141], 142, 147, 186, 208, 212, 226.
  6359  \:\\{big\_line\_break}, \[86], 87, 186, 222.
  6360  \:\\{blink}, \[242], 243, 250, 251, 252.
  6361  \:\\{boolean}, 28, 29, 45, 71, 74, 93, 122, 143, 258.
  6362  \:\\{break\_out}, 125, 126, \[127].
  6363  \:\\{break\_space}, \[141], 143, 147, 152, 155, 156, 160, 164, 168, 170, 200,
  6364  208, 211, 212.
  6365  \:\\{breakpoint}, 258, \[260].
  6366  \:\\{bucket}, \[242], 243, 249, 251.
  6367  \:\\{buf\_size}, \[8], 28, 73, 74, 75, 79, 123.
  6368  \:\\{buffer}, \[27], 28, 31, 32, 55, 58, 59, 61, 62, 63, 74, 76, 78, 79, 80,
  6369  81, 82, 84, 85, 89, 90, 91, 92, 93, 95, 97, 98, 99, 100, 103, 104, 106, 107,
  6370  110, 123, 132, 133, 134, 135, 136, 137, 179, 182, 183, 189, 190, 196, 208, 214,
  6371  216, 217, 221, 223, 224, 260.
  6372  \:\\{byte\_mem}, 36, \[37], 38, 39, 40, 43, 44, 52, 58, 61, 62, 66, 67, 68, 69,
  6373  131, 208, 209, 214, 215, 216, 217, 243, 244, 251.
  6374  \:\\{byte\_ptr}, 38, \[39], 41, 62, 67, 262.
  6375  \:\\{byte\_start}, 36, \[37], 38, 39, 41, 44, 50, 55, 61, 62, 67, 68, 93, 114,
  6376  131, 209, 214, 243, 251.
  6377  \:\|{c}, \[66], \[69], \[87], \[89], \[90], \[91], \[95], \[132], \[134], %
  6378  \[136], \[140], \[172], \[174], \[242], \[247], \[249].
  6379  \:\\{cancel}, \[141], 142, 143, 147, 153, 155, 156, 159, 160, 162, 163, 164,
  6380  165, 193, 197, 200, 208, 211, 212.
  6381  \:\\{carriage\_return}, \[15], 17, 28.
  6382  \:\\{carryover}, \[122].
  6383  \:\\{case\_head}, \[140], 143, 149, 153, 154, 162, 163, 165.
  6384  \:\\{case\_like}, \[42], 64, 193.
  6385  \:\\{casey}, \[140], 142, 143, 149, 153, 165, 193.
  6386  \:\\{cat}, \[144], 149, 150, 151, 152, 153, 154, 155, 156, 158, 159, 160, 161,
  6387  162, 163, 164, 165, 167, 168, 170, 172, 174, 176, 178, 179, 180, 181, 183, 184,
  6388  194, 195, 197, 244, 250, 260.
  6389  \:\.{Change file ended...}, 77, 79, 84.
  6390  \:\.{Change file entry did not match}, 85.
  6391  \:\\{change\_buffer}, \[73], 74, 75, 78, 79, 85.
  6392  \:\\{change\_changing}, \[72], 79, 81, 84.
  6393  \:\\{change\_exists}, \[45], 109, 110, 239.
  6394  \:\\{change\_file}, \[2\*], \[23], 24, 32, 71, 73, 76, 77, 79, 84.
  6395  \:\\{change\_limit}, \[73], 74, 75, 78, 79, 83, 85.
  6396  \:\\{change\_pending}, \[71], 79, 84.
  6397  \:\\{changed\_module}, \[45], 71, 79, 84, 109, 110, 130, 241.
  6398  \:\\{changing}, 32, \[71], 72, 73, 75, 79, 81, 82, 85, 110.
  6399  \:\\{char}, 12, 14.
  6400  \:\\{char\_like}, \[42], 64, 191.
  6401  \:\\{check\_change}, \[79], 83.
  6402  \:\\{check\_sum}, \[86], 87, 186, 222.
  6403  \:\\{chr}, 12, 13, 17, 18.
  6404  \:\\{clause}, \[140], 142, 143, 149, 151, 153, 154, 156, 193.
  6405  \:\\{close}, \[140], 142, 143, 152, 153, 160, 162, 163, 164, 167, 186, 193.
  6406  \:\\{collate}, \[246], 247, 248, 249.
  6407  \:\\{colon}, \[140], 142, 143, 148, 151, 160, 163, 167, 170, 186.
  6408  \:\\{comment}, \[142].
  6409  \:\\{comment\_scrap}, \[184], 186.
  6410  \:\\{compress}, \[97].
  6411  \:\\{cond}, \[140], 142, 143, 149, 193.
  6412  \:\\{confusion}, \[34].
  6413  \:\\{const\_like}, \[42], 64, 191, 192.
  6414  \:\\{continue}, \[5], 75, 76.
  6415  \:\.{Control codes are forbidden...}, 106.
  6416  \:\.{Control text didn't end}, 106.
  6417  \:\\{control\_code}, \[87], 88, 90, 93, 100, 135.
  6418  \:\\{copy\_comment}, 132, \[136], 198.
  6419  \:\\{copy\_limbo}, \[132], 218.
  6420  \:\\{copy\_TeX}, 132, \[134], 222.
  6421  \:\\{count}, \[69].
  6422  \:\\{cur\_bank}, \[244], 251, 262.
  6423  \:\\{cur\_byte}, \[244], 251.
  6424  \:\\{cur\_depth}, \[244], 250, 251.
  6425  \:\\{cur\_end}, 201, \[202], 204, 205, 206.
  6426  \:\\{cur\_mod\_name}, \[208], 214, 215, 216.
  6427  \:\\{cur\_mode}, 201, \[202], 204, 206, 208, 211, 212.
  6428  \:\\{cur\_module}, \[93], 101, 117, 230, 232.
  6429  \:\\{cur\_name}, \[63], 206, 209, 213, 214, 242, 243, 251, 252, 253, 255.
  6430  \:\\{cur\_state}, \[202], 204, 205.
  6431  \:\\{cur\_tok}, 201, \[202], 204, 205, 206.
  6432  \:\\{cur\_val}, \[244], 254.
  6433  \:\\{cur\_xref}, \[118], 119, 213, 231, 234, 235, 236, 237, 254, 255, 256.
  6434  \:\|{d}, \[95], \[127], \[172], \[174], \[249].
  6435  \:\\{dd}, \[258], 260.
  6436  \:\\{ddt}, \[258], 260.
  6437  \:\&{debug}, \[3], \[4], \[30], \[31], \[88], \[95], \[140], \[146], \[148], %
  6438  \[177], \[178], \[179], \[181], \[182], \[206], \[252], \[258], \[259], \[260].
  6439  \:\\{debug\_cycle}, 31, \[258], 259, 260.
  6440  \:\\{debug\_help}, \[30], 31, 95, 206, 252, 258, \[260].
  6441  \:\\{debug\_skipped}, 31, \[258], 259, 260.
  6442  \:\\{decr}, \[6], 28, 92, 98, 103, 122, 127, 130, 135, 137, 138, 205, 251, 252.
  6443  \:\\{def\_flag}, \[46], 48, 50, 51, 93, 100, 111, 113, 115, 117, 119, 130, 213,
  6444  231, 233, 235, 236, 254.
  6445  \:\\{definition}, \[86], 87, 115, 225.
  6446  \:\\{depth}, \[244], 249.
  6447  \:\\{dig}, \[129], 130.
  6448  \:\\{div\_like}, \[42], 64, 191, 192.
  6449  \:\\{do\_like}, \[42], 64, 191, 192.
  6450  \:\\{do\_nothing}, \[6], 95, 113, 149, 150, 186, 189, 222, 253.
  6451  \:\\{done}, \[5], 75, 76, 90, 91, 92, 95, 103, 104, 122, 134, 135, 136, 137,
  6452  138, 175, 179, 236, 237.
  6453  \:\.{Double \AT! required...}, 133.
  6454  \:\.{Double \AT! should be used...}, 189.
  6455  \:\\{double\_dot}, \[86], 97, 186.
  6456  \:\\{easy\_cases}, 183, 185, \[186].
  6457  \:\\{eight\_bits}, \[36], 58, 87, 90, 91, 95, 108, 112, 122, 134, 136, 140,
  6458  144, 172, 174, 178, 198, 206, 208, 244, 249.
  6459  \:\&{else}, 7\*.
  6460  \:\\{else\_like}, \[42], 64, 193.
  6461  \:\\{elsie}, \[140], 142, 143, 149, 156, 193.
  6462  \:\\{emit\_space\_if\_needed}, \[219], 225, 230.
  6463  \:\&{end}, 3, 7\*.
  6464  \:\\{end\_comment}, \[86], 87, 97, 186, 222.
  6465  \:\\{end\_field}, \[201], 202.
  6466  \:\\{end\_like}, \[42], 64, 193.
  6467  \:\\{end\_of\_WEAVE}, \[2\*], 33\*.
  6468  \:\\{end\_translation}, \[141], 147, 201, 207, 208, 212.
  6469  \:\&{endcases}, \[7\*].
  6470  \:\\{eof}, 28.
  6471  \:\\{eoln}, 28.
  6472  \:\\{equal}, \[66], 67, 68.
  6473  \:\\{equivalence\_sign}, \[15], 97, 116, 188, 228, 231.
  6474  \:\\{err\_print}, \[31], 66, 69, 72, 76, 77, 79, 80, 84, 85, 87, 95, 99, 103,
  6475  104, 106, 107, 133, 136, 137, 189, 197, 222, 227, 228, 231, 232.
  6476  \:\\{error}, 28, \[31], 33\*.
  6477  \:\\{error\_message}, \[9], 263\*.
  6478  \:\\{exit}, \[5], 6, 50, 74, 75, 79, 89, 111, 123, 127, 132, 183, 208, 236, 260.
  6479  \:\\{exp}, \[140], 142, 143, 149, 186.
  6480  \:\\{exponent}, \[93], 98, 186.
  6481  \:\\{extension}, \[66], 68, 69.
  6482  \:\.{Extra \}}, 95.
  6483  \:\.{Extra \AT!>}, 87.
  6484  \:\|{f}, \[28].
  6485  \:\\{false}, 28, 29, 72, 73, 74, 79, 81, 84, 94, 96, 109, 122, 123, 127, 218,
  6486  238, 259.
  6487  \:\\{fatal\_error}, \[33\*], 34, 35.
  6488  \:\\{fatal\_message}, \[9], 263\*.
  6489  \:\\{final\_limit}, \[28].
  6490  \:\\{finish\_line}, \[123], 124, 132, 134, 135, 212, 218, 226, 236, 238, 239,
  6491  254, 256.
  6492  \:\\{finish\_Pascal}, 225, \[226], 230.
  6493  \:\\{first\_text\_char}, \[12], 18.
  6494  \:\\{first\_xref}, \[234], 235.
  6495  \:\\{five\_cases}, 149, \[150].
  6496  \:\\{flag}, \[236], 237.
  6497  \:\\{flush\_buffer}, \[122], 123, 127, 128, 218, 238.
  6498  \:\\{footnote}, 233, \[236], 256.
  6499  \:\\{for\_like}, \[42], 64, 191, 192.
  6500  \:\\{force}, \[141], 142, 143, 146, 147, 153, 155, 156, 160, 161, 167, 186,
  6501  192, 193, 198, 200, 208, 212, 226, 231.
  6502  \:\\{force\_line}, \[86], 87, 186.
  6503  \:\\{form\_feed}, \[15], 28.
  6504  \:\\{format}, \[86], 87, 111, 112, 113, 115, 183, 198, 222, 225.
  6505  \:\\{forward}, 30, 207.
  6506  \:\\{found}, \[5], 58, 60, 61, 66, 95, 96, 122, 148, 149, 150, 151, 175, 179,
  6507  208, 216.
  6508  \:\\{freeze\_text}, \[171], 172, 180, 184, 195, 198, 208.
  6509  \:\\{get}, 28, 259.
  6510  \:\\{get\_line}, 71, \[82], 89, 90, 91, 95, 103, 123, 132, 134, 136.
  6511  \:\\{get\_next}, 93, \[95], 108, 111, 113, 115, 116, 117, 183, 222, 227, 228,
  6512  230, 231, 232.
  6513  \:\\{get\_output}, \[206], 207, 208, 211, 212.
  6514  \:\\{goto\_like}, \[42], 64, 191, 192.
  6515  \:\\{greater}, \[66], 68, 69.
  6516  \:\\{greater\_or\_equal}, \[15], 97, 188.
  6517  \:\&{gubed}, \[3].
  6518  \:\|{h}, \[56], \[58], \[242].
  6519  \:\\{harmless\_message}, \[9], 263\*.
  6520  \:\\{hash}, 38, \[55], 57, 60, 242, 243.
  6521  \:\\{hash\_size}, \[8], 55, 56, 57, 58, 59, 242, 243.
  6522  \:\\{head}, \[244], 249, 250, 251, 252.
  6523  \:\\{hex}, \[86], 87, 100, 186, 222.
  6524  \:\\{hi\_ptr}, \[144], 176, 178, 179.
  6525  \:\\{history}, \[9], 10, 263\*.
  6526  \:\.{Hmm... n of the preceding...}, 80.
  6527  \:\|{i}, \[16], \[58], \[172], \[174], \[179].
  6528  \:\\{id\_first}, \[55], 58, 59, 61, 62, 63, 93, 98, 99, 106, 107, 189, 190.
  6529  \:\\{id\_flag}, \[146], 192, 206, 227, 228.
  6530  \:\\{id\_loc}, \[55], 58, 59, 61, 62, 64, 93, 98, 99, 106, 107, 189, 190.
  6531  \:\\{id\_lookup}, 55, \[58], 63, 93, 111, 113, 116, 191, 227, 228.
  6532  \:\\{identifier}, \[93], 98, 111, 113, 116, 185, 206, 208, 209, 227, 228.
  6533  \:\\{id2}, \[63], 64.
  6534  \:\\{id3}, \[63], 64.
  6535  \:\\{id4}, \[63], 64.
  6536  \:\\{id5}, \[63], 64.
  6537  \:\\{id6}, \[63], 64.
  6538  \:\\{id7}, \[63], 64.
  6539  \:\\{id8}, \[63], 64.
  6540  \:\\{id9}, \[63], 64.
  6541  \:\\{if\_like}, \[42], 64, 193.
  6542  \:\\{if\_module\_start\_then\_make\_change\_pending}, \[79], 84.
  6543  \:\\{ignore}, \[86], 87, 88, 186.
  6544  \:\\{ii}, \[71], 85.
  6545  \:\\{ilk}, 36, \[37], 42, 43, 55, 58, 60, 62, 111, 116, 191, 192, 253.
  6546  \:\.{Illegal control code...}, 215.
  6547  \:\.{Illegal use of \AT!...}, 137.
  6548  \:\.{Improper format definition}, 228.
  6549  \:\.{Improper macro definition}, 227.
  6550  \:\.{Incompatible section names}, 66.
  6551  \:\\{incr}, \[6], 28, 50, 59, 61, 62, 67, 68, 69, 76, 77, 79, 83, 84, 89, 90,
  6552  91, 92, 95, 97, 98, 99, 100, 103, 104, 106, 107, 110, 122, 125, 130, 133, 135,
  6553  136, 137, 148, 149, 150, 171, 176, 184, 189, 196, 204, 206, 214, 215, 216, 217,
  6554  220, 223, 224, 241, 249, 260.
  6555  \:\\{indent}, \[141], 142, 143, 147, 151, 160, 165, 193, 208.
  6556  \:\\{infinity}, \[249], 250.
  6557  \:\\{init\_stack}, \[202], 222, 225, 230, 256.
  6558  \:\\{initialize}, \[2\*], 261\*.
  6559  \:\\{inner}, 200, \[201], 206, 212.
  6560  \:\\{inner\_tok\_flag}, \[146], 198, 206, 207.
  6561  \:\.{Input ended in mid-comment}, 136.
  6562  \:\.{Input ended in section name}, 103.
  6563  \:\.{Input line too long}, 28.
  6564  \:\\{input\_has\_ended}, \[71], 79, 81, 83, 89, 90, 91, 95, 103, 109, 132, 134,
  6565  136, 218.
  6566  \:\\{input\_ln}, \[28], 76, 77, 79, 83, 84.
  6567  \:\\{integer}, 14, 71, 79, 121, 130, 172, 174, 219, 258, 260.
  6568  \:\\{intercal\_like}, \[42].
  6569  \:\\{intro}, \[140], 142, 143, 148, 150, 157, 160, 162, 163, 165, 167, 170,
  6570  192, 193, 227, 228.
  6571  \:\|{j}, \[66], \[69], \[95], \[122], \[146], \[172], \[174], \[179], \[183], %
  6572  \[208].
  6573  \:\\{join}, \[86], 87, 186, 222.
  6574  \:\\{jump\_out}, 2\*, \[33\*].
  6575  \:\|{k}, \[31], \[44], \[58], \[66], \[69], \[74], \[75], \[79], \[95], \[122],
  6576  \[123], \[127], \[130], \[131], \[172], \[174], \[178], \[179], \[208], \[260].
  6577  \:\\{k\_limit}, \[208], 214, 216.
  6578  \:\\{k\_module}, \[240], 241.
  6579  \:\|{l}, \[31], \[58], \[66], \[69].
  6580  \:\\{last\_text\_char}, \[12], 18.
  6581  \:\\{lbrace}, \[146], 147.
  6582  \:\\{left\_arrow}, \[15], 97, 188.
  6583  \:\\{length}, \[38], 60, 209, 253.
  6584  \:\\{less}, \[66], 67, 68, 69.
  6585  \:\\{less\_or\_equal}, \[15], 97, 188.
  6586  \:\\{lhs}, \[114], 116.
  6587  \:\\{limit}, 28, 32, \[71], 74, 76, 77, 78, 79, 80, 81, 82, 84, 85, 89, 90, 91,
  6588  95, 97, 99, 103, 106, 107, 123, 132, 133, 134, 135, 136, 208, 214, 216, 223.
  6589  \:\\{line}, 32, \[71], 72, 76, 77, 79, 81, 83, 84, 85, 182.
  6590  \:\.{Line had to be broken}, 128.
  6591  \:\\{line\_break}, \[86], 87, 186, 222.
  6592  \:\\{line\_feed}, \[15], 28.
  6593  \:\\{line\_length}, \[8], 121, 122, 125, 127.
  6594  \:\\{lines\_dont\_match}, \[74], 79.
  6595  \:\\{link}, 36, \[37], 38, 43, 60, 243.
  6596  \:\\{llink}, \[43], 66, 67, 69, 119, 256.
  6597  \:\\{lo\_ptr}, \[144], 172, 175, 176, 178, 179, 180, 181.
  6598  \:\\{loc}, 28, 32, \[71], 76, 79, 80, 81, 82, 84, 85, 89, 90, 91, 92, 95, 97,
  6599  98, 99, 100, 103, 104, 106, 107, 110, 113, 132, 133, 134, 135, 136, 137, 182,
  6600  196, 208, 214, 221, 222, 223, 224.
  6601  \:\\{long\_buf\_size}, \[8], 27, 28, 31, 55, 58, 71, 179, 183, 208, 216, 217.
  6602  \:\\{longest\_name}, \[8], 65, 66, 69, 95, 103, 105.
  6603  \:\&{loop}, \[6].
  6604  \:\\{loop\_like}, \[42], 64, 193.
  6605  \:\|{m}, \[50], \[130].
  6606  \:\\{make\_output}, \[207], \[208], 213, 226, 256.
  6607  \:\\{mark\_error}, \[9], 31, 215, 216.
  6608  \:\\{mark\_fatal}, \[9], 33\*.
  6609  \:\\{mark\_harmless}, \[9], 105, 119, 128, 181, 182.
  6610  \:\\{math}, 139, \[140], 142, 143, 148, 150, 151, 158, 160, 162, 163, 167, 170,
  6611  179, 180, 186, 188, 192, 227, 228, 231.
  6612  \:\\{math\_bin}, \[141], 142, 147, 192, 208, 210.
  6613  \:\\{math\_break}, \[86], 87, 186, 222.
  6614  \:\\{math\_op}, \[141], 143, 147, 162, 163, 208.
  6615  \:\\{math\_rel}, \[141], 142, 146, 147, 192, 208, 210, 231.
  6616  \:\\{max\_bytes}, \[8], 37, 39, 44, 58, 62, 66, 67, 69, 131, 208, 244.
  6617  \:\\{max\_modules}, \[8], 45, 46, 110, 240.
  6618  \:\\{max\_names}, \[8], 37, 38, 62, 67, 69, 242.
  6619  \:\\{max\_refs}, \[8], 47, 50.
  6620  \:\\{max\_scr\_ptr}, \[144], 145, 187, 197, 199, 226, 262.
  6621  \:\\{max\_scraps}, \[8], 144, 172, 174, 178, 179, 187, 197, 199, 244.
  6622  \:\\{max\_sort\_ptr}, \[244], 245, 249, 262.
  6623  \:\\{max\_sorts}, \[244], 249.
  6624  \:\\{max\_stack\_ptr}, \[202], 203, 204, 262.
  6625  \:\\{max\_texts}, \[8], 52, 175, 179, 187, 199.
  6626  \:\\{max\_tok\_ptr}, \[53], 54, 175, 187, 199, 207, 226, 262.
  6627  \:\\{max\_toks}, \[8], 53, 136, 146, 175, 179, 180, 187, 189, 198, 199.
  6628  \:\\{max\_txt\_ptr}, \[53], 54, 175, 187, 199, 207, 226, 262.
  6629  \:\\{mid\_xref}, \[234], 235.
  6630  \:\.{Missing "|"...}, 197.
  6631  \:\\{mod\_check}, \[119], 120.
  6632  \:\\{mod\_flag}, \[146], 206, 231, 232, 256.
  6633  \:\\{mod\_lookup}, 65, \[66], 101, 102.
  6634  \:\\{mod\_name}, \[206], 208.
  6635  \:\\{mod\_print}, \[256], 257.
  6636  \:\\{mod\_scrap}, \[140], 142, 143, 149, 167, 231, 232.
  6637  \:\\{mod\_text}, \[65], 66, 67, 68, 69, 95, 101, 102, 103, 104, 105, 260.
  6638  \:\\{mod\_xref\_switch}, 46, \[48], 49, 51, 117.
  6639  \:\\{mode}, \[201], 208.
  6640  \:\\{mode\_field}, \[201], 202.
  6641  \:\\{module\_count}, \[45], 50, 51, 71, 79, 84, 109, 110, 181, 218, 220, 221,
  6642  231, 241.
  6643  \:\\{module\_name}, \[86], 87, 93, 100, 113, 117, 222, 230, 232.
  6644  \:\|{n}, \[50], \[79], \[178].
  6645  \:\.{Name does not match}, 69.
  6646  \:\\{name\_pointer}, \[38], 39, 44, 50, 51, 58, 63, 66, 69, 93, 111, 114, 119,
  6647  131, 144, 183, 192, 208, 229, 242, 256.
  6648  \:\\{name\_ptr}, 38, \[39], 41, 44, 58, 60, 62, 67, 262.
  6649  \:\.{Never defined: <section name>}, 119.
  6650  \:\.{Never used: <section name>}, 119.
  6651  \:\\{new\_line}, \[20\*], 31, 32, 33\*, 128.
  6652  \:\\{new\_mod\_xref}, \[51], 117.
  6653  \:\\{new\_module}, \[86], 87, 90, 95, 134.
  6654  \:\\{new\_xref}, \[50], 111, 113, 116.
  6655  \:\\{next\_control}, \[108], 111, 112, 113, 115, 116, 117, 183, 185, 186, 189,
  6656  191, 197, 198, 207, 222, 225, 227, 228, 229, 230, 231, 232.
  6657  \:\\{next\_name}, \[242], 243, 251.
  6658  \:\\{next\_xref}, \[234], 235, 255.
  6659  \:\&{nil}, 6.
  6660  \:\\{nil\_like}, \[42], 64, 191, 192.
  6661  \:\\{no\_line\_break}, \[86], 87, 186, 222.
  6662  \:\\{no\_underline}, \[86], 87, 100, 113.
  6663  \:\\{normal}, \[42], 58, 60, 111, 116, 191, 192, 227, 228, 253.
  6664  \:\\{not\_equal}, \[15], 97, 188.
  6665  \:\\{not\_found}, \[5].
  6666  \:\\{not\_sign}, \[15], 64, 188.
  6667  \:\\{num}, \[46], 49, 50, 51, 119, 213, 231, 235, 236, 237, 254.
  6668  \:\\{num\_field}, 46, \[48].
  6669  \:\\{octal}, \[86], 87, 186, 222.
  6670  \:\\{omega}, \[140], 142, 143, 151, 192, 193, 195.
  6671  \:\\{oot}, \[125].
  6672  \:\\{oot1}, \[125].
  6673  \:\\{oot2}, \[125].
  6674  \:\\{oot3}, \[125].
  6675  \:\\{oot4}, \[125].
  6676  \:\\{oot5}, \[125].
  6677  \:\\{open}, 139, \[140], 142, \[143], 150, 186.
  6678  \:\\{open\_input}, \[24], 81.
  6679  \:\\{opt}, 139, \[141], 142, 143, 147, 159, 163, 186, 208, 211.
  6680  \:\\{or\_sign}, \[15], 64, 188.
  6681  \:\\{ord}, 13.
  6682  \:\\{other\_line}, \[71], 72, 81, 85.
  6683  \:\&{othercases}, \[7\*].
  6684  \:\\{others}, 7\*.
  6685  \:\\{out}, \[125], 130, 131, 133, 135, 208, 209, 210, 211, 212, 213, 214, 221,
  6686  222, 223, 224, 236, 237, 241, 254.
  6687  \:\\{out\_buf}, \[121], 122, 124, 125, 126, 127, 128, 212, 226, 231, 260.
  6688  \:\\{out\_line}, \[121], 122, 124, 128, 219.
  6689  \:\\{out\_mod}, \[130], 213, 221, 237, 241, 254.
  6690  \:\\{out\_name}, \[131], 209, 253.
  6691  \:\\{out\_ptr}, \[121], 122, 123, 124, 125, 127, 128, 135, 212, 219, 226, 231,
  6692  260.
  6693  \:\\{outdent}, \[141], 143, 147, 153, 155, 156, 160, 162, 163, 164, 208.
  6694  \:\\{outer}, 200, \[201], 202, 211, 212.
  6695  \:\\{outer\_parse}, \[198], 225, 230.
  6696  \:\\{outer\_xref}, \[112], 115, 117, 198.
  6697  \:\\{output\_Pascal}, \[207], 214, 222.
  6698  \:\\{output\_state}, \[201], 202.
  6699  \:\\{out2}, \[125], 130, 210, 211, 212, 213, 219, 221, 226, 237, 241, 252, 253,
  6700  254, 256.
  6701  \:\\{out3}, \[125], 210, 223, 224, 237, 238.
  6702  \:\\{out4}, \[125], 226, 239, 241.
  6703  \:\\{out5}, \[125], 210.
  6704  \:\\{overflow}, \[35], 50, 62, 67, 110, 136, 175, 180, 187, 199, 204, 216, 217,
  6705  249.
  6706  \:\|{p}, \[44], \[50], \[51], \[58], \[66], \[69], \[111], \[119], \[131], %
  6707  \[146], \[183], \[192], \[197], \[198], \[204], \[226].
  6708  \:\\{panic}, 33\*.
  6709  \:\\{param}, \[86].
  6710  \:\.{Pascal text...didn't end}, 216.
  6711  \:\\{Pascal\_parse}, \[183], 186, 192, 196, 197, 198.
  6712  \:\\{Pascal\_translate}, \[197], 198, 207.
  6713  \:\\{Pascal\_xref}, \[111], 112, 113, 183, 198.
  6714  \:\\{per\_cent}, \[122].
  6715  \:\\{Phase\_I}, \[261\*].
  6716  \:\\{Phase\_II}, \[261\*].
  6717  \:\\{phase\_one}, \[29], 31, 109.
  6718  \:\\{phase\_three}, \[29], 109, 213, 239.
  6719  \:\\{pop\_level}, \[205], 206.
  6720  \:\\{pp}, \[144], 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
  6721  160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 173, 175, 176, 178, 179.
  6722  \:\\{prefix}, \[66], 68.
  6723  \:\\{prefix\_lookup}, \[69], 101.
  6724  \:\\{prime\_the\_change\_buffer}, \[75], 81, 84.
  6725  \:\\{print}, \[20\*], 31, 32, 33\*, 44, 105, 110, 119, 128, 140, 146, 147, 178,
  6726  181, 182, 215, 216, 221, 239, 260, 262.
  6727  \:\\{print\_cat}, \[140], 178, 181, 260.
  6728  \:\\{print\_id}, \[44], 119, 146, 215, 216, 260.
  6729  \:\\{print\_ln}, \[20\*], 32, 128, 181, 261\*.
  6730  \:\\{print\_nl}, \[20\*], 28, 105, 119, 128, 178, 181, 182, 215, 216, 218, 239,
  6731  260, 262, 263\*.
  6732  \:\\{print\_text}, \[146], 260.
  6733  \:\\{proc}, \[140], 142, \[143], 149, 162, 163, 164, 193.
  6734  \:\\{proc\_like}, \[42], 64, 111, 193.
  6735  \:\\{prod}, 148, \[178], 183.
  6736  \:\\{production}, \[148].
  6737  \:\\{production\_end}, \[148].
  6738  \:{productions, table of}, 143.
  6739  \:\\{pseudo\_semi}, \[86], 87, 186, 222.
  6740  \:\\{push\_level}, \[204], 206, 208.
  6741  \:\|{q}, \[50], \[51], \[66], \[69], \[198], \[236].
  6742  \:\|{r}, \[51], \[69], \[146].
  6743  \:\\{rbrace}, \[146].
  6744  \:\\{read}, 260.
  6745  \:\\{read\_ln}, \[20\*], 28.
  6746  \:\\{readln}, 20\*.
  6747  \:\\{record\_head}, \[140], 142, 143, 149, 193.
  6748  \:\\{record\_like}, \[42], 64, 193.
  6749  \:{recursion}, 119, 207, 256.
  6750  \:\\{red}, 148, \[172], 174.
  6751  \:\\{reduce}, \[148], 151, 152, 153, 155, 156, 158, 159, 160, 161, 162, 163,
  6752  164, 165, 167, 168, 170, 172, 178.
  6753  \:\\{repeat\_like}, \[42], 64, 193.
  6754  \:\\{res\_flag}, \[146], 192, 193, 206.
  6755  \:\\{res\_word}, \[206], 208, 209.
  6756  \:\\{reserved}, \[42], 50, 60.
  6757  \:\\{reset}, 24, 259.
  6758  \:\\{reset\_input}, \[81], 109, 218.
  6759  \:\\{restart}, \[5], 82, 95, 100, 206.
  6760  \:\\{reswitch}, \[5], 183, 185, 191, 208, 212.
  6761  \:\&{return}, 5, \[6].
  6762  \:\\{rewrite}, 26.
  6763  \:\\{rhs}, \[114], 116.
  6764  \:\\{rlink}, \[43], 66, 67, 69, 119, 256.
  6765  \:\\{roman}, \[42], 111, 253.
  6766  \:\\{root}, \[43], 66, 69, 120, 257.
  6767  \:\\{save\_base}, \[197].
  6768  \:\\{save\_limit}, \[208], 214.
  6769  \:\\{save\_line}, \[219].
  6770  \:\\{save\_loc}, \[208], 214.
  6771  \:\\{save\_mode}, \[208], 212.
  6772  \:\\{save\_next\_control}, \[207].
  6773  \:\\{save\_place}, \[219].
  6774  \:\\{save\_position}, \[219], 220, 225.
  6775  \:\\{save\_text\_ptr}, \[207].
  6776  \:\\{save\_tok\_ptr}, \[207].
  6777  \:\\{scanning\_hex}, \[93], 94, 95, 96, 100.
  6778  \:\\{scrap\_base}, \[144], 145, 173, 178, 179, 180, 181, 194, 195, 197.
  6779  \:\\{scrap\_ptr}, \[144], 145, 176, 178, 179, 183, 184, 187, 194, 195, 197,
  6780  199, 226, 228, 244, 256.
  6781  \:\\{sc0}, \[184], 186, 193, 194, 195, 228.
  6782  \:\\{sc1}, \[184], 186, 189, 190, 192, 193, 196, 227, 228, 231, 232.
  6783  \:\\{sc2}, \[184], 186, 188, 192, 193, 227, 228, 231.
  6784  \:\\{sc3}, \[184], 186, 192, 193, 231.
  6785  \:\\{sc4}, \[184], 186, 193.
  6786  \:\.{Section name didn't end}, 104.
  6787  \:\.{Section name too long}, 105.
  6788  \:\\{semi}, 139, \[140], 142, 143, 149, 161, 163, 186, 194, 195, 228, 231.
  6789  \:\\{set\_element\_sign}, \[15], 64, 186.
  6790  \:\\{sid1}, \[63].
  6791  \:\\{sid2}, \[63].
  6792  \:\\{sid3}, \[63].
  6793  \:\\{sid4}, \[63].
  6794  \:\\{sid5}, \[63].
  6795  \:\\{sid6}, \[63].
  6796  \:\\{sid7}, \[63].
  6797  \:\\{sid8}, \[63].
  6798  \:\\{sid9}, \[63].
  6799  \:\\{simp}, \[140], 142, 143, 148, 150, 151, 158, 160, 161, 162, 167, 170, 186,
  6800  189, 190, 192, 196.
  6801  \:\\{sixteen\_bits}, \[36], 37, 48, 50, 53, 55, 66, 69, 172, 174, 201, 206,
  6802  207, 219, 236, 242, 244.
  6803  \:\\{skip\_comment}, \[91], 112, 132, 136.
  6804  \:\\{skip\_limbo}, \[89], 109, 132.
  6805  \:\\{skip\_TeX}, \[90], 113, 132.
  6806  \:\.{Sorry, x capacity exceeded}, 35.
  6807  \:\\{sort\_ptr}, \[244], 249, 250, 251, 252.
  6808  \:{special string characters}, 189.
  6809  \:{split procedures}, 149, 183, 261\*.
  6810  \:\\{spotless}, \[9], 10, 263\*.
  6811  \:\\{sq}, 148, \[174].
  6812  \:\\{squash}, \[148], 151, 152, 154, 157, 160, 161, 162, 163, 166, 167, 169,
  6813  170, 174, 178.
  6814  \:\\{stack}, 201, \[202], 204, 205.
  6815  \:\\{stack\_ptr}, 201, \[202], 204, 205.
  6816  \:\\{stack\_size}, \[8], 202, 204.
  6817  \:\&{stat}, \[3].
  6818  \:\\{stmt}, \[140], 143, 149, 152, 153, 155, 156, 159, 160, 161, 162, 164, 167,
  6819  168, 169, 170.
  6820  \:\\{string}, \[93], 99, 185.
  6821  \:\.{String constant didn't end}, 99.
  6822  \:\\{string\_delimiter}, \[208], 216.
  6823  \:\\{sub\_cases}, 183, 191, \[192].
  6824  \:{system dependencies}, \[1\*], 2\*, 4, 7\*, 12, 17, 20\*, 21\*, 22\*, 24, 26,
  6825  28, 32, 33\*, 259, 260, 261\*, 263\*, 264.
  6826  \:\\{s0}, \[184].
  6827  \:\\{s1}, \[184].
  6828  \:\\{s2}, \[184].
  6829  \:\\{s3}, \[184].
  6830  \:\\{s4}, \[184].
  6831  \:\|{t}, \[58].
  6832  \:\\{tab\_mark}, \[15], 32, 79, 87, 89, 92, 95, 103, 104, 123, 133, 135.
  6833  \:\&{tats}, \[3].
  6834  \:\\{temp\_line}, \[71], 72.
  6835  \:\\{term\_in}, \[258], 259, 260.
  6836  \:\\{term\_out}, 20\*, 21\*.
  6837  \:\\{terminator}, 139, \[140], 142, 143, 149, 152, 153, 160, 161, 164, 166,
  6838  167, 179, 194, 195.
  6839  \:\.{TeX string should be...}, 222.
  6840  \:\\{tex\_file}, \[2\*], \[25], 26, 122, 124.
  6841  \:\\{TeX\_string}, \[86], 87, 93, 100, 185, 222.
  6842  \:\\{text\_char}, \[12], 13, 20\*.
  6843  \:\\{text\_file}, \[12], 23, 25, 28, 258.
  6844  \:\\{text\_pointer}, \[52], 53, 144, 146, 179, 197, 198, 204, 207, 226.
  6845  \:\\{text\_ptr}, \[53], 54, 146, 171, 172, 175, 179, 180, 184, 187, 195, 198,
  6846  199, 207, 208, 226, 256.
  6847  \:\\{thin\_space}, \[86], 87, 186, 222.
  6848  \:\.{This can't happen}, 34.
  6849  \:\\{this\_module}, \[229], 230, 231, 233, 235.
  6850  \:\\{this\_xref}, \[234], 235, 255.
  6851  \:\\{to\_like}, \[42], 64, 191, 192.
  6852  \:\\{tok\_field}, \[201], 202.
  6853  \:\\{tok\_flag}, \[146], 148, 195, 198, 206, 226.
  6854  \:\\{tok\_mem}, \[53], 136, \[146], 148, 201, 202, 206, 213.
  6855  \:\\{tok\_ptr}, \[53], 54, 136, 137, 148, 171, 175, 179, 180, 187, 189, 198,
  6856  199, 207, 226, 256.
  6857  \:\\{tok\_start}, 52, \[53], 54, 144, 146, 171, 204.
  6858  \:\\{tracing}, 88, \[177], 178, 181, 182, 259.
  6859  \:\\{trans}, \[144], 148, 172, 176, 179, 183, 184, 195, 197, 244.
  6860  \:\\{translate}, 149, \[179], 180, 197, 226.
  6861  \:\\{trouble\_shooting}, 95, 206, 252, \[258], 259.
  6862  \:\\{true}, 6, 28, 29, 71, 72, 74, 79, 81, 83, 84, 85, 93, 100, 109, 110, 122,
  6863  127, 128, 239, 258, 259.
  6864  \:\\{typewriter}, \[42], 111, 253.
  6865  \:\\{unbucket}, \[249], 250, 251.
  6866  \:\\{underline}, \[86], 87, 100, 113.
  6867  \:\.{Unknown control code}, 87.
  6868  \:\\{until\_like}, \[42], 64, 193.
  6869  \:\\{up\_to}, \[95].
  6870  \:\\{update\_terminal}, \[22\*], 31, 110, 221, 260.
  6871  \:\\{var\_head}, \[140], 142, 143, 148, 149, 162, 163, 170, 193.
  6872  \:\\{var\_like}, \[42], 64, 111, 193.
  6873  \:\\{verbatim}, \[86], 87, 100, 107, 185, 189.
  6874  \:\.{Verbatim string didn't end}, 107.
  6875  \:\|{w}, \[44], \[58], \[66], \[69], \[131], \[208].
  6876  \:\\{WEAVE}, \[2\*].
  6877  \:\.{WEB file ended...}, 79.
  6878  \:\\{web\_file}, \[2\*], \[23], 24, 32, 71, 73, 79, 83, 85.
  6879  \:\.{webmac}, 124.
  6880  \:\.{Where is the match...}, 76, 80, 84.
  6881  \:\\{wi}, \[40], 41.
  6882  \:\\{wildcard}, \[42], 111, 253.
  6883  \:\\{write}, 20\*, 122, 124.
  6884  \:\\{write\_ln}, \[20\*], 122, 263\*.
  6885  \:\\{writeln}, 20\*.
  6886  \:\\{ww}, 8, \[37], 38, 39, 40, 41, 44, 50, 58, 61, 62, 66, 67, 68, 69, 131,
  6887  208, 209, 214, 243, 244, 251, 262.
  6888  \:\\{xchr}, \[13], 14, 16, 17, 18, 32, 44, 105, 122, 128, 146, 147, 182, 260.
  6889  \:\&{xclause}, 6.
  6890  \:\\{xlink}, \[46], 50, 51, 119, 213, 235, 237, 254, 255.
  6891  \:\\{xlink\_field}, 46, \[48].
  6892  \:\\{xmem}, 46, \[48].
  6893  \:\\{xord}, \[13], 16, 18, 28.
  6894  \:\\{xref}, 36, \[37], 46, 49, 50, 51, 62, 67, 119, 213, 231, 235, 243, 255.
  6895  \:\\{xref\_number}, \[47], 48, 50, 51, 118, 234, 236.
  6896  \:\\{xref\_ptr}, 46, \[48], 49, 50, 51, 262.
  6897  \:\\{xref\_roman}, \[86], 87, 93, 100, 111, 113, 186, 222.
  6898  \:\\{xref\_switch}, 46, \[48], 49, 50, 93, 100, 101, 111, 113, 115.
  6899  \:\\{xref\_typewriter}, \[86], 87, 93, 111, 113, 186, 222.
  6900  \:\\{xref\_wildcard}, \[86], 87, 93, 111, 113, 186, 222.
  6901  \:\.{You can't do that...}, 222, 232.
  6902  \:\.{You need an = sign...}, 231.
  6903  \fin
  6904  \:\X189:Append a \(string scrap\X
  6905  \U185.
  6906  \:\X190:Append a \TeX\ string scrap\X
  6907  \U185.
  6908  \:\X191:Append an identifier scrap\X
  6909  \U185.
  6910  \:\X185:Append the scrap appropriate to \\{next\_control}\X
  6911  \U183.
  6912  \:\X194:Append \\{terminator} if not already present\X
  6913  \Us193, 193\ETs193.
  6914  \:\X151:Cases for \\{alpha}\X
  6915  \U150.
  6916  \:\X152:Cases for \\{beginning}\X
  6917  \U150.
  6918  \:\X153:Cases for \\{case\_head}\X
  6919  \U149.
  6920  \:\X154:Cases for \\{casey}\X
  6921  \U149.
  6922  \:\X155:Cases for \\{clause}\X
  6923  \U149.
  6924  \:\X156:Cases for \\{cond}\X
  6925  \U149.
  6926  \:\X157:Cases for \\{elsie}\X
  6927  \U149.
  6928  \:\X158:Cases for \\{exp}\X
  6929  \U149.
  6930  \:\X159:Cases for \\{intro}\X
  6931  \U150.
  6932  \:\X160:Cases for \\{math}\X
  6933  \U150.
  6934  \:\X161:Cases for \\{mod\_scrap}\X
  6935  \U149.
  6936  \:\X163:Cases for $\\{open}\,\\{math}$\X
  6937  \U162.
  6938  \:\X162:Cases for \\{open}\X
  6939  \U150.
  6940  \:\X164:Cases for \\{proc}\X
  6941  \U149.
  6942  \:\X165:Cases for \\{record\_head}\X
  6943  \U149.
  6944  \:\X166:Cases for \\{semi}\X
  6945  \U149.
  6946  \:\X167:Cases for \\{simp}\X
  6947  \U150.
  6948  \:\X168:Cases for \\{stmt}\X
  6949  \U149.
  6950  \:\X169:Cases for \\{terminator}\X
  6951  \U149.
  6952  \:\X170:Cases for \\{var\_head}\X
  6953  \U149.
  6954  \:\X188:Cases involving nonstandard ASCII characters\X
  6955  \U186.
  6956  \:\X193:Cases that generate more than one scrap\X
  6957  \U191.
  6958  \:\X173:Change \\{pp} to $\max(\\{scrap\_base},$\\{pp}+\|d$)$\X
  6959  \Us172\ET174.
  6960  \:\X105:Check for overlong name\X
  6961  \U103.
  6962  \:\X85:Check that all changes have been read\X
  6963  \U261\*.
  6964  \:\X231:Check that $=$ or $\S$ follows this module name, and emit the scraps to
  6965  start the module definition\X
  6966  \U230.
  6967  \:\X138:Clear \\{bal} and \&{goto} \\{done}\X
  6968  \Us136\ET137.
  6969  \:\X180:Combine the irreducible scraps that remain\X
  6970  \U179.
  6971  \:\X61:Compare name \|p with current identifier, \&{goto} \\{found} if equal\X
  6972  \U60.
  6973  \:\X4:Compiler directives\X
  6974  \U2\*.
  6975  \:\X97:Compress two-symbol combinations like `\.{:=}'\X
  6976  \U95.
  6977  \:\X59:Compute the hash code \|h\X
  6978  \U58.
  6979  \:\X60:Compute the name location \|p\X
  6980  \U58.
  6981  \:\X8:Constants in the outer block\X
  6982  \U2\*.
  6983  \:\X217:Copy a control code into the buffer\X
  6984  \U216.
  6985  \:\X137:Copy special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"\}"}$; %
  6986  \&{goto} \\{done} at end\X
  6987  \U136.
  6988  \:\X216:Copy the \PASCAL\ text into $\\{buffer}[(\\{limit}+1)\to\|j]$\X
  6989  \U214.
  6990  \:\X135:Copy up to `\v' or control code, \&{goto} \\{done} if finished\X
  6991  \U134.
  6992  \:\X133:Copy up to control code, \&{return} if finished\X
  6993  \U132.
  6994  \:\X150:Declaration of subprocedures for \\{translate}\X
  6995  \U179.
  6996  \:\X195:Declaration of the \\{app\_comment} procedure\X
  6997  \U183.
  6998  \:\X196:Declaration of the \\{app\_octal} and \\{app\_hex} procedures\X
  6999  \U183.
  7000  \:\X186:Declaration of the \\{easy\_cases} procedure\X
  7001  \U183.
  7002  \:\X192:Declaration of the \\{sub\_cases} procedure\X
  7003  \U183.
  7004  \:\X92:Do special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"\}"}$; %
  7005  \&{goto} \\{done} at end\X
  7006  \U91.
  7007  \:\X243:Do the first pass of sorting\X
  7008  \U239.
  7009  \:\X232:Emit the scrap for a module name if present\X
  7010  \U230.
  7011  \:\X67:Enter a new module name into the tree\X
  7012  \U66.
  7013  \:\X62:Enter a new name into the table at position \|p\X
  7014  \U58.
  7015  \:\X30, 31, 33\*:Error handling procedures\X
  7016  \U2\*.
  7017  \:\X99:Get a string\X
  7018  \U95.
  7019  \:\X98:Get an identifier\X
  7020  \U95.
  7021  \:\X100:Get control code and possible module name\X
  7022  \U95.
  7023  \:\X9, 13, 20\*, 23, 25, 27, 29, 37, 39, 45, 48, 53, 55, 63, 65, 71, 73, 93,
  7024  108, 114, 118, 121, 129, 144, 177, 202, 219, 229, 234, 240, 242, 244, 246,
  7025  258:Globals in the outer block\X
  7026  \U2\*.
  7027  \:\X96:Go to \\{found} if \|c is a hexadecimal digit, otherwise set $%
  7028  \\{scanning\_hex}\K\\{false}$\X
  7029  \U95.
  7030  \:\X104:If end of name, \&{goto} \\{done}\X
  7031  \U103.
  7032  \:\X181:If semi-tracing, show the irreducible scraps\X
  7033  \U180.
  7034  \:\X80:If the current line starts with \.{@y}, report any discrepancies and %
  7035  \&{return}\X
  7036  \U79.
  7037  \:\X182:If tracing, print an indication of where we are\X
  7038  \U179.
  7039  \:\X255:Invert the cross-reference list at \\{cur\_name}, making \\{cur\_xref}
  7040  the head\X
  7041  \U254.
  7042  \:\X16, 40, 56, 247:Local variables for initialization\X
  7043  \U2\*.
  7044  \:\X212:Look ahead for strongest line break, \&{goto} \\{reswitch}\X
  7045  \U211.
  7046  \:\X187:Make sure that there is room for at least four more scraps, six more
  7047  tokens, and four more texts\X
  7048  \U185.
  7049  \:\X199:Make sure that there is room for at least seven more tokens, three more
  7050  texts, and one more scrap\X
  7051  \U198.
  7052  \:\X176:Make sure the entries $\\{cat}[\\{pp}\to(\\{pp}+3)]$ are defined\X
  7053  \U175.
  7054  \:\X149:Match a production at \\{pp}, or increase \\{pp} if there is no match\X
  7055  \U175.
  7056  \:\X78:Move \\{buffer} and \\{limit} to \\{change\_buffer} and \\{change%
  7057  \_limit}\X
  7058  \Us75\ET79.
  7059  \:\X211:Output a \(control, look ahead in case of line breaks, possibly %
  7060  \&{goto} \\{reswitch}\X
  7061  \U208.
  7062  \:\X210:Output a \.{\\math} operator\X
  7063  \U208.
  7064  \:\X213:Output a module name\X
  7065  \U208.
  7066  \:\X257:Output all the module names\X
  7067  \U239.
  7068  \:\X237:Output all the module numbers on the reference list \\{cur\_xref}\X
  7069  \U236.
  7070  \:\X209:Output an identifier\X
  7071  \U208.
  7072  \:\X252:Output index entries for the list at \\{sort\_ptr}\X
  7073  \U250.
  7074  \:\X221:Output the code for the beginning of a new module\X
  7075  \U220.
  7076  \:\X238:Output the code for the end of a module\X
  7077  \U220.
  7078  \:\X254:Output the cross-references at \\{cur\_name}\X
  7079  \U252.
  7080  \:\X253:Output the name at \\{cur\_name}\X
  7081  \U252.
  7082  \:\X214:Output the text of the module name\X
  7083  \U213.
  7084  \:\X109:Phase I: Read all the user's text and store the cross references\X
  7085  \U261\*.
  7086  \:\X218:Phase II: Read all the text again and translate it to \TeX\ form\X
  7087  \U261\*.
  7088  \:\X239:Phase III: Output the cross-reference index\X
  7089  \U261\*.
  7090  \:\X32:Print error location based on input buffer\X
  7091  \U31.
  7092  \:\X120:Print error messages about unused or undefined module names\X
  7093  \U109.
  7094  \:\X262:Print statistics about memory usage\X
  7095  \U261\*.
  7096  \:\X263\*:Print the job \\{history}\X
  7097  \U261\*.
  7098  \:\X147:Print token \|r in symbolic form\X
  7099  \U146.
  7100  \:\X128:Print warning message, break the line, \&{return}\X
  7101  \U127.
  7102  \:\X116:Process a format definition\X
  7103  \U115.
  7104  \:\X103:Put module name into $\\{mod\_text}[1\to\|k]$\X
  7105  \U101.
  7106  \:\X84:Read from \\{change\_file} and maybe turn off \\{changing}\X
  7107  \U82.
  7108  \:\X83:Read from \\{web\_file} and maybe turn on \\{changing}\X
  7109  \U82.
  7110  \:\X235:Rearrange the list pointed to by \\{cur\_xref}\X
  7111  \U233.
  7112  \:\X175:Reduce the scraps using the productions until no more rules apply\X
  7113  \U179.
  7114  \:\X107:Scan a verbatim string\X
  7115  \U100.
  7116  \:\X101:Scan the module name and make \\{cur\_module} point to it\X
  7117  \U100.
  7118  \:\X106:Scan to the next \.{@>}\X
  7119  \U100.
  7120  \:\X10, 14, 17, 18, 21\*, 26, 41, 43, 49, 54, 57, 94, 102, 124, 126, 145, 203,
  7121  245, 248, 259:Set initial values\X
  7122  \U2\*.
  7123  \:\X68:Set variable \|c to the result of comparing the given name to name \|p\X
  7124  \Us66\ET69.
  7125  \:\X233:Show cross references to this module\X
  7126  \U220.
  7127  \:\X215:Skip next character, give error if not `\.{@}'\X
  7128  \U214.
  7129  \:\X76:Skip over comment lines in the change file; \&{return} if end of file\X
  7130  \U75.
  7131  \:\X77:Skip to the next nonblank line; \&{return} if end of file\X
  7132  \U75.
  7133  \:\X250:Sort and output the index\X
  7134  \U239.
  7135  \:\X88:Special control codes allowed only when debugging\X
  7136  \U87.
  7137  \:\X251:Split the list at \\{sort\_ptr} into further lists\X
  7138  \U250.
  7139  \:\X228:Start a format definition\X
  7140  \U225.
  7141  \:\X227:Start a macro definition\X
  7142  \U225.
  7143  \:\X64:Store all the reserved words\X
  7144  \U261\*.
  7145  \:\X110:Store cross reference data for the current module\X
  7146  \U109.
  7147  \:\X115:Store cross references in the \(definition part of a module\X
  7148  \U110.
  7149  \:\X117:Store cross references in the \PASCAL\ part of a module\X
  7150  \U110.
  7151  \:\X113:Store cross references in the \TeX\ part of a module\X
  7152  \U110.
  7153  \:\X241:Tell about changed modules\X
  7154  \U239.
  7155  \:\X224:Translate a hexadecimal constant appearing in \TeX\ text\X
  7156  \U222.
  7157  \:\X223:Translate an octal constant appearing in \TeX\ text\X
  7158  \U222.
  7159  \:\X220:Translate the \(current module\X
  7160  \U218.
  7161  \:\X225:Translate the \(definition part of the current module\X
  7162  \U220.
  7163  \:\X230:Translate the \PASCAL\ part of the current module\X
  7164  \U220.
  7165  \:\X222:Translate the \TeX\ part of the current module\X
  7166  \U220.
  7167  \:\X11, 12, 36, 38, 47, 52, 201:Types in the outer block\X
  7168  \U2\*.
  7169  \con