\input webmac
% This program by D. E. Knuth is not copyrighted and can be used freely.
% Version 0 was released in December, 1981.
% Version 1 was released in September, 1982, with version 0 of TeX.
% Slight changes were made in October, 1982, for version 0.6 of TeX.
% Version 1.1 changed "←" to "\←" if not within an identifier (November, 1982).
% Version 1.2 added @= and @\ and marked changed modules (December, 1982).
% Version 1.3 marked and indexed changed modules better (January, 1983).
% Version 1.4 added "history" (February, 1983).
% Version 1.5 conformed to TeX version 0.96 (March, 1983).
% Version 1.6 conformed to TeX version 0.98 (May, 1983).
% Version 1.7 introduced the new change file format (June, 1983).
% Version 2 was released in July, 1983, with version 0.999 of TeX.
% Version 2.1 corrected a bug in changed←module reckoning (August, 1983).
% Version 2.2 corrected it better (August, 1983).
% Version 2.3 starts the output with \input webmac (August, 1983).
% Version 2.4 fixed a bug in compress(#) (September, 1983).
% Version 2.5 cleared xrefswitch after module names (November, 1983).
% Version 2.6 fixed a bug in declaration of trans array (January, 1984).

% Here is TeX material that gets inserted after \input webmac
\def\hang{\hangindent 3em\indent\ignorespaces}
\font\ninerm=amr9
\let\mc=\ninerm % medium caps for names like PASCAL
\def\PASCAL{{\mc PASCAL}}
\def\pb{$\.|\ldots\.|$} % pascal brackets (|...|)
\def\v{\.{\char'174}} % vertical (|) in typewriter font
\def\dleft{[\![} \def\dright{]\!]} % double brackets
\mathchardef\RA="3221 % right arrow
\mathchardef\BA="3224 % double arrow
\def\({} % kludge for alphabetizing certain module names

\def\title{WEAVE}
\def\contentspagenumber{15} % should be odd
\def\topofcontents{\null\vfill
  \titlefalse % include headline on the contents page
  \def\rheader{\mainfont Appendix D\hfil \contentspagenumber}
  \centerline{\titlefont The {\ttitlefont WEAVE} processor}
  \vskip 15pt
  \centerline{(Version 2.6)}
  \vfill}
\pageno=\contentspagenumber \advance\pageno by 1


\N1\*.  Introduction.
This program converts a \.{WEB} file to a \TeX\ file. It was written
by D. E. Knuth in October, 1981; a somewhat similar {\mc SAIL} program had
been developed in March, 1979, although the earlier program used a top-down
parsing method that is quite different from the present scheme.

The code uses a few features of the local \PASCAL\ compiler that may need
to be changed in other installations:

\yskip\item{1)} Case statements have a default.
\item{2)} Input-output routines may need to be adapted for use with a
particular
character set and/or for printing messages on the user's terminal.

\yskip\noindent
These features are also present in the \PASCAL\ version of \TeX, where they
are used in a similar (but more complex) way. System-dependent portions
of \.{WEAVE} can be identified by looking at the entries for `system
dependencies' in the index below.

The ``banner line'' defined here should be changed whenever \.{WEAVE}
is modified.

\Y\P\D \37$\\{banner}\S\.{\'This\ is\ Cedar\ Weave,\ Version\ 2.6\'}$\par
\fi

\M2\*. The program begins with a fairly normal header, made up of pieces that
will mostly be filled in later. The \.{WEB} input comes from files \\{web%
\←file}
and \\{change\←file}, and the \TeX\ output goes to file \\{tex\←file}.

If it is necessary to abort the job because of a fatal error, the program
calls the `\\{jump\←out}' procedure, which goes to the label \\{end\←of%
\←WEAVE}.

\Y\P\D \37$\\{end\←of\←WEAVE}=9999$\C{go here to wrap it up}\par
\P\D \37$\\{read\←ln}\S\\{readln}$\par
\P\D \37$\\{write\←ln}\S\\{writeln}$\par
\Y\P\hbox{\4}\X4:Compiler directives\X\6
\4\&{program}\1\  \37$\\{WEAVE}(\\{web\←file},\39\\{change\←file},\39\\{tex%
\←file})$;\6
\4\&{label} \37\\{end\←of\←WEAVE};\C{go here to finish}\6
\4\&{const} \37\X8\*:Constants in the outer block\X\6
\4\&{type} \37\X11:Types in the outer block\X\6
\4\&{var} \37\X9:Globals in the outer block\X\6
\X265\*:External procedure declarations for things implemented directly in
Cedar\X\6
\X30:Error handling procedures\X\6
\4\&{procedure}\1\  \37\\{initialize};\6
\4\&{var} \37\X16:Local variables for initialization\X\2\6
\&{begin} \37\X10:Set initial values\X\6
\&{end};\par
\fi

\M3. Some of this code is optional for use when debugging only;
such material is enclosed between the delimiters  \&{debug}  and $  \&{gubed}
$.
Other parts, delimited by  \&{stat}  and $  \&{tats} $, are optionally included
if statistics about \.{WEAVE}'s memory usage are desired.

\Y\P\D \37$\\{debug}\S\B$\C{change this to `$\\{debug}\equiv\null$' when
debugging}\par
\P\D \37$\\{gubed}\S\hbox{}\T$\C{change this to `$\\{gubed}\equiv\null$' when
debugging}\par
\P\F \37$\\{debug}\S\\{begin}$\par
\P\F \37$\\{gubed}\S\\{end}$\Y\par
\P\D \37$\\{stat}\S\B$\C{change this to `$\\{stat}\equiv\null$'   when
gathering usage statistics}\par
\P\D \37$\\{tats}\S\hbox{}\T$\C{change this to `$\\{tats}\equiv\null$'   when
gathering usage statistics}\par
\P\F \37$\\{stat}\S\\{begin}$\par
\P\F \37$\\{tats}\S\\{end}$\par
\fi

\M4. The \PASCAL\ compiler used to develop this system has ``compiler
directives'' that can appear in comments whose first character is a dollar
sign.
In production versions of \.{WEAVE} these directives tell the compiler that
it is safe to avoid range checks and to leave out the extra code it inserts
for the \PASCAL\ debugger's benefit, although interrupts will occur if
there is arithmetic overflow.

\Y\P$\4\X4:Compiler directives\X\S$\6
$\B\J\$\|C-,\39\|A+,\39\|D-\T$\C{no range check, catch arithmetic overflow, no
debug overhead}\6
\&{debug} \37$\B\J\$\|C+,\39\|D+\T$\ \&{gubed}\C{but turn everything on when
debugging}\par
\U section~2\*.\fi

\M5. Labels are given symbolic names by the following definitions. We insert
the label `\\{exit}:' just before the `\ignorespaces  \&{end} \unskip' of a
procedure in which we have used the `\&{return}' statement defined below;
the label `\\{restart}' is occasionally used at the very beginning of a
procedure; and the label `\\{reswitch}' is occasionally used just prior to
a \&{case} statement in which some cases change the conditions and we wish to
branch to the newly applicable case.
Loops that are set up with the \&{loop} construction defined below are
commonly exited by going to `\\{done}' or to `\\{found}' or to `\\{not%
\←found}',
and they are sometimes repeated by going to `\\{continue}'.

\Y\P\D \37$\\{exit}=10$\C{go here to leave a procedure}\par
\P\D \37$\\{restart}=20$\C{go here to start a procedure again}\par
\P\D \37$\\{reswitch}=21$\C{go here to start a case statement again}\par
\P\D \37$\\{continue}=22$\C{go here to resume a loop}\par
\P\D \37$\\{done}=30$\C{go here to exit a loop}\par
\P\D \37$\\{found}=31$\C{go here when you've found it}\par
\P\D \37$\\{not\←found}=32$\C{go here when you've found something else}\par
\fi

\M6. Here are some macros for common programming idioms.

\Y\P\D \37$\\{incr}(\#)\S\#\K\#+1$\C{increase a variable by unity}\par
\P\D \37$\\{decr}(\#)\S\#\K\#-1$\C{decrease a variable by unity}\par
\P\D \37$\\{loop}\S$\ \&{while} $\\{true}$ \1\&{do}\ \C{repeat over and over
until a \&{goto}  happens}\par
\P\D \37$\\{do\←nothing}\S$\C{empty statement}\par
\P\D \37$\\{return}\S$\1\5
\&{goto} \37\\{exit}\C{terminate a procedure call}\2\par
\P\F \37$\\{return}\S\\{nil}$\par
\P\F \37$\\{loop}\S\\{xclause}$\par
\fi

\M7. We assume that   \&{case}  statements may include a default case that
applies
if no matching label is found. Thus, we shall use constructions like
$$\vbox{\halign{#\hfil\cr
 \&{case} $\|x$ \&{of}\cr
1: $\langle\,$code for $x=1\,\rangle$;\cr
3: $\langle\,$code for $x=3\,\rangle$;\cr
 \&{othercases}  $\langle\,$code for $\|x\I1$ and $\|x\I3$$\,\rangle$\cr
  \&{endcases} \cr}}$$
since most \PASCAL\ compilers have plugged this hole in the language by
incorporating some sort of default mechanism. For example, the compiler
used to develop \.{WEB} and \TeX\ allows `\\{others}:' as a default label,
and other \PASCAL s allow syntaxes like `\ignorespaces \&{else} \unskip' or
`\\{otherwise}' or `\\{otherwise}:', etc. The definitions of  \&{othercases}
and   \&{endcases}  should be changed to agree with local conventions.
(Of course, if no default mechanism is available, the   \&{case}  statements of
this program must be extended by listing all remaining cases.)

\Y\P\D \37$\\{othercases}\S\\{others}$: \37\C{default for cases not listed
explicitly}\par
\P\D \37$\\{endcases}\S$\ \&{end} \C{follows the default case in an extended   %
\&{case}  statement}\par
\P\F \37$\\{othercases}\S\\{else}$\par
\P\F \37$\\{endcases}\S\\{end}$\par
\fi

\M8\*. The following parameters are set big enough to handle \TeX, so they
should be sufficient for most applications of \.{WEAVE}.

\Y\P$\4\X8\*:Constants in the outer block\X\S$\6
$\\{max\←bytes}=45000$;\C{$1/\\{ww}$ times the number of bytes in identifiers,
 index entries, and module names; must be less than 65536}\6
$\\{max\←names}=5000$;\C{number of identifiers, index entries, and module
names;   must be less than 10240}\6
$\\{max\←modules}=2000$;\C{greater than the total number of modules}\6
$\\{hash\←size}=353$;\C{should be prime}\6
$\\{buf\←size}=5000$;\C{maximum length of input line}\6
$\\{longest\←name}=400$;\C{module names shouldn't be longer than this}\6
$\\{long\←buf\←size}=5400$;\C{$\\{buf\←size}+\\{longest\←name}$}\6
$\\{line\←length}=80$;\C{lines of \TeX\ output have at most this many
characters,   should be less than 256}\6
$\\{max\←refs}=20000$;\C{number of cross references; must be less than 65536}\6
$\\{max\←toks}=20000$;\C{number of symbols in \PASCAL\ texts being parsed;
must be less than 65536}\6
$\\{max\←texts}=2000$;\C{number of phrases in \PASCAL\ texts being parsed;
must be less than 10240}\6
$\\{max\←scraps}=1000$;\C{number of tokens in \PASCAL\ texts being parsed}\6
$\\{stack\←size}=200$;\C{number of simultaneous output levels}\par
\U section~2\*.\fi

\M9. A global variable called \\{history} will contain one of four values
at the end of every run: \\{spotless} means that no unusual messages were
printed; \\{harmless\←message} means that a message of possible interest
was printed but no serious errors were detected; \\{error\←message} means that
at least one error was found; \\{fatal\←message} means that the program
terminated abnormally. The value of \\{history} does not influence the
behavior of the program; it is simply computed for the convenience
of systems that might want to use such information.

\Y\P\D \37$\\{spotless}=0$\C{\\{history} value for normal jobs}\par
\P\D \37$\\{harmless\←message}=1$\C{\\{history} value when non-serious info was
printed}\par
\P\D \37$\\{error\←message}=2$\C{\\{history} value when an error was noted}\par
\P\D \37$\\{fatal\←message}=3$\C{\\{history} value when we had to stop
prematurely}\Y\par
\P\D \37$\\{mark\←harmless}\S\hbox{}$\ \&{if} $\\{history}=\\{spotless}$ \1%
\&{then}\5
$\\{history}\K\\{harmless\←message}$\2\par
\P\D \37$\\{mark\←error}\S\\{history}\K\\{error\←message}$\par
\P\D \37$\\{mark\←fatal}\S\\{history}\K\\{fatal\←message}$\par
\Y\P$\4\X9:Globals in the outer block\X\S$\6
\4\\{history}: \37$\\{spotless}\to\\{fatal\←message}$;\C{how bad was this run?}%
\par
\A sections~13, 20, 23, 25, 27, 29, 37, 39, 45, 49\*, 54, 56, 64, 66, 72, 74,
94, 109, 115, 119, 122, 130, 145, 178, 203, 220, 230, 235, 241, 243, 245, 247,
and~259.
\U section~2\*.\fi

\M10. \P$\X10:Set initial values\X\S$\6
$\\{history}\K\\{spotless}$;\par
\A sections~14, 17\*, 18, 21\*, 26\*, 41, 43, 50, 55, 58, 95, 103, 125, 127,
146, 204, 246, 249, and~260.
\U section~2\*.\fi

\N11.  The character set.
One of the main goals in the design of \.{WEB} has been to make it readily
portable between a wide variety of computers. Yet \.{WEB} by its very
nature must use a greater variety of characters than most computer
programs deal with, and character encoding is one of the areas in which
existing machines differ most widely from each other.

To resolve this problem, all input to \.{WEAVE} and \.{TANGLE} is
converted to an internal seven-bit code that is essentially standard
ASCII, the ``American Standard Code for Information Interchange.''  The
conversion is done immediately when each character is read in. Conversely,
characters are converted from ASCII to the user's external representation
just before they are output.

Such an internal code is relevant to users of \.{WEB} only because it is
the code used for preprocessed constants like \.{"A"}. If you are writing
a program in \.{WEB} that makes use of such one-character constants, you
should convert your input to ASCII form, like \.{WEAVE} and \.{TANGLE} do.
Otherwise \.{WEB}'s internal coding scheme does not affect you.

Here is a table of the standard visible ASCII codes:
$$\def\:{\char\count255\global\advance\count255 by 1}
\count255='40
\vbox{
\hbox{\hbox to 40pt{\it\hfill0\/\hfill}%
\hbox to 40pt{\it\hfill1\/\hfill}%
\hbox to 40pt{\it\hfill2\/\hfill}%
\hbox to 40pt{\it\hfill3\/\hfill}%
\hbox to 40pt{\it\hfill4\/\hfill}%
\hbox to 40pt{\it\hfill5\/\hfill}%
\hbox to 40pt{\it\hfill6\/\hfill}%
\hbox to 40pt{\it\hfill7\/\hfill}}
\vskip 4pt
\hrule
\def\↑{\vrule height 10.5pt depth 4.5pt}
\halign{\hbox to 0pt{\hskip -24pt\O{#0}\hfill}&\↑
\hbox to 40pt{\tt\hfill#\hfill\↑}&
&\hbox to 40pt{\tt\hfill#\hfill\↑}\cr
04&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
05&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
06&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
07&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
10&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
11&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
12&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
13&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
14&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
15&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
16&\:&\:&\:&\:&\:&\:&\:&\:\cr\noalign{\hrule}
17&\:&\:&\:&\:&\:&\:&\:\cr}
\hrule width 280pt}$$
(Actually, of course, code \O{040} is an invisible blank space.)  Code \O{136}
was once an upward arrow (\.{\char'13}), and code \O{137} was
once a left arrow (\.↑↑X), in olden times when the first draft
of ASCII code was prepared; but \.{WEB} works with today's standard
ASCII in which those codes represent circumflex and underline as shown.

\Y\P$\4\X11:Types in the outer block\X\S$\6
$\\{ASCII\←code}=0\to127$;\C{seven-bit numbers, a subrange of the integers}\par
\A sections~12\*, 36, 38, 47, 48\*, 53, and~202.
\U section~2\*.\fi

\M12\*. The original \PASCAL\ compiler was designed in the late 60s, when
six-bit
character sets were common, so it did not make provision for lowercase
letters. Nowadays, of course, we need to deal with both capital and small
letters in a convenient way, so \.{WEB} assumes that it is being used
with a \PASCAL\ whose character set contains at least the characters of
standard ASCII as listed above. Some \PASCAL\ compilers use the original
name \\{char} for the data type associated with the characters in text files,
while other \PASCAL s consider \\{char} to be a 64-element subrange of a larger
data type that has some other name.

In order to accommodate this difference, we shall use the name \\{text\←char}
to stand for the data type of the characters in the input and output
files.  We shall also assume that \\{text\←char} consists of the elements
$\\{chr}(\\{first\←text\←char})$ through $\\{chr}(\\{last\←text\←char})$,
inclusive. The
following definitions should be adjusted if necessary.

\Y\P\D \37$\\{text\←char}\S\\{char}$\C{the data type of characters in text
files}\par
\P\D \37$\\{first\←text\←char}=0$\C{ordinal number of the smallest element of %
\\{text\←char}}\par
\P\D \37$\\{last\←text\←char}=255$\C{ordinal number of the largest element of %
\\{text\←char}}\par
\Y\P$\4\X11:Types in the outer block\X\mathrel{+}\S$\6
$\\{text\←file}=$\1\5
\&{packed} \37\&{file} \1\&{of}\5
\\{text\←char};\2\2\par
\fi

\M13. The \.{WEAVE} and \.{TANGLE} processors convert between ASCII code and
the user's external character set by means of arrays \\{xord} and \\{xchr}
that are analogous to \PASCAL's \\{ord} and \\{chr} functions.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{xord}: \37\&{array} $[\\{text\←char}]$ \1\&{of}\5
\\{ASCII\←code};\C{specifies conversion of input characters}\2\6
\4\\{xchr}: \37\&{array} $[\\{ASCII\←code}]$ \1\&{of}\5
\\{text\←char};\C{specifies conversion of output characters}\2\par
\fi

\M14. If we assume that every system using \.{WEB} is able to read and write
the
visible characters of standard ASCII (although not necessarily using the
ASCII codes to represent them), the following assignment statements initialize
most of the \\{xchr} array properly, without needing any system-dependent
changes. For example, the statement \.{xchr[@\'101]:=\'A\'} that appears
in the present \.{WEB} file might be encoded in, say, {\mc EBCDIC} code
on the external medium on which it resides, but \.{TANGLE} will convert from
this external code to ASCII and back again. Therefore the assignment
statement \.{XCHR[65]:=\'A\'} will appear in the corresponding \PASCAL\ file,
and \PASCAL\ will compile this statement so that $\\{xchr}[65]$ receives the
character \.A in the external (\\{char}) code. Note that it would be quite
incorrect to say \.{xchr[@\'101]:="A"}, because \.{"A"} is a constant of
type \\{integer}, not \\{char}, and because we have $\.{"A"}=65$ regardless of
the external character set.

\Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
$\\{xchr}[\O{40}]\K\.{\'\ \'}$;\5
$\\{xchr}[\O{41}]\K\.{\'!\'}$;\5
$\\{xchr}[\O{42}]\K\.{\'"\'}$;\5
$\\{xchr}[\O{43}]\K\.{\'\#\'}$;\5
$\\{xchr}[\O{44}]\K\.{\'\$\'}$;\5
$\\{xchr}[\O{45}]\K\.{\'\%\'}$;\5
$\\{xchr}[\O{46}]\K\.{\'\&\'}$;\5
$\\{xchr}[\O{47}]\K\.{\'\'}\.{\'\'}$;\6
$\\{xchr}[\O{50}]\K\.{\'(\'}$;\5
$\\{xchr}[\O{51}]\K\.{\')\'}$;\5
$\\{xchr}[\O{52}]\K\.{\'*\'}$;\5
$\\{xchr}[\O{53}]\K\.{\'+\'}$;\5
$\\{xchr}[\O{54}]\K\.{\',\'}$;\5
$\\{xchr}[\O{55}]\K\.{\'-\'}$;\5
$\\{xchr}[\O{56}]\K\.{\'.\'}$;\5
$\\{xchr}[\O{57}]\K\.{\'/\'}$;\6
$\\{xchr}[\O{60}]\K\.{\'0\'}$;\5
$\\{xchr}[\O{61}]\K\.{\'1\'}$;\5
$\\{xchr}[\O{62}]\K\.{\'2\'}$;\5
$\\{xchr}[\O{63}]\K\.{\'3\'}$;\5
$\\{xchr}[\O{64}]\K\.{\'4\'}$;\5
$\\{xchr}[\O{65}]\K\.{\'5\'}$;\5
$\\{xchr}[\O{66}]\K\.{\'6\'}$;\5
$\\{xchr}[\O{67}]\K\.{\'7\'}$;\6
$\\{xchr}[\O{70}]\K\.{\'8\'}$;\5
$\\{xchr}[\O{71}]\K\.{\'9\'}$;\5
$\\{xchr}[\O{72}]\K\.{\':\'}$;\5
$\\{xchr}[\O{73}]\K\.{\';\'}$;\5
$\\{xchr}[\O{74}]\K\.{\'<\'}$;\5
$\\{xchr}[\O{75}]\K\.{\'=\'}$;\5
$\\{xchr}[\O{76}]\K\.{\'>\'}$;\5
$\\{xchr}[\O{77}]\K\.{\'?\'}$;\6
$\\{xchr}[\O{100}]\K\.{\'@\'}$;\5
$\\{xchr}[\O{101}]\K\.{\'A\'}$;\5
$\\{xchr}[\O{102}]\K\.{\'B\'}$;\5
$\\{xchr}[\O{103}]\K\.{\'C\'}$;\5
$\\{xchr}[\O{104}]\K\.{\'D\'}$;\5
$\\{xchr}[\O{105}]\K\.{\'E\'}$;\5
$\\{xchr}[\O{106}]\K\.{\'F\'}$;\5
$\\{xchr}[\O{107}]\K\.{\'G\'}$;\6
$\\{xchr}[\O{110}]\K\.{\'H\'}$;\5
$\\{xchr}[\O{111}]\K\.{\'I\'}$;\5
$\\{xchr}[\O{112}]\K\.{\'J\'}$;\5
$\\{xchr}[\O{113}]\K\.{\'K\'}$;\5
$\\{xchr}[\O{114}]\K\.{\'L\'}$;\5
$\\{xchr}[\O{115}]\K\.{\'M\'}$;\5
$\\{xchr}[\O{116}]\K\.{\'N\'}$;\5
$\\{xchr}[\O{117}]\K\.{\'O\'}$;\6
$\\{xchr}[\O{120}]\K\.{\'P\'}$;\5
$\\{xchr}[\O{121}]\K\.{\'Q\'}$;\5
$\\{xchr}[\O{122}]\K\.{\'R\'}$;\5
$\\{xchr}[\O{123}]\K\.{\'S\'}$;\5
$\\{xchr}[\O{124}]\K\.{\'T\'}$;\5
$\\{xchr}[\O{125}]\K\.{\'U\'}$;\5
$\\{xchr}[\O{126}]\K\.{\'V\'}$;\5
$\\{xchr}[\O{127}]\K\.{\'W\'}$;\6
$\\{xchr}[\O{130}]\K\.{\'X\'}$;\5
$\\{xchr}[\O{131}]\K\.{\'Y\'}$;\5
$\\{xchr}[\O{132}]\K\.{\'Z\'}$;\5
$\\{xchr}[\O{133}]\K\.{\'[\'}$;\5
$\\{xchr}[\O{134}]\K\.{\'\\\'}$;\5
$\\{xchr}[\O{135}]\K\.{\']\'}$;\5
$\\{xchr}[\O{136}]\K\.{\'\↑\'}$;\5
$\\{xchr}[\O{137}]\K\.{\'\←\'}$;\6
$\\{xchr}[\O{140}]\K\.{\'\`\'}$;\5
$\\{xchr}[\O{141}]\K\.{\'a\'}$;\5
$\\{xchr}[\O{142}]\K\.{\'b\'}$;\5
$\\{xchr}[\O{143}]\K\.{\'c\'}$;\5
$\\{xchr}[\O{144}]\K\.{\'d\'}$;\5
$\\{xchr}[\O{145}]\K\.{\'e\'}$;\5
$\\{xchr}[\O{146}]\K\.{\'f\'}$;\5
$\\{xchr}[\O{147}]\K\.{\'g\'}$;\6
$\\{xchr}[\O{150}]\K\.{\'h\'}$;\5
$\\{xchr}[\O{151}]\K\.{\'i\'}$;\5
$\\{xchr}[\O{152}]\K\.{\'j\'}$;\5
$\\{xchr}[\O{153}]\K\.{\'k\'}$;\5
$\\{xchr}[\O{154}]\K\.{\'l\'}$;\5
$\\{xchr}[\O{155}]\K\.{\'m\'}$;\5
$\\{xchr}[\O{156}]\K\.{\'n\'}$;\5
$\\{xchr}[\O{157}]\K\.{\'o\'}$;\6
$\\{xchr}[\O{160}]\K\.{\'p\'}$;\5
$\\{xchr}[\O{161}]\K\.{\'q\'}$;\5
$\\{xchr}[\O{162}]\K\.{\'r\'}$;\5
$\\{xchr}[\O{163}]\K\.{\'s\'}$;\5
$\\{xchr}[\O{164}]\K\.{\'t\'}$;\5
$\\{xchr}[\O{165}]\K\.{\'u\'}$;\5
$\\{xchr}[\O{166}]\K\.{\'v\'}$;\5
$\\{xchr}[\O{167}]\K\.{\'w\'}$;\6
$\\{xchr}[\O{170}]\K\.{\'x\'}$;\5
$\\{xchr}[\O{171}]\K\.{\'y\'}$;\5
$\\{xchr}[\O{172}]\K\.{\'z\'}$;\5
$\\{xchr}[\O{173}]\K\.{\'\{\'}$;\5
$\\{xchr}[\O{174}]\K\.{\'|\'}$;\5
$\\{xchr}[\O{175}]\K\.{\'\}\'}$;\5
$\\{xchr}[\O{176}]\K\.{\'\~\'}$;\6
$\\{xchr}[0]\K\.{\'\ \'}$;\5
$\\{xchr}[\O{177}]\K\.{\'\ \'}$;\C{these ASCII codes are not used}\par
\fi

\M15. Some of the ASCII codes below \O{40} have been given symbolic names in
\.{WEAVE} and \.{TANGLE} because they are used with a special meaning.

\Y\P\D \37$\\{and\←sign}=\O{4}$\C{equivalent to `\.{and}'}\par
\P\D \37$\\{not\←sign}=\O{5}$\C{equivalent to `\.{not}'}\par
\P\D \37$\\{set\←element\←sign}=\O{6}$\C{equivalent to `\.{in}'}\par
\P\D \37$\\{tab\←mark}=\O{11}$\C{ASCII code used as tab-skip}\par
\P\D \37$\\{line\←feed}=\O{12}$\C{ASCII code thrown away at end of line}\par
\P\D \37$\\{form\←feed}=\O{14}$\C{ASCII code used at end of page}\par
\P\D \37$\\{carriage\←return}=\O{15}$\C{ASCII code used at end of line}\par
\P\D \37$\\{left\←arrow}=\O{30}$\C{equivalent to `\.{:=}'}\par
\P\D \37$\\{not\←equal}=\O{32}$\C{equivalent to `\.{<>}'}\par
\P\D \37$\\{less\←or\←equal}=\O{34}$\C{equivalent to `\.{<=}'}\par
\P\D \37$\\{greater\←or\←equal}=\O{35}$\C{equivalent to `\.{>=}'}\par
\P\D \37$\\{equivalence\←sign}=\O{36}$\C{equivalent to `\.{==}'}\par
\P\D \37$\\{or\←sign}=\O{37}$\C{equivalent to `\.{or}'}\par
\fi

\M16. When we initialize the \\{xord} array and the remaining parts of %
\\{xchr},
it will be convenient to make use of an index variable, \|i.

\Y\P$\4\X16:Local variables for initialization\X\S$\6
\4\|i: \37$0\to\\{last\←text\←char}$;\par
\A sections~40, 57, and~248.
\U section~2\*.\fi

\M17\*. Here now is the system-dependent part of the character set.
If \.{WEB} is being implemented on a garden-variety \PASCAL\ for which
only standard ASCII codes will appear in the input and output files, you
don't need to make any changes here. But at MIT, for example, the code in
this module should be changed to
$$\hbox{ \&{for} $\|i\K1\mathrel{\&{to}}\O{37}$ \&{do} $\\{xchr}[\|i]\K\\{chr}(%
\|i)$;}$$
\.{WEB}'s character set is essentially identical to MIT's, even with respect to
characters less than \O{40}.

Changes to the present module will make \.{WEB} more friendly on computers
that have an extended character set, so that one can type things like
\.↑↑Z\ instead of \.{<>}. If you have an extended set of characters that
are easily incorporated into text files, you can assign codes arbitrarily
here, giving an \\{xchr} equivalent to whatever characters the users of
\.{WEB} are allowed to have in their input files, provided that unsuitable
characters do not correspond to special codes like \\{carriage\←return}
that are listed above.

(The present file \.{WEAVE.WEB} does not contain any of the non-ASCII
characters, because it is intended to be used with all implementations of
\.{WEB}.  It was originally created on a Stanford system that has a
convenient extended character set, then ``sanitized'' by applying another
program that transliterated all of the non-standard characters into
standard equivalents.)

\Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
\&{for} $\|i\K1\mathrel{\&{to}}\O{37}$ \1\&{do}\5
$\\{xchr}[\|i]\K\\{chr}(\|i)$;\2\par
\fi

\M18. The following system-independent code makes the \\{xord} array contain a
suitable inverse to the information in \\{xchr}.

\Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
\&{for} $\|i\K\\{first\←text\←char}\mathrel{\&{to}}\\{last\←text\←char}$ \1%
\&{do}\5
$\\{xord}[\\{chr}(\|i)]\K\O{40}$;\2\6
\&{for} $\|i\K1\mathrel{\&{to}}\O{176}$ \1\&{do}\5
$\\{xord}[\\{xchr}[\|i]]\K\|i$;\2\par
\fi

\N19.  Input and output.
The input conventions of this program are intended to be very much like those
of \TeX\ (except, of course, that they are much simpler, because much less
needs to be done). Furthermore they are identical to those of \.{TANGLE}.
Therefore people who need to make modifications to all three systems
should be able to do so without too many headaches.

We use the standard \PASCAL\ input/output procedures in several places that
\TeX\ cannot, since \.{WEAVE} does not have to deal with files that are named
dynamically by the user, and since there is no input from the terminal.

\fi

\M20. Terminal output is done by writing on file \\{term\←out}, which is
assumed to
consist of characters of type \\{text\←char}:

\Y\P\D \37$\\{print}(\#)\S\\{write}(\\{term\←out},\39\#)$\C{`\\{print}' means
write on the terminal}\par
\P\D \37$\\{print\←ln}(\#)\S\\{write\←ln}(\\{term\←out},\39\#)$\C{`\\{print}'
and then start new line}\par
\P\D \37$\\{new\←line}\S\\{write\←ln}(\\{term\←out})$\C{start new line}\par
\P\D \37$\\{print\←nl}(\#)\S$\C{print information starting on a new line}\6
\&{begin} \37\\{new\←line};\5
$\\{print}(\#)$;\6
\&{end}\par
\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{term\←out}: \37\\{text\←file};\C{the terminal as an output file}\par
\fi

\M21\*. Different systems have different ways of specifying that the output on
a
certain file will appear on the user's terminal. Here is one way to do this
on the \PASCAL\ system that was used in \.{TANGLE}'s initial development:

\Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
$\\{tty\←rewrite}(\\{term\←out})$;\C{send \\{term\←out} output to the terminal}%
\par
\fi

\M22. The \\{update\←terminal} procedure is called when we want
to make sure that everything we have output to the terminal so far has
actually left the computer's internal buffers and been sent.

\Y\P\D \37$\\{update\←terminal}\S\\{break}(\\{term\←out})$\C{empty the terminal
output buffer}\par
\fi

\M23. The main input comes from \\{web\←file}; this input may be overridden
by changes in \\{change\←file}. (If \\{change\←file} is empty, there are no
changes.)

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{web\←file}: \37\\{text\←file};\C{primary input}\6
\4\\{change\←file}: \37\\{text\←file};\C{updates}\par
\fi

\M24\*. The following code opens the input files.  Since these files were
listed
in the program header, we assume that the \PASCAL\ runtime system has
already checked that suitable file names have been given; therefore no
additional error checking needs to be done. We will see below that
\.{WEAVE} reads through the entire input twice.

\Y\P\4\&{procedure}\1\  \37\\{open\←input};\C{prepare to read \\{web\←file} and
\\{change\←file}}\2\6
\&{begin} \37$\\{file\←reset}(\\{web\←file},\39\.{\'web\ \ \ \ \ \ \ \'})$;\5
$\\{file\←reset}(\\{change\←file},\39\.{\'changes\ \ \ \'})$;\6
\&{end};\par
\fi

\M25. The main output goes to \\{tex\←file}.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{tex\←file}: \37\\{text\←file};\par
\fi

\M26\*. The following code opens \\{tex\←file}.
Since this file was listed in the program header, we assume that the
\PASCAL\ runtime system has checked that a suitable external file name has
been given.

\Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
$\\{file\←rewrite}(\\{tex\←file},\39\.{\'tex\ \ \ \ \ \ \ \'})$;\par
\fi

\M27. Input goes into an array called \\{buffer}.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{buffer}: \37\&{array} $[0\to\\{long\←buf\←size}]$ \1\&{of}\5
\\{ASCII\←code};\2\par
\fi

\M28. The \\{input\←ln} procedure brings the next line of input from the
specified
file into the \\{buffer} array and returns the value \\{true}, unless the file
has
already been entirely read, in which case it returns \\{false}. The conventions
of \TeX\ are followed; i.e., \\{ASCII\←code} numbers representing the next line
of the file are input into $\\{buffer}[0]$, $\\{buffer}[1]$, \dots,
$\\{buffer}[\\{limit}-1]$; trailing blanks are ignored;
and the global variable \\{limit} is set to the length of the
line. The value of \\{limit} must be strictly less than \\{buf\←size}.

We assume that none of the \\{ASCII\←code} values
of $\\{buffer}[\|j]$ for $0\L\|j<\\{limit}$ is equal to 0, \O{177}, \\{line%
\←feed}, \\{form\←feed},
or \\{carriage\←return}. Since \\{buf\←size} is strictly less than \\{long\←buf%
\←size},
some of \.{WEAVE}'s routines use the fact that it is safe to refer to
$\\{buffer}[\\{limit}+2]$ without overstepping the bounds of the array.

\Y\P\4\&{function}\1\  \37$\\{input\←ln}(\mathop{\&{var}}\|f:\\{text\←file})$: %
\37\\{boolean};\C{inputs a line or returns \\{false}}\6
\4\&{var} \37\\{final\←limit}: \37$0\to\\{buf\←size}$;\C{\\{limit} without
trailing blanks}\2\6
\&{begin} \37$\\{limit}\K0$;\5
$\\{final\←limit}\K0$;\6
\&{if} $\\{eof}(\|f)$ \1\&{then}\5
$\\{input\←ln}\K\\{false}$\6
\4\&{else} \&{begin} \37\&{while} $\R\\{eoln}(\|f)$ \1\&{do}\6
\&{begin} \37$\\{buffer}[\\{limit}]\K\\{xord}[\|f\↑]$;\5
$\\{get}(\|f)$;\5
$\\{incr}(\\{limit})$;\6
\&{if} $\\{buffer}[\\{limit}-1]\I\.{"\ "}$ \1\&{then}\5
$\\{final\←limit}\K\\{limit}$;\2\6
\&{if} $\\{limit}=\\{buf\←size}$ \1\&{then}\6
\&{begin} \37\&{while} $\R\\{eoln}(\|f)$ \1\&{do}\5
$\\{get}(\|f)$;\2\6
$\\{decr}(\\{limit})$;\C{keep $\\{buffer}[\\{buf\←size}]$ empty}\6
$\\{print\←nl}(\.{\'!\ Input\ line\ too\ long\'})$;\5
$\\{loc}\K0$;\5
\\{error};\6
\&{end};\2\6
\&{end};\2\6
$\\{read\←ln}(\|f)$;\5
$\\{limit}\K\\{final\←limit}$;\5
$\\{input\←ln}\K\\{true}$;\6
\&{end};\2\6
\&{end};\par
\fi

\N29.  Reporting errors to the user.
The \.{WEAVE} processor operates in three phases: first it inputs the source
file and stores cross-reference data, then it inputs the source once again and
produces the \TeX\ output file, and finally it sorts and outputs the index.

The global variables \\{phase\←one} and \\{phase\←three} tell which Phase we
are in.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{phase\←one}: \37\\{boolean};\C{\\{true} in Phase I, \\{false} in Phases II
and III}\6
\4\\{phase\←three}: \37\\{boolean};\C{\\{true} in Phase III, \\{false} in
Phases I and II}\par
\fi

\M30. If an error is detected while we are debugging,
we usually want to look at the contents of memory.
A special procedure will be declared later for this purpose.

\Y\P$\4\X30:Error handling procedures\X\S$\6
\&{debug} \37\ \&{procedure}\1\  \37\\{debug\←help};\5
\\{forward};\ \&{gubed} \par
\A sections~31 and~33.
\U section~2\*.\fi

\M31. The command `$\\{err\←print}(\.{\'!\ Error\ message\'})$' will report a
syntax error to
the user, by printing the error message at the beginning of a new line and
then giving an indication of where the error was spotted in the source file.
Note that no period follows the error message, since the error routine
will automatically supply a period.

The actual error indications are provided by a procedure called \\{error}.
However, error messages are not actually reported during phase one,
since errors detected on the first pass will be detected again
during the second.

\Y\P\D \37$\\{err\←print}(\#)\S$\1\6
\&{begin} \37\&{if} $\R\\{phase\←one}$ \1\&{then}\6
\&{begin} \37\\{new\←line};\5
$\\{print}(\#)$;\5
\\{error};\6
\&{end};\2\6
\&{end}\2\par
\Y\P$\4\X30:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{error};\C{prints `\..' and location of error message}%
\6
\4\&{var} \37$\|k,\39\|l$: \37$0\to\\{long\←buf\←size}$;\C{indices into %
\\{buffer}}\2\6
\&{begin} \37\X32\*:Print error location based on input buffer\X;\6
\\{update\←terminal};\5
\\{mark\←error};\6
\&{debug} \37$\\{debug\←skipped}\K\\{debug\←cycle}$;\5
\\{debug\←help};\ \&{gubed}\6
\&{end};\par
\fi

\M32\*. The error locations can be indicated by using the global variables
\\{loc}, \\{line}, and \\{changing}, which tell respectively the first
unlooked-at position in \\{buffer}, the current line number, and whether or not
the current line is from \\{change\←file} or \\{web\←file}.
This routine should be modified on systems whose standard text editor
has special line-numbering conventions.

\Y\P$\4\X32\*:Print error location based on input buffer\X\S$\6
\&{begin} \37\&{if} $\\{loc}\G\\{limit}$ \1\&{then}\5
$\|l\K\\{limit}$\6
\4\&{else} $\|l\K\\{loc}$;\2\6
\&{if} $\\{changing}$ \1\&{then}\5
$\\{print\←ln}(\.{\'.\ (change\ file\ pos:\'},\39\\{file\←get\←pos}(\\{change%
\←file})-(\\{limit}-\|l)-2:1,\39\.{\')\'})$\6
\4\&{else} $\\{print\←ln}(\.{\'.\ (pos:\'},\39\\{file\←get\←pos}(\\{web%
\←file})-(\\{limit}-\|l)-2:1,\39\.{\')\'})$;\2\6
\&{for} $\|k\K1\mathrel{\&{to}}\|l$ \1\&{do}\6
\&{if} $\\{buffer}[\|k-1]=\\{tab\←mark}$ \1\&{then}\5
$\\{print}(\.{\'\ \'})$\6
\4\&{else} $\\{print}(\\{xchr}[\\{buffer}[\|k-1]])$;\C{print the characters
already read}\2\2\6
\\{new\←line};\6
\&{for} $\|k\K1\mathrel{\&{to}}\|l$ \1\&{do}\5
$\\{print}(\.{\'\ \'})$;\C{space out the next line}\2\6
\&{for} $\|k\K\|l+1\mathrel{\&{to}}\\{limit}$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{buffer}[\|k-1]])$;\C{print the part not yet read}\2\6
\&{if} $\\{buffer}[\\{limit}]=\.{"|"}$ \1\&{then}\5
$\\{print}(\\{xchr}[\.{"|"}])$;\C{end of \PASCAL\ text in module names}\2\6
$\\{print}(\.{\'\ \'})$;\C{this space separates the message from future
asterisks}\6
\&{end}\par
\U section~31.\fi

\M33. The \\{jump\←out} procedure just cuts across all active procedure levels
and jumps out of the program. This is the only non-local \&{goto} statement
in \.{WEAVE}. It is used when no recovery from a particular error has
been provided.

Some \PASCAL\ compilers do not implement non-local \&{goto}  statements.
In such cases the code that appears at label \\{end\←of\←WEAVE} should be
copied into the \\{jump\←out} procedure, followed by a call to a system
procedure
that terminates the program.

\Y\P\D \37$\\{fatal\←error}(\#)\S$\1\6
\&{begin} \37\\{new\←line};\5
$\\{print}(\#)$;\5
\\{error};\5
\\{mark\←fatal};\5
\\{jump\←out};\6
\&{end}\2\par
\Y\P$\4\X30:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{jump\←out};\2\6
\&{begin} \37\&{goto} \37\\{end\←of\←WEAVE};\6
\&{end};\par
\fi

\M34. Sometimes the program's behavior is far different from what it should be,
and \.{WEAVE} prints an error message that is really for the \.{WEAVE}
maintenance person, not the user. In such cases the program says
$\\{confusion}(\.{\'indication\ of\ where\ we\ are\'})$.

\Y\P\D \37$\\{confusion}(\#)\S\\{fatal\←error}(\.{\'!\ This\ can\'}\.{\'t\
happen\ (\'},\39\#,\39\.{\')\'})$\par
\fi

\M35. An overflow stop occurs if \.{WEAVE}'s tables aren't large enough.

\Y\P\D \37$\\{overflow}(\#)\S\\{fatal\←error}(\.{\'!\ Sorry,\ \'},\39\#,\39\.{%
\'\ capacity\ exceeded\'})$\par
\fi

\N36.  Data structures.
During the first phase of its processing, \.{WEAVE} puts identifier names,
index entries, and module names into the large \\{byte\←mem} array, which is
packed with seven-bit integers. Allocation is sequential, since names are
never deleted.

An auxiliary array \\{byte\←start} is used as a directory for \\{byte\←mem},
and the \\{link}, \\{ilk}, and \\{xref} arrays give further information about
names.
These auxiliary arrays consist of sixteen-bit items.

\Y\P$\4\X11:Types in the outer block\X\mathrel{+}\S$\6
$\\{eight\←bits}=0\to255$;\C{unsigned one-byte quantity}\6
$\\{sixteen\←bits}=0\to65535$;\C{unsigned two-byte quantity}\par
\fi

\M37. \.{WEAVE} has been designed to avoid the need for indices that are more
than sixteen bits wide, so that it can be used on most computers. But
there are programs that need more than 65536 bytes; \TeX\ is one of these.
To get around this problem, a slight complication has been added to the
data structures:  \\{byte\←mem} is a two-dimensional array, whose first index
is either 0 or 1. (For generality, the first index is actually allowed to
run between 0 and $\\{ww}-1$, where \\{ww} is defined to be 2; the program will
work for any positive value of \\{ww}, and it can be simplified in obvious
ways if $\\{ww}=1$.)

\Y\P\D \37$\\{ww}=2$\C{we multiply the byte capacity by approximately this
amount}\par
\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{byte\←mem}: \37\&{packed} \37\&{array} $[0\to\\{ww}-1,\390\to\\{max%
\←bytes}]$ \1\&{of}\5
\\{ASCII\←code};\C{characters of names}\2\6
\4\\{byte\←start}: \37\&{array} $[0\to\\{max\←names}]$ \1\&{of}\5
\\{sixteen\←bits};\C{directory into \\{byte\←mem}}\2\6
\4\\{link}: \37\&{array} $[0\to\\{max\←names}]$ \1\&{of}\5
\\{sixteen\←bits};\C{hash table or tree links}\2\6
\4\\{ilk}: \37\&{array} $[0\to\\{max\←names}]$ \1\&{of}\5
\\{sixteen\←bits};\C{type codes or tree links}\2\6
\4\\{xref}: \37\&{array} $[0\to\\{max\←names}]$ \1\&{of}\5
\\{sixteen\←bits};\C{heads of cross-reference lists}\2\par
\fi

\M38. The names of identifiers are found by computing a hash address \|h and
then looking at strings of bytes signified by $\\{hash}[\|h]$, $\\{link}[%
\\{hash}[\|h]]$,
$\\{link}[\\{link}[\\{hash}[\|h]]]$, \dots, until either finding the desired
name
or encountering a zero.

A `\\{name\←pointer}' variable, which signifies a name, is an index into
\\{byte\←start}. The actual sequence of characters in the name pointed to by
\|p appears in positions $\\{byte\←start}[\|p]$ to $\\{byte\←start}[\|p+%
\\{ww}]-1$, inclusive,
in the segment of \\{byte\←mem} whose first index is $\|p\mathbin{\&{mod}}%
\\{ww}$. Thus, when
$\\{ww}=2$ the even-numbered name bytes appear in $\\{byte\←mem}[0,\hbox{$*$}]$
and the odd-numbered ones appear in $\\{byte\←mem}[1,\hbox{$*$}]$.
The pointer 0 is used for undefined module names; we don't
want to use it for the names of identifiers, since 0 stands for a null
pointer in a linked list.

We usually have $\\{byte\←start}[\\{name\←ptr}+\|w]=\\{byte\←ptr}[(\\{name%
\←ptr}+\|w)\mathbin{\&{mod}}\\{ww}]$
for $0\L\|w<\\{ww}$, since these are the starting positions for the next \\{ww}
names to be stored in \\{byte\←mem}.

\Y\P\D \37$\\{length}(\#)\S\\{byte\←start}[\#+\\{ww}]-\\{byte\←start}[\#]$%
\C{the length of a name}\par
\Y\P$\4\X11:Types in the outer block\X\mathrel{+}\S$\6
$\\{name\←pointer}=0\to\\{max\←names}$;\C{identifies a name}\par
\fi

\M39. \P$\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{name\←ptr}: \37\\{name\←pointer};\C{first unused position in \\{byte%
\←start}}\6
\4\\{byte\←ptr}: \37\&{array} $[0\to\\{ww}-1]$ \1\&{of}\5
$0\to\\{max\←bytes}$;\C{first unused position in \\{byte\←mem}}\2\par
\fi

\M40. \P$\X16:Local variables for initialization\X\mathrel{+}\S$\6
\4\\{wi}: \37$0\to\\{ww}-1$;\C{to initialize the \\{byte\←mem} indices}\par
\fi

\M41. \P$\X10:Set initial values\X\mathrel{+}\S$\6
\&{for} $\\{wi}\K0\mathrel{\&{to}}\\{ww}-1$ \1\&{do}\6
\&{begin} \37$\\{byte\←start}[\\{wi}]\K0$;\5
$\\{byte\←ptr}[\\{wi}]\K0$;\6
\&{end};\2\6
$\\{byte\←start}[\\{ww}]\K0$;\C{this makes name 0 of length zero}\6
$\\{name\←ptr}\K1$;\par
\fi

\M42. Several types of identifiers are distinguished by their \\{ilk}:

\yskip\hang \\{normal} identifiers are part of the \PASCAL\ program and
will appear in italic type.

\yskip\hang \\{roman} identifiers are index entries that appear after
\.{@\↑} in the \.{WEB} file.

\yskip\hang \\{wildcard} identifiers are index entries that appear after
\.{@:} in the \.{WEB} file.

\yskip\hang \\{typewriter} identifiers are index entries that appear after
\.{@.} in the \.{WEB} file.

\yskip\hang \\{array\←like}, \\{begin\←like}, \dots, \\{var\←like}
identifiers are \PASCAL\ reserved words whose \\{ilk} explains how they are
to be treated when \PASCAL\ code is being formatted.

\yskip\hang Finally, if \|c is an ASCII code, an \\{ilk} equal to
$\\{char\←like}+\|c$ denotes a reserved word that will be converted to
character
\|c.

\Y\P\D \37$\\{normal}=0$\C{ordinary identifiers have \\{normal} ilk}\par
\P\D \37$\\{roman}=1$\C{normal index entries have \\{roman} ilk}\par
\P\D \37$\\{wildcard}=2$\C{user-formatted index entries have \\{wildcard} ilk}%
\par
\P\D \37$\\{typewriter}=3$\C{`typewriter type' entries have \\{typewriter} ilk}%
\par
\P\D \37$\\{reserved}(\#)\S(\\{ilk}[\#]>\\{typewriter})$\C{tells if a name is a
reserved word}\par
\P\D \37$\\{array\←like}=4$\C{\&{array}, \&{file}, \&{set}}\par
\P\D \37$\\{begin\←like}=5$\C{\&{begin}}\par
\P\D \37$\\{case\←like}=6$\C{\&{case}}\par
\P\D \37$\\{const\←like}=7$\C{\&{const}, \&{label}, \&{type}}\par
\P\D \37$\\{div\←like}=8$\C{\&{div}, \&{mod}}\par
\P\D \37$\\{do\←like}=9$\C{\&{do}, \&{of}, \&{then}}\par
\P\D \37$\\{else\←like}=10$\C{\&{else}}\par
\P\D \37$\\{end\←like}=11$\C{\&{end}}\par
\P\D \37$\\{for\←like}=12$\C{\&{for}, \&{while}, \&{with}}\par
\P\D \37$\\{goto\←like}=13$\C{\&{goto}, \&{packed}}\par
\P\D \37$\\{if\←like}=14$\C{\&{if}}\par
\P\D \37$\\{in\←like}=15$\C{\&{in}}\par
\P\D \37$\\{nil\←like}=16$\C{\&{nil}}\par
\P\D \37$\\{proc\←like}=17$\C{\&{function}, \&{procedure}, \&{program}}\par
\P\D \37$\\{record\←like}=18$\C{\&{record}}\par
\P\D \37$\\{repeat\←like}=19$\C{\&{repeat}}\par
\P\D \37$\\{to\←like}=20$\C{\&{downto}, \&{to}}\par
\P\D \37$\\{until\←like}=21$\C{\&{until}}\par
\P\D \37$\\{var\←like}=22$\C{\&{var}}\par
\P\D \37$\\{loop\←like}=23$\C{\&{loop}, \&{xclause}}\par
\P\D \37$\\{char\←like}=24$\C{\&{and}, \&{or}, \&{not}, \&{in}}\par
\fi

\M43. The names of modules are stored in \\{byte\←mem} together
with the identifier names, but a hash table is not used for them because
\.{WEAVE} needs to be able to recognize a module name when given a prefix of
that name. A conventional binary seach tree is used to retrieve module names,
with fields called \\{llink} and \\{rlink} in place of \\{link} and \\{ilk}.
The
root of this tree is $\\{rlink}[0]$.

\Y\P\D \37$\\{llink}\S\\{link}$\C{left link in binary search tree for module
names}\par
\P\D \37$\\{rlink}\S\\{ilk}$\C{right link in binary search tree for module
names}\par
\P\D \37$\\{root}\S\\{rlink}[0]$\C{the root of the binary search tree for
module names}\par
\Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
$\\{root}\K0$;\C{the binary search tree starts out with nothing in it}\par
\fi

\M44. Here is a little procedure that prints the text of a given name on the
user's terminal.

\Y\P\4\&{procedure}\1\  \37$\\{print\←id}(\|p:\\{name\←pointer})$;\C{print
identifier or module name}\6
\4\&{var} \37\|k: \37$0\to\\{max\←bytes}$;\C{index into \\{byte\←mem}}\6
\|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\←mem}}\2\6
\&{begin} \37\&{if} $\|p\G\\{name\←ptr}$ \1\&{then}\5
$\\{print}(\.{\'IMPOSSIBLE\'})$\6
\4\&{else} \&{begin} \37$\|w\K\|p\mathbin{\&{mod}}\\{ww}$;\6
\&{for} $\|k\K\\{byte\←start}[\|p]\mathrel{\&{to}}\\{byte\←start}[\|p+%
\\{ww}]-1$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{byte\←mem}[\|w,\39\|k]])$;\2\6
\&{end};\2\6
\&{end};\par
\fi

\M45. We keep track of the current module number in
\\{module\←count}, which is the total number of modules that have started.
Modules which have been altered by a change file entry
have their \\{changed\←module} flag turned on during the first phase.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{module\←count}: \37$0\to\\{max\←modules}$;\C{the current module number}\6
\4\\{changed\←module}: \37\&{packed} \37\&{array} $[0\to\\{max\←modules}]$ \1%
\&{of}\5
\\{boolean};\C{is it changed?}\2\6
\4\\{change\←exists}: \37\\{boolean};\C{has any module changed?}\par
\fi

\M46. The other large memory area in \.{WEAVE} keeps the cross-reference data.
All uses of the name \|p are recorded in a linked list beginning at
$\\{xref}[\|p]$, which points into the \\{xmem} array. Entries in \\{xmem}
consist
of two sixteen-bit items per word, called the \\{num} and \\{xlink} fields.
If \|x is an index into \\{xmem}, reached from name \|p, the value of $\\{num}(%
\|x)$
is either a module number where \|p is used, or it is \\{def\←flag} plus a
module number where \|p is defined; and $\\{xlink}(\|x)$ points to the next
such
cross reference for \|p, if any. This list of cross references is in
decreasing order by module number. The current number of cross references
is \\{xref\←ptr}.

The global variable \\{xref\←switch} is set either to \\{def\←flag} or to zero,
depending on whether the next cross reference to an identifier is to be
underlined or not in the index. This switch is set to \\{def\←flag} when
\.{@!} or \.{@d} or \.{@f} is scanned, and it is cleared to zero when
the next identifier or index entry cross reference has been made. Similarly,
the global variable \\{mod\←xref\←switch} is either \\{def\←flag} or zero,
depending
on whether a module name is being defined or used.

\Y\P\D \37$\\{num}(\#)\S\\{xmem}[\#].\\{num\←field}$\par
\P\D \37$\\{xlink}(\#)\S\\{xmem}[\#].\\{xlink\←field}$\par
\P\D \37$\\{def\←flag}=10240$\C{must be strictly larger than \\{max\←modules}}%
\par
\fi

\M47. \P$\X11:Types in the outer block\X\mathrel{+}\S$\6
$\\{xref\←number}=0\to\\{max\←refs}$;\par
\fi

\M48\*. \P$\X11:Types in the outer block\X\mathrel{+}\S$\6
$\\{xmem\←record}=$\1\5
\&{packed} \37\1\&{record} \37\hbox{}\6
\4\\{num\←field}: \37\\{sixteen\←bits};\C{module number plus zero or \\{def%
\←flag}}\6
\4\\{xlink\←field}: \37\\{sixteen\←bits};\C{pointer to the previous cross
reference}\2\6
\&{end};\2\par
\fi

\M49\*. \P$\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{xmem}: \37\&{array} $[\\{xref\←number}]$ \1\&{of}\5
\\{xmem\←record};\2\6
\4\\{xref\←ptr}: \37\\{xref\←number};\C{the largest occupied position in %
\\{xmem}}\6
\4$\\{xref\←switch},\39\\{mod\←xref\←switch}$: \37$0\to\\{def\←flag}$;\C{either
zero or \\{def\←flag}}\par
\fi

\M50. \P$\X10:Set initial values\X\mathrel{+}\S$\6
$\\{xref\←ptr}\K0$;\5
$\\{xref\←switch}\K0$;\5
$\\{mod\←xref\←switch}\K0$;\5
$\\{num}(0)\K0$;\5
$\\{xref}[0]\K0$;\C{cross references to undefined modules}\par
\fi

\M51. A new cross reference for an identifier is formed by calling \\{new%
\←xref},
which discards duplicate entries and ignores non-underlined references
to one-letter identifiers or \PASCAL's reserved words.

\Y\P\D \37$\\{append\←xref}(\#)\S$\1\6
\&{if} $\\{xref\←ptr}=\\{max\←refs}$ \1\&{then}\5
$\\{overflow}(\.{\'cross\ reference\'})$\6
\4\&{else} \&{begin} \37$\\{incr}(\\{xref\←ptr})$;\5
$\\{num}(\\{xref\←ptr})\K\#$;\6
\&{end}\2\2\par
\Y\P\4\&{procedure}\1\  \37$\\{new\←xref}(\|p:\\{name\←pointer})$;\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|q: \37\\{xref\←number};\C{pointer to previous cross reference}\6
$\|m,\39\|n$: \37\\{sixteen\←bits};\C{new and previous cross-reference value}\2%
\6
\&{begin} \37\&{if} $(\\{reserved}(\|p)\V(\\{byte\←start}[\|p]+1=\\{byte%
\←start}[\|p+\\{ww}]))\W(\\{xref\←switch}=0)$ \1\&{then}\5
\&{return};\2\6
$\|m\K\\{module\←count}+\\{xref\←switch}$;\5
$\\{xref\←switch}\K0$;\5
$\|q\K\\{xref}[\|p]$;\6
\&{if} $\|q>0$ \1\&{then}\6
\&{begin} \37$\|n\K\\{num}(\|q)$;\6
\&{if} $(\|n=\|m)\V(\|n=\|m+\\{def\←flag})$ \1\&{then}\5
\&{return}\6
\4\&{else} \&{if} $\|m=\|n+\\{def\←flag}$ \1\&{then}\6
\&{begin} \37$\\{num}(\|q)\K\|m$;\5
\&{return};\6
\&{end};\2\2\6
\&{end};\2\6
$\\{append\←xref}(\|m)$;\5
$\\{xlink}(\\{xref\←ptr})\K\|q$;\5
$\\{xref}[\|p]\K\\{xref\←ptr}$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M52. The cross reference lists for module names are slightly different.
Suppose
that a module name is defined in modules $m←1$, \dots, $m←k$ and used in
modules $n←1$, \dots, $n←l$. Then its list will contain $m←1+\\{def\←flag}$,
$m←k+\\{def\←flag}$, \dots, $m←2+\\{def\←flag}$, $n←l$, \dots, $n←1$, in
this order.  After Phase II, however, the order will be
$m←1+\\{def\←flag}$, \dots, $m←k+\\{def\←flag}$, $n←1$, \dots, $n←l$.

\Y\P\4\&{procedure}\1\  \37$\\{new\←mod\←xref}(\|p:\\{name\←pointer})$;\6
\4\&{var} \37$\|q,\39\|r$: \37\\{xref\←number};\C{pointers to previous cross
references}\2\6
\&{begin} \37$\|q\K\\{xref}[\|p]$;\5
$\|r\K0$;\6
\&{if} $\|q>0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{mod\←xref\←switch}=0$ \1\&{then}\6
\&{while} $\\{num}(\|q)\G\\{def\←flag}$ \1\&{do}\6
\&{begin} \37$\|r\K\|q$;\5
$\|q\K\\{xlink}(\|q)$;\6
\&{end}\2\6
\4\&{else} \&{if} $\\{num}(\|q)\G\\{def\←flag}$ \1\&{then}\6
\&{begin} \37$\|r\K\|q$;\5
$\|q\K\\{xlink}(\|q)$;\6
\&{end};\2\2\6
\&{end};\2\6
$\\{append\←xref}(\\{module\←count}+\\{mod\←xref\←switch})$;\5
$\\{xlink}(\\{xref\←ptr})\K\|q$;\5
$\\{mod\←xref\←switch}\K0$;\6
\&{if} $\|r=0$ \1\&{then}\5
$\\{xref}[\|p]\K\\{xref\←ptr}$\6
\4\&{else} $\\{xlink}(\|r)\K\\{xref\←ptr}$;\2\6
\&{end};\par
\fi

\M53. A third large area of memory is used for sixteen-bit `tokens', which
appear
in short lists similar to the strings of characters in \\{byte\←mem}. Token
lists
are used to contain the result of \PASCAL\ code translated into \TeX\ form;
further details about them will be explained later. A \\{text\←pointer}
variable
is an index into \\{tok\←start}.

\Y\P$\4\X11:Types in the outer block\X\mathrel{+}\S$\6
$\\{text\←pointer}=0\to\\{max\←texts}$;\C{identifies a token list}\par
\fi

\M54. The first position of \\{tok\←mem}
that is unoccupied by replacement text is called \\{tok\←ptr}, and the first
unused location of \\{tok\←start} is called \\{text\←ptr}.
Thus, we usually have $\\{tok\←start}[\\{text\←ptr}]=\\{tok\←ptr}$.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\hbox{\hskip1em}\\{tok\←mem}: \37\&{packed} \37\&{array} $[0\to\\{max%
\←toks}]$ \1\&{of}\5
\\{sixteen\←bits};\C{tokens}\2\6
\4\hbox{\hskip1em}\\{tok\←start}: \37\&{array} $[\\{text\←pointer}]$ \1\&{of}\5
\\{sixteen\←bits};\C{directory into \\{tok\←mem}}\2\6
\4\hbox{\hskip1em}\\{text\←ptr}: \37\\{text\←pointer};\C{first unused position
in \\{tok\←start}}\6
\4\hbox{\hskip1em}\\{tok\←ptr}: \37$0\to\\{max\←toks}$;\C{first unused position
in \\{tok\←mem}}\6
\&{stat} \37$\\{max\←tok\←ptr},\39\\{max\←txt\←ptr}$: \37$0\to\\{max\←toks}$;%
\C{largest values occurring}\6
\&{tats}\par
\fi

\M55. \P$\X10:Set initial values\X\mathrel{+}\S$\6
$\\{tok\←ptr}\K1$;\5
$\\{text\←ptr}\K1$;\5
$\\{tok\←start}[0]\K1$;\5
$\\{tok\←start}[1]\K1$;\6
\&{stat} \37$\\{max\←tok\←ptr}\K1$;\5
$\\{max\←txt\←ptr}\K1$;\ \&{tats}\par
\fi

\N56.  Searching for identifiers.
The hash table described above is updated by the \\{id\←lookup} procedure,
which finds a given identifier and returns a pointer to its index in
\\{byte\←start}. The identifier is supposed to match character by character
and it is also supposed to have a given \\{ilk} code; the same name may be
present more than once if it is supposed to appear in the index with
different typesetting conventions.
If the identifier was not already present, it is inserted into the table.

Because of the way \.{WEAVE}'s scanning mechanism works, it is most convenient
to let \\{id\←lookup} search for an identifier that is present in the %
\\{buffer}
array. Two other global variables specify its position in the buffer: the
first character is $\\{buffer}[\\{id\←first}]$, and the last is $\\{buffer}[%
\\{id\←loc}-1]$.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{id\←first}: \37$0\to\\{long\←buf\←size}$;\C{where the current identifier
begins in the buffer}\6
\4\\{id\←loc}: \37$0\to\\{long\←buf\←size}$;\C{just after the current
identifier in the buffer}\7
\4\\{hash}: \37\&{array} $[0\to\\{hash\←size}]$ \1\&{of}\5
\\{sixteen\←bits};\C{heads of hash lists}\2\par
\fi

\M57. Initially all the hash lists are empty.

\Y\P$\4\X16:Local variables for initialization\X\mathrel{+}\S$\6
\4\|h: \37$0\to\\{hash\←size}$;\C{index into hash-head array}\par
\fi

\M58. \P$\X10:Set initial values\X\mathrel{+}\S$\6
\&{for} $\|h\K0\mathrel{\&{to}}\\{hash\←size}-1$ \1\&{do}\5
$\\{hash}[\|h]\K0$;\2\par
\fi

\M59. Here now is the main procedure for finding identifiers (and index
entries).  The parameter \|t is set to the desired \\{ilk} code. The
identifier must either have $\\{ilk}=\|t$, or we must have
$\|t=\\{normal}$ and the identifier must be a reserved word.

\Y\P\4\&{function}\1\  \37$\\{id\←lookup}(\|t:\\{eight\←bits})$: \37\\{name%
\←pointer};\C{finds current identifier}\6
\4\&{label} \37\\{found};\6
\4\&{var} \37\|i: \37$0\to\\{long\←buf\←size}$;\C{index into \\{buffer}}\6
\|h: \37$0\to\\{hash\←size}$;\C{hash code}\6
\|k: \37$0\to\\{max\←bytes}$;\C{index into \\{byte\←mem}}\6
\|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\←mem}}\6
\|l: \37$0\to\\{long\←buf\←size}$;\C{length of the given identifier}\6
\|p: \37\\{name\←pointer};\C{where the identifier is being sought}\2\6
\&{begin} \37$\|l\K\\{id\←loc}-\\{id\←first}$;\C{compute the length}\6
\X60:Compute the hash code \|h\X;\6
\X61:Compute the name location \|p\X;\6
\&{if} $\|p=\\{name\←ptr}$ \1\&{then}\5
\X63:Enter a new name into the table at position \|p\X;\2\6
$\\{id\←lookup}\K\|p$;\6
\&{end};\par
\fi

\M60. A simple hash code is used: If the sequence of
ASCII codes is $c←1c←2\ldots c←m$, its hash value will be
$$(2↑{n-1}c←1+2↑{n-2}c←2+\cdots+c←n)\,\bmod\,\\{hash\←size}.$$

\Y\P$\4\X60:Compute the hash code \|h\X\S$\6
$\|h\K\\{buffer}[\\{id\←first}]$;\5
$\|i\K\\{id\←first}+1$;\6
\&{while} $\|i<\\{id\←loc}$ \1\&{do}\6
\&{begin} \37$\|h\K(\|h+\|h+\\{buffer}[\|i])\mathbin{\&{mod}}\\{hash\←size}$;\5
$\\{incr}(\|i)$;\6
\&{end}\2\par
\U section~59.\fi

\M61. If the identifier is new, it will be placed in position $\|p=\\{name%
\←ptr}$,
otherwise \|p will point to its existing location.

\Y\P$\4\X61:Compute the name location \|p\X\S$\6
$\|p\K\\{hash}[\|h]$;\6
\&{while} $\|p\I0$ \1\&{do}\6
\&{begin} \37\&{if} $(\\{length}(\|p)=\|l)\W((\\{ilk}[\|p]=\|t)\V((\|t=%
\\{normal})\W\\{reserved}(\|p)))$ \1\&{then}\5
\X62:Compare name \|p with current identifier, \&{goto} \\{found} if equal\X;\2%
\6
$\|p\K\\{link}[\|p]$;\6
\&{end};\2\6
$\|p\K\\{name\←ptr}$;\C{the current identifier is new}\6
$\\{link}[\|p]\K\\{hash}[\|h]$;\5
$\\{hash}[\|h]\K\|p$;\C{insert \|p at beginning of hash list}\6
\4\\{found}: \37\par
\U section~59.\fi

\M62. \P$\X62:Compare name \|p with current identifier, \&{goto} \\{found} if
equal\X\S$\6
\&{begin} \37$\|i\K\\{id\←first}$;\5
$\|k\K\\{byte\←start}[\|p]$;\5
$\|w\K\|p\mathbin{\&{mod}}\\{ww}$;\6
\&{while} $(\|i<\\{id\←loc})\W(\\{buffer}[\|i]=\\{byte\←mem}[\|w,\39\|k])$ \1%
\&{do}\6
\&{begin} \37$\\{incr}(\|i)$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
\&{if} $\|i=\\{id\←loc}$ \1\&{then}\5
\&{goto} \37\\{found};\C{all characters agree}\2\6
\&{end}\par
\U section~61.\fi

\M63. When we begin the following segment of the program, $\|p=\\{name\←ptr}$.

\Y\P$\4\X63:Enter a new name into the table at position \|p\X\S$\6
\&{begin} \37$\|w\K\\{name\←ptr}\mathbin{\&{mod}}\\{ww}$;\6
\&{if} $\\{byte\←ptr}[\|w]+\|l>\\{max\←bytes}$ \1\&{then}\5
$\\{overflow}(\.{\'byte\ memory\'})$;\2\6
\&{if} $\\{name\←ptr}+\\{ww}>\\{max\←names}$ \1\&{then}\5
$\\{overflow}(\.{\'name\'})$;\2\6
$\|i\K\\{id\←first}$;\5
$\|k\K\\{byte\←ptr}[\|w]$;\C{get ready to move the identifier into \\{byte%
\←mem}}\6
\&{while} $\|i<\\{id\←loc}$ \1\&{do}\6
\&{begin} \37$\\{byte\←mem}[\|w,\39\|k]\K\\{buffer}[\|i]$;\5
$\\{incr}(\|k)$;\5
$\\{incr}(\|i)$;\6
\&{end};\2\6
$\\{byte\←ptr}[\|w]\K\|k$;\5
$\\{byte\←start}[\\{name\←ptr}+\\{ww}]\K\|k$;\5
$\\{incr}(\\{name\←ptr})$;\5
$\\{ilk}[\|p]\K\|t$;\5
$\\{xref}[\|p]\K0$;\6
\&{end}\par
\U section~59.\fi

\N64.  Initializing the table of reserved words.
We have to get \PASCAL's reserved words into the hash table, and the
simplest way to do this is to insert them every time \.{WEAVE} is run.
A few macros permit us to do the initialization with a compact program.

\Y\P\D \37$\\{sid9}(\#)\S\\{buffer}[9]\K\#$;\5
$\\{cur\←name}\K\\{id\←lookup}$\par
\P\D \37$\\{sid8}(\#)\S\\{buffer}[8]\K\#$;\5
\\{sid9}\par
\P\D \37$\\{sid7}(\#)\S\\{buffer}[7]\K\#$;\5
\\{sid8}\par
\P\D \37$\\{sid6}(\#)\S\\{buffer}[6]\K\#$;\5
\\{sid7}\par
\P\D \37$\\{sid5}(\#)\S\\{buffer}[5]\K\#$;\5
\\{sid6}\par
\P\D \37$\\{sid4}(\#)\S\\{buffer}[4]\K\#$;\5
\\{sid5}\par
\P\D \37$\\{sid3}(\#)\S\\{buffer}[3]\K\#$;\5
\\{sid4}\par
\P\D \37$\\{sid2}(\#)\S\\{buffer}[2]\K\#$;\5
\\{sid3}\par
\P\D \37$\\{sid1}(\#)\S\\{buffer}[1]\K\#$;\5
\\{sid2}\par
\P\D \37$\\{id2}\S\\{id\←first}\K8$;\5
\\{sid8}\par
\P\D \37$\\{id3}\S\\{id\←first}\K7$;\5
\\{sid7}\par
\P\D \37$\\{id4}\S\\{id\←first}\K6$;\5
\\{sid6}\par
\P\D \37$\\{id5}\S\\{id\←first}\K5$;\5
\\{sid5}\par
\P\D \37$\\{id6}\S\\{id\←first}\K4$;\5
\\{sid4}\par
\P\D \37$\\{id7}\S\\{id\←first}\K3$;\5
\\{sid3}\par
\P\D \37$\\{id8}\S\\{id\←first}\K2$;\5
\\{sid2}\par
\P\D \37$\\{id9}\S\\{id\←first}\K1$;\5
\\{sid1}\par
\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cur\←name}: \37\\{name\←pointer};\C{points to the identifier just
inserted}\par
\fi

\M65. The intended use of the macros above might not be immediately obvious,
but the riddle is answered by the following:

\Y\P$\4\X65:Store all the reserved words\X\S$\6
$\\{id\←loc}\K10$;\6
$\\{id3}(\.{"a"})(\.{"n"})(\.{"d"})(\\{char\←like}+\\{and\←sign})$;\6
$\\{id5}(\.{"a"})(\.{"r"})(\.{"r"})(\.{"a"})(\.{"y"})(\\{array\←like})$;\6
$\\{id5}(\.{"b"})(\.{"e"})(\.{"g"})(\.{"i"})(\.{"n"})(\\{begin\←like})$;\6
$\\{id4}(\.{"c"})(\.{"a"})(\.{"s"})(\.{"e"})(\\{case\←like})$;\6
$\\{id5}(\.{"c"})(\.{"o"})(\.{"n"})(\.{"s"})(\.{"t"})(\\{const\←like})$;\6
$\\{id3}(\.{"d"})(\.{"i"})(\.{"v"})(\\{div\←like})$;\6
$\\{id2}(\.{"d"})(\.{"o"})(\\{do\←like})$;\6
$\\{id6}(\.{"d"})(\.{"o"})(\.{"w"})(\.{"n"})(\.{"t"})(\.{"o"})(\\{to\←like})$;\6
$\\{id4}(\.{"e"})(\.{"l"})(\.{"s"})(\.{"e"})(\\{else\←like})$;\6
$\\{id3}(\.{"e"})(\.{"n"})(\.{"d"})(\\{end\←like})$;\6
$\\{id4}(\.{"f"})(\.{"i"})(\.{"l"})(\.{"e"})(\\{array\←like})$;\6
$\\{id3}(\.{"f"})(\.{"o"})(\.{"r"})(\\{for\←like})$;\6
$\\{id8}(\.{"f"})(\.{"u"})(\.{"n"})(\.{"c"})(\.{"t"})(\.{"i"})(\.{"o"})(%
\.{"n"})(\\{proc\←like})$;\6
$\\{id4}(\.{"g"})(\.{"o"})(\.{"t"})(\.{"o"})(\\{goto\←like})$;\6
$\\{id2}(\.{"i"})(\.{"f"})(\\{if\←like})$;\6
$\\{id2}(\.{"i"})(\.{"n"})(\\{char\←like}+\\{set\←element\←sign})$;\6
$\\{id5}(\.{"l"})(\.{"a"})(\.{"b"})(\.{"e"})(\.{"l"})(\\{const\←like})$;\6
$\\{id3}(\.{"m"})(\.{"o"})(\.{"d"})(\\{div\←like})$;\6
$\\{id3}(\.{"n"})(\.{"i"})(\.{"l"})(\\{nil\←like})$;\6
$\\{id3}(\.{"n"})(\.{"o"})(\.{"t"})(\\{char\←like}+\\{not\←sign})$;\6
$\\{id2}(\.{"o"})(\.{"f"})(\\{do\←like})$;\6
$\\{id2}(\.{"o"})(\.{"r"})(\\{char\←like}+\\{or\←sign})$;\6
$\\{id6}(\.{"p"})(\.{"a"})(\.{"c"})(\.{"k"})(\.{"e"})(\.{"d"})(\\{goto%
\←like})$;\6
$\\{id9}(\.{"p"})(\.{"r"})(\.{"o"})(\.{"c"})(\.{"e"})(\.{"d"})(\.{"u"})(%
\.{"r"})(\.{"e"})(\\{proc\←like})$;\6
$\\{id7}(\.{"p"})(\.{"r"})(\.{"o"})(\.{"g"})(\.{"r"})(\.{"a"})(\.{"m"})(\\{proc%
\←like})$;\6
$\\{id6}(\.{"r"})(\.{"e"})(\.{"c"})(\.{"o"})(\.{"r"})(\.{"d"})(\\{record%
\←like})$;\6
$\\{id6}(\.{"r"})(\.{"e"})(\.{"p"})(\.{"e"})(\.{"a"})(\.{"t"})(\\{repeat%
\←like})$;\6
$\\{id3}(\.{"s"})(\.{"e"})(\.{"t"})(\\{array\←like})$;\6
$\\{id4}(\.{"t"})(\.{"h"})(\.{"e"})(\.{"n"})(\\{do\←like})$;\6
$\\{id2}(\.{"t"})(\.{"o"})(\\{to\←like})$;\6
$\\{id4}(\.{"t"})(\.{"y"})(\.{"p"})(\.{"e"})(\\{const\←like})$;\6
$\\{id5}(\.{"u"})(\.{"n"})(\.{"t"})(\.{"i"})(\.{"l"})(\\{until\←like})$;\6
$\\{id3}(\.{"v"})(\.{"a"})(\.{"r"})(\\{var\←like})$;\6
$\\{id5}(\.{"w"})(\.{"h"})(\.{"i"})(\.{"l"})(\.{"e"})(\\{for\←like})$;\6
$\\{id4}(\.{"w"})(\.{"i"})(\.{"t"})(\.{"h"})(\\{for\←like})$;\6
$\\{id7}(\.{"x"})(\.{"c"})(\.{"l"})(\.{"a"})(\.{"u"})(\.{"s"})(\.{"e"})(\\{loop%
\←like})$;\par
\U section~262\*.\fi

\N66.  Searching for module names.
The \\{mod\←lookup} procedure finds the module name $\\{mod\←text}[1\to\|l]$ in
the
search tree, after inserting it if necessary, and returns a pointer to
where it was found.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{mod\←text}: \37\&{array} $[0\to\\{longest\←name}]$ \1\&{of}\5
\\{ASCII\←code};\C{name being sought for}\2\par
\fi

\M67. According to the rules of \.{WEB}, no module name
should be a proper prefix of another, so a ``clean'' comparison should
occur between any two names. The result of \\{mod\←lookup} is 0 if this
prefix condition is violated. An error message is printed when such violations
are detected during phase two of \.{WEAVE}.

\Y\P\D \37$\\{less}=0$\C{the first name is lexicographically less than the
second}\par
\P\D \37$\\{equal}=1$\C{the first name is equal to the second}\par
\P\D \37$\\{greater}=2$\C{the first name is lexicographically greater than the
second}\par
\P\D \37$\\{prefix}=3$\C{the first name is a proper prefix of the second}\par
\P\D \37$\\{extension}=4$\C{the first name is a proper extension of the second}%
\par
\Y\P\4\&{function}\1\  \37$\\{mod\←lookup}(\|l:\\{sixteen\←bits})$: \37\\{name%
\←pointer};\C{finds module name}\6
\4\&{label} \37\\{found};\6
\4\&{var} \37\|c: \37$\\{less}\to\\{extension}$;\C{comparison between two
names}\6
\|j: \37$0\to\\{longest\←name}$;\C{index into \\{mod\←text}}\6
\|k: \37$0\to\\{max\←bytes}$;\C{index into \\{byte\←mem}}\6
\|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\←mem}}\6
\|p: \37\\{name\←pointer};\C{current node of the search tree}\6
\|q: \37\\{name\←pointer};\C{father of node \|p}\2\6
\&{begin} \37$\|c\K\\{greater}$;\5
$\|q\K0$;\5
$\|p\K\\{root}$;\6
\&{while} $\|p\I0$ \1\&{do}\6
\&{begin} \37\X69:Set \|c to the result of comparing the given name to name \|p%
\X;\6
$\|q\K\|p$;\6
\&{if} $\|c=\\{less}$ \1\&{then}\5
$\|p\K\\{llink}[\|q]$\6
\4\&{else} \&{if} $\|c=\\{greater}$ \1\&{then}\5
$\|p\K\\{rlink}[\|q]$\6
\4\&{else} \&{goto} \37\\{found};\2\2\6
\&{end};\2\6
\X68:Enter a new module name into the tree\X;\6
\4\\{found}: \37\&{if} $\|c\I\\{equal}$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ Incompatible\ section\ names\'})$;\5
$\|p\K0$;\6
\&{end};\2\6
$\\{mod\←lookup}\K\|p$;\6
\&{end};\par
\fi

\M68. \P$\X68:Enter a new module name into the tree\X\S$\6
$\|w\K\\{name\←ptr}\mathbin{\&{mod}}\\{ww}$;\5
$\|k\K\\{byte\←ptr}[\|w]$;\6
\&{if} $\|k+\|l>\\{max\←bytes}$ \1\&{then}\5
$\\{overflow}(\.{\'byte\ memory\'})$;\2\6
\&{if} $\\{name\←ptr}>\\{max\←names}-\\{ww}$ \1\&{then}\5
$\\{overflow}(\.{\'name\'})$;\2\6
$\|p\K\\{name\←ptr}$;\6
\&{if} $\|c=\\{less}$ \1\&{then}\5
$\\{llink}[\|q]\K\|p$\6
\4\&{else} $\\{rlink}[\|q]\K\|p$;\2\6
$\\{llink}[\|p]\K0$;\5
$\\{rlink}[\|p]\K0$;\5
$\\{xref}[\|p]\K0$;\5
$\|c\K\\{equal}$;\6
\&{for} $\|j\K1\mathrel{\&{to}}\|l$ \1\&{do}\5
$\\{byte\←mem}[\|w,\39\|k+\|j-1]\K\\{mod\←text}[\|j]$;\2\6
$\\{byte\←ptr}[\|w]\K\|k+\|l$;\5
$\\{byte\←start}[\\{name\←ptr}+\\{ww}]\K\|k+\|l$;\5
$\\{incr}(\\{name\←ptr})$;\par
\U section~67.\fi

\M69. \P$\X69:Set \|c to the result of comparing the given name to name \|p\X%
\S$\6
\&{begin} \37$\|k\K\\{byte\←start}[\|p]$;\5
$\|w\K\|p\mathbin{\&{mod}}\\{ww}$;\5
$\|c\K\\{equal}$;\5
$\|j\K1$;\6
\&{while} $(\|k<\\{byte\←start}[\|p+\\{ww}])\W(\|j\L\|l)\W(\\{mod\←text}[\|j]=%
\\{byte\←mem}[\|w,\39\|k])$ \1\&{do}\6
\&{begin} \37$\\{incr}(\|k)$;\5
$\\{incr}(\|j)$;\6
\&{end};\2\6
\&{if} $\|k=\\{byte\←start}[\|p+\\{ww}]$ \1\&{then}\6
\&{if} $\|j>\|l$ \1\&{then}\5
$\|c\K\\{equal}$\6
\4\&{else} $\|c\K\\{extension}$\2\6
\4\&{else} \&{if} $\|j>\|l$ \1\&{then}\5
$\|c\K\\{prefix}$\6
\4\&{else} \&{if} $\\{mod\←text}[\|j]<\\{byte\←mem}[\|w,\39\|k]$ \1\&{then}\5
$\|c\K\\{less}$\6
\4\&{else} $\|c\K\\{greater}$;\2\2\2\6
\&{end}\par
\U sections~67 and~70.\fi

\M70. The \\{prefix\←lookup} procedure is supposed to find exactly one module
name that has $\\{mod\←text}[1\to\|l]$ as a prefix. Actually the algorithm
silently accepts also the situation that some module name is a prefix of
$\\{mod\←text}[1\to\|l]$, because the user who painstakingly typed in more than
necessary probably doesn't want to be told about the wasted effort.

Recall that error messages are not printed during phase one. It is
possible that the \\{prefix\←lookup} procedure will fail on the first pass,
because there is no match, yet the second pass might detect no error if a
matching module name has occurred after the offending prefix. In such a
case the cross-reference information will be incorrect and \.{WEAVE} will
report no error. However, such a mistake will be detected by the
\.{TANGLE} processor.

\Y\P\4\&{function}\1\  \37$\\{prefix\←lookup}(\|l:\\{sixteen\←bits})$: \37%
\\{name\←pointer};\C{finds name extension}\6
\4\&{var} \37\|c: \37$\\{less}\to\\{extension}$;\C{comparison between two
names}\6
\\{count}: \37$0\to\\{max\←names}$;\C{the number of hits}\6
\|j: \37$0\to\\{longest\←name}$;\C{index into \\{mod\←text}}\6
\|k: \37$0\to\\{max\←bytes}$;\C{index into \\{byte\←mem}}\6
\|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\←mem}}\6
\|p: \37\\{name\←pointer};\C{current node of the search tree}\6
\|q: \37\\{name\←pointer};\C{another place to resume the search after one
branch is done}\6
\|r: \37\\{name\←pointer};\C{extension found}\2\6
\&{begin} \37$\|q\K0$;\5
$\|p\K\\{root}$;\5
$\\{count}\K0$;\5
$\|r\K0$;\C{begin search at root of tree}\6
\&{while} $\|p\I0$ \1\&{do}\6
\&{begin} \37\X69:Set \|c to the result of comparing the given name to name \|p%
\X;\6
\&{if} $\|c=\\{less}$ \1\&{then}\5
$\|p\K\\{llink}[\|p]$\6
\4\&{else} \&{if} $\|c=\\{greater}$ \1\&{then}\5
$\|p\K\\{rlink}[\|p]$\6
\4\&{else} \&{begin} \37$\|r\K\|p$;\5
$\\{incr}(\\{count})$;\5
$\|q\K\\{rlink}[\|p]$;\5
$\|p\K\\{llink}[\|p]$;\6
\&{end};\2\2\6
\&{if} $\|p=0$ \1\&{then}\6
\&{begin} \37$\|p\K\|q$;\5
$\|q\K0$;\6
\&{end};\2\6
\&{end};\2\6
\&{if} $\\{count}\I1$ \1\&{then}\6
\&{if} $\\{count}=0$ \1\&{then}\5
$\\{err\←print}(\.{\'!\ Name\ does\ not\ match\'})$\6
\4\&{else} $\\{err\←print}(\.{\'!\ Ambiguous\ prefix\'})$;\2\2\6
$\\{prefix\←lookup}\K\|r$;\C{the result will be 0 if there was no match}\6
\&{end};\par
\fi

\N71.  Lexical scanning.
Let us now consider the subroutines that read the \.{WEB} source file
and break it into meaningful units. There are four such procedures:
One simply skips to the next `\.{@\ }' or `\.{@*}' that begins a
module; another passes over the \TeX\ text at the beginning of a
module; the third passes over the \TeX\ text in a \PASCAL\ comment;
and the last, which is the most interesting, gets the next token of
a \PASCAL\ text.

\fi

\M72. But first we need to consider the low-level routine \\{get\←line}
that takes care of merging \\{change\←file} into \\{web\←file}. The \\{get%
\←line}
procedure also updates the line numbers for error messages.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{line}: \37\\{integer};\C{the number of the current line in the current
file}\6
\4\\{other\←line}: \37\\{integer};\C{the number of the current line in the
input file that   is not currently being read}\6
\4\\{temp\←line}: \37\\{integer};\C{used when interchanging \\{line} with %
\\{other\←line}}\6
\4\\{limit}: \37$0\to\\{long\←buf\←size}$;\C{the last character position
occupied in the buffer}\6
\4\\{loc}: \37$0\to\\{long\←buf\←size}$;\C{the next character position to be
read from the buffer}\6
\4\\{input\←has\←ended}: \37\\{boolean};\C{if \\{true}, there is no more input}%
\6
\4\\{changing}: \37\\{boolean};\C{if \\{true}, the current line is from %
\\{change\←file}}\par
\fi

\M73. As we change \\{changing} from \\{true} to \\{false} and back again, we
must
remember to swap the values of \\{line} and \\{other\←line} so that the \\{err%
\←print}
routine will be sure to report the correct line number.

\Y\P\D \37$\\{change\←changing}\S\\{changing}\K\R\\{changing}$;\5
$\\{temp\←line}\K\\{other\←line}$;\5
$\\{other\←line}\K\\{line}$;\5
$\\{line}\K\\{temp\←line}$\C{\\{line}\hbox{$\null\BA\null$}\\{other\←line}}\par
\fi

\M74. When \\{changing} is \\{false}, the next line of \\{change\←file} is kept
in
$\\{change\←buffer}[0\to\\{change\←limit}]$, for purposes of comparison with
the next
line of \\{web\←file}. After the change file has been completely input, we
set $\\{change\←limit}\K0$, so that no further matches will be made.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{change\←buffer}: \37\&{array} $[0\to\\{buf\←size}]$ \1\&{of}\5
\\{ASCII\←code};\2\6
\4\\{change\←limit}: \37$0\to\\{buf\←size}$;\C{the last position occupied in %
\\{change\←buffer}}\par
\fi

\M75. Here's a simple function that checks if the two buffers are different.

\Y\P\4\&{function}\1\  \37\\{lines\←dont\←match}: \37\\{boolean};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|k: \37$0\to\\{buf\←size}$;\C{index into the buffers}\2\6
\&{begin} \37$\\{lines\←dont\←match}\K\\{true}$;\6
\&{if} $\\{change\←limit}\I\\{limit}$ \1\&{then}\5
\&{return};\2\6
\&{if} $\\{limit}>0$ \1\&{then}\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{limit}-1$ \1\&{do}\6
\&{if} $\\{change\←buffer}[\|k]\I\\{buffer}[\|k]$ \1\&{then}\5
\&{return};\2\2\2\6
$\\{lines\←dont\←match}\K\\{false}$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M76. Procedure \\{prime\←the\←change\←buffer} sets \\{change\←buffer} in
preparation
for the next matching operation. Since blank lines in the change file are
not used for matching, we have $(\\{change\←limit}=0)\W\R\\{changing}$ if and
only if the change file is exhausted. This procedure is called only
when \\{changing} is true; hence error messages will be reported correctly.

\Y\P\4\&{procedure}\1\  \37\\{prime\←the\←change\←buffer};\6
\4\&{label} \37$\\{continue},\39\\{done},\39\\{exit}$;\6
\4\&{var} \37\|k: \37$0\to\\{buf\←size}$;\C{index into the buffers}\2\6
\&{begin} \37$\\{change\←limit}\K0$;\C{this value will be used if the change
file ends}\6
\X77:Skip over comment lines in the change file; \&{return} if end of file\X;\6
\X78:Skip to the next nonblank line; \&{return} if end of file\X;\6
\X79:Move \\{buffer} and \\{limit} to \\{change\←buffer} and \\{change\←limit}%
\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M77. While looking for a line that begins with \.{@x} in the change file,
we allow lines that begin with \.{@}, as long as they don't begin with
\.{@y} or \.{@z} (which would probably indicate that the change file is
fouled up).

\Y\P$\4\X77:Skip over comment lines in the change file; \&{return} if end of
file\X\S$\6
\~ \1\&{loop}\ \&{begin} \37$\\{incr}(\\{line})$;\6
\&{if} $\R\\{input\←ln}(\\{change\←file})$ \1\&{then}\5
\&{return};\2\6
\&{if} $\\{limit}<2$ \1\&{then}\5
\&{goto} \37\\{continue};\2\6
\&{if} $\\{buffer}[0]\I\.{"@"}$ \1\&{then}\5
\&{goto} \37\\{continue};\2\6
\&{if} $(\\{buffer}[1]\G\.{"X"})\W(\\{buffer}[1]\L\.{"Z"})$ \1\&{then}\5
$\\{buffer}[1]\K\\{buffer}[1]+\.{"z"}-\.{"Z"}$;\C{lowercasify}\2\6
\&{if} $\\{buffer}[1]=\.{"x"}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $(\\{buffer}[1]=\.{"y"})\V(\\{buffer}[1]=\.{"z"})$ \1\&{then}\6
\&{begin} \37$\\{loc}\K2$;\5
$\\{err\←print}(\.{\'!\ Where\ is\ the\ matching\ @x?\'})$;\6
\&{end};\2\6
\4\\{continue}: \37\&{end};\2\6
\4\\{done}: \37\par
\U section~76.\fi

\M78. Here we are looking at lines following the \.{@x}.

\Y\P$\4\X78:Skip to the next nonblank line; \&{return} if end of file\X\S$\6
\1\&{repeat} \37$\\{incr}(\\{line})$;\6
\&{if} $\R\\{input\←ln}(\\{change\←file})$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ Change\ file\ ended\ after\ @x\'})$;\5
\&{return};\6
\&{end};\2\6
\4\&{until}\5
$\\{limit}>0$;\2\par
\U section~76.\fi

\M79. \P$\X79:Move \\{buffer} and \\{limit} to \\{change\←buffer} and \\{change%
\←limit}\X\S$\6
\&{begin} \37$\\{change\←limit}\K\\{limit}$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{limit}$ \1\&{do}\5
$\\{change\←buffer}[\|k]\K\\{buffer}[\|k]$;\2\6
\&{end}\par
\U sections~76 and~80.\fi

\M80. The following procedure is used to see if the next change entry should
go into effect; it is called only when \\{changing} is false.
The idea is to test whether or not the current
contents of \\{buffer} matches the current contents of \\{change\←buffer}.
If not, there's nothing more to do; but if so, a change is called for:
All of the text down to the \.{@y} is supposed to match. An error
message is issued if any discrepancy is found. Then the procedure
prepares to read the next line from \\{change\←file}.

\Y\P\4\&{procedure}\1\  \37\\{check\←change};\C{switches to \\{change\←file} if
the buffers match}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|n: \37\\{integer};\C{the number of discrepancies found}\6
\|k: \37$0\to\\{buf\←size}$;\C{index into the buffers}\2\6
\&{begin} \37\&{if} $\\{lines\←dont\←match}$ \1\&{then}\5
\&{return};\2\6
$\|n\K0$;\6
\~ \1\&{loop}\ \&{begin} \37\\{change\←changing};\C{now it's \\{true}}\6
$\\{incr}(\\{line})$;\6
\&{if} $\R\\{input\←ln}(\\{change\←file})$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ Change\ file\ ended\ before\ @y\'})$;\5
$\\{change\←limit}\K0$;\5
\\{change\←changing};\C{\\{false} again}\6
\&{return};\6
\&{end};\2\6
\X81:If the current line starts with \.{@y}, report any discrepancies and %
\&{return}\X;\6
\X79:Move \\{buffer} and \\{limit} to \\{change\←buffer} and \\{change\←limit}%
\X;\6
\\{change\←changing};\C{now it's \\{false}}\6
$\\{incr}(\\{line})$;\6
\&{if} $\R\\{input\←ln}(\\{web\←file})$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ WEB\ file\ ended\ during\ a\ change\'})$;\5
$\\{input\←has\←ended}\K\\{true}$;\5
\&{return};\6
\&{end};\2\6
\&{if} $\\{lines\←dont\←match}$ \1\&{then}\5
$\\{incr}(\|n)$;\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M81. \P$\X81:If the current line starts with \.{@y}, report any discrepancies
and \&{return}\X\S$\6
\&{if} $\\{limit}>1$ \1\&{then}\6
\&{if} $\\{buffer}[0]=\.{"@"}$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{buffer}[1]\G\.{"X"})\W(\\{buffer}[1]\L\.{"Z"})$ \1%
\&{then}\5
$\\{buffer}[1]\K\\{buffer}[1]+\.{"z"}-\.{"Z"}$;\C{lowercasify}\2\6
\&{if} $(\\{buffer}[1]=\.{"x"})\V(\\{buffer}[1]=\.{"z"})$ \1\&{then}\6
\&{begin} \37$\\{loc}\K2$;\5
$\\{err\←print}(\.{\'!\ Where\ is\ the\ matching\ @y?\'})$;\6
\&{end}\6
\4\&{else} \&{if} $\\{buffer}[1]=\.{"y"}$ \1\&{then}\6
\&{begin} \37\&{if} $\|n>0$ \1\&{then}\6
\&{begin} \37$\\{loc}\K2$;\5
$\\{err\←print}(\.{\'!\ Hmm...\ \'},\39\|n:1,\39\.{\'\ of\ the\ preceding\
lines\ failed\ to\ match\'})$;\6
\&{end};\2\6
\&{return};\6
\&{end};\2\2\6
\&{end}\2\2\par
\U section~80.\fi

\M82. The \\{reset\←input} procedure, which gets \.{WEAVE} ready to read the
user's \.{WEB} input, is used at the beginning of phases one and two.

\Y\P\4\&{procedure}\1\  \37\\{reset\←input};\2\6
\&{begin} \37\\{open\←input};\5
$\\{line}\K0$;\5
$\\{other\←line}\K0$;\6
$\\{changing}\K\\{true}$;\5
\\{prime\←the\←change\←buffer};\5
\\{change\←changing};\6
$\\{limit}\K0$;\5
$\\{loc}\K1$;\5
$\\{buffer}[0]\K\.{"\ "}$;\5
$\\{input\←has\←ended}\K\\{false}$;\6
\&{end};\par
\fi

\M83. The \\{get\←line} procedure is called when $\\{loc}>\\{limit}$; it puts
the next
line of merged input into the buffer and updates the other variables
appropriately. A space is placed at the right end of the line.

\Y\P\4\&{procedure}\1\  \37\\{get\←line};\C{inputs the next line}\6
\4\&{label} \37\\{restart};\2\6
\&{begin} \37\\{restart}: \37\&{if} $\\{changing}$ \1\&{then}\5
$\\{changed\←module}[\\{module\←count}]\K\\{true}$\6
\4\&{else} \X84:Read from \\{web\←file} and maybe turn on \\{changing}\X;\2\6
\&{if} $\\{changing}$ \1\&{then}\6
\&{begin} \37\X85:Read from \\{change\←file} and maybe turn off \\{changing}\X;%
\6
\&{if} $\R\\{changing}$ \1\&{then}\6
\&{begin} \37$\\{changed\←module}[\\{module\←count}]\K\\{true}$;\5
\&{goto} \37\\{restart};\6
\&{end};\2\6
\&{end};\2\6
$\\{loc}\K0$;\5
$\\{buffer}[\\{limit}]\K\.{"\ "}$;\6
\&{end};\par
\fi

\M84. \P$\X84:Read from \\{web\←file} and maybe turn on \\{changing}\X\S$\6
\&{begin} \37$\\{incr}(\\{line})$;\6
\&{if} $\R\\{input\←ln}(\\{web\←file})$ \1\&{then}\5
$\\{input\←has\←ended}\K\\{true}$\6
\4\&{else} \&{if} $\\{limit}=\\{change\←limit}$ \1\&{then}\6
\&{if} $\\{buffer}[0]=\\{change\←buffer}[0]$ \1\&{then}\6
\&{if} $\\{change\←limit}>0$ \1\&{then}\5
\\{check\←change};\2\2\2\2\6
\&{end}\par
\U section~83.\fi

\M85. \P$\X85:Read from \\{change\←file} and maybe turn off \\{changing}\X\S$\6
\&{begin} \37$\\{incr}(\\{line})$;\6
\&{if} $\R\\{input\←ln}(\\{change\←file})$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ Change\ file\ ended\ without\ @z\'})$;\5
$\\{buffer}[0]\K\.{"@"}$;\5
$\\{buffer}[1]\K\.{"z"}$;\5
$\\{limit}\K2$;\6
\&{end};\2\6
\&{if} $\\{limit}>1$ \1\&{then}\C{check if the change has ended}\6
\&{if} $\\{buffer}[0]=\.{"@"}$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{buffer}[1]\G\.{"X"})\W(\\{buffer}[1]\L\.{"Z"})$ \1%
\&{then}\5
$\\{buffer}[1]\K\\{buffer}[1]+\.{"z"}-\.{"Z"}$;\C{lowercasify}\2\6
\&{if} $(\\{buffer}[1]=\.{"x"})\V(\\{buffer}[1]=\.{"y"})$ \1\&{then}\6
\&{begin} \37$\\{loc}\K2$;\5
$\\{err\←print}(\.{\'!\ Where\ is\ the\ matching\ @z?\'})$;\6
\&{end}\6
\4\&{else} \&{if} $\\{buffer}[1]=\.{"z"}$ \1\&{then}\6
\&{begin} \37\\{prime\←the\←change\←buffer};\5
\\{change\←changing};\6
\&{end};\2\2\6
\&{end};\2\2\6
\&{end}\par
\U section~83.\fi

\M86. At the end of the program, we will tell the user if the change file
had a line that didn't match any relevant line in \\{web\←file}.

\Y\P$\4\X86:Check that all changes have been read\X\S$\6
\&{if} $\\{change\←limit}\I0$ \1\&{then}\C{\\{changing} is false}\6
\&{begin} \37\&{for} $\\{loc}\K0\mathrel{\&{to}}\\{change\←limit}$ \1\&{do}\5
$\\{buffer}[\\{loc}]\K\\{change\←buffer}[\\{loc}]$;\2\6
$\\{limit}\K\\{change\←limit}$;\5
$\\{changing}\K\\{true}$;\5
$\\{line}\K\\{other\←line}$;\5
$\\{loc}\K\\{change\←limit}$;\5
$\\{err\←print}(\.{\'!\ Change\ file\ entry\ did\ not\ match\'})$;\6
\&{end}\2\par
\U section~262\*.\fi

\M87. Control codes in \.{WEB}, which begin with `\.{@}', are converted
into a numeric code designed to simplify \.{WEAVE}'s logic; for example,
larger numbers are given to the control codes that denote more significant
milestones, and the code of \\{new\←module} should be the largest of
all. Some of these numeric control codes take the place of ASCII
control codes that will not otherwise appear in the output of the
scanning routines.

\Y\P\D \37$\\{ignore}=0$\C{control code of no interest to \.{WEAVE}}\par
\P\D \37$\\{verbatim}=\O{2}$\C{extended ASCII alpha will not appear}\par
\P\D \37$\\{force\←line}=\O{3}$\C{extended ASCII beta will not appear}\par
\P\D \37$\\{begin\←comment}=\O{11}$\C{ASCII tab mark will not appear}\par
\P\D \37$\\{end\←comment}=\O{12}$\C{ASCII line feed will not appear}\par
\P\D \37$\\{octal}=\O{14}$\C{ASCII form feed will not appear}\par
\P\D \37$\\{hex}=\O{15}$\C{ASCII carriage return will not appear}\par
\P\D \37$\\{double\←dot}=\O{40}$\C{ASCII space will not appear except in
strings}\par
\P\D \37$\\{no\←underline}=\O{175}$\C{this code will be intercepted without
confusion}\par
\P\D \37$\\{underline}=\O{176}$\C{this code will be intercepted without
confusion}\par
\P\D \37$\\{param}=\O{177}$\C{ASCII delete will not appear}\par
\P\D \37$\\{xref\←roman}=\O{203}$\C{control code for `\.{@\↑}'}\par
\P\D \37$\\{xref\←wildcard}=\O{204}$\C{control code for `\.{@:}'}\par
\P\D \37$\\{xref\←typewriter}=\O{205}$\C{control code for `\.{@.}'}\par
\P\D \37$\\{TeX\←string}=\O{206}$\C{control code for `\.{@t}'}\par
\P\D \37$\\{check\←sum}=\O{207}$\C{control code for `\.{@\$}'}\par
\P\D \37$\\{join}=\O{210}$\C{control code for `\.{@\&}'}\par
\P\D \37$\\{thin\←space}=\O{211}$\C{control code for `\.{@,}'}\par
\P\D \37$\\{math\←break}=\O{212}$\C{control code for `\.{@\char'174}'}\par
\P\D \37$\\{line\←break}=\O{213}$\C{control code for `\.{@/}'}\par
\P\D \37$\\{big\←line\←break}=\O{214}$\C{control code for `\.{@\#}'}\par
\P\D \37$\\{no\←line\←break}=\O{215}$\C{control code for `\.{@+}'}\par
\P\D \37$\\{pseudo\←semi}=\O{216}$\C{control code for `\.{@;}'}\par
\P\D \37$\\{format}=\O{217}$\C{control code for `\.{@f}'}\par
\P\D \37$\\{definition}=\O{220}$\C{control code for `\.{@d}'}\par
\P\D \37$\\{begin\←pascal}=\O{221}$\C{control code for `\.{@p}'}\par
\P\D \37$\\{module\←name}=\O{222}$\C{control code for `\.{@<}'}\par
\P\D \37$\\{new\←module}=\O{223}$\C{control code for `\.{@\ }' and `\.{@*}'}\par
\fi

\M88. Control codes are converted from ASCII to \.{WEAVE}'s internal
representation by the \\{control\←code} routine.

\Y\P\4\&{function}\1\  \37$\\{control\←code}(\|c:\\{ASCII\←code})$: \37\\{eight%
\←bits};\C{convert \|c   after \.{@}}\2\6
\&{begin} \37\&{case} $\|c$ \1\&{of}\6
\4\.{"@"}: \37$\\{control\←code}\K\.{"@"}$;\C{`quoted' at sign}\6
\4\.{"\'"}: \37$\\{control\←code}\K\\{octal}$;\C{precedes octal constant}\6
\4\.{""}\.{""}: \37$\\{control\←code}\K\\{hex}$;\C{precedes hexadecimal
constant}\6
\4\.{"\$"}: \37$\\{control\←code}\K\\{check\←sum}$;\C{precedes check sum
constant}\6
\4$\.{"\ "},\39\\{tab\←mark},\39\.{"*"}$: \37$\\{control\←code}\K\\{new%
\←module}$;\C{beginning of a new module}\6
\4\.{"="}: \37$\\{control\←code}\K\\{verbatim}$;\6
\4\.{"\\"}: \37$\\{control\←code}\K\\{force\←line}$;\6
\4$\.{"D"},\39\.{"d"}$: \37$\\{control\←code}\K\\{definition}$;\C{macro
definition}\6
\4$\.{"F"},\39\.{"f"}$: \37$\\{control\←code}\K\\{format}$;\C{format
definition}\6
\4\.{"\{"}: \37$\\{control\←code}\K\\{begin\←comment}$;\C{begin-comment
delimiter}\6
\4\.{"\}"}: \37$\\{control\←code}\K\\{end\←comment}$;\C{end-comment delimiter}\6
\4$\.{"P"},\39\.{"p"}$: \37$\\{control\←code}\K\\{begin\←pascal}$;\C{\PASCAL\
text in unnamed module}\6
\4\.{"\&"}: \37$\\{control\←code}\K\\{join}$;\C{concatenate two tokens}\6
\4\.{"<"}: \37$\\{control\←code}\K\\{module\←name}$;\C{beginning of a module
name}\6
\4\.{">"}: \37\&{begin} \37$\\{err\←print}(\.{\'!\ Extra\ @>\'})$;\5
$\\{control\←code}\K\\{ignore}$;\6
\&{end};\C{end of module name should not be discovered in this way}\6
\4$\.{"T"},\39\.{"t"}$: \37$\\{control\←code}\K\\{TeX\←string}$;\C{\TeX\ box
within \PASCAL}\6
\4\.{"!"}: \37$\\{control\←code}\K\\{underline}$;\C{set definition flag}\6
\4\.{"?"}: \37$\\{control\←code}\K\\{no\←underline}$;\C{reset definition flag}\6
\4\.{"\↑"}: \37$\\{control\←code}\K\\{xref\←roman}$;\C{index entry to be
typeset normally}\6
\4\.{":"}: \37$\\{control\←code}\K\\{xref\←wildcard}$;\C{index entry to be in
user format}\6
\4\.{"."}: \37$\\{control\←code}\K\\{xref\←typewriter}$;\C{index entry to be in
typewriter type}\6
\4\.{","}: \37$\\{control\←code}\K\\{thin\←space}$;\C{puts extra space in %
\PASCAL\ format}\6
\4\.{"|"}: \37$\\{control\←code}\K\\{math\←break}$;\C{allows a break in a
formula}\6
\4\.{"/"}: \37$\\{control\←code}\K\\{line\←break}$;\C{forces end-of-line in %
\PASCAL\ format}\6
\4\.{"\#"}: \37$\\{control\←code}\K\\{big\←line\←break}$;\C{forces end-of-line
and some space besides}\6
\4\.{"+"}: \37$\\{control\←code}\K\\{no\←line\←break}$;\C{cancels end-of-line
down to single space}\6
\4\.{";"}: \37$\\{control\←code}\K\\{pseudo\←semi}$;\C{acts like a semicolon,
but is invisible}\6
\hbox{\4}\X89:Special control codes allowed only when debugging\X\6
\4\&{othercases} \37\&{begin} \37$\\{err\←print}(\.{\'!\ Unknown\ control\ code%
\'})$;\5
$\\{control\←code}\K\\{ignore}$;\6
\&{end}\2\6
\&{endcases};\6
\&{end};\par
\fi

\M89. If \.{WEAVE} is compiled with debugging commands, one can write
\.{@2}, \.{@1}, and \.{@0} to turn tracing fully on, partly on,
and off, respectively.

\Y\P$\4\X89:Special control codes allowed only when debugging\X\S$\6
\&{debug} \37\hbox{}\6
\4$\.{"0"},\39\.{"1"},\39\.{"2"}$: \37\&{begin} \37$\\{tracing}\K\|c-\.{"0"}$;\5
$\\{control\←code}\K\\{ignore}$;\6
\&{end};\6
\&{gubed}\par
\U section~88.\fi

\M90. The \\{skip\←limbo} routine is used on the first pass to skip through
portions of the input that are not in any modules, i.e., that precede
the first module. After this procedure has been called, the value of
\\{input\←has\←ended} will tell whether or not a new module has
actually been found.

\Y\P\4\&{procedure}\1\  \37\\{skip\←limbo};\C{skip to next module}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|c: \37\\{ASCII\←code};\C{character following \.{@}}\2\6
\&{begin} \37\~ \1\&{loop}\6
\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
\&{begin} \37\\{get\←line};\6
\&{if} $\\{input\←has\←ended}$ \1\&{then}\5
\&{return};\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{buffer}[\\{limit}+1]\K\.{"@"}$;\6
\&{while} $\\{buffer}[\\{loc}]\I\.{"@"}$ \1\&{do}\5
$\\{incr}(\\{loc})$;\2\6
\&{if} $\\{loc}\L\\{limit}$ \1\&{then}\6
\&{begin} \37$\\{loc}\K\\{loc}+2$;\5
$\|c\K\\{buffer}[\\{loc}-1]$;\6
\&{if} $(\|c=\.{"\ "})\V(\|c=\\{tab\←mark})\V(\|c=\.{"*"})$ \1\&{then}\5
\&{return};\2\6
\&{end};\2\6
\&{end};\2\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M91. The \\{skip\←TeX} routine is used on the first pass to skip through
the \TeX\ code at the beginning of a module. It returns the next
control code or `\v' found in the input. A \\{new\←module} is
assumed to exist at the very end of the file.

\Y\P\4\&{function}\1\  \37\\{skip\←TeX}: \37\\{eight\←bits};\C{skip past pure %
\TeX\ code}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|c: \37\\{eight\←bits};\C{control code found}\2\6
\&{begin} \37\~ \1\&{loop}\6
\&{begin} \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
\&{begin} \37\\{get\←line};\6
\&{if} $\\{input\←has\←ended}$ \1\&{then}\6
\&{begin} \37$\|c\K\\{new\←module}$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{end};\2\6
$\\{buffer}[\\{limit}+1]\K\.{"@"}$;\6
\1\&{repeat} \37$\|c\K\\{buffer}[\\{loc}]$;\5
$\\{incr}(\\{loc})$;\6
\&{if} $\|c=\.{"|"}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\4\&{until}\5
$\|c=\.{"@"}$;\2\6
\&{if} $\\{loc}\L\\{limit}$ \1\&{then}\6
\&{begin} \37$\|c\K\\{control\←code}(\\{buffer}[\\{loc}])$;\5
$\\{incr}(\\{loc})$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{end};\2\6
\4\\{done}: \37$\\{skip\←TeX}\K\|c$;\6
\&{end};\par
\fi

\M92. The \\{skip\←comment} routine is used on the first pass to skip
through \TeX\ code in \PASCAL\ comments. The \\{bal} parameter
tells how many left braces are assumed to have been scanned when
this routine is called, and the procedure returns a corresponding
value of \\{bal} at the point that scanning has stopped. Scanning
stops either at a `\v' that introduces \PASCAL\ text,
in which case the returned value is positive, or it stops at the
end of the comment, in which case the returned value is zero.
The scanning also stops in anomalous situations when the comment
doesn't end or when it contains an illegal use of \.{@}.
One should call $\\{skip\←comment}(1)$ when beginning to scan a comment.

\Y\P\4\&{function}\1\  \37$\\{skip\←comment}(\\{bal}:\\{eight\←bits})$: \37%
\\{eight\←bits};\C{skips \TeX\   code in comments}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|c: \37\\{ASCII\←code};\C{the current character}\2\6
\&{begin} \37\~ \1\&{loop}\6
\&{begin} \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
\&{begin} \37\\{get\←line};\6
\&{if} $\\{input\←has\←ended}$ \1\&{then}\6
\&{begin} \37$\\{bal}\K0$;\5
\&{goto} \37\\{done};\6
\&{end};\C{an error message will occur in phase two}\2\6
\&{end};\2\6
$\|c\K\\{buffer}[\\{loc}]$;\5
$\\{incr}(\\{loc})$;\6
\&{if} $\|c=\.{"|"}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\X93:Do special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"\}"}$; \&{goto} %
\\{done} at end\X;\6
\&{end};\2\6
\4\\{done}: \37$\\{skip\←comment}\K\\{bal}$;\6
\&{end};\par
\fi

\M93. \P$\X93:Do special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"\}"}$; %
\&{goto} \\{done} at end\X\S$\6
\&{if} $\|c=\.{"@"}$ \1\&{then}\6
\&{begin} \37$\|c\K\\{buffer}[\\{loc}]$;\6
\&{if} $(\|c\I\.{"\ "})\W(\|c\I\\{tab\←mark})\W(\|c\I\.{"*"})$ \1\&{then}\5
$\\{incr}(\\{loc})$\6
\4\&{else} \&{begin} \37$\\{decr}(\\{loc})$;\5
$\\{bal}\K0$;\5
\&{goto} \37\\{done};\6
\&{end}\C{an error message will occur in phase two}\2\6
\&{end}\6
\4\&{else} \&{if} $(\|c=\.{"\\"})\W(\\{buffer}[\\{loc}]\I\.{"@"})$ \1\&{then}\5
$\\{incr}(\\{loc})$\6
\4\&{else} \&{if} $\|c=\.{"\{"}$ \1\&{then}\5
$\\{incr}(\\{bal})$\6
\4\&{else} \&{if} $\|c=\.{"\}"}$ \1\&{then}\6
\&{begin} \37$\\{decr}(\\{bal})$;\6
\&{if} $\\{bal}=0$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{end}\2\2\2\2\par
\U section~92.\fi

\N94.  Inputting the next token.
As stated above, \.{WEAVE}'s most interesting lexical scanning routine is the
\\{get\←next} function that inputs the next token of \PASCAL\ input. However,
\\{get\←next} is not especially complicated.

The result of \\{get\←next} is either an ASCII code for some special character,
or it is a special code representing a pair of characters (e.g., `\.{:=}'
or `\.{..}'), or it is the numeric value computed by the \\{control\←code}
procedure, or it is one of the following special codes:

\yskip\hang \\{exponent}: The `\.E' in a real constant.

\yskip\hang \\{identifier}: In this case the global variables \\{id\←first}
and \\{id\←loc} will have been set to the appropriate values needed by the
\\{id\←lookup} routine.

\yskip\hang \\{string}: In this case the global variables \\{id\←first} and
\\{id\←loc} will have been set to the beginning and ending-plus-one locations
in the buffer.  The string ends with the first reappearance of its initial
delimiter; thus, for example, $$\.{\'This isn\'\'t a single string\'}$$
will be treated as two consecutive strings, the first being \.{\'This
isn\'}.

\yskip\noindent Furthermore, some of the control codes cause
\\{get\←next} to take additional actions:

\yskip\hang \\{xref\←roman}, \\{xref\←wildcard},
\\{xref\←typewriter}, \\{TeX\←string}: The values of
\\{id\←first} and \\{id\←loc} will be set so that the string in question
appears
in $\\{buffer}[\\{id\←first}\to(\\{id\←loc}-1)]$.

\yskip\hang \\{module\←name}: In this case the global variable \\{cur\←module}
will
point to the \\{byte\←start} entry for the module name that has just been
scanned.

\yskip\noindent If \\{get\←next} sees `\.{@!}' or `\.{@?}',
it sets \\{xref\←switch} to \\{def\←flag} or zero and goes on to the next
token.

A global variable called \\{scanning\←hex} is set \\{true} during the time that
the letters \.A through \.F should be treated as if they were digits.

\Y\P\D \37$\\{exponent}=\O{200}$\C{\.E or \.e following a digit}\par
\P\D \37$\\{string}=\O{201}$\C{\PASCAL\ string or \.{WEB} precomputed string}%
\par
\P\D \37$\\{identifier}=\O{202}$\C{\PASCAL\ identifier or reserved word}\par
\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cur\←module}: \37\\{name\←pointer};\C{name of module just scanned}\6
\4\\{scanning\←hex}: \37\\{boolean};\C{are we scanning a hexadecimal constant?}%
\par
\fi

\M95. \P$\X10:Set initial values\X\mathrel{+}\S$\6
$\\{scanning\←hex}\K\\{false}$;\par
\fi

\M96. As one might expect, \\{get\←next} consists mostly of a big switch
that branches to the various special cases that can arise.

\Y\P\D \37$\\{up\←to}(\#)\S\#-24,\39\#-23,\39\#-22,\39\#-21,\39\#-20,\39\#-19,%
\39\#-18,\39\#-17,\39\#-16,\39\#-15,\39\#-14,\39\#-13,\39\#-12,\39\#-11,\39%
\#-10,\39\#-9,\39\#-8,\39\#-7,\39\#-6,\39\#-5,\39\#-4,\39\#-3,\39\#-2,\39\#-1,%
\39\#$\par
\Y\P\4\&{function}\1\  \37\\{get\←next}: \37\\{eight\←bits};\C{produces the
next input token}\6
\4\&{label} \37$\\{restart},\39\\{done},\39\\{found}$;\6
\4\&{var} \37\|c: \37\\{eight\←bits};\C{the current character}\6
\|d: \37\\{eight\←bits};\C{the next character}\6
$\|j,\39\|k$: \37$0\to\\{longest\←name}$;\C{indices into \\{mod\←text}}\2\6
\&{begin} \37\\{restart}: \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
\&{begin} \37\\{get\←line};\6
\&{if} $\\{input\←has\←ended}$ \1\&{then}\6
\&{begin} \37$\|c\K\\{new\←module}$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
\&{end};\2\6
$\|c\K\\{buffer}[\\{loc}]$;\5
$\\{incr}(\\{loc})$;\6
\&{if} $\\{scanning\←hex}$ \1\&{then}\5
\X97:Go to \\{found} if \|c is a hexadecimal digit, otherwise set $\\{scanning%
\←hex}\K\\{false}$\X;\2\6
\&{case} $\|c$ \1\&{of}\6
\4$\.{"A"},\39\\{up\←to}(\.{"Z"}),\39\.{"a"},\39\\{up\←to}(\.{"z"})$: \37%
\X99:Get an identifier\X;\6
\4$\.{"\'"},\39\.{""}\.{""}$: \37\X100:Get a string\X;\6
\4\.{"@"}: \37\X101:Get control code and possible module name\X;\6
\hbox{\4}\X98:Compress two-symbol combinations like `\.{:=}'\X\6
\4$\.{"\ "},\39\\{tab\←mark}$: \37\&{goto} \37\\{restart};\C{ignore spaces and
tabs}\6
\4\&{othercases} \37\\{do\←nothing}\2\6
\&{endcases};\6
\4\\{found}: \37\&{debug} \37\&{if} $\\{trouble\←shooting}$ \1\&{then}\5
\\{debug\←help};\2\ \&{gubed}\6
$\\{get\←next}\K\|c$;\6
\&{end};\par
\fi

\M97. \P$\X97:Go to \\{found} if \|c is a hexadecimal digit, otherwise set $%
\\{scanning\←hex}\K\\{false}$\X\S$\6
\&{if} $((\|c\G\.{"0"})\W(\|c\L\.{"9"}))\V((\|c\G\.{"A"})\W(\|c\L\.{"F"}))$ \1%
\&{then}\5
\&{goto} \37\\{found}\6
\4\&{else} $\\{scanning\←hex}\K\\{false}$\2\par
\U section~96.\fi

\M98. Note that the following code substitutes \.{@\{} and \.{@\}} for the
respective combinations `\.{(*}' and `\.{*)}'. Explicit braces should be used
for \TeX\ comments in \PASCAL\ text.

\Y\P\D \37$\\{compress}(\#)\S$\1\6
\&{begin} \37\&{if} $\\{loc}\L\\{limit}$ \1\&{then}\6
\&{begin} \37$\|c\K\#$;\5
$\\{incr}(\\{loc})$;\6
\&{end};\2\6
\&{end}\2\par
\Y\P$\4\X98:Compress two-symbol combinations like `\.{:=}'\X\S$\6
\4\.{"."}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"."}$ \1\&{then}\5
$\\{compress}(\\{double\←dot})$\6
\4\&{else} \&{if} $\\{buffer}[\\{loc}]=\.{")"}$ \1\&{then}\5
$\\{compress}(\.{"]"})$;\2\2\6
\4\.{":"}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"="}$ \1\&{then}\5
$\\{compress}(\\{left\←arrow})$;\2\6
\4\.{"="}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"="}$ \1\&{then}\5
$\\{compress}(\\{equivalence\←sign})$;\2\6
\4\.{">"}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"="}$ \1\&{then}\5
$\\{compress}(\\{greater\←or\←equal})$;\2\6
\4\.{"<"}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"="}$ \1\&{then}\5
$\\{compress}(\\{less\←or\←equal})$\6
\4\&{else} \&{if} $\\{buffer}[\\{loc}]=\.{">"}$ \1\&{then}\5
$\\{compress}(\\{not\←equal})$;\2\2\6
\4\.{"("}: \37\&{if} $\\{buffer}[\\{loc}]=\.{"*"}$ \1\&{then}\5
$\\{compress}(\\{begin\←comment})$\6
\4\&{else} \&{if} $\\{buffer}[\\{loc}]=\.{"."}$ \1\&{then}\5
$\\{compress}(\.{"["})$;\2\2\6
\4\.{"*"}: \37\&{if} $\\{buffer}[\\{loc}]=\.{")"}$ \1\&{then}\5
$\\{compress}(\\{end\←comment})$;\2\par
\U section~96.\fi

\M99. \P$\X99:Get an identifier\X\S$\6
\&{begin} \37\&{if} $((\|c=\.{"E"})\V(\|c=\.{"e"}))\W(\\{loc}>1)$ \1\&{then}\6
\&{if} $(\\{buffer}[\\{loc}-2]\L\.{"9"})\W(\\{buffer}[\\{loc}-2]\G\.{"0"})$ \1%
\&{then}\5
$\|c\K\\{exponent}$;\2\2\6
\&{if} $\|c\I\\{exponent}$ \1\&{then}\6
\&{begin} \37$\\{decr}(\\{loc})$;\5
$\\{id\←first}\K\\{loc}$;\6
\1\&{repeat} \37$\\{incr}(\\{loc})$;\5
$\|d\K\\{buffer}[\\{loc}]$;\6
\4\&{until}\5
$((\|d<\.{"0"})\V((\|d>\.{"9"})\W(\|d<\.{"A"}))\V((\|d>\.{"Z"})\W(\|d<\.{"a"}))%
\V(\|d>\.{"z"}))\W(\|d\I\.{"\←"})$;\2\6
$\|c\K\\{identifier}$;\5
$\\{id\←loc}\K\\{loc}$;\6
\&{end};\2\6
\&{end}\par
\U section~96.\fi

\M100. A string that starts and ends with single or double quote marks is
scanned by the following piece of the program.

\Y\P$\4\X100:Get a string\X\S$\6
\&{begin} \37$\\{id\←first}\K\\{loc}-1$;\6
\1\&{repeat} \37$\|d\K\\{buffer}[\\{loc}]$;\5
$\\{incr}(\\{loc})$;\6
\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ String\ constant\ didn\'}\.{\'t\ end\'})$;%
\5
$\\{loc}\K\\{limit}$;\5
$\|d\K\|c$;\6
\&{end};\2\6
\4\&{until}\5
$\|d=\|c$;\2\6
$\\{id\←loc}\K\\{loc}$;\5
$\|c\K\\{string}$;\6
\&{end}\par
\U section~96.\fi

\M101. After an \.{@} sign has been scanned, the next character tells us
whether there is more work to do.

\Y\P$\4\X101:Get control code and possible module name\X\S$\6
\&{begin} \37$\|c\K\\{control\←code}(\\{buffer}[\\{loc}])$;\5
$\\{incr}(\\{loc})$;\6
\&{if} $\|c=\\{underline}$ \1\&{then}\6
\&{begin} \37$\\{xref\←switch}\K\\{def\←flag}$;\5
\&{goto} \37\\{restart};\6
\&{end}\6
\4\&{else} \&{if} $\|c=\\{no\←underline}$ \1\&{then}\6
\&{begin} \37$\\{xref\←switch}\K0$;\5
\&{goto} \37\\{restart};\6
\&{end}\6
\4\&{else} \&{if} $(\|c\L\\{TeX\←string})\W(\|c\G\\{xref\←roman})$ \1\&{then}\5
\X107:Scan to the next \.{@>}\X\6
\4\&{else} \&{if} $\|c=\\{hex}$ \1\&{then}\5
$\\{scanning\←hex}\K\\{true}$\6
\4\&{else} \&{if} $\|c=\\{module\←name}$ \1\&{then}\5
\X102:Scan the module name and make \\{cur\←module} point to it\X\6
\4\&{else} \&{if} $\|c=\\{verbatim}$ \1\&{then}\5
\X108:Scan a verbatim string\X;\2\2\2\2\2\2\6
\&{end}\par
\U section~96.\fi

\M102. The occurrence of a module name sets \\{xref\←switch} to zero,
because the module name might (for example) follow \&{var}.

\Y\P$\4\X102:Scan the module name and make \\{cur\←module} point to it\X\S$\6
\&{begin} \37\X104:Put module name into $\\{mod\←text}[1\to\|k]$\X;\6
\&{if} $\|k>3$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{mod\←text}[\|k]=\.{"."})\W(\\{mod\←text}[\|k-1]=%
\.{"."})\W(\\{mod\←text}[\|k-2]=\.{"."})$ \1\&{then}\5
$\\{cur\←module}\K\\{prefix\←lookup}(\|k-3)$\6
\4\&{else} $\\{cur\←module}\K\\{mod\←lookup}(\|k)$;\2\6
\&{end}\6
\4\&{else} $\\{cur\←module}\K\\{mod\←lookup}(\|k)$;\2\6
$\\{xref\←switch}\K0$;\6
\&{end}\par
\U section~101.\fi

\M103. Module names are placed into the \\{mod\←text} array with consecutive
spaces,
tabs, and carriage-returns replaced by single spaces. There will be no
spaces at the beginning or the end. (We set $\\{mod\←text}[0]\K\.{"\ "}$ to
facilitate
this, since the \\{mod\←lookup} routine uses $\\{mod\←text}[1]$ as the first
character of the name.)

\Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
$\\{mod\←text}[0]\K\.{"\ "}$;\par
\fi

\M104. \P$\X104:Put module name into $\\{mod\←text}[1\to\|k]$\X\S$\6
$\|k\K0$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
\&{begin} \37\\{get\←line};\6
\&{if} $\\{input\←has\←ended}$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ Input\ ended\ in\ section\ name\'})$;\5
$\\{loc}\K1$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{end};\2\6
$\|d\K\\{buffer}[\\{loc}]$;\5
\X105:If end of name, \&{goto} \\{done}\X;\6
$\\{incr}(\\{loc})$;\6
\&{if} $\|k<\\{longest\←name}-1$ \1\&{then}\5
$\\{incr}(\|k)$;\2\6
\&{if} $(\|d=\.{"\ "})\V(\|d=\\{tab\←mark})$ \1\&{then}\6
\&{begin} \37$\|d\K\.{"\ "}$;\6
\&{if} $\\{mod\←text}[\|k-1]=\.{"\ "}$ \1\&{then}\5
$\\{decr}(\|k)$;\2\6
\&{end};\2\6
$\\{mod\←text}[\|k]\K\|d$;\6
\&{end};\2\6
\4\\{done}: \37\X106:Check for overlong name\X;\6
\&{if} $(\\{mod\←text}[\|k]=\.{"\ "})\W(\|k>0)$ \1\&{then}\5
$\\{decr}(\|k)$\2\par
\U section~102.\fi

\M105. \P$\X105:If end of name, \&{goto} \\{done}\X\S$\6
\&{if} $\|d=\.{"@"}$ \1\&{then}\6
\&{begin} \37$\|d\K\\{buffer}[\\{loc}+1]$;\6
\&{if} $\|d=\.{">"}$ \1\&{then}\6
\&{begin} \37$\\{loc}\K\\{loc}+2$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{if} $(\|d=\.{"\ "})\V(\|d=\\{tab\←mark})\V(\|d=\.{"*"})$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ Section\ name\ didn\'}\.{\'t\ end\'})$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
$\\{incr}(\|k)$;\5
$\\{mod\←text}[\|k]\K\.{"@"}$;\5
$\\{incr}(\\{loc})$;\C{now $\|d=\\{buffer}[\\{loc}]$ again}\6
\&{end}\2\par
\U section~104.\fi

\M106. \P$\X106:Check for overlong name\X\S$\6
\&{if} $\|k\G\\{longest\←name}-2$ \1\&{then}\6
\&{begin} \37$\\{print\←nl}(\.{\'!\ Section\ name\ too\ long:\ \'})$;\6
\&{for} $\|j\K1\mathrel{\&{to}}25$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{mod\←text}[\|j]])$;\2\6
$\\{print}(\.{\'...\'})$;\5
\\{mark\←harmless};\6
\&{end}\2\par
\U section~104.\fi

\M107. \P$\X107:Scan to the next \.{@>}\X\S$\6
\&{begin} \37$\\{id\←first}\K\\{loc}$;\5
$\\{buffer}[\\{limit}+1]\K\.{"@"}$;\6
\&{while} $\\{buffer}[\\{loc}]\I\.{"@"}$ \1\&{do}\5
$\\{incr}(\\{loc})$;\2\6
$\\{id\←loc}\K\\{loc}$;\6
\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ Control\ text\ didn\'}\.{\'t\ end\'})$;\5
$\\{loc}\K\\{limit}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{loc}\K\\{loc}+2$;\6
\&{if} $\\{buffer}[\\{loc}-1]\I\.{">"}$ \1\&{then}\5
$\\{err\←print}(\.{\'!\ Control\ codes\ are\ forbidden\ in\ control\ text\'})$;%
\2\6
\&{end};\2\6
\&{end}\par
\U section~101.\fi

\M108. A verbatim \PASCAL\ string will be treated like ordinary strings, but
with no surrounding delimiters.  At the present point in the program we
have $\\{buffer}[\\{loc}-1]=\\{verbatim}$; we must set \\{id\←first} to the
beginning
of the string itself, and \\{id\←loc} to its ending-plus-one location in the
buffer.  We also set \\{loc} to the position just after the ending delimiter.

\Y\P$\4\X108:Scan a verbatim string\X\S$\6
\&{begin} \37$\\{id\←first}\K\\{loc}$;\5
$\\{incr}(\\{loc})$;\5
$\\{buffer}[\\{limit}+1]\K\.{"@"}$;\5
$\\{buffer}[\\{limit}+2]\K\.{">"}$;\6
\&{while} $(\\{buffer}[\\{loc}]\I\.{"@"})\V(\\{buffer}[\\{loc}+1]\I\.{">"})$ \1%
\&{do}\5
$\\{incr}(\\{loc})$;\2\6
\&{if} $\\{loc}\G\\{limit}$ \1\&{then}\5
$\\{err\←print}(\.{\'!\ Verbatim\ string\ didn\'}\.{\'t\ end\'})$;\2\6
$\\{id\←loc}\K\\{loc}$;\5
$\\{loc}\K\\{loc}+2$;\6
\&{end}\par
\U section~101.\fi

\N109.  Phase one processing.
We now have accumulated enough subroutines to make it possible to carry out
\.{WEAVE}'s first pass over the source file. If everything works right,
both phase one and phase two of \.{WEAVE} will assign the same numbers to
modules, and these numbers will agree with what \.{TANGLE} does.

The global variable \\{next\←control} often contains the most recent output of
\\{get\←next}; in interesting cases, this will be the control code that
ended a module or part of a module.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{next\←control}: \37\\{eight\←bits};\C{control code waiting to be acting
upon}\par
\fi

\M110. The overall processing strategy in phase one has the following
straightforward outline.

\Y\P$\4\X110:Phase I: Read all the user's text and store the cross references\X%
\S$\6
$\\{phase\←one}\K\\{true}$;\5
$\\{phase\←three}\K\\{false}$;\5
\\{reset\←input};\5
$\\{module\←count}\K0$;\5
\\{skip\←limbo};\5
$\\{change\←exists}\K\\{false}$;\6
\&{while} $\R\\{input\←has\←ended}$ \1\&{do}\5
\X111:Store cross reference data for the current module\X;\2\6
$\\{changed\←module}[\\{module\←count}]\K\\{change\←exists}$;\C{the index
changes if anything does}\6
$\\{phase\←one}\K\\{false}$;\C{prepare for second phase}\6
\X121:Print error messages about unused or undefined module names\X;\par
\U section~262\*.\fi

\M111. \P$\X111:Store cross reference data for the current module\X\S$\6
\&{begin} \37$\\{incr}(\\{module\←count})$;\6
\&{if} $\\{module\←count}=\\{max\←modules}$ \1\&{then}\5
$\\{overflow}(\.{\'section\ number\'})$;\2\6
$\\{changed\←module}[\\{module\←count}]\K\\{false}$;\C{it will become \\{true}
if any line changes}\6
\&{if} $\\{buffer}[\\{loc}-1]=\.{"*"}$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{\'*\'},\39\\{module\←count}:1)$;\5
\\{update\←terminal};\C{print a progress report}\6
\&{end};\2\6
\X114:Store cross references in the \TeX\ part of a module\X;\6
\X116:Store cross references in the \(definition part of a module\X;\6
\X118:Store cross references in the \PASCAL\ part of a module\X;\6
\&{if} $\\{changed\←module}[\\{module\←count}]$ \1\&{then}\5
$\\{change\←exists}\K\\{true}$;\2\6
\&{end}\par
\U section~110.\fi

\M112. The \\{PASCAL\←xref} subroutine stores references to identifiers in
\PASCAL\ text material beginning with the current value of \\{next\←control}
and continuing until \\{next\←control} is `\.\{' or `\v', or until the next
``milestone'' is passed (i.e., $\\{next\←control}\G\\{format}$). If
$\\{next\←control}\G\\{format}$ when \\{PASCAL\←xref} is called, nothing will
happen;
but if $\\{next\←control}=\.{"|"}$ upon entry, the procedure assumes that this
is
the `\v' preceding \PASCAL\ text that is to be processed.

The program uses the fact that our internal code numbers satisfy
the relations $\\{xref\←roman}=\\{identifier}+\\{roman}$ and $\\{xref%
\←wildcard}=\\{identifier}+\\{wildcard}$ and $\\{xref\←typewriter}=%
\\{identifier}+\\{typewriter}$ and $\\{normal}=0$. An implied `\.{@!}' is
inserted after
\&{function}, \&{procedure}, \&{program}, and \&{var}.

\Y\P\4\&{procedure}\1\  \37\\{PASCAL\←xref};\C{makes cross references for %
\PASCAL\ identifiers}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|p: \37\\{name\←pointer};\C{a referenced name}\2\6
\&{begin} \37\&{while} $\\{next\←control}<\\{format}$ \1\&{do}\6
\&{begin} \37\&{if} $(\\{next\←control}\G\\{identifier})\W(\\{next\←control}\L%
\\{xref\←typewriter})$ \1\&{then}\6
\&{begin} \37$\|p\K\\{id\←lookup}(\\{next\←control}-\\{identifier})$;\5
$\\{new\←xref}(\|p)$;\6
\&{if} $(\\{ilk}[\|p]=\\{proc\←like})\V(\\{ilk}[\|p]=\\{var\←like})$ \1\&{then}%
\5
$\\{xref\←switch}\K\\{def\←flag}$;\C{implied `\.{@!}'}\2\6
\&{end};\2\6
$\\{next\←control}\K\\{get\←next}$;\6
\&{if} $(\\{next\←control}=\.{"|"})\V(\\{next\←control}=\.{"\{"})$ \1\&{then}\5
\&{return};\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M113. The \\{outer\←xref} subroutine is like \\{PASCAL\←xref} but it begins
with $\\{next\←control}\I\.{"|"}$ and ends with $\\{next\←control}\G%
\\{format}$. Thus, it
handles \PASCAL\ text with embedded comments.

\Y\P\4\&{procedure}\1\  \37\\{outer\←xref};\C{extension of \\{PASCAL\←xref}}\6
\4\&{var} \37\\{bal}: \37\\{eight\←bits};\C{brace level in comment}\2\6
\&{begin} \37\&{while} $\\{next\←control}<\\{format}$ \1\&{do}\6
\&{if} $\\{next\←control}\I\.{"\{"}$ \1\&{then}\5
\\{PASCAL\←xref}\6
\4\&{else} \&{begin} \37$\\{bal}\K\\{skip\←comment}(1)$;\5
$\\{next\←control}\K\.{"|"}$;\6
\&{while} $\\{bal}>0$ \1\&{do}\6
\&{begin} \37\\{PASCAL\←xref};\6
\&{if} $\\{next\←control}=\.{"|"}$ \1\&{then}\5
$\\{bal}\K\\{skip\←comment}(\\{bal})$\6
\4\&{else} $\\{bal}\K0$;\C{an error will be reported in phase two}\2\6
\&{end};\2\6
\&{end};\2\2\6
\&{end};\par
\fi

\M114. In the \TeX\ part of a module, cross reference entries are made only for
the identifiers in \PASCAL\ texts enclosed in \pb, or for control texts
enclosed in \.{@\↑}$\,\ldots\,$\.{@>} or \.{@.}$\,\ldots\,$\.{@>}
or \.{@:}$\,\ldots\,$\.{@>}.

\Y\P$\4\X114:Store cross references in the \TeX\ part of a module\X\S$\6
\1\&{repeat} \37$\\{next\←control}\K\\{skip\←TeX}$;\6
\&{case} $\\{next\←control}$ \1\&{of}\6
\4\\{underline}: \37$\\{xref\←switch}\K\\{def\←flag}$;\6
\4\\{no\←underline}: \37$\\{xref\←switch}\K0$;\6
\4\.{"|"}: \37\\{PASCAL\←xref};\6
\4$\\{xref\←roman},\39\\{xref\←wildcard},\39\\{xref\←typewriter},\39\\{module%
\←name}$: \37\&{begin} \37$\\{loc}\K\\{loc}-2$;\5
$\\{next\←control}\K\\{get\←next}$;\C{scan to \.{@>}}\6
\&{if} $\\{next\←control}\I\\{module\←name}$ \1\&{then}\5
$\\{new\←xref}(\\{id\←lookup}(\\{next\←control}-\\{identifier}))$;\2\6
\&{end};\6
\4\&{othercases} \37\\{do\←nothing}\2\6
\&{endcases};\6
\4\&{until}\5
$\\{next\←control}\G\\{format}$\2\par
\U section~111.\fi

\M115. During the definition and \PASCAL\ parts of a module, cross references
are made for all identifiers except reserved words; however, the
identifiers in a format definition are referenced even if they are
reserved. The \TeX\ code in comments is, of course, ignored, except for
\PASCAL\ portions enclosed in \pb; the text of a module name is skipped
entirely, even if it contains \pb\ constructions.

The variables \\{lhs} and \\{rhs} point to the respective identifiers involved
in a format definition.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4$\\{lhs},\39\\{rhs}$: \37\\{name\←pointer};\C{indices into \\{byte\←start}
for format identifiers}\par
\fi

\M116. When we get to the following code we have $\\{next\←control}\G%
\\{format}$.

\Y\P$\4\X116:Store cross references in the \(definition part of a module\X\S$\6
\&{while} $\\{next\←control}\L\\{definition}$ \1\&{do}\C{\\{format} or %
\\{definition}}\6
\&{begin} \37$\\{xref\←switch}\K\\{def\←flag}$;\C{implied \.{@!}}\6
\&{if} $\\{next\←control}=\\{definition}$ \1\&{then}\5
$\\{next\←control}\K\\{get\←next}$\6
\4\&{else} \X117:Process a format definition\X;\2\6
\\{outer\←xref};\6
\&{end}\2\par
\U section~111.\fi

\M117. Error messages for improper format definitions will be issued in phase
two. Our job in phase one is to define the \\{ilk} of a properly formatted
identifier, and to fool the \\{new\←xref} routine into thinking that the
identifier on the right-hand side of the format definition is not a
reserved word.

\Y\P$\4\X117:Process a format definition\X\S$\6
\&{begin} \37$\\{next\←control}\K\\{get\←next}$;\6
\&{if} $\\{next\←control}=\\{identifier}$ \1\&{then}\6
\&{begin} \37$\\{lhs}\K\\{id\←lookup}(\\{normal})$;\5
$\\{ilk}[\\{lhs}]\K\\{normal}$;\5
$\\{new\←xref}(\\{lhs})$;\5
$\\{next\←control}\K\\{get\←next}$;\6
\&{if} $\\{next\←control}=\\{equivalence\←sign}$ \1\&{then}\6
\&{begin} \37$\\{next\←control}\K\\{get\←next}$;\6
\&{if} $\\{next\←control}=\\{identifier}$ \1\&{then}\6
\&{begin} \37$\\{rhs}\K\\{id\←lookup}(\\{normal})$;\5
$\\{ilk}[\\{lhs}]\K\\{ilk}[\\{rhs}]$;\5
$\\{ilk}[\\{rhs}]\K\\{normal}$;\5
$\\{new\←xref}(\\{rhs})$;\5
$\\{ilk}[\\{rhs}]\K\\{ilk}[\\{lhs}]$;\5
$\\{next\←control}\K\\{get\←next}$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\2\6
\&{end}\par
\U section~116.\fi

\M118. Finally, when the \TeX\ and definition parts have been treated, we have
$\\{next\←control}\G\\{begin\←pascal}$.

\Y\P$\4\X118:Store cross references in the \PASCAL\ part of a module\X\S$\6
\&{if} $\\{next\←control}\L\\{module\←name}$ \1\&{then}\C{\\{begin\←pascal} or %
\\{module\←name}}\6
\&{begin} \37\&{if} $\\{next\←control}=\\{begin\←pascal}$ \1\&{then}\5
$\\{mod\←xref\←switch}\K0$\6
\4\&{else} $\\{mod\←xref\←switch}\K\\{def\←flag}$;\2\6
\1\&{repeat} \37\&{if} $\\{next\←control}=\\{module\←name}$ \1\&{then}\5
$\\{new\←mod\←xref}(\\{cur\←module})$;\2\6
$\\{next\←control}\K\\{get\←next}$;\5
\\{outer\←xref};\6
\4\&{until}\5
$\\{next\←control}>\\{module\←name}$;\2\6
\&{end}\2\par
\U section~111.\fi

\M119. After phase one has looked at everything, we want to check that each
module name was both defined and used.
The variable \\{cur\←xref} will point to cross references for the
current module name of interest.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cur\←xref}: \37\\{xref\←number};\C{temporary cross reference pointer}\par
\fi

\M120. The following recursive procedure
walks through the tree of module names and prints out anomalies.

\Y\P\4\&{procedure}\1\  \37$\\{mod\←check}(\|p:\\{name\←pointer})$;\C{print
anomalies in subtree \|p}\2\6
\&{begin} \37\&{if} $\|p>0$ \1\&{then}\6
\&{begin} \37$\\{mod\←check}(\\{llink}[\|p])$;\6
$\\{cur\←xref}\K\\{xref}[\|p]$;\6
\&{if} $\\{num}(\\{cur\←xref})<\\{def\←flag}$ \1\&{then}\6
\&{begin} \37$\\{print\←nl}(\.{\'!\ Never\ defined:\ <\'})$;\5
$\\{print\←id}(\|p)$;\5
$\\{print}(\.{\'>\'})$;\5
\\{mark\←harmless};\6
\&{end};\2\6
\&{while} $\\{num}(\\{cur\←xref})\G\\{def\←flag}$ \1\&{do}\5
$\\{cur\←xref}\K\\{xlink}(\\{cur\←xref})$;\2\6
\&{if} $\\{cur\←xref}=0$ \1\&{then}\6
\&{begin} \37$\\{print\←nl}(\.{\'!\ Never\ used:\ <\'})$;\5
$\\{print\←id}(\|p)$;\5
$\\{print}(\.{\'>\'})$;\5
\\{mark\←harmless};\6
\&{end};\2\6
$\\{mod\←check}(\\{rlink}[\|p])$;\6
\&{end};\2\6
\&{end};\par
\fi

\M121. \P$\X121:Print error messages about unused or undefined module names\X%
\S$\ $\\{mod\←check}(\\{root})$\par
\U section~110.\fi

\N122.  Low-level output routines.
The \TeX\ output is supposed to appear in lines at most \\{line\←length}
characters long, so we place it into an output buffer. During the output
process, \\{out\←line} will hold the current line number of the line about to
be output.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{out\←buf}: \37\&{array} $[0\to\\{line\←length}]$ \1\&{of}\5
\\{ASCII\←code};\C{assembled characters}\2\6
\4\\{out\←ptr}: \37$0\to\\{line\←length}$;\C{number of characters in \\{out%
\←buf}}\6
\4\\{out\←line}: \37\\{integer};\C{coordinates of next line to be output}\par
\fi

\M123. The \\{flush\←buffer} routine empties the buffer up to a given
breakpoint,
and moves any remaining characters to the beginning of the next line.
If the \\{per\←cent} parameter is \\{true}, a \.{"\%"} is appended to the line
that is being output; in this case the breakpoint \|b should be strictly
less than \\{line\←length}. If the \\{per\←cent} parameter is \\{false},
trailing blanks are suppressed.
The characters emptied from the buffer form a new line of output.

\Y\P\4\&{procedure}\1\  \37$\\{flush\←buffer}(\|b:\\{eight\←bits};\,\35\\{per%
\←cent}:\\{boolean})$;\C{outputs $\\{out\←buf}[1\to\|b]$,where $\|b\L\\{out%
\←ptr}$}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37$\|j,\39\|k$: \37$0\to\\{line\←length}$;\2\6
\&{begin} \37$\|j\K\|b$;\6
\&{if} $\R\\{per\←cent}$ \1\&{then}\C{remove trailing blanks}\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\|j=0$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\\{out\←buf}[\|j]\I\.{"\ "}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{decr}(\|j)$;\6
\&{end};\2\2\6
\4\\{done}: \37\&{for} $\|k\K1\mathrel{\&{to}}\|j$ \1\&{do}\5
$\\{write}(\\{tex\←file},\39\\{xchr}[\\{out\←buf}[\|k]])$;\2\6
\&{if} $\\{per\←cent}$ \1\&{then}\5
$\\{write}(\\{tex\←file},\39\\{xchr}[\.{"\%"}])$;\2\6
$\\{write\←ln}(\\{tex\←file})$;\5
$\\{incr}(\\{out\←line})$;\6
\&{if} $\|b<\\{out\←ptr}$ \1\&{then}\6
\&{for} $\|k\K\|b+1\mathrel{\&{to}}\\{out\←ptr}$ \1\&{do}\5
$\\{out\←buf}[\|k-\|b]\K\\{out\←buf}[\|k]$;\2\2\6
$\\{out\←ptr}\K\\{out\←ptr}-\|b$;\6
\&{end};\par
\fi

\M124. When we are copying \TeX\ source material, we retain line breaks
that occur in the input, except that an empty line is not
output when the \TeX\ source line was nonempty. For example, a line
of the \TeX\ file that contains only an index cross-reference entry
will not be copied. The \\{finish\←line} routine is called just before
\\{get\←line} inputs a new line, and just after a line break token has
been emitted during the output of translated \PASCAL\ text.

\Y\P\4\&{procedure}\1\  \37\\{finish\←line};\C{do this at the end of a line}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|k: \37$0\to\\{buf\←size}$;\C{index into \\{buffer}}\2\6
\&{begin} \37\&{if} $\\{out\←ptr}>0$ \1\&{then}\5
$\\{flush\←buffer}(\\{out\←ptr},\39\\{false})$\6
\4\&{else} \&{begin} \37\&{for} $\|k\K0\mathrel{\&{to}}\\{limit}$ \1\&{do}\6
\&{if} $(\\{buffer}[\|k]\I\.{"\ "})\W(\\{buffer}[\|k]\I\\{tab\←mark})$ \1%
\&{then}\5
\&{return};\2\2\6
$\\{flush\←buffer}(0,\39\\{false})$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M125. In particular, the \\{finish\←line} procedure is called near the very
beginning of phase two. We initialize the output variables in a slightly
tricky way so that the first line of the output file will be
`\.{\\input webmac}'.

\Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
$\\{out\←ptr}\K1$;\5
$\\{out\←line}\K1$;\5
$\\{out\←buf}[1]\K\.{"c"}$;\5
$\\{write}(\\{tex\←file},\39\.{\'\\input\ webma\'})$;\par
\fi

\M126. When we wish to append the character \|c to the output buffer, we write
`$\\{out}(c)$'; this will cause the buffer to be emptied if it was already
full. Similarly, `$\\{out2}(c←1)(c←2)$' appends a pair of characters.
A line break will occur at a space or after a single-nonletter
\TeX\ control sequence.

\Y\P\D \37$\\{oot}(\#)\S$\6
\&{if} $\\{out\←ptr}=\\{line\←length}$ \1\&{then}\5
\\{break\←out};\2\6
$\\{incr}(\\{out\←ptr})$;\5
$\\{out\←buf}[\\{out\←ptr}]\K\#$;\par
\P\D \37$\\{oot1}(\#)\S\\{oot}(\#)$\ \&{end} \par
\P\D \37$\\{oot2}(\#)\S\\{oot}(\#)\,\\{oot1}$\par
\P\D \37$\\{oot3}(\#)\S\\{oot}(\#)\,\\{oot2}$\par
\P\D \37$\\{oot4}(\#)\S\\{oot}(\#)\,\\{oot3}$\par
\P\D \37$\\{oot5}(\#)\S\\{oot}(\#)\,\\{oot4}$\par
\P\D \37$\\{out}\S$\ \&{begin} \37\\{oot1}\par
\P\D \37$\\{out2}\S$\ \&{begin} \37\\{oot2}\par
\P\D \37$\\{out3}\S$\ \&{begin} \37\\{oot3}\par
\P\D \37$\\{out4}\S$\ \&{begin} \37\\{oot4}\par
\P\D \37$\\{out5}\S$\ \&{begin} \37\\{oot5}\par
\fi

\M127. The \\{break\←out} routine is called just before the output buffer is
about
to overflow. To make this routine a little faster, we initialize position
0 of the output buffer to `\.\\'; this character isn't really output.

\Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
$\\{out\←buf}[0]\K\.{"\\"}$;\par
\fi

\M128\*. A long line is broken at a blank space or just before a backslash that
isn't
preceded by another backslash. In the latter case, a \.{"\%"} is output at
the break.

\Y\P\4\&{procedure}\1\  \37\\{break\←out};\C{finds a way to break the output
line}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|k: \37$0\to\\{line\←length}$;\C{index into \\{out\←buf}}\6
\|d: \37\\{ASCII\←code};\C{character from the buffer}\2\6
\&{begin} \37$\|k\K\\{out\←ptr}$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\|k=0$ \1\&{then}\5
\X129:Print warning message, break the line, \&{return}\X;\2\6
$\|d\K\\{out\←buf}[\|k]$;\6
\&{if} $\|d=\.{"\ "}$ \1\&{then}\6
\&{begin} \37$\\{flush\←buffer}(\|k,\39\\{false})$;\5
\&{return};\6
\&{end};\2\6
\&{if} $(\|d=\.{"\\"})\W(\\{out\←buf}[\|k-1]\I\.{"\\"})$ \1\&{then}\C{in this
case $\|k>1$}\6
\&{begin} \37$\\{flush\←buffer}(\|k-1,\39\\{true})$;\5
\&{return};\6
\&{end};\2\6
$\\{decr}(\|k)$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M129. We get to this module only in unusual cases that the entire output line
consists of a string of backslashes followed by a string of nonblank
non-backslashes. In such cases it is almost always safe to break the
line by putting a \.{"\%"} just before the last character.

\Y\P$\4\X129:Print warning message, break the line, \&{return}\X\S$\6
\&{begin} \37$\\{print\←nl}(\.{\'!\ Line\ had\ to\ be\ broken\ (output\ l.\'},%
\39\\{out\←line}:1)$;\5
$\\{print\←ln}(\.{\'):\'})$;\6
\&{for} $\|k\K1\mathrel{\&{to}}\\{out\←ptr}-1$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{out\←buf}[\|k]])$;\2\6
\\{new\←line};\5
\\{mark\←harmless};\5
$\\{flush\←buffer}(\\{out\←ptr}-1,\39\\{true})$;\5
\&{return};\6
\&{end}\par
\U section~128\*.\fi

\M130. Here is a procedure that outputs a module number in decimal notation.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{dig}: \37\&{array} $[0\to4]$ \1\&{of}\5
$0\to9$;\C{digits to output}\2\par
\fi

\M131. The number to be converted by \\{out\←mod} is known to be less than
\\{def\←flag}, so it cannot have more than five decimal digits.  If
the module is changed, we output `\.{\\*}' just after the number.

\Y\P\4\&{procedure}\1\  \37$\\{out\←mod}(\|m:\\{integer})$;\C{output a module
number}\6
\4\&{var} \37\|k: \37$0\to5$;\C{index into \\{dig}}\6
\|a: \37\\{integer};\C{accumulator}\2\6
\&{begin} \37$\|k\K0$;\5
$\|a\K\|m$;\6
\1\&{repeat} \37$\\{dig}[\|k]\K\|a\mathbin{\&{mod}}10$;\5
$\|a\K\|a\mathbin{\&{div}}10$;\5
$\\{incr}(\|k)$;\6
\4\&{until}\5
$\|a=0$;\2\6
\1\&{repeat} \37$\\{decr}(\|k)$;\5
$\\{out}(\\{dig}[\|k]+\.{"0"})$;\6
\4\&{until}\5
$\|k=0$;\2\6
\&{if} $\\{changed\←module}[\|m]$ \1\&{then}\5
$\\{out2}(\.{"\\"})(\.{"*"})$;\2\6
\&{end};\par
\fi

\M132. The \\{out\←name} subroutine is used to output an identifier or index
entry, enclosing it in braces.

\Y\P\4\&{procedure}\1\  \37$\\{out\←name}(\|p:\\{name\←pointer})$;\C{outputs a
name}\6
\4\&{var} \37\|k: \37$0\to\\{max\←bytes}$;\C{index into \\{byte\←mem}}\6
\|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\←mem}}\2\6
\&{begin} \37$\\{out}(\.{"\{"})$;\5
$\|w\K\|p\mathbin{\&{mod}}\\{ww}$;\6
\&{for} $\|k\K\\{byte\←start}[\|p]\mathrel{\&{to}}\\{byte\←start}[\|p+%
\\{ww}]-1$ \1\&{do}\6
\&{begin} \37\&{if} $\\{byte\←mem}[\|w,\39\|k]=\.{"\←"}$ \1\&{then}\5
$\\{out}(\.{"\\"})$;\2\6
$\\{out}(\\{byte\←mem}[\|w,\39\|k])$;\6
\&{end};\2\6
$\\{out}(\.{"\}"})$;\6
\&{end};\par
\fi

\N133.  Routines that copy \TeX\ material.
During phase two, we use the subroutines \\{copy\←limbo}, \\{copy\←TeX}, and
\\{copy\←comment} in place of the analogous \\{skip\←limbo}, \\{skip\←TeX}, and
\\{skip\←comment} that were used in phase one.

The \\{copy\←limbo} routine, for example, takes \TeX\ material that is not
part of any module and transcribes it almost verbatim to the output file.
No `\.{@}' signs should occur in such material except in `\.{@@}'
pairs; such pairs are replaced by singletons.

\Y\P\4\&{procedure}\1\  \37\\{copy\←limbo};\C{copy \TeX\ code until the next
module begins}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|c: \37\\{ASCII\←code};\C{character following \.{@} sign}\2\6
\&{begin} \37\~ \1\&{loop}\6
\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
\&{begin} \37\\{finish\←line};\5
\\{get\←line};\6
\&{if} $\\{input\←has\←ended}$ \1\&{then}\5
\&{return};\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{buffer}[\\{limit}+1]\K\.{"@"}$;\5
\X134:Copy up to control code, \&{return} if finished\X;\6
\&{end};\2\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M134. \P$\X134:Copy up to control code, \&{return} if finished\X\S$\6
\&{while} $\\{buffer}[\\{loc}]\I\.{"@"}$ \1\&{do}\6
\&{begin} \37$\\{out}(\\{buffer}[\\{loc}])$;\5
$\\{incr}(\\{loc})$;\6
\&{end};\2\6
\&{if} $\\{loc}\L\\{limit}$ \1\&{then}\6
\&{begin} \37$\\{loc}\K\\{loc}+2$;\5
$\|c\K\\{buffer}[\\{loc}-1]$;\6
\&{if} $(\|c=\.{"\ "})\V(\|c=\\{tab\←mark})\V(\|c=\.{"*"})$ \1\&{then}\5
\&{return};\2\6
\&{if} $(\|c\I\.{"z"})\W(\|c\I\.{"Z"})$ \1\&{then}\6
\&{begin} \37$\\{out}(\.{"@"})$;\6
\&{if} $\|c\I\.{"@"}$ \1\&{then}\5
$\\{err\←print}(\.{\'!\ Double\ @\ required\ outside\ of\ sections\'})$;\2\6
\&{end};\2\6
\&{end}\2\par
\U section~133.\fi

\M135. The \\{copy\←TeX} routine processes the \TeX\ code at the beginning of a
module; for example, the words you are now reading were copied in this
way. It returns the next control code or `\v' found in the input.

\Y\P\4\&{function}\1\  \37\\{copy\←TeX}: \37\\{eight\←bits};\C{copy pure \TeX\
material}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|c: \37\\{eight\←bits};\C{control code found}\2\6
\&{begin} \37\~ \1\&{loop}\6
\&{begin} \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
\&{begin} \37\\{finish\←line};\5
\\{get\←line};\6
\&{if} $\\{input\←has\←ended}$ \1\&{then}\6
\&{begin} \37$\|c\K\\{new\←module}$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{end};\2\6
$\\{buffer}[\\{limit}+1]\K\.{"@"}$;\5
\X136:Copy up to `\v' or control code, \&{goto} \\{done} if finished\X;\6
\&{end};\2\6
\4\\{done}: \37$\\{copy\←TeX}\K\|c$;\6
\&{end};\par
\fi

\M136. We don't copy spaces or tab marks into the beginning of a line. This
makes the test for empty lines in \\{finish\←line} work.

\Y\P$\4\X136:Copy up to `\v' or control code, \&{goto} \\{done} if finished\X%
\S$\6
\1\&{repeat} \37$\|c\K\\{buffer}[\\{loc}]$;\5
$\\{incr}(\\{loc})$;\6
\&{if} $\|c=\.{"|"}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\|c\I\.{"@"}$ \1\&{then}\6
\&{begin} \37$\\{out}(\|c)$;\6
\&{if} $(\\{out\←ptr}=1)\W((\|c=\.{"\ "})\V(\|c=\\{tab\←mark}))$ \1\&{then}\5
$\\{decr}(\\{out\←ptr})$;\2\6
\&{end};\2\6
\4\&{until}\5
$\|c=\.{"@"}$;\2\6
\&{if} $\\{loc}\L\\{limit}$ \1\&{then}\6
\&{begin} \37$\|c\K\\{control\←code}(\\{buffer}[\\{loc}])$;\5
$\\{incr}(\\{loc})$;\5
\&{goto} \37\\{done};\6
\&{end}\2\par
\U section~135.\fi

\M137. The \\{copy\←comment} uses and returns a brace-balance value, following
the
conventions of \\{skip\←comment} above. Instead of copying the \TeX\ material
into the output buffer, this procedure copies it into the token memory.
The abbreviation $\\{app\←tok}(\|t)$ is used to append token \|t to the current
token list, and it also makes sure that it is possible to append at least
one further token without overflow.

\Y\P\D \37$\\{app\←tok}(\#)\S$\1\6
\&{begin} \37\&{if} $\\{tok\←ptr}+2>\\{max\←toks}$ \1\&{then}\5
$\\{overflow}(\.{\'token\'})$;\2\6
$\\{tok\←mem}[\\{tok\←ptr}]\K\#$;\5
$\\{incr}(\\{tok\←ptr})$;\6
\&{end}\2\par
\Y\P\4\&{function}\1\  \37$\\{copy\←comment}(\\{bal}:\\{eight\←bits})$: \37%
\\{eight\←bits};\C{copies \TeX\ code in   comments}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|c: \37\\{ASCII\←code};\C{current character being copied}\2\6
\&{begin} \37\~ \1\&{loop}\6
\&{begin} \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\6
\&{begin} \37\\{get\←line};\6
\&{if} $\\{input\←has\←ended}$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ Input\ ended\ in\ mid-comment\'})$;\5
$\\{loc}\K1$;\5
\X139:Clear \\{bal} and \&{goto} \\{done}\X;\6
\&{end};\2\6
\&{end};\2\6
$\|c\K\\{buffer}[\\{loc}]$;\5
$\\{incr}(\\{loc})$;\6
\&{if} $\|c=\.{"|"}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{app\←tok}(\|c)$;\5
\X138:Copy special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"\}"}$; %
\&{goto} \\{done} at end\X;\6
\&{end};\2\6
\4\\{done}: \37$\\{copy\←comment}\K\\{bal}$;\6
\&{end};\par
\fi

\M138. \P$\X138:Copy special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"%
\}"}$; \&{goto} \\{done} at end\X\S$\6
\&{if} $\|c=\.{"@"}$ \1\&{then}\6
\&{begin} \37$\\{incr}(\\{loc})$;\6
\&{if} $\\{buffer}[\\{loc}-1]\I\.{"@"}$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ Illegal\ use\ of\ @\ in\ comment\'})$;\5
$\\{loc}\K\\{loc}-2$;\5
$\\{decr}(\\{tok\←ptr})$;\5
\X139:Clear \\{bal} and \&{goto} \\{done}\X;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $(\|c=\.{"\\"})\W(\\{buffer}[\\{loc}]\I\.{"@"})$ \1\&{then}\6
\&{begin} \37$\\{app\←tok}(\\{buffer}[\\{loc}])$;\5
$\\{incr}(\\{loc})$;\6
\&{end}\6
\4\&{else} \&{if} $\|c=\.{"\{"}$ \1\&{then}\5
$\\{incr}(\\{bal})$\6
\4\&{else} \&{if} $\|c=\.{"\}"}$ \1\&{then}\6
\&{begin} \37$\\{decr}(\\{bal})$;\6
\&{if} $\\{bal}=0$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{end}\2\2\2\2\par
\U section~137.\fi

\M139. When the comment has terminated abruptly due to an error, we output
enough right braces to keep \TeX\ happy.

\Y\P$\4\X139:Clear \\{bal} and \&{goto} \\{done}\X\S$\6
$\\{app\←tok}(\.{"\ "})$;\C{this is done in case the previous character was `\.%
\\'}\6
\1\&{repeat} \37$\\{app\←tok}(\.{"\}"})$;\5
$\\{decr}(\\{bal})$;\6
\4\&{until}\5
$\\{bal}=0$;\2\6
\&{goto} \37\\{done};\par
\U sections~137 and~138.\fi

\N140.  Parsing.
The most intricate part of \.{WEAVE} is its mechanism for converting
\PASCAL-like code into \TeX\ code, and we might as well plunge into this
aspect of the program now. A ``bottom up'' approach is used to parse the
\PASCAL-like material, since \.{WEAVE} must deal with fragmentary
constructions whose overall ``part of speech'' is not known.

At the lowest level, the input is represented as a sequence of entities
that we shall call {\it scraps}, where each scrap of information consists
of two parts, its {\it category} and its {\it translation}. The category
is essentially a syntactic class, and the translation is a token list that
represents \TeX\ code. Rules of syntax and semantics tell us how to
combine adjacent scraps into larger ones, and if we are lucky an entire
\PASCAL\ text that starts out as hundreds of small scraps will join
together into one gigantic scrap whose translation is the desired \TeX\
code. If we are unlucky, we will be left with several scraps that don't
combine; their translations will simply be output, one by one.

The combination rules are given as context-sensitive productions that are
applied from left to right. Suppose that we are currently working on the
sequence of scraps $s←1\,s←2\ldots s←n$. We try first to find the longest
production that applies to an initial substring $s←1\,s←2\ldots\,$; but if
no such productions exist, we find to find the longest production
applicable to the next substring $s←2\,s←3\ldots\,$; and if that fails, we
try to match $s←3\,s←4\ldots\,$, etc.

A production applies if the category codes have a given pattern. For
example, one of the productions is
$$\\{open}\;\\{math}\;\\{semi}\;\RA\;\\{open}\;\\{math}$$
and it means that three consecutive scraps whose respective categories are
\\{open}, \\{math}, and \\{semi} are con\-verted to two scraps whose categories
are \\{open} and \\{math}. This production also has an associated rule that
tells how to combine the translation parts:
$$\eqalign{O←2&=O←1\cr
M←2&=M←1\,S\,\.{\\,}\,\hbox{\\{opt}\thinspace\tt5}\cr}$$
This means that the \\{open} scrap has not changed, while the new \\{math}
scrap
has a translation $M←2$ composed of the translation $M←1$ of the original
\\{math} scrap followed by the translation \|S of the \\{semi} scrap followed
by `\.{\\,}' followed by `\\{opt}' followed by `\.5'. (In the \TeX\ file,
this will specify an additional thin space after the semicolon, followed
by an optional line break with penalty 50.) Translation rules use subscripts
to distinguish between translations of scraps whose categories have the
same initial letter; these subscripts are assigned from left to right.

$\.{WEAVE}$ also has the production rule
$$\\{semi}\;\RA\;\\{terminator}$$
(meaning that a semicolon can terminate a \PASCAL\ statement). Since
productions are applied from left to right, this rule will be activated
only if the \\{semi} is not preceded by scraps that match other productions;
in particular, a \\{semi} that is preceded by `\\{open} \\{math}' will have
disappeared because of the production above, and such semicolons do not
act as statement terminators.  This incidentally is how \.{WEAVE} is able
to treat semicolons in two distinctly different ways, the first of which
is intended for semicolons in the parameter list of a procedure
declaration.

The translation rule corresponding to $\\{semi}\;\RA\;\\{terminator}$ is
$$T=S$$
but we shall not mention translation rules in the common case that the
translation of the new scrap on the right-hand side is simply the
concatenation of the disappearing scraps on the left-hand side.

\fi

\M141. Here is a list of the category codes that scraps can have.

\Y\P\D \37$\\{simp}=1$\C{the translation can be used both in horizontal mode
and in math mode of \TeX}\par
\P\D \37$\\{math}=2$\C{the translation should be used only in \TeX\ math mode}%
\par
\P\D \37$\\{intro}=3$\C{a statement is expected to follow this, after a space
and   an optional break}\par
\P\D \37$\\{open}=4$\C{denotes an incomplete parenthesized quantity to be used
in   math mode}\par
\P\D \37$\\{beginning}=5$\C{denotes an incomplete compound statement to be used
in   horizontal mode}\par
\P\D \37$\\{close}=6$\C{ends a parenthesis or compound statement}\par
\P\D \37$\\{alpha}=7$\C{denotes the beginning of a clause}\par
\P\D \37$\\{omega}=8$\C{denotes the ending of a clause and possible comment
following}\par
\P\D \37$\\{semi}=9$\C{denotes a semicolon and possible comment following it}%
\par
\P\D \37$\\{terminator}=10$\C{something that ends a statement or declaration}%
\par
\P\D \37$\\{stmt}=11$\C{denotes a statement or declaration including its
terminator}\par
\P\D \37$\\{cond}=12$\C{precedes an \&{if} clause that might have a matching %
\&{else}}\par
\P\D \37$\\{clause}=13$\C{precedes a statement after which indentation ends}\par
\P\D \37$\\{colon}=14$\C{denotes a colon}\par
\P\D \37$\\{exp}=15$\C{stands for the E in a floating point constant}\par
\P\D \37$\\{proc}=16$\C{denotes a procedure or program or function heading}\par
\P\D \37$\\{case\←head}=17$\C{denotes a case statement or record heading}\par
\P\D \37$\\{record\←head}=18$\C{denotes a record heading without indentation}%
\par
\P\D \37$\\{var\←head}=19$\C{denotes a variable declaration heading}\par
\P\D \37$\\{elsie}=20$\C{\&{else}}\par
\P\D \37$\\{casey}=21$\C{\&{case}}\par
\P\D \37$\\{mod\←scrap}=22$\C{denotes a module name}\par
\Y\P\&{debug} \37\&{procedure}\1\  \37$\\{print\←cat}(\|c:\\{eight\←bits})$;%
\C{symbolic printout of a category}\2\6
\&{begin} \37\&{case} $\|c$ \1\&{of}\6
\4\\{simp}: \37$\\{print}(\.{\'simp\'})$;\6
\4\\{math}: \37$\\{print}(\.{\'math\'})$;\6
\4\\{intro}: \37$\\{print}(\.{\'intro\'})$;\6
\4\\{open}: \37$\\{print}(\.{\'open\'})$;\6
\4\\{beginning}: \37$\\{print}(\.{\'beginning\'})$;\6
\4\\{close}: \37$\\{print}(\.{\'close\'})$;\6
\4\\{alpha}: \37$\\{print}(\.{\'alpha\'})$;\6
\4\\{omega}: \37$\\{print}(\.{\'omega\'})$;\6
\4\\{semi}: \37$\\{print}(\.{\'semi\'})$;\6
\4\\{terminator}: \37$\\{print}(\.{\'terminator\'})$;\6
\4\\{stmt}: \37$\\{print}(\.{\'stmt\'})$;\6
\4\\{cond}: \37$\\{print}(\.{\'cond\'})$;\6
\4\\{clause}: \37$\\{print}(\.{\'clause\'})$;\6
\4\\{colon}: \37$\\{print}(\.{\'colon\'})$;\6
\4\\{exp}: \37$\\{print}(\.{\'exp\'})$;\6
\4\\{proc}: \37$\\{print}(\.{\'proc\'})$;\6
\4\\{case\←head}: \37$\\{print}(\.{\'casehead\'})$;\6
\4\\{record\←head}: \37$\\{print}(\.{\'recordhead\'})$;\6
\4\\{var\←head}: \37$\\{print}(\.{\'varhead\'})$;\6
\4\\{elsie}: \37$\\{print}(\.{\'elsie\'})$;\6
\4\\{casey}: \37$\\{print}(\.{\'casey\'})$;\6
\4\\{mod\←scrap}: \37$\\{print}(\.{\'module\'})$;\6
\4\&{othercases} \37$\\{print}(\.{\'UNKNOWN\'})$\2\6
\&{endcases};\6
\&{end};\6
\&{gubed}\par
\fi

\M142. The token lists for translated \TeX\ output contain some special control
symbols as well as ordinary characters. These control symbols are
interpreted by \.{WEAVE} before they are written to the output file.

\yskip\hang \\{break\←space} denotes an optional line break or an en space;

\yskip\hang \\{force} denotes a line break;

\yskip\hang \\{big\←force} denotes a line break with additional vertical space;

\yskip\hang \\{opt} denotes an optional line break (with the continuation
line indented two ems with respect to the normal starting position)---this
code is followed by an integer \|n, and the break will occur with penalty
$10n$;

\yskip\hang \\{backup} denotes a backspace of one em;

\yskip\hang \\{cancel} obliterates any \\{break\←space} or \\{force} or \\{big%
\←force}
tokens that immediately precede or follow it and also cancels any
\\{backup} tokens that follow it;

\yskip\hang \\{indent} causes future lines to be indented one more em;

\yskip\hang \\{outdent} causes future lines to be indented one less em.

\yskip\noindent All of these tokens are removed from the \TeX\ output that
comes from \PASCAL\ text between \pb\ signs; \\{break\←space} and \\{force} and
\\{big\←force} become single spaces in this mode. The translation of other
\PASCAL\ texts results in \TeX\ control sequences \.{\\1}, \.{\\2},
\.{\\3}, \.{\\4}, \.{\\5}, \.{\\6}, \.{\\7} corresponding respectively to
\\{indent}, \\{outdent}, \\{opt}, \\{backup}, \\{break\←space}, \\{force}, and
\\{big\←force}. However, a sequence of consecutive `\.\ ', \\{break\←space},
\\{force}, and/or \\{big\←force} tokens is first replaced by a single token
(the maximum of the given ones).

The tokens \\{math\←rel}, \\{math\←bin}, \\{math\←op} will be translated into
\.{\\mathrel\{}, \.{\\mathbin\{}, and \.{\\mathop\{}, respectively.
Other control sequences in the \TeX\ output will be `\.{\\\\\{}$\,\ldots\,$\.%
\}'
surrounding identifiers, `\.{\\\&\{}$\,\ldots\,$\.\}' surrounding
reserved words, `\.{\\.\{}$\,\ldots\,$\.\}' surrounding strings,
`\.{\\C\{}$\,\ldots\,$\.\}$\,$\\{force}' surrounding comments, and
`\.{\\X$n$:}$\,\ldots\,$\.{\\X}' surrounding module names, where
\|n is the module number.

\Y\P\D \37$\\{math\←bin}=\O{203}$\par
\P\D \37$\\{math\←rel}=\O{204}$\par
\P\D \37$\\{math\←op}=\O{205}$\par
\P\D \37$\\{big\←cancel}=\O{206}$\C{like \\{cancel}, also overrides spaces}\par
\P\D \37$\\{cancel}=\O{207}$\C{overrides \\{backup}, \\{break\←space}, %
\\{force}, \\{big\←force}}\par
\P\D \37$\\{indent}=\\{cancel}+1$\C{one more tab (\.{\\1})}\par
\P\D \37$\\{outdent}=\\{cancel}+2$\C{one less tab (\.{\\2})}\par
\P\D \37$\\{opt}=\\{cancel}+3$\C{optional break in mid-statement (\.{\\3})}\par
\P\D \37$\\{backup}=\\{cancel}+4$\C{stick out one unit to the left (\.{\\4})}%
\par
\P\D \37$\\{break\←space}=\\{cancel}+5$\C{optional break between statements (%
\.{\\5})}\par
\P\D \37$\\{force}=\\{cancel}+6$\C{forced break between statements (\.{\\6})}%
\par
\P\D \37$\\{big\←force}=\\{cancel}+7$\C{forced break with additional space (\.{%
\\7})}\par
\P\D \37$\\{end\←translation}=\\{big\←force}+1$\C{special sentinel token at end
of list}\par
\fi

\M143. The raw input is converted into scraps according to the following table,
which gives category codes followed by the translations. Sometimes a single
item of input produces more than one scrap.
\def\stars {\.{**}}%
(The symbol `\stars' stands for `\.{\\\&\{{\rm identifier}\}}',
i.e., the identifier itself treated as a reserved word. In a few cases the
category is given as `\\{comment}'; this is not an actual category code, it
means that the translation will be treated as a comment, as explained
below.)

\yskip\halign{\quad#\hfil&\quad#\hfil\cr
\.{<>}& \\{math}: \.{\\I}\cr
\.{<=}& \\{math}: \.{\\L}\cr
\.{>=}& \\{math}: \.{\\G}\cr
\.{:=}& \\{math}: \.{\\K}\cr
\.{==}& \\{math}: \.{\\S}\cr
\.{(*}& \\{math}: \.{\\B}\cr
\.{*)}& \\{math}: \.{\\T}\cr
\.{(.}& \\{open}: \.[\cr
\.{.)}& \\{close}: \.]\cr
\."$\,$string$\,$\."& \\{simp}: \.{\\.\{"{\rm$\,$modified string$\,$}"\}}\cr
\.\'$\,$string$\,$\.\'& \\{simp}: \.{\\.\{\\\'{\rm$\,$modified
string$\,$}\\\'\}}\cr
\.{@=}$\,$string$\,$\.{@>}& \\{simp}: \.{\\=\{{\rm$\,$modified string$\,$}\}}%
\cr
\#& \\{math}: \.{\\\#}\cr
\.\$& \\{math}: \.{\\\$}\cr
\.\←& \\{math}: \.{\\\←}\cr
\.\%& \\{math}: \.{\\\%}\cr
\.\↑& \\{math}: \.{\\\↑}\cr
\.(& \\{open}: \.(\cr
\.)& \\{close}: \.)\cr
\.[& \\{open}: \.[\cr
\.]& \\{close}: \.]\cr
\.*& \\{math}: \.{\\ast}\cr
\.,& \\{math}: \.,$\,\\{opt}\,$\.9\cr
\.{..}& \\{math}: \.{\\to}\cr
\..& \\{simp}: \..\cr
\.:& \\{colon}: \.:\cr
\.;& \\{semi}: \.;\cr
identifier& \\{simp}: \.{\\\\\{{\rm$\,$identifier$\,$}\}}\cr
\.E in constant& \\{exp}: \.{\\E\{}\cr
digit $d$& \\{simp}: $d$\cr
other character $c$& \\{math}: $c$\cr
\.{and}& \\{math}: \.{\\W}\cr
\.{array}& \\{alpha}: \stars\cr
\.{begin}& \\{beginning}: $\\{force}\,\stars\,\\{cancel}$\qquad \\{intro}: \cr
\.{case}& \\{casey}: \qquad \\{alpha}: $\\{force}\,\stars$\cr
\.{const}& \\{intro}: $\\{force}\,\\{backup}\,\stars$\cr
\.{div}& \\{math}: $\\{math\←bin}\,\stars\,\.\}$\cr
\.{do}& \\{omega}: \stars\cr
\.{downto}& \\{math}: $\\{math\←rel}\,\stars\,\.\}$\cr
\.{else}& \\{terminator}: \qquad \\{elsie}: $\\{force}\,\\{backup}\,\stars$\cr
\.{end}& \\{terminator}: \qquad \\{close}: $\\{force}\,\stars$\cr
\.{file}& \\{alpha}: \stars\cr
\.{for}& \\{alpha}: $\\{force}\,\stars$\cr
\.{function}& \\{proc}: $\\{force}\,\\{backup}\,\stars\,\\{cancel}$\qquad
 \\{intro}: $\\{indent}\,\.{\\\ }$\cr
\.{goto}& \\{intro}: \stars\cr
\.{if}& \\{cond}: \qquad \\{alpha}: $\\{force}\,\stars$\cr
\.{in}& \\{math}: \.{\\in}\cr
\.{label}& \\{intro}: $\\{force}\,\\{backup}\,\stars$\cr
\.{mod}& \\{math}: $\\{math\←bin}\,\stars\,\.\}$\cr
\.{nil}& \\{simp}: \stars\cr
\.{not}& \\{math}: \.{\\R}\cr
\.{of}& \\{omega}: \stars\cr
\.{or}& \\{math}: \.{\\V}\cr
\.{packed}& \\{intro}: \stars\cr
\.{procedure}& \\{proc}: $\\{force}\,\\{backup}\,\stars\,\\{cancel}$\qquad
 \\{intro}: $\\{indent}\,\.{\\\ }$\cr
\.{program}& \\{proc}: $\\{force}\,\\{backup}\,\stars\,\\{cancel}$\qquad
 \\{intro}: $\\{indent}\,\.{\\\ }$\cr
\.{record}& \\{record\←head}: \stars\qquad \\{intro}: \cr
\.{repeat}& \\{beginning}: $\\{force}\,\\{indent}\,\stars\,\\{cancel}$\qquad %
\\{intro}: \cr
\.{set}& \\{alpha}: \stars\cr
\.{then}& \\{omega}: \stars\cr
\.{to}& \\{math}: $\\{math\←rel}\,\stars\,\.\}$\cr
\.{type}& \\{intro}: $\\{force}\,\\{backup}\,\stars$\cr
\.{until}& \\{terminator}: \qquad \\{close}: $\\{force}\,\\{backup}\,\stars$%
\qquad
 \\{clause}: \cr
\.{var}& \\{var\←head}: $\\{force}\,\\{backup}\,\stars\,\\{cancel}$\qquad %
\\{intro}: \cr
\.{while}& \\{alpha}: $\\{force}\,\stars$\cr
\.{with}& \\{alpha}: $\\{force}\,\stars$\cr
\.{xclause}& \\{alpha}: $\\{force}\,\.{\\\~}$\qquad \\{omega}: \stars\cr
\.{@\'}$\,$const& \\{simp}: \.{\\O\{}\hbox{const}\.\}\cr
\.{@"}$\,$const& \\{simp}: \.{\\H\{}\hbox{const}\.\}\cr
\.{@\$}& \\{simp}: \.{\\)}\cr
\.{@\\}& \\{simp}: \.{\\]}\cr
\.{@,}& \\{math}: \.{\\,}\cr
\.{@t}$\,$stuff$\,$\.{@>}& \\{simp}: \.{\\hbox\{{\rm$\,$stuff$\,$}\}}\cr
\.{@<}$\,$module$\,$\.{@>}& \\{mod\←scrap}: \.{\\X$n$:{\rm$\,$module$\,$}\\X}%
\cr
\.{@\#}& \\{comment}: \\{big\←force}\cr
\.{@/}& \\{comment}: \\{force}\cr
\.{@\char'174}& \\{simp}: $\\{opt}\,\.0$\cr
\.{@+}& \\{comment}: $\\{big\←cancel}\,\.{\\\ }\,\\{big\←cancel}$\cr
\.{@;}& \\{semi}: \cr
\.{@\&}& \\{math}: \.{\\J}\cr
\.{@\{}& \\{math}: \.{\\B}\cr
\.{@\}}& \\{math}: \.{\\T}\cr}
\yskip\noindent When a string is output, certain characters are preceded by
`\.\\' signs so that they will print properly.

A comment in the input will be combined with the preceding
\\{omega} or \\{semi} scrap, or with the following \\{terminator} scrap, if
possible; otherwise it will be inserted as a separate \\{terminator} scrap.
An additional ``comment'' is effectively appended at the end of the
\PASCAL\ text, just before translation begins; this consists of a \\{cancel}
token in the case of \PASCAL\ text in \pb, otherwise it consists of a
\\{force} token.

From this table it is evident that \.{WEAVE} will parse a lot of non-\PASCAL\
programs. For example, the reserved words `\.{for}' and `\.{array}' are
treated in an identical way by \.{WEAVE} from a syntactic standpoint,
and semantically they are equivalent except that a forced line break occurs
just before `\&{for}'; \PASCAL\ programmers may well be surprised at this
similarity. The idea is to keep \.{WEAVE}'s rules as simple as possible,
consistent with doing a reasonable job on syntactically correct \PASCAL\
programs. The production rules below have been formulated in the same
spirit of ``almost anything goes.''

\fi

\M144. Here is a table of all the productions. The reader can best get a feel
for
how they work by trying them out by hand on small examples; no amount of
explanation will be as effective as watching the rules in action.
Parsing can also be watched by debugging with `\.{@2}'.

\def\[#1]{\quad$\dleft#1\dright$}
\def\sp{\.{\ }}
\yskip
\halign to\the\hsize{\hfil\it# &
#\hfil\hskip-200pt\tabskip 0pt plus 100pt&
#\hfil\tabskip0pt\cr
&Production categories\[\hbox{translations}]&Remarks\cr
\noalign{\yskip}
1&$\\{alpha}\,\\{math}\,\\{colon}$ $\RA$ $\\{alpha}\,\\{math}$&e.g.,  \&{case}
$\|v:\\{boolean}$ \&{of}\cr
2&$\\{alpha}\,\\{math}\,\\{omega}$ $\RA$ \\{clause}\[C=A\,\sp\,\.\$\,M\,\.\$\,%
\sp\,\\{indent}\,
O]&e.g.,  \&{while} $\|x>0$ \&{do}\cr
3&$\\{alpha}\,\\{omega}$ $\RA$ \\{clause}\[C=A\,\sp\,\\{indent}\,O]&e.g., %
\&{file} \&{of}\cr
4&$\\{alpha}\,\\{simp}$ $\RA$ $\\{alpha}\,\\{math}$&convert to math mode\cr
5&$\\{beginning}\,\\{close}\,(\\{terminator}\hbox{ or }\\{stmt})$ $\RA$ %
\\{stmt}&compound statement
ends\cr
6&$\\{beginning}\,\\{stmt}$ $\RA$ \\{beginning}\[B←2=B←1\,\\{break\←space}%
\,S]&compound
statement grows\cr
7&$\\{case\←head}\,\\{casey}\,\\{clause}$ $\RA$ \\{case\←head}\[C←4=C←1\,%
\\{outdent}\,C←2\,C←3]&
variant records\cr
8&$\\{case\←head}\,\\{close}\,\\{terminator}$ $\RA$ \\{stmt}\[S=C←1\,\\{cancel}%
\,\\{outdent}\,
C←2\,T]&end of case statement\cr
9&$\\{case\←head}\,\\{stmt}$ $\RA$ \\{case\←head}\[C←2=C←1\,\\{force}\,S]&case
statement
grows\cr
10&$\\{casey}\,\\{clause}$ $\RA$ \\{case\←head}&beginning of case statement\cr
11&$\\{clause}\,\\{stmt}$ $\RA$ \\{stmt}\[S←2=C\,\\{break\←space}\,S←1\,%
\\{cancel}\,\\{outdent}\,
\\{force}]&end of controlled statement\cr
12&$\\{cond}\,\\{clause}\,\\{stmt}\,\\{elsie}$ $\RA$ \\{clause}\[C←3=C←1\,C←2\,%
\\{break\←space}\,S\,
E\,\sp\,\\{cancel}]&complete conditional\cr
13&$\\{cond}\,\\{clause}\,\\{stmt}$ $\RA$ \\{stmt}\cr
&\qquad\[S←2=C←1\,C←2\,\\{break\←space}\,S←1\,
\\{cancel}\,\\{outdent}\,\\{force}]&incomplete conditional\cr
14&\\{elsie} $\RA$ \\{intro}&unmatched else\cr
15&$\\{exp}\,\\{math}\,\\{simp}$ $\RA$ \\{math}\[M←2=E\,M←1\,S\,\.\}]&signed
exponent\cr
16&$\\{exp}\,\\{simp}$ $\RA$ \\{math}\[M=E\,S\,\.\}]&unsigned exponent\cr
17&$\\{intro}\,\\{stmt}$ $\RA$ \\{stmt}\[S←2=I\,\sp\,\\{opt}\,\.7\,\\{cancel}%
\,S←1]&labeled
statement, etc.\cr
18&$\\{math}\,\\{close}$ $\RA$ $\\{stmt}\,\\{close}$\[S=\.\$\,M\,\.\$]&end of
field list\cr
19&$\\{math}\,\\{colon}$ $\RA$ \\{intro}\[I=\\{force}\,\\{backup}\,\.\$\,M\,\.%
\$\,C]&compound
label\cr
20&$\\{math}\,\\{math}$ $\RA$ \\{math}&simple concatenation\cr
21&$\\{math}\,\\{simp}$ $\RA$ \\{math}&simple concatenation\cr
22&$\\{math}\,\\{stmt}$ $\RA$ \\{stmt}\cr
&\qquad\[S←2=\.\$\,M\,\.\$\,\\{indent}\,\\{break\←space}\,
S←1\,\\{cancel}\,\\{outdent}\,\\{force}]&macro or type definition\cr
23&$\\{math}\,\\{terminator}$ $\RA$ \\{stmt}\[S=\.\$\,M\,\.\$\,T]&statement
involving
math\cr
24&$\\{mod\←scrap}\,(\\{terminator}\hbox{ or }\\{semi})$ $\RA$ \\{stmt}\[S=M\,T%
\,\\{force}]&module
like a statement\cr
25&\\{mod\←scrap} $\RA$ \\{simp}&module unlike a statement\cr
26&$\\{open}\,\\{case\←head}\,\\{close}$ $\RA$ \\{math}\[M=O\,\.\$\,\\{cancel}%
\,C←1\,
\\{cancel}\,\\{outdent}\,\.\$\,C←2]&case in field list\cr
27&$\\{open}\,\\{close}$ $\RA$ \\{math}\[M=O\,\.\\\,\.,\,C]&empty set $[\,]$\cr
28&$\\{open}\,\\{math}\,\\{case\←head}\,\\{close}$ $\RA$ \\{math}\cr
&\qquad\[M←2=O\,M←1\,\.\$\,\\{cancel}\,
C←1\,\\{cancel}\,\\{outdent}\,\.\$\,C←2]&case in field list\cr
29&$\\{open}\,\\{math}\,\\{close}$ $\RA$ \\{math}&parenthesized group\cr
30&$\\{open}\,\\{math}\,\\{colon}$ $\RA$ $\\{open}\,\\{math}$&colon in
parentheses\cr
31&$\\{open}\,\\{math}\,\\{proc}\,\\{intro}$ $\RA$ $\\{open}\,\\{math}$%
\[M←2=M←1\,\\{math\←op}\,\\{cancel}\,
P\,\.\}]& \&{procedure}\   in parentheses\cr
32&$\\{open}\,\\{math}\,\\{semi}$ $\RA$ $\\{open}\,\\{math}$\[M←2=M←1\,S\,\.%
\\\,\.,\,\\{opt}\,
\.5]&semicolon in parentheses\cr
33&$\\{open}\,\\{math}\,\\{var\←head}\,\\{intro}$ $\RA$ $\\{open}\,\\{math}$%
\[M←2=M←1\,\\{math\←op}\,
\\{cancel}\,V\,\.\}]& \&{var}  in parentheses\cr
34&$\\{open}\,\\{proc}\,\\{intro}$ $\RA$ $\\{open}\,\\{math}$\[M=\\{math\←op}\,%
\\{cancel}\,
P\,\.\}]& \&{procedure}\   in parentheses\cr
35&$\\{open}\,\\{simp}$ $\RA$ $\\{open}\,\\{math}$&convert to math mode\cr
36&$\\{open}\,\\{stmt}\,\\{close}$ $\RA$ \\{math}\[M=O\,\.\$\,\\{cancel}\,S\,%
\\{cancel}\,
\.\$\,C]&field list\cr
37&$\\{open}\,\\{var\←head}\,\\{intro}$ $\RA$ $\\{open}\,\\{math}$\[M=\\{math%
\←op}\,\\{cancel}\,V\,
\.\}]& \&{var}  in parentheses\cr
38&$\\{proc}\,\\{beginning}\,\\{close}\,\\{terminator}$ $\RA$ \\{stmt}\[S=P\,%
\\{cancel}\,
\\{outdent}\,B\,C\,T]&end of procedure declaration\cr
39&$\\{proc}\,\\{stmt}$ $\RA$ \\{proc}\[P←2=P←1\,\\{break\←space}\,S]&procedure
declaration
grows\cr
40&$\\{record\←head}\,\\{intro}\,\\{casey}$ $\RA$ \\{casey}\[C←2=R\,I\,\sp\,%
\\{cancel}\,C←1]&
\&{record case} $\ldots$\cr
41&\\{record\←head} $\RA$ \\{case\←head}\[C=\\{indent}\,R\,\\{cancel}]&other %
\&{record}
structures\cr
42&\\{semi} $\RA$ \\{terminator}&semicolon after statement\cr
43&$\\{simp}\,\\{close}$ $\RA$ $\\{stmt}\,\\{close}$&end of field list\cr
44&$\\{simp}\,\\{colon}$ $\RA$ \\{intro}\[I=\\{force}\,\\{backup}\,S\,C]&simple
label\cr
45&$\\{simp}\,\\{math}$ $\RA$ \\{math}&simple concatenation\cr
46&$\\{simp}\,\\{mod\←scrap}$ $\RA$ \\{mod\←scrap}&in emergencies\cr
47&$\\{simp}\,\\{simp}$ $\RA$ \\{simp}&simple concatenation\cr
48&$\\{simp}\,\\{terminator}$ $\RA$ \\{stmt}&simple statement\cr
49&$\\{stmt}\,\\{stmt}$ $\RA$ \\{stmt}\[S←3=S←1\,\\{break\←space}%
\,S←2]&adjacent
statements\cr
50&\\{terminator} $\RA$ \\{stmt}&empty statement\cr
51&$\\{var\←head}\,\\{beginning}$ $\RA$ $\\{stmt}\,\\{beginning}$&end of
variable
declarations\cr
52&$\\{var\←head}\,\\{math}\,\\{colon}$ $\RA$ $\\{var\←head}\,\\{intro}$\[I=\.%
\$\,M\,\.\$\,C]&
variable declaration\cr
53&$\\{var\←head}\,\\{simp}\,\\{colon}$ $\RA$ $\\{var\←head}\,%
\\{intro}$&variable declaration\cr
54&$\\{var\←head}\,\\{stmt}$ $\RA$ \\{var\←head}\[V←2=V←1\,\\{break\←space}%
\,S]&variable
declarations grow\cr}
\yskip\noindent
Translations are not specified here when they are simple concatenations
of the scraps that change. For example, the full translation of
`$\\{open}\,\\{math}\,\\{colon}$ $\RA$ $\\{open}\,\\{math}$' is $O←2=O←1$,
$M←2=M←1C$.

\fi

\N145.  Implementing the productions.
When \PASCAL\ text is to be processed with the grammar above, we put its
initial scraps $s←1\ldots s←n$ into two arrays $\\{cat}[1\to\|n]$ and $%
\\{trans}[1\to\|n]$.
The value of $\\{cat}[\|k]$ is simply a category code from the list above; the
value of $\\{trans}[\|k]$ is a text pointer, i.e., an index into \\{tok%
\←start}.
Our production rules have the nice property that the right-hand side is never
longer than the left-hand side. Therefore it is convenient to use sequential
allocation for the current sequence of scraps. Five pointers are used to
manage the parsing:

\yskip\hang \\{pp} (the parsing pointer) is such that we are trying to match
the category codes $\\{cat}[\\{pp}]\,\\{cat}[\\{pp}+1]$$\,\ldots\,$ to the
left-hand sides
of productions.

\yskip\hang \\{scrap\←base}, \\{lo\←ptr}, \\{hi\←ptr}, and \\{scrap\←ptr} are
such that
the current sequence of scraps appears in positions \\{scrap\←base} through
\\{lo\←ptr} and \\{hi\←ptr} through \\{scrap\←ptr}, inclusive, in the \\{cat}
and
\\{trans} arrays. Scraps located between \\{scrap\←base} and \\{lo\←ptr} have
been examined, while those in positions $\G\\{hi\←ptr}$ have not yet been
looked at by the parsing process.

\yskip\noindent Initially \\{scrap\←ptr} is set to the position of the final
scrap to be parsed, and it doesn't change its value. The parsing process
makes sure that $\\{lo\←ptr}\G\\{pp}+3$, since productions have as many as four
terms,
by moving scraps from \\{hi\←ptr} to \\{lo\←ptr}. If there are
fewer than $\\{pp}+3$ scraps left, the positions up to $\\{pp}+3$ are filled
with
blanks that will not match in any productions. Parsing stops when
$\\{pp}=\\{lo\←ptr}+1$ and $\\{hi\←ptr}=\\{scrap\←ptr}+1$.

The \\{trans} array elements are declared to be of type $0\to10239$ instead
of type \\{text\←pointer}, because the final sorting phase of \.{WEAVE}
uses this array to contain elements of type \\{name\←pointer}. Both
of these types are subranges of $0\to10239$.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cat}: \37\&{array} $[0\to\\{max\←scraps}]$ \1\&{of}\5
\\{eight\←bits};\C{category codes of scraps}\2\6
\4\\{trans}: \37\&{array} $[0\to\\{max\←scraps}]$ \1\&{of}\5
$0\to10239$;\C{translation texts of scraps}\2\6
\4\\{pp}: \37$0\to\\{max\←scraps}$;\C{current position for reducing
productions}\6
\4\\{scrap\←base}: \37$0\to\\{max\←scraps}$;\C{beginning of the current scrap
sequence}\6
\4\\{scrap\←ptr}: \37$0\to\\{max\←scraps}$;\C{ending of the current scrap
sequence}\6
\4\\{lo\←ptr}: \37$0\to\\{max\←scraps}$;\C{last scrap that has been examined}\6
\4\\{hi\←ptr}: \37$0\to\\{max\←scraps}$;\C{first scrap that has not been
examined}\6
\&{stat} \37\\{max\←scr\←ptr}: \37$0\to\\{max\←scraps}$;\C{largest value
assumed by \\{scrap\←ptr}}\6
\&{tats}\par
\fi

\M146. \P$\X10:Set initial values\X\mathrel{+}\S$\6
$\\{scrap\←base}\K1$;\5
$\\{scrap\←ptr}\K0$;\6
\&{stat} \37$\\{max\←scr\←ptr}\K0$;\ \&{tats}\par
\fi

\M147. Token lists in \\{tok\←mem} are composed of the following kinds of
items for \TeX\ output.

\yskip\item{$\bullet$}ASCII codes and special codes like \\{force} and
\\{math\←rel} represent themselves;

\item{$\bullet$}$\\{id\←flag}+\|p$ represents \.{\\\\\{{\rm identifier $p$}\}};

\item{$\bullet$}$\\{res\←flag}+\|p$ represents \.{\\\&\{{\rm identifier $p$}%
\}};

\item{$\bullet$}$\\{mod\←flag}+\|p$ represents module name \|p;

\item{$\bullet$}$\\{tok\←flag}+\|p$ represents token list number \|p;

\item{$\bullet$}$\\{inner\←tok\←flag}+\|p$ represents token list number \|p, to
be
translated without line-break controls.

\Y\P\D \37$\\{id\←flag}=10240$\C{signifies an identifier}\par
\P\D \37$\\{res\←flag}=\\{id\←flag}+\\{id\←flag}$\C{signifies a reserved word}%
\par
\P\D \37$\\{mod\←flag}=\\{res\←flag}+\\{id\←flag}$\C{signifies a module name}%
\par
\P\D \37$\\{tok\←flag}\S\\{mod\←flag}+\\{id\←flag}$\C{signifies a token list}%
\par
\P\D \37$\\{inner\←tok\←flag}\S\\{tok\←flag}+\\{id\←flag}$\C{signifies a token
list in `\pb'}\Y\par
\P\D \37$\\{lbrace}\S\\{xchr}[\.{"\{"}]$\C{this avoids possible \PASCAL\
compiler confusion}\par
\P\D \37$\\{rbrace}\S\\{xchr}[\.{"\}"}]$\C{because these braces might occur
within comments}\par
\Y\P\&{debug} \37\&{procedure}\1\  \37$\\{print\←text}(\|p:\\{text\←pointer})$;%
\C{prints a token list}\6
\4\&{var} \37\|j: \37$0\to\\{max\←toks}$;\C{index into \\{tok\←mem}}\6
\|r: \37$0\to\\{id\←flag}-1$;\C{remainder of token after the flag has been
stripped off}\2\6
\&{begin} \37\&{if} $\|p\G\\{text\←ptr}$ \1\&{then}\5
$\\{print}(\.{\'BAD\'})$\6
\4\&{else} \&{for} $\|j\K\\{tok\←start}[\|p]\mathrel{\&{to}}\\{tok\←start}[%
\|p+1]-1$ \1\&{do}\6
\&{begin} \37$\|r\K\\{tok\←mem}[\|j]\mathbin{\&{mod}}\\{id\←flag}$;\6
\&{case} $\\{tok\←mem}[\|j]\mathbin{\&{div}}\\{id\←flag}$ \1\&{of}\6
\41: \37\&{begin} \37$\\{print}(\.{\'\\\\\'},\39\\{lbrace})$;\5
$\\{print\←id}(\|r)$;\5
$\\{print}(\\{rbrace})$;\6
\&{end};\C{\\{id\←flag}}\6
\42: \37\&{begin} \37$\\{print}(\.{\'\\\&\'},\39\\{lbrace})$;\5
$\\{print\←id}(\|r)$;\5
$\\{print}(\\{rbrace})$;\6
\&{end};\C{\\{res\←flag}}\6
\43: \37\&{begin} \37$\\{print}(\.{\'<\'})$;\5
$\\{print\←id}(\|r)$;\5
$\\{print}(\.{\'>\'})$;\6
\&{end};\C{\\{mod\←flag}}\6
\44: \37$\\{print}(\.{\'[[\'},\39\|r:1,\39\.{\']]\'})$;\C{\\{tok\←flag}}\6
\45: \37$\\{print}(\.{\'|[[\'},\39\|r:1,\39\.{\']]|\'})$;\C{\\{inner\←tok%
\←flag}}\6
\4\&{othercases} \37\X148:Print token \|r in symbolic form\X\2\6
\&{endcases};\6
\&{end};\2\2\6
\&{end};\6
\&{gubed}\par
\fi

\M148. \P$\X148:Print token \|r in symbolic form\X\S$\6
\&{case} $\|r$ \1\&{of}\6
\4\\{math\←bin}: \37$\\{print}(\.{\'\\mathbin\'},\39\\{lbrace})$;\6
\4\\{math\←rel}: \37$\\{print}(\.{\'\\mathrel\'},\39\\{lbrace})$;\6
\4\\{math\←op}: \37$\\{print}(\.{\'\\mathop\'},\39\\{lbrace})$;\6
\4\\{big\←cancel}: \37$\\{print}(\.{\'[ccancel]\'})$;\6
\4\\{cancel}: \37$\\{print}(\.{\'[cancel]\'})$;\6
\4\\{indent}: \37$\\{print}(\.{\'[indent]\'})$;\6
\4\\{outdent}: \37$\\{print}(\.{\'[outdent]\'})$;\6
\4\\{backup}: \37$\\{print}(\.{\'[backup]\'})$;\6
\4\\{opt}: \37$\\{print}(\.{\'[opt]\'})$;\6
\4\\{break\←space}: \37$\\{print}(\.{\'[break]\'})$;\6
\4\\{force}: \37$\\{print}(\.{\'[force]\'})$;\6
\4\\{big\←force}: \37$\\{print}(\.{\'[fforce]\'})$;\6
\4\\{end\←translation}: \37$\\{print}(\.{\'[quit]\'})$;\6
\4\&{othercases} \37$\\{print}(\\{xchr}[\|r])$\2\6
\&{endcases}\par
\U section~147.\fi

\M149. The production rules listed above are embedded directly into the %
\.{WEAVE}
program, since it is easier to do this than to write an interpretive system
that would handle production systems in general. Several macros are defined
here so that the program for each production is fairly short.

All of our productions conform to the general notion that some \|k
consecutive scraps starting at some position \|j are to be replaced by a
single scrap of some category \|c whose translations is composed from the
translations of the disappearing scraps. After this production has been
applied, the production pointer \\{pp} should change by an amount \|d. Such
a production can be represented by the quadruple $(j,k,c,d)$. For example,
the production `$\\{simp}\,\\{math}$ $\RA$ \\{math}' would be represented by
`$(\\{pp},2,\\{math},-1)$'; in this case the pointer $pp$ should decrease by 1
after the production has been applied, because some productions with
\\{math} in their second positions might now match, but no productions have
\\{math} in the third or fourth position of their left-hand sides. Note that
the value of \|d is determined by the whole collection of productions, not
by an individual one. Consider the further example
`$\\{var\←head}\,\\{math}\,\\{colon}$ $\RA$ $\\{var\←head}\,\\{intro}$', which
is represented by
`$(\\{pp}+1,2,\\{intro},+1)$'; the $+1$ here is deduced by looking at the
grammar and seeing that no matches could possibly occur at positions $\L\\{pp}$
after this production has been applied. The determination of \|d has been
done by hand in each case, based on the full set of productions but not on
the grammar of \PASCAL\ or on the rules for constructing the initial
scraps.

We also attach a serial number of each production, so that additional
information is available when debugging. For example, the program below
contains the statement `$\\{reduce}(\\{pp}+1,2,\\{intro},+1)(52)$' when it
implements
the production just mentioned.

Before calling \\{reduce}, the program should have appended the tokens of
the new translation to the \\{tok\←mem} array. We commonly want to append
copies of several existing translations, and macros are defined to
simplify these common cases. For example, $\\{app2}(\\{pp})$ will append the
translations of two consecutive scraps, $\\{trans}[\\{pp}]$ and $\\{trans}[%
\\{pp}+1]$, to
the current token list. If the entire new translation is formed in this
way, we write `$\\{squash}(j,k,c,d)$' instead of `$\\{reduce}(j,k,c,d)$'. For
example, `$\\{squash}(\\{pp},2,\\{math},-1)$' is an abbreviation for `$%
\\{app2}(\\{pp})$; $\\{reduce}(\\{pp},2,\\{math},-1)$'.

The code below is an exact translation of the production rules into
\PASCAL, using such macros, and the reader should have no difficulty
understanding the format by comparing the code with the symbolic
productions as they were listed earlier.

{\sl Caution:\/} The macros \\{app}, \\{app1}, \\{app2}, and \\{app3} are
sequences of statements that are not enclosed with  \&{begin}  and $  \&{end}
$,
because such delimiters would make the \PASCAL\ program much longer. This
means that it is necessary to write  \&{begin}  and   \&{end}  explicitly when
such
a macro is used as a single statement. Several mysterious bugs in the
original programming of \.{WEAVE} were caused by a failure to remember
this fact.  Next time the author will know better.

\Y\P\D \37$\\{production}(\#)\S$\1\6
\&{debug} \37$\\{prod}(\#)$\6
\&{gubed};\2\6
\&{goto} \37\\{found}\par
\P\D \37$\\{reduce}(\#)\S\\{red}(\#)$;\5
\\{production}\par
\P\D \37$\\{production\←end}(\#)\S$\1\6
\&{debug} \37$\\{prod}(\#)$\6
\&{gubed};\2\6
\&{goto} \37\\{found}; \6
\&{end} \par
\P\D $\\{squash}(\#)\S$ \6
\&{begin} \37$\\{sq}(\#)$;\5
\\{production\←end}\par
\P\D \37$\\{app}(\#)\S\\{tok\←mem}[\\{tok\←ptr}]\K\#$;\5
$\\{incr}(\\{tok\←ptr})$\C{this is like \\{app\←tok},   but it doesn't test for
overflow}\par
\P\D \37$\\{app1}(\#)\S\\{tok\←mem}[\\{tok\←ptr}]\K\\{tok\←flag}+\\{trans}[%
\#]$;\5
$\\{incr}(\\{tok\←ptr})$\par
\P\D \37$\\{app2}(\#)\S\\{app1}(\#)$;\5
$\\{app1}(\#+1)$\par
\P\D \37$\\{app3}(\#)\S\\{app2}(\#)$;\5
$\\{app1}(\#+2)$\par
\fi

\M150. Let us consider the big case statement for productions now, before
looking
at its context. We want to design the program so that this case statement
works, so we might as well not keep ourselves in suspense about exactly what
code needs to be provided with a proper environment.

The code here is more complicated than it need be, since some popular
\PASCAL\ compilers are unable to deal with procedures that contain a lot
of program text. The \\{translate} procedure, which incorporates the   \&{case}
statement here, would become too long for those compilers if we did
not do something to split the cases into parts. Therefore
a separate procedure called \\{five\←cases} has been introduced.
This auxiliary procedure contains approximately half of the program text
that \\{translate} would otherwise have had. There's also a procedure
called \\{alpha\←cases}, which turned out to be necessary because the best
two-way split wasn't good enough. The procedure could be split further
in an analogous manner, but the present scheme works on all compilers
known to the author.

\Y\P$\4\X150:Match a production at \\{pp}, or increase \\{pp} if there is no
match\X\S$\6
\&{if} $\\{cat}[\\{pp}]\L\\{alpha}$ \1\&{then}\6
\&{if} $\\{cat}[\\{pp}]<\\{alpha}$ \1\&{then}\5
\\{five\←cases}\ \&{else} \\{alpha\←cases}\2\6
\4\&{else} \&{begin} \37\&{case} $\\{cat}[\\{pp}]$ \1\&{of}\6
\4\\{case\←head}: \37\X154:Cases for \\{case\←head}\X;\6
\4\\{casey}: \37\X155:Cases for \\{casey}\X;\6
\4\\{clause}: \37\X156:Cases for \\{clause}\X;\6
\4\\{cond}: \37\X157:Cases for \\{cond}\X;\6
\4\\{elsie}: \37\X158:Cases for \\{elsie}\X;\6
\4\\{exp}: \37\X159:Cases for \\{exp}\X;\6
\4\\{mod\←scrap}: \37\X162:Cases for \\{mod\←scrap}\X;\6
\4\\{proc}: \37\X165:Cases for \\{proc}\X;\6
\4\\{record\←head}: \37\X166:Cases for \\{record\←head}\X;\6
\4\\{semi}: \37\X167:Cases for \\{semi}\X;\6
\4\\{stmt}: \37\X169:Cases for \\{stmt}\X;\6
\4\\{terminator}: \37\X170:Cases for \\{terminator}\X;\6
\4\\{var\←head}: \37\X171:Cases for \\{var\←head}\X;\6
\4\&{othercases} \37\\{do\←nothing}\2\6
\&{endcases};\6
$\\{incr}(\\{pp})$;\C{if no match was found, we move to the right}\6
\4\\{found}: \37\&{end}\2\par
\U section~176.\fi

\M151. Here are the procedures that need to be present for the reason just
explained.

\Y\P$\4\X151:Declaration of subprocedures for \\{translate}\X\S$\6
\4\&{procedure}\1\  \37\\{five\←cases};\C{handles almost half of the syntax}\6
\4\&{label} \37\\{found};\2\6
\&{begin} \37\&{case} $\\{cat}[\\{pp}]$ \1\&{of}\6
\4\\{beginning}: \37\X153:Cases for \\{beginning}\X;\6
\4\\{intro}: \37\X160:Cases for \\{intro}\X;\6
\4\\{math}: \37\X161:Cases for \\{math}\X;\6
\4\\{open}: \37\X163:Cases for \\{open}\X;\6
\4\\{simp}: \37\X168:Cases for \\{simp}\X;\6
\4\&{othercases} \37\\{do\←nothing}\2\6
\&{endcases};\6
$\\{incr}(\\{pp})$;\C{if no match was found, we move to the right}\6
\4\\{found}: \37\&{end};\7
\4\&{procedure}\1\  \37\\{alpha\←cases};\6
\4\&{label} \37\\{found};\2\6
\&{begin} \37\X152:Cases for \\{alpha}\X;\6
$\\{incr}(\\{pp})$;\C{if no match was found, we move to the right}\6
\4\\{found}: \37\&{end};\par
\U section~180\*.\fi

\M152. Now comes the code that tries to match each production that starts
with a particular type of scrap. Whenever a match is discovered,
the \\{squash} or \\{reduce} macro will cause the appropriate action
to be performed, followed by \&{goto} \\{found}.

\Y\P$\4\X152:Cases for \\{alpha}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{colon}$ \1\&{then}\5
$\\{squash}(\\{pp}+1,\392,\39\\{math},\390)(1)$\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{omega}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\.{"\ "})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app}(\.{"\ "})$;\5
$\\{app}(\\{indent})$;\5
$\\{app1}(\\{pp}+2)$;\5
$\\{reduce}(\\{pp},\393,\39\\{clause},\39-2)(2)$;\6
\&{end};\2\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{omega}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\.{"\ "})$;\5
$\\{app}(\\{indent})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\392,\39\\{clause},\39-2)(3)$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\5
$\\{squash}(\\{pp}+1,\391,\39\\{math},\390)(4)$\2\2\2\par
\U section~151.\fi

\M153. \P$\X153:Cases for \\{beginning}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{close}$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{cat}[\\{pp}+2]=\\{terminator})\V(\\{cat}[\\{pp}+2]=%
\\{stmt})$ \1\&{then}\5
$\\{squash}(\\{pp},\393,\39\\{stmt},\39-2)(5)$;\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\\{break\←space})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\392,\39\\{beginning},\39-1)(6)$;\6
\&{end}\2\2\par
\U section~151.\fi

\M154. \P$\X154:Cases for \\{case\←head}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{casey}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{clause}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\\{outdent})$;\5
$\\{app2}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\393,\39\\{case\←head},\390)(7)$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{close}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{terminator}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\\{cancel})$;\5
$\\{app}(\\{outdent})$;\5
$\\{app2}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\393,\39\\{stmt},\39-2)(8)$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\\{force})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\392,\39\\{case\←head},\390)(9)$;\6
\&{end}\2\2\2\par
\U section~150.\fi

\M155. \P$\X155:Cases for \\{casey}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{clause}$ \1\&{then}\5
$\\{squash}(\\{pp},\392,\39\\{case\←head},\390)(10)$\2\par
\U section~150.\fi

\M156. \P$\X156:Cases for \\{clause}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\\{break\←space})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{app}(\\{cancel})$;\5
$\\{app}(\\{outdent})$;\5
$\\{app}(\\{force})$;\5
$\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(11)$;\6
\&{end}\2\par
\U section~150.\fi

\M157. \P$\X157:Cases for \\{cond}\X\S$\6
\&{if} $(\\{cat}[\\{pp}+1]=\\{clause})\W(\\{cat}[\\{pp}+2]=\\{stmt})$ \1%
\&{then}\6
\&{if} $\\{cat}[\\{pp}+3]=\\{elsie}$ \1\&{then}\6
\&{begin} \37$\\{app2}(\\{pp})$;\5
$\\{app}(\\{break\←space})$;\5
$\\{app2}(\\{pp}+2)$;\5
$\\{app}(\.{"\ "})$;\5
$\\{app}(\\{cancel})$;\5
$\\{reduce}(\\{pp},\394,\39\\{clause},\39-2)(12)$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{app2}(\\{pp})$;\5
$\\{app}(\\{break\←space})$;\5
$\\{app1}(\\{pp}+2)$;\5
$\\{app}(\\{cancel})$;\5
$\\{app}(\\{outdent})$;\5
$\\{app}(\\{force})$;\5
$\\{reduce}(\\{pp},\393,\39\\{stmt},\39-2)(13)$;\6
\&{end}\2\2\par
\U section~150.\fi

\M158. \P$\X158:Cases for \\{elsie}\X\S$\6
$\\{squash}(\\{pp},\391,\39\\{intro},\39-3)(14)$\par
\U section~150.\fi

\M159. \P$\X159:Cases for \\{exp}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{simp}$ \1\&{then}\6
\&{begin} \37$\\{app3}(\\{pp})$;\5
$\\{app}(\.{"\}"})$;\5
$\\{reduce}(\\{pp},\393,\39\\{math},\39-1)(15)$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\6
\&{begin} \37$\\{app2}(\\{pp})$;\5
$\\{app}(\.{"\}"})$;\5
$\\{reduce}(\\{pp},\392,\39\\{math},\39-1)(16)$;\6
\&{end}\2\2\par
\U section~150.\fi

\M160. \P$\X160:Cases for \\{intro}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\.{"\ "})$;\5
$\\{app}(\\{opt})$;\5
$\\{app}(\.{"7"})$;\5
$\\{app}(\\{cancel})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(17)$;\6
\&{end}\2\par
\U section~151.\fi

\M161. \P$\X161:Cases for \\{math}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{close}$ \1\&{then}\6
\&{begin} \37$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{reduce}(\\{pp},\391,\39\\{stmt},\39-2)(18)$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{colon}$ \1\&{then}\6
\&{begin} \37$\\{app}(\\{force})$;\5
$\\{app}(\\{backup})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\392,\39\\{intro},\39-3)(19)$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\5
$\\{squash}(\\{pp},\392,\39\\{math},\39-1)(20)$\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\5
$\\{squash}(\\{pp},\392,\39\\{math},\39-1)(21)$\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
\&{begin} \37$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app}(\\{indent})$;\5
$\\{app}(\\{break\←space})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{app}(\\{cancel})$;\5
$\\{app}(\\{outdent})$;\5
$\\{app}(\\{force})$;\5
$\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(22)$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{terminator}$ \1\&{then}\6
\&{begin} \37$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(23)$;\6
\&{end}\2\2\2\2\2\2\par
\U section~151.\fi

\M162. \P$\X162:Cases for \\{mod\←scrap}\X\S$\6
\&{if} $(\\{cat}[\\{pp}+1]=\\{terminator})\V(\\{cat}[\\{pp}+1]=\\{semi})$ \1%
\&{then}\6
\&{begin} \37$\\{app2}(\\{pp})$;\5
$\\{app}(\\{force})$;\5
$\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(24)$;\6
\&{end}\6
\4\&{else} $\\{squash}(\\{pp},\391,\39\\{simp},\39-2)(25)$\2\par
\U section~150.\fi

\M163. \P$\X163:Cases for \\{open}\X\S$\6
\&{if} $(\\{cat}[\\{pp}+1]=\\{case\←head})\W(\\{cat}[\\{pp}+2]=\\{close})$ \1%
\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app}(\\{cancel})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{app}(\\{cancel})$;\5
$\\{app}(\\{outdent})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp}+2)$;\5
$\\{reduce}(\\{pp},\393,\39\\{math},\39-1)(26)$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{close}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\.{"\\"})$;\5
$\\{app}(\.{","})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\392,\39\\{math},\39-1)(27)$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\5
\X164:Cases for $\\{open}\,\\{math}$\X\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{proc}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{intro}$ \1\&{then}\6
\&{begin} \37$\\{app}(\\{math\←op})$;\5
$\\{app}(\\{cancel})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{app}(\.{"\}"})$;\5
$\\{reduce}(\\{pp}+1,\392,\39\\{math},\390)(34)$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\5
$\\{squash}(\\{pp}+1,\391,\39\\{math},\390)(35)$\6
\4\&{else} \&{if} $(\\{cat}[\\{pp}+1]=\\{stmt})\W(\\{cat}[\\{pp}+2]=\\{close})$
\1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app}(\\{cancel})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{app}(\\{cancel})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp}+2)$;\5
$\\{reduce}(\\{pp},\393,\39\\{math},\39-1)(36)$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{var\←head}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{intro}$ \1\&{then}\6
\&{begin} \37$\\{app}(\\{math\←op})$;\5
$\\{app}(\\{cancel})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{app}(\.{"\}"})$;\5
$\\{reduce}(\\{pp}+1,\392,\39\\{math},\390)(37)$;\6
\&{end};\2\6
\&{end}\2\2\2\2\2\2\2\par
\U section~151.\fi

\M164. \P$\X164:Cases for $\\{open}\,\\{math}$\X\S$\6
\&{begin} \37\&{if} $(\\{cat}[\\{pp}+2]=\\{case\←head})\W(\\{cat}[\\{pp}+3]=%
\\{close})$ \1\&{then}\6
\&{begin} \37$\\{app2}(\\{pp})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app}(\\{cancel})$;\5
$\\{app1}(\\{pp}+2)$;\5
$\\{app}(\\{cancel})$;\5
$\\{app}(\\{outdent})$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp}+3)$;\5
$\\{reduce}(\\{pp},\394,\39\\{math},\39-1)(28)$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{close}$ \1\&{then}\5
$\\{squash}(\\{pp},\393,\39\\{math},\39-1)(29)$\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{colon}$ \1\&{then}\5
$\\{squash}(\\{pp}+1,\392,\39\\{math},\390)(30)$\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{proc}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cat}[\\{pp}+3]=\\{intro}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp}+1)$;\5
$\\{app}(\\{math\←op})$;\5
$\\{app}(\\{cancel})$;\5
$\\{app1}(\\{pp}+2)$;\5
$\\{app}(\.{"\}"})$;\5
$\\{reduce}(\\{pp}+1,\393,\39\\{math},\390)(31)$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{semi}$ \1\&{then}\6
\&{begin} \37$\\{app2}(\\{pp}+1)$;\5
$\\{app}(\.{"\\"})$;\5
$\\{app}(\.{","})$;\5
$\\{app}(\\{opt})$;\5
$\\{app}(\.{"5"})$;\5
$\\{reduce}(\\{pp}+1,\392,\39\\{math},\390)(32)$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+2]=\\{var\←head}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cat}[\\{pp}+3]=\\{intro}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp}+1)$;\5
$\\{app}(\\{math\←op})$;\5
$\\{app}(\\{cancel})$;\5
$\\{app1}(\\{pp}+2)$;\5
$\\{app}(\.{"\}"})$;\5
$\\{reduce}(\\{pp}+1,\393,\39\\{math},\390)(31)$;\6
\&{end};\2\6
\&{end};\2\2\2\2\2\2\6
\&{end}\par
\U section~163.\fi

\M165. \P$\X165:Cases for \\{proc}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{beginning}$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{cat}[\\{pp}+2]=\\{close})\W(\\{cat}[\\{pp}+3]=%
\\{terminator})$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\\{cancel})$;\5
$\\{app}(\\{outdent})$;\5
$\\{app3}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\394,\39\\{stmt},\39-2)(38)$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\\{break\←space})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\392,\39\\{proc},\39-2)(39)$;\6
\&{end}\2\2\par
\U section~150.\fi

\M166. \P$\X166:Cases for \\{record\←head}\X\S$\6
\&{if} $(\\{cat}[\\{pp}+1]=\\{intro})\W(\\{cat}[\\{pp}+2]=\\{casey})$ \1%
\&{then}\6
\&{begin} \37$\\{app2}(\\{pp})$;\5
$\\{app}(\.{"\ "})$;\5
$\\{app}(\\{cancel})$;\5
$\\{app1}(\\{pp}+2)$;\5
$\\{reduce}(\\{pp},\393,\39\\{casey},\39-2)(40)$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{app}(\\{indent})$;\5
$\\{app1}(\\{pp})$;\5
$\\{app}(\\{cancel})$;\5
$\\{reduce}(\\{pp},\391,\39\\{case\←head},\390)(41)$;\6
\&{end}\2\par
\U section~150.\fi

\M167. \P$\X167:Cases for \\{semi}\X\S$\6
$\\{squash}(\\{pp},\391,\39\\{terminator},\39-3)(42)$\par
\U section~150.\fi

\M168. \P$\X168:Cases for \\{simp}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{close}$ \1\&{then}\5
$\\{squash}(\\{pp},\391,\39\\{stmt},\39-2)(43)$\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{colon}$ \1\&{then}\6
\&{begin} \37$\\{app}(\\{force})$;\5
$\\{app}(\\{backup})$;\5
$\\{app2}(\\{pp})$;\5
$\\{reduce}(\\{pp},\392,\39\\{intro},\39-3)(44)$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\5
$\\{squash}(\\{pp},\392,\39\\{math},\39-1)(45)$\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{mod\←scrap}$ \1\&{then}\5
$\\{squash}(\\{pp},\392,\39\\{mod\←scrap},\390)(46)$\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\5
$\\{squash}(\\{pp},\392,\39\\{simp},\39-2)(47)$\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{terminator}$ \1\&{then}\5
$\\{squash}(\\{pp},\392,\39\\{stmt},\39-2)(48)$\2\2\2\2\2\2\par
\U section~151.\fi

\M169. \P$\X169:Cases for \\{stmt}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\\{break\←space})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\392,\39\\{stmt},\39-2)(49)$;\6
\&{end}\2\par
\U section~150.\fi

\M170. \P$\X170:Cases for \\{terminator}\X\S$\6
$\\{squash}(\\{pp},\391,\39\\{stmt},\39-2)(50)$\par
\U section~150.\fi

\M171. \P$\X171:Cases for \\{var\←head}\X\S$\6
\&{if} $\\{cat}[\\{pp}+1]=\\{beginning}$ \1\&{then}\5
$\\{squash}(\\{pp},\391,\39\\{stmt},\39-2)(51)$\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{math}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{colon}$ \1\&{then}\6
\&{begin} \37$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{app}(\.{"\$"})$;\5
$\\{app1}(\\{pp}+2)$;\5
$\\{reduce}(\\{pp}+1,\392,\39\\{intro},\39+1)(52)$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{simp}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cat}[\\{pp}+2]=\\{colon}$ \1\&{then}\5
$\\{squash}(\\{pp}+1,\392,\39\\{intro},\39+1)(53)$;\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cat}[\\{pp}+1]=\\{stmt}$ \1\&{then}\6
\&{begin} \37$\\{app1}(\\{pp})$;\5
$\\{app}(\\{break\←space})$;\5
$\\{app1}(\\{pp}+1)$;\5
$\\{reduce}(\\{pp},\392,\39\\{var\←head},\39-2)(54)$;\6
\&{end}\2\2\2\2\par
\U section~150.\fi

\M172. The `\\{freeze\←text}' macro is used to give official status to a token
list.
Before saying \\{freeze\←text}, items are appended to the current token list,
and we know that the eventual number of this token list will be the current
value of \\{text\←ptr}. But no list of that number really exists as yet,
because no ending point for the current list has been
stored in the \\{tok\←start} array. After saying \\{freeze\←text}, the
old current token list becomes legitimate, and its number is the current
value of $\\{text\←ptr}-1$ since \\{text\←ptr} has been increased. The new
current token list is empty and ready to be appended to.
Note that \\{freeze\←text} does not check to see that \\{text\←ptr} hasn't
gotten
too large, since it is assumed that this test was done beforehand.

\Y\P\D \37$\\{freeze\←text}\S\\{incr}(\\{text\←ptr})$;\5
$\\{tok\←start}[\\{text\←ptr}]\K\\{tok\←ptr}$\par
\fi

\M173. The `\\{reduce}' macro used in our code for productions actually calls
on
a procedure named `\\{red}', which makes the appropriate changes to the
scrap list.

\Y\P\4\&{procedure}\1\  \37$\\{red}(\|j:\\{sixteen\←bits};\,\35\|k:\\{eight%
\←bits};\,\35\|c:\\{eight\←bits};\,\35\|d:\\{integer})$;\6
\4\&{var} \37\|i: \37$0\to\\{max\←scraps}$;\C{index into scrap memory}\2\6
\&{begin} \37$\\{cat}[\|j]\K\|c$;\5
$\\{trans}[\|j]\K\\{text\←ptr}$;\5
\\{freeze\←text};\6
\&{if} $\|k>1$ \1\&{then}\6
\&{begin} \37\&{for} $\|i\K\|j+\|k\mathrel{\&{to}}\\{lo\←ptr}$ \1\&{do}\6
\&{begin} \37$\\{cat}[\|i-\|k+1]\K\\{cat}[\|i]$;\5
$\\{trans}[\|i-\|k+1]\K\\{trans}[\|i]$;\6
\&{end};\2\6
$\\{lo\←ptr}\K\\{lo\←ptr}-\|k+1$;\6
\&{end};\2\6
\X174:Change \\{pp} to $\max(\\{scrap\←base},$\\{pp}+\|d$)$\X;\6
\&{end};\par
\fi

\M174. \P$\X174:Change \\{pp} to $\max(\\{scrap\←base},$\\{pp}+\|d$)$\X\S$\6
\&{if} $\\{pp}+\|d\G\\{scrap\←base}$ \1\&{then}\5
$\\{pp}\K\\{pp}+\|d$\6
\4\&{else} $\\{pp}\K\\{scrap\←base}$\2\par
\U sections~173 and~175.\fi

\M175. Similarly, the `\\{squash}' macro invokes a procedure called `\\{sq}'.
This
procedure takes advantage of the simplification that occurs when $\|k=1$.

\Y\P\4\&{procedure}\1\  \37$\\{sq}(\|j:\\{sixteen\←bits};\,\35\|k:\\{eight%
\←bits};\,\35\|c:\\{eight\←bits};\,\35\|d:\\{integer})$;\6
\4\&{var} \37\|i: \37$0\to\\{max\←scraps}$;\C{index into scrap memory}\2\6
\&{begin} \37\&{if} $\|k=1$ \1\&{then}\6
\&{begin} \37$\\{cat}[\|j]\K\|c$;\5
\X174:Change \\{pp} to $\max(\\{scrap\←base},$\\{pp}+\|d$)$\X;\6
\&{end}\6
\4\&{else} \&{begin} \37\&{for} $\|i\K\|j\mathrel{\&{to}}\|j+\|k-1$ \1\&{do}\6
\&{begin} \37$\\{app1}(\|i)$;\6
\&{end};\2\6
$\\{red}(\|j,\39\|k,\39\|c,\39\|d)$;\6
\&{end};\2\6
\&{end};\par
\fi

\M176. Here now is the code that applies productions as long as possible. It
requires two local labels (\\{found} and \\{done}), as well as a local
variable (\|i).

\Y\P$\4\X176:Reduce the scraps using the productions until no more rules apply%
\X\S$\6
\~ \1\&{loop}\ \&{begin} \37\X177:Make sure the entries $\\{cat}[\\{pp}\to(%
\\{pp}+3)]$ are defined\X;\6
\&{if} $(\\{tok\←ptr}+8>\\{max\←toks})\V(\\{text\←ptr}+4>\\{max\←texts})$ \1%
\&{then}\6
\&{begin} \37\&{stat} \37\&{if} $\\{tok\←ptr}>\\{max\←tok\←ptr}$ \1\&{then}\5
$\\{max\←tok\←ptr}\K\\{tok\←ptr}$;\2\6
\&{if} $\\{text\←ptr}>\\{max\←txt\←ptr}$ \1\&{then}\5
$\\{max\←txt\←ptr}\K\\{text\←ptr}$;\2\6
\&{tats}\6
$\\{overflow}(\.{\'token/text\'})$;\6
\&{end};\2\6
\&{if} $\\{pp}>\\{lo\←ptr}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\X150:Match a production at \\{pp}, or increase \\{pp} if there is no match\X;\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~180\*.\fi

\M177. If we get to the end of the scrap list, category codes equal to zero are
stored, since zero does not match anything in a production.

\Y\P$\4\X177:Make sure the entries $\\{cat}[\\{pp}\to(\\{pp}+3)]$ are defined\X%
\S$\6
\&{if} $\\{lo\←ptr}<\\{pp}+3$ \1\&{then}\6
\&{begin} \37\1\&{repeat} \37\&{if} $\\{hi\←ptr}\L\\{scrap\←ptr}$ \1\&{then}\6
\&{begin} \37$\\{incr}(\\{lo\←ptr})$;\6
$\\{cat}[\\{lo\←ptr}]\K\\{cat}[\\{hi\←ptr}]$;\5
$\\{trans}[\\{lo\←ptr}]\K\\{trans}[\\{hi\←ptr}]$;\6
$\\{incr}(\\{hi\←ptr})$;\6
\&{end};\2\6
\4\&{until}\5
$(\\{hi\←ptr}>\\{scrap\←ptr})\V(\\{lo\←ptr}=\\{pp}+3)$;\2\6
\&{for} $\|i\K\\{lo\←ptr}+1\mathrel{\&{to}}\\{pp}+3$ \1\&{do}\5
$\\{cat}[\|i]\K0$;\2\6
\&{end}\2\par
\U section~176.\fi

\M178. If \.{WEAVE} is being run in debugging mode, the production numbers and
current stack categories will be printed out when \\{tracing} is set to 2;
a sequence of two or more irreducible scraps will be printed out when
\\{tracing} is set to 1.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\&{debug} \37\\{tracing}: \37$0\to2$;\C{can be used to show parsing details}\6
\&{gubed}\par
\fi

\M179. The \\{prod} procedure is called in debugging mode just after \\{reduce}
or
\\{squash}; its parameter is the number of the production that has just
been applied.

\Y\P\&{debug} \37\&{procedure}\1\  \37$\\{prod}(\|n:\\{eight\←bits})$;\C{shows
current categories}\6
\4\&{var} \37\|k: \37$1\to\\{max\←scraps}$;\C{index into \\{cat}}\2\6
\&{begin} \37\&{if} $\\{tracing}=2$ \1\&{then}\6
\&{begin} \37$\\{print\←nl}(\|n:1,\39\.{\':\'})$;\6
\&{for} $\|k\K\\{scrap\←base}\mathrel{\&{to}}\\{lo\←ptr}$ \1\&{do}\6
\&{begin} \37\&{if} $\|k=\\{pp}$ \1\&{then}\5
$\\{print}(\.{\'*\'})$\ \&{else} $\\{print}(\.{\'\ \'})$;\2\6
$\\{print\←cat}(\\{cat}[\|k])$;\6
\&{end};\2\6
\&{if} $\\{hi\←ptr}\L\\{scrap\←ptr}$ \1\&{then}\5
$\\{print}(\.{\'...\'})$;\C{indicate that more is coming}\2\6
\&{end};\2\6
\&{end};\6
\&{gubed}\par
\fi

\M180\*. The \\{translate} function assumes that scraps have been stored in
positions \\{scrap\←base} through \\{scrap\←ptr} of \\{cat} and \\{trans}. It
appends a \\{terminator} scrap and begins to apply productions as much as
possible. The result is a token list containing the translation of
the given sequence of scraps.

After calling \\{translate}, we will have $\\{text\←ptr}+3\L\\{max\←texts}$ and
$\\{tok\←ptr}+6\L\\{max\←toks}$, so it will be possible to create up to three
token
lists with up to six tokens without checking for overflow. Before calling
\\{translate}, we should have $\\{text\←ptr}<\\{max\←texts}$ and $\\{scrap%
\←ptr}<\\{max\←scraps}$,
since \\{translate} might add a new text and a new scrap before it checks
for overflow.

\Y\P\X151:Declaration of subprocedures for \\{translate}\X\6
\4\&{function}\1\  \37\\{translate}: \37\\{text\←pointer};\C{converts a
sequence of scraps}\6
\4\&{label} \37$\\{done},\39\\{found}$;\6
\4\&{var} \37\|i: \37$1\to\\{max\←scraps}$;\C{index into \\{cat}}\6
\|j: \37$0\to\\{max\←scraps}$;\C{runs through final scraps}\2\6
\&{begin} \37$\\{pp}\K\\{scrap\←base}$;\5
$\\{lo\←ptr}\K\\{pp}-1$;\5
$\\{hi\←ptr}\K\\{pp}$;\5
\X183:If tracing, print an indication of where we are\X;\6
\X176:Reduce the scraps using the productions until no more rules apply\X;\6
\&{if} $(\\{lo\←ptr}=\\{scrap\←base})\W(\\{cat}[\\{lo\←ptr}]\I\\{math})$ \1%
\&{then}\5
$\\{translate}\K\\{trans}[\\{lo\←ptr}]$\6
\4\&{else} \X181:Combine the irreducible scraps that remain\X;\2\6
\&{end};\par
\fi

\M181. If the initial sequence of scraps does not reduce to a single scrap,
we concatenate the translations of all remaining scraps, separated by
blank spaces, with dollar signs surrounding the translations of \\{math}
scraps.

\Y\P$\4\X181:Combine the irreducible scraps that remain\X\S$\6
\&{begin} \37\X182:If semi-tracing, show the irreducible scraps\X;\6
\&{for} $\|j\K\\{scrap\←base}\mathrel{\&{to}}\\{lo\←ptr}$ \1\&{do}\6
\&{begin} \37\&{if} $\|j\I\\{scrap\←base}$ \1\&{then}\6
\&{begin} \37$\\{app}(\.{"\ "})$;\6
\&{end};\2\6
\&{if} $\\{cat}[\|j]=\\{math}$ \1\&{then}\6
\&{begin} \37$\\{app}(\.{"\$"})$;\6
\&{end};\2\6
$\\{app1}(\|j)$;\6
\&{if} $\\{cat}[\|j]=\\{math}$ \1\&{then}\6
\&{begin} \37$\\{app}(\.{"\$"})$;\6
\&{end};\2\6
\&{if} $\\{tok\←ptr}+6>\\{max\←toks}$ \1\&{then}\5
$\\{overflow}(\.{\'token\'})$;\2\6
\&{end};\2\6
\\{freeze\←text};\5
$\\{translate}\K\\{text\←ptr}-1$;\6
\&{end}\par
\U section~180\*.\fi

\M182. \P$\X182:If semi-tracing, show the irreducible scraps\X\S$\6
\&{debug} \37\&{if} $(\\{lo\←ptr}>\\{scrap\←base})\W(\\{tracing}=1)$ \1\&{then}%
\6
\&{begin} \37$\\{print\←nl}(\.{\'Irreducible\ scrap\ sequence\ in\ section\ %
\'},\39\\{module\←count}:1)$;\5
$\\{print\←ln}(\.{\':\'})$;\5
\\{mark\←harmless};\6
\&{for} $\|j\K\\{scrap\←base}\mathrel{\&{to}}\\{lo\←ptr}$ \1\&{do}\6
\&{begin} \37$\\{print}(\.{\'\ \'})$;\5
$\\{print\←cat}(\\{cat}[\|j])$;\6
\&{end};\2\6
\&{end};\2\6
\&{gubed}\par
\U section~181.\fi

\M183. \P$\X183:If tracing, print an indication of where we are\X\S$\6
\&{debug} \37\&{if} $\\{tracing}=2$ \1\&{then}\6
\&{begin} \37$\\{print\←nl}(\.{\'Tracing\ after\ l.\'},\39\\{line}:1,\39\.{\':%
\'})$;\5
\\{mark\←harmless};\6
\&{if} $\\{loc}>50$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{\'...\'})$;\6
\&{for} $\|k\K\\{loc}-50\mathrel{\&{to}}\\{loc}$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{buffer}[\|k-1]])$;\2\6
\&{end}\6
\4\&{else} \&{for} $\|k\K1\mathrel{\&{to}}\\{loc}$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{buffer}[\|k-1]])$;\2\2\6
\&{end}\2\6
\&{gubed}\par
\U section~180\*.\fi

\N184.  Initializing the scraps.
If we are going to use the powerful production mechanism just developed, we
must get the scraps set up in the first place, given a \PASCAL\ text. A table
of the initial scraps corresponding to \PASCAL\ tokens appeared above in the
section on parsing; our goal now is to implement that table. We shall do this
by implementing a subroutine called \\{PASCAL\←parse} that is analogous to the
\\{PASCAL\←xref} routine used during phase one.

Like \\{PASCAL\←xref}, the \\{PASCAL\←parse} procedure starts with the current
value of \\{next\←control} and it uses the operation $\\{next\←control}\K\\{get%
\←next}$
repeatedly to read \PASCAL\ text until encountering the next `\v' or
`\.\{', or until $\\{next\←control}\G\\{format}$. The scraps corresponding to
what
it reads are appended into the \\{cat} and \\{trans} arrays, and \\{scrap\←ptr}
is advanced.

Like \\{prod}, this procedure has to split into pieces so that each
part is short enough to be handled by \PASCAL\ compilers that discriminate
against long subroutines. This time there are two split-off routines,
called \\{easy\←cases} and \\{sub\←cases}.

After studying \\{PASCAL\←parse}, we will look at the sub-procedures
\\{app\←comment}, \\{app\←octal}, and \\{app\←hex} that are used in some of its
branches.

\Y\P\X196:Declaration of the \\{app\←comment} procedure\X\6
\X197:Declaration of the \\{app\←octal} and \\{app\←hex} procedures\X\6
\X187:Declaration of the \\{easy\←cases} procedure\X\6
\X193:Declaration of the \\{sub\←cases} procedure\X\6
\4\&{procedure}\1\  \37\\{PASCAL\←parse};\C{creates scraps from \PASCAL\
tokens}\6
\4\&{label} \37$\\{reswitch},\39\\{exit}$;\6
\4\&{var} \37\|j: \37$0\to\\{long\←buf\←size}$;\C{index into \\{buffer}}\6
\|p: \37\\{name\←pointer};\C{identifier designator}\2\6
\&{begin} \37\&{while} $\\{next\←control}<\\{format}$ \1\&{do}\6
\&{begin} \37\X186:Append the scrap appropriate to \\{next\←control}\X;\6
$\\{next\←control}\K\\{get\←next}$;\6
\&{if} $(\\{next\←control}=\.{"|"})\V(\\{next\←control}=\.{"\{"})$ \1\&{then}\5
\&{return};\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M185. The macros defined here are helpful abbreviations for the operations
needed when generating the scraps. A scrap of category \|c whose
translation has three tokens $t←1$, $t←2$, $t←3$ is generated by
\\{sc3}$(t←1)(t←2)(t←3)(c)$, etc.

\Y\P\D \37$\\{s0}(\#)\S\\{incr}(\\{scrap\←ptr})$;\5
$\\{cat}[\\{scrap\←ptr}]\K\#$;\5
$\\{trans}[\\{scrap\←ptr}]\K\\{text\←ptr}$;\5
\\{freeze\←text}; \6
\&{end} \par
\P\D \37$\\{s1}(\#)\S\\{app}(\#)$;\5
\\{s0}\par
\P\D \37$\\{s2}(\#)\S\\{app}(\#)$;\5
\\{s1}\par
\P\D \37$\\{s3}(\#)\S\\{app}(\#)$;\5
\\{s2}\par
\P\D \37$\\{s4}(\#)\S\\{app}(\#)$;\5
\\{s3}\par
\P\D \37$\\{sc4}\S$\ \&{begin} \37\\{s4}\par
\P\D \37$\\{sc3}\S$\ \&{begin} \37\\{s3}\par
\P\D \37$\\{sc2}\S$\ \&{begin} \37\\{s2}\par
\P\D \37$\\{sc1}\S$\ \&{begin} \37\\{s1}\par
\P\D \37$\\{sc0}(\#)\S$\1\6
\&{begin} \37$\\{incr}(\\{scrap\←ptr})$;\5
$\\{cat}[\\{scrap\←ptr}]\K\#$;\5
$\\{trans}[\\{scrap\←ptr}]\K0$;\6
\&{end}\2\par
\P\D \37$\\{comment\←scrap}(\#)\S$\1\6
\&{begin} \37$\\{app}(\#)$;\5
\\{app\←comment};\6
\&{end}\2\par
\fi

\M186. \P$\X186:Append the scrap appropriate to \\{next\←control}\X\S$\6
\X188:Make sure that there is room for at least four more scraps, six more
tokens, and four more texts\X;\6
\4\\{reswitch}: \37\&{case} $\\{next\←control}$ \1\&{of}\6
\4$\\{string},\39\\{verbatim}$: \37\X190:Append a \(string scrap\X;\6
\4\\{identifier}: \37\X192:Append an identifier scrap\X;\6
\4\\{TeX\←string}: \37\X191:Append a \TeX\ string scrap\X;\6
\4\&{othercases} \37\\{easy\←cases}\2\6
\&{endcases}\par
\U section~184.\fi

\M187. The \\{easy\←cases} each result in straightforward scraps.

\Y\P$\4\X187:Declaration of the \\{easy\←cases} procedure\X\S$\6
\4\&{procedure}\1\  \37\\{easy\←cases};\C{a subprocedure of \\{PASCAL\←parse}}%
\2\6
\&{begin} \37\&{case} $\\{next\←control}$ \1\&{of}\6
\4\\{set\←element\←sign}: \37$\\{sc3}(\.{"\\"})(\.{"i"})(\.{"n"})(\\{math})$;\6
\4\\{double\←dot}: \37$\\{sc3}(\.{"\\"})(\.{"t"})(\.{"o"})(\\{math})$;\6
\4$\.{"\#"},\39\.{"\$"},\39\.{"\%"},\39\.{"\↑"},\39\.{"\←"}$: \37$\\{sc2}(\.{"%
\\"})(\\{next\←control})(\\{math})$;\6
\4$\\{ignore},\39\.{"|"},\39\\{xref\←roman},\39\\{xref\←wildcard},\39\\{xref%
\←typewriter}$: \37\\{do\←nothing};\6
\4$\.{"("},\39\.{"["}$: \37$\\{sc1}(\\{next\←control})(\\{open})$;\6
\4$\.{")"},\39\.{"]"}$: \37$\\{sc1}(\\{next\←control})(\\{close})$;\6
\4\.{"*"}: \37$\\{sc4}(\.{"\\"})(\.{"a"})(\.{"s"})(\.{"t"})(\\{math})$;\6
\4\.{","}: \37$\\{sc3}(\.{","})(\\{opt})(\.{"9"})(\\{math})$;\6
\4$\.{"."},\39\.{"0"},\39\.{"1"},\39\.{"2"},\39\.{"3"},\39\.{"4"},\39\.{"5"},%
\39\.{"6"},\39\.{"7"},\39\.{"8"},\39\.{"9"}$: \37$\\{sc1}(\\{next\←control})(%
\\{simp})$;\6
\4\.{";"}: \37$\\{sc1}(\.{";"})(\\{semi})$;\6
\4\.{":"}: \37$\\{sc1}(\.{":"})(\\{colon})$;\6
\hbox{\4}\X189:Cases involving nonstandard ASCII characters\X\6
\4\\{exponent}: \37$\\{sc3}(\.{"\\"})(\.{"E"})(\.{"\{"})(\\{exp})$;\6
\4\\{begin\←comment}: \37$\\{sc2}(\.{"\\"})(\.{"B"})(\\{math})$;\6
\4\\{end\←comment}: \37$\\{sc2}(\.{"\\"})(\.{"T"})(\\{math})$;\6
\4\\{octal}: \37\\{app\←octal};\6
\4\\{hex}: \37\\{app\←hex};\6
\4\\{check\←sum}: \37$\\{sc2}(\.{"\\"})(\.{")"})(\\{simp})$;\6
\4\\{force\←line}: \37$\\{sc2}(\.{"\\"})(\.{"]"})(\\{simp})$;\6
\4\\{thin\←space}: \37$\\{sc2}(\.{"\\"})(\.{","})(\\{math})$;\6
\4\\{math\←break}: \37$\\{sc2}(\\{opt})(\.{"0"})(\\{simp})$;\6
\4\\{line\←break}: \37$\\{comment\←scrap}(\\{force})$;\6
\4\\{big\←line\←break}: \37$\\{comment\←scrap}(\\{big\←force})$;\6
\4\\{no\←line\←break}: \37\&{begin} \37$\\{app}(\\{big\←cancel})$;\5
$\\{app}(\.{"\\"})$;\5
$\\{app}(\.{"\ "})$;\5
$\\{comment\←scrap}(\\{big\←cancel})$;\6
\&{end};\6
\4\\{pseudo\←semi}: \37$\\{sc0}(\\{semi})$;\6
\4\\{join}: \37$\\{sc2}(\.{"\\"})(\.{"J"})(\\{math})$;\6
\4\&{othercases} \37$\\{sc1}(\\{next\←control})(\\{math})$\2\6
\&{endcases};\6
\&{end};\par
\U section~184.\fi

\M188. \P$\X188:Make sure that there is room for at least four more scraps, six
more tokens, and four more texts\X\S$\6
\&{if} $(\\{scrap\←ptr}+4>\\{max\←scraps})\V(\\{tok\←ptr}+6>\\{max\←toks})\V(%
\\{text\←ptr}+4>\\{max\←texts})$ \1\&{then}\6
\&{begin} \37\&{stat} \37\&{if} $\\{scrap\←ptr}>\\{max\←scr\←ptr}$ \1\&{then}\5
$\\{max\←scr\←ptr}\K\\{scrap\←ptr}$;\2\6
\&{if} $\\{tok\←ptr}>\\{max\←tok\←ptr}$ \1\&{then}\5
$\\{max\←tok\←ptr}\K\\{tok\←ptr}$;\2\6
\&{if} $\\{text\←ptr}>\\{max\←txt\←ptr}$ \1\&{then}\5
$\\{max\←txt\←ptr}\K\\{text\←ptr}$;\2\6
\&{tats}\6
$\\{overflow}(\.{\'scrap/token/text\'})$;\6
\&{end}\2\par
\U section~186.\fi

\M189. Some nonstandard ASCII characters may have entered \.{WEAVE} by means of
standard ones. They are converted to \TeX\ control sequences so that it is
possible to keep \.{WEAVE} from stepping beyond standard ASCII.

\Y\P$\4\X189:Cases involving nonstandard ASCII characters\X\S$\6
\4\\{not\←equal}: \37$\\{sc2}(\.{"\\"})(\.{"I"})(\\{math})$;\6
\4\\{less\←or\←equal}: \37$\\{sc2}(\.{"\\"})(\.{"L"})(\\{math})$;\6
\4\\{greater\←or\←equal}: \37$\\{sc2}(\.{"\\"})(\.{"G"})(\\{math})$;\6
\4\\{equivalence\←sign}: \37$\\{sc2}(\.{"\\"})(\.{"S"})(\\{math})$;\6
\4\\{and\←sign}: \37$\\{sc2}(\.{"\\"})(\.{"W"})(\\{math})$;\6
\4\\{or\←sign}: \37$\\{sc2}(\.{"\\"})(\.{"V"})(\\{math})$;\6
\4\\{not\←sign}: \37$\\{sc2}(\.{"\\"})(\.{"R"})(\\{math})$;\6
\4\\{left\←arrow}: \37$\\{sc2}(\.{"\\"})(\.{"K"})(\\{math})$;\par
\U section~187.\fi

\M190. The following code must use \\{app\←tok} instead of \\{app} in order to
protect against overflow. Note that $\\{tok\←ptr}+1\L\\{max\←toks}$ after %
\\{app\←tok}
has been used, so another \\{app} is legitimate before testing again.

Many of the special characters in a string must be prefixed by `\.\\' so that
\TeX\ will print them properly.

\Y\P$\4\X190:Append a \(string scrap\X\S$\6
\&{begin} \37$\\{app}(\.{"\\"})$;\6
\&{if} $\\{next\←control}=\\{verbatim}$ \1\&{then}\6
\&{begin} \37$\\{app}(\.{"="})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{app}(\.{"."})$;\6
\&{end};\2\6
$\\{app}(\.{"\{"})$;\5
$\|j\K\\{id\←first}$;\6
\&{while} $\|j<\\{id\←loc}$ \1\&{do}\6
\&{begin} \37\&{case} $\\{buffer}[\|j]$ \1\&{of}\6
\4$\.{"\ "},\39\.{"\\"},\39\.{"\#"},\39\.{"\%"},\39\.{"\$"},\39\.{"\↑"},\39\.{"%
\'"},\39\.{"\`"},\39\.{"\{"},\39\.{"\}"},\39\.{"\~"},\39\.{"\&"},\39\.{"\←"}$: %
\37\&{begin} \37$\\{app}(\.{"\\"})$;\6
\&{end};\6
\4\.{"@"}: \37\&{if} $\\{buffer}[\|j+1]=\.{"@"}$ \1\&{then}\5
$\\{incr}(\|j)$\6
\4\&{else} $\\{err\←print}(\.{\'!\ Double\ @\ should\ be\ used\ in\ strings%
\'})$;\2\6
\4\&{othercases} \37\\{do\←nothing}\2\6
\&{endcases};\6
$\\{app\←tok}(\\{buffer}[\|j])$;\5
$\\{incr}(\|j)$;\6
\&{end};\2\6
$\\{sc1}(\.{"\}"})(\\{simp})$;\6
\&{end}\par
\U section~186.\fi

\M191. \P$\X191:Append a \TeX\ string scrap\X\S$\6
\&{begin} \37$\\{app}(\.{"\\"})$;\5
$\\{app}(\.{"h"})$;\5
$\\{app}(\.{"b"})$;\5
$\\{app}(\.{"o"})$;\5
$\\{app}(\.{"x"})$;\5
$\\{app}(\.{"\{"})$;\6
\&{for} $\|j\K\\{id\←first}\mathrel{\&{to}}\\{id\←loc}-1$ \1\&{do}\5
$\\{app\←tok}(\\{buffer}[\|j])$;\2\6
$\\{sc1}(\.{"\}"})(\\{simp})$;\6
\&{end}\par
\U section~186.\fi

\M192. \P$\X192:Append an identifier scrap\X\S$\6
\&{begin} \37$\|p\K\\{id\←lookup}(\\{normal})$;\6
\&{case} $\\{ilk}[\|p]$ \1\&{of}\6
\4$\\{normal},\39\\{array\←like},\39\\{const\←like},\39\\{div\←like},\39\\{do%
\←like},\39\\{for\←like},\39\\{goto\←like},\39\\{nil\←like},\39\\{to\←like}$: %
\37$\\{sub\←cases}(\|p)$;\6
\hbox{\4}\X194:Cases that generate more than one scrap\X\6
\4\&{othercases} \37\&{begin} \37$\\{next\←control}\K\\{ilk}[\|p]-\\{char%
\←like}$;\5
\&{goto} \37\\{reswitch};\6
\&{end}\C{\&{and}, \&{in}, \&{not}, \&{or}}\2\6
\&{endcases};\6
\&{end}\par
\U section~186.\fi

\M193. The \\{sub\←cases} also result in straightforward scraps.

\Y\P$\4\X193:Declaration of the \\{sub\←cases} procedure\X\S$\6
\4\&{procedure}\1\  \37$\\{sub\←cases}(\|p:\\{name\←pointer})$;\C{a
subprocedure of \\{PASCAL\←parse}}\2\6
\&{begin} \37\&{case} $\\{ilk}[\|p]$ \1\&{of}\6
\4\\{normal}: \37$\\{sc1}(\\{id\←flag}+\|p)(\\{simp})$;\C{not a reserved word}\6
\4\\{array\←like}: \37$\\{sc1}(\\{res\←flag}+\|p)(\\{alpha})$;\C{\&{array}, %
\&{file}, \&{set}}\6
\4\\{const\←like}: \37$\\{sc3}(\\{force})(\\{backup})(\\{res\←flag}+\|p)(%
\\{intro})$;\C{\&{const}, \&{label}, \&{type}}\6
\4\\{div\←like}: \37$\\{sc3}(\\{math\←bin})(\\{res\←flag}+\|p)(\.{"\}"})(%
\\{math})$;\C{\&{div}, \&{mod}}\6
\4\\{do\←like}: \37$\\{sc1}(\\{res\←flag}+\|p)(\\{omega})$;\C{\&{do}, \&{of}, %
\&{then}}\6
\4\\{for\←like}: \37$\\{sc2}(\\{force})(\\{res\←flag}+\|p)(\\{alpha})$;\C{%
\&{for}, \&{while}, \&{with}}\6
\4\\{goto\←like}: \37$\\{sc1}(\\{res\←flag}+\|p)(\\{intro})$;\C{\&{goto}, %
\&{packed}}\6
\4\\{nil\←like}: \37$\\{sc1}(\\{res\←flag}+\|p)(\\{simp})$;\C{\&{nil}}\6
\4\\{to\←like}: \37$\\{sc3}(\\{math\←rel})(\\{res\←flag}+\|p)(\.{"\}"})(%
\\{math})$;\C{\&{downto}, \&{to}}\2\6
\&{end};\6
\&{end};\par
\U section~184.\fi

\M194. \P$\X194:Cases that generate more than one scrap\X\S$\6
\4\\{begin\←like}: \37\&{begin} \37$\\{sc3}(\\{force})(\\{res\←flag}+\|p)(%
\\{cancel})(\\{beginning})$;\5
$\\{sc0}(\\{intro})$;\6
\&{end};\C{\&{begin}}\6
\4\\{case\←like}: \37\&{begin} \37$\\{sc0}(\\{casey})$;\5
$\\{sc2}(\\{force})(\\{res\←flag}+\|p)(\\{alpha})$;\6
\&{end};\C{\&{case}}\6
\4\\{else\←like}: \37\&{begin} \37\X195:Append \\{terminator} if not already
present\X;\6
$\\{sc3}(\\{force})(\\{backup})(\\{res\←flag}+\|p)(\\{elsie})$;\6
\&{end};\C{\&{else}}\6
\4\\{end\←like}: \37\&{begin} \37\X195:Append \\{terminator} if not already
present\X;\6
$\\{sc2}(\\{force})(\\{res\←flag}+\|p)(\\{close})$;\6
\&{end};\C{\&{end}}\6
\4\\{if\←like}: \37\&{begin} \37$\\{sc0}(\\{cond})$;\5
$\\{sc2}(\\{force})(\\{res\←flag}+\|p)(\\{alpha})$;\6
\&{end};\C{\&{if}}\6
\4\\{loop\←like}: \37\&{begin} \37$\\{sc3}(\\{force})(\.{"\\"})(\.{"\~"})(%
\\{alpha})$;\5
$\\{sc1}(\\{res\←flag}+\|p)(\\{omega})$;\6
\&{end};\C{\&{xclause}}\6
\4\\{proc\←like}: \37\&{begin} \37$\\{sc4}(\\{force})(\\{backup})(\\{res%
\←flag}+\|p)(\\{cancel})(\\{proc})$;\5
$\\{sc3}(\\{indent})(\.{"\\"})(\.{"\ "})(\\{intro})$;\6
\&{end};\C{\&{function}, \&{procedure}, \&{program}}\6
\4\\{record\←like}: \37\&{begin} \37$\\{sc1}(\\{res\←flag}+\|p)(\\{record%
\←head})$;\5
$\\{sc0}(\\{intro})$;\6
\&{end};\C{\&{record}}\6
\4\\{repeat\←like}: \37\&{begin} \37$\\{sc4}(\\{force})(\\{indent})(\\{res%
\←flag}+\|p)(\\{cancel})(\\{beginning})$;\5
$\\{sc0}(\\{intro})$;\6
\&{end};\C{\&{repeat}}\6
\4\\{until\←like}: \37\&{begin} \37\X195:Append \\{terminator} if not already
present\X;\6
$\\{sc3}(\\{force})(\\{backup})(\\{res\←flag}+\|p)(\\{close})$;\5
$\\{sc0}(\\{clause})$;\6
\&{end};\C{\&{until}}\6
\4\\{var\←like}: \37\&{begin} \37$\\{sc4}(\\{force})(\\{backup})(\\{res\←flag}+%
\|p)(\\{cancel})(\\{var\←head})$;\5
$\\{sc0}(\\{intro})$;\6
\&{end};\C{\&{var}}\par
\U section~192.\fi

\M195. If a comment or semicolon appears before the reserved words \&{end},
\&{else}, or \&{until}, the \\{semi} or \\{terminator} scrap that is already
present overrides the \\{terminator} scrap belonging to this reserved word.

\Y\P$\4\X195:Append \\{terminator} if not already present\X\S$\6
\&{if} $(\\{scrap\←ptr}<\\{scrap\←base})\V((\\{cat}[\\{scrap\←ptr}]\I%
\\{terminator})\W(\\{cat}[\\{scrap\←ptr}]\I\\{semi}))$ \1\&{then}\5
$\\{sc0}(\\{terminator})$\2\par
\U sections~194, 194, and~194.\fi

\M196. A comment is incorporated into the previous scrap if that scrap is of
type
\\{omega} or \\{semi} or \\{terminator}. (These three categories have
consecutive
category codes.) Otherwise the comment is entered as a separate scrap
of type \\{terminator}, and it will combine with a \\{terminator} scrap that
immediately follows~it.

The \\{app\←comment} procedure takes care of placing a comment at the end of
the
current scrap list. When \\{app\←comment} is called, we assume that the current
token list is the translation of the comment involved.

\Y\P$\4\X196:Declaration of the \\{app\←comment} procedure\X\S$\6
\4\&{procedure}\1\  \37\\{app\←comment};\C{append a comment to the scrap list}%
\2\6
\&{begin} \37\\{freeze\←text};\6
\&{if} $(\\{scrap\←ptr}<\\{scrap\←base})\V(\\{cat}[\\{scrap\←ptr}]<\\{omega})%
\V(\\{cat}[\\{scrap\←ptr}]>\\{terminator})$ \1\&{then}\5
$\\{sc0}(\\{terminator})$\6
\4\&{else} \&{begin} \37$\\{app1}(\\{scrap\←ptr})$;\C{$\\{cat}[\\{scrap\←ptr}]$
is     \\{omega} or \\{semi} or \\{terminator}}\6
\&{end};\2\6
$\\{app}(\\{text\←ptr}-1+\\{tok\←flag})$;\5
$\\{trans}[\\{scrap\←ptr}]\K\\{text\←ptr}$;\5
\\{freeze\←text};\6
\&{end};\par
\U section~184.\fi

\M197. We are now finished with \\{PASCAL\←parse}, except for two relatively
trivial subprocedures that convert constants into tokens.

\Y\P$\4\X197:Declaration of the \\{app\←octal} and \\{app\←hex} procedures\X\S$%
\6
\4\&{procedure}\1\  \37\\{app\←octal};\2\6
\&{begin} \37$\\{app}(\.{"\\"})$;\5
$\\{app}(\.{"O"})$;\5
$\\{app}(\.{"\{"})$;\6
\&{while} $(\\{buffer}[\\{loc}]\G\.{"0"})\W(\\{buffer}[\\{loc}]\L\.{"7"})$ \1%
\&{do}\6
\&{begin} \37$\\{app\←tok}(\\{buffer}[\\{loc}])$;\5
$\\{incr}(\\{loc})$;\6
\&{end};\2\6
$\\{sc1}(\.{"\}"})(\\{simp})$;\6
\&{end};\7
\4\&{procedure}\1\  \37\\{app\←hex};\2\6
\&{begin} \37$\\{app}(\.{"\\"})$;\5
$\\{app}(\.{"H"})$;\5
$\\{app}(\.{"\{"})$;\6
\&{while} $((\\{buffer}[\\{loc}]\G\.{"0"})\W(\\{buffer}[\\{loc}]\L\.{"9"}))\V%
\30((\\{buffer}[\\{loc}]\G\.{"A"})\W(\\{buffer}[\\{loc}]\L\.{"F"}))$ \1\&{do}\6
\&{begin} \37$\\{app\←tok}(\\{buffer}[\\{loc}])$;\5
$\\{incr}(\\{loc})$;\6
\&{end};\2\6
$\\{sc1}(\.{"\}"})(\\{simp})$;\6
\&{end};\par
\U section~184.\fi

\M198. When the `\v' that introduces \PASCAL\ text is sensed, a call on
\\{PASCAL\←translate} will return a pointer to the \TeX\ translation of
that text. If scraps exist in the \\{cat} and \\{trans} arrays, they are
unaffected by this translation process.

\Y\P\4\&{function}\1\  \37\\{PASCAL\←translate}: \37\\{text\←pointer};\6
\4\&{var} \37\|p: \37\\{text\←pointer};\C{points to the translation}\6
\\{save\←base}: \37$0\to\\{max\←scraps}$;\C{holds original value of \\{scrap%
\←base}}\2\6
\&{begin} \37$\\{save\←base}\K\\{scrap\←base}$;\5
$\\{scrap\←base}\K\\{scrap\←ptr}+1$;\5
\\{PASCAL\←parse};\C{get the scraps together}\6
\&{if} $\\{next\←control}\I\.{"|"}$ \1\&{then}\5
$\\{err\←print}(\.{\'!\ Missing\ "|"\ after\ PASCAL\ text\'})$;\2\6
$\\{app\←tok}(\\{cancel})$;\5
\\{app\←comment};\C{place a \\{cancel} token as a final ``comment''}\6
$\|p\K\\{translate}$;\C{make the translation}\6
\&{stat} \37\&{if} $\\{scrap\←ptr}>\\{max\←scr\←ptr}$ \1\&{then}\5
$\\{max\←scr\←ptr}\K\\{scrap\←ptr}$;\2\ \&{tats}\6
$\\{scrap\←ptr}\K\\{scrap\←base}-1$;\5
$\\{scrap\←base}\K\\{save\←base}$;\C{scrap the scraps}\6
$\\{PASCAL\←translate}\K\|p$;\6
\&{end};\par
\fi

\M199. The \\{outer\←parse} routine is to \\{PASCAL\←parse} as \\{outer\←xref}
is to \\{PASCAL\←xref}: It constructs a sequence of scraps for \PASCAL\ text
until $\\{next\←control}\G\\{format}$. Thus, it takes care of embedded
comments.

\Y\P\4\&{procedure}\1\  \37\\{outer\←parse};\C{makes scraps from \PASCAL\
tokens and comments}\6
\4\&{var} \37\\{bal}: \37\\{eight\←bits};\C{brace level in comment}\6
$\|p,\39\|q$: \37\\{text\←pointer};\C{partial comments}\2\6
\&{begin} \37\&{while} $\\{next\←control}<\\{format}$ \1\&{do}\6
\&{if} $\\{next\←control}\I\.{"\{"}$ \1\&{then}\5
\\{PASCAL\←parse}\6
\4\&{else} \&{begin} \37\X200:Make sure that there is room for at least seven
more tokens, three more texts, and one more scrap\X;\6
$\\{app}(\.{"\\"})$;\5
$\\{app}(\.{"C"})$;\5
$\\{app}(\.{"\{"})$;\5
$\\{bal}\K\\{copy\←comment}(1)$;\5
$\\{next\←control}\K\.{"|"}$;\6
\&{while} $\\{bal}>0$ \1\&{do}\6
\&{begin} \37$\|p\K\\{text\←ptr}$;\5
\\{freeze\←text};\5
$\|q\K\\{PASCAL\←translate}$;\C{at this point we have $\\{tok\←ptr}+6\L\\{max%
\←toks}$}\6
$\\{app}(\\{tok\←flag}+\|p)$;\5
$\\{app}(\\{inner\←tok\←flag}+\|q)$;\6
\&{if} $\\{next\←control}=\.{"|"}$ \1\&{then}\5
$\\{bal}\K\\{copy\←comment}(\\{bal})$\6
\4\&{else} $\\{bal}\K0$;\C{an error has been reported}\2\6
\&{end};\2\6
$\\{app}(\\{force})$;\5
\\{app\←comment};\C{the full comment becomes a scrap}\6
\&{end};\2\2\6
\&{end};\par
\fi

\M200. \P$\X200:Make sure that there is room for at least seven more tokens,
three more texts, and one more scrap\X\S$\6
\&{if} $(\\{tok\←ptr}+7>\\{max\←toks})\V(\\{text\←ptr}+3>\\{max\←texts})\V(%
\\{scrap\←ptr}\G\\{max\←scraps})$ \1\&{then}\6
\&{begin} \37\&{stat} \37\&{if} $\\{scrap\←ptr}>\\{max\←scr\←ptr}$ \1\&{then}\5
$\\{max\←scr\←ptr}\K\\{scrap\←ptr}$;\2\6
\&{if} $\\{tok\←ptr}>\\{max\←tok\←ptr}$ \1\&{then}\5
$\\{max\←tok\←ptr}\K\\{tok\←ptr}$;\2\6
\&{if} $\\{text\←ptr}>\\{max\←txt\←ptr}$ \1\&{then}\5
$\\{max\←txt\←ptr}\K\\{text\←ptr}$;\2\6
\&{tats}\6
$\\{overflow}(\.{\'token/text/scrap\'})$;\6
\&{end}\2\par
\U section~199.\fi

\N201.  Output of tokens.
So far our programs have only built up multi-layered token lists in
\.{WEAVE}'s internal memory; we have to figure out how to get them into
the desired final form. The job of converting token lists to characters in
the \TeX\ output file is not difficult, although it is an implicitly
recursive process. Three main considerations had to be kept in mind when
this part of \.{WEAVE} was designed:  (a) There are two modes of output,
\\{outer} mode that translates tokens like \\{force} into line-breaking
control sequences, and \\{inner} mode that ignores them except that blank
spaces take the place of line breaks. (b) The \\{cancel} instruction applies
to adjacent token or tokens that are output, and this cuts across levels
of recursion since `\\{cancel}' occurs at the beginning or end of a token
list on one level. (c) The \TeX\ output file will be semi-readable if line
breaks are inserted after the result of tokens like \\{break\←space} and
\\{force}.  (d) The final line break should be suppressed, and there should
be no \\{force} token output immediately after `\.{\\Y\\P}'.

\fi

\M202. The output process uses a stack to keep track of what is going on at
different ``levels'' as the token lists are being written out. Entries on
this stack have three parts:

\yskip\hang \\{end\←field} is the \\{tok\←mem} location where the token list of
a
particular level will end;

\yskip\hang \\{tok\←field} is the \\{tok\←mem} location from which the next
token
on a particular level will be read;

\yskip\hang \\{mode\←field} is the current mode, either \\{inner} or \\{outer}.

\yskip\noindent The current values of these quantities are referred to
quite frequently, so they are stored in a separate place instead of in the
\\{stack} array. We call the current values \\{cur\←end}, \\{cur\←tok}, and
\\{cur\←mode}.

The global variable \\{stack\←ptr} tells how many levels of output are
currently in progress. The end of output occurs when an \\{end\←translation}
token is found, so the stack is never empty except when we first begin the
output process.

\Y\P\D \37$\\{inner}=0$\C{value of \\{mode} for \PASCAL\ texts within \TeX\
texts}\par
\P\D \37$\\{outer}=1$\C{value of \\{mode} for \PASCAL\ texts in modules}\par
\Y\P$\4\X11:Types in the outer block\X\mathrel{+}\S$\6
$\\{mode}=\\{inner}\to\\{outer}$;\6
$\\{output\←state}=$\1\5
\1\&{record} \37\\{end\←field}: \37\\{sixteen\←bits};\C{ending location of
token list}\6
\4\\{tok\←field}: \37\\{sixteen\←bits};\C{present location within token list}\6
\4\\{mode\←field}: \37\\{mode};\C{interpretation of control tokens}\2\6
\&{end};\2\par
\fi

\M203. \P\D \37$\\{cur\←end}\S\\{cur\←state}.\\{end\←field}$\C{current ending
location in \\{tok\←mem}}\par
\P\D \37$\\{cur\←tok}\S\\{cur\←state}.\\{tok\←field}$\C{location of next output
token in \\{tok\←mem}}\par
\P\D \37$\\{cur\←mode}\S\\{cur\←state}.\\{mode\←field}$\C{current mode of
interpretation}\par
\P\D \37$\\{init\←stack}\S\\{stack\←ptr}\K0$;\5
$\\{cur\←mode}\K\\{outer}$\C{do this to initialize the stack}\par
\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cur\←state}: \37\\{output\←state};\C{\\{cur\←end}, \\{cur\←tok}, \\{cur%
\←mode}}\6
\4\\{stack}: \37\&{array} $[1\to\\{stack\←size}]$ \1\&{of}\5
\\{output\←state};\C{info for non-current levels}\2\6
\4\\{stack\←ptr}: \37$0\to\\{stack\←size}$;\C{first unused location in the
output state stack}\6
\&{stat} \37\\{max\←stack\←ptr}: \37$0\to\\{stack\←size}$;\C{largest value
assumed by \\{stack\←ptr}}\6
\&{tats}\par
\fi

\M204. \P$\X10:Set initial values\X\mathrel{+}\S$\6
\&{stat} \37$\\{max\←stack\←ptr}\K0$;\ \&{tats}\par
\fi

\M205. To insert token-list \|p into the output, the \\{push\←level} subroutine
is called; it saves the old level of output and gets a new one going.
The value of \\{cur\←mode} is not changed.

\Y\P\4\&{procedure}\1\  \37$\\{push\←level}(\|p:\\{text\←pointer})$;\C{suspends
the current level}\2\6
\&{begin} \37\&{if} $\\{stack\←ptr}=\\{stack\←size}$ \1\&{then}\5
$\\{overflow}(\.{\'stack\'})$\6
\4\&{else} \&{begin} \37\&{if} $\\{stack\←ptr}>0$ \1\&{then}\5
$\\{stack}[\\{stack\←ptr}]\K\\{cur\←state}$;\C{save \\{cur\←end}$\,\ldots\,$%
\\{cur\←mode}}\2\6
$\\{incr}(\\{stack\←ptr})$;\6
\&{stat} \37\&{if} $\\{stack\←ptr}>\\{max\←stack\←ptr}$ \1\&{then}\5
$\\{max\←stack\←ptr}\K\\{stack\←ptr}$;\2\ \&{tats}\6
$\\{cur\←tok}\K\\{tok\←start}[\|p]$;\5
$\\{cur\←end}\K\\{tok\←start}[\|p+1]$;\6
\&{end};\2\6
\&{end};\par
\fi

\M206. Conversely, the \\{pop\←level} routine restores the conditions that were
in
force when the current level was begun. This subroutine will never be
called when $\\{stack\←ptr}=1$. It is so simple, we declare it as a macro:

\Y\P\D \37$\\{pop\←level}\S$\1\6
\&{begin} \37$\\{decr}(\\{stack\←ptr})$;\5
$\\{cur\←state}\K\\{stack}[\\{stack\←ptr}]$;\6
\&{end}\C{do this when \\{cur\←tok} reaches \\{cur\←end}}\2\par
\fi

\M207. The \\{get\←output} function returns the next byte of output that is not
a
reference to a token list. It returns the values \\{identifier} or \\{res%
\←word}
or \\{mod\←name} if the next token is to be an identifier (typeset in
italics), a reserved word (typeset in boldface) or a module name (typeset
by a complex routine that might generate additional levels of output).
In these cases \\{cur\←name} points to the identifier or module name in
question.

\Y\P\D \37$\\{res\←word}=\O{201}$\C{returned by \\{get\←output} for reserved
words}\par
\P\D \37$\\{mod\←name}=\O{200}$\C{returned by \\{get\←output} for module names}%
\par
\Y\P\4\&{function}\1\  \37\\{get\←output}: \37\\{eight\←bits};\C{returns the
next token of output}\6
\4\&{label} \37\\{restart};\6
\4\&{var} \37\|a: \37\\{sixteen\←bits};\C{current item read from \\{tok\←mem}}%
\2\6
\&{begin} \37\\{restart}: \37\&{while} $\\{cur\←tok}=\\{cur\←end}$ \1\&{do}\5
\\{pop\←level};\2\6
$\|a\K\\{tok\←mem}[\\{cur\←tok}]$;\5
$\\{incr}(\\{cur\←tok})$;\6
\&{if} $\|a\G\O{400}$ \1\&{then}\6
\&{begin} \37$\\{cur\←name}\K\|a\mathbin{\&{mod}}\\{id\←flag}$;\6
\&{case} $\|a\mathbin{\&{div}}\\{id\←flag}$ \1\&{of}\6
\42: \37$\|a\K\\{res\←word}$;\C{$\|a=\\{res\←flag}+\\{cur\←name}$}\6
\43: \37$\|a\K\\{mod\←name}$;\C{$\|a=\\{mod\←flag}+\\{cur\←name}$}\6
\44: \37\&{begin} \37$\\{push\←level}(\\{cur\←name})$;\5
\&{goto} \37\\{restart};\6
\&{end};\C{$\|a=\\{tok\←flag}+\\{cur\←name}$}\6
\45: \37\&{begin} \37$\\{push\←level}(\\{cur\←name})$;\5
$\\{cur\←mode}\K\\{inner}$;\5
\&{goto} \37\\{restart};\6
\&{end};\C{$\|a=\\{inner\←tok\←flag}+\\{cur\←name}$}\6
\4\&{othercases} \37$\|a\K\\{identifier}$\C{$\|a=\\{id\←flag}+\\{cur\←name}$}\2%
\6
\&{endcases};\6
\&{end};\2\6
\&{debug} \37\&{if} $\\{trouble\←shooting}$ \1\&{then}\5
\\{debug\←help};\ \2\6
\&{gubed}\6
$\\{get\←output}\K\|a$;\6
\&{end};\par
\fi

\M208. The real work associated with token output is done by \\{make\←output}.
This procedure appends an \\{end\←translation} token to the current token list,
and then it repeatedly calls \\{get\←output} and feeds characters to the output
buffer until reaching the \\{end\←translation} sentinel. It is possible for
\\{make\←output} to
be called recursively, since a module name may include embedded \PASCAL\
text; however, the depth of recursion never exceeds one level, since
module names cannot be inside of module names.

A procedure called \\{output\←PASCAL} does the scanning, translation, and
output of \PASCAL\ text within `\pb' brackets, and this procedure uses
\\{make\←output} to output the current token list. Thus, the recursive call
of \\{make\←output} actually occurs when \\{make\←output} calls \\{output%
\←PASCAL}
while outputting the name of a module.

\Y\P\4\&{procedure}\1\  \37\\{make\←output};\5
\\{forward};\5
\hbox{\2}\7
\4\&{procedure}\1\  \37\\{output\←PASCAL};\C{outputs the current token list}\6
\4\&{var} \37$\\{save\←tok\←ptr},\39\\{save\←text\←ptr},\39\\{save\←next%
\←control}$: \37\\{sixteen\←bits};\C{values to be restored}\6
\|p: \37\\{text\←pointer};\C{translation of the \PASCAL\ text}\2\6
\&{begin} \37$\\{save\←tok\←ptr}\K\\{tok\←ptr}$;\5
$\\{save\←text\←ptr}\K\\{text\←ptr}$;\5
$\\{save\←next\←control}\K\\{next\←control}$;\5
$\\{next\←control}\K\.{"|"}$;\5
$\|p\K\\{PASCAL\←translate}$;\5
$\\{app}(\|p+\\{inner\←tok\←flag})$;\5
\\{make\←output};\C{output the list}\6
\&{stat} \37\&{if} $\\{text\←ptr}>\\{max\←txt\←ptr}$ \1\&{then}\5
$\\{max\←txt\←ptr}\K\\{text\←ptr}$;\2\6
\&{if} $\\{tok\←ptr}>\\{max\←tok\←ptr}$ \1\&{then}\5
$\\{max\←tok\←ptr}\K\\{tok\←ptr}$;\2\ \&{tats}\6
$\\{text\←ptr}\K\\{save\←text\←ptr}$;\5
$\\{tok\←ptr}\K\\{save\←tok\←ptr}$;\C{forget the tokens}\6
$\\{next\←control}\K\\{save\←next\←control}$;\C{restore \\{next\←control} to
original state}\6
\&{end};\par
\fi

\M209. Here is \.{WEAVE}'s major output handler.

\Y\P\4\&{procedure}\1\  \37\\{make\←output};\C{outputs the equivalents of
tokens}\6
\4\&{label} \37$\\{reswitch},\39\\{exit},\39\\{found}$;\6
\4\&{var} \37\|a: \37\\{eight\←bits};\C{current output byte}\6
\|b: \37\\{eight\←bits};\C{next output byte}\6
$\|k,\39\\{k\←limit}$: \37$0\to\\{max\←bytes}$;\C{indices into \\{byte\←mem}}\6
\|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\←mem}}\6
\|j: \37$0\to\\{long\←buf\←size}$;\C{index into \\{buffer}}\6
\\{string\←delimiter}: \37\\{ASCII\←code};\C{first and last character of
string being copied}\6
$\\{save\←loc},\39\\{save\←limit}$: \37$0\to\\{long\←buf\←size}$;\C{\\{loc} and
\\{limit} to be restored}\6
\\{cur\←mod\←name}: \37\\{name\←pointer};\C{name of module being output}\6
\\{save\←mode}: \37\\{mode};\C{value of \\{cur\←mode} before a sequence of
breaks}\2\6
\&{begin} \37$\\{app}(\\{end\←translation})$;\C{append a sentinel}\6
\\{freeze\←text};\5
$\\{push\←level}(\\{text\←ptr}-1)$;\6
\~ \1\&{loop}\ \&{begin} \37$\|a\K\\{get\←output}$;\6
\4\\{reswitch}: \37\&{case} $\|a$ \1\&{of}\6
\4\\{end\←translation}: \37\&{return};\6
\4$\\{identifier},\39\\{res\←word}$: \37\X210:Output an identifier\X;\6
\4\\{mod\←name}: \37\X214:Output a module name\X;\6
\4$\\{math\←bin},\39\\{math\←op},\39\\{math\←rel}$: \37\X211:Output a \.{%
\\math} operator\X;\6
\4\\{cancel}: \37\&{begin} \37\1\&{repeat} \37$\|a\K\\{get\←output}$;\6
\4\&{until}\5
$(\|a<\\{backup})\V(\|a>\\{big\←force})$;\2\6
\&{goto} \37\\{reswitch};\6
\&{end};\6
\4\\{big\←cancel}: \37\&{begin} \37\1\&{repeat} \37$\|a\K\\{get\←output}$;\6
\4\&{until}\5
$((\|a<\\{backup})\W(\|a\I\.{"\ "}))\V(\|a>\\{big\←force})$;\2\6
\&{goto} \37\\{reswitch};\6
\&{end};\6
\4$\\{indent},\39\\{outdent},\39\\{opt},\39\\{backup},\39\\{break\←space},\39%
\\{force},\39\\{big\←force}$: \37\X212:Output a \(control, look ahead in case
of line breaks, possibly \&{goto} \\{reswitch}\X;\6
\4\&{othercases} \37$\\{out}(\|a)$\C{otherwise \|a is an ASCII character}\2\6
\&{endcases};\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M210. An identifier of length one does not have to be enclosed in braces, and
it
looks slightly better if set in a math-italic font instead of a (slightly
narrower) text-italic font. Thus we output `\.{\\\char'174a}' but
`\.{\\\\\{aa\}}'.

\Y\P$\4\X210:Output an identifier\X\S$\6
\&{begin} \37$\\{out}(\.{"\\"})$;\6
\&{if} $\|a=\\{identifier}$ \1\&{then}\6
\&{if} $\\{length}(\\{cur\←name})=1$ \1\&{then}\5
$\\{out}(\.{"|"})$\6
\4\&{else} $\\{out}(\.{"\\"})$\2\6
\4\&{else} $\\{out}(\.{"\&"})$;\C{$\|a=\\{res\←word}$}\2\6
\&{if} $\\{length}(\\{cur\←name})=1$ \1\&{then}\5
$\\{out}(\\{byte\←mem}[\\{cur\←name}\mathbin{\&{mod}}\\{ww},\39\\{byte\←start}[%
\\{cur\←name}]])$\6
\4\&{else} $\\{out\←name}(\\{cur\←name})$;\2\6
\&{end}\par
\U section~209.\fi

\M211. \P$\X211:Output a \.{\\math} operator\X\S$\6
\&{begin} \37$\\{out5}(\.{"\\"})(\.{"m"})(\.{"a"})(\.{"t"})(\.{"h"})$;\6
\&{if} $\|a=\\{math\←bin}$ \1\&{then}\5
$\\{out3}(\.{"b"})(\.{"i"})(\.{"n"})$\6
\4\&{else} \&{if} $\|a=\\{math\←rel}$ \1\&{then}\5
$\\{out3}(\.{"r"})(\.{"e"})(\.{"l"})$\6
\4\&{else} $\\{out2}(\.{"o"})(\.{"p"})$;\2\2\6
$\\{out}(\.{"\{"})$;\6
\&{end}\par
\U section~209.\fi

\M212. The current mode does not affect the behavior of \.{WEAVE}'s output
routine
except when we are outputting control tokens.

\Y\P$\4\X212:Output a \(control, look ahead in case of line breaks, possibly %
\&{goto} \\{reswitch}\X\S$\6
\&{if} $\|a<\\{break\←space}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cur\←mode}=\\{outer}$ \1\&{then}\6
\&{begin} \37$\\{out2}(\.{"\\"})(\|a+-\\{cancel}+\.{"0"})$;\6
\&{if} $\|a=\\{opt}$ \1\&{then}\5
$\\{out}(\\{get\←output})$\C{\\{opt} is followed by a digit}\2\6
\&{end}\6
\4\&{else} \&{if} $\|a=\\{opt}$ \1\&{then}\5
$\|b\K\\{get\←output}$\C{ignore digit following \\{opt}}\2\2\6
\&{end}\6
\4\&{else} \X213:Look ahead for strongest line break, \&{goto} \\{reswitch}\X\2%
\par
\U section~209.\fi

\M213. If several of the tokens \\{break\←space}, \\{force}, \\{big\←force}
occur in a
row, possibly mixed with blank spaces (which are ignored),
the largest one is used. A line break also occurs in the output file,
except at the very end of the translation. The very first line break
is suppressed (i.e., a line break that follows `\.{\\Y\\P}').

\Y\P$\4\X213:Look ahead for strongest line break, \&{goto} \\{reswitch}\X\S$\6
\&{begin} \37$\|b\K\|a$;\5
$\\{save\←mode}\K\\{cur\←mode}$;\6
\~ \1\&{loop}\ \&{begin} \37$\|a\K\\{get\←output}$;\6
\&{if} $(\|a=\\{cancel})\V(\|a=\\{big\←cancel})$ \1\&{then}\5
\&{goto} \37\\{reswitch};\C{\\{cancel} overrides everything}\2\6
\&{if} $((\|a\I\.{"\ "})\W(\|a<\\{break\←space}))\V(\|a>\\{big\←force})$ \1%
\&{then}\6
\&{begin} \37\&{if} $\\{save\←mode}=\\{outer}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{out\←ptr}>3$ \1\&{then}\6
\&{if} $(\\{out\←buf}[\\{out\←ptr}]=\.{"P"})\W(\\{out\←buf}[\\{out\←ptr}-1]=%
\.{"\\"})\W(\\{out\←buf}[\\{out\←ptr}-2]=\.{"Y"})\W(\\{out\←buf}[\\{out%
\←ptr}-3]=\.{"\\"})$ \1\&{then}\5
\&{goto} \37\\{reswitch};\2\2\6
$\\{out2}(\.{"\\"})(\|b-\\{cancel}+\.{"0"})$;\6
\&{if} $\|a\I\\{end\←translation}$ \1\&{then}\5
\\{finish\←line};\2\6
\&{end}\6
\4\&{else} \&{if} $(\|a\I\\{end\←translation})\W(\\{cur\←mode}=\\{inner})$ \1%
\&{then}\5
$\\{out}(\.{"\ "})$;\2\2\6
\&{goto} \37\\{reswitch};\6
\&{end};\2\6
\&{if} $\|a>\|b$ \1\&{then}\5
$\|b\K\|a$;\C{if $\|a=\.{"\ "}$ we have $\|a<\|b$}\2\6
\&{end};\2\6
\&{end}\par
\U section~212.\fi

\M214. The remaining part of \\{make\←output} is somewhat more complicated.
When we
output a module name, we may need to enter the parsing and translation
routines, since the name may contain \PASCAL\ code embedded in
\pb\ constructions. This \PASCAL\ code is placed at the end of the active
input buffer and the translation process uses the end of the active
\\{tok\←mem} area.

\Y\P$\4\X214:Output a module name\X\S$\6
\&{begin} \37$\\{out2}(\.{"\\"})(\.{"X"})$;\5
$\\{cur\←xref}\K\\{xref}[\\{cur\←name}]$;\6
\&{if} $\\{num}(\\{cur\←xref})\G\\{def\←flag}$ \1\&{then}\6
\&{begin} \37$\\{out\←mod}(\\{num}(\\{cur\←xref})-\\{def\←flag})$;\6
\&{if} $\\{phase\←three}$ \1\&{then}\6
\&{begin} \37$\\{cur\←xref}\K\\{xlink}(\\{cur\←xref})$;\6
\&{while} $\\{num}(\\{cur\←xref})\G\\{def\←flag}$ \1\&{do}\6
\&{begin} \37$\\{out2}(\.{","})(\.{"\ "})$;\5
$\\{out\←mod}(\\{num}(\\{cur\←xref})-\\{def\←flag})$;\5
$\\{cur\←xref}\K\\{xlink}(\\{cur\←xref})$;\6
\&{end};\2\6
\&{end};\2\6
\&{end}\6
\4\&{else} $\\{out}(\.{"0"})$;\C{output the module number, or zero if it was
undefined}\2\6
$\\{out}(\.{":"})$;\5
\X215:Output the text of the module name\X;\6
$\\{out2}(\.{"\\"})(\.{"X"})$;\6
\&{end}\par
\U section~209.\fi

\M215. \P$\X215:Output the text of the module name\X\S$\6
$\|k\K\\{byte\←start}[\\{cur\←name}]$;\5
$\|w\K\\{cur\←name}\mathbin{\&{mod}}\\{ww}$;\5
$\\{k\←limit}\K\\{byte\←start}[\\{cur\←name}+\\{ww}]$;\5
$\\{cur\←mod\←name}\K\\{cur\←name}$;\6
\&{while} $\|k<\\{k\←limit}$ \1\&{do}\6
\&{begin} \37$\|b\K\\{byte\←mem}[\|w,\39\|k]$;\5
$\\{incr}(\|k)$;\6
\&{if} $\|b=\.{"@"}$ \1\&{then}\5
\X216:Skip next character, give error if not `\.{@}'\X;\2\6
\&{if} $\|b\I\.{"|"}$ \1\&{then}\5
$\\{out}(\|b)$\6
\4\&{else} \&{begin} \37\X217:Copy the \PASCAL\ text into $\\{buffer}[(%
\\{limit}+1)\to\|j]$\X;\6
$\\{save\←loc}\K\\{loc}$;\5
$\\{save\←limit}\K\\{limit}$;\5
$\\{loc}\K\\{limit}+2$;\5
$\\{limit}\K\|j+1$;\5
$\\{buffer}[\\{limit}]\K\.{"|"}$;\5
\\{output\←PASCAL};\5
$\\{loc}\K\\{save\←loc}$;\5
$\\{limit}\K\\{save\←limit}$;\6
\&{end};\2\6
\&{end}\2\par
\U section~214.\fi

\M216. \P$\X216:Skip next character, give error if not `\.{@}'\X\S$\6
\&{begin} \37\&{if} $\\{byte\←mem}[\|w,\39\|k]\I\.{"@"}$ \1\&{then}\6
\&{begin} \37$\\{print\←nl}(\.{\'!\ Illegal\ control\ code\ in\ section\ name:%
\'})$;\5
$\\{print\←nl}(\.{\'<\'})$;\5
$\\{print\←id}(\\{cur\←mod\←name})$;\5
$\\{print}(\.{\'>\ \'})$;\5
\\{mark\←error};\6
\&{end};\2\6
$\\{incr}(\|k)$;\6
\&{end}\par
\U section~215.\fi

\M217. The \PASCAL\ text enclosed in \pb\ should not contain `\v' characters,
except within strings. We put a `\v' at the front of the buffer, so that an
error message that displays the whole buffer will look a little bit sensible.
The variable \\{string\←delimiter} is zero outside of strings, otherwise it
equals the delimiter that began the string being copied.

\Y\P$\4\X217:Copy the \PASCAL\ text into $\\{buffer}[(\\{limit}+1)\to\|j]$\X\S$%
\6
$\|j\K\\{limit}+1$;\5
$\\{buffer}[\|j]\K\.{"|"}$;\5
$\\{string\←delimiter}\K0$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\|k\G\\{k\←limit}$ \1\&{then}\6
\&{begin} \37$\\{print\←nl}(\.{\'!\ PASCAL\ text\ in\ section\ name\ didn\'}\.{%
\'t\ end:\'})$;\5
$\\{print\←nl}(\.{\'<\'})$;\5
$\\{print\←id}(\\{cur\←mod\←name})$;\5
$\\{print}(\.{\'>\ \'})$;\5
\\{mark\←error};\5
\&{goto} \37\\{found};\6
\&{end};\2\6
$\|b\K\\{byte\←mem}[\|w,\39\|k]$;\5
$\\{incr}(\|k)$;\6
\&{if} $\|b=\.{"@"}$ \1\&{then}\5
\X218:Copy a control code into the buffer\X\6
\4\&{else} \&{begin} \37\&{if} $(\|b=\.{""}\.{""})\V(\|b=\.{"\'"})$ \1\&{then}\6
\&{if} $\\{string\←delimiter}=0$ \1\&{then}\5
$\\{string\←delimiter}\K\|b$\6
\4\&{else} \&{if} $\\{string\←delimiter}=\|b$ \1\&{then}\5
$\\{string\←delimiter}\K0$;\2\2\2\6
\&{if} $(\|b\I\.{"|"})\V(\\{string\←delimiter}\I0)$ \1\&{then}\6
\&{begin} \37\&{if} $\|j>\\{long\←buf\←size}-3$ \1\&{then}\5
$\\{overflow}(\.{\'buffer\'})$;\2\6
$\\{incr}(\|j)$;\5
$\\{buffer}[\|j]\K\|b$;\6
\&{end}\6
\4\&{else} \&{goto} \37\\{found};\2\6
\&{end};\2\6
\&{end};\2\6
\4\\{found}: \37\par
\U section~215.\fi

\M218. \P$\X218:Copy a control code into the buffer\X\S$\6
\&{begin} \37\&{if} $\|j>\\{long\←buf\←size}-4$ \1\&{then}\5
$\\{overflow}(\.{\'buffer\'})$;\2\6
$\\{buffer}[\|j+1]\K\.{"@"}$;\5
$\\{buffer}[\|j+2]\K\\{byte\←mem}[\|w,\39\|k]$;\5
$\|j\K\|j+2$;\5
$\\{incr}(\|k)$;\6
\&{end}\par
\U section~217.\fi

\N219.  Phase two processing.
We have assembled enough pieces of the puzzle in order to be ready to specify
the processing in \.{WEAVE}'s main pass over the source file. Phase two
is analogous to phase one, except that more work is involved because we must
actually output the \TeX\ material instead of merely looking at the
\.{WEB} specifications.

\Y\P$\4\X219:Phase II: Read all the text again and translate it to \TeX\ form\X%
\S$\6
\\{reset\←input};\5
$\\{print\←nl}(\.{\'Writing\ the\ output\ file...\'})$;\5
$\\{module\←count}\K0$;\5
\\{copy\←limbo};\5
\\{finish\←line};\5
$\\{flush\←buffer}(0,\39\\{false})$;\C{insert a blank line, it looks nice}\6
\&{while} $\R\\{input\←has\←ended}$ \1\&{do}\5
\X221:Translate the \(current module\X\2\par
\U section~262\*.\fi

\M220. The output file will contain the control sequence \.{\\Y} between
non-null
sections of a module, e.g., between the \TeX\ and definition parts if both
are nonempty. This puts a little white space between the parts when they are
printed. However, we don't want \.{\\Y} to occur between two definitions
within a single module. The variables \\{out\←line} or \\{out\←ptr} will
change if a section is non-null, so the following macros `\\{save\←position}'
and `\\{emit\←space\←if\←needed}' are able to handle the situation:

\Y\P\D \37$\\{save\←position}\S\\{save\←line}\K\\{out\←line}$;\5
$\\{save\←place}\K\\{out\←ptr}$\par
\P\D \37$\\{emit\←space\←if\←needed}\S$\1\6
\&{if} $(\\{save\←line}\I\\{out\←line})\V(\\{save\←place}\I\\{out\←ptr})$ \1%
\&{then}\5
$\\{out2}(\.{"\\"})(\.{"Y"})$\2\2\par
\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{save\←line}: \37\\{integer};\C{former value of \\{out\←line}}\6
\4\\{save\←place}: \37\\{sixteen\←bits};\C{former value of \\{out\←ptr}}\par
\fi

\M221. \P$\X221:Translate the \(current module\X\S$\6
\&{begin} \37$\\{incr}(\\{module\←count})$;\6
\X222:Output the code for the beginning of a new module\X;\6
\\{save\←position};\6
\X223:Translate the \TeX\ part of the current module\X;\6
\X226:Translate the \(definition part of the current module\X;\6
\X231:Translate the \PASCAL\ part of the current module\X;\6
\X234:Show cross references to this module\X;\6
\X239:Output the code for the end of a module\X;\6
\&{end}\par
\U section~219.\fi

\M222. Modules beginning with the \.{WEB} control sequence `\.{@\ }' start in
the
output with the \TeX\ control sequence `\.{\\M}', followed by the module
number. Similarly, `\.{@*}' modules lead to the control sequence `\.{\\N}'.
If this is a changed module, we put \.{*} just before the module number.

\Y\P$\4\X222:Output the code for the beginning of a new module\X\S$\6
$\\{out}(\.{"\\"})$;\6
\&{if} $\\{buffer}[\\{loc}-1]\I\.{"*"}$ \1\&{then}\5
$\\{out}(\.{"M"})$\6
\4\&{else} \&{begin} \37$\\{out}(\.{"N"})$;\5
$\\{print}(\.{\'*\'},\39\\{module\←count}:1)$;\5
\\{update\←terminal};\C{print a progress report}\6
\&{end};\2\6
$\\{out\←mod}(\\{module\←count})$;\5
$\\{out2}(\.{"."})(\.{"\ "})$\par
\U section~221.\fi

\M223. In the \TeX\ part of a module, we simply copy the source text, except
that
index entries are not copied and \PASCAL\ text within \pb\ is translated.

\Y\P$\4\X223:Translate the \TeX\ part of the current module\X\S$\6
\1\&{repeat} \37$\\{next\←control}\K\\{copy\←TeX}$;\6
\&{case} $\\{next\←control}$ \1\&{of}\6
\4\.{"|"}: \37\&{begin} \37\\{init\←stack};\5
\\{output\←PASCAL};\6
\&{end};\6
\4\.{"@"}: \37$\\{out}(\.{"@"})$;\6
\4\\{octal}: \37\X224:Translate an octal constant appearing in \TeX\ text\X;\6
\4\\{hex}: \37\X225:Translate a hexadecimal constant appearing in \TeX\ text\X;%
\6
\4$\\{TeX\←string},\39\\{xref\←roman},\39\\{xref\←wildcard},\39\\{xref%
\←typewriter},\39\\{module\←name}$: \37\&{begin} \37$\\{loc}\K\\{loc}-2$;\5
$\\{next\←control}\K\\{get\←next}$;\C{skip to \.{@>}}\6
\&{if} $\\{next\←control}=\\{TeX\←string}$ \1\&{then}\5
$\\{err\←print}(\.{\'!\ TeX\ string\ should\ be\ in\ PASCAL\ text\ only\'})$;\2%
\6
\&{end};\6
\4$\\{begin\←comment},\39\\{end\←comment},\39\\{check\←sum},\39\\{thin\←space},%
\39\\{math\←break},\39\\{line\←break},\39\\{big\←line\←break},\39\\{no\←line%
\←break},\39\\{join},\39\\{pseudo\←semi}$: \37$\\{err\←print}(\.{\'!\ You\ can%
\'}\.{\'t\ do\ that\ in\ TeX\ text\'})$;\6
\4\&{othercases} \37\\{do\←nothing}\2\6
\&{endcases};\6
\4\&{until}\5
$\\{next\←control}\G\\{format}$\2\par
\U section~221.\fi

\M224. \P$\X224:Translate an octal constant appearing in \TeX\ text\X\S$\6
\&{begin} \37$\\{out3}(\.{"\\"})(\.{"O"})(\.{"\{"})$;\6
\&{while} $(\\{buffer}[\\{loc}]\G\.{"0"})\W(\\{buffer}[\\{loc}]\L\.{"7"})$ \1%
\&{do}\6
\&{begin} \37$\\{out}(\\{buffer}[\\{loc}])$;\5
$\\{incr}(\\{loc})$;\6
\&{end};\C{since $\\{buffer}[\\{limit}]=\.{"\ "}$, this loop will end}\2\6
$\\{out}(\.{"\}"})$;\6
\&{end}\par
\U section~223.\fi

\M225. \P$\X225:Translate a hexadecimal constant appearing in \TeX\ text\X\S$\6
\&{begin} \37$\\{out3}(\.{"\\"})(\.{"H"})(\.{"\{"})$;\6
\&{while} $((\\{buffer}[\\{loc}]\G\.{"0"})\W(\\{buffer}[\\{loc}]\L\.{"9"}))\V%
\30((\\{buffer}[\\{loc}]\G\.{"A"})\W(\\{buffer}[\\{loc}]\L\.{"F"}))$ \1\&{do}\6
\&{begin} \37$\\{out}(\\{buffer}[\\{loc}])$;\5
$\\{incr}(\\{loc})$;\6
\&{end};\2\6
$\\{out}(\.{"\}"})$;\6
\&{end}\par
\U section~223.\fi

\M226. When we get to the following code we have $\\{next\←control}\G%
\\{format}$, and
the token memory is in its initial empty state.

\Y\P$\4\X226:Translate the \(definition part of the current module\X\S$\6
\&{if} $\\{next\←control}\L\\{definition}$ \1\&{then}\C{definition part
non-empty}\6
\&{begin} \37\\{emit\←space\←if\←needed};\5
\\{save\←position};\6
\&{end};\2\6
\&{while} $\\{next\←control}\L\\{definition}$ \1\&{do}\C{\\{format} or %
\\{definition}}\6
\&{begin} \37\\{init\←stack};\6
\&{if} $\\{next\←control}=\\{definition}$ \1\&{then}\5
\X228:Start a macro definition\X\6
\4\&{else} \X229:Start a format definition\X;\2\6
\\{outer\←parse};\5
\\{finish\←PASCAL};\6
\&{end}\2\par
\U section~221.\fi

\M227. The \\{finish\←PASCAL} procedure outputs the translation of the current
scraps, preceded by the control sequence `\.{\\P}' and followed by the
control sequence `\.{\\par}'. It also restores the token and scrap
memories to their initial empty state.

A \\{force} token is appended to the current scraps before translation
takes place, so that the translation will normally end with \.{\\6} or
\.{\\7} (the \TeX\ macros for \\{force} and \\{big\←force}). This \.{\\6} or
\.{\\7} is replaced by the concluding \.{\\par} or by \.{\\Y\\par}.

\Y\P\4\&{procedure}\1\  \37\\{finish\←PASCAL};\C{finishes a definition or a %
\PASCAL\ part}\6
\4\&{var} \37\|p: \37\\{text\←pointer};\C{translation of the scraps}\2\6
\&{begin} \37$\\{out2}(\.{"\\"})(\.{"P"})$;\5
$\\{app\←tok}(\\{force})$;\5
\\{app\←comment};\5
$\|p\K\\{translate}$;\5
$\\{app}(\|p+\\{tok\←flag})$;\5
\\{make\←output};\C{output the list}\6
\&{if} $\\{out\←ptr}>1$ \1\&{then}\6
\&{if} $\\{out\←buf}[\\{out\←ptr}-1]=\.{"\\"}$ \1\&{then}\6
\&{if} $\\{out\←buf}[\\{out\←ptr}]=\.{"6"}$ \1\&{then}\5
$\\{out\←ptr}\K\\{out\←ptr}-2$\6
\4\&{else} \&{if} $\\{out\←buf}[\\{out\←ptr}]=\.{"7"}$ \1\&{then}\5
$\\{out\←buf}[\\{out\←ptr}]\K\.{"Y"}$;\2\2\2\2\6
$\\{out4}(\.{"\\"})(\.{"p"})(\.{"a"})(\.{"r"})$;\5
\\{finish\←line};\6
\&{stat} \37\&{if} $\\{text\←ptr}>\\{max\←txt\←ptr}$ \1\&{then}\5
$\\{max\←txt\←ptr}\K\\{text\←ptr}$;\2\6
\&{if} $\\{tok\←ptr}>\\{max\←tok\←ptr}$ \1\&{then}\5
$\\{max\←tok\←ptr}\K\\{tok\←ptr}$;\2\6
\&{if} $\\{scrap\←ptr}>\\{max\←scr\←ptr}$ \1\&{then}\5
$\\{max\←scr\←ptr}\K\\{scrap\←ptr}$;\2\6
\&{tats}\6
$\\{tok\←ptr}\K1$;\5
$\\{text\←ptr}\K1$;\5
$\\{scrap\←ptr}\K0$;\C{forget the tokens and the scraps}\6
\&{end};\par
\fi

\M228. \P$\X228:Start a macro definition\X\S$\6
\&{begin} \37$\\{sc2}(\.{"\\"})(\.{"D"})(\\{intro})$;\C{this will produce `%
\&{define }'}\6
$\\{next\←control}\K\\{get\←next}$;\6
\&{if} $\\{next\←control}\I\\{identifier}$ \1\&{then}\5
$\\{err\←print}(\.{\'!\ Improper\ macro\ definition\'})$\6
\4\&{else} $\\{sc1}(\\{id\←flag}+\\{id\←lookup}(\\{normal}))(\\{math})$;\2\6
$\\{next\←control}\K\\{get\←next}$;\6
\&{end}\par
\U section~226.\fi

\M229. \P$\X229:Start a format definition\X\S$\6
\&{begin} \37$\\{sc2}(\.{"\\"})(\.{"F"})(\\{intro})$;\C{this will produce `%
\&{format }'}\6
$\\{next\←control}\K\\{get\←next}$;\6
\&{if} $\\{next\←control}=\\{identifier}$ \1\&{then}\6
\&{begin} \37$\\{sc1}(\\{id\←flag}+\\{id\←lookup}(\\{normal}))(\\{math})$;\5
$\\{next\←control}\K\\{get\←next}$;\6
\&{if} $\\{next\←control}=\\{equivalence\←sign}$ \1\&{then}\6
\&{begin} \37$\\{sc2}(\.{"\\"})(\.{"S"})(\\{math})$;\C{output an equivalence
sign}\6
$\\{next\←control}\K\\{get\←next}$;\6
\&{if} $\\{next\←control}=\\{identifier}$ \1\&{then}\6
\&{begin} \37$\\{sc1}(\\{id\←flag}+\\{id\←lookup}(\\{normal}))(\\{math})$;\5
$\\{sc0}(\\{semi})$;\C{insert an invisible semicolon}\6
$\\{next\←control}\K\\{get\←next}$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\2\6
\&{if} $\\{scrap\←ptr}\I5$ \1\&{then}\5
$\\{err\←print}(\.{\'!\ Improper\ format\ definition\'})$;\2\6
\&{end}\par
\U section~226.\fi

\M230. Finally, when the \TeX\ and definition parts have been treated, we have
$\\{next\←control}\G\\{begin\←pascal}$. We will make the global variable %
\\{this\←module}
point to the current module name, if it has a name.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{this\←module}: \37\\{name\←pointer};\C{the current module name, or zero}%
\par
\fi

\M231. \P$\X231:Translate the \PASCAL\ part of the current module\X\S$\6
$\\{this\←module}\K0$;\6
\&{if} $\\{next\←control}\L\\{module\←name}$ \1\&{then}\6
\&{begin} \37\\{emit\←space\←if\←needed};\5
\\{init\←stack};\6
\&{if} $\\{next\←control}=\\{begin\←pascal}$ \1\&{then}\5
$\\{next\←control}\K\\{get\←next}$\6
\4\&{else} \&{begin} \37$\\{this\←module}\K\\{cur\←module}$;\5
\X232\*:Check that $=$ or $\S$ follows this module name, and emit the scraps to
start the module definition\X;\6
\&{end};\2\6
\&{while} $\\{next\←control}\L\\{module\←name}$ \1\&{do}\6
\&{begin} \37\\{outer\←parse};\5
\X233:Emit the scrap for a module name if present\X;\6
\&{end};\2\6
\\{finish\←PASCAL};\6
\&{end}\2\par
\U section~221.\fi

\M232\*. \P$\X232\*:Check that $=$ or $\S$ follows this module name, and emit
the scraps to start the module definition\X\S$\6
\1\&{repeat} \37$\\{next\←control}\K\\{get\←next}$;\6
\4\&{until}\5
$\\{next\←control}\I\.{"+"}$;\C{allow optional `\.{+=}'}\2\6
\&{if} $(\\{next\←control}\I\.{"="})\W(\\{next\←control}\I\\{equivalence%
\←sign})$ \1\&{then}\5
$\\{err\←print}(\.{\'!\ You\ need\ an\ =\ sign\ after\ the\ section\ name\'})$\6
\4\&{else} $\\{next\←control}\K\\{get\←next}$;\2\6
\&{if} $\\{out\←ptr}>1$ \1\&{then}\6
\&{if} $(\\{out\←buf}[\\{out\←ptr}]=\.{"Y"})\W(\\{out\←buf}[\\{out\←ptr}-1]=%
\.{"\\"})$ \1\&{then}\6
\&{begin} \37$\\{app}(\\{backup})$;\C{the module name will be flush left}\6
\&{end};\2\2\6
$\\{sc1}(\\{mod\←flag}+\\{this\←module})(\\{mod\←scrap})$;\5
$\\{cur\←xref}\K\\{xref}[\\{this\←module}]$;\5
$\\{mod\←count\←plus\←def\←flag}\K\\{module\←count}+\\{def\←flag}$;\6
\&{if} $\\{num}(\\{cur\←xref})\I\\{mod\←count\←plus\←def\←flag}$ \1\&{then}\6
\&{begin} \37$\\{sc3}(\\{math\←rel})(\.{"+"})(\.{"\}"})(\\{math})$;\C{module
name is multiply defined}\6
$\\{this\←module}\K0$;\C{so we won't give cross-reference info here}\6
\&{end};\2\6
$\\{sc2}(\.{"\\"})(\.{"S"})(\\{math})$;\C{output an equivalence sign}\6
$\\{sc1}(\\{force})(\\{semi})$;\C{this forces a line break unless `\.{@+}'
follows}\par
\U section~231.\fi

\M233. \P$\X233:Emit the scrap for a module name if present\X\S$\6
\&{if} $\\{next\←control}<\\{module\←name}$ \1\&{then}\6
\&{begin} \37$\\{err\←print}(\.{\'!\ You\ can\'}\.{\'t\ do\ that\ in\ PASCAL\
text\'})$;\5
$\\{next\←control}\K\\{get\←next}$;\6
\&{end}\6
\4\&{else} \&{if} $\\{next\←control}=\\{module\←name}$ \1\&{then}\6
\&{begin} \37$\\{sc1}(\\{mod\←flag}+\\{cur\←module})(\\{mod\←scrap})$;\5
$\\{next\←control}\K\\{get\←next}$;\6
\&{end}\2\2\par
\U section~231.\fi

\M234. Cross references relating to a named module are given after the module
ends.

\Y\P$\4\X234:Show cross references to this module\X\S$\6
\&{if} $\\{this\←module}>0$ \1\&{then}\6
\&{begin} \37\X236:Rearrange the list pointed to by \\{cur\←xref}\X;\6
$\\{footnote}(\\{def\←flag})$;\5
$\\{footnote}(0)$;\6
\&{end}\2\par
\U section~221.\fi

\M235. To rearrange the order of the linked list of cross references, we need
four more variables that point to cross reference entries.  We'll end up
with a list pointed to by \\{cur\←xref}.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4$\\{next\←xref},\39\\{this\←xref},\39\\{first\←xref},\39\\{mid\←xref}$: \37%
\\{xref\←number};\C{pointer variables for rearranging a list}\par
\fi

\M236. We want to rearrange the cross reference list so that all the entries
with
\\{def\←flag} come first, in ascending order; then come all the other
entries, in ascending order.  There may be no entries in either one or both
of these categories.

\Y\P$\4\X236:Rearrange the list pointed to by \\{cur\←xref}\X\S$\6
$\\{first\←xref}\K\\{xref}[\\{this\←module}]$;\5
$\\{this\←xref}\K\\{xlink}(\\{first\←xref})$;\C{bypass current module number}\6
\&{if} $\\{num}(\\{this\←xref})>\\{def\←flag}$ \1\&{then}\6
\&{begin} \37$\\{mid\←xref}\K\\{this\←xref}$;\5
$\\{cur\←xref}\K0$;\C{this value doesn't matter}\6
\1\&{repeat} \37$\\{next\←xref}\K\\{xlink}(\\{this\←xref})$;\5
$\\{xlink}(\\{this\←xref})\K\\{cur\←xref}$;\5
$\\{cur\←xref}\K\\{this\←xref}$;\5
$\\{this\←xref}\K\\{next\←xref}$;\6
\4\&{until}\5
$\\{num}(\\{this\←xref})\L\\{def\←flag}$;\2\6
$\\{xlink}(\\{first\←xref})\K\\{cur\←xref}$;\6
\&{end}\6
\4\&{else} $\\{mid\←xref}\K0$;\C{first list null}\2\6
$\\{cur\←xref}\K0$;\6
\&{while} $\\{this\←xref}\I0$ \1\&{do}\6
\&{begin} \37$\\{next\←xref}\K\\{xlink}(\\{this\←xref})$;\5
$\\{xlink}(\\{this\←xref})\K\\{cur\←xref}$;\5
$\\{cur\←xref}\K\\{this\←xref}$;\5
$\\{this\←xref}\K\\{next\←xref}$;\6
\&{end};\2\6
\&{if} $\\{mid\←xref}>0$ \1\&{then}\5
$\\{xlink}(\\{mid\←xref})\K\\{cur\←xref}$\6
\4\&{else} $\\{xlink}(\\{first\←xref})\K\\{cur\←xref}$;\2\6
$\\{cur\←xref}\K\\{xlink}(\\{first\←xref})$\par
\U section~234.\fi

\M237. The \\{footnote} procedure gives cross reference information about
multiply defined module names (if the \\{flag} parameter is \\{def\←flag}), or
about
the uses of a module name (if the \\{flag} parameter is zero). It assumes that
\\{cur\←xref} points to the first cross-reference entry of interest, and it
leaves \\{cur\←xref} pointing to the first element not printed.  Typical
outputs:
`\.{\\A\ section 101.}'; `\.{\\U\ sections 370 and 1009.}';
`\.{\\A\ sections 8, 27\\*, and 64.}'.

\Y\P\4\&{procedure}\1\  \37$\\{footnote}(\\{flag}:\\{sixteen\←bits})$;%
\C{outputs module cross-references}\6
\4\&{label} \37$\\{done},\39\\{exit}$;\6
\4\&{var} \37\|q: \37\\{xref\←number};\C{cross-reference pointer variable}\2\6
\&{begin} \37\&{if} $\\{num}(\\{cur\←xref})\L\\{flag}$ \1\&{then}\5
\&{return};\2\6
\\{finish\←line};\5
$\\{out}(\.{"\\"})$;\6
\&{if} $\\{flag}=0$ \1\&{then}\5
$\\{out}(\.{"U"})$\ \&{else} $\\{out}(\.{"A"})$;\2\6
$\\{out4}(\.{"\ "})(\.{"s"})(\.{"e"})(\.{"c"})$;\5
$\\{out4}(\.{"t"})(\.{"i"})(\.{"o"})(\.{"n"})$;\5
\X238:Output all the module numbers on the reference list \\{cur\←xref}\X;\6
$\\{out}(\.{"."})$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M238. The following code distinguishes three cases, according as the number
of cross references is one, two, or more than two. Variable \|q points
to the first cross reference, and the last link is a zero.

\Y\P$\4\X238:Output all the module numbers on the reference list \\{cur\←xref}%
\X\S$\6
$\|q\K\\{cur\←xref}$;\6
\&{if} $\\{num}(\\{xlink}(\|q))>\\{flag}$ \1\&{then}\5
$\\{out}(\.{"s"})$;\C{plural}\2\6
$\\{out}(\.{"\~"})$;\6
\~ \1\&{loop}\ \&{begin} \37$\\{out\←mod}(\\{num}(\\{cur\←xref})-\\{flag})$;\5
$\\{cur\←xref}\K\\{xlink}(\\{cur\←xref})$;\C{point to the next cross reference
to output}\6
\&{if} $\\{num}(\\{cur\←xref})\L\\{flag}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $(\\{num}(\\{xlink}(\\{cur\←xref}))>\\{flag})\V(\\{cur\←xref}\I%
\\{xlink}(\|q))$ \1\&{then}\5
$\\{out}(\.{","})$;\C{not the last of two}\2\6
$\\{out}(\.{"\ "})$;\6
\&{if} $\\{num}(\\{xlink}(\\{cur\←xref}))\L\\{flag}$ \1\&{then}\5
$\\{out4}(\.{"a"})(\.{"n"})(\.{"d"})(\.{"\~"})$;\C{the last}\2\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~237.\fi

\M239. \P$\X239:Output the code for the end of a module\X\S$\6
$\\{out3}(\.{"\\"})(\.{"f"})(\.{"i"})$;\5
\\{finish\←line};\5
$\\{flush\←buffer}(0,\39\\{false})$;\C{insert a blank line, it looks nice}\par
\U section~221.\fi

\N240.  Phase three processing.
We are nearly finished! \.{WEAVE}'s only remaining task is to write out the
index, after sorting the identifiers and index entries.

\Y\P$\4\X240:Phase III: Output the cross-reference index\X\S$\6
$\\{phase\←three}\K\\{true}$;\5
$\\{print\←nl}(\.{\'Writing\ the\ index...\'})$;\6
\&{if} $\\{change\←exists}$ \1\&{then}\6
\&{begin} \37\\{finish\←line};\5
\X242:Tell about changed modules\X;\6
\&{end};\2\6
\\{finish\←line};\5
$\\{out4}(\.{"\\"})(\.{"i"})(\.{"n"})(\.{"x"})$;\5
\\{finish\←line};\5
\X244:Do the first pass of sorting\X;\6
\X251:Sort and output the index\X;\6
$\\{out4}(\.{"\\"})(\.{"f"})(\.{"i"})(\.{"n"})$;\5
\\{finish\←line};\5
\X258:Output all the module names\X;\6
$\\{out4}(\.{"\\"})(\.{"c"})(\.{"o"})(\.{"n"})$;\5
\\{finish\←line};\5
$\\{print}(\.{\'Done.\'})$;\par
\U section~262\*.\fi

\M241. Just before the index comes a list of all the changed modules, including
the index module itself.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{k\←module}: \37$0\to\\{max\←modules}$;\C{runs through the modules}\par
\fi

\M242. \P$\X242:Tell about changed modules\X\S$\6
\&{begin} \37\C{remember that the index is already marked as changed}\6
$\\{k\←module}\K1$;\6
\&{while} $\R\\{changed\←module}[\\{k\←module}]$ \1\&{do}\5
$\\{incr}(\\{k\←module})$;\2\6
$\\{out4}(\.{"\\"})(\.{"c"})(\.{"h"})(\.{"\ "})$;\5
$\\{out\←mod}(\\{k\←module})$;\6
\1\&{repeat} \37\1\&{repeat} \37$\\{incr}(\\{k\←module})$\ \&{until}\5
$\\{changed\←module}[\\{k\←module}]$;\2\6
$\\{out2}(\.{","})(\.{"\ "})$;\5
$\\{out\←mod}(\\{k\←module})$;\6
\4\&{until}\5
$\\{k\←module}=\\{module\←count}$;\2\6
$\\{out}(\.{"."})$;\6
\&{end}\par
\U section~240.\fi

\M243. A left-to-right radix sorting method is used, since this makes it easy
to
adjust the collating sequence and since the running time will be at worst
proportional to the total length of all entries in the index. We put the
identifiers into 102 different lists based on their first characters.
(Uppercase letters are put into the same list as the corresponding lowercase
letters, since we want to have `$t<\\{TeX}<\&{to}$'.) The
list for character \|c begins at location $\\{bucket}[\|c]$ and continues
through
the \\{blink} array.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{bucket}: \37\&{array} $[\\{ASCII\←code}]$ \1\&{of}\5
\\{name\←pointer};\2\6
\4\\{next\←name}: \37\\{name\←pointer};\C{successor of \\{cur\←name} when
sorting}\6
\4\|c: \37\\{ASCII\←code};\C{index into \\{bucket}}\6
\4\|h: \37$0\to\\{hash\←size}$;\C{index into \\{hash}}\6
\4\\{blink}: \37\&{array} $[0\to\\{max\←names}]$ \1\&{of}\5
\\{sixteen\←bits};\C{links in the buckets}\2\par
\fi

\M244. To begin the sorting, we go through all the hash lists and put each
entry
having a nonempty cross-reference list into the proper bucket.

\Y\P$\4\X244:Do the first pass of sorting\X\S$\6
\&{for} $\|c\K0\mathrel{\&{to}}127$ \1\&{do}\5
$\\{bucket}[\|c]\K0$;\2\6
\&{for} $\|h\K0\mathrel{\&{to}}\\{hash\←size}-1$ \1\&{do}\6
\&{begin} \37$\\{next\←name}\K\\{hash}[\|h]$;\6
\&{while} $\\{next\←name}\I0$ \1\&{do}\6
\&{begin} \37$\\{cur\←name}\K\\{next\←name}$;\5
$\\{next\←name}\K\\{link}[\\{cur\←name}]$;\6
\&{if} $\\{xref}[\\{cur\←name}]\I0$ \1\&{then}\6
\&{begin} \37$\|c\K\\{byte\←mem}[\\{cur\←name}\mathbin{\&{mod}}\\{ww},\39%
\\{byte\←start}[\\{cur\←name}]]$;\6
\&{if} $(\|c\L\.{"Z"})\W(\|c\G\.{"A"})$ \1\&{then}\5
$\|c\K\|c+\O{40}$;\2\6
$\\{blink}[\\{cur\←name}]\K\\{bucket}[\|c]$;\5
$\\{bucket}[\|c]\K\\{cur\←name}$;\6
\&{end};\2\6
\&{end};\2\6
\&{end}\2\par
\U section~240.\fi

\M245. During the sorting phase we shall use the \\{cat} and \\{trans} arrays
from
\.{WEAVE}'s parsing algorithm and rename them \\{depth} and \\{head}. They now
represent a stack of identifier lists for all the index entries that have
not yet been output. The variable \\{sort\←ptr} tells how many such lists are
present; the lists are output in reverse order (first \\{sort\←ptr}, then
$\\{sort\←ptr}-1$, etc.). The \|jth list starts at $\\{head}[\|j]$, and if the
first
\|k characters of all entries on this list are known to be equal we have
$\\{depth}[\|j]=\|k$.

\Y\P\D \37$\\{depth}\S\\{cat}$\C{reclaims memory that is no longer needed for
parsing}\par
\P\D \37$\\{head}\S\\{trans}$\C{ditto}\par
\P\D \37$\\{sort\←ptr}\S\\{scrap\←ptr}$\C{ditto}\par
\P\D \37$\\{max\←sorts}\S\\{max\←scraps}$\C{ditto}\par
\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{cur\←depth}: \37\\{eight\←bits};\C{depth of current buckets}\6
\4\\{cur\←byte}: \37$0\to\\{max\←bytes}$;\C{index into \\{byte\←mem}}\6
\4\\{cur\←bank}: \37$0\to\\{ww}-1$;\C{row of \\{byte\←mem}}\6
\4\\{cur\←val}: \37\\{sixteen\←bits};\C{current cross reference number}\6
\&{stat} \37\\{max\←sort\←ptr}: \37$0\to\\{max\←sorts}$;\ \&{tats}\C{largest
value of \\{sort\←ptr}}\par
\fi

\M246. \P$\X10:Set initial values\X\mathrel{+}\S$\6
\&{stat} \37$\\{max\←sort\←ptr}\K0$;\ \&{tats}\par
\fi

\M247. The desired alphabetic order is specified by the \\{collate} array;
namely,
$\\{collate}[0]<\\{collate}[1]<\hbox{$\cdots$}<\\{collate}[100]$.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\4\\{collate}: \37\&{array} $[0\to100]$ \1\&{of}\5
\\{ASCII\←code};\C{collation order}\2\par
\fi

\M248. \P$\X16:Local variables for initialization\X\mathrel{+}\S$\6
\4\|c: \37\\{ASCII\←code};\C{used to initialize \\{collate}}\par
\fi

\M249. We use the order $\hbox{null}<\.\ <\hbox{other characters}<\.\←<
\.A=\.a<\cdots<\.Z=\.z<\.0<\cdots<\.9.$

\Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
$\\{collate}[0]\K0$;\5
$\\{collate}[1]\K\.{"\ "}$;\6
\&{for} $\|c\K1\mathrel{\&{to}}\.{"\ "}-1$ \1\&{do}\5
$\\{collate}[\|c+1]\K\|c$;\2\6
\&{for} $\|c\K\.{"\ "}+1\mathrel{\&{to}}\.{"0"}-1$ \1\&{do}\5
$\\{collate}[\|c]\K\|c$;\2\6
\&{for} $\|c\K\.{"9"}+1\mathrel{\&{to}}\.{"A"}-1$ \1\&{do}\5
$\\{collate}[\|c-10]\K\|c$;\2\6
\&{for} $\|c\K\.{"Z"}+1\mathrel{\&{to}}\.{"\←"}-1$ \1\&{do}\5
$\\{collate}[\|c-36]\K\|c$;\2\6
$\\{collate}[\.{"\←"}-36]\K\.{"\←"}+1$;\6
\&{for} $\|c\K\.{"z"}+1\mathrel{\&{to}}126$ \1\&{do}\5
$\\{collate}[\|c-63]\K\|c$;\2\6
$\\{collate}[64]\K\.{"\←"}$;\6
\&{for} $\|c\K\.{"a"}\mathrel{\&{to}}\.{"z"}$ \1\&{do}\5
$\\{collate}[\|c-\.{"a"}+65]\K\|c$;\2\6
\&{for} $\|c\K\.{"0"}\mathrel{\&{to}}\.{"9"}$ \1\&{do}\5
$\\{collate}[\|c-\.{"0"}+91]\K\|c$;\2\par
\fi

\M250. Procedure \\{unbucket} goes through the buckets and adds nonempty lists
to the stack, using the collating sequence specified in the \\{collate} array.
The parameter to \\{unbucket} tells the current depth in the buckets.
Any two sequences that agree in their first 255 character positions are
regarded as identical.

\Y\P\D \37$\\{infinity}=255$\C{$\infty$ (approximately)}\par
\Y\P\4\&{procedure}\1\  \37$\\{unbucket}(\|d:\\{eight\←bits})$;\C{empties
buckets having depth \|d}\6
\4\&{var} \37\|c: \37\\{ASCII\←code};\C{index into \\{bucket}}\2\6
\&{begin} \37\&{for} $\|c\K100\mathrel{\&{downto}}0$ \1\&{do}\6
\&{if} $\\{bucket}[\\{collate}[\|c]]>0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{sort\←ptr}>\\{max\←sorts}$ \1\&{then}\5
$\\{overflow}(\.{\'sorting\'})$;\2\6
$\\{incr}(\\{sort\←ptr})$;\6
\&{stat} \37\&{if} $\\{sort\←ptr}>\\{max\←sort\←ptr}$ \1\&{then}\5
$\\{max\←sort\←ptr}\K\\{sort\←ptr}$;\2\ \&{tats}\6
\&{if} $\|c=0$ \1\&{then}\5
$\\{depth}[\\{sort\←ptr}]\K\\{infinity}$\6
\4\&{else} $\\{depth}[\\{sort\←ptr}]\K\|d$;\2\6
$\\{head}[\\{sort\←ptr}]\K\\{bucket}[\\{collate}[\|c]]$;\5
$\\{bucket}[\\{collate}[\|c]]\K0$;\6
\&{end};\2\2\6
\&{end};\par
\fi

\M251. \P$\X251:Sort and output the index\X\S$\6
$\\{sort\←ptr}\K0$;\5
$\\{unbucket}(1)$;\6
\&{while} $\\{sort\←ptr}>0$ \1\&{do}\6
\&{begin} \37$\\{cur\←depth}\K\\{cat}[\\{sort\←ptr}]$;\6
\&{if} $(\\{blink}[\\{head}[\\{sort\←ptr}]]=0)\V(\\{cur\←depth}=\\{infinity})$ %
\1\&{then}\5
\X253:Output index entries for the list at \\{sort\←ptr}\X\6
\4\&{else} \X252:Split the list at \\{sort\←ptr} into further lists\X;\2\6
\&{end}\2\par
\U section~240.\fi

\M252. \P$\X252:Split the list at \\{sort\←ptr} into further lists\X\S$\6
\&{begin} \37$\\{next\←name}\K\\{head}[\\{sort\←ptr}]$;\6
\1\&{repeat} \37$\\{cur\←name}\K\\{next\←name}$;\5
$\\{next\←name}\K\\{blink}[\\{cur\←name}]$;\5
$\\{cur\←byte}\K\\{byte\←start}[\\{cur\←name}]+\\{cur\←depth}$;\5
$\\{cur\←bank}\K\\{cur\←name}\mathbin{\&{mod}}\\{ww}$;\6
\&{if} $\\{cur\←byte}=\\{byte\←start}[\\{cur\←name}+\\{ww}]$ \1\&{then}\5
$\|c\K0$\C{we hit the end of the name}\6
\4\&{else} \&{begin} \37$\|c\K\\{byte\←mem}[\\{cur\←bank},\39\\{cur\←byte}]$;\6
\&{if} $(\|c\L\.{"Z"})\W(\|c\G\.{"A"})$ \1\&{then}\5
$\|c\K\|c+\O{40}$;\2\6
\&{end};\2\6
$\\{blink}[\\{cur\←name}]\K\\{bucket}[\|c]$;\5
$\\{bucket}[\|c]\K\\{cur\←name}$;\6
\4\&{until}\5
$\\{next\←name}=0$;\2\6
$\\{decr}(\\{sort\←ptr})$;\5
$\\{unbucket}(\\{cur\←depth}+1)$;\6
\&{end}\par
\U section~251.\fi

\M253. \P$\X253:Output index entries for the list at \\{sort\←ptr}\X\S$\6
\&{begin} \37$\\{cur\←name}\K\\{head}[\\{sort\←ptr}]$;\6
\&{debug} \37\&{if} $\\{trouble\←shooting}$ \1\&{then}\5
\\{debug\←help};\2\ \&{gubed}\6
\1\&{repeat} \37$\\{out2}(\.{"\\"})(\.{":"})$;\5
\X254:Output the name at \\{cur\←name}\X;\6
\X255:Output the cross-references at \\{cur\←name}\X;\6
$\\{cur\←name}\K\\{blink}[\\{cur\←name}]$;\6
\4\&{until}\5
$\\{cur\←name}=0$;\2\6
$\\{decr}(\\{sort\←ptr})$;\6
\&{end}\par
\U section~251.\fi

\M254. \P$\X254:Output the name at \\{cur\←name}\X\S$\6
\&{case} $\\{ilk}[\\{cur\←name}]$ \1\&{of}\6
\4\\{normal}: \37\&{if} $\\{length}(\\{cur\←name})=1$ \1\&{then}\5
$\\{out2}(\.{"\\"})(\.{"|"})$\ \&{else} $\\{out2}(\.{"\\"})(\.{"\\"})$;\2\6
\4\\{roman}: \37\\{do\←nothing};\6
\4\\{wildcard}: \37$\\{out2}(\.{"\\"})(\.{"9"})$;\6
\4\\{typewriter}: \37$\\{out2}(\.{"\\"})(\.{"."})$;\6
\4\&{othercases} \37$\\{out2}(\.{"\\"})(\.{"\&"})$\2\6
\&{endcases};\6
$\\{out\←name}(\\{cur\←name})$\par
\U section~253.\fi

\M255. Section numbers that are to be underlined are enclosed in
`\.{\\[}$\,\ldots\,$\.]'.

\Y\P$\4\X255:Output the cross-references at \\{cur\←name}\X\S$\6
\X256:Invert the cross-reference list at \\{cur\←name}, making \\{cur\←xref}
the head\X;\6
\1\&{repeat} \37$\\{out2}(\.{","})(\.{"\ "})$;\5
$\\{cur\←val}\K\\{num}(\\{cur\←xref})$;\6
\&{if} $\\{cur\←val}<\\{def\←flag}$ \1\&{then}\5
$\\{out\←mod}(\\{cur\←val})$\6
\4\&{else} \&{begin} \37$\\{out2}(\.{"\\"})(\.{"["})$;\5
$\\{out\←mod}(\\{cur\←val}-\\{def\←flag})$;\5
$\\{out}(\.{"]"})$;\6
\&{end};\2\6
$\\{cur\←xref}\K\\{xlink}(\\{cur\←xref})$;\6
\4\&{until}\5
$\\{cur\←xref}=0$;\2\6
$\\{out}(\.{"."})$;\5
\\{finish\←line}\par
\U section~253.\fi

\M256. List inversion is best thought of as popping elements off one stack and
pushing them onto another. In this case \\{cur\←xref} will be the head of
the stack that we push things onto.

\Y\P$\4\X256:Invert the cross-reference list at \\{cur\←name}, making \\{cur%
\←xref} the head\X\S$\6
$\\{this\←xref}\K\\{xref}[\\{cur\←name}]$;\5
$\\{cur\←xref}\K0$;\6
\1\&{repeat} \37$\\{next\←xref}\K\\{xlink}(\\{this\←xref})$;\5
$\\{xlink}(\\{this\←xref})\K\\{cur\←xref}$;\5
$\\{cur\←xref}\K\\{this\←xref}$;\5
$\\{this\←xref}\K\\{next\←xref}$;\6
\4\&{until}\5
$\\{this\←xref}=0$\2\par
\U section~255.\fi

\M257. The following recursive procedure walks through the tree of module names
and
prints them.

\Y\P\4\&{procedure}\1\  \37$\\{mod\←print}(\|p:\\{name\←pointer})$;\C{print all
module names in subtree \|p}\2\6
\&{begin} \37\&{if} $\|p>0$ \1\&{then}\6
\&{begin} \37$\\{mod\←print}(\\{llink}[\|p])$;\6
$\\{out2}(\.{"\\"})(\.{":"})$;\6
$\\{tok\←ptr}\K1$;\5
$\\{text\←ptr}\K1$;\5
$\\{scrap\←ptr}\K0$;\5
\\{init\←stack};\5
$\\{app}(\|p+\\{mod\←flag})$;\5
\\{make\←output};\5
$\\{footnote}(0)$;\C{\\{cur\←xref} was set by \\{make\←output}}\6
\\{finish\←line};\6
$\\{mod\←print}(\\{rlink}[\|p])$;\6
\&{end};\2\6
\&{end};\par
\fi

\M258. \P$\X258:Output all the module names\X\S$\ $\\{mod\←print}(\\{root})$\par
\U section~240.\fi

\N259.  Debugging.
The \PASCAL\ debugger with which \.{WEAVE} was developed allows breakpoints
to be set, and variables can be read and changed, but procedures cannot be
executed. Therefore a `\\{debug\←help}' procedure has been inserted in the main
loops of each phase of the program; when \\{ddt} and \\{dd} are set to
appropriate
values, symbolic printouts of various tables will appear.

The idea is to set a breakpoint inside the \\{debug\←help} routine, at the
place of `\ignorespaces \\{breakpoint}: \unskip' below.  Then when
\\{debug\←help} is to be activated, set \\{trouble\←shooting} equal to %
\\{true}.
The \\{debug\←help} routine will prompt you for values of \\{ddt} and \\{dd},
discontinuing this when $\\{ddt}\L0$; thus you type $2n+1$ integers, ending
with zero or a negative number. Then control either passes to the
breakpoint, allowing you to look at and/or change variables (if you typed
zero), or you exit the routine (if you typed a negative value).

Another global variable, \\{debug\←cycle}, can be used to skip silently
past calls on \\{debug\←help}. If you set $\\{debug\←cycle}>1$, the program
stops
only every \\{debug\←cycle} times \\{debug\←help} is called; however,
any error stop will set \\{debug\←cycle} to zero.

\Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
\&{debug} \37\\{trouble\←shooting}: \37\\{boolean};\C{is \\{debug\←help}
wanted?}\6
\4\\{ddt}: \37\\{sixteen\←bits};\C{operation code for the \\{debug\←help}
routine}\6
\4\\{dd}: \37\\{sixteen\←bits};\C{operand in procedures performed by \\{debug%
\←help}}\6
\4\\{debug\←cycle}: \37\\{integer};\C{threshold for \\{debug\←help} stopping}\6
\4\\{debug\←skipped}: \37\\{integer};\C{we have skipped this many \\{debug%
\←help} calls}\6
\4\\{term\←in}: \37\\{text\←file};\C{the user's terminal as an input file}\6
\&{gubed}\par
\fi

\M260. The debugging routine needs to read from the user's terminal.
\Y\P$\4\X10:Set initial values\X\mathrel{+}\S$\6
\&{debug} \37$\\{trouble\←shooting}\K\\{true}$;\5
$\\{debug\←cycle}\K1$;\5
$\\{debug\←skipped}\K0$;\5
$\\{tracing}\K0$;\6
$\\{trouble\←shooting}\K\\{false}$;\5
$\\{debug\←cycle}\K99999$;\C{use these when it almost works}\6
$\\{reset}(\\{term\←in},\39\.{\'TTY:\'},\39\.{\'/I\'})$;\C{open \\{term\←in} as
the terminal, don't do a \\{get}}\6
\&{gubed}\par
\fi

\M261. \P\D \37$\\{breakpoint}=888$\C{place where a breakpoint is desirable}\par
\Y\P\&{debug} \37\&{procedure}\1\  \37\\{debug\←help};\C{routine to display
various things}\6
\4\&{label} \37$\\{breakpoint},\39\\{exit}$;\6
\4\&{var} \37\|k: \37\\{sixteen\←bits};\C{index into various arrays}\2\6
\&{begin} \37$\\{incr}(\\{debug\←skipped})$;\6
\&{if} $\\{debug\←skipped}<\\{debug\←cycle}$ \1\&{then}\5
\&{return};\2\6
$\\{debug\←skipped}\K0$;\6
\~ \1\&{loop}\ \&{begin} \37$\\{write}(\\{term\←out},\39\.{\'\#\'})$;\5
\\{update\←terminal};\C{prompt}\6
$\\{read}(\\{term\←in},\39\\{ddt})$;\C{read a list of integers}\6
\&{if} $\\{ddt}<0$ \1\&{then}\5
\&{return}\6
\4\&{else} \&{if} $\\{ddt}=0$ \1\&{then}\6
\&{begin} \37\&{goto} \37\\{breakpoint};\5
\]\C{go to every label at least once}\6
\4\\{breakpoint}: \37$\\{ddt}\K0$;\5
\]\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{read}(\\{term\←in},\39\\{dd})$;\6
\&{case} $\\{ddt}$ \1\&{of}\6
\41: \37$\\{print\←id}(\\{dd})$;\6
\42: \37$\\{print\←text}(\\{dd})$;\6
\43: \37\&{for} $\|k\K1\mathrel{\&{to}}\\{dd}$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{buffer}[\|k]])$;\2\6
\44: \37\&{for} $\|k\K1\mathrel{\&{to}}\\{dd}$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{mod\←text}[\|k]])$;\2\6
\45: \37\&{for} $\|k\K1\mathrel{\&{to}}\\{out\←ptr}$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{out\←buf}[\|k]])$;\2\6
\46: \37\&{for} $\|k\K1\mathrel{\&{to}}\\{dd}$ \1\&{do}\6
\&{begin} \37$\\{print\←cat}(\\{cat}[\|k])$;\5
$\\{print}(\.{\'\ \'})$;\6
\&{end};\2\6
\4\&{othercases} \37$\\{print}(\.{\'?\'})$\2\6
\&{endcases};\6
\&{end};\2\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\6
\&{gubed}\par
\fi

\N262\*.  The main program.
Let's put it all together now: \.{WEAVE} starts and ends here.

The main procedure has been split into three sub-procedures in order to
keep certain \PASCAL\ compilers from overflowing their capacity.

\Y\P\4\&{procedure}\1\  \37\\{Phase\←I};\2\6
\&{begin} \37\X110:Phase I: Read all the user's text and store the cross
references\X;\6
\&{end};\7
\4\&{procedure}\1\  \37\\{Phase\←II};\6
\4\&{var} \37\\{mod\←count\←plus\←def\←flag}: \37\\{sixteen\←bits};\2\6
\&{begin} \37\X219:Phase II: Read all the text again and translate it to \TeX\
form\X;\6
\&{end};\7
\4\&{procedure}\1\  \37\\{Phase\←III};\2\6
\&{begin} \37\X240:Phase III: Output the cross-reference index\X;\6
\&{end};\7
\&{begin} \37\\{initialize};\C{beginning of the main program}\6
$\\{print\←ln}(\\{banner})$;\C{print a ``banner line''}\6
\X65:Store all the reserved words\X;\6
\\{Phase\←I};\5
\\{Phase\←II};\5
\\{Phase\←III};\6
\X86:Check that all changes have been read\X;\6
\4\\{end\←of\←WEAVE}: \37\&{stat} \37\X263:Print statistics about memory usage%
\X;\ \&{tats}\6
$\\{file\←close}(\\{web\←file})$;\5
$\\{file\←close}(\\{change\←file})$;\5
$\\{file\←close}(\\{tex\←file})$;\5
\X264:Print the job \\{history}\X;\6
\\{new\←line};\6
\&{end}.\par
\fi

\M263. \P$\X263:Print statistics about memory usage\X\S$\6
$\\{print\←nl}(\.{\'Memory\ usage\ statistics:\ \'},\39\\{name\←ptr}:1,\39\.{\'%
\ names,\ \'},\39\\{xref\←ptr}:1,\39\.{\'\ cross\ references,\ \'},\39\\{byte%
\←ptr}[0]:1)$;\6
\&{for} $\\{cur\←bank}\K1\mathrel{\&{to}}\\{ww}-1$ \1\&{do}\5
$\\{print}(\.{\'+\'},\39\\{byte\←ptr}[\\{cur\←bank}]:1)$;\2\6
$\\{print}(\.{\'\ bytes;\'})$;\5
$\\{print\←nl}(\.{\'parsing\ required\ \'},\39\\{max\←scr\←ptr}:1,\39\.{\'\
scraps,\ \'},\39\\{max\←txt\←ptr}:1,\39\.{\'\ texts,\ \'},\39\\{max\←tok%
\←ptr}:1,\39\.{\'\ tokens,\ \'},\39\\{max\←stack\←ptr}:1,\39\.{\'\ levels;%
\'})$;\5
$\\{print\←nl}(\.{\'sorting\ required\ \'},\39\\{max\←sort\←ptr}:1,\39\.{\'\
levels.\'})$\par
\U section~262\*.\fi

\M264. Some implementations may wish to pass the \\{history} value to the
operating system so that it can be used to govern whether or not other
programs are started. Here we simply report the history to the user.

\Y\P$\4\X264:Print the job \\{history}\X\S$\6
\&{case} $\\{history}$ \1\&{of}\6
\4\\{spotless}: \37$\\{print\←nl}(\.{\'(No\ errors\ were\ found.)\'})$;\6
\4\\{harmless\←message}: \37$\\{print\←nl}(\.{\'(Did\ you\ see\ the\ warning\
message\ above?)\'})$;\6
\4\\{error\←message}: \37$\\{print\←nl}(\.{\'(Pardon\ me,\ but\ I\ think\ I\
spotted\ something\ wrong.)\'})$;\6
\4\\{fatal\←message}: \37$\\{print\←nl}(\.{\'(That\ was\ a\ fatal\ error,\ my\
friend.)\'})$;\2\6
\&{end}\C{there are no other cases}\par
\U section~262\*.\fi

\N265\*.  System-dependent changes.
Here at PARC, any Pascal output by Tangle must be transliterated into Cedar
by McCreight's PasMesa compiler before it can be executed.   Rather than
incorporate the funny features of Pascal-H into PasMesa, we instead here
declare some procedures \\{external} that we never intend to implement in
Pascal at all.  Instead, these procedures are written by hand in Cedar, and
are linked in with the translated Pascal program by the Cedar binding process.


\Y\P$\4\X265\*:External procedure declarations for things implemented directly
in Cedar\X\S$\6
\4\&{procedure}\1\  \37$\\{tty\←rewrite}(\mathop{\&{var}}\|f:\\{text\←file})$;\5
\\{external};\C{set up for output to terminal}\6
\4\&{procedure}\1\  \37$\\{file\←reset}(\mathop{\&{var}}\|f:\\{text\←file};\,%
\35\\{ext}:\\{alfa})$;\5
\\{external};\C{set up for input from file}\6
\4\&{procedure}\1\  \37$\\{file\←rewrite}(\mathop{\&{var}}\|f:\\{text\←file};\,%
\35\\{ext}:\\{alfa})$;\5
\\{external};\C{set up for output to file}\6
\4\&{procedure}\1\  \37$\\{file\←close}(\mathop{\&{var}}\|f:\\{text\←file})$;\5
\\{external};\C{close a file}\6
\4\&{function}\1\  \37$\\{file\←get\←pos}(\mathop{\&{var}}\|f:\\{text\←file})$:
\37\\{integer};\5
\\{external};\C{return character count}\par
\U section~2\*.\fi

\N266\*.  Index.
If you have read and understood the code for Phase III above, you know what
is in this index and how it got here. All modules in which an identifier is
used are listed with that identifier, except that reserved words are
indexed only when they appear in format definitions, and the appearances
of identifiers in module names are not indexed. Underlined entries
correspond to where the identifier was declared. Error messages, control
sequences put into the output, and a few
other things like ``recursion'' are indexed here too.
\fi


\ch 1\*, 2\*, 8\*, 12\*, 17\*, 21\*, 24\*, 26\*, 32\*, 48\*, 49\*, 128\*, 180%
\*, 232\*, 262\*, 265\*, 266\*.
\inx
\:\.{\\)}, 187.
\:\.{\\*}, 131.
\:\.{\\,}, 163, 164, 187.
\:\.{\\.}, 190, 254.
\:\.{\\:}, 253, 257.
\:\.{\\=}, 190.
\:\.{\\[}, 255.
\:\.{\\\ }, 187, 190, 194.
\:\.{\\\#}, 187, 190.
\:\.{\\\$}, 187, 190.
\:\.{\\\%}, 187, 190.
\:\.{\\\&}, 190, 210, 254.
\:\.{\\\'}, 190.
\:\.{\\\\}, 190, 210, 254.
\:\.{\\\↑}, 187, 190.
\:\.{\\\`}, 190.
\:\.{\\\{}, 190.
\:\.{\\\}}, 190.
\:\.{\\\~}, 190, 194.
\:\.{\\]}, 187.
\:\.{\\|}, 210, 254.
\:\.{\\\←}, 132, 190.
\:\.{\\A}, 237.
\:\.{\\ast}, 187.
\:\.{\\B}, 187.
\:\.{\\C}, 199.
\:\.{\\con}, 240.
\:\.{\\D}, 228.
\:\.{\\E}, 187.
\:\.{\\F}, 229.
\:\.{\\fi}, 239.
\:\.{\\fin}, 240.
\:\.{\\G}, 189.
\:\.{\\H}, 197, 225.
\:\.{\\I}, 189.
\:\.{\\in}, 187.
\:\.{\\inx}, 240.
\:\.{\\J}, 187.
\:\.{\\K}, 189.
\:\.{\\L}, 189.
\:\.{\\M}, 222.
\:\.{\\N}, 222.
\:\.{\\O}, 197, 224.
\:\.{\\P}, 213, 227.
\:\.{\\R}, 189.
\:\.{\\S}, 189, 229, 232\*.
\:\.{\\T}, 187.
\:\.{\\to}, 187.
\:\.{\\U}, 237.
\:\.{\\V}, 189.
\:\.{\\W}, 189.
\:\.{\\X}, 214.
\:\.{\\Y}, 213, 220, 227, 232\*.
\:\.{\\1}, 212, 213.
\:\.{\\2}, 212, 213.
\:\.{\\3}, 212, 213.
\:\.{\\4}, 212, 213.
\:\.{\\5}, 212, 213.
\:\.{\\6}, 212, 213, 227.
\:\.{\\7}, 212, 213, 227.
\:\.{\\9}, 254.
\:\.{\AT!1}, 89, 178.
\:\.{\AT!2}, 89, 178.
\:\|{a}, \[131], \[207], \[209].
\:\\{alfa}, 265\*.
\:\\{alpha}, \[141], 143, 144, 150, 193, 194.
\:\\{alpha\←cases}, 150, \[151].
\:\.{Ambiguous prefix}, 70.
\:\\{and\←sign}, \[15], 65, 189.
\:\\{app}, \[149], 152, 153, 154, 156, 157, 159, 160, 161, 162, 163, 164, 165,
166, 168, 169, 171, 181, 185, 187, 190, 191, 196, 197, 199, 208, 209, 227, 232%
\*, 257.
\:\\{app\←comment}, 184, 185, \[196], 198, 199, 227.
\:\\{app\←hex}, 184, 187, \[197].
\:\\{app\←octal}, 184, 187, \[197].
\:\\{app\←tok}, \[137], 138, 139, 149, 190, 191, 197, 198, 227.
\:\\{append\←xref}, \[51], 52.
\:\\{app1}, \[149], 152, 153, 154, 156, 157, 160, 161, 163, 164, 165, 166, 169,
171, 175, 181, 196.
\:\\{app2}, \[149], 154, 157, 159, 162, 164, 166, 168.
\:\\{app3}, \[149], 159, 165.
\:\\{array\←like}, \[42], 65, 192, 193.
\:{ASCII code}, 11, 87.
\:\\{ASCII\←code}, \[11], 13, 27, 28, 37, 66, 74, 88, 90, 92, 122, 128\*, 133,
137, 209, 243, 247, 248, 250.
\:\|{b}, \[123], \[209].
\:\\{backup}, \[142], 143, 144, 148, 161, 168, 193, 194, 209, 232\*.
\:\\{bal}, \[92], 93, \[113], \[137], 138, 139, \[199].
\:\\{banner}, \[1\*], 262\*.
\:\&{begin}, 3.
\:\\{begin\←comment}, \[87], 88, 98, 187, 223.
\:\\{begin\←like}, \[42], 65, 194.
\:\\{begin\←pascal}, \[87], 88, 118, 230, 231.
\:\\{beginning}, \[141], 143, 144, 151, 153, 165, 171, 194.
\:\\{big\←cancel}, \[142], 143, 148, 187, 209, 213.
\:\\{big\←force}, \[142], 143, 148, 187, 209, 213, 227.
\:\\{big\←line\←break}, \[87], 88, 187, 223.
\:\\{blink}, \[243], 244, 251, 252, 253.
\:\\{boolean}, 28, 29, 45, 72, 75, 94, 123, 144, 259.
\:\\{break}, 22.
\:\\{break\←out}, 126, 127, \[128\*].
\:\\{break\←space}, \[142], 144, 148, 153, 156, 157, 161, 165, 169, 171, 201,
209, 212, 213.
\:\\{breakpoint}, 259, \[261].
\:\\{bucket}, \[243], 244, 250, 252.
\:\\{buf\←size}, \[8\*], 28, 74, 75, 76, 80, 124.
\:\\{buffer}, \[27], 28, 31, 32\*, 56, 59, 60, 62, 63, 64, 75, 77, 79, 80, 81,
82, 83, 84, 85, 86, 90, 91, 92, 93, 94, 96, 98, 99, 100, 101, 104, 105, 107,
108, 111, 124, 133, 134, 135, 136, 137, 138, 183, 184, 190, 191, 197, 209, 215,
217, 218, 222, 224, 225, 261.
\:\\{byte\←mem}, 36, \[37], 38, 39, 40, 43, 44, 53, 59, 62, 63, 67, 68, 69, 70,
132, 209, 210, 215, 216, 217, 218, 244, 245, 252.
\:\\{byte\←ptr}, 38, \[39], 41, 63, 68, 263.
\:\\{byte\←start}, 36, \[37], 38, 39, 41, 44, 51, 56, 62, 63, 68, 69, 94, 115,
132, 210, 215, 244, 252.
\:\|{c}, \[67], \[70], \[88], \[90], \[91], \[92], \[96], \[133], \[135], %
\[137], \[141], \[173], \[175], \[243], \[248], \[250].
\:\\{cancel}, \[142], 143, 144, 148, 154, 156, 157, 160, 161, 163, 164, 165,
166, 194, 198, 201, 209, 212, 213.
\:\\{carriage\←return}, \[15], 17\*, 28.
\:\\{case\←head}, \[141], 144, 150, 154, 155, 163, 164, 166.
\:\\{case\←like}, \[42], 65, 194.
\:\\{casey}, \[141], 143, 144, 150, 154, 166, 194.
\:\\{cat}, \[145], 150, 151, 152, 153, 154, 155, 156, 157, 159, 160, 161, 162,
163, 164, 165, 166, 168, 169, 171, 173, 175, 177, 179, 180\*, 181, 182, 184,
185, 195, 196, 198, 245, 251, 261.
\:\.{Change file ended...}, 78, 80, 85.
\:\.{Change file entry did not match}, 86.
\:\\{change\←buffer}, \[74], 75, 76, 79, 80, 84, 86.
\:\\{change\←changing}, \[73], 80, 82, 85.
\:\\{change\←exists}, \[45], 110, 111, 240.
\:\\{change\←file}, \[2\*], \[23], 24\*, 32\*, 72, 74, 77, 78, 80, 85, 262\*.
\:\\{change\←limit}, \[74], 75, 76, 79, 80, 84, 86.
\:{changed modules}, 265\*.
\:\\{changed\←module}, \[45], 83, 110, 111, 131, 242.
\:\\{changing}, 32\*, \[72], 73, 74, 76, 80, 82, 83, 86.
\:\\{char}, 12\*, 14.
\:\\{char\←like}, \[42], 65, 192.
\:\\{check\←change}, \[80], 84.
\:\\{check\←sum}, \[87], 88, 187, 223.
\:\\{chr}, 12\*, 13, 17\*, 18.
\:\\{clause}, \[141], 143, 144, 150, 152, 154, 155, 157, 194.
\:\\{close}, \[141], 143, 144, 153, 154, 161, 163, 164, 165, 168, 187, 194.
\:\\{collate}, \[247], 248, 249, 250.
\:\\{colon}, \[141], 143, 144, 149, 152, 161, 164, 168, 171, 187.
\:\\{comment}, \[143].
\:\\{comment\←scrap}, \[185], 187.
\:\\{compress}, \[98].
\:\\{cond}, \[141], 143, 144, 150, 194.
\:\\{confusion}, \[34].
\:\\{const\←like}, \[42], 65, 192, 193.
\:\\{continue}, \[5], 76, 77.
\:\.{Control codes are forbidden...}, 107.
\:\.{Control text didn't end}, 107.
\:\\{control\←code}, \[88], 89, 91, 94, 101, 136.
\:\\{copy\←comment}, 133, \[137], 199.
\:\\{copy\←limbo}, \[133], 219.
\:\\{copy\←TeX}, 133, \[135], 223.
\:\\{count}, \[70].
\:\\{cur\←bank}, \[245], 252, 263.
\:\\{cur\←byte}, \[245], 252.
\:\\{cur\←depth}, \[245], 251, 252.
\:\\{cur\←end}, 202, \[203], 205, 206, 207.
\:\\{cur\←mod\←name}, \[209], 215, 216, 217.
\:\\{cur\←mode}, 202, \[203], 205, 207, 209, 212, 213.
\:\\{cur\←module}, \[94], 102, 118, 231, 233.
\:\\{cur\←name}, \[64], 207, 210, 214, 215, 243, 244, 252, 253, 254, 256.
\:\\{cur\←state}, \[203], 205, 206.
\:\\{cur\←tok}, 202, \[203], 205, 206, 207.
\:\\{cur\←val}, \[245], 255.
\:\\{cur\←xref}, \[119], 120, 214, 232\*, 235, 236, 237, 238, 255, 256, 257.
\:\|{d}, \[96], \[128\*], \[173], \[175], \[250].
\:\\{dd}, \[259], 261.
\:\\{ddt}, \[259], 261.
\:\&{debug}, \[3], \[4], \[30], \[31], \[89], \[96], \[141], \[147], \[149], %
\[178], \[179], \[182], \[183], \[207], \[253], \[259], \[260], \[261].
\:\\{debug\←cycle}, 31, \[259], 260, 261.
\:\\{debug\←help}, \[30], 31, 96, 207, 253, 259, \[261].
\:\\{debug\←skipped}, 31, \[259], 260, 261.
\:\\{decr}, \[6], 28, 93, 99, 104, 123, 128\*, 131, 136, 138, 139, 206, 252,
253.
\:\\{def\←flag}, \[46], 48\*, 49\*, 51, 52, 94, 101, 112, 114, 116, 118, 120,
131, 214, 232\*, 234, 236, 237, 255.
\:\\{definition}, \[87], 88, 116, 226.
\:\\{depth}, \[245], 250.
\:\\{dig}, \[130], 131.
\:\\{div\←like}, \[42], 65, 192, 193.
\:\\{do\←like}, \[42], 65, 192, 193.
\:\\{do\←nothing}, \[6], 96, 114, 150, 151, 187, 190, 223, 254.
\:\\{done}, \[5], 76, 77, 91, 92, 93, 96, 104, 105, 123, 135, 136, 137, 138,
139, 176, 180\*, 237, 238.
\:\.{Double \AT! required...}, 134.
\:\.{Double \AT! should be used...}, 190.
\:\\{double\←dot}, \[87], 98, 187.
\:\\{easy\←cases}, 184, 186, \[187].
\:\\{eight\←bits}, \[36], 59, 88, 91, 92, 96, 109, 113, 123, 135, 137, 141,
145, 173, 175, 179, 199, 207, 209, 245, 250.
\:\&{else}, 7.
\:\\{else\←like}, \[42], 65, 194.
\:\\{elsie}, \[141], 143, 144, 150, 157, 194.
\:\\{emit\←space\←if\←needed}, \[220], 226, 231.
\:\&{end}, 3, 7.
\:\\{end\←comment}, \[87], 88, 98, 187, 223.
\:\\{end\←field}, \[202], 203.
\:\\{end\←like}, \[42], 65, 194.
\:\\{end\←of\←WEAVE}, \[2\*], 33, 262\*.
\:\\{end\←translation}, \[142], 148, 202, 208, 209, 213.
\:\&{endcases}, \[7].
\:\\{eof}, 28.
\:\\{eoln}, 28.
\:\\{equal}, \[67], 68, 69.
\:\\{equivalence\←sign}, \[15], 98, 117, 189, 229, 232\*.
\:\\{err\←print}, \[31], 67, 70, 73, 77, 78, 80, 81, 85, 86, 88, 100, 104, 105,
107, 108, 134, 137, 138, 190, 198, 223, 228, 229, 232\*, 233.
\:\\{error}, 28, \[31], 33.
\:\\{error\←message}, \[9], 264.
\:\\{exit}, \[5], 6, 51, 75, 76, 80, 90, 112, 124, 128\*, 133, 184, 209, 237,
261.
\:\\{exp}, \[141], 143, 144, 150, 187.
\:\\{exponent}, \[94], 99, 187.
\:\\{ext}, 265\*.
\:\\{extension}, \[67], 69, 70.
\:\\{external}, 265\*.
\:\.{Extra \AT!>}, 88.
\:\|{f}, \[28], \[265\*].
\:\\{false}, 28, 29, 73, 74, 75, 80, 82, 95, 97, 110, 111, 123, 124, 128\*,
219, 239, 260.
\:\\{fatal\←error}, \[33], 34, 35.
\:\\{fatal\←message}, \[9], 264.
\:\\{file\←close}, 262\*, \[265\*].
\:\\{file\←get\←pos}, 32\*, \[265\*].
\:\\{file\←reset}, 24\*, \[265\*].
\:\\{file\←rewrite}, 26\*, \[265\*].
\:\\{final\←limit}, \[28].
\:\\{finish\←line}, \[124], 125, 133, 135, 136, 213, 219, 227, 237, 239, 240,
255, 257.
\:\\{finish\←PASCAL}, 226, \[227], 231.
\:\\{first\←text\←char}, \[12\*], 18.
\:\\{first\←xref}, \[235], 236.
\:\\{five\←cases}, 150, \[151].
\:\\{flag}, \[237], 238.
\:\\{flush\←buffer}, \[123], 124, 128\*, 129, 219, 239.
\:\\{footnote}, 234, \[237], 257.
\:\\{for\←like}, \[42], 65, 192, 193.
\:\\{force}, \[142], 143, 144, 147, 148, 154, 156, 157, 161, 162, 168, 187,
193, 194, 199, 201, 209, 213, 227, 232\*.
\:\\{force\←line}, \[87], 88, 187.
\:\\{form\←feed}, \[15], 28.
\:\\{format}, \[87], 88, 112, 113, 114, 116, 184, 199, 223, 226.
\:\\{forward}, 30, 208.
\:\\{found}, \[5], 59, 61, 62, 67, 96, 97, 149, 150, 151, 152, 176, 180\*, 209,
217.
\:\\{freeze\←text}, \[172], 173, 181, 185, 196, 199, 209.
\:\\{get}, 28, 260.
\:\\{get\←line}, 72, \[83], 90, 91, 92, 96, 104, 124, 133, 135, 137.
\:\\{get\←next}, 94, \[96], 109, 112, 114, 116, 117, 118, 184, 223, 228, 229,
231, 232\*, 233.
\:\\{get\←output}, \[207], 208, 209, 212, 213.
\:\\{goto\←like}, \[42], 65, 192, 193.
\:\\{greater}, \[67], 69, 70.
\:\\{greater\←or\←equal}, \[15], 98, 189.
\:\&{gubed}, \[3].
\:\|{h}, \[57], \[59], \[243].
\:\\{harmless\←message}, \[9], 264.
\:\\{hash}, 38, \[56], 58, 61, 243, 244.
\:\\{hash\←size}, \[8\*], 56, 57, 58, 59, 60, 243, 244.
\:\\{head}, \[245], 250, 251, 252, 253.
\:\\{hex}, \[87], 88, 101, 187, 223.
\:\\{hi\←ptr}, \[145], 177, 179, 180\*.
\:\\{history}, \[9], 10, 264.
\:\.{Hmm... n of the preceding...}, 81.
\:\|{i}, \[16], \[59], \[173], \[175], \[180\*].
\:\\{id\←first}, \[56], 59, 60, 62, 63, 64, 94, 99, 100, 107, 108, 190, 191.
\:\\{id\←flag}, \[147], 193, 207, 228, 229.
\:\\{id\←loc}, \[56], 59, 60, 62, 63, 65, 94, 99, 100, 107, 108, 190, 191.
\:\\{id\←lookup}, 56, \[59], 64, 94, 112, 114, 117, 192, 228, 229.
\:\\{identifier}, \[94], 99, 112, 114, 117, 186, 207, 209, 210, 228, 229.
\:\\{id2}, \[64], 65.
\:\\{id3}, \[64], 65.
\:\\{id4}, \[64], 65.
\:\\{id5}, \[64], 65.
\:\\{id6}, \[64], 65.
\:\\{id7}, \[64], 65.
\:\\{id8}, \[64], 65.
\:\\{id9}, \[64], 65.
\:\\{if\←like}, \[42], 65, 194.
\:\\{ignore}, \[87], 88, 89, 187.
\:\\{ilk}, 36, \[37], 42, 43, 56, 59, 61, 63, 112, 117, 192, 193, 254.
\:\.{Illegal control code...}, 216.
\:\.{Illegal use of \AT!...}, 138.
\:\.{Improper format definition}, 229.
\:\.{Improper macro definition}, 228.
\:\\{in\←like}, \[42].
\:\.{Incompatible section names}, 67.
\:\\{incr}, \[6], 28, 51, 60, 62, 63, 68, 69, 70, 77, 78, 80, 84, 85, 90, 91,
92, 93, 96, 98, 99, 100, 101, 104, 105, 107, 108, 111, 123, 126, 131, 134, 136,
137, 138, 149, 150, 151, 172, 177, 185, 190, 197, 205, 207, 215, 216, 217, 218,
221, 224, 225, 242, 250, 261.
\:\\{indent}, \[142], 143, 144, 148, 152, 161, 166, 194, 209.
\:\\{infinity}, \[250], 251.
\:\\{init\←stack}, \[203], 223, 226, 231, 257.
\:\\{initialize}, \[2\*], 262\*.
\:\\{inner}, 201, \[202], 207, 213.
\:\\{inner\←tok\←flag}, \[147], 199, 207, 208.
\:\.{Input ended in mid-comment}, 137.
\:\.{Input ended in section name}, 104.
\:\.{Input line too long}, 28.
\:\\{input\←has\←ended}, \[72], 80, 82, 84, 90, 91, 92, 96, 104, 110, 133, 135,
137, 219.
\:\\{input\←ln}, \[28], 77, 78, 80, 84, 85.
\:\\{integer}, 14, 72, 80, 122, 131, 173, 175, 220, 259, 265\*.
\:\\{intro}, \[141], 143, 144, 149, 151, 158, 161, 163, 164, 166, 168, 171,
193, 194, 228, 229.
\:\|{j}, \[67], \[70], \[96], \[123], \[147], \[173], \[175], \[180\*], \[184],
\[209].
\:\\{join}, \[87], 88, 187, 223.
\:\\{jump\←out}, 2\*, \[33].
\:\|{k}, \[31], \[44], \[59], \[67], \[70], \[75], \[76], \[80], \[96], \[123],
\[124], \[128\*], \[131], \[132], \[173], \[175], \[179], \[209], \[261].
\:\\{k\←limit}, \[209], 215, 217.
\:\\{k\←module}, \[241], 242.
\:\|{l}, \[31], \[59], \[67], \[70].
\:\\{last\←text\←char}, \[12\*], 16, 18.
\:\\{lbrace}, \[147], 148.
\:\\{left\←arrow}, \[15], 98, 189.
\:\\{length}, \[38], 61, 210, 254.
\:\\{less}, \[67], 68, 69, 70.
\:\\{less\←or\←equal}, \[15], 98, 189.
\:\\{lhs}, \[115], 117.
\:\\{limit}, 28, 32\*, \[72], 75, 77, 78, 79, 81, 82, 83, 84, 85, 86, 90, 91,
92, 96, 98, 100, 104, 107, 108, 124, 133, 134, 135, 136, 137, 209, 215, 217,
224.
\:\\{line}, 32\*, \[72], 73, 77, 78, 80, 82, 84, 85, 86, 183.
\:\.{Line had to be broken}, 129.
\:\\{line\←break}, \[87], 88, 187, 223.
\:\\{line\←feed}, \[15], 28.
\:\\{line\←length}, \[8\*], 122, 123, 126, 128\*.
\:\\{lines\←dont\←match}, \[75], 80.
\:\\{link}, 36, \[37], 38, 43, 61, 244.
\:\\{llink}, \[43], 67, 68, 70, 120, 257.
\:\\{lo\←ptr}, \[145], 173, 176, 177, 179, 180\*, 181, 182.
\:\\{loc}, 28, 32\*, \[72], 77, 81, 82, 83, 85, 86, 90, 91, 92, 93, 96, 98, 99,
100, 101, 104, 105, 107, 108, 111, 114, 133, 134, 135, 136, 137, 138, 183, 197,
209, 215, 222, 223, 224, 225.
\:\\{long\←buf\←size}, \[8\*], 27, 28, 31, 56, 59, 72, 184, 209, 217, 218.
\:\\{longest\←name}, \[8\*], 66, 67, 70, 96, 104, 106.
\:\&{loop}, \[6].
\:\\{loop\←like}, \[42], 65, 194.
\:\|{m}, \[51], \[131].
\:\\{make\←output}, \[208], \[209], 214, 227, 257.
\:\\{mark\←error}, \[9], 31, 216, 217.
\:\\{mark\←fatal}, \[9], 33.
\:\\{mark\←harmless}, \[9], 106, 120, 129, 182, 183.
\:\\{math}, 140, \[141], 143, 144, 149, 151, 152, 159, 161, 163, 164, 168, 171,
180\*, 181, 187, 189, 193, 228, 229, 232\*.
\:\\{math\←bin}, \[142], 143, 148, 193, 209, 211.
\:\\{math\←break}, \[87], 88, 187, 223.
\:\\{math\←op}, \[142], 144, 148, 163, 164, 209.
\:\\{math\←rel}, \[142], 143, 147, 148, 193, 209, 211, 232\*.
\:\\{max\←bytes}, \[8\*], 37, 39, 44, 59, 63, 67, 68, 70, 132, 209, 245.
\:\\{max\←modules}, \[8\*], 45, 46, 111, 241.
\:\\{max\←names}, \[8\*], 37, 38, 63, 68, 70, 243.
\:\\{max\←refs}, \[8\*], 47, 51.
\:\\{max\←scr\←ptr}, \[145], 146, 188, 198, 200, 227, 263.
\:\\{max\←scraps}, \[8\*], 145, 173, 175, 179, 180\*, 188, 198, 200, 245.
\:\\{max\←sort\←ptr}, \[245], 246, 250, 263.
\:\\{max\←sorts}, \[245], 250.
\:\\{max\←stack\←ptr}, \[203], 204, 205, 263.
\:\\{max\←texts}, \[8\*], 53, 176, 180\*, 188, 200.
\:\\{max\←tok\←ptr}, \[54], 55, 176, 188, 200, 208, 227, 263.
\:\\{max\←toks}, \[8\*], 54, 137, 147, 176, 180\*, 181, 188, 190, 199, 200.
\:\\{max\←txt\←ptr}, \[54], 55, 176, 188, 200, 208, 227, 263.
\:\\{mid\←xref}, \[235], 236.
\:\.{Missing "|"...}, 198.
\:\\{mod\←check}, \[120], 121.
\:\\{mod\←count\←plus\←def\←flag}, 232\*, \[262\*].
\:\\{mod\←flag}, \[147], 207, 232\*, 233, 257.
\:\\{mod\←lookup}, 66, \[67], 102, 103.
\:\\{mod\←name}, \[207], 209.
\:\\{mod\←print}, \[257], 258.
\:\\{mod\←scrap}, \[141], 143, 144, 150, 168, 232\*, 233.
\:\\{mod\←text}, \[66], 67, 68, 69, 70, 96, 102, 103, 104, 105, 106, 261.
\:\\{mod\←xref\←switch}, 46, \[49\*], 50, 52, 118.
\:\\{mode}, \[202], 209.
\:\\{mode\←field}, \[202], 203.
\:\\{module\←count}, \[45], 51, 52, 83, 110, 111, 182, 219, 221, 222, 232\*,
242.
\:\\{module\←name}, \[87], 88, 94, 101, 114, 118, 223, 231, 233.
\:\|{n}, \[51], \[80], \[179].
\:\.{Name does not match}, 70.
\:\\{name\←pointer}, \[38], 39, 44, 51, 52, 59, 64, 67, 70, 94, 112, 115, 120,
132, 145, 184, 193, 209, 230, 243, 257.
\:\\{name\←ptr}, 38, \[39], 41, 44, 59, 61, 63, 68, 263.
\:\.{Never defined: <section name>}, 120.
\:\.{Never used: <section name>}, 120.
\:\\{new\←line}, \[20], 31, 32\*, 33, 129, 262\*.
\:\\{new\←mod\←xref}, \[52], 118.
\:\\{new\←module}, \[87], 88, 91, 96, 135.
\:\\{new\←xref}, \[51], 112, 114, 117.
\:\\{next\←control}, \[109], 112, 113, 114, 116, 117, 118, 184, 186, 187, 190,
192, 198, 199, 208, 223, 226, 228, 229, 230, 231, 232\*, 233.
\:\\{next\←name}, \[243], 244, 252.
\:\\{next\←xref}, \[235], 236, 256.
\:\&{nil}, 6.
\:\\{nil\←like}, \[42], 65, 192, 193.
\:\\{no\←line\←break}, \[87], 88, 187, 223.
\:\\{no\←underline}, \[87], 88, 101, 114.
\:\\{normal}, \[42], 59, 61, 112, 117, 192, 193, 228, 229, 254.
\:\\{not\←equal}, \[15], 98, 189.
\:\\{not\←found}, \[5].
\:\\{not\←sign}, \[15], 65, 189.
\:\\{num}, \[46], 50, 51, 52, 120, 214, 232\*, 236, 237, 238, 255.
\:\\{num\←field}, 46, \[48\*].
\:\\{octal}, \[87], 88, 187, 223.
\:\\{omega}, \[141], 143, 144, 152, 193, 194, 196.
\:\\{oot}, \[126].
\:\\{oot1}, \[126].
\:\\{oot2}, \[126].
\:\\{oot3}, \[126].
\:\\{oot4}, \[126].
\:\\{oot5}, \[126].
\:\\{open}, 140, \[141], 143, \[144], 151, 187.
\:\\{open\←input}, \[24\*], 82.
\:\\{opt}, 140, \[142], 143, 144, 148, 160, 164, 187, 209, 212.
\:\\{or\←sign}, \[15], 65, 189.
\:\\{ord}, 13.
\:\\{other\←line}, \[72], 73, 82, 86.
\:\&{othercases}, \[7].
\:\\{others}, 7.
\:\\{out}, \[126], 131, 132, 134, 136, 209, 210, 211, 212, 213, 214, 215, 222,
223, 224, 225, 237, 238, 242, 255.
\:\\{out\←buf}, \[122], 123, 125, 126, 127, 128\*, 129, 213, 227, 232\*, 261.
\:\\{out\←line}, \[122], 123, 125, 129, 220.
\:\\{out\←mod}, \[131], 214, 222, 238, 242, 255.
\:\\{out\←name}, \[132], 210, 254.
\:\\{out\←ptr}, \[122], 123, 124, 125, 126, 128\*, 129, 136, 213, 220, 227, 232%
\*, 261.
\:\\{outdent}, \[142], 144, 148, 154, 156, 157, 161, 163, 164, 165, 209.
\:\\{outer}, 201, \[202], 203, 212, 213.
\:\\{outer\←parse}, \[199], 226, 231.
\:\\{outer\←xref}, \[113], 116, 118, 199.
\:\\{output\←PASCAL}, \[208], 215, 223.
\:\\{output\←state}, \[202], 203.
\:\\{out2}, \[126], 131, 211, 212, 213, 214, 220, 222, 227, 242, 253, 254, 255,
257.
\:\\{out3}, \[126], 211, 224, 225, 239.
\:\\{out4}, \[126], 227, 237, 238, 240, 242.
\:\\{out5}, \[126], 211.
\:\\{overflow}, \[35], 51, 63, 68, 111, 137, 176, 181, 188, 200, 205, 217, 218,
250.
\:\|{p}, \[44], \[51], \[52], \[59], \[67], \[70], \[112], \[120], \[132], %
\[147], \[184], \[193], \[198], \[199], \[205], \[227].
\:\\{param}, \[87].
\:\.{PASCAL text...didn't end}, 217.
\:\\{PASCAL\←parse}, \[184], 187, 193, 197, 198, 199.
\:\\{PASCAL\←translate}, \[198], 199, 208.
\:\\{PASCAL\←xref}, \[112], 113, 114, 184, 199.
\:\\{per\←cent}, \[123].
\:\\{Phase\←I}, \[262\*].
\:\\{Phase\←II}, \[262\*].
\:\\{Phase\←III}, \[262\*].
\:\\{phase\←one}, \[29], 31, 110.
\:\\{phase\←three}, \[29], 110, 214, 240.
\:\\{pop\←level}, \[206], 207.
\:\\{pp}, \[145], 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 174, 176, 177, 179, 180%
\*.
\:\\{prefix}, \[67], 69.
\:\\{prefix\←lookup}, \[70], 102.
\:\\{prime\←the\←change\←buffer}, \[76], 82, 85.
\:\\{print}, \[20], 31, 32\*, 33, 44, 106, 111, 120, 129, 141, 147, 148, 179,
182, 183, 216, 217, 222, 240, 261, 263.
\:\\{print\←cat}, \[141], 179, 182, 261.
\:\\{print\←id}, \[44], 120, 147, 216, 217, 261.
\:\\{print\←ln}, \[20], 32\*, 129, 182, 262\*.
\:\\{print\←nl}, \[20], 28, 106, 120, 129, 179, 182, 183, 216, 217, 219, 240,
263, 264.
\:\\{print\←text}, \[147], 261.
\:\\{proc}, \[141], 143, \[144], 150, 163, 164, 165, 194.
\:\\{proc\←like}, \[42], 65, 112, 194.
\:\\{prod}, 149, \[179], 184.
\:\\{production}, \[149].
\:\\{production\←end}, \[149].
\:{productions, table of}, 144.
\:\\{pseudo\←semi}, \[87], 88, 187, 223.
\:\\{push\←level}, \[205], 207, 209.
\:\|{q}, \[51], \[52], \[67], \[70], \[199], \[237].
\:\|{r}, \[52], \[70], \[147].
\:\\{rbrace}, \[147].
\:\\{read}, 261.
\:\\{read\←ln}, \[2\*], 28.
\:\\{readln}, 2\*.
\:\\{record\←head}, \[141], 143, 144, 150, 194.
\:\\{record\←like}, \[42], 65, 194.
\:{recursion}, 120, 208, 257.
\:\\{red}, 149, \[173], 175.
\:\\{reduce}, \[149], 152, 153, 154, 156, 157, 159, 160, 161, 162, 163, 164,
165, 166, 168, 169, 171, 173, 179.
\:\\{repeat\←like}, \[42], 65, 194.
\:\\{res\←flag}, \[147], 193, 194, 207.
\:\\{res\←word}, \[207], 209, 210.
\:\\{reserved}, \[42], 51, 61.
\:\\{reset}, 260.
\:\\{reset\←input}, \[82], 110, 219.
\:\\{restart}, \[5], 83, 96, 101, 207.
\:\\{reswitch}, \[5], 184, 186, 192, 209, 213.
\:\&{return}, 5, \[6].
\:\\{rhs}, \[115], 117.
\:\\{rlink}, \[43], 67, 68, 70, 120, 257.
\:\\{roman}, \[42], 112, 254.
\:\\{root}, \[43], 67, 70, 121, 258.
\:\\{save\←base}, \[198].
\:\\{save\←limit}, \[209], 215.
\:\\{save\←line}, \[220].
\:\\{save\←loc}, \[209], 215.
\:\\{save\←mode}, \[209], 213.
\:\\{save\←next\←control}, \[208].
\:\\{save\←place}, \[220].
\:\\{save\←position}, \[220], 221, 226.
\:\\{save\←text\←ptr}, \[208].
\:\\{save\←tok\←ptr}, \[208].
\:\\{scanning\←hex}, \[94], 95, 96, 97, 101.
\:\\{scrap\←base}, \[145], 146, 174, 179, 180\*, 181, 182, 195, 196, 198.
\:\\{scrap\←ptr}, \[145], 146, 177, 179, 180\*, 184, 185, 188, 195, 196, 198,
200, 227, 229, 245, 257.
\:\\{sc0}, \[185], 187, 194, 195, 196, 229.
\:\\{sc1}, \[185], 187, 190, 191, 193, 194, 197, 228, 229, 232\*, 233.
\:\\{sc2}, \[185], 187, 189, 193, 194, 228, 229, 232\*.
\:\\{sc3}, \[185], 187, 193, 194, 232\*.
\:\\{sc4}, \[185], 187, 194.
\:\.{Section name didn't end}, 105.
\:\.{Section name too long}, 106.
\:\\{semi}, 140, \[141], 143, 144, 150, 162, 164, 187, 195, 196, 229, 232\*.
\:\\{set\←element\←sign}, \[15], 65, 187.
\:\\{sid1}, \[64].
\:\\{sid2}, \[64].
\:\\{sid3}, \[64].
\:\\{sid4}, \[64].
\:\\{sid5}, \[64].
\:\\{sid6}, \[64].
\:\\{sid7}, \[64].
\:\\{sid8}, \[64].
\:\\{sid9}, \[64].
\:\\{simp}, \[141], 143, 144, 149, 151, 152, 159, 161, 162, 163, 168, 171, 187,
190, 191, 193, 197.
\:\\{sixteen\←bits}, \[36], 37, 48\*, 51, 54, 56, 67, 70, 173, 175, 202, 207,
208, 220, 237, 243, 245, 259, 261, 262\*.
\:\\{skip\←comment}, \[92], 113, 133, 137.
\:\\{skip\←limbo}, \[90], 110, 133.
\:\\{skip\←TeX}, \[91], 114, 133.
\:\.{Sorry, x capacity exceeded}, 35.
\:\\{sort\←ptr}, \[245], 250, 251, 252, 253.
\:{special string characters}, 190.
\:{split procedures}, 150, 184, 262\*.
\:\\{spotless}, \[9], 10, 264.
\:\\{sq}, 149, \[175].
\:\\{squash}, \[149], 152, 153, 155, 158, 161, 162, 163, 164, 167, 168, 170,
171, 175, 179.
\:\\{stack}, 202, \[203], 205, 206.
\:\\{stack\←ptr}, 202, \[203], 205, 206.
\:\\{stack\←size}, \[8\*], 203, 205.
\:\&{stat}, \[3].
\:\\{stmt}, \[141], 144, 150, 153, 154, 156, 157, 160, 161, 162, 163, 165, 168,
169, 170, 171.
\:\\{string}, \[94], 100, 186.
\:\.{String constant didn't end}, 100.
\:\\{string\←delimiter}, \[209], 217.
\:\\{sub\←cases}, 184, 192, \[193].
\:{system dependencies}, \[1\*], 2\*, 4, 7, 12\*, 17\*, 20, 21\*, 22, 24\*, 26%
\*, 28, 32\*, 33, 260, 261, 262\*, 264, 265\*.
\:\\{s0}, \[185].
\:\\{s1}, \[185].
\:\\{s2}, \[185].
\:\\{s3}, \[185].
\:\\{s4}, \[185].
\:\|{t}, \[59].
\:\\{tab\←mark}, \[15], 32\*, 88, 90, 93, 96, 104, 105, 124, 134, 136.
\:\&{tats}, \[3].
\:\\{temp\←line}, \[72], 73.
\:\\{term\←in}, \[259], 260, 261.
\:\\{term\←out}, \[20], 21\*, 22, 261.
\:\\{terminator}, 140, \[141], 143, 144, 150, 153, 154, 161, 162, 165, 167,
168, 180\*, 195, 196.
\:\.{TeX string should be...}, 223.
\:\\{tex\←file}, \[2\*], \[25], 26\*, 123, 125, 262\*.
\:\\{TeX\←string}, \[87], 88, 94, 101, 186, 223.
\:\\{text\←char}, \[12\*], 13, 20.
\:\\{text\←file}, \[12\*], 20, 23, 25, 28, 259, 265\*.
\:\\{text\←pointer}, \[53], 54, 145, 147, 180\*, 198, 199, 205, 208, 227.
\:\\{text\←ptr}, \[54], 55, 147, 172, 173, 176, 180\*, 181, 185, 188, 196, 199,
200, 208, 209, 227, 257.
\:\\{thin\←space}, \[87], 88, 187, 223.
\:\.{This can't happen}, 34.
\:\\{this\←module}, \[230], 231, 232\*, 234, 236.
\:\\{this\←xref}, \[235], 236, 256.
\:\\{to\←like}, \[42], 65, 192, 193.
\:\\{tok\←field}, \[202], 203.
\:\\{tok\←flag}, \[147], 149, 196, 199, 207, 227.
\:\\{tok\←mem}, \[54], 137, \[147], 149, 202, 203, 207, 214.
\:\\{tok\←ptr}, \[54], 55, 137, 138, 149, 172, 176, 180\*, 181, 188, 190, 199,
200, 208, 227, 257.
\:\\{tok\←start}, 53, \[54], 55, 145, 147, 172, 205.
\:\\{tracing}, 89, \[178], 179, 182, 183, 260.
\:\\{trans}, \[145], 149, 173, 177, 180\*, 184, 185, 196, 198, 245.
\:\\{translate}, 150, \[180\*], 181, 198, 227.
\:\\{trouble\←shooting}, 96, 207, 253, \[259], 260.
\:\\{true}, 6, 28, 29, 72, 73, 75, 80, 82, 83, 84, 86, 94, 101, 110, 111, 123,
128\*, 129, 240, 259, 260.
\:\\{tty\←rewrite}, 21\*, \[265\*].
\:\\{typewriter}, \[42], 112, 254.
\:\\{unbucket}, \[250], 251, 252.
\:\\{underline}, \[87], 88, 101, 114.
\:\.{Unknown control code}, 88.
\:\\{until\←like}, \[42], 65, 194.
\:\\{up\←to}, \[96].
\:\\{update\←terminal}, \[22], 31, 111, 222, 261.
\:\\{var\←head}, \[141], 143, 144, 149, 150, 163, 164, 171, 194.
\:\\{var\←like}, \[42], 65, 112, 194.
\:\\{verbatim}, \[87], 88, 101, 108, 186, 190.
\:\.{Verbatim string didn't end}, 108.
\:\|{w}, \[44], \[59], \[67], \[70], \[132], \[209].
\:\\{WEAVE}, \[2\*].
\:\.{WEB file ended...}, 80.
\:\\{web\←file}, \[2\*], \[23], 24\*, 32\*, 72, 74, 80, 84, 86, 262\*.
\:\.{Where is the match...}, 77, 81, 85.
\:\\{wi}, \[40], 41.
\:\\{wildcard}, \[42], 112, 254.
\:\\{write}, 20, 123, 125, 261.
\:\\{write\←ln}, \[2\*], 20, 123.
\:\\{writeln}, 2\*.
\:\\{ww}, 8\*, \[37], 38, 39, 40, 41, 44, 51, 59, 62, 63, 67, 68, 69, 70, 132,
209, 210, 215, 244, 245, 252, 263.
\:\\{xchr}, \[13], 14, 16, 17\*, 18, 32\*, 44, 106, 123, 129, 147, 148, 183,
261.
\:\&{xclause}, 6.
\:\\{xlink}, \[46], 51, 52, 120, 214, 236, 238, 255, 256.
\:\\{xlink\←field}, 46, \[48\*].
\:\\{xmem}, 46, \[49\*].
\:\\{xmem\←record}, \[48\*], 49\*.
\:\\{xord}, \[13], 16, 18, 28.
\:\\{xref}, 36, \[37], 46, 50, 51, 52, 63, 68, 120, 214, 232\*, 236, 244, 256.
\:\\{xref\←number}, \[47], 49\*, 51, 52, 119, 235, 237.
\:\\{xref\←ptr}, 46, \[49\*], 50, 51, 52, 263.
\:\\{xref\←roman}, \[87], 88, 94, 101, 112, 114, 187, 223.
\:\\{xref\←switch}, 46, \[49\*], 50, 51, 94, 101, 102, 112, 114, 116.
\:\\{xref\←typewriter}, \[87], 88, 94, 112, 114, 187, 223.
\:\\{xref\←wildcard}, \[87], 88, 94, 112, 114, 187, 223.
\:\.{You can't do that...}, 223, 233.
\:\.{You need an = sign...}, 232\*.
\fin
\:\X190:Append a \(string scrap\X
\U section~186.
\:\X191:Append a \TeX\ string scrap\X
\U section~186.
\:\X192:Append an identifier scrap\X
\U section~186.
\:\X186:Append the scrap appropriate to \\{next\←control}\X
\U section~184.
\:\X195:Append \\{terminator} if not already present\X
\U sections~194, 194, and~194.
\:\X152:Cases for \\{alpha}\X
\U section~151.
\:\X153:Cases for \\{beginning}\X
\U section~151.
\:\X154:Cases for \\{case\←head}\X
\U section~150.
\:\X155:Cases for \\{casey}\X
\U section~150.
\:\X156:Cases for \\{clause}\X
\U section~150.
\:\X157:Cases for \\{cond}\X
\U section~150.
\:\X158:Cases for \\{elsie}\X
\U section~150.
\:\X159:Cases for \\{exp}\X
\U section~150.
\:\X160:Cases for \\{intro}\X
\U section~151.
\:\X161:Cases for \\{math}\X
\U section~151.
\:\X162:Cases for \\{mod\←scrap}\X
\U section~150.
\:\X164:Cases for $\\{open}\,\\{math}$\X
\U section~163.
\:\X163:Cases for \\{open}\X
\U section~151.
\:\X165:Cases for \\{proc}\X
\U section~150.
\:\X166:Cases for \\{record\←head}\X
\U section~150.
\:\X167:Cases for \\{semi}\X
\U section~150.
\:\X168:Cases for \\{simp}\X
\U section~151.
\:\X169:Cases for \\{stmt}\X
\U section~150.
\:\X170:Cases for \\{terminator}\X
\U section~150.
\:\X171:Cases for \\{var\←head}\X
\U section~150.
\:\X189:Cases involving nonstandard ASCII characters\X
\U section~187.
\:\X194:Cases that generate more than one scrap\X
\U section~192.
\:\X174:Change \\{pp} to $\max(\\{scrap\←base},$\\{pp}+\|d$)$\X
\U sections~173 and~175.
\:\X106:Check for overlong name\X
\U section~104.
\:\X86:Check that all changes have been read\X
\U section~262\*.
\:\X232\*:Check that $=$ or $\S$ follows this module name, and emit the scraps
to start the module definition\X
\U section~231.
\:\X139:Clear \\{bal} and \&{goto} \\{done}\X
\U sections~137 and~138.
\:\X181:Combine the irreducible scraps that remain\X
\U section~180\*.
\:\X62:Compare name \|p with current identifier, \&{goto} \\{found} if equal\X
\U section~61.
\:\X4:Compiler directives\X
\U section~2\*.
\:\X98:Compress two-symbol combinations like `\.{:=}'\X
\U section~96.
\:\X60:Compute the hash code \|h\X
\U section~59.
\:\X61:Compute the name location \|p\X
\U section~59.
\:\X8\*:Constants in the outer block\X
\U section~2\*.
\:\X218:Copy a control code into the buffer\X
\U section~217.
\:\X138:Copy special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"\}"}$; %
\&{goto} \\{done} at end\X
\U section~137.
\:\X217:Copy the \PASCAL\ text into $\\{buffer}[(\\{limit}+1)\to\|j]$\X
\U section~215.
\:\X136:Copy up to `\v' or control code, \&{goto} \\{done} if finished\X
\U section~135.
\:\X134:Copy up to control code, \&{return} if finished\X
\U section~133.
\:\X151:Declaration of subprocedures for \\{translate}\X
\U section~180\*.
\:\X196:Declaration of the \\{app\←comment} procedure\X
\U section~184.
\:\X197:Declaration of the \\{app\←octal} and \\{app\←hex} procedures\X
\U section~184.
\:\X187:Declaration of the \\{easy\←cases} procedure\X
\U section~184.
\:\X193:Declaration of the \\{sub\←cases} procedure\X
\U section~184.
\:\X93:Do special things when $\|c=\.{"@"},\.{"\\"},\.{"\{"},\.{"\}"}$; %
\&{goto} \\{done} at end\X
\U section~92.
\:\X244:Do the first pass of sorting\X
\U section~240.
\:\X233:Emit the scrap for a module name if present\X
\U section~231.
\:\X68:Enter a new module name into the tree\X
\U section~67.
\:\X63:Enter a new name into the table at position \|p\X
\U section~59.
\:\X30, 31, 33:Error handling procedures\X
\U section~2\*.
\:\X265\*:External procedure declarations for things implemented directly in
Cedar\X
\U section~2\*.
\:\X100:Get a string\X
\U section~96.
\:\X99:Get an identifier\X
\U section~96.
\:\X101:Get control code and possible module name\X
\U section~96.
\:\X9, 13, 20, 23, 25, 27, 29, 37, 39, 45, 49\*, 54, 56, 64, 66, 72, 74, 94,
109, 115, 119, 122, 130, 145, 178, 203, 220, 230, 235, 241, 243, 245, 247,
259:Globals in the outer block\X
\U section~2\*.
\:\X97:Go to \\{found} if \|c is a hexadecimal digit, otherwise set $%
\\{scanning\←hex}\K\\{false}$\X
\U section~96.
\:\X105:If end of name, \&{goto} \\{done}\X
\U section~104.
\:\X182:If semi-tracing, show the irreducible scraps\X
\U section~181.
\:\X81:If the current line starts with \.{@y}, report any discrepancies and %
\&{return}\X
\U section~80.
\:\X183:If tracing, print an indication of where we are\X
\U section~180\*.
\:\X256:Invert the cross-reference list at \\{cur\←name}, making \\{cur\←xref}
the head\X
\U section~255.
\:\X16, 40, 57, 248:Local variables for initialization\X
\U section~2\*.
\:\X213:Look ahead for strongest line break, \&{goto} \\{reswitch}\X
\U section~212.
\:\X188:Make sure that there is room for at least four more scraps, six more
tokens, and four more texts\X
\U section~186.
\:\X200:Make sure that there is room for at least seven more tokens, three more
texts, and one more scrap\X
\U section~199.
\:\X177:Make sure the entries $\\{cat}[\\{pp}\to(\\{pp}+3)]$ are defined\X
\U section~176.
\:\X150:Match a production at \\{pp}, or increase \\{pp} if there is no match\X
\U section~176.
\:\X79:Move \\{buffer} and \\{limit} to \\{change\←buffer} and \\{change%
\←limit}\X
\U sections~76 and~80.
\:\X212:Output a \(control, look ahead in case of line breaks, possibly %
\&{goto} \\{reswitch}\X
\U section~209.
\:\X211:Output a \.{\\math} operator\X
\U section~209.
\:\X214:Output a module name\X
\U section~209.
\:\X258:Output all the module names\X
\U section~240.
\:\X238:Output all the module numbers on the reference list \\{cur\←xref}\X
\U section~237.
\:\X210:Output an identifier\X
\U section~209.
\:\X253:Output index entries for the list at \\{sort\←ptr}\X
\U section~251.
\:\X222:Output the code for the beginning of a new module\X
\U section~221.
\:\X239:Output the code for the end of a module\X
\U section~221.
\:\X255:Output the cross-references at \\{cur\←name}\X
\U section~253.
\:\X254:Output the name at \\{cur\←name}\X
\U section~253.
\:\X215:Output the text of the module name\X
\U section~214.
\:\X110:Phase I: Read all the user's text and store the cross references\X
\U section~262\*.
\:\X219:Phase II: Read all the text again and translate it to \TeX\ form\X
\U section~262\*.
\:\X240:Phase III: Output the cross-reference index\X
\U section~262\*.
\:\X32\*:Print error location based on input buffer\X
\U section~31.
\:\X121:Print error messages about unused or undefined module names\X
\U section~110.
\:\X263:Print statistics about memory usage\X
\U section~262\*.
\:\X264:Print the job \\{history}\X
\U section~262\*.
\:\X148:Print token \|r in symbolic form\X
\U section~147.
\:\X129:Print warning message, break the line, \&{return}\X
\U section~128\*.
\:\X117:Process a format definition\X
\U section~116.
\:\X104:Put module name into $\\{mod\←text}[1\to\|k]$\X
\U section~102.
\:\X85:Read from \\{change\←file} and maybe turn off \\{changing}\X
\U section~83.
\:\X84:Read from \\{web\←file} and maybe turn on \\{changing}\X
\U section~83.
\:\X236:Rearrange the list pointed to by \\{cur\←xref}\X
\U section~234.
\:\X176:Reduce the scraps using the productions until no more rules apply\X
\U section~180\*.
\:\X108:Scan a verbatim string\X
\U section~101.
\:\X102:Scan the module name and make \\{cur\←module} point to it\X
\U section~101.
\:\X107:Scan to the next \.{@>}\X
\U section~101.
\:\X10, 14, 17\*, 18, 21\*, 26\*, 41, 43, 50, 55, 58, 95, 103, 125, 127, 146,
204, 246, 249, 260:Set initial values\X
\U section~2\*.
\:\X69:Set \|c to the result of comparing the given name to name \|p\X
\U sections~67 and~70.
\:\X234:Show cross references to this module\X
\U section~221.
\:\X216:Skip next character, give error if not `\.{@}'\X
\U section~215.
\:\X77:Skip over comment lines in the change file; \&{return} if end of file\X
\U section~76.
\:\X78:Skip to the next nonblank line; \&{return} if end of file\X
\U section~76.
\:\X251:Sort and output the index\X
\U section~240.
\:\X89:Special control codes allowed only when debugging\X
\U section~88.
\:\X252:Split the list at \\{sort\←ptr} into further lists\X
\U section~251.
\:\X229:Start a format definition\X
\U section~226.
\:\X228:Start a macro definition\X
\U section~226.
\:\X65:Store all the reserved words\X
\U section~262\*.
\:\X111:Store cross reference data for the current module\X
\U section~110.
\:\X116:Store cross references in the \(definition part of a module\X
\U section~111.
\:\X118:Store cross references in the \PASCAL\ part of a module\X
\U section~111.
\:\X114:Store cross references in the \TeX\ part of a module\X
\U section~111.
\:\X242:Tell about changed modules\X
\U section~240.
\:\X225:Translate a hexadecimal constant appearing in \TeX\ text\X
\U section~223.
\:\X224:Translate an octal constant appearing in \TeX\ text\X
\U section~223.
\:\X221:Translate the \(current module\X
\U section~219.
\:\X226:Translate the \(definition part of the current module\X
\U section~221.
\:\X231:Translate the \PASCAL\ part of the current module\X
\U section~221.
\:\X223:Translate the \TeX\ part of the current module\X
\U section~221.
\:\X11, 12\*, 36, 38, 47, 48\*, 53, 202:Types in the outer block\X
\U section~2\*.
\con