summaryrefslogtreecommitdiff
path: root/web/spiderweb/doc/spdjman.tex
blob: bcb6b28a8a5c4219ed496666dcc6f0e8e3079c60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
% $Header: /usr2/nabe/Tools/WEB_Tool/Spiderweb/doc-j/RCS/spdjman.tex,v 1.5 92/02/28 16:34:11 nabe Exp $
% This file is translated from English into Japanese by Izumi Watanabe,
% (nabe@miya.fujifilm.co.jp).
% As Mr. Ramsey wrote, to be used for reserch purposes only.
% This file contains Japanese Kanji-character codes, called EUC (Extended
% Unix Code), and is written for Japanese-LaTeX, called ASCII-jLaTeX.


%% Copyright 1989 by Norman Ramsey and Odyssey Research Associates
%% To be used for research purposes only
%% For more information, see file COPYRIGHT in the parent directory

% この日本語訳は参考として 渡辺泉(nabe@miya.fujifilm.co.jp)が行ないました。
% このドキュメントはオリジナルの spider.man を修正したものなので、
% Mr. Ramsey の指定通りに研究目的にのみ使用可能です。
% 扱いには注意して下さい。

%% spiderman.tex, with apologies to Stan Lee 

%%\documentstyle[11pt]{article}
\documentstyle[a4j]{jarticle}
\setcounter{secnumdepth}{0}
\newcommand{\syntax}[1]{\mbox{$\langle\hbox{\sl #1\/}\rangle$}}
\newcommand{\produces}{\mbox{${}::={}$}}
\newcommand{\opt}[1]{$[$#1$]$}
\newcommand{\BS}{\relax}
\chardef\BS=`\\ % backslash in a string
\def\jem{\em\gt}
\def\P#1#2{#2:#1}
\newcommand {\WEB}{{\tt WEB}}

\title{{Spider} ユーザーズガイド}
\author{Norman Ramsey\thanks{
	Department of Computer Science, Princeton University,
	``A {Spider} User's Guide'',{July 1989}.}\ 著 \\
	渡辺泉\thanks{日経mix:w.izumi, nabe@miya.fujifilm.co.jp}\ 訳}
\date{Feb 1992 \\ J-$Revision: 1.5 $}

\begin{document}
\maketitle

\section{はじめに}
Donald Knuth は {\tt WEB} という、構造化ドキュメンテーション・システムを
{\TeX} プロジェクト~\cite{knuth:literate-programming} の一部として開発した。
{\tt WEB}を使うと、プログラマーは自分のプログラムをいくつものかたまり (
{\jem モジュール}) に分割して、それらに文章を付与し、好きな順番に説明することができるようになる。
Knuth が作ったものでは、各モジュールは PASCAL プログラムであり、
それらが {\TeX} を使用して清書される。

  {\tt WEB} のアイデアは、{\jem 任意}のプログラミング言語と
{\jem 任意}の文書清書言語\index{\P{document formatting language}{文書清書言語}}
を結合する方法を提案している。
しかし、最近までは、PASCAL プログラム用の \WEB 以外の
支援ソフトウェアはなかった。 
\hbox{1987年}に、Silvio Levy が Cのための{\tt WEB} システムをC で書き直した。
この時も文書清書言語としては {\TeX} が引き続き使われた~\cite{levy:cweb}。
筆者は、Levy の書いたものを修正し、 C をターゲット言語とする部分を取り除いた。
そして、{Spider}という {\tt WEAVE}と{\tt TANGLE}を作る
第3のツールを追加した。
{Spider} は、ある プログラミング言語についての記述を読み、
その言語をサポートした {\tt WEAVE} と {\tt TANGLE} のソースコードを
書き出す。
 {Spider}、  C~コンパイラ、 Awk~インタプリタを使えば、
 経験を積んだシステムプログラマなら Algol のような言語の
{\tt WEB} システムを 数時間で生成することができるだろう。

このドキュメントは、任意のプログラム言語のための{\WEB}システムを作るための
{Spider} の使い方を説明している (プログラミング言語の選択は、
後で見ることになるが、Spidery {\tt WEB}の中
に作り込まれた字句構造\index{\P{lexical structure}{字句構造}}
の制限にのみ制限を受ける)。
参考書として
「The Spidery {\WEB} system of structured documentation」で、
{\WEB} system の作り方を学んでおくとよい。


\paragraph{事前準備}
{Spider} を使って {\WEB} システムを
作ろうとしているなら、{\tt WEB}になじんでおくこと。
{\tt WEB} が何をどうするのかを知りたければ、
Knuth の書いた{\WEB}~\cite{knuth:literate-programming}の紹介記事:
 {\WEB} users' manual を読んでおくべきである ( {\WEB} user's manual は、
手始めとしてはかなり重量級である。
参考文献の中に、{\WEB}のもっと導入的なものを捜し求めても良い。
Wayne Sewell の {\it Weaving a Program: Literate Programming in {\tt
WEB}}
は役に立つだろう~\cite{sewell:weaving})。

これ以降は、読者が{\tt WEAVE} と {\tt TANGLE} とはなにかを知っており、
それらが何を入力とし、出力するものがなにかを知っているものとして話を進める。


\paragraph{このガイドの進め方}
まず、weaving と tangling の復習から始め、言語に依存しない {\WEB}を
作るのに必要なアイデアをつかめるようにする。
それから、{\WEB}にプログラミング言語について教えるという、
{Spider} の特徴についての議論を述べる。
これらを詳細に定義し、いくつかの例を示す。
そして最後に、
{Spider} 言語とツールについての完全な記述をもって終わることにする。


\section{{\tt WEAVE} と {\tt TANGLE} から見た世界}
{\tt WEAVE} と {\tt TANGLE} はいずれも同一の{\WEB}ファイルを入力とする。
{\tt WEAVE} は、入力を検査し、{\TeX}テキストを生成しなければならない。一方、
{\tt TANGLE} は、同じ入力からプログラムテキストを生成しなければならない。
入力は、{\TeX}部、定義部、コード部からなる。
 {\TeX}部はもっとも扱いが容易である: {\tt WEAVE} ではコピーし、
 {\tt TANGLE} では捨てれば良い。
定義部は少し複雑である: {\tt WEAVE}の仕事は、それらを組版し、
一方{\tt TANGLE} は定義を記憶し適切なときに展開する。
コード部は一番複雑である: {\tt WEAVE} はそれらを清書しなければならないし、
{\tt TANGLE} は一貫したプログラムテキストに整理し直さなければならない。


\paragraph{{\WEB}の字句解析}
{\tt WEAVE} と {\tt TANGLE} のいずれも、コード部を{\jem トークン}の連なりとして
解釈する。
すべてのプログラミング言語が同じトークンを持っているわけではないので、
{Spider}の仕事は、 {\tt WEAVE} と {\tt TANGLE} に
入力をトークンに分解するやり方を教えることになる
\footnote{%
現在の{\tt WEB}の字句解析の実装は限定されている。
これは、正規表現を使ったものに置き換えられるべきである。
}。
Spidery {\WEB} システムは以下のトークンを認識することができる。
\begin{itemize}
\item 識別子(identifiers)
\item 数値定数と文字列定数
\item 改行
\item ``疑似セミコロン'' ({\tt @;})
\item 予約語
\item 非英数字トークン
\end{itemize}

{\tt TANGLE} は、これらのトークンを1つの長いプログラムテキストとして再整理
したのち、トークン毎にプログラムテキストを書き出す。
通常 {\tt TANGLE} は、トークンの間に空白文字を挿入しない。
しかし、識別子、予約語、数値定数の回りには空白をおく。
入力が、
\begin{quote}
\tt if 0 > x-y then z := -1;
\end{quote}
ならば、出力は、
\begin{quote}
\tt if 0>x-y then z:=-1;
\end{quote}
となり、解析できないような
\begin{quote}
\tt if0>x-ythenz:=-1;
\end{quote}
とはならない。
{\tt TANGLE} が変換するのと違うトークンを望む時には、
各トークンに {\tt tangleto}属性を与えることができる。
この指定は、そのトークンをプログラムテキストとしてどう印刷すべきかを指定する
ものである。
例えば、
C{\WEB}を生成するための{\tt spider}ファイルでは、{\tt =} を\ {\tt "=\ "}
という文字列で印刷されるトークンとしておきたい。 C では\ {\tt "=-"} という
文字列の意味が曖昧になってしまうからである。

%{\tt WEAVE} must turn the token stream into a {\TeX} text that will
{\tt WEAVE} はトークンの並びを{\TeX} テキストに変換し、
整形印刷しなければならない。
これは 3つのステップで実現される。
\begin{enumerate}
\item 
{\tt WEAVE} は、各トークンを {\jem スクラップ}に変換する。
スクラップは、2つの重要な特性値を持つ: それは、
構文上の{\jem カテゴリー} と
{\jem 翻訳$($translation$)$}\index{\P{translation}{翻訳}}
である。
カテゴリーは、清書をするための文法上の記号である; 
この文法とは、{\tt WEAVE} が清書用の命令を使ってスクラップを組み合わせる
方法である。
%The translations are the {\TeX} texts that will tell {\TeX} exactly
%how to print the scraps.
translation\index{translation}とは、{\TeX}がスクラップを印刷するための
{\TeX}テキストである。
\item
{\tt WEAVE}は、スクラップの並びを清書文法にしたがって還元していく(
{\tt WEAVE} は、shift-reduce 構文解析の一種を行なう)。
translation \index{translation} を結合しているあいだ中、{\tt WEAVE} は 
インデント、アウトデント、行変えなどをするための
{\TeX} テキストを追加していく。
\item
理想的な場合には、{\tt WEAVE}は非常に長い translation\index{translation}を持った
一つのスクラップになるまで、還元したスクラップを保持する。
しかし、たぶん、還元できないスクラップの並びによって終ってしまうだろう。
いずれにせよ、それ以上還元できなくなった後は、
残ったスクラップの translation\index{translation}を一つずつ出力する。
\end{enumerate}


\section{{Spider}を使って {\WEB}のトークン分解を決める}
{Spider} は トークンを 予約語とその他 の 2種類に区別する。
予約語は、コマンド {\tt reserved} と {\tt ilk}
を使って指定する。
その他のトークンは、コマンド{\tt token}を使って指定する(
%This somewhat unusual setup is dictated by the way {\tt
%WEAVE} works; its advantage is that is is easy to define a whole group
%of reserved words that will be treated identically.)
このいささか非定常的な設定は、{\tt WEAVE}の癖に合わせるためである。
これは、区別して扱って欲しい予約語のグループ全体を簡単に定義できるという
長所を持つ)。
%Here's how it works: the {\tt reserved} command designates
働きを以下に示そう: {\tt reserved} コマンドは特定の識別子を
予約語としてみなし、どのような{\jem ilk $($属性$)$}として扱われるかを
明示する。
% a particular identifier as a reserved word, and says
%what {\jem ilk} it belongs to.
%The {\tt token} and {\tt ilk} commands tell {\tt WEAVE} and {\tt
%TANGLE} what to do with a particular token, or with all the reserved
%words of a particular ilk.
コマンド {\tt token} と {\tt ilk} は、{\tt WEAVE} と {\tt TANGLE}に
そのトークンをどうするか、またはその属性を持つ全ての予約語を
どうするかを指定する。

%For each token or ilk one can specify the {\jem tangleto} field, the
%token's {\jem mathness} (whether it has to be typeset in math mode), and
%its {\jem category} and {\jem translation} (for conversion to scraps).
各トークンと属性は {\jem tangleto} フィールドを持つことができ、
トークンの {\jem mathness} (数式モードで組版することの指定)と、
{\jem カテゴリー}、{\jem translation}\index{translation} (スクラップでの
記述を参照)を
指定できる。
カテゴリー以外は、{\tt defaults}でそのデフォルト値を設定することができる。
カテゴリー名はユーザーの任意である。

トークン分解のコマンドについては、後ほど{Spider}の構文を詳細に説明する時に
議論したい。
ともかく、
C~言語用の{\tt spider} ファイルのトークン分解コマンドの例を
見ることにしよう:
\begin{verbatim}
token + category unorbinop
token - category unorbinop
token * category unorbinop
token = category equals translation <"\\leftarrow"> tangleto <"="-space>
token ~ category unop translation <"\\TI">
token & category unorbinop translation <"\\amp">
token ^ translation <"\\^"> category binop
token ? translation <"\\?"> category question
token % translation <"\\%"> category binop
token # translation <"\\#"> category sharp
token ! category unop translation <"\\neg">
token ( category lpar
token ) category rpar
token [ category lpar
token ] category rpar
token { translation <"\\{"> category lbrace
token } translation <"\\}"> category rbrace
token ++ category unop translation <"\\PP">
token -- category unop translation <"\\MM">
token != translation <"\\I"> category binop
token == translation <"\\S"> category binop
token && translation <"\\W"> category binop

ilk case_like category case
ilk int_like category int

reserved auto ilk int_like
reserved break ilk case_like
reserved case ilk case_like
reserved char ilk int_like
\end{verbatim}
ここには、Cで使われるトークンのいくつかの定義例が示されている。
{\tt tangleto}オプションが ほとんどの場合デフォルトのままであることと、
そして {\tt translation} オプションがしばしばデフォルトのままであることに
注意して欲しい。

%Once the tokens are specified, and each has a {\tt tangleto} string,
%we can almost construct a {\tt TANGLE} for the language. 
一度トークンが指定され、それぞれ{\tt tangleto} 文字列を持っていれば、
言語としての{\tt TANGLE} は、ほとんど構築できたようなものである。
% Before we can construct a {\tt WEAVE}, we have to tell it how to
%combine and reduce scraps.
{\tt WEAVE}を構築するためには、スクラップの結合と還元についてのやり方を
指定しなければならない。



\section{{Spider}で{\tt WEAVE}のスクラップの還元の仕方を指定する}
%The most intricate part of {\tt WEAVE} is its mechanism for converting
%programming language code into \TeX\ code.
{\tt WEAVE}のもっとも複雑な部分は、プログラム言語のコードを \TeX\ コードに
翻訳するところにある。
%{\tt WEAVE} uses a simple bottom-up parsing algorithm, since it
% must deal with fragmentary
%constructions whose overall ``part of speech'' is not known.
{\tt WEAVE} は、単純な 上昇型構文解析アルゴリズムを使っている。
それは、 既知の「話し言葉の一部」ではない、分断されている構造を
扱わなければならないためである。

入力は、{\jem スクラップ} の並びとして与えられ、
各スクラップは 2つの情報を含んでいる。
{\jem category} と {\jem translation}\index{translation}である。
カテゴリーは基本的に構文的なクラスを示し、
translation\index{translation} は{\TeX}コードを示している。
構文規則と意味規則は隣あったスクラップをより大きなものにまとめる方法を規定する。
運が良ければ、プログラムテキスト全部が、
何百もの小さなスクラップだったところから、互いに結合されて行き、
一つの巨大なスクラップになり、
その translation\index{translation} が期待していた \TeX\ コードになるだろう。
運が悪ければ、いくつかのスクラップは結合されないままになるだろう;
それらの translation\index{translation} は単純に一つずつ出力されることになる。

結合規則は、左から右への文脈依存生成規則\index{\P{context-sensitive productions}{
文脈依存生成規則}}
として与えられる。
今、 $s_1\,s_2\ldots s_n$ というスクラップの並びを処理しているとする。
最初の並びである$s_1\,s_2\ldots\,$ に対する最長の生成規則を探す。
しかし、もしそのような生成規則が存在しなければ、
次の $s_2\,s_3\ldots\,$ に対して最長の生成規則を次々に探してゆく。
そして、それも失敗したら $s_3\,s_4\ldots\,$, etc. という具合にマッチングを試行する。

生成規則は、あらかじめ与えられたカテゴリーコードのパターンを持つ時に適用される。
例えば、ある生成規則が
$$\hbox{\tt open [ math semi <"\BS\BS,"-opt-5> ] -->
open math}$$ 
であれば、それは、
それぞれ{\tt open}、 {\tt math}、 {\tt semi}というカテゴリーを持つ3つの
連続したスクラップは、
 {\tt open} と {\tt math}というカテゴリーを持つ
2つのスクラップに変換されることを意味する。
{\tt open}スクラップは変換されない。一方、
文字列 {\tt <"\BS\BS,"-opt-5>} が指定されているので、
新しい {\tt math} スクラップは
元の{\tt math}のtranslation\index{translation}、
{\tt semi} のtranslation\index{translation}、
 `{\tt \BS,}'、 `{\tt opt}'、 `{\tt5}'
という一連のもので構成さることになる(
 \TeX\ ファイルにおいて、これは追加の小さいスペースがセミコロンの後に
付き、
penalty 50 の optional line break が続くことを意味する)。
translation\index{translation} は 角括弧 ({\tt <>}) で括られており、
引用符({\tt "})で括られた文字列(
C の環境ではバックスラッシュ({\tt \BS}) でエスケープされた文字でも良い)、
特別なキーワードを含むことができる。

役に立つ生成規則の例を示す前に、
{Spider}の構文の大部分を含むサブセットの詳細を説明しよう。



\section{{\tt spider} ファイルの構文}

{Spider} は、{\tt WEAVE} と {\tt TANGLE}のために
言語の記述をCのコードに変換する Awk プログラムである。
{Spider}が Awk プログラムなので、入力は行のシーケンスであり、
全ての {Spider} コマンドが1行に収まらなければならない。

\paragraph{コメントと空白行}
{\jem 任意の} 文字列がプログラミング言語のトークンになり得るので、
特定の文字並びを ``コメントの開始記号''として決めておくことができない。
従って、 {Spider} にはコメントはなく、 {\jem コメント行}のみがある。
コメント行は、最初が ``{\tt \#}'' で始まっている行である。
{Spider}処理系はコメント行と空白行を無視する。

\paragraph{フィールド}
{\tt spider} の各コマンドは、{\jem フィールド}の並びからなる。
これは、Awk のフィールドと同一で、ホワイトスペース\index{white space}
で区切られている。
この Awk から継承した性質のゆえに、{Spider}はフィールド中に
ホワイトスペースは使用できない。


\subsection{翻訳}
%Most fields in a {Spider} file are simple identifiers, or perhaps
%strings of non-alphanumeric characters.
{Spider}ファイルの大部分のフィールドは、単純な識別子\index{identifier}か、
たぶん非英数字文字\index{non-alphanumeric character}である。
%The major exception is {\jem translations}.
最大の例外は、{\jem 翻訳}\index{translations}である。
%Translations are always surrounded by angle brackets ({\tt <>}),
翻訳は常に角カッコ\index{angle bracket} ({\tt <>}) で囲まれており、
%and consist of a (possibly empty) list of translation pieces.
(空でも良い)翻訳要素\index{translation pieces}のリストである。
%The pieces on a list are separated by dashes ({\tt -}).
リスト中の各要素は、ダッシュ({\tt -})で区切られる。
翻訳要素は、下記の一つである。
\begin{itemize}
\item 引用符で囲まれた文字列.
この文字列は、``\verb+\+'' でエスケープされた文字を許すが、
ホワイトスペースとダッシュを含んではならない。
\item ``self'' マーカー, ``{\tt *}'',
 は、翻訳されようとしているトークンの文字列を参照する。
%refers to the sequence of characters making up the token being translated.
%The self marker is permitted only in certain contexts, and its precise
%meaning depends on the context.
セルフマーカは確定している文脈の中でのみ許されており、その意味するところは
文脈に依存している。
\item 数字
\item キーワード:
{Spider} のキーワードは、以下の通りである。
\begin{description} 
\item [\tt space] 1つの空白文字 ({\tt "\ "})を意味する.
\item[\tt dash] 1つのダッシュ ({\tt "-"})を意味する.
\end{description}
その他のキーワードは{\tt WEAVE}に渡される。

{\tt WEAVE} は、以下のキーワードを認識する:
\begin{description}
\item[\tt break\_space] optional line break または 空白;
\item[\tt force] line break;
\item[\tt big\_force] 垂直スペースを持つ line break;
\item[\tt opt] optional line break ( 以降の行は通常の開始位置より
2em インデントされる)---
このコードは、整数$n$ を伴い、break はペナルティ $10n$ として扱われる。
%code is followed by an integer $n$, and the break will occur with penalty
%$10n$;
\item[\tt backup] 1em の backspace;
\item[\tt cancel] 先行していた\ または続くすべての {\tt break\_space},
 {\tt force},{\tt big\_force} を取り消す。さらに、
続く {\tt backup} トークンもキャンセルする;
\item[\tt indent] 以降の行を 1em インデントする
\item[\tt outdent] 以降の行を -1em インデントする
\item[\tt math\_rel]  \verb+\mathrel{+ に変換される
\item[\tt math\_bin]  \verb+\mathbin{+ に変換される
\item[\tt math\_op]  \verb+\mathop{+ に変換される
\end{description}
数式モードでも正しく処理される {\jem 唯一} のキーワードは、{\tt
indent} と {\tt outdent}だけである。
もし、他のキーワードを含む翻訳を定義したい時は、
そのトークンには{\tt mathness~no} を使わねばならない。
%You may use any recognized key words in the translations of a
%production; there the mathness is automatically taken care of for you.
生成規則の翻訳の中では、どんなキーワードを使っても構わない。
それらの数式性は自動的に処理される。
\end{itemize}

以下は、翻訳\index{translation}の例である。:
\begin{verbatim}
<"\\"-space>
<indent-force>
<"{\\let\\\\=\\bf"-space>
<"}"-indent-"{}"-space>
\end{verbatim}

\paragraph{制限された翻訳}\index{Restricted translations}
いくつかの場合は、例えば、{\tt tangleto} 記述などでは、
翻訳\index{translations}は制限される。
制限された翻訳\index{restricted translation} は、タイプセッティングコードに
変換されることはなく 常に ASCII 文字列となる。
%is never converted to typesetting code,
%but is always converted to an ASCII string, 
%usually for output by {\tt
%TANGLE}, but sometimes for other things.
たいていは{\tt TANGLE} の出力用に使われるが、別の用途でも使う。
制限された翻訳\index{restricted translation}は、
{\jem 引用符で括られた文字列} および、
{\tt space} と{\tt dash} の2つのキーワードのみが許される。


\subsection{{\tt token} コマンド}
{\tt token} コマンドの構文は、次の通りである:
\begin{quote}
\tt  
\syntax{command} \produces~token \syntax{token-designator}
\syntax{token-descriptions}
\end{quote}
ここで \syntax{token-descriptions} は (空でも良い) トークン記述のリストである。

\paragraph{トークン記述}
トークン記述は
\begin{itemize}\parindent=0pt
\item
{\tt tangleto \syntax{restricted translation}}

\syntax{restricted translation} は {\tt TANGLE}に
このトークンをプログラムテキストに書き出すものを規定する。
制限された翻訳\index{restricted translation}で有効なものは、
{\jem 引用符で括られた文字列} および、
{\tt space} と{\tt dash} の2つのキーワードのみである。
もし {\tt tangleto} 記述がなければ、 {\tt TANGLE} は
トークンを構成した文字列を書き出す。

\item
{\tt translation \syntax{translation}}

%Tells {\tt WEAVE} what translation to assign when making this token into
%a scrap.
{\tt WEAVE} がトークンをスクラップの中に置く時にどう翻訳するかを指示する。
%The self
%marker~({\tt*}) stands for the sequence of characters that were read in to
%make up the token.
セルフマーカー~({\tt*}) は、トークンを構成している文字列そのものを示す。
翻訳はしばしば \verb+translation <*>+ がデフォルトとなる; {Spider}
はこれをあらかじめデフォルトとして組み込んである。

\item
{\tt category \syntax{category-name}}

%Tells {\tt WEAVE}  what category to assign when making this token into
%a scrap.
{\tt WEAVE} がこのトークンをスクラップにいれるときに使うカテゴリーを指定する。
{Spider} ファイルを書く時は好きなカテゴリー名を
使うことができる。
守るべき条件は、{Spider} が知っている他の名前(予約キーワード、
ilkの名前  など)と衝突しないようにすることだけである。
%Using category names that are identical to reserved words of the
%target programming language (または C~の予約語) is not only
%supported, it is strongly encouraged, for clarity.
%Using category names that are identical to reserved words of the
カテゴリー名を
ターゲット言語の予約語(または C~の予約語)と同一にしておくことは、
明快さの為だけでなく、強い要請である。
%Also, when we get to the sample grammars later on, you will see some
%other conventions we use for category names.
後ほど文法の例を見ることになるが、
カテゴリー名を使うためのいくつかの約束事がある。

\item
{\tt mathness \syntax{mathness-indicator}}

ここで、\syntax{mathness-indicator} は {\tt yes}、{\tt no}、{\tt
maybe}のいずれかである。
%This indicates to {\tt WEAVE} whether the translation for this token
%needs to be typeset in {\TeX}'s math mode or not, or whether it
%doesn't matter.
これは {\tt WEAVE} がこのトークンを印刷するための translation として
{\TeX}の数式モードを使うか否か、または気にする必要がないかを指示する。
この生成規則が適用されたとき、
{\tt WEAVE} は数式シフト文字~(\verb+$+) を{\TeX}テキスト中におくことで
正しいモードにトークンが置かれることを保証しようとする。
%Tokens with the {\jem empty translation} (\verb+<>+) should always have
%{\tt mathness maybe}, lest they cause {\tt WEAVE} to place two
%consecutive math shift characters.
{\jem 空の translation} (\verb+<>+) を持つトークンは常に
{\tt mathness maybe}であるとみなされ、その結果として {\tt WEAVE}が
2つの数式シフト文字を置くことができるように扱われる。

\item 
{\tt name \syntax{token-name}}

これは、{Spider} または {\WEB}のデバッグの時のみに使われる。
%It causes the specified name to be attached to the token, 
これによって、トークンは指定された名前が付与され、
%so that a programmer can search for that name in the C~code generated by 
%{Spider}.
プログラマーは{Spider}によって生成されたC~コードの中からこの名前を
検索することが可能になる。

\end{itemize}

%\paragraph{Token designators}
\paragraph{トークン名}
{Spider} は以下の トークン名を認識する:
\begin{description}
\item[{\tt 識別子(identifier)}]
これを使う {\tt token} コマンドは
{\tt WEAVE} と {\tt TANGLE} に識別子トークンに対する処理を指示する。
残念ながら、{Spider} に何を識別子とすべきかを指定することはできない。
識別子の定義は{\tt WEAVE} と {\tt TANGLE}の内部に組み込まれている。
識別子は以下の正規表現式に合致する最長の文字列である%
\footnote{読者が Unix の正規表現に馴染みがないのであれば、
{\it ed(1)} のマニュアルページを参考にして欲しい。}:
\begin{verbatim}
[a-zA-Z_][a-zA-Z0-9_]*
\end{verbatim}

\item[{\tt 数値(number)}]
{Spider} と {\tt WEAVE}の現状の実現の仕方では、
{\tt token} コマンドは数値定数と文字列定数の両方をカバーする。
識別子と同様に、数値定数と文字定数が何で構成されるかという定義は
変更することができない。
{\samepage
数値定数は以下のような最長合致である%
\footnote{言語が持つ浮動小数点表記をサポートするための
{\WEB} コントロールシーケンスがあって当然である。}:
\begin{verbatim}
[0-9]+(\.[0-9]*)?
\end{verbatim}
}
文字列定数は以下のような最長合致である
\begin{verbatim}
\"([^"]*\\\")*[^"]*\"|'[^@\]'|'\\.'|'@@'
\end{verbatim}
バックスラッシュ~(\verb+\+)でエスケープされた改行は文字列定数に
含むことができる。

\item[{\tt newline}]
これを使う{\tt token} コマンドは {\tt WEAVE} と {\tt
TANGLE} に改行の扱い方を指示する。
後ほど、{\tt WEAVE} に改行を無視させる方法を示す。

\item[{\tt pseudo\_semi}]
これを使う{\tt token} コマンドは、
{\tt WEAVE} が
{\tt @;}という{\WEB} コントロールシーケンスで処理することを指定する。
このコントロールシーケンスは{\tt TANGLE}では常に無視される。

\item[\syntax{characters}]
ここで、characters は非英数字である。
これを使う {\tt token} コマンドは、
文字列をトークンとして定義し、
{\tt WEAVE} と {\tt TANGLE} がこのトークンに対して行なう処理を指示する。
トークンは他のトークンの接頭辞であっても良い; {\tt WEAVE} と {\tt TANGLE}
は最長のものを採用する。
そういうわけで、 C~{\WEB}では、 \verb+==+ は単一の\ \verb+==+ トークン
として読み込まれ、
二つの \verb+=+ トークンとされることはない。
\end{description}




\subsection{予約語トークン}
%Reserved words are attached to a particular {\jem ilk} using the {\tt
%reserved} command.
予約語は{\tt reserved} コマンドで特定の {\jem ilk} と結び付けられる。
\begin{quote}
\tt  reserved \syntax{reserved-word} $[$ilk \syntax{ilk-name}$]$
\end{quote}
%If you're writing a {Spider} file, you may choose any ilk
%names you like, subject only to the restriction that they not conflict
%with other names known to {Spider} (e.g.~predefined key words,
%names of categories, and so on).
{Spider} ファイルを書く時は好きなカテゴリー名を
使うことができる。
守るべき条件は、{Spider} が知っている他の名前(予約キーワード、
ilkの名前、 など)と衝突しないようにすることだけである。
%The convention, however, is to use ilk {\tt with\_like} for a reserved
%word {\tt with}, and so on.%
しかしながら、約束事として例えば{\tt with}という予約語には{\tt with\_like}
という ilk が使われる%
\footnote{%
この約束事のせいで、筆者は有害な機能を{Spider}に加えるという誘惑に
負けてしまった --- もし {\tt reserved} コマンドで ilk を省略してしまったら、
%{Spider} will make an ilk name by appending {\tt \_like}
%to the name of the reserved word.
{Spider}は予約語の名前の後ろに{\tt \_like}を付加した ilk 名を作ろうとする。
%Furthermore, if that ilk doesn't already exist, {Spider} will
%construct one.
さらに、そのような ilk がまだ存在していなければ、
{Spider}はそれを作ってしまう。
この機能を使ってはいけない。
}。

{\tt  ilk}コマンドと {\tt  token} コマンドは非常に似た構文を持つ。
{\tt ilk} コマンドの構文は、以下の通り:
\begin{quote}\tt
\syntax{command} \produces~ilk \syntax{ilk-name}
\syntax{token-descriptions}
\end{quote}
%In translations that appear in {\tt ilk} commands, the self
%marker~({\tt *}) designates the string of characters making up the
%reserved word, surrounded by \verb+\&{...}+, which makes the reserved
%words appear in bold face.
{\tt ilk}コマンド中に現れる translation において、
セルフマーカー~({\tt *})は予約語自身を構成する文字列\ を意味し、
\verb+\&{...}+ で囲まれて
予約語を意味するボールド体で印刷される。








\section{整形印刷文法の構文}
%Defining the tokens of a language is somewhat tedious, but it is
%essentially straightforward, and the definition usually does not need
%fine tuning.
言語のトークンを定義することは、いささか退屈なものである。
しかし、基本的には直接的にでき、
普通は定義自体にチューニングをする必要はない。
%When developing a new {\WEB} with {Spider}, you will spend most of
%your time writing the grammar that tells {\tt WEAVE} how to reduce
%scraps.
{Spider} によって新しい {\WEB} を開発するときには、
ほとんどの時間を {\tt WEAVE} がスクラップを還元するための文法を書くことに
費やすことになるだろう。
%The grammar is defined as a sequence of context-sensitive productions. 
文法は、文脈に依存する生成規則として定義される。
%Each production has the form:
各々の生成規則は次のような形式を持つ:
\begin{quote}
\tt 
\syntax{left context} [ \syntax{firing instructions} ] \syntax{right context}
\\\null\qquad
--> \syntax{left context} \syntax{target category} \syntax{right context}
\end{quote}
%where the left and right contexts are (possibly empty) sequences of
%scrap designators, 
ここで、 left context と right context は(空でも良い)
スクラップシーケンスを示し、
%the firing instructions are a sequence of scrap
%designators and translations (containing at least one scrap
%designator), 
firing instructions は、
スクラップ名称と(少なくとも一つのスクラップを指定している)
トランスレーションのシーケンスであり、そして
%and the target category is a category designator.
target category はカテゴリー名称である。
%If the left and right contexts are both empty, the square brackets
%({\tt []}) can be omitted, and the production is context free.
もし、 left context と right context のいずれも空であれば、
角括弧({\tt []}) は省略可能であり、生成規則は文脈に依存しないものとなる。
%The left and right contexts must be the same on both sides of the {\tt
%-->}.
left context と right context は {\tt -->} の両辺で同一でなければならない。

%What does the production mean?
生成規則の意味するものは何だろうか ?
%Well, {\tt WEAVE} is trying to reduce a sequence of scraps.
そう、{\tt WEAVE} はスクラップのシーケンスを還元しようとする。
%So what {\tt WEAVE} does is look at the sequence, to find out whether
%the left hand side of some production matches an initial subsequence
%of the scraps.
したがって、{\tt WEAVE} はシーケンスを調べ、どの生成規則の左辺が
最初にスクラップの部分シーケンスに合致するかを見つけようとする。
%{\tt WEAVE} picks the first matching production, and {\jem fires} it,
%reducing the scraps described in the firing instructions to a single
%scrap, and it gives the new scrap the {\jem target category}.
{\tt WEAVE} は最初に合致した生成規則を取り上げ、それを {\jem 適用し}、
{firing instructions} に記述されていたスクラップを一つのスクラップに還元し、
新しいスクラップを{\jem target category} とする。
%The translation of the new scrap is formed by concatenating the
%translations in the {\jem firing instructions}, where a scrap
%designator stands for the translation of the designated scrap.
新しいスクラップのトランスレーションは{\jem fireing instructions} の
トランスレーションと結合することによって整形される。
ここで、スクラップ名称は、指定されたスクラップの
トランスレーションのことである。

%Here is the syntax that describes contexts, firing instructions, scrap
%designators, and so on.
以下は、文脈、命令の起動、スクラップの指定などを記述したものである。
\begin{quote}
\tt
\syntax{left context} \produces~\syntax{scrap designators}\\
\syntax{right context} \produces~\syntax{scrap designators}\\
\syntax{firing instruction} \produces \syntax{scrap designator}\\
\syntax{firing instruction} \produces \syntax{translation}\\
\syntax{scrap designator} \produces~?\\
\syntax{scrap designator} \produces~\opt{!}\syntax{category name}\opt{*}\\
\syntax{scrap designator} 
   \produces~\opt{!}\syntax{category alternatives}\opt{*}\\
\syntax{category alternatives} 
   \produces~\rlap{(\syntax{optional alternatives}\syntax{category name})}\\
\syntax{optional alternative} \produces~\syntax{category name}|\\
\syntax{target category} \produces~\#\syntax{integer}\\
\syntax{target category} \produces~\syntax{category name}\\
\end{quote}


%\paragraph{Matching the left hand side of a production}
\paragraph{生成規則の左辺の合致}
%When does a sequence of scraps match the left hand side of a
%production?
生成規則の左辺がスクラップの並びと合致する時とはいつだろうか ?
%For matching purposes, we can ignore the translations and the square
%brackets~({\tt []}), and look at the left hand side just as a sequence
%of scrap designators.
合致させるという目的からいえば、トランスレーションと角括弧~({\tt []})は
無視して、左辺をあたかもスクラップ名称の並びからだけなるものとみなす
ことができる。
%A sequence of scraps matches a sequence of scrap designators if and
%only if each scrap on the sequence matches the corresponding scrap
%designator.
その並びの中の対応するすべてのスクラップの名称が一致したときにのみ
スクラップの並びがスクラップ名称の並びに一致したと見なせる。
%Here are the rules for matching scrap designators (we can
%ignore starring%
ここで、スクラップ名称の一致のための規則は以下の通り(スターは無視して良い
\footnote{オプションの {\tt *}を伴うカテゴリー名は、
{\jem スター付き(starred)}と呼ばれる。}%
):
\begin{itemize}
\item
%Every scrap matches the designator {\tt ?}.
すべてのスクラップは {\tt ?}に一致する。
\item
%A scrap matches \syntax{marked category} if and only if its category
%is the same as the category of the designator.
そのスクラップのカテゴリーが指定されているスクラップ名と一致したときに限り、
そのスクラップは \syntax{marked category} と一致する。
\item
%A scrap matches {\tt!}\syntax{marked category} if and only if its category
%is {\jem not} the same as the category of the designator.
スクラップのカテゴリーが指定されているカテゴリー名と一致して{\jem いなかった}
時にのみ、そのスクラップは {\tt!}\syntax{marked category} と一致する
({\tt !} は否定を意味する)。
\item
%A scrap matches a list of category alternatives if and only if its
%category is on the list of alternatives.
スクラップのカテゴリーが選択リストの中にあった場合のみ、
そのスクラップはカテゴリーの選択リストに一致する。
\item
%A scrap matches a {\jem negated} list of category alternatives if and
%only if its category is {\jem not} on the list of alternatives.
スクラップのカテゴリーが選択リストの中に{\jem 無かった}場合にのみ、
そのスクラップは{\jem 否定された}選択リストに一致する。
\end{itemize}


%\paragraph{Firing a production}
\paragraph{生成規則の適用}
%Once a match is found, {\tt WEAVE} fires the production by replacing
%the subsequence of scraps matching the firing instructions.
いったん合致するものが見つかったら、{\tt WEAVE} は生成規則を適用し、
適用した命令に一致したスクラップのサブシーケンスを置き換えてゆく。
%{\tt WEAVE} replaces this subsequence with a new scrap whose category
%is the target category, and whose translation is the concatenation of
%all the translations in the firing instructions.
{\tt WEAVE}はこのサブシーケンスを目的のカテゴリーを持つ新しいスクラップで
置き換え、そのトランスレーションは適用された規則の中の
すべてのトランスレーションを合わせたものとする
%(When the new translation is constructed, the
%translations of the old scraps are included at the positions of the
%corresponding scrap designators.)
(新しいトランスレーションが作成されるときは、
古いスクラップのトランスレーションはスクラップの対応する場所に取り込まれる
)。
%If the target category is not given by name, but rather by
%number~({\tt \#$n$}), {\tt WEAVE} will take the category of the $n$th
%scrap in the subsequence that matches the left hand side of the
%production, and make that the target category.
もし目的のカテゴリーが名前ではなく {\tt \#$n$}という番号で指定されていたら、
{\tt WEAVE} は生成規則の左辺の対応する $n$番目のカテゴリーを取り上げ、
それを目的のカテゴリーとみなす。

\subparagraph{生成規則適用の副作用}
生成規則が適用されると、 {\tt WEAVE} は 
%for the first identifier in any {\jem starred} scrap.
スタード・スクラップの最初の識別子を \hbox{\jem 下線付の見出し語}とする。


%\paragraph{If no initial subsequence matches any production}
\paragraph{最初のサブシーケンスが生成規則に合致しなかった場合}
%If the initial subsequence of scraps does not match the left hand side
%of any production, {\tt WEAVE} will try to match the subsequence
%beginning with the second scrap, and so on, until a match is found.
%Once a match is found, {\tt WEAVE} fires the production, changing its
%sequence of scraps.
%It then starts all over again at the beginning of the new sequence,
%looking for a match.%
初期サブシーケンスが左辺の生成規則と合致しなければ、
{\tt WEAVE}は次のサブシーケンス以降で合致するものを見つけようとする。
合致するものが見つかれば、 {\tt WEAVE}は生成規則を適用し、
各スクラップの並びを変更する。
そして、新しいシーケンスに対して最初からもう一度やり直す%
\footnote{
%The implementation is better than that; {Spider} figures out just
%how much {\tt WEAVE} must backtrack to get the same effect as
%returning to the beginning.%
この実現方法は、
「最初に戻ると同じ効果を得るためには
{\tt WEAVE}が何回バックトラックをしなければならないかを
{Spider}が 算出する」
というものよりも良い。
}。
%If {\jem no} subsequence of the scraps matches any production, then the
%sequence of scraps is irreducible, and {\tt WEAVE} writes out the
%translations of the scraps, one at a time.
すべてのサブシーケンスがいずれの生成規則とも合致しなかったならば、
スクラップのシーケンスは元に戻されることなく {\tt WEAVE} は
一つずつスクラップの翻訳を書き出す。





\section{{\tt WEAVE} 文法の例}
%This all must seem very intimidating, but it's not really.
%In this section we present some grammar fragments and explain what's
%going on.
ここまでのすべてのことは脅しのように感じたかも知れないが、全くそんなことはない。
この章ではいくつかの文法を示し、何がなされるかを解説する。

\paragraph{簡単な例}
\begin{verbatim} 
? ignore_scrap --> #1
\end{verbatim} 
%This production should appear in  every grammar, because Spidery {\tt
%WEAVE} expects category \verb+ignore_scrap+ to exist with roughly this
%semantics. 
この生成規則はすべての文法に存在しなければならない。
なぜなら、Spidery {\tt WEAVE} は
\verb+ignore_scrap+ というカテゴリーが乱暴にもこの意味で存在していると
みなしているためである
(例えば、コメントは全て {\tt ignore\_scrap} というカテゴリーの
スクラップを生成する) 。
%Any scrap of category \verb+ignore_scrap+ essentially doesn't affect
%the reduction of scraps: it is absorbed into the scrap to its left.
\verb+ignore_scrap+ というカテゴリーのいかなるスクラップも
基本的にはスクラップの還元の影響を受けない:
そのままスクラップの中に置かれたままになる。

\begin{verbatim}
token newline category newline translation <>
newline --> ignore_scrap
\end{verbatim}
%This token definition and production, combined with the previous
%production, causes {\tt WEAVE} to ignore all newlines.
この定義と生成規則は、前述の生成規則と組み合わされて
すべての newline を{\tt WEAVE}に無視させることになる。

%For this next example, from the C~grammar, you will need to know that 
%{\tt math} represents a mathematical expression, {\tt semi} a
%semicolon, and {\tt stmt} a statement or sequence of statements.
次の Cの文法の例では、{\tt math} は算術式、
{\tt semi}はセミコロン、{\tt stmt}は文または文の並びを意味していることを
断っておこう。
\begin{verbatim}
math semi --> stmt
stmt <force> stmt --> stmt
\end{verbatim}
%The first production says that a mathematical expression, followed by
%a semicolon, should be treated as a statement.
第一の生成規則はセミコロンを伴う算術式は文として扱われることを指示する。
%The second says that two statements can be combined to make a single
%statement by putting a line break between them.
第二の生成規則では、 2 つの文は 1 つの文として結合され、
間に改行が置かれることを指示する。

\paragraph{式}
%This more extended example shows the treatment of expressions in Awk.
この拡張された例は、 Awk の式の扱いを示している。
%This is identical to the treatment of expressions in C and in several
%other languages.
これは、C やいくつかの言語における式の扱いと同一である。
%We will use the following categories:
以下のようなカテゴリーを使うことにする:
\begin{description}
\item[math] 算術式 %A mathematical expression
\item[binop] 二項中置演算子 %A binary infix operator
\item[unop] 単項前置演算子または単項後置演算子
 %A unary prefix or postfix operator
\item[unorbinop] 二項中置か単項前置になりうる演算子
 %An operator that could be binary infix or unary prefix
\end{description}
%To show you how these might be used, here are some sample token
%definitions using these categories:
どうやって使われるかを示すために、これらのカテゴリーを用いた
トークンの定義例を示す。
\begin{verbatim}
token + category unorbinop
token - category unorbinop
token * category binop
token / category binop
token < category binop
token > category binop
token , category binop translation <",\\,"-opt-3>
token = category binop translation <"\\K">
token != translation <"\\I"> category binop
token == name eq_eq translation <"\\S"> category binop
token ++ name gt_gt category unop translation <"\\uparrow">
token -- name lt_lt category unop translation <"\\downarrow">
\end{verbatim}
%Notice that the translation for the comma specifies a thin space and
%an optional line break after the comma.
ここではカンマは小さなスペースの後 optional line break
を置くことに注意して欲しい。
{\tt =}、 {\tt !=}、 {\tt ==} の翻訳はそれぞれ
\ $\leftarrow$、 $\ne$、 $\equiv$ となる。


%Here is the grammar for expressions.
以下は、式のための文法である。
\begin{verbatim}
math (binop|unorbinop) math --> math
(unop|unorbinop) math --> math
math unop --> math
math <"\\"-space> math --> math
\end{verbatim}
%In Awk there is no concatenation operator; concatenation is by
%juxtaposition.
Awk では、文字列の結合子がない; 結合は並べて置くことで表記される。
%The last production tells {\tt WEAVE} to insert a space between two
%juxtaposed expressions.
最後の生成規則は {\tt WEAVE} に並置された式の間に
スペースを挿入させるためのものである。

%So far we haven't dealt with parentheses, but that's easily done:
今までは括弧を処理していなかったが、以下のように容易に記述できる:
\begin{verbatim}
token ( category open
token ) category close
token [ category open
token ] category close
open math close --> math
\end{verbatim}


%Now this grammar just given doesn't handle the Awk or C {\tt +=}
%feature very well; {\tt x+=1} comes out as~$x+\leftarrow 1$, and {\tt
%x/=2} is irreducible!
さて、この文法のままでは Awk や C の {\tt +=} という機能を
うまく扱うことができない;
{\tt x+=1} は $x+\leftarrow 1$ のようになり、{\tt x/=2} は
還元することができない。
%Here's the cure; first, we make a new category for assignment:
以下に修正の仕方を述べる;
まず最初に、代入のため新しいカテゴリーを作ることにする。
\begin{verbatim}
token = category equals translation <"\\K">
\end{verbatim}
%And then we write productions that reduces assignment (possibly
%preceded by another operator) to a binary operator:
次に、(他の演算子が先行してもかまわない)代入を二項演算子に還元するための
生成規則を書こう。
\begin{verbatim}
<"\\buildrel"> (binop|unorbinop) <"\\over{"> equals <"}"> --> binop
equals --> binop
\end{verbatim}
%Notice that, given the rules stated above, the second production can
%fire only if {\tt equals} is {\jem not} preceded by an operator.
上記の規則で注意すべきことは、第二の生成規則は
{\tt equals}が演算子を前に{\jem 伴わない}時にのみ適用可能だということである。
%On input~{\tt x+=1}, the first production fires, and we have the
%translation~$x\buildrel+\over{\leftarrow} 1$. 
{\tt x+=1}という入力に対して、第一の生成規則が最初に適用され、
$x\buildrel+\over{\leftarrow} 1$ という翻訳を得ることになる。

\paragraph{条件文}
%Here is the grammar for (possibly nested) conditional statements in
%Awk.
以下は、Awk における(ネスト可能な)条件文の文法である。
\begin{verbatim}
if <"\\"-space> math --> ifmath
ifmath lbrace --> ifbrace
ifmath newline --> ifline
ifbrace <force> stmt --> ifbrace
ifbrace <outdent-force> close else <"\\"-space> if --> if
ifbrace <outdent-force> close else lbrace --> ifbrace
ifbrace <outdent-force> close else newline --> ifline
ifbrace <outdent-force> close --> stmt
(ifline|ifmath) <indent-force> stmt <outdent> --> stmt
\end{verbatim}
%It relies on the following token definitions:
以下のトークンの定義に依存する:
\begin{verbatim}
ilk if_like category if
reserved if
ilk else_like category else
reserved else
token { translation <"\\;\\{"-indent> category lbrace
token } translation <"\\}\\"-space> category close
token newline category newline translation <>
\end{verbatim}

\paragraph{C のプリプロセッサ用命令の扱い}
ここではCプリプロセッサ用命令を扱うための文法の
簡単なバージョンを示す。
プリプロセッサ命令は行の左端におかれ、バックスラッシュでエスケープされた
改行も正しく扱われる。
(最終バージョンはファイル名を {\tt <...>}という
``より小さい'' と ``より大きい'' を意味する同一の記号で括った表記も
可能である。)

{\small\advance\hsize 1in
\begin{verbatim}
# control sequence \8 puts things on the left margin
<"\\8"> sharp <"{\\let\\\\=\\bf"-space> math <"}"-indent-"{}"-space> --> preproc
preproc backslash <force-"\\8\\hskip1em"-space> newline --> preproc
<force> preproc <force-outdent> newline --> ignore_scrap
preproc math --> preproc
newline --> ignore_scrap
\end{verbatim}
}
最初の生成規則にある \verb+\let+ によって、
{\tt \#} に続く識別子をボールド体に変更する。


%\subsection{Using context-dependent productions}
\subsection{文脈依存生成規則の使用}
%So far we've been able to do a lot without using the
%context-dependent features of {Spider} productions.
%(For example, the entire {\tt spider} file for Awk is written using
%only context-free productions.)
%Now we'll show some examples that use the context-dependence.
今までのは、多くのことを文脈に依存しない方法でやってこれた
(例えば、Awk 用の {\tt spider}ファイルは文脈自由規則のみで書かれている)。
今から、文脈依存文法を使った例を示すことにする。

%In the grammar for Ada, a semicolon is used as a terminator for
%statements.
%But semicolons are also used as {\jem separators} in parameter
%declarations.
%The first two productions here find the statements, but the third
%production supersedes them when a semicolon is seen in a parenthesized
%list.
Ada の文法では、セミコロンは文の終端記号である。
しかし、パラメータ宣言では {\jem セパレータ} としても使われる。
以下の最初の 2 つの規則は文を見つけるためにある。
しかし3番目は、括弧で括られたリストの中にあるセミコロンの扱いを変える。
\begin{verbatim}
semi --> terminator
math terminator --> stmt
open [ math semi ] --> open math
\end{verbatim}


%\paragraph{Underlining the index entry for the name of a declared
%function}
\paragraph{宣言された関数名の下線付けされた索引登録}
%In SSL, function declarations begin with the type of the function
%being declared, followed by the name of that function.
SSL では、関数の宣言は関数名の前に関数の型を宣言する。
%The following production causes the index entry for that function to
%be underlined, so that we can look up the function name in the index
%and easily find the section in which the function is declared:
以下の生成規則は、関数を下線付きで索引に登録する。したがって、
索引の中で関数名を調べることができ、宣言されているセクションを
見つけることが可能である。
\begin{verbatim} 
decl simp [ simp* ] --> decl simp math
\end{verbatim}
%Where we've relied on
ここでは、以下の定義に依存している。
\begin{verbatim}
token identifier category simp mathness yes
\end{verbatim}


\paragraph{条件式}
%Suppose we want to format conditional expressions (for example in C)
%like this:
(例えば C において)次のように条件式を整形することを考えよう。
\begin{quote}
\syntax{condition}\\
\mbox{\qquad}$?$ \syntax{expression}\\
\mbox{\qquad}$:$ \syntax{expression}
\end{quote}
%The problem is that it's hard to know when the conditional expression
%ends.
ここでの問題は、いつ条件式が終るかを判断するのが難しいことである。
%It's essentially a question of precedence, 
これは、基本的に先読み問題であり、
%and what we're going to do
%is look ahead until we see an operator with sufficiently low
%precedence that it terminates a conditional expression.
やるべきことは、条件式を終端させるに十分な程度に
演算子を先読みすることである。
%In SSL a conditional expression can be terminated by a semicolon, a
%right parenthesis, a comma, or a colon.
SSL では、条件式はセミコロン、右括弧、カンマ、コロンで終端し得る。
%We'll use the {\jem right context} to do the lookahead.
先読みをするために、{\jem right context} を使うことにしよう。
{\small
\begin{verbatim}
token ? translation <"\\?"> category question
token : category colon

<indent-force> question math <force> colon --> condbegin
[ condbegin math <outdent> ] (semi|close|comma|colon) --> math (semi|close|comma|colon)
\end{verbatim}
}




\subsection{整形印刷文法のデバッグ}
{\tt WEAVE} は整形印刷文法のデバッグに役立つ 2 つのモードを持つ。
{\tt @1} という制御シーケンスは部分トレースを開始し、
{\tt @2} はフルトレースを開始する。
{\tt @0} はトレースをオフにする。%turns tracing back off again.
%In the partial tracing mode, {\tt WEAVE} applies all the productions
%as many times as possible, 
部分トレースモードでは、{\tt WEAVE} は可能な限りすべての生成規則を
適用し、結果として還元できなかった残りのスクラップをプリントアウトする。
%and then it prints out the irreducible
%scraps that remain.
%If the scraps reduce to a single scrap,  no diagnostics are printed.
スクラップがすべて一つのスクラップに還元できた場合は、
診断メッセージはプリントされない。

%When a scrap is printed, {\tt WEAVE} prints a leading
%{\tt+}~or~{\tt-}, the name of the category of that scrap, and a
%trailing {\tt+}~or~{\tt-}.
スクラップがプリントされるとき、{\tt WEAVE} は、{\tt+}~か~{\tt-}のリーダー、
そのスクラップのカテゴリー名、{\tt+}~か~{\tt-}のトレーラーをプリントする。
%The {\tt+} indicates that {\TeX} should be in math mode, and the
%{\tt-} that {\TeX} should not be in math mode, at the beginning and
%end of the scrap's translation, respectively.
それぞれのスクラップのトランスレーションの始めと終わりで、
{\tt+} は {\TeX} が数式モードに入ったことを示し、
{\tt-} は {\TeX} が数式モードでなくなったことを示す
%(You can see the translations by looking at the {\tt.tex} file, since
%that's where they're written out.)
(トランスレーションは{\tt.tex}ファイルを見れば解る)。

%For beginners, the full trace is more helpful.
初心者にとっては、フルトレースの方が役に立つ。
%It prints out the following information every time a production is
%fired:
フルトレースモードでは、生成規則が適用される度に以下の情報をプリントする:
\begin{itemize}
\item
%The number of the production just fired (from {\tt productions.list});
適用した生成規則の({\tt productions.list}に書き出された)番号;
\item
%The sequence of scraps {\tt WEAVE} is now trying to reduce;
{\tt WEAVE}が現在還元しようとしているスクラップの並び;
\item
%A {\tt*} indicating what subsequence {\tt WEAVE} will try to reduce next.
{\tt*} で示される {\tt WEAVE} が次に還元しようとしているサブシーケンス。
\end{itemize}
%A good way to understand how 整形印刷文法 work is to take
%a {\tt productions.list} file, and look at a full trace of the
%corresponding {\tt WEAVE}.
整形印刷文法 の働きを知る良い方法は、
{\tt productions.list} ファイルを手にとって、
{\tt WEAVE} がプリンとしたフルトレースと
突き合わせることである。
%Or, if you prefer, you can simulate by hand the action of {\tt WEAVE}
%on a sequence of scraps.
もしくは、お望みならば、{\tt WEAVE} がスクラップの並びに対して行う動作を手で
シミュレートしてもいいだろう。


\section{{Spider} 言語の残り}
%The tokens and the grammar are not quite the whole story.
%Here's  the rest of the truth about what you can do with {Spider}.
トークンと文法で話しがすべて終ったわけではない。
この章では、 {Spider} でできることの未説明の部分を述べる。

\subsection{ターゲット言語の命名}
%When a Spidery {\tt WEAVE} or {\tt TANGLE} starts up, it prints the
%target language for which it was generated, and the date and time of
%the generation.
Spidery {\tt WEAVE} または Spidery {\tt TANGLE} が起動された時、
ターゲット言語と作成日時を表示する。
{\tt language} コマンドはターゲットにする言語を指定する。

構文は以下の通り。
\begin{quote}
\tt language \syntax{language-name}
\opt{extension \syntax{extension-name}}\\
\mbox{\qquad\qquad}\opt{version \syntax{version-name}}
\end{quote}
extension--name は、{\tt TANGLE} がプログラムを書き出す
拡張子として({\tt .web}ファイルに埋め込むために)使われる。
extension は、{\tt WEAVE} で使われる 言語に固有の 
{\TeX} マクロファイルを生成する時にも使われる。
したがって、異なる言語は異なる拡張子(extension) を持たなければならない。
extension が指定されていない時は、言語名がデフォルトとなる。
version 情報が指定されていれば、それもプログラム起動時に表示されるようになる。

筆者が Unix で使っている {\tt c.spider} では、以下のようになっている。
\begin{verbatim}
language C extension c
\end{verbatim}




\subsection{{\TeX} マクロの定義}
%In addition to the ``kernel'' {\WEB} macros stored in {\tt
%webkernel.tex}, you may want to create some {\TeX} macros of your
%own for use in translations.
{\tt webkernel.tex}に記述されている「カーネル」{\WEB}マクロを拡張するために、
translations の中で使う専用の{\TeX}マクロを
定義することができる。
%Any macro definitions you put between lines saying {\tt macros begin}
%and {\tt macros end} will be included verbatim in the {\TeX} macro
%file for this language.
どんなマクロでも、{\tt macros begin}行と
{\tt macros end} 行の間にあるものは
そのままその言語用の {\TeX} マクロファイルの中に取り込まれる。
%That macro  file will automatically be \verb+\input+ by every {\TeX}
%file generated by this {\tt WEAVE}.
このマクロファイルは、%That macro  file will automatically be 
{\tt WEAVE}によって生成されるすべての {\TeX}ファイルに
\verb+\input+ 命令で自動的に取り込まれるようになる。

%For example, the C grammar includes productions to handle preprocessor
%directives.
%These  directives may include file names that are delimited by angle
%brackets.
%I wanted to use the abbreviations \verb+\LN+ and \verb+\RN+ for left
%and right angle brackets, so I included
例えば、C の文法はプリプロセッサ命令を扱う規則を含んでいる。
この命令は角カッコで括ったファイル名を使う。
筆者は、\verb+\LN+ , \verb+\RN+ を左角カッコ, 
右角カッコの短縮形として使うため、
以下の定義を{\tt c.spider} ファイルに書いてある。
\begin{verbatim}
macros begin
\let\LN\langle
\let\RN\rangle
macros end
\end{verbatim}


\subsection{デフォルトのトークン情報の設定}
%It's possible to set default values for the {\tt translation} and {\tt
%mathness} properties of tokens, so that they don't have to be
%repeated.
トークンの \hbox{\tt translation} と \hbox{\tt mathness} のデフォルト値を
設定することにより、毎回繰り返して記述する必要がなくなる。
%This is done with the {\tt default} command, whose syntax is:
これは\hbox{\tt default} コマンドを使う。書式は以下の通り:
\begin{quote}
\tt
default \syntax{token descriptions}
\end{quote}
%The initial defaults (when {Spider} begins execution) are {\tt
%translation~<*>} and {\tt mathness~maybe}.
({Spider}が実行開始したときの)デフォルト値の初期値は
{\tt translation~<*>} と {\tt mathness~maybe}である。






\subsection{モジュールの扱い方の指定}
{\WEB} は、他のどんなプログラミング言語にもなかった種類のトークン
「モジュール名」を導入した({\tt @<...@>} または {\tt @(...@>})。
%introduces a new kind of token that isn't in any programming
%language, and that's the module name ({\tt @<...@>} or {\tt @(...@>}).
{\tt TANGLE}の仕事は、このモジュール名をプログラムテキストにすることであり、
%'s job is to convert the module names to program text, and
モジュール名がなくなった時に終了する。
%when {\tt TANGLE} is finished no module names remain.
しかし、{\tt WEAVE} はモジュール名を組版しなければならないので、
%has to typeset the module names, and we need to tell
{\tt WEAVE} がモジュール名をどんなカテゴリーのスクラップにするかを
規定してやる必要がある。
%what category to give a scrap created from a module name.
2つのカテゴリーが許される。
%We allow two different categories, 
1つはモジュール名の定義 (モジュールの開始)用であり、
もう一つは、モジュール名の使用時のものである。
{\samepage
{\tt module}コマンドの構文は以下の通り。
\begin{quote}
\tt
module \opt{definition \syntax{category name}} 
\opt{use \syntax{category name}}
\end{quote}
}

{\tt c.spider} では以下のようにしている。
\begin{verbatim}
module definition decl use math
\end{verbatim}

\subsection{at sign の決定}
{Spider}で{\WEB}システムを作るならば、
 ``{\tt @}'' を ``magic at sign'' として{\WEB}の制御コマンドの
開始キャラクタにする必要はない。
しかしながら、慣例として、望ましくない場合以外は ``{\tt @}'' 
を使うことにしよう。
``{\tt @}'' が望ましくない時は、代わりに ``{\tt \#}''を使うことにする。
{Spider} で {\tt WEAVE} と {\tt TANGLE} の C~{\WEB} コードを書くには、
多くの {\tt @} を書くことになる。
一つ一つをエスケープしなければならない時に筆者はそうはしなかった。
``{\tt \#}'' Awk~{\WEB}の at~sign を ``{\tt \#}'' にした:
\begin{verbatim}
at_sign #
\end{verbatim}
指定されない時にはデフォルトは ``{\tt @}'' のままである。

\paragraph{コントロールシーケンスの変更}
at~sign の変更はひとつか二つのコントロールシーケンスの意味を変更する。
%This is more easily illustrated by example than explained.
言葉で説明するよりは例を示した方が解りやすいので、
at~sign を{\tt\#}に変えた場合を示そう。
結果として {\WEB} の二つのコントロールシーケンスは新しい意味を持つことになる:
\begin{description}
\item[{\tt \#\#}]
%Stands for a {\tt \#} in the input, by analogy with {\tt @@} in normal
%{\WEB}.
通常の{WEB}の{\tt @@}と同様な意味で、入力中の{\tt\#}を示す。
%You will need this when defining {\TeX} macros that take parameters.
パラメータを伴う{\TeX} マクロを定義するときに必要になる。
\item[{\tt \#@}]
%This is the new name of the control sequence normally represented by
%{\tt@\#}.
これは、通常の{\tt@\#}という制御シーケンスの新しい名前である。
% You would use {\tt\#@} to get a line break followed by vertical
%white space.
{\tt\#@}は、垂直スペースを伴う改行を得るときに使う。
\end{description}
%If you change the at sign to something other than {\tt@}~or~{\tt\#},
%the above will still hold provided you substitute your at sign for
%{\tt\#}.
もしあなたが at~sign を {\tt@}~または~{\tt\#} 以外の何かに変えたなら、
上の記述の{\tt\#}をあなたが指定した at~sign に置き換えて読めば良い。




\subsection{プログラム言語内でのコメント}
{\tt WEAVE} と {\tt TANGLE} にターゲット言語の中のコメントの扱いを
指定しておかなければならない。
コメントテキストは、
{\tt WEAVE}では{\TeX}テキストとして扱われなければならないし、
{\tt TANGLE}では無視されなければならない。
{\tt comment} コマンドの構文は、以下の通り。
\begin{quote}
\tt
comment begin \syntax{restricted translation} \\
\null\qquad end $(\syntax{restricted translation}|{\tt newline})$
\end{quote}
括られた文字列、{\tt space}、{\tt dash} のみが、
制限つきの translation として記述できる。
%They give the character sequences that begin and end comments.
これらはコメントの開始と終了の文字列である。
コメントが改行で終了するのなら、正しいおまじないは {\tt end
newline}である。

もしコメント文字が ``at sign''と同じであれば、
{\WEB} ファイルの中では二重に書かなければならない。
%file to have any effect.
筆者が忘れてしまったせいで、
{Spider} これを検出できない馬鹿者になってしまい、
%is too dumb to figure this out 
{\jem {\tt Spider} ファイルの中で
コメント文字を二重に書かねばならなくなってしまった}。
%This is not totally unreasonable since any at sign that actually appears in a
%{\WEB}  file will have to be double to be interpreted correctly.
{\WEB}ファイルが正しく解釈するために at~sign が現実には
二重に書かれなければならないので、総合的には全く不当というわけではない。


{\tt WEAVE} は \verb+\commentbegin+ と
\verb+\commentend+ というマクロを
コメントの開始と終了に使う。
%at the beginning and end of comments, so you can
よって、{Spider}のデフォルトが気に入らなければ
({\tt macros}コマンドを使って)好きなように定義することができる。
{Spider} は{\TeX}のデフォルトの特殊文字を回避する程度には十分スマートである。
%is smart enough to escape {\TeX}'s special characters in
%coming up with these defaults.

%Here's a real-world ugly example of how things really are, from the
%{\tt spider} file for Awk:
以下に実際にどうしているかを Awk の{\tt spider} ファイルから引用する:
\begin{verbatim}
comment begin <"##"> end newline
macros begin
\def\commentbegin{\#} % we don't want \#\#
macros end
\end{verbatim}



\subsection{行番号の制御}
 コンパイラが{\WEB}ファイルを直接見ることはない。{\tt TANGLE} の
出力を読まねばならない。
{\tt TANGLE}が作ったファイルの行番号を示すエラーメッセージは、
非常に有効だとは言い難い。そこで、
Spidery {\tt TANGLE} は、多少改善した状況を提供するため、
 C~プリプロセッサー用の {\tt \#line} 命令を出力に書く(
{\tt TANGLE} も{\WEB} ソースの改行情報を保持しているので、
 {\tt \#line} 情報は有用だろう)。
{\tt cc} と {\tt dbx}を持った
Unix のようなシステムでは、コンパイル時とランタイム時の両方で
{\WEB}ソースの用語でデバッグすることができる。
中間のプログラミングソースはけっして調べる必要がない。

全てのコンパイラが{\tt \#line}命令をサポートしているわけではないので、
{Spider}は {\tt line} コマンドで
 {\tt \#line} 命令のフォーマットを変更できるようになっている。
自分のコンパイラが {\tt \#line} をサポートしていなければ、
{\tt line} コマンドを使って行番号情報をコメントの中に入れるように
変更することができる\footnote{%
行番号を出さないコマンドがあるべきである。%
}。
構文は以下の通り:
\begin{quote}
\tt
line begin \syntax{restricted translation} end \syntax{restricted translation}
\end{quote}
{\tt begin} はファイル名と行番号の前に置く文字列を指定し、
{\tt end} は後に置く文字列を指定する。
デフォルトは (C用に設定されているが)以下の通り。
\begin{verbatim}
line begin <"#line"> end <"">
\end{verbatim}
次のは Ada~{Spider}ファイルでの例である。
ここでは、行番号情報を Ada のコメントとしている:
\begin{verbatim}
line begin <"--"-space-"line"> end <"">
\end{verbatim}




\subsection{作成日時の表示}
Spidery {\tt WEAVE} と{\tt TANGLE}が処理を始める時、
{Spider}ファイルを処理した日時が表示される。
これは、{Spider}の {\tt date}コマンドによって次のように設定される。
\begin{quote}
\tt
date \syntax{date}
\end{quote}
ここで \syntax{date} は、{\tt "Fri Dec 11 11:31:18 EST 1987"} などである。
通常、{\tt date} コマンドの必要はない。
{Spider} ツールが自動的に挿入する。
しかし、Unix マシンでないシステムに{Spider}を移植する時には、
上記のことが必要になる。





\section{Spiderのエラーメッセージ}
{Spider} は仕様上のエラーを検出するために非常な努力をする。
{Spider}のエラーメッセージは読めばわかるように作るつもりであるが、
うまく成功させる方法を知らない。
トラブルにあった時のために、以下に{Spider}が検出しようとしている条件を示しておく:
\begin{itemize}
\item 
 未定義なコマンド、誤ったフィールドを含む行、
%Garbled commands, lines with bad fields in them, or commands with
使われないフィールドを持つコマンド。
%Any command with a field {Spider} can't follow or with an extra
%field is ignored from the bad field onward, but the earlier fields may
%have an effect.
フィールドが必要なすべてのコマンドについて、
{Spider}はフィールドを補わないしよけいなフィールド以降を無効とする。
ただし、それ以前のフィールドは有効になるかも知れない。
誤ったフィールドやエラーのある生成規則は完全に無効とされる。
\item
{\tt language} コマンドがない。
\item
{\tt macros} または {\tt comment} コマンドが {\tt language} コマンドの
前に定義されている。
{Spider}  は {\tt extension} 情報を
from the  {\tt language} コマンドから得ており、
マクロを書き出すファイル名を決定するために使う。
また{\tt comment} コマンドは
{Spider} が{\TeX}のためにコメントの始まりと終りを
マクロファイルに書くことを要請する。
\item
文脈が左導出、右導出のいずれにも合致しない。
\item
%A numbered target token doesn't fall in the range defined by the
%left hand side of its production.
番号で参照されたトークンがその生成規則の左辺にない。
\item
{\jem 追加できない}カテゴリーがある。
これは、そのカテゴリーがスクラップを生成する方法がないことを意味する。
{Spider} は単にすべてのカテゴリーが少なくとも一度は
トークンかターゲットトークンとして生成規則の中に現れることを
調べているだけである。
(もしけして適用されない生成規則があるならば)
{Spider}は条件を検出できないので失敗する。
\item
{\jem 還元できない}カテゴリーがある。
これは、このカテゴリーが生成規則の中で参照されていないことを意味する。
%This  means that the category never appears in a scrap
%designator from the firing instructions of a production.
カテゴリーが還元できなければ、
{Spider} は単に警告を出すのみで、
エラーによって処理を停止することはない。

カテゴリー名の綴の誤りによる追加と還元のチェックはたいてい検出される。
\item
{\tt WEAVE} と {\tt TANGLE} が扱える以上の
トークンを指定している。
\item
トークンの情報が不完全; 識別子、数値定数、newline、
疑似セミコロン~({\tt @;})、モジュール定義、モジュールの使用を忘れている。
\item
ilk が translation を持たない、または予約語を持たない ilk があった。
%no reserved words.
\end{itemize}




\section{{Spider}の出力ファイル}
{Spider} は多くの出力ファイルを生成する。必要ならそれらを調べ、
何がなされているかを解析できる。
以下はその一部である (完全なファイルのリストは
{\tt spider.web}を調べればわかる):
\begin{description}
\item[\tt cycle.test]
文法のループ可能性を検出するのに使用される。
このようなループは 特定の入力に対し{\tt WEAVE} を無限に (メモリーを使いきるまで)
走らせることになるようなものである。
後で {Spider}ツールと一緒に議論する。
\item[\tt spider.slog]
{Spider} がファイルを処理中のすべての冗長な内容。
ひどいことが起きた時に調べるためのものである。
\item[\tt *web.tex]
生成された{\WEB}のためのマクロ。
\item[\tt productions.list]
すべての規則の番号付けしたリスト。
Spidery {\tt WEAVE}のトレース機能 ({\tt @2})を使って文法のデバッグを
する際に重宝する。
\end{description}




\section{{Spider} で{\WEB}を作る ({Spider} tools)}
多くの {Spider} ツールがエラーをチェックする。例えば:
\begin{itemize}
\item
カテゴリー、ilk、translation のキーワード名の重複チェックをする。
\item
translation キーワードが{\tt WEAVE}のキーワードと衝突していないかをチェックし、
衝突していれば警告を発する。
%keywords against a list of those recognized by
% and yelps if trouble happens.
\item
{\tt WEAVE}が無限ループに陥るような「生成規則の循環」がないかを検出する。
%Try to determine whether there is a ``production cycle'' that could
%cause  to loop infinitely by firing the productions in the
%cycle one after another.
\end{itemize}

ここでは、それらがどうなっているか、{\tt WEAVE} や {\tt TANGLE}を
どうやって生成するかについて、多くを説明するつもりはない。
%I'm not going to say much about how to do all this, or how to make
代わりに、{\tt Makefile} を提示し、少々コメントすることにしよう。
%and comment on it a little bit.
%Since right now Spidery {\tt WEB} is available only on Unix systems,
%chances are you have the {\tt Makefile} and can just type ``{\tt
%make~tangle}'' or ``{\tt make~weave}.'' 
現在のところ、 Spidery {\tt WEB} は Unix システムの上にしか存在していない。
{\tt Makefile} を入手し、
 ``{\tt make~tangle}'' または ``{\tt make~weave}'' とタイプするだけで
よい可能性がある。
%If not, reading the Makefile is still your best bet to figure out what
%the tools do.
そうでないとしても、 Makefile を読んでツールのすることを理解するのが
最善の方法である。

%We assume that you are making {\tt WEAVE} and {\tt TANGLE} in some
%directory, and that the ``master sources'' for Spidery {\WEB} are kept
%in some other directory.
あなたは既に {\tt WEAVE} と {\tt TANGLE} をどこかのディレクトリーに作ってあり、
Spidery {\WEB} の ``master sources'' がどこか別のディレクトリーに
保管されているのを前提とする。
%Some of the  {\tt Makefile} macros deserve special mention:
{\tt Makefile} の マクロのいくつかは特に言及する価値がある:
\begin{description}
\renewcommand{\makelabel}[1]{{\tt#1}\hfil}
\item[THETANGLE]
生成しようとしている {\tt TANGLE} の名前。
\item[THEWEAVE]
生成しようとしている{\tt WEAVE} の名前。
\item[SPIDER]
{Spider} の入力ファイル名。
\item[DEST]
\verb+$(TANGLE)+ と\verb+$(WEAVE)+ として定義された実行ファイルが置かれるべき
ディレクトリー。
\item[WEBROOT]
Spidery {\WEB} 配布物のルートディレクトリー。
\item[MASTER]
``マスターソース''のある場所。
これは、必ず {\tt make} が実行されるディレクトリーと異なっていなければならない。
さもなければ台無しになってしまうだろう。
%This should always be different from the directory in which {\tt make}
%is called, or havoc will result.
\item[CTANGLE]
tangle の C コードで使われるプログラム名。
\item[AWKTANGLE]
Awkのコードを tangle するプログラムの名前。

\item[MACROS]
%The name of a directory in which to put {\TeX} macro definitions (a
%{\tt *web.tex} file.
{\TeX}マクロファイル({\tt *web.tex} )を格納するべきディレクトリー名。
\end{description}

%Usually we will only be interested in two commands: ``\/{\tt
%make~weave}'' and ``\/{\tt make~tangle}.''
普段良く使うのは \hbox{``{\tt make~weave}''} と
\hbox{``\/{\tt make~tangle}''} の
2つのコマンドだけであろう。
%It's safe to use ``\/{\tt make~clean}'' only if you use the current
%directory for nothing exception spidering; ``\/{\tt make~clean}'' is
%really vicious.
\hbox{``{\tt make~clean}''} は、 現在のディレクトリーで
{\WEB} 作成作業以外のことをしない時でなければ安全ではない。
%only if you use the current directory 
%for nothing exception spidering;
\hbox{``\/{\tt make~clean}''}は、 本当にひどいことをする。

本当に興味深い行は、
{\tt grammar.web} の依存関係を表記しているところである。
第一に、 {Spider}を起動する。
次に、整形印刷文法 の中に、間違った translation キーワードや
循環の可能性がないかをチェックする。
そして、名前のに重複定義がないことをチェックし、
最後に (全てがOKだったら)
{\tt *web.tex} ファイルを出力する。

\newpage
以下は、 \verb+$(MASTER)/WebMakefile+である:
\begingroup\small
\begin{verbatim}
# Copyright 1989 by Norman Ramsey and Odyssey Research Associates.
# To be used for research purposes only.
# For more information, see file COPYRIGHT in the parent directory.

HOME=/u/nr#			# Make no longer inherits environment vars
THETANGLE=tangle
THEWEAVE=weave
SPIDER=any.spider
#
DVI=dvi
CFLAGS=-DDEBUG -g -DSTAT

# CPUTYPE is a grim hack that attempts to solve the problem of multiple
# cpus sharing a file system.  In my environment I have to have different
# copies of object and executable for vax, sun3, next, iris, and other 
# cpu types.  If you will be using Spidery WEB in a homogeneous processor
# environment, you can just set CPUTYPE to a constant, or eliminate it 
# entirely.  
#
# In my environment, the 'cputype' program returns a string that
# describes the current processor.  That means that the easiest thing
# for you to do is to define a 'cputype' program that does something
# sensible.  A shell script that says 'echo "vax"' is fine.

CPUTYPE=`cputype`

# Change the following three directories to match your installation
#
# the odd placement of # is to prevent any trailing spaces from slipping in

WEBROOT=$(HOME)/web/src# 	# root of the WEB source distribution
DEST=$(HOME)/bin/$(CPUTYPE)#	 	# place where the executables go
MACROS=$(HOME)/tex/macros# 	# place where the macros go

MASTER=$(WEBROOT)/master# 	# master source directory
OBDIR=$(MASTER)/$(CPUTYPE)#	# common object files

TANGLESRC=tangle
CTANGLE=ceetangle -I$(MASTER)
CWEAVE=ceeweave -I$(MASTER)
AWKTANGLE=awktangle -I$(MASTER)
COMMONOBJS=$(OBDIR)/common.o $(OBDIR)/pathopen.o
COMMONC=$(MASTER)/common.c $(MASTER)/pathopen.c
COMMONSRC=$(COMMONC) $(MASTER)/spider.awk



# Our purpose is to make tangle and weave

web: tangle weave

tangle: $(COMMONOBJS) $(TANGLESRC).o
	cc $(CFLAGS) -o $(DEST)/$(THETANGLE) $(COMMONOBJS) $(TANGLESRC).o

weave: $(COMMONOBJS) weave.o
	cc $(CFLAGS) -o $(DEST)/$(THEWEAVE) $(COMMONOBJS) weave.o


source: $(TANGLESRC).c $(COMMONSRC) # make tangle.c and common src, then clean
	if [ -f WebMakefile ]; then exit 1; fi  # don't clean the master!
	if [ -f spiderman.tex ]; then exit 1; fi # don't clean the manual
	-rm -f tangle.web weave.* common.* # remove links that may be obsolete
	-rm -f *.unsorted *.list grammar.web outtoks.web scraps.web 
	-rm -f cycle.test spider.slog
	-rm -f *.o *.tex *.toc *.dvi *.log *.makelog *~ *.wlog *.printlog

# Here is how we make the common stuff

$(MASTER)/common.c: $(MASTER)/common.web # no change file
	$(CTANGLE) $(MASTER)/common 

$(OBDIR)/common.o: $(MASTER)/common.c
	cc $(CFLAGS) -c $(MASTER)/common.c
	mv common.o $(OBDIR)


$(MASTER)/pathopen.c: $(MASTER)/pathopen.web # no change file
	$(CTANGLE) $(MASTER)/pathopen 
	mv pathopen.h $(MASTER)

$(OBDIR)/pathopen.o: $(MASTER)/pathopen.c
	cc $(CFLAGS) -c $(MASTER)/pathopen.c
	mv pathopen.o $(OBDIR)


## Now we make the tangle and weave source locally

$(TANGLESRC).c: $(MASTER)/$(TANGLESRC).web $(MASTER)/common.h grammar.web
	-/bin/rm -f $(TANGLESRC).web
	ln $(MASTER)/$(TANGLESRC).web $(TANGLESRC).web
#	chmod -w $(TANGLESRC).web
	$(CTANGLE) $(TANGLESRC)

weave.c: $(MASTER)/weave.web $(MASTER)/common.h grammar.web 
	-/bin/rm -f weave.web
	ln $(MASTER)/weave.web weave.web
#	chmod -w weave.web
	$(CTANGLE) weave 

## Here's where we run SPIDER to create the source

grammar.web: $(MASTER)/cycle.awk $(MASTER)/spider.awk $(SPIDER)
	echo "date" `date` | cat - $(SPIDER) | awk -f $(MASTER)/spider.awk
	cat $(MASTER)/transcheck.list trans_keys.unsorted | awk -f $(MASTER)/transcheck.awk
	awk -f $(MASTER)/cycle.awk < cycle.test
	sort *.unsorted | awk -f $(MASTER)/nodups.awk
	mv *web.tex $(MACROS)

## We might have to make spider first.

$(MASTER)/spider.awk: $(MASTER)/spider.web
	$(AWKTANGLE) $(MASTER)/spider
	mv cycle.awk nodups.awk transcheck.awk $(MASTER)
	rm junk.list


# $(MASTER)/cycle.awk: $(MASTER)/cycle.web # making spider also makes cycle
# 	$(AWKTANGLE) $(MASTER)/cycle


# This cleanup applies to every language

clean:
	if [ -f WebMakefile ]; then exit 1; fi # don't clean the master!
	if [ -f spiderman.tex ]; then exit 1; fi # don't clean the manual
	-rm -f tangle.* weave.* common.* # remove links that may be obsolete
	-rm -f *.unsorted *.list grammar.web outtoks.web scraps.web 
	-rm -f cycle.test spider.slog
	-rm -f *.c *.o *.tex *.toc *.dvi *.log *.makelog *~ *.wlog *.printlog



# booting the new distribution
boot:
	cd ../master; rm -f *.o; for i in $(COMMONC); do \
		cc $(CFLAGS) -c $$i; \
		mv *.o $(OBDIR) ; \
	done; cd ../c
	cc $(CFLAGS) -c $(TANGLESRC).c; \
	cc $(CFLAGS) -o $(DEST)/$(THETANGLE) $(COMMONOBJS) $(TANGLESRC).o

 
\end{verbatim}
\endgroup

\section{自分用の Spidery {\tt WEB}を作る}
今のところ、 Spidery {\tt WEB} はUnix マシンでしかテストされていない。
Cコンパイラと Awk インタープリターの動くマシンであれば、移植は簡単なはずだが、
間違いなく、いくつかの修正が必要であろう。
このマニュアルも含んだ 完全な{Spider}の配布は、anonymous {\tt ftp}
( {\tt princeton.edu:~ftp/pub/spiderweb.tar.Z}) で入手できる。
{Spider} をインストールするディレクトリーを選び、配布されたものを untar し、
%distribution, and follow the directions in the 
README ファイルの指示に従えば良い。
選んだディレクトリーは、{\tt WEBROOT}となる。

もし、配布の中の {\tt Makefile} が、上記で示したものと違っていたら、
配布の中のものが正しいと考えて欲しい。




\pagebreak
\section{実際の {Spider} ファイル}
これまで、{Spider}の使い方を説明するために実際の例を使ってきた。
ここでは、Awk 言語用の完全な {Spider} ファイルを発展した例として以下に示す。
配布されたものを簡単に研究できない人は、これが役立つであろう。
\begingroup\small
\begin{verbatim}
# Copyright 1989 by Norman Ramsey and Odyssey Research Associates.
# To be used for research purposes only.
# For more information, see file COPYRIGHT in the parent directory.

language AWK extension awk

at_sign #

module definition stmt use stmt
# use as stmt is unavoidable since tangle introduces line breaks

comment begin <"##"> end newline
macros begin
\def\commentbegin{\#} % we don't want \#\#
macros end

line begin <"#line"> end <"">

default translation <*> mathness yes

token identifier category math mathness yes
token number category math mathness yes
token newline category newline translation <> mathness maybe
token pseudo_semi category ignore_scrap mathness no translation <opt-0>

token \ category backslash translation <> mathness maybe
token + category unorbinop
token - category unorbinop
token * category binop
token / category binop
token < category binop
token > category binop
token >> category binop translation <"\\GG">
token = category equals translation <"\\K">
token ~ category binop translation <"\\TI">
token !~ category binop translation <"\\not\\TI">
token & category binop translation <"\\amp">
token % translation <"\\%"> category binop
token ( category open
token [ category lsquare
token ) category close
token ] category close
token { translation <"\\;\\{"-indent> category lbrace
token } translation <"\\}\\"-space> category close
token , category binop translation <",\\,"-opt-3>

token ; category semi translation <";"-space-opt-2> mathness no
# stuff with semi can be empty in for statements
open semi --> open
semi semi --> semi
semi close --> close
semi --> binop

# token : category colon
# token | category bar
token != name not_eq translation <"\\I"> category binop
token <= name lt_eq translation <"\\L"> category binop
token >= name gt_eq translation <"\\G"> category binop
token == name eq_eq translation <"\\S"> category binop
token && name and_and translation <"\\W"> category binop
token || name or_or translation <"\\V"> category binop
# token -> name minus_gt translation <"\\MG"> category binop
token ++ name gt_gt category unop translation <"\\uparrow">
token -- name lt_lt category unop translation <"\\downarrow">
# preunop is for unary operators that are prefix only
token $ category preunop translation <"\\DO"> mathness yes

default mathness yes translation <*>

ilk pattern_like category math
reserved BEGIN ilk pattern_like
reserved END ilk pattern_like

ilk if_like category if
reserved if
ilk else_like category else
reserved else

ilk print_like category math
# math forces space between this and other math...
reserved print ilk print_like
reserved printf ilk print_like
reserved sprintf ilk print_like


ilk functions category unop mathness yes
reserved length ilk functions
reserved substr ilk functions
reserved index ilk functions
reserved split ilk functions
reserved sqrt ilk functions
reserved log  ilk functions
reserved exp ilk functions
reserved int ilk functions

ilk variables category math mathness yes
reserved NR ilk variables
reserved NF ilk variables
reserved FS ilk variables
reserved RS ilk variables
reserved OFS ilk variables
reserved ORS ilk variables

ilk for_like category for
reserved for ilk for_like
reserved while ilk for_like

ilk in_like category binop translation <math_bin-*-"}"> mathness yes
# translation <"\\"-space-*-"\\"-space>
reserved in ilk in_like

ilk stmt_like category math
reserved break ilk stmt_like
reserved continue ilk stmt_like
reserved next ilk stmt_like
reserved exit ilk stmt_like


backslash newline --> math
# The following line must be changed to make a backslash
backslash <"\\backslash"> --> math

math (binop|unorbinop) math --> math
<"\\buildrel"> (binop|unorbinop) <"\\over{"> equals <"}"> --> binop
equals --> binop
(unop|preunop|unorbinop) math --> math
# unorbinop can only act like unary op as *prefix*, not postfix
math unop --> math
math <"\\"-space> math --> math
# concatenation

math newline --> stmt
newline --> ignore_scrap

stmt <force> stmt --> stmt

(open|lsquare) math close --> math

math lbrace --> lbrace
lbrace <force> stmt --> lbrace
lbrace <outdent-force> close --> stmt

if <"\\"-space> math --> ifmath
ifmath lbrace --> ifbrace
ifmath newline --> ifline
ifbrace <force> stmt --> ifbrace
ifbrace <outdent-force> close else <"\\"-space> if --> if
ifbrace <outdent-force> close else lbrace --> ifbrace
ifbrace <outdent-force> close else newline --> ifline
ifbrace <outdent-force> close --> stmt
(ifline|ifmath) <indent-force> stmt <outdent-force> else <"\\"-space> if --> if
(ifline|ifmath) <indent-force> stmt <outdent-force> else lbrace --> ifbrace
(ifline|ifmath) <indent-force> stmt <outdent-force> else newline --> ifline
(ifline|ifmath) <indent-force> stmt <outdent-force> else --> ifmath
(ifline|ifmath) <indent-force> stmt <outdent> --> stmt

for <"\\"-space> math --> formath
formath lbrace --> forbrace
formath newline --> forline
forbrace <force> stmt --> forbrace
forbrace <outdent-force> close --> stmt
(forline|formath) <indent-force> stmt <outdent> --> stmt


? ignore_scrap --> #1
\end{verbatim}
\endgroup


\newpage
\section{Bibliography}
\begin{thebibliography}{Knuth~999}
\bibitem[Bentley~87]{bentley:pearls}
Jon L. Bentley, ``Programming Pearls,'' {\sl Communications of the
ACM}~{\bf 29:5}(May 1986), 364--?, and {\bf 29:6}(June 1986),
471--483.
文書化プログラミングについての2つのコラム。
最初のものは入門編。二番目のは
Donald Knuth による拡張された例で
Douglas MacIlroy がコメントしている。
\bibitem[Knuth~83]{knuth:web}
Donald~E. Knuth,
``The {{\tt WEB}} system of structured documentation''
 Technical Report 980, Stanford Computer Science, Stanford,
  California, September 1983.
オリジナルの {\tt WEB}のマニュアル。
\bibitem[Knuth~84]{knuth:literate-programming}
Donald E. Knuth, ``Literate Programming,'' {\sl The Computer Journal}
{\bf 27:2}(1984), 97--111.
{\WEB}による文書化プログラミングのオリジナルの入門書。
\bibitem[Levy~87]{levy:cweb}
Silvio Levy, ``Web Adapted to C, Another Approach'' {\sl TUGBoat}
{\bf 8:2}(1987), 12--13.
{\WEB}を C で実現することについての小報告書。
これから Spidery {\WEB} は派生した。
\bibitem[Sewell~89]{sewell:weaving}
Wayne Sewell, ``Weaving a program: Literate programming in {\tt
WEB},''
Van Nostrand Reinhold, 1989.
\end{thebibliography}


\end{document}