File: prod.web

package info (click to toggle)
fweb 1.62-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,656 kB
  • ctags: 5,149
  • sloc: ansic: 41,947; makefile: 383; sh: 166
file content (6175 lines) | stat: -rw-r--r-- 124,659 bytes parent folder | download | duplicates (9)
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
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
@z --- prod.web ---

FWEB version 1.62 (September 25, 1998)

Based on version 0.5 of S. Levy's CWEB [copyright (C) 1987 Princeton University]

@x-----------------------------------------------------------------------------

\Title{PROD.WEB} % Productions for the FWEAVE processor.

@c

@* INTRODUCTION.
In order to accomodate memory-starved personal computers, the productions
have been split off from the main part of \FWEAVE.

@d _PROD_h

@A 
@<Possibly split into parts@>@;

@<Include files@>@;
@<Typedef declarations@>@;
@<Prototypes@>@;
@<Global variables@>@;

/* For PC's, the file is split into two compilable parts using the
compiler-line macro |part|, which must equal either~1 or~2. */
#if(part != 2)
	@<Part 1@>@;
#endif /* Part 1 */

#if(part != 1)
	@<Part 2@>@;
#endif /* Part 2 */

@I typedefs.hweb

@
@<Include...@>=
#include "map.h"

@ The function prototypes must appear before the global variables.
@<Proto...@>=

#include "p_type.h"

@I xrefs.hweb
@I tokens.hweb

@* PARSING.  The most intricate part of \.{WEAVE} is its mechanism for
converting \cee-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 \cee-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 \cee\ 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 $$\hbox{|expr| |binop| |expr| $\RA$
|expr|}$$ and it means that three consecutive scraps whose respective
categories are |expr|, |binop|, and |expr| are con\-verted to one scraps
whose category is |expr|.  The scraps are simply concatenated.  The case of
$$\hbox{|expr| |comma| |expr| $\RA$ |expr|}$$ is only slightly more
complicated: here the resulting |expr| scrap consists not only of the three
original scraps, but also of the tokens~|opt| and~9 between the |comma| and
the following |expr|.  In the \TeX\ file, this will specify an additional
thin space after the comma, followed by an optional line break with penalty~90.

At each opportunity the longest possible production is applied: for
example, if the current sequence of scraps is |struct_like| |expr| |lbrace|
this is transformed into a |struct_hd| by rule~31, but if the sequence is
|struct_like| |expr| followed by anything other than |lbrace| only two
scraps are used (by rule~32) to form an |int_like|.

@I ccodes.hweb

@ For debugging, we need to append a newline to the output of certain
routines so the output gets flushed.

@d DFLUSH if(dflush) puts("");

@<Glob...@>=

IN_PROD boolean dflush PSET(NO); // Turn this on from debugger.

@ The following function symbolically prints out a category. (In using the
|OUT1| macro, we take advantage of the fact that the \.{\#}~operator does
not put a second set of quotes around a string. By enclosing the |name|
arguments in quotes, we keep \FWEAVE\ from getting confused about the part
of speech under discussion; it's not used to seeing a reserved word in the
location of an argument.)

@m OUT(cs) case cs: printf(#*cs); @~ break@;
@m OUT1(cs,name) case cs: printf(#*name); @~ break@;

@<Part 1@>=
#ifdef DEBUG

@[SRTN 
prn_cat FCN((c))
	eight_bits c C1("Category.")@;
{
  switch(c) 
	{
	OUT1(language_scrap,"@@L");
	OUT(expr);
	OUT1(exp_op,"^^");
	OUT1(_EXPR,$_EXPR); @~ OUT1(EXPR_,$EXPR_); @~ OUT1(_EXPR_,$_EXPR_);
	OUT(new_like);
	OUT(stmt);
	OUT(decl);
	OUT(decl_hd);
	OUT1(Decl_hd,$Decl_hd);
	OUT(struct_hd);
	OUT(functn);
	OUT(fn_decl);
	OUT(fcn_hd);
	OUT1(else_like,"else");
	OUT1(ELSE_like,ELSE);
	OUT(if_hd);
	OUT(IF_top);
	OUT(else_hd);
	OUT(for_hd);
	OUT(unop);
	OUT1(UNOP,$UNOP_ @e);
	OUT(binop);
	OUT1(BINOP,@e $_BINOP_ @e);
	OUT(unorbinop);
	OUT1(semi,";");
	OUT1(colon,":");
	OUT1(comma,`,`);
	OUT1(COMMA,@e $_COMMA_ @e);
	OUT1(question,"?");
	OUT(tag);
	OUT(cast);
	OUT1(lpar,"(");
	OUT1(rpar,")");
	OUT1(lbracket,"[");
	OUT1(rbracket,"]");
	OUT1(lbrace,"{");
	OUT1(rbrace,"}");
	OUT(common_hd);
	OUT(read_hd);
	OUT1(slash_like,"slash");
	OUT1(private_like, "private");
	OUT(slashes);
	OUT1(lproc,"#{");
	OUT(LPROC);
	OUT1(rproc,"#}");
	OUT1(ignore_scrap,"ignore");

	OUT1(define_like,define);
	OUT(no_order);
	OUT1(do_like,"do");
	OUT1(while_do, "while");
	OUT1(Rdo_like,Rdo);
	OUT1(if_like,"if");
	OUT1(IF_like,IF);
	OUT1(for_like,"for");
	OUT1(program_like,program);
	OUT1(int_like,int);
	OUT(modifier);
	OUT1(huge_like,"huge");
	OUT1(CASE_like,CASE);
	OUT1(case_like,"case");
	OUT1(sizeof_like,sizeof @e);
	OUT1(op_like,"op");
	OUT1(proc_like,"proc");
	OUT1(class_like,"class");
	OUT1(struct_like,"struct");
	OUT1(typedef_like,"typedef");
	OUT1(imp_reserved,"imp_rsrvd");
	OUT1(extern_like,"extern");
	OUT1(common_like,common);
	OUT1(read_like,read);
	OUT1(entry_like,entry);
	OUT1(implicit_like,implicit);
	OUT(implicit_hd);
	OUT(built_in);
	OUT1(endif_like,endif);
	OUT1(end_like,end);
	OUT1(END_like,END);
	OUT(END_stmt);
	OUT1(go_like,go);
	OUT1(newline,"\n");
	OUT(label);
	OUT(space);
	OUT1(until_like,until);
	OUT(template);
	OUT(langle);
	OUT(rangle);
	OUT(tstart);
	OUT(tlist);
	OUT(namespace);
	OUT(virtual);
	OUT1(reference,ref);
	OUT1(kill_newlines, killnl);

	OUT1(0,zero);
	default: printf("UNKNOWN(%i)", c); @~ break;
	}

DFLUSH;
}

#endif /* |DEBUG| */

@I output.hweb

@ Here is a table of all the productions. The reader can best get a feel for
@^productions, table of@>
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}' or by using the
command-line option ``\.{-2}''.  [Please see file
\.{examples/prod.web}.]

@i scraps.hweb

@ This dummy module keeps \FTANGLE\ from complaining. (It's needed only by
\FWEAVE.)


@<Rest of |trans_plus| union@>=

@ The following functions prints a token list. It is intended to be called
from the debugger.

@<Part 1@>=
#ifdef DEBUG

SRTN 
prn_text FCN((p))
	text_pointer p C1("The token list.")@;
{
  token_pointer j; /* index into |tok_mem| */
  sixteen_bits r; /* remainder of token after the flag has been stripped off */

  if (p>=text_ptr) 
	printf("BAD");
  else for (j=*p; j<*(p+1); j++) 
	{
	    r = (sixteen_bits)(*j % id_flag);

	    switch (*j/id_flag) 
		{
      case 1: printf("\\\\{"); prn_id((name_dir+r)); printf("}"); break;
	/* |id_flag| */
      case 2: printf("\\&{"); prn_id((name_dir+r)); printf("}"); break;
	/* |res_flag| */
      case 3: printf("<"); prn_id((name_dir+r)); printf(">"); break;
        /* |mod_flag| */
      case 4: printf("[[%d]]",r); break; /* |tok_flag| */
      case 5: printf("|[[%d]]|",r); break; /* |inner_tok_flag| */
      default: @<Print token |r| in symbolic form@>;
		}
	  }

DFLUSH;
}

SRTN
prn_trans FCN((p))
	scrap_pointer p C1("")@;
{
prn_text(indirect(p->trans));
}

#endif /* |DEBUG| */

@ 
@<Print token |r|...@>=

switch (r) 
	{
  case math_bin: printf("\\mathbin}"); @~ break;
  case math_rel: printf("\\mathrel}"); @~ break;
  case big_cancel: printf("[ccancel]"); @~ break;
  case cancel: printf("[cancel]"); @~ break;
  case indent: printf("[indent]"); @~ break;
  case outdent: printf("[outdent]"); @~ break;
  case backup: printf("[backup]"); @~ break;
  case opt: printf("[opt]"); @~ break;
  case break_space: printf("[break]"); @~ break;
  case force: printf("[force]"); @~ break;
  case big_force: printf("[fforce]"); @~ break;
  case end_translation: printf("[quit]"); @~ break;
  default: putxchar(XCHR(r));
	}

@ 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 `|expr@,comma@,expr| $\RA$ |expr|' would be represented by
`|(pp,3,expr,-2)|'; in this case the pointer |pp| should decrease by~2
after the production has been applied, because some productions with |expr|
in their second or third positions might now match, but no productions have
|expr| in the 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.  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 the
language 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,3,expr,-2,4)|' 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, |b_app2(pp)| will append the translations of
two consecutive scraps, |pp->trans| and |(pp+1)->trans|, 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,3,expr,-2,3)|' is an abbreviation for `|b_app3(pp);
REDUCE(pp,3,math,-2,3)|'.

The code below is an exact translation of the production rules into~C
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.

To understand the routines that append tokens or scraps in detail, we must
discuss the concept of \It{mathness}. This is used to determine how to
enclose things in dollar signs---i.e., what things should be treated in
math mode. 

Routines such as |app| or |app_str| append stuff to the list without
changing the mathness.

Routines such as |b_app| or |b_app1| (the 'b' stands for 'big')
provisionally change the mathness depending on what's come before and
what's being appended.

Three flags handle the mathness. |cur_mathness| is the mathness at this
point in the construction. |ini_mathness| is the initial mathness of the
stuff that's been appended so far. |last_mathness| is the mathness of the
last stuff that's been appended. (|cur_mathness| and |last_mathness| appear
to be redundant, but we're not changing the code right now.)

The next macros \It{big\_appn} append $n$~consective tokens.

@D b_app2(a) b_app1(a); @~ b_app1(a+1)
@D b_app3(a) b_app2(a); @~ b_app1(a+2)
@D b_app4(a) b_app3(a); @~ b_app1(a+3)

@<Global...@>=

IN_PROD int cur_mathness, ini_mathness, last_mathness;

@ Append an entire string, converting to |ASCII| if necessary. (Don't
change the mathness.)

@<Part 1@>=@[

SRTN 
app_str FCN((s))
	CONST outer_char HUGE *s C1("String to be appended.")@;
{ 
while (*s) 
	app(XORD(*(s++)));
}

/* Append a string that's already Ascii. */
SRTN 
app_ASCII_str FCN((s))
	CONST ASCII HUGE *s C1("")@;
{
while(*s) 
	app(*s++);
}

@ Append a token, possibly changing the mathness.

@<Part 1@>=@[

SRTN 
b_app FCN((a))
	Token a C1("Token to be appended.")@;
{
if (a==@' ' || (a>=big_cancel && a<=big_force))
	{/* Appending a non-math token, including a space. */
	if (cur_mathness ==maybe_math) 
		ini_mathness=no_math;
	else if (cur_mathness==yes_math) 
		{
#ifdef DBGM
		app(@'4');
#endif	
		app(@'$'); // End math mode.
		}

	cur_mathness=last_mathness=no_math;
	}
else 
	{ /* Append a math token. (Tokens can't be |maybe_math|.) */
	if (cur_mathness==maybe_math) 
		ini_mathness=yes_math;
	else if (cur_mathness==no_math) 
		{
		app(@'$'); // Begin math mode.
#ifdef DBGM
		app(@'3');
#endif
		}

	cur_mathness=last_mathness=yes_math;
}

app(a);
}

@ Append an entire scrap, possibly changing the mathness. The mathness for
scraps is stored in an |eight_bits| in the form |4*last_mathness +
ini_mathness|. 

@d INI_MATHNESS(p) ((p)->mathness % 4) 
	/* Left boundary (|ini_mathness|) of the current scrap. */
@d LAST_MATHNESS(p) ((p)->mathness / 4)
		/* Right boundary (|last_mathness|) */

@<Part 1@>=@[

SRTN 
b_app1 FCN((a))
	scrap_pointer a C1("Scrap to be appended.")@;
{
switch(INI_MATHNESS(a))
	{ 
  case no_math:
	    if (cur_mathness==maybe_math) 
		ini_mathness = no_math;
	    else if (cur_mathness==yes_math) 
		{
#ifdef DBGM
		app(@'2');
#endif
		APP_STR("$"); /* End math mode. (The braces take care of
ending the math part with something like a~$+$.) */
		}
	
	    cur_mathness = last_mathness = LAST_MATHNESS(a);
	    break;

  case yes_math:
	    if (cur_mathness==maybe_math) 
		ini_mathness=yes_math;
	    else if (cur_mathness==no_math) 
		{
		APP_STR("$"); /* Begin math mode.  (The braces take care
of beginning the math part with something like a~$+$.) */
#ifdef DBGM
		app(@'1');
#endif
		}

	    cur_mathness = last_mathness = LAST_MATHNESS(a);
	    break;

  case maybe_math: 
	break; // No changes in mathness.
	  }

app(a->trans + tok_flag - tok_start);
}

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

\Ratfor\ and \Fortran\ are treated as two dialects of the same language,
because almost all of the rules are the same. The most important exception
is in the \&{if} statements.

The first thing we do is to process any language scrap.  Such scraps begin
with |begin_language|, then the language number as the next token.  We use
that token to reset the language.

If it's not a language scrap, we gobble up any |ignore_scrap|. For reasons
that are now obscure, we regress by $-2$ after that. This doesn't work
quite right; the logic of some of the |if| statements gets screwed up if
there's a comment in the wrong place.

@<Match a production at |pp|, or increase |pp| if there is no match@>= 
{
if(cat0 == language_scrap)
	{
	language = lan_enum(get_language(pp->trans)); /* Get language from
language~\#. */
	ini0_language(); // Reset params like |auto_semi|.
	SQUASH(pp,1,ignore_scrap,-1,0);
	}
else if(cat1==ignore_scrap) SQUASH(pp,2,cat0,-2,0);//Gobble an |ignore_scrap|.
@% else if(cat0==ignore_scrap) SQUASH(pp,2,cat1,0,0); // Screws language cmd.
else switch(language)
		{
   	   case NO_LANGUAGE:
		CONFUSION("match production",
			"Language hasn't been defined yet");

	   case C: 
	   case C_PLUS_PLUS:
		C_productions();
		break;

	   case RATFOR:
	   case RATFOR_90:
		if(!RAT_OK("(translate)"))
			CONFUSION("match production",
				"Language shouldn't be Ratfor here");

	   case FORTRAN:
	   case FORTRAN_90:		
		R_productions();
		break;

	   case LITERAL:
		V_productions();
		break;

	   case TEX:
		X_productions();
		break;

	   case NUWEB_OFF:
	   case NUWEB_ON:
		CONFUSION("match a production","Invalid language");
		}

pp++; // if no match was found, we move to the right and try again.
}

@ 
@<Part 1@>=@[
int 
get_language FCN((xp))
	text_pointer xp C1("")@;
{
token_pointer tp,tp1;

tp = *xp;
tp1 = *(xp+1) - 1; /* The |-1| is because we should always have the
	combination |begin_language| followed by the language number. */

while(tp < tp1)
	if(*tp++ == begin_language) return *tp;

return CONFUSION("get_language",
	"Can't find |begin_language| token in language_scrap");
}

@* PRODUCTIONS for C. The productions have been made into individual
functions to accomodate memory-starved pc's.

@<Part 1@>=@[

SRTN 
C_productions(VOID)
{
switch (pp->cat) 
    {
    case ignore_scrap:  @<CASES for |ignore_scrap| (C)@>@; break;
    case built_in: @<CASES for |built_in| (R)@>@; @~ break;
    case expr: @<CASES for |expr| (C)@>@; @~ break;
    case exp_op: @<CASES for |exp_op| (R)@>@; @~ break;
    case _EXPR: @<CASES for |_EXPR| (C)@>@; @~ break;
    case _EXPR_: @<CASES for |_EXPR_| (C)@>@; @~ break;
    case EXPR_: @<CASES for |EXPR_| (C)@>@; @~ break;
    case new_like: @<CASES for |new_like| (C)@>@; @~ break;
    case lpar: @<CASES for |lpar| (C)@>@; @~ break;
    case lbracket: @<CASES for |lbracket| (C)@>@; @~ break;
    case rbracket: @<CASES for |rbracket| (C)@>@; @~ break;
    case question: @<CASES for |question| (C)@>@; @~ break;
    case unop: @<CASES for |unop| (C)@>@; @~ break;
    case UNOP: @<CASES for |UNOP| (C)@>@; @~ break;
    case unorbinop: @<CASES for |unorbinop| (C)@>@; @~ break;
    case binop: @<CASES for |binop| (C)@>@; @~ break;
    case BINOP: @<CASES for |BINOP| (C)@>@; @~ break;
    case COMMA: @<CASES for |COMMA| (C)@>@; @~ break;
    case cast: @<CASES for |cast| (C)@>@; @~ break;
    case sizeof_like: @<CASES for |sizeof_like| (C)@>@; @~ break;
    case int_like: @<CASES for |int_like| (C)@>@; @~ break;
    case extern_like: @<CASES for |extern_like| (C)@>@; @~ break;
    case modifier: @<CASES for |modifier| (C)@>@; @~ break;
    case huge_like: @<CASES for |huge_like| (C)@>@; @~ break;
    case decl_hd: @<CASES for |decl_hd| (C)@>@; @~ break;
    case decl: @<CASES for |decl| (C)@>@; @~ break;
    case typedef_like: @<CASES for |typedef_like| (C)@>@; @~ break;
    case imp_reserved: @<CASES for |imp_reserved| (C)@>@; @~ break;
    case op_like: @<CASES for |op_like| (C)@>@; @~ break;
    case class_like: @<CASES for |class_like| (C)@>@; @~ break;
    case struct_like: @<CASES for |struct_like| (C)@>@; @~ break;
    case struct_hd: @<CASES for |struct_hd| (C)@>@; @~ break;
    case fn_decl: @<CASES for |fn_decl| (C)@>@; @~ break;
    case functn: @<CASES for |functn| (C)@>@; @~ break;
    case lbrace: @<CASES for |lbrace| (C)@>@; @~ break;
    case do_like: @<CASES for |do_like| (C)@>@; @~ break;
    case while_do: @<CASES for |while_do| (C)@>@; @~ break;
    case if_like: @<CASES for |if_like| (C)@>@; @~ break;
    case IF_like: @<CASES for |IF_like| (C)@>@; @~ break;
    case IF_top: @<CASES for |IF_top| (C)@>@; @~ break;
    case for_like: @<CASES for |for_like| (C)@>@; @~ break;
    case for_hd: @<CASES for |for_hd| (C)@>@; @~ break;
    case else_like: @<CASES for |else_like| (C)@>@; @~ break;
@#if(0)
    case ELSE_like: @<CASES for |ELSE_like| (C)@>@; @~ break;
@#endif
    case if_hd: @<CASES for |if_hd| (C)@>@; @~ break;
    case else_hd: @<CASES for |else_hd| (C)@>@; @~ break;
    case case_like: @<CASES for |case_like| (C)@>@; @~ break;
    case stmt: @<CASES for |stmt| (C)@>@; @~ break;
    case tag: @<CASES for |tag| (C)@>@; @~ break;
    case semi: @<CASES for |semi| (C)@>@; @~ break;
    case lproc: @<CASES for |lproc| (C)@>@; @~ break;
    case LPROC: @<CASES for |LPROC| (C)@>@; @~ break;
    case space: @<CASES for |space| (C)@>@; @~ break;

    case template: @<CASES for |template| (C++)@>@; @~ break;
    case langle: @<CASES for |langle| (C++)@>@; @~ break;
    case rangle: @<CASES for |rangle| (C++)@>@; @~ break;
    case tstart: @<CASES for |tstart| (C++)@>@; @~ break;
    case tlist: @<CASES for |tlist| (C++)@>@; @~ break;

    case virtual: @<CASES for |virtual| (C++)@>@; @~ break;
    case reference: @<CASES for |reference| (C++)@>@; @~ break;
    case namespace: @<CASES for |namespace| (C++)@>@; @~ break;

    case kill_newlines:  @<CASES for |kill_newlines| (C++)@>@; @~ break;
  }
}

@ In~C, new specifier names can be defined via |typedef|, and we want
to make the parser recognize future ocurrences of the identifier thus
defined as specifiers.  This is done by the procedure |make_reserved|,
which changes the |ilk| of the relevant identifier. (One difficulty with
this solution is that it is implemented in phase~2, so if one uses an
identifier before it is actually |typedef|'d, it won't typeset properly. In
these cases, an explicit~\.{@@f} is required as well.)

The original \CWEB\ design of |make_reserved| didn't handle a situation such as
|typedef int (*I)()|, because |I|~was inside parentheses. The procedure has
been augmented to handle this situation by following the indirection chain
to the bitter end.

@<Part 1@>=@[

SRTN 
make_reserved FCN((p)) /* Make the first identifier in |p->trans| like
				|int| */ 
	scrap_pointer p C1("")@;
{
sixteen_bits tok_value = first_id(p->trans); 
	// The first identifier, plus its flag.
name_pointer pname = name_dir + tok_value - id_flag;

if(!tok_value || tok_value==@'(') 
	return; // Emergency return; no	identifier found.

if(DEFINED_TYPE(pname) == M_MACRO || DEFINED_TYPE(pname) == D_MACRO)
	return; // Don't |typedef| macro names.

/* Change categories of all future occurrences of the identifier. */
  for (; p<=scrp_ptr; p++) 
	{
	    if (p->cat==expr) 
		{
	        if (**(p->trans)==tok_value) 
			{
			p->cat=int_like;
			**(p->trans)+=res_flag-id_flag; // Mark as reserved.
		        }
		}
	  }

pname->ilk = int_like;
pname->reserved_word |= (boolean)language;

if(mark_defined.typedef_name)
	{
	pname->defined_in(language) = module_count;
	SET_TYPE(pname,TYPEDEF_NAME);
	}
}

@ This function hunts through a translation until it finds the first
identifier, if there is one.

@d FIRST_ID(p) ( ((tok0=first_id(p->trans)) && tok0!=@'(') ? name_dir + tok0 -
		id_flag : name_dir) 	 // Ptr to actual id.

@<Glob...@>=

IN_PROD sixteen_bits tok0;

@ This function considers a token list between~|pk| and~|pk1|; it returns
the first (flagged) identifier token it finds, or 0~if there's none.
Because each component of the token list may itself be a token list, this
routine is called recursively.

@<Part 1@>=@[

sixteen_bits 
first_id FCN((t))
	text_pointer t C1("Pointer to start of token list")@;
{
token_pointer pk = *t; // Start of end.
token_pointer pk1 = *(t+1); // End of list.
sixteen_bits tok_value; // Current element.

for(; pk < pk1; pk++)
	{
	tok_value = *pk;

	if(tok_value > inner_tok_flag) tok_value -= (inner_tok_flag -
tok_flag); 

	if(tok_value <= tok_flag)
		{ // It's an ordinary (non-flagged) token.
		if( tok_value >= id_flag && tok_value < res_flag)
			return tok_value; // Found identifier.
		else if(tok_value == @'(') return tok_value; // STOP!!!
		}
	else
		{ // Flagged token; use indirection.
	 	t = tok_start + (int)(tok_value - tok_flag); /* Flagged token
corresponds to a |text_pointer|; |*t|~points to beginning of translation. */
		tok_value = first_id(t);// Check that translation recursively. 
		if(tok_value) return tok_value;
		}
	}

return 0; // Really couldn't find anything!
}

@ In the following situations we want to mark the occurrence of an
identifier as a definition: when |make_reserved| has just been used; after
a specifier, as in |char **argv|; before a colon, as in |found:|; and in
the declaration of a function, as in |main(){@t\dots@>;}|.  This is
accomplished by the invocation of |make_underlined| at appropriate times.
Since, in the declaration of a function, we only find out that the
identifier is being defined after it has been swallowed up by an |expr|, we
must hunt through an indirection chain.

@<Part 1@>=@[

name_pointer 
make_underlined FCN((p)) /* underline the entry for the first
				identifier in |p->trans| */ 
	scrap_pointer p C1("")@;
{
  sixteen_bits tok_value; /* the name of this identifier, plus its flag */

  tok_value=**(p->trans);

  if (tok_value>inner_tok_flag) tok_value-=(inner_tok_flag-tok_flag);

  if (tok_value>tok_flag) {
	do 
		{ /* Follow an indirection chain to a real identifier. {\bf
Watch the 16-bit arithmetic!} */
		tok_value=**(tok_start +
				(int)(tok_value-tok_flag));  /* {\bf Don't
remove the parens!} */
		}
	while(tok_value > tok_flag);

    if (tok_value<id_flag || tok_value>=res_flag) return NULL; /* shouldn't
happen */ 

    xref_switch=def_flag; underline_xref(tok_value-id_flag+name_dir);
  }

  if (tok_value<id_flag || tok_value>=res_flag) return NULL; 
	// shouldn't happen!

  xref_switch=def_flag; return underline_xref(tok_value-id_flag+name_dir);
}

@ We cannot use |new_xref| to underline a cross-reference at this point
because this would just make a new cross-reference at the end of the list.
We actually have to search through the list for the existing
cross-reference.

@<Part 1@>=@[

name_pointer 
underline_xref FCN((p))
	name_pointer p C1("")@;
{
  xref_pointer q = (xref_pointer)p->xref; /* Pointer to cross-reference
being examined */ 
  xref_pointer r; /* Temporary pointer for permuting cross-references */
  sixteen_bits m; /* Cross-reference value to be installed */
  sixteen_bits n; /* Cross-reference value being examined */
extern boolean strt_off;

  if (no_xref || (strt_off && !index_hidden)) 
	return p;

  xref_switch = def_flag;
  m = (sixteen_bits)(module_count + xref_switch);

  while (q != xmem) 
	{
	    n=q->num;

	    if (n==m) return p;	/* Same status; need to do nothing. */
	    else if (m==n+def_flag) /* Module numbers match; update to
				defined. */ 
		{
		q->num=m; return p;
		 }
	    else if (n>=def_flag && n<m) break;

	    q=q->xlink;
	  }

@<Insert new cross-reference at |q|, not at beginning of list@>;

return p;
}

@ Record the module at which an identifier was defined. A global variable
distinguishes between |INNER| and |OUTER| modes.

@<Glob...@>=

IN_PROD PARSING_MODE translate_mode; // Set by |translate|.

@
@<Part 1@>=@[

SRTN 
defined_at FCN((p))
	name_pointer p C1("")@;
{
extern boolean ok_to_define;

if(ok_to_define && translate_mode==OUTER && p > name_dir) 
	{
	sixteen_bits mod_defined = p->defined_in(language);

	if(mod_defined && mod_defined != module_count && language!=C_PLUS_PLUS)
		{
		if(msg_level >= WARNINGS)
		 {
		printf("\n! (FWEAVE):  Implicit phase 2 declaration of `");
		prn_id(p);
		printf("' at %s \
repeats or conflicts with declaration at %s.\n",
			(char *)MOD_TRANS(module_count), 
			(char *)MOD_TRANS(mod_defined));
		mfree();
		 }
		mark_harmless;
		}
	else if(mark_defined.fcn_name)
		{
		p->defined_in(language) = module_count;
		SET_TYPE(p,FUNCTION_NAME);
		}
	}
}

@ We get to this module only when the identifier is one letter long, so it
didn't get a non-underlined entry during phase one.  But it may have got
some explicitly underlined entries in later modules, so in order to
preserve the numerical order of the entries in the index, we have to insert
the new cross-reference not at the beginning of the list (namely, at
|p->xref|), but rather right before~|q|.

@<Insert new cross-reference at |q|...@>=

  append_xref(0); /* This number doesn't matter */
  xref_ptr->xlink = (xref_pointer)p->xref;
 r = xref_ptr; p->xref = (ASCII *)xref_ptr;

  while (r->xlink!=q) {r->num=r->xlink->num; r=r->xlink;}

  r->num=m; /* Everything from |q| on is left undisturbed */

@ 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| procedures will cause the appropriate action to be performed,
followed by |goto found|.

@D cat0 pp->cat
@D cat1 (pp+1)->cat
@D cat2 (pp+2)->cat
@D cat3 (pp+3)->cat
@D cat4 (pp+4)->cat
@D cat5 (pp+5)->cat

@d indent_force b_app(indent); @~ b_app(force)@;

/* Append $m$~things, followed by a space, followed by $n$~things. */
@m PP_PP(m,n) b_app##m(pp); @~ b_app(@' '); @~ b_app##n(pp+m)@;

@<CASES for |ignore_scrap| (C)@>=

#if FCN_CALLS
	C_ignore_scrap();
#else
	@<Cases for |ignore_scrap| (C)@>@;
#endif

@
@<Part 1@>=

#if FCN_CALLS
	@[SRTN C_ignore_scrap(VOID)
		{
		@<Cases for |ignore_scrap| (C)@>@;
		}
#endif

@
@<Cases for |ignore_scrap| (C)@>=
{
switch(cat1)
	{
   case stmt:
   case functn:
	SQUASH(pp,2,cat1,0,1);
	break;
	}
}

@ Ordinary expressions.
@<CASES for |expr| (C)@>=
#if FCN_CALLS
	C_expr();
#else
	@<Cases for |expr| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_expr(VOID)
		{
		@<Cases for |expr| (C)@>@;
		}
#endif

@

@d OPT9	APP_SPACE; app(opt); app(@'9')@;

@<Cases for |expr| (C)@>=
{
if (cat1==lbrace || ((!Cpp) && cat1==int_like))
	{ /* ``|f(x) {}|'' or ``|f(x) float x;|'' (old-style) */
	defined_at(make_underlined(pp)); /* Recognized function name;
remember current module number. */
	in_function = YES;
	SQUASH(pp, 1, fn_decl, 0, 111); 
	}
else if (cat1==unop) 
	SQUASH(pp,2,expr,-2,2); /* ``|x--|'' */
else if (cat1==binop)
	{
	if(cat2==expr) 
		SQUASH(pp,3,expr,-2,3); /* ``|x + y|'' */
	else if(cat2==decl_hd)
		SQUASH(pp, 3, tstart, 0, 6061); 
			/* Trap for ``|@c++ A<int>|'', with |A| undefined. */
	}
else if (cat1==unorbinop && cat2==expr)
	{
	sixteen_bits *s = *(pp+1)->trans;
	b_app1(pp);

/* If the translation of the next scrap begins with an escape character, we
assume we're seeing \.{\\amp}. */
	if( (s[0] == (sixteen_bits)@'\\') && s[1] == (sixteen_bits)@'a'
			&& s[2] == (sixteen_bits)@'m')
		{
		APP_SPACE; b_app1(pp+1); @~ APP_SPACE; /* ``|x & y|'' */
		}
	else b_app1(pp+1); /* ``|x*y|'' */

	b_app1(pp+2);
	REDUCE(pp,3,expr,-2,3000);
	}
else if (cat1==comma)
	{
	if((cat2==expr || cat2==int_like)) /* ``|x,y|'' or ``|x,char|''  */
		{
		b_app2(pp);
		OPT9;
		b_app1(pp+2); REDUCE(pp,3,cat2,-2,4);
		}
	else if(cat2==space)
		SQUASH(pp, 3, expr, -2, 88); // Macros.
	}
else if (cat1==expr) 
	SQUASH(pp,2,expr,-2,5); /* ``|f(x)|'' */
else if (cat1==semi) 
	SQUASH(pp,2,stmt,-1,6); /* ``|x;|'' */
else if (cat1==colon)  /* ``|label:|'' */
	{
	if(!Cpp || in_function)
		{ /* Ordinary C tag. */
		make_underlined (pp);  /* Label name. */
		SQUASH(pp,2,tag,0,7);
		}
	else if(cat2==expr || cat2==int_like) 
		{ /* Put the spaces in explicitly in case we're not in math
mode at the time. */
		b_app1(pp); @~ b_app(@' '); @~ b_app1(pp+1); @~ b_app(@' '); 
@~ b_app1(pp+2);		
		REDUCE(pp,3,expr,-2,701); 
			/* \Cpp: ``|@c++ derived() : base()|'' */
		}
	}
else if(cat1==space) 
	SQUASH(pp,2,expr,-2,8); /* For use in macros. */
}

@ The next several cases are for symbols that are formatted like operators.
These need to get explicit spaces to set them off from their surroundings.

@<Bracket with spaces@>=

APP_SPACE; @~ b_app1(pp); @~ APP_SPACE;

@ Name as unary operator: ``\.{\$UNOP\_\ }''.
@<CASES for |UNOP| (C)@>=
#if FCN_CALLS
	C_UNOP();
#else
	@<Cases for |UNOP| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_UNOP(VOID)
		{
		@<Cases for |UNOP| (C)@>@;
		}
#endif

@
@<Cases for |UNOP| (C)@>=
{
b_app1(pp); @~ APP_SPACE;
REDUCE(pp,1,unop,-1,4443);
}

@ Name as binary operator: ``\.{\ \$\_BINOP\_\ }''.
@<CASES for |BINOP| (C)@>=
#if FCN_CALLS
	C_BINOP();
#else
	@<Cases for |BINOP| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_BINOP(VOID)
		{
		@<Cases for |BINOP| (C)@>@;
		}
#endif

@
@<Cases for |BINOP| (C)@>=
{
@<Bracket with spaces@>;
REDUCE(pp,1,binop,-1,4444);
}

@ Name as comma: ``\.{\ \$\_COMMA\_\ }''.
@<CASES for |COMMA| (C)@>=
#if FCN_CALLS
	C_COMMA();
#else
	@<Cases for |COMMA| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_COMMA(VOID)
		{
		@<Cases for |COMMA| (C)@>@;
		}
#endif

@
@<Cases for |COMMA| (C)@>=
{
@<Bracket with spaces@>;
REDUCE(pp,1,comma,-1,4445);
}

@ Expression with space to left: ``\.{\ \$\_EXPR}''.
@<CASES for |_EXPR| (C)@>=
#if FCN_CALLS
	C__E();
#else
	@<Cases for |_EXPR| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C__E(VOID)
		{
		@<Cases for |_EXPR| (C)@>@;
		}
#endif

@
@<Cases for |_EXPR| (C)@>=
{
APP_SPACE; @~ b_app1(pp);
REDUCE(pp,1,expr,-2,4446);
}

@ Expression with spaces on both sides: ``\.{\ \$\_EXPR\_\ }''.
@<CASES for |_EXPR_| (C)@>=
#if FCN_CALLS
	C__E_();
#else
	@<Cases for |_EXPR_| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C__E_(VOID)
		{
		@<Cases for |_EXPR_| (C)@>@;
		}
#endif

@
@<Cases for |_EXPR_| (C)@>=
{
@<Bracket with spaces@>;
REDUCE(pp,1,expr,-2,4447);
}

@ Expression with space to right: ``\.{\$EXPR\_\ }''.
@<CASES for |EXPR_| (C)@>=
#if FCN_CALLS
	C_E_();
#else
	@<Cases for |EXPR_| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_E_(VOID)
		{
		@<Cases for |EXPR_| (C)@>@;
		}
#endif

@
@<Cases for |EXPR_| (C)@>=
{
b_app1(pp); @~ APP_SPACE;
REDUCE(pp,1,expr,-2,4448);
}

@ There are right and wrong ways of inserting a real space. What we want to
do is to insert the macro \.{\\\ } (which works either in or out of math mode)
without changing the mathness.

@d APP_SPACE APP_STR("\\ ")

@ The next stuff handles C~preprocessing (not very well).
@<Glob...@>=

IN_PROD boolean active_space PSET(NO);
IN_PROD boolean in_LPROC PSET(NO);
IN_PROD boolean expanded_lproc PSET(NO);

@ In \Cpp, the syntax for |new| and |delete| is unusual.
@<CASES for |new_like| (C)@>=
#if FCN_CALLS
	C_new_like();
#else
	@<Cases for |new_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_new_like(VOID)
		{
		@<Cases for |new_like| (C)@>@;
		}
#endif

@
@<Cases for |new_like| (C)@>=
{
if(cat1==lbracket && cat2==rbracket)
	{ /* |@c++ delete [] expr| */
	PP_PP(1, 1); @~@<Append thickspace@>; @~ b_app1(pp+2);
	b_app(@' ');
	REDUCE(pp, 3, expr, -2, 910);
	}
else if(cat1==decl_hd || cat1==expr)
	{ /* \Cpp: |@c++ new int| or |@c++ new class(20)| */
	PP_PP(1,1);
	if(cat1==decl_hd) 
		{
		OUTDENT;
		}
	REDUCE(pp,2,expr,-2,909);
	}
}

@ The \CWEB\ code didn't work right here. The present attempt is a mess.

@<CASES for |lproc| (C)@>=
#if FCN_CALLS
	C_lproc();
#else
	@<Cases for |lproc| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_lproc(VOID)
		{
		@<Cases for |lproc| (C)@>@;
		}
#endif

@ |lproc| signals the beginning of a preprocessor statement.  |rproc|
signals the end.

@<Glob...@>=

extern boolean did_arg;

@
@<Cases for |lproc| (C)@>=
{
expanded_lproc = YES;

if(!in_LPROC) 
	active_space = YES;

if(cat1==define_like) 
	make_underlined(pp+3); /* ``\.{\#\ define\ M}'' */

if (cat1==else_like || cat1==if_like ||cat1==define_like)
	SQUASH(pp, 2, lproc, 0, 10); /* ``\.{\#\ define}'' $\to$
``\.{\#define}'' */
else if (cat1==rproc)
	{
	expanded_lproc = active_space = in_LPROC = NO;
	SQUASH(pp, 2, ignore_scrap, -1, 11); 
	}
else if(cat1==expr) 
#if 0
	SQUASH(pp, 1, LPROC, 0, 12); /* ``|#if(0)|'' (??) */
#endif
	{
	PP_PP(1, 1);

	if(cat2==lpar)
		did_arg = NO;
	else
		{
		b_app(@' ');  /* ``|#define x|'' */
		did_arg = YES;
		}

	REDUCE(pp, 2, LPROC, 0, 12);
	}
else if (cat1==space)
	{ 
	if(cat2==lpar)
		SQUASH(pp, 1, lproc, PLUS 2, 1332); // \.{if\ (x)}
/* Following stuff for \&{\#define}.  
Absorb the identifier: ``\&{\#define M}'' */  
	else if(cat3==lpar) 
		SQUASH(pp,1,lproc,PLUS 3,1333); /* Expand the parens. */
	else if(cat3==expr) 
		SQUASH(pp,4,LPROC,0,13); /* |expr| should be
			``|()|''; get them too. */ 
	else if(cat3==space || cat3==ignore_scrap || cat3==rproc) 
		SQUASH(pp,3,LPROC,0,14); /* Just the identifier. */ 
	}
expanded_lproc = NO;
}

@ 
@<CASES for |LPROC| (C)@>=
#if FCN_CALLS
	C_LPRC();
#else
	@<Cases for |LPROC| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_LPRC(VOID)
		{
		@<Cases for |LPROC| (C)@>@;
		}
#endif

@
@<Cases for |LPROC| (C)@>=
{
active_space = NO; in_LPROC = YES;

if(cat1==space) 
	{
	b_app1(pp);
	b_app(@' ');
	REDUCE(pp, 2, LPROC, 0, 20);
	}
else if(!did_arg && cat1==expr)
	{
	SQUASH(pp, 2, LPROC, 0, 24);
	did_arg = YES;
	}
else if(cat1==rproc) 
	{
	in_LPROC = NO;
	SQUASH(pp, 2, ignore_scrap, -1, 21);
	}
else if(cat2==rproc)
	{
	in_LPROC = NO;
	SQUASH(pp, 3, ignore_scrap, -1, 22);
	}

#if(0)
	if(cat3==lpar && cat4==expr && cat5==rpar)
	  if (cat2==rproc) 
		{
		    b_app1(pp); b_app(@' '); b_app2(pp+1);
		    REDUCE(pp,3,ignore_scrap,-1,53);
		  }
	  else if (cat2==expr && cat3==rproc) 
		{ 
	    b_app1(pp); b_app(@' '); b_app1(pp+1); b_app(@' ');
	    b_app2(pp+2); REDUCE(pp,4,ignore_scrap,-1,53);
		}
#endif
}

@
@<CASES for |space| (C)@>=
#if FCN_CALLS
	C_space();
#else
	@<Cases for |space| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_space(VOID)
		{
		@<Cases for |space| (C)@>@;
		}
#endif

@
@<Cases for |space| (C)@>=
{
if(active_space)
	{
	if(expanded_lproc) 
		SQUASH(pp,1,space,-1,5336);
	else 
		SQUASH(pp,1,space,1,5335);
	}
else 
	REDUCE(pp,1,ignore_scrap,-1,5334);
}

@ 
@<CASES for |question| (C)@>=
#if FCN_CALLS
	C_question();
#else
	@<Cases for |question| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_question(VOID)
		{
		@<Cases for |question| (C)@>@;
		}
#endif

@
@<Cases for |question| (C)@>=
{
if (cat1==expr && cat2==colon) SQUASH(pp,3,binop,-2,30); /* ``|i==1 ? YES :
					NO|'' */
}

@ 
@<CASES for |int_like| (C)@>=
#if FCN_CALLS
	C_int_like();
#else
	@<Cases for |int_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_int_like(VOID)
		{
		@<Cases for |int_like| (C)@>@;
		}
#endif

@
@<Cases for |int_like| (C)@>=
{
if(cat1==unop)
	{
	if(cat2==expr || cat2==int_like) 
		SQUASH(pp,3,expr,-2,35); /* \Cpp: |@c++ class::f| or
			constructor: |@c++ class::class| */ 
	else if(cat2==op_like) 
		SQUASH(pp,1,int_like,PLUS 2,36); /* \Cpp: Expand |@c++ operator|
			construction. */ 
	}
else if (cat1==int_like|| cat1==struct_like)
	{ /* ``|extern int|'' or ``|@c++ typedef int bool|''. */
	PP_PP(1,1);
	REDUCE(pp,2,cat1,0,40);
	}	
else if(cat1==reference)
	SQUASH(pp, 2, int_like, -2, 43); // |@c++ int &ref;|
else if (cat1==expr || cat1==unorbinop || cat1==semi)
	{ /* ``|int i|'' or ``|int *|'' */ 
	b_app1(pp); 

	if(cat1!=semi) 
		app(@'~'); 

#if 0
	INDENT; /* Start long declaration. (Note: Whenever we leave
			|decl_hd|, we must |OUTDENT|.) */ 
#endif

	REDUCE(pp,1,decl_hd,-1,41);
	}
else if(cat1==comma) 
	{
	b_app1(pp);
#if 0
	INDENT;
#endif
	REDUCE(pp,1,decl_hd,-2,42); /* Function prototype: |int,|. */ 
	}
else if(cat1==rpar)
	{
	b_app1(pp);
#if 0
	INDENT;
#endif
	REDUCE(pp,1,decl_hd,-2,502);
	}
else if(Cpp && cat1==lpar && !in_prototype)
	{ // The \Cpp\ is a KLUDGE. Consider ``|int (*f)()|''.
	b_app1(pp);
	@<Append thinspace@>@;
	REDUCE(pp,1,expr,-2,5021); /* \Cpp\ constructor: ``|@c++ base()|'';
					or ``|@c++ int(x)|''. */
	}
else if(cat1==binop && cat2==expr)
	SQUASH(pp,3,int_like,-2,5022); /* \Cpp\ initializer: |@c++ base = 0| */
else if(cat1 == langle)
	SQUASH(pp, 1, int_like, PLUS 1, 5997); // |@c++ int<24>|
else if(cat1 == rangle)
	{
	b_app1(pp);
#if 0
	INDENT;
#endif
	REDUCE(pp,1,decl_hd,-2,5998);
	}
else if(cat1 == class_like)
	{ // \Cpp:  |@c++ friend class|.
	PP_PP(1,1);
	REDUCE(pp, 2, class_like, 0, 5995);
	}	
else if(cat1 == tlist)
	SQUASH(pp, 2, int_like, -2, 5999);
else if(cat1 == namespace)
	{ /* |@c++ using namespace| */
	PP_PP(1,1);
	REDUCE(pp, 2, namespace, 0, 5996);
	}
}

@ We need a special case for |extern|, because of constructions like |@c+
extern "C"| in \Cpp.

@<CASES for |extern_like| (C)@>=
#if FCN_CALLS
	C_ext_like();
#else
	@<Cases for |extern_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_ext_like(VOID)
		{
		@<Cases for |extern_like| (C)@>@;
		}
#endif

@
@<Cases for |extern_like| (C)@>=
{
if(Cpp &&cat1==expr)
	{ /* |@c++ extern "C"| */
	PP_PP(1,1);
	if(cat2==lbrace || cat2==kill_newlines)
		REDUCE(pp, 2, fn_decl, 0, 5025); // ``|@c++ extern "C" {}|''.
	else
		REDUCE(pp, 2, int_like, 0, 5023); 
			// ``|@c++ extern "C" int fcn();|''
	}
else 
	SQUASH(pp,1,int_like,0,5024);
}

@ A case related but not identical to |int_like| is |modifier|, which is
used for things like |const| and |volatile|. The difficulty is that it may
come first in the declaration, but it need not. Compare |const char c| and
|char const c|; also |char *const p| and |const char *p|.

@<CASES for |modifier| (C)@>=
#if FCN_CALLS
	C_modifier();
#else
	@<Cases for |modifier| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_modifier(VOID)
		{
		@<Cases for |modifier| (C)@>@;
		}
#endif

@
@<Cases for |modifier| (C)@>=
{
if(cat1==int_like || cat1==struct_like || cat1==class_like)
	SQUASH(pp, 1, cat1, -2, 503);
else if(pp == lo_ptr)
	SQUASH(pp, 1, expr, 0, 5040);
else if(cat1==comma || cat1==semi || cat1==lbrace || cat1==kill_newlines)
	SQUASH(pp, 1, _EXPR, 0, 5042); 
		/* |@c++ int f() const, g();| or @c++ int f() const;| or
			|@c++ int f() const {}|. */
else
	SQUASH(pp, 1, EXPR_, 0, 5041);
}

@ Personal computers have a strange syntax with the |HUGE| operator.  We
must deal with declarations such as |char HUGE *p;|.
@<CASES for |huge_like| (C)@>=
#if FCN_CALLS
	C_huge_like();
#else
	@<Cases for |huge_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_huge_like(VOID)
		{
		@<Cases for |huge_like| (C)@>@;
		}
#endif

@
@<Cases for |huge_like| (C)@>=
{
if(cat1==unorbinop) 
	{
	b_app1(pp); @~ APP_SPACE; @~ b_app1(pp+1);
	REDUCE(pp,2,unorbinop,-1,505);
	}
}

@ 
@<CASES for |virtual| (C++)@>=
#if FCN_CALLS
	C_virtual();
#else
	@<Cases for |virtual| (C++)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_virtual(VOID)
		{
		@<Cases for |virtual| (C++)@>@;
		}
#endif

@
@<Cases for |virtual| (C++)@>=
{
b_app1(pp);

if(cat1==unop) 
	APP_SPACE; // |@c++ virtual ~base();|

REDUCE(pp,1,int_like,0,506);
}

@ 
@<CASES for |reference| (C++)@>=
#if FCN_CALLS
	C_reference();
#else
	@<Cases for |reference| (C++)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_reference(VOID)
		{
		@<Cases for |reference| (C++)@>@;
		}
#endif

@ If we can't figure out that an ampersand is a reference, treat it just
like an asterisk.
@<Cases for |reference| (C++)@>=
{
SQUASH(pp, 1, unorbinop, -1, 507);
}

@ With the advent of ANSI~C, we have to deal with function prototypes,
which look very much like casts. 

@d INDENT if(!indented)
		{
		b_app(indent);
		indented = YES;
		}

@d OUTDENT if(indented)
		{
		b_app(outdent);
		indented = NO;
		}

@<Glob...@>=

IN_PROD int in_prototype PSET(NO); 
	// This is used as a numerical counter.
IN_PROD int indented PSET(NO);

@ For \Cpp, it becomes necessary to know whether one is inside or outside
of a function.

@<Glob...@>=

IN_PROD boolean in_function PSET(NO);

@ A |decl_hd| is something like ``|int i|''.

@<CASES for |decl_hd| (C)@>=
#if FCN_CALLS
	C_decl_hd();
#else
	@<Cases for |decl_hd| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_decl_hd(VOID)
		{
		@<Cases for |decl_hd| (C)@>@;
		}
#endif

@
@<Cases for |decl_hd| (C)@>=
{
if(cat1==rpar) 
	{
	if((pp-1)->cat==lpar) 
		SQUASH(pp,1,decl_hd,-1,4990); // ``|(int i)|''.
	else if((pp-2)->cat==decl_hd) 
		SQUASH(pp,1,decl_hd,-2,4991); // ``|(int i, int j)|''.
	else if((pp-3)->cat==decl_hd)
		SQUASH(pp, 1, decl_hd, -3, 4992);
	}
else if(cat1==decl_hd) 
	SQUASH(pp,2,decl_hd,0,50); // ``|(int,int)|''
else if(cat1==comma)
	{
	if(cat2==decl_hd)
		{ /* For function prototype. */
		b_app2(pp); @~ OPT9;
		b_app1(pp+2);
		REDUCE(pp,3,decl_hd,0,501);
		}
	else if(cat2==ignore_scrap && cat3==decl_hd)
		{ /* For function prototype with comment. */
		b_app2(pp); @~ OPT9;
		b_app2(pp+2);
		REDUCE(pp,4,decl_hd,0,504);
		}
#if 0
	else if(Cpp && (cat2==decl || cat2==stmt))
		SQUASH(pp, 3, stmt, -2, 508); 
			/* ``|@c++ for(int i=0, int j=0;;)|'' or ``|@c++
				for(int i=0, int j=0, int k=0;;)|''. */
#endif
	else
	{ /* ``|int i,|'' */
	if(cat2==ignore_scrap && (cat3==int_like || cat3==struct_like ||
			cat3==modifier) ) 
		{/* Function prototype, with intervening comment. */
		b_app1(pp);
		if((pp-3)->cat != decl_hd && (pp-2)->cat != decl_hd
				&& cat3 != modifier)
			in_prototype++;
		REDUCE(pp,1,decl_hd,PLUS 3,5221);
		}
	else if(cat2==int_like || cat2==struct_like || cat2==modifier) 
		{ /* Function prototype. */ 
		b_app1(pp);
		if((pp-3)->cat != decl_hd && (pp-2)->cat != decl_hd
				&& cat2 != modifier)
			in_prototype++; /* The |modifier| clause is to
prevent a situation like |(int, const int)| from thinking it's two levels
of prototypes. */
		REDUCE(pp,1,decl_hd,PLUS 2,52);
		}
	else 
		{  /* Expecting list of something. */
		b_app2(pp); app(@'~');

#if 0
		if(Cpp)
			REDUCE(pp, 2, decl_hd, -2, 540); 
				// ``|@c++ int i=0, int j=0|'' (e.g., in |for|)
		else
#endif
			REDUCE(pp,2,decl_hd,-1,54); // ``|int i,j|''
		}
	}
	}
else if (cat1==unorbinop)
	{ /* ``|int **p|'' */
	b_app1(pp); 
	b_app(@'{'); 
	b_app1(pp+1); 
	b_app(@'}');
	REDUCE(pp,2,decl_hd,-1,55);
	}
else if (cat1==expr) 
	{ /* ``|int i|'' or ``|int i, j|'' */
	make_underlined(pp+1);
	SQUASH(pp,2,decl_hd,-1,56);  /* The |-1| is to pick up a left
					paren for function prototype. */
	}
else if ((cat1==binop||cat1==colon
||cat1==expr	/* (for initializations) */
) && cat2==expr && (cat3==comma || cat3==semi || cat3==rpar))
#if 0
	if(cat1==binop)
		{
		PP_PP(1,2);
		REDUCE(pp,3,decl_hd,-1,5660);
		}
	else 
#endif
		SQUASH(pp,3,decl_hd,-1,5661);
else if(cat1==int_like && (cat2==unop || cat2==langle))
	SQUASH(pp, 1, decl_hd, PLUS 1, 5662); 
	/* \Cpp:  ``|@c++ void *int::fcn()|'' or ``|@c++ void
		*int<int>::fcn()|'' */
else if (cat1==lbrace || (cat1==int_like && 
	((pp-1)->trans == NULL || **(pp-1)->trans != @'('))) /*
Recognize beginning of function: ``|float f() {}|'' or ``|float f(x) float
x|'' */ 
	{
	b_app1(pp);
#if 0
	OUTDENT;
#endif
	in_function = YES;
	defined_at(FIRST_ID(pp));
	REDUCE(pp,1,fn_decl,0,58); 
	}
else if (cat1==semi)
	{ /* ``|int i;|'' */
	b_app2(pp);
#if 0
	OUTDENT; /* Finish long declaration. */
#endif
#if 0
	if(Cpp)
		REDUCE(pp, 2, decl, -2, 594); 
			// ``|@c++ for(int i=0, int j=0;;)|''
	else
#endif
		REDUCE(pp,2,decl,-1,59);
	}
else if(Cpp && cat1==int_like && cat2==unop)
	SQUASH(pp,1,decl_hd,PLUS 1,590); /* \Cpp: |@c++ void *class::f| */
else if(Cpp && cat1 == rangle)
	SQUASH(pp, 1, decl_hd, -2, 591); /* \Cpp:  end of template. */
else if(Cpp && cat1 == struct_like)
	SQUASH(pp, 2, decl_hd, -1, 593); 
		/* \Cpp: |@c++ template<class C1, class C2>|. */
}

@ A |decl| is a |decl_hd| followed by a semicolon---i.e., a complete
statement. 

@<CASES for |decl| (C)@>=
#if FCN_CALLS
	C_decl();
#else
	@<Cases for |decl| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_decl(VOID)
		{
		@<Cases for |decl| (C)@>@;
		}
#endif

@
@<Cases for |decl| (C)@>=
{
if(Cpp)
	{
	if(cat1==functn)
		{
		b_app1(pp); @~ b_app(big_force);
		b_app1(pp+1);
		REDUCE(pp,2,functn,-1,61);
		}
	else 
		SQUASH(pp,1,stmt,-1,611); // E.g., ``|@c++ for(int i=0;;)|''
	}
else
	{
	if (cat1==decl)
		{ /* ``|int i; float x;|'' */
		b_app1(pp); @~ b_app(force);
		b_app1(pp+1);
		REDUCE(pp,2,decl,-1,60);
		}
	else if (cat1==stmt || cat1==functn)
		{  /* ``|int i; x=0;|'' or ``|int i; f(){}|'' */
		b_app1(pp); @~ b_app(big_force); 
		b_app1(pp+1); 
		REDUCE(pp,2,cat1,-1,61);
		}
	}
}

@ A |fn_decl| is the beginning of a function.

@<CASES for |fn_decl| (C)@>=
#if FCN_CALLS
	C_fn_decl();
#else
	@<Cases for |fn_decl| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_fn_decl(VOID)
		{
		@<Cases for |fn_decl| (C)@>@;
		}
#endif

@
@<Cases for |fn_decl| (C)@>=
{
if(cat1 == semi && Cpp)
	{ /* |@c++ using namespace X;| */
	b_app2(pp);
	REDUCE(pp, 2, stmt, -1, 72);
	}
else if (cat1==decl)
	{ /* ``|f(x) float x;|'' */
	b_app1(pp); 
	b_app(indent); @~ indent_force;
		b_app1(pp+1); /* Accrete old-style declarations. */
	b_app(outdent); @~ b_app(outdent);
	REDUCE(pp,2,fn_decl,0,70);
	}
else if (cat1==stmt) 
	{ /* ``|f(){}|'' */
#if(0)
	b_app(backup); /* Beginning of function. */
#endif
	b_app1(pp); @~ b_app(force); 
	b_app(indent);
		b_app1(pp+1); /* Function body */
	b_app(outdent);
	in_function = kill_nl = NO;
	REDUCE(pp,2,functn,-1,71);
	}
}

@ Deal with a complete function. Handle ``|f(){} g(){}|'' or ``|f(){}
extern int i;|''. 
@<CASES for |functn| (C)@>=
#if FCN_CALLS
	C_functn();
#else
	@<Cases for |functn| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_functn(VOID)
		{
		@<Cases for |functn| (C)@>@;
		}
#endif

@ The |stmt| clause takes care of \Cpp\ constructions like |@c++ try{}
catch(){}|. 
@<Cases for |functn| (C)@>=
{
if (cat1==functn || cat1==decl || cat1==stmt) 
	{
	b_app1(pp); @~ b_app(big_force); 
	b_app1(pp+1); REDUCE(pp,2,cat1,-1,80); /* |-1| for \Cpp */
	}
}

@ Handle syntaxes like ``|typedef int I;|'' or ``|typedef int
(**f[])();|''.
@<CASES for |typedef_like| (C)@>=
#if FCN_CALLS
	C_typedef_like();
#else
	@<Cases for |typedef_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_typedef_like(VOID)
		{
		@<Cases for |typedef_like| (C)@>@;
		}
#endif

@
@<Glob...@>=

IN_PROD boolean typedefing PSET(NO); // Are we inside a |typedef|?

@
@<Cases for |typedef_like| (C)@>=
{
if (cat1==decl_hd && (cat2==expr || cat2 == int_like))
	{
	make_underlined(pp+2); make_reserved(pp+2); /* NEEDS TO BE IMPROVED! */
	b_app2(pp+1);
	REDUCE(pp+1,2,decl_hd,0,90);
	}
else if(cat1==decl)
	{
	PP_PP(1,1);
	REDUCE(pp,2,decl,-1,91);
	}
else if(cat1==semi)
	SQUASH(pp, 2, stmt, -1, 94); 
		/* ``|typedef|''. */
else if(cat1==stmt)
	{
	PP_PP(1,1);
	REDUCE(pp, 2, stmt, -1, 95);  
		/* ``|typedef int I[3]|''. (|I| is defined in first pass.) */
	}
	
}

@ 
@<CASES for |imp_reserved| (C)@>=
#if FCN_CALLS
	C_imp_reserved();
#else
	@<Cases for |imp_reserved| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_imp_reserved(VOID)
		{
		@<Cases for |imp_reserved| (C)@>@;
		}
#endif

@ The special type |imp_reserved| is needed for forward referencing, but
when it's encountered within a |typedef| it should be interpreted as an
expression. 
@<Cases for |imp_reserved| (C)@>=
{
if(typedefing) SQUASH(pp,1,expr,-2,92);
else SQUASH(pp,1,int_like,-2,93);
}

@ In \Cpp, operator overloading has a somewhat unusual syntax, in that
constructions like |operator -=| plays the role of a function name.

@d MAX_OP_TOKENS 5 /* Maximum \# of tokens that could conceivably make up
	the function name. */

@<CASES for |op_like| (C)@>=
#if FCN_CALLS
	C_op_like();
#else
	@<Cases for |op_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_op_like(VOID)
		{
		@<Cases for |op_like| (C)@>@;
		}
#endif

@
@<Cases for |op_like| (C)@>=
{
short n; 
 // The actual number of tokens that make up the effective function name. 

if((cat1==lpar && cat2==rpar) || (cat1==lbracket && cat2==rbracket))
	{ /* |@c++ operator ()()|  is a special case because it begins with
left paren.  |@c++ operator []()| is handled as a special case because we
now have the categories |lbracket| and |rbracket|, and |lbracket| doesn't
regress when it's reduced to |lpar|. */
	APP_STR("\\Woperator");
	b_app(@'{');
	b_app1(pp+1); // |lpar| or |lbracket|
	@<Append thinspace@>@;
	b_app1(pp+2); // |rpar| or |rbracket|
	b_app(@'}');
	n = 3;
	}
else
	{ /* We'll search for the obligatory left paren that indicates the
argument list. */
	scrap_pointer q;
	int k; /* Counter. */

/* If the paren is missing, we could end up appending the entire rest of
the code, so we limit the search. */
	for(q = pp+1; q <= scrp_ptr && q-pp <= MAX_OP_TOKENS; q++)
		if(q->cat == lpar) 
			break;

	n = (q->cat == lpar) ? PTR_DIFF(short, q, pp) : 0;

/* Append all the tokens between |operator| and left paren. */
	if(n > 0)
		{
		text_pointer xp;
		token_pointer tp,tp1;

#if 0
		b_app1(pp); // |@c++ operator|; really \.{\\Woperator}.
		b_app(@'{'); /* Braces prevent possible spurious blanks
before the left paren. */
#endif
		APP_STR("\\Woperator");
		b_app(@'{');

		id_first = id_loc = mod_text + 1;

		for(k=1; k<n; k++)
			{
			b_app1(pp+k);

			xp = indirect((pp+k)->trans);
			tp = *xp;
			tp1 = *(xp+1);
			while(tp < tp1)
				*id_loc++ = (ASCII)(*tp++);
			}

		underline_xref(id_lookup(id_first,id_loc,0));

		b_app(@'}');
		}
	}

if(n > 0) 
	REDUCE(pp, n, expr, -2, 6666);
else
	{
	APP_STR("\\Woperatoro");
	REDUCE(pp, 1, expr, -2, 6668);
	}		
}
	
@ |@c++ class| is almost like |struct|, but it has to reserve the class name.
(Note that it might have been declared earlier, hence the |int_like| option.)

@<CASES for |class_like| (C)@>=
#if FCN_CALLS
	C_class_like();
#else
	@<Cases for |class_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_class_like(VOID)
		{
		@<Cases for |class_like| (C)@>@;
		}
#endif

@
@<Cases for |class_like| (C)@>=
{
if(cat1==expr || cat1==int_like)
	{ /* \Cpp: |@c++ class A| */
	make_underlined(pp+1); @~ make_reserved(pp+1);

	PP_PP(1,1);

	if((pp-1)->cat == tstart || (pp-1)->cat == decl_hd 
			|| (pp-1)->cat == lpar)
		REDUCE(pp, 2, decl_hd, -1, 8998);
	else
		REDUCE(pp, 2, struct_like, 0, 8999);
	}
else if(cat1==lbrace)
	SQUASH(pp, 1, struct_like, 0, 8987); 
		// |@c++ class{}| or |@c++ struct{}|.
}

@ Deal with beginning of a structure.

@<CASES for |struct_like| (C)@>=
#if FCN_CALLS
	C_struct_like();
#else
	@<Cases for |struct_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_struct_like(VOID)
		{
		@<Cases for |struct_like| (C)@>@;
		}
#endif

@
@c++
@f base int
@f derived int
@<Cases for |struct_like| (C)@>=
{
if (cat1==lbrace)
	{  /* ``|struct {int i;} S;|'' or \Cpp: ``|@c++ class A{int i;};|'' */
	b_app1(pp); @~ indent_force;	
	b_app1(pp+1); REDUCE(pp,2,struct_hd,0,100);
	}
else if (cat1==expr) 
	{ /* Structure name: ``|struct s|'' */
	if (cat2==lbrace) /* ``|struct s {}|'' */
		{
/* In \Cpp, this construction defines a new type. */
		if(Cpp) 
			{make_underlined(pp+1); @~ make_reserved(pp+1);}

		PP_PP(1,1);
		indent_force;
		b_app1(pp+2);
		REDUCE(pp,3,struct_hd,0,101);
		}
	  else 
		{ /* ``|struct s ss|'' */
		PP_PP(1, 1);
		REDUCE(pp,2,int_like,-1,102);
		}
	}
else if(cat1==colon && cat2==int_like && Cpp)
	{ /* |@c++ class A: base| */
	if(cat3==langle)
		SQUASH(pp, 1, struct_like, PLUS 3, 1023);
	else
		{
		b_app1(pp); @~ b_app(@' '); @~ b_app1(pp+1); @~ b_app(@' '); @~
			b_app1(pp+2);
		REDUCE(pp,3,struct_like,0,1021);
		}
	}
else if(cat1==comma && cat2==int_like && Cpp)
	{ /* |@c++ class A: base, base | */
	if(cat3==langle)
		SQUASH(pp, 1, struct_like, PLUS 3, 1024);
	else
		{
		PP_PP(2, 1);
		REDUCE(pp,3,struct_like,0,1022);
		}
	}
else if(cat1==tlist)
	SQUASH(pp, 2, struct_like, 0, 1025); // \Cpp: |@c++ class A<int>|.
else if(cat1==semi) 
	SQUASH(pp,2,decl,-1,103); /* \Cpp: |@c++ class base;| */
else if(cat1 == rangle)
	SQUASH(pp, 1, decl_hd, -2, 592); /* \Cpp:  end of template. */
}

@ Handle ``|enum{red,yellow}|;''.
@<CASES for |struct_hd| (C)@>=
#if FCN_CALLS
	C_str_hd();
#else
	@<Cases for |struct_hd| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_str_hd(VOID)
		{
		@<Cases for |struct_hd| (C)@>@;
		}
#endif

@
@<Cases for |struct_hd| (C)@>=
{
if ((cat1==decl || cat1==stmt
 || cat1==expr /*  (For enum) */
 || cat1==functn /* \Cpp */
) && cat2==rbrace) 
	{
	b_app1(pp); /* ``|struct {|'' */
	@<Append a body@>@;
	b_app1(pp+2); /* ``|}|'' */
	b_app(outdent); 
@#if 0
	b_app(break_space);
@#endif
	REDUCE(pp,3,int_like,-1,110);
	}
else if(cat1==rbrace)
	{
	b_app1(pp); @~ @<Append thin...@>@; b_app1(pp+1);
	b_app(outdent);
	REDUCE(pp,2,int_like,-1,1101);
	}
}

@ 
@<CASES for |lpar| (C)@>=
#if FCN_CALLS
	C_lpar();
#else
	@<Cases for |lpar| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_lpar(VOID)
		{
		@<Cases for |lpar| (C)@>@;
		}
#endif

@
@<Cases for |lpar| (C)@>=
{
if (cat2==rpar && (cat1==expr || cat1==unorbinop)) 
	SQUASH(pp,3,expr,-2,120); /* ``|(x)|''  or ``|(*)|''*/
else if (cat1==rpar) 
	{ /* ``|()|''. This looks better with a bit of extra space between
		the parens. */ 
	  b_app1(pp); @~ @<Append thickspace@>; @~ b_app1(pp+1);
	  REDUCE(pp,2,expr,-2,121);
	}
else if ((cat1==decl_hd) && cat2==rpar)
	{ /* Function prototype or cast, like ``|typedef (*T)|'' where |T|
		was |typedef|d on the first pass. */
	b_app3(pp);

	OUTDENT;

	if(in_prototype) 
		in_prototype--;

	REDUCE(pp,3,cast,-1,122);
	}
else if (cat1==stmt)
	{ /* ``|for(x;y;z)|'' */
	b_app2(pp); b_app(@' '); REDUCE(pp,2,lpar,0,123);
	}
else if(cat1==for_like && cat2==rpar) 
	SQUASH(pp,3,expr,-2,1201); /* Macros: |(for)| */ 
}

@ 
@<CASES for |lbracket| (C)@>=
#if FCN_CALLS
	C_lbracket();
#else
	@<Cases for |lbracket| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_lbracket(VOID)
		{
		@<Cases for |lbracket| (C)@>@;
		}
#endif

@
@<Cases for |lbracket| (C)@>=
{
if(active_brackets)
	{
	b_app(@'\\');
	APP_STR("WXA{");
	}
else b_app1(pp);

REDUCE(pp,1,lpar,0,5000);
}

@ 
@<CASES for |rbracket| (C)@>=
#if FCN_CALLS
	C_rbracket();
#else
	@<Cases for |rbracket| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_rbracket(VOID)
		{
		@<Cases for |rbracket| (C)@>@;
		}
#endif

@
@<Cases for |rbracket| (C)@>=
{
if(active_brackets) 
	{
	text_pointer t = indirect(pp->trans);

	if(**t == @']') **t = @'}';
	}

b_app1(pp);

REDUCE(pp,1,rpar,-5,5001);
}

@
@<CASES for |kill_newlines| (C++)@>=
#if FCN_CALLS
	C_killnl();
#else
	@<Cases for |kill_newlines| (C++)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_killnl(VOID)
		{
		@<Cases for |kill_newlines| (C++)@>@;
		}
#endif

@ The |kill_nl| flag is intended to make prettier short functions for such
things as simple \Cpp\ constructors.  The scrap of ilk |kill_newlines| is
appended by \.{@@\{}.

@<Glob...@>=
IN_PROD boolean kill_nl PSET(NO);

@
@<Append a |force| or thinspace@>=
{
if(kill_nl)
	@<Append thinspace@>@;
else
	b_app(force);
}

@
@<Cases for |kill_newlines| (C++)@>=
{
kill_nl = YES;
SQUASH(pp, 1, lbrace, -2, 8888);
}

@ 
@<CASES for |lbrace| (C)@>=
#if FCN_CALLS
	C_lbrace();
#else
	@<Cases for |lbrace| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_lbrace(VOID)
		{
		@<Cases for |lbrace| (C)@>@;
		}
#endif

@
@<Cases for |lbrace| (C)@>=
{
if (cat1==rbrace)  /* ``|{}|'' */
	{
	b_app1(pp); @~ @<Append thinspace@>; @~ b_app1(pp+1); 
	REDUCE(pp,2,stmt,-1,130);
	}
else if ((cat1==stmt || cat1==decl || cat1==functn) && cat2==rbrace)  
	/* ``|{x;}|''  or \dots\ or \Cpp:  |@c++ main(){try{}catch(){}}| */
	{
	b_app(force);
	b_app1(pp);  /* ``|{|'' */

	@<Append a body@>@;

	b_app1(pp+2); /* ``|}|'' */

	REDUCE(pp,3,stmt,-1,131);
	}
else if (cat1==expr) 
	{
	if (cat2==rbrace) 
		SQUASH(pp,3,expr,-2,132); /* ``|enum{red}|'' */
	else if (cat2==comma && cat3==rbrace) 
		SQUASH(pp,4,expr,-2,132);
	}
}

@
@<Append a body@>=
{
@<Append a |force| or thinspace@>@;

b_app1(pp+1); /* Body */

@<Append a |force| or thinspace@>@;

kill_nl = NO;
}

@ 
@<CASES for |unop| (C)@>=
#if FCN_CALLS
	C__unop();
#else
	@<Cases for |unop| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C__unop(VOID)
		{
		@<Cases for |unop| (C)@>@;
		}
#endif

@
@<Cases for |unop| (C)@>=
{
if (cat1==expr) 
	SQUASH(pp,2,expr,-2,140); /* ``|!x|'' or ``|++x|'' */
else if(cat1==int_like) 
	SQUASH(pp,2,int_like,0,141); /* \Cpp\ destructor:
			``|@c++ ~base|'' */ 
}

@ 
@<CASES for |unorbinop| (C)@>=
#if FCN_CALLS
	C_unorbinop();
#else
	@<Cases for |unorbinop| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_unorbinop(VOID)
		{
		@<Cases for |unorbinop| (C)@>@;
		}
#endif

@
@<Cases for |unorbinop| (C)@>=
{
if(cat1==expr || (cat1==int_like && !(cat2 == lpar || cat2 == unop)) )
	{  /* ``|*p|'' or ``|&x|''; ``|typedef
		(*T)|'' where |T| was |typedef|d on the first pass.  Not
\Cpp:  ``|@c++ x + int(i)|'' or ``|@c++ x + base::y|''. */
	b_app(@'{'); @~b_app1(pp); @~ b_app(@'}'); 
	b_app1(pp+1); 
	REDUCE(pp,2,cat1,-2,150);
	}
else if (cat1==binop) 
	@<Reduce cases like |*=|@>@;
}

@
@<Reduce cases like |*=|@>=
{
  b_app(math_bin); 
b_app1(pp); 
b_app(@'{'); @~ b_app1(pp+1); @~ b_app(@'}');
  b_app(@'}'); /* End |math_bin| */
  REDUCE(pp,2,binop,-1,151);
}

@ 
@<CASES for |cast| (C)@>=
#if FCN_CALLS
	C_cast();
#else
	@<Cases for |cast| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_cast(VOID)
		{
		@<Cases for |cast| (C)@>@;
		}
#endif

@
@<Cases for |cast| (C)@>=
{
if (cat1==expr)  /* ``|(int *)p|'' */
	{
	b_app1(pp); @~ @<Append thinspace@>; @~ b_app1(pp+1); 
	REDUCE(pp,2,expr,-2,160);
	}
else if(cat1 == unorbinop || cat1 == reference)
	SQUASH(pp, 1, cast, PLUS 1, 162); // ``|(int *)&prms|''.
else 
	SQUASH(pp,1,expr,-2,161); // Turn function prototype into expression.
}

@ 
@<CASES for |sizeof_like| (C)@>=
#if FCN_CALLS
	C_sizeof_like();
#else
	@<Cases for |sizeof_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_sizeof_like(VOID)
		{
		@<Cases for |sizeof_like| (C)@>@;
		}
#endif

@
@<Cases for |sizeof_like| (C)@>=
{
if (cat1==cast) 
	SQUASH(pp,2,expr,-2,170); /* ``|sizeof (int *)|'' */
else if (cat1==expr) 
	SQUASH(pp,2,expr,-2,171); /* ``|sizeof(x)|'' */
}

@ 
@<CASES for |binop| (C)@>=
#if FCN_CALLS
	C__binop();
#else
	@<Cases for |binop| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C__binop(VOID)
		{
		@<Cases for |binop| (C)@>@;
		}
#endif

@
@<Cases for |binop| (C)@>=
{
if (cat1==binop) 
	@<Reduce cases like |+=|@>@; /* ``|+=|'' */
else if(cat1==space)
	{
	b_app1(pp); // We eat the space in this macro situation.
	REDUCE(pp, 2, binop, -1, 181); // |#if(a == b)|.
	}
else if(Cpp && cat1==decl_hd)
	SQUASH(pp, 2, tstart, 0, 6063);
		/* Trap for ``|@c++ A<int>|'', with |A| undefined.  See
			also Rule 6061. */
}

@
@<Reduce cases like |+=|@>=
{
  b_app(math_bin); b_app1(pp); 
b_app(@'{'); @~ b_app1(pp+1); @~ b_app(@'}');
  b_app(@'}'); /* End |math_bin| */
  REDUCE(pp,2,binop,-1,180);
}

@ 
@<CASES for |do_like| (C)@>=
#if FCN_CALLS
	C_do_like();
#else
	@<Cases for |do_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_do_like(VOID)
		{
		@<Cases for |do_like| (C)@>@;
		}
#endif

@
@<Cases for |do_like| (C)@>=
{
if (cat1==stmt)
	if(cat2==for_like)
		{
		cat2 = while_do;
		SQUASH(pp, 1, do_like, PLUS 2, 191);
		}
	else if(cat2==expr && cat3==semi)
		{ /* ``|do {} while(flag);|'' */
		b_app1(pp); // ``\&{do}''
		indent_force;
		   b_app1(pp+1); // stmt 
		b_app(outdent);
		b_app(force);
		b_app2(pp+2); // ``\&{while}\dots''
		REDUCE(pp,4,stmt,-1,190);
		}
	}

@
@<CASES for |while_do| (C)@>=
#if FCN_CALLS
	C_wh_do();
#else
	@<Cases for |while_do| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_wh_do(VOID)
		{
		@<Cases for |while_do| (C)@>@;
		}
#endif

@
@<Cases for |while_do| (C)@>=
{
b_app1(pp);
@<Append thinspace@>;
REDUCE(pp, 1, expr, 0, 192);
}

@ Identifiers that are |for_like| must in normal usage be followed by a
parenthesized expression. However, since they might be used in isolation in
a macro argument, we allow a default possibility.

@<CASES for |for_like| (C)@>=
#if FCN_CALLS
	C_for_like();
#else
	@<Cases for |for_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_for_like(VOID)
		{
		@<Cases for |for_like| (C)@>@;
		}
#endif

@
@<Cases for |for_like| (C)@>=
{
if (cat1==expr)
	{ /* ``\&{for}\dots'' */
	b_app1(pp); @~ @<Append thinspace@>;  @~ b_app1(pp+1); 
	b_app(@' '); // Unnecessary?  (Space at end of |for| line?)

	if(cat2==semi)
		{ /* ``|for(;;);|'' */
		if(!auto_semi || (auto_semi && cat3==semi))
			{
			indent_force;
			b_app1(pp+2); // Semi on separate line.
			b_app(outdent);
			REDUCE(pp,3,stmt,-2,200); /*  The $-2$ is for the
\&{do} case. Also get here from Ratfor's \&{until}. */ 
			}
		else 
			REDUCE(pp,3,for_hd,0,2011); // Eat the |auto_semi|.
		}
	else 
		REDUCE(pp,2,for_hd,0,201); // Eat the arguments.
	}
else if(cat1 != lpar) 
	SQUASH(pp,1,expr,0,2010); // Default possiblity.
}

@ 
@<CASES for |for_hd| (C)@>=
#if FCN_CALLS
	C_forhd();
#else
	@<Cases for |for_hd| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_forhd(VOID)
		{
		@<Cases for |for_hd| (C)@>@;
		}
#endif

@
@<Cases for |for_hd| (C)@>=
{
if (cat1==stmt)
	{ /* ``|for(;;) x;|'' */
	b_app1(pp); 
	indent_force;
	   b_app1(pp+1);
	b_app(outdent);
	REDUCE(pp,2,stmt,-1,210);
	}
}

@ Begin an \&{if} statement by just absorbing the argument in parentheses.
We check to see if there's a comment coming up, and set a flag. We have to
do that here because |ignore_scrap| is digested before the big switch.

@<CASES for |if_like| (C)@>=
#if FCN_CALLS
	C_if_like();
#else
	@<Cases for |if_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_if_like(VOID)
		{
		@<Cases for |if_like| (C)@>@;
		}
#endif

@
@<Cases for |if_like| (C)@>=
{
if (cat1==lpar && cat2==expr && cat3==rpar) /* ``|if(x)|'' */
	{
	  b_app1(pp); @<Append thinspace@>;  b_app3(pp+1); 
#if(0)
	cmnt_after_IF = (cat4==ignore_scrap); /* Comment coming up? */
#endif
	REDUCE(pp,4,IF_like,0,220);
	}
}

@ We need a flag to tell us whether a comment (really, |ignore_scrap|)
follows an |if(x)| construction. If so, we'll put even simple statements on
the next line, properly indented. (Not working yet!)

@<Glob...@>=

@#if(0)
	IN_PROD cmnt_after_IF PSET(NO);
@#endif

@ Attach |stmt| to |if(x)|. Statements get indented on next line. 
If there's no \&{else} following, we're done.

@<CASES for |IF_like| (C)@>=
#if FCN_CALLS
	C_IF();
#else
	@<Cases for |IF_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_IF(VOID)
		{
		@<Cases for |IF_like| (C)@>@;
		}
#endif

@
@<Cases for |IF_like| (C)@>=
{
if(cat1==stmt
	|| cat1==lbrace || cat1==if_like || cat1==for_like || cat1==do_like
		|| cat1==Rdo_like
#if(0)
 || cmnt_after_IF
#endif
		)
	SQUASH(pp,1,if_hd,0,230); // |if_hd| does the indenting.
#if(0)
else if(cat1==stmt) 
	{ /* Attach simple statement. */
	PP_PP(1,1);
	REDUCE(pp,2,IF_top,-1,231);
	}
#endif
}

@ The purpose here is to take a complete statement and indent it on the
next line. 
@<CASES for |if_hd| (C)@>=
#if FCN_CALLS
	C_if_hd();
#else
	@<Cases for |if_hd| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_if_hd(VOID)
		{
		@<Cases for |if_hd| (C)@>@;
		}
#endif

@
@<Cases for |if_hd| (C)@>=
{
if (cat1==stmt) /* ``|if(x) {}|'' */
	{
	b_app1(pp); /* ``|if(x)|'' */
	indent_force;
	 b_app1(pp+1); /* ``|{}|'' */
	b_app(outdent);
	REDUCE(pp,2,IF_top,-1,233);
	}
else if(cat1==IF_top && cat2==else_like) 
	SQUASH(pp,1,if_hd,2,234);
}

@
@<CASES for |else_hd| (C)@>=
#if FCN_CALLS
	C_els_hd();
#else
	@<Cases for |else_hd| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_els_hd(VOID)
		{
		@<Cases for |else_hd| (C)@>@;
		}
#endif

@
@<Cases for |else_hd| (C)@>=
{
if (cat1==stmt) /* ``|if(x) {}|'' */
	{
	b_app1(pp); /* ``|if(x)|'' */
	indent_force;
	 b_app1(pp+1); /* ``|{}|'' */
	b_app(outdent);
	REDUCE(pp,2,ELSE_like,-1,241);
	}
}

@ 
@<CASES for |else_like| (C)@>=
#if FCN_CALLS
	C_else();
#else
	@<Cases for |else_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_else(VOID)
		{
		@<Cases for |else_like| (C)@>@;
		}
#endif

@
@<Cases for |else_like| (C)@>=
{
if(cat1==if_like) /* ``|else if|'' */
	{
	PP_PP(1,1);
	REDUCE(pp,2,if_like,0,235);
	}
else if(cat1==stmt || cat1==lbrace || cat1==for_like || cat1==do_like)
	SQUASH(pp,1,else_hd,0,236); /* ``|else {}|'' */
#if 0 /* The following puts simple statement on same line. */
else if(cat1==stmt) /* ``|else z;|'' */
	{
	PP_PP(1,1);
	REDUCE(pp,2,ELSE_like,-1,237);
	}
#endif
}

@ This is commented out above.
@<CASES for |ELSE_like| (C)@>=
#if FCN_CALLS
	C_ELS();
#else
	@<Cases for |ELSE_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_ELS(VOID)
		{
		@<Cases for |ELSE_like| (C)@>@;
		}
#endif

@
@<Cases for |ELSE_like| (C)@>=

@
@<CASES for |IF_top| (C)@>=
#if FCN_CALLS
	C_IF_top();
#else
	@<Cases for |IF_top| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_IF_top(VOID)
		{
		@<Cases for |IF_top| (C)@>@;
		}
#endif

@
@<Cases for |IF_top| (C)@>=
{
if(cat1==else_like || cat1==else_hd || cat1==space) 
	SQUASH(pp,1,IF_top,1,242); /* Expand ahead. */ 
else if(cat1==IF_top)
	{
	b_app1(pp); /* \&{if}\dots */
	b_app(force);
	b_app1(pp+1); /* \&{else if}\dots */
	REDUCE(pp,2,IF_top,-1,238);
	}
else if(cat1==ELSE_like)
	{
	b_app1(pp); /* \&{if} */
	b_app(force);
	b_app1(pp+1); /* \&{else} */
	REDUCE(pp,2,stmt,-1,239);
	}
else if(cat1==IF_like && (cat2==expr || cat2==stmt))
	SQUASH(pp,1,IF_top,1,241);
else 
	SQUASH(pp,1,stmt,-1,240);
}

@ 
@<CASES for |stmt| (C)@>=
#if FCN_CALLS
	C_stmt();
#else
	@<Cases for |stmt| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_stmt(VOID)
		{
		@<Cases for |stmt| (C)@>@;
		}
#endif

@
@<Cases for |stmt| (C)@>=
{
if (cat1==stmt || (Cpp && cat1==decl)) /* ``|x; y;|'' */
	{
	b_app1(pp); 

	@<Append a |force| or thinspace@>@;

	b_app1(pp+1); 

	REDUCE(pp,2,stmt,-1,250);
	}
else if (cat1==functn)
	{
	b_app1(pp); @~ b_app(big_force);
	b_app1(pp+1);
	REDUCE(pp,2,stmt,-1,251);
	}
}

@ 
@<CASES for |case_like| (C)@>=
#if FCN_CALLS
	C_case_like();
#else
	@<Cases for |case_like| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_case_like(VOID)
		{
		@<Cases for |case_like| (C)@>@;
		}
#endif

@
@<Cases for |case_like| (C)@>=
{
if (cat1==semi) 
	SQUASH(pp,2,stmt,-1,260); /* |return;| */
else if (cat1==colon) 
	SQUASH(pp,2,tag,-1,261); /* |default:| or \Cpp: |@c++ public:| */
else if (cat1==expr) 
	{
	  if (cat2==semi) /* |return x;| */
		{
		PP_PP(1,2);
		REDUCE(pp,3,stmt,-1,262);
		}
	  else if (cat2==colon)  /* |case one:| */
		{
		PP_PP(1,2);
		REDUCE(pp,3,tag,-1,263);
		}
	}
else if(cat1==int_like)
	{ /* \Cpp: |@c++ public base| */
	PP_PP(1,1);
	REDUCE(pp,2,int_like,-2,264);
	}
}

@ 
@<CASES for |tag| (C)@>=
#if FCN_CALLS
	C_tag();
#else
	@<Cases for |tag| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_tag(VOID)
		{
		@<Cases for |tag| (C)@>@;
		}
#endif

@
@<Cases for |tag| (C)@>=
{
if (cat1==tag) /* ``|case one: case two:|'' */
	{
	  b_app1(pp); 
	  b_app(force);
	  b_app(backup);
	  b_app1(pp+1); REDUCE(pp,2,tag,-1,270);
	}
else if (cat1==stmt || cat1==decl || cat1==functn) /* ``|case one:
		break;|'' or \Cpp: ``|@c++ public: int constructor();|''  */
	{
	b_app(big_force); 
	b_app(backup); @~ b_app1(pp); @~ b_app(force);
	b_app1(pp+1); 
	REDUCE(pp,2,cat1,-1,271);
	}
}

@ To help distinguish a null statement, we preface the semicolon by a space.
@<CASES for |semi| (C)@>=
#if FCN_CALLS
	C_semi();
#else
	@<Cases for |semi| (C)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_semi(VOID)
		{
		@<Cases for |semi| (C)@>@;
		}
#endif

@
@<Cases for |semi| (C)@>=
{
b_app(@' '); @~ b_app1(pp); 
REDUCE(pp,1,stmt,-1,280);
}

@
@<CASES for |template| (C++)@>=
#if FCN_CALLS
	C_template();
#else
	@<Cases for |template| (C++)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_template(VOID)
		{
		@<Cases for |template| (C++)@>@;
		}
#endif

@
@<Cases for |template| (C++)@>=
{
if(cat1 == langle)
	SQUASH(pp, 1, template, PLUS 1, 6000);
else if(cat1 == tlist)
	{
	PP_PP(1, 1); @~ b_app(force);
	REDUCE(pp, 2, int_like, 0, 6001);
	}
}

@
@<CASES for |langle| (C++)@>=
#if FCN_CALLS
	C_langle();
#else
	@<Cases for |langle| (C++)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_langle(VOID)
		{
		@<Cases for |langle| (C++)@>@;
		}
#endif

@ If the |langle| isn't grabbed up by |template|, it's just an ordinary
binary operator.
@<Cases for |langle| (C++)@>=
{
if((pp-1)->cat == template || (pp-1)->cat == int_like || (pp-1)->cat ==
		struct_like) 
	{
	b_app(@'\\');
	APP_STR("WLA "); // \.{\\WLA} $\equiv$ `$\WLA$'.
	REDUCE(pp, 1, tstart, 0, 6050); // Begining of template parameter list.
	}
else if(cat1 == decl_hd && cat2 == rangle)
	{
	b_app(@'\\');
	APP_STR("WLA ");
	b_app1(pp+1);
	b_app(@'\\');
	APP_STR("WRA ");
	REDUCE(pp, 3, expr, -1, 6053); // |@c++ f<int, int>|.
	}
else if(cat1 == int_like)
	SQUASH(pp, 1, langle, PLUS 1, 6054); // |@c++ f<int>|.
else
	SQUASH(pp, 1, binop, -1, 6051);
}

@
@<CASES for |rangle| (C++)@>=
#if FCN_CALLS
	C_rangle();
#else
	@<Cases for |rangle| (C++)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_rangle(VOID)
		{
		@<Cases for |rangle| (C++)@>@;
		}
#endif

@ If the |rangle| isn't grabbed up by |template|, it's just an ordinary
binary operator.
@<Cases for |rangle| (C++)@>=
{
if((pp-1)->cat == decl_hd)
	SQUASH(pp, 1, rangle, -2, 6055);
else
	SQUASH(pp, 1, binop, -1, 6052);
}

@
@<CASES for |tstart| (C++)@>=
#if FCN_CALLS
	C_tstart();
#else
	@<Cases for |tstart| (C++)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_tstart(VOID)
		{
		@<Cases for |tstart| (C++)@>@;
		}
#endif

@
@<Cases for |tstart| (C++)@>=
{
if(cat2 == rangle && (cat1==int_like || cat1==decl_hd || cat1==expr 
		|| cat1==unorbinop))
	{
	b_app2(pp);
	b_app(@'\\');
	APP_STR("WRA "); // Closing of template.
	OUTDENT;
	REDUCE(pp, 3, tlist, -1, 6060);
	}
}

@
@<CASES for |tlist| (C++)@>=
#if FCN_CALLS
	C_tlist();
#else
	@<Cases for |tlist| (C++)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_tlist(VOID)
		{
		@<Cases for |tlist| (C++)@>@;
		}
#endif

@
@<Cases for |tlist| (C++)@>=

@
@<CASES for |namespace| (C++)@>=
#if FCN_CALLS
	C_namespace();
#else
	@<Cases for |namespace| (C++)@>@;
#endif

@
@<Part 1@>=
#if FCN_CALLS
	@[SRTN C_namespace(VOID)
		{
		@<Cases for |namespace| (C++)@>@;
		}
#endif

@
@<Cases for |namespace| (C++)@>=
{
if(cat1==expr || cat1==int_like)
	{ /* \Cpp: |@c++ namespace A| */
	make_underlined(pp+1); @~ make_reserved(pp+1);

	PP_PP(1,1);

	REDUCE(pp, 2, fn_decl, 0, 7901);
	}
else if(cat1==lbrace)
	SQUASH(pp, 1, fn_decl, 0, 7902); // |@c++ namespace{}|
}

@
@<Glob...@>=

IN_PROD boolean forward_exp PSET(NO);

@* PRODUCTIONS for RATFOR and FORTRAN.
Note that in some cases we use the C~rules for \RATFOR\ as well.

@<Part 2@>=@[

SRTN 
R_productions(VOID)
{
switch (pp->cat) 
    {
    case ignore_scrap:  @<CASES for |ignore_scrap| (C)@>@; break;
    case expr: @<CASES for |expr| (R)@>@; @~ break;
    case key_wd: @<CASES for |key_wd| (R)@>@; @~ break;
    case exp_op: @<CASES for |exp_op| (R)@>@; @~ break;
    case _EXPR: @<CASES for |_EXPR| (C)@>@; @~ break;
    case _EXPR_: @<CASES for |_EXPR_| (C)@>@; @~ break;
    case EXPR_: @<CASES for |EXPR_| (C)@>@; @~ break;
    case lpar: @<CASES for |lpar| (R)@>@; @~ break;
    case lbracket: @<CASES for |lbracket| (C)@>@; @~ break;
    case rbracket: @<CASES for |rbracket| (C)@>@; @~ break;
    case unop: @<CASES for |unop| (R)@>@; @~ break;
    case UNOP: @<CASES for |UNOP| (C)@>@; @~ break;
    case unorbinop: @<CASES for |unorbinop| (R)@>@; @~ break;
    case binop: @<CASES for |binop| (R)@>@; @~ break;
    case BINOP: @<CASES for |BINOP| (C)@>@; @~ break;
    case slash_like: @<CASES for |slash_like| (R)@>@; @~ break;
    case colon: @<CASES for |colon| (R)@>@; @~ break;
    case program_like: @<CASES for |program_like| (R)@>@; @~ break;
    case struct_like: @<CASES for |struct_like| (R)@>@; @~ break;
    case struct_hd: @<CASES for |struct_hd| (R)@>@; @~ break;
    case op_like: @<CASES for |op_like| (R)@>@; @~ break;	
    case proc_like: @<CASES for |proc_like| (R)@>@; @~ break;
    case private_like: @<CASES for |private_like| (R)@>@; @~ break;
    case int_like: @<CASES for |int_like| (R)@>@; @~ break;
    case decl_hd: @<CASES for |decl_hd| (R)@>@; @~ break;
    case decl: @<CASES for |decl| (R)@>@; @~ break;
    case fn_decl: @<CASES for |fn_decl| (C)@>@; @~ break;
    case fcn_hd: @<CASES for |fcn_hd| (R)@>@; @~ break;
    case functn: @<CASES for |functn| (R)@>@; @~ break;
    case lbrace: @<CASES for |lbrace| (R)@>@; @~ break;
    case do_like: @<CASES for |do_like| (R)@>@; @~ break;
    case until_like: @<CASES for |until_like| (R)@>@; @~ break;
    case Rdo_like: @<CASES for |Rdo_like| (R)@>@; @~ break;
    case if_like: @<CASES for |if_like| (R)@>@; @~ break;
    case IF_like: @<CASES for |IF_like| (C)@>@; @~ break; /* The C form serves
both. */
    case IF_top: @<CASES for |IF_top| (C)@>@; @~ break;
    case endif_like: @<CASES for |endif_like| (R)@>@; @~ break;
    case end_like: @<CASES for |end_like| (R)@>@; @~ break;
    case END_like: @<CASES for |END_like| (R)@>@; @~ break;
    case go_like: @<CASES for |go_like| (R)@>@; @~ break;
    case for_like: @<CASES for |for_like| (C)@>@; @~ break;
    case for_hd: @<CASES for |for_hd| (C)@>@; @~ break; /* C serves both. */
    case else_like: @<CASES for |else_like| (R)@>@; @~ break;
    case else_hd: @<CASES for |else_hd| (C)@>@; @~ break;
@#if(0)
    case ELSE_like: @<CASES for |ELSE_like| (C)@>@; @~ break; /* C serves
both. */ 
@#endif
    case if_hd: @<CASES for |if_hd| (R)@>@; @~ break;
    case CASE_like: @<CASES for |CASE_like| (R)@>@; @~ break;
    case case_like: @<CASES for |case_like| (R)@>@; @~ break;
    case stmt: @<CASES for |stmt| (R)@>@; @~ break;
    case tag: @<CASES for |tag| (R)@>@; @~ break;
    case label: @<CASES for |label| (R)@>@; @~ break;
    case semi: @<CASES for |semi| (R)@>@; @~ break;

    case common_like: @<CASES for |common_like| (R)@>@; @~ break;
    case common_hd: @<CASES for |common_hd| (R)@>@; @~ break;
    case read_like: @<CASES for |read_like| (R)@>@; @~ break;
    case read_hd: @<CASES for |read_hd| (R)@>@; @~ break;
    case entry_like: @<CASES for |entry_like| (R)@>@; @~ break;
    case implicit_like: @<CASES for |implicit_like| (R)@>@; @~ break;
    case implicit_hd: @<CASES for |implicit_hd| (R)@>@; @~ break;
    case assign_like: @<CASES for |assign_like| (R)@>@; @~ break;
    case define_like: @<CASES for |define_like| (R)@>@; @~ break;
    case built_in: @<CASES for |built_in| (R)@>@; @~ break;
    case no_order: @<CASES for |no_order| (R)@>@; @~ break;
    case newline: @<CASES for |newline| (R)@>@; @~ break;
    case COMMA: @<CASES for |COMMA| (C)@>@; @~ break;

  }
}

@
@<CASES for |expr| (R)@>=
#if FCN_CALLS
	R_expr();
#else
	@<Cases for |expr| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_expr(VOID)
		{
		@<Cases for |expr| (R)@>@;
		}
#endif

@
@<Cases for |expr| (R)@>=
{
if (cat1==unop) SQUASH(pp,2,expr,-2,2);
else if ((cat1==binop || cat1==unorbinop || cat1==colon) && cat2==expr)
/* Here we have to worry about constructions such as `|@r #:0|'. */
	if(cat1==colon && (*pp->trans)[1]==(sixteen_bits)@'#')
		{
		b_app1(pp);
		APP_STR("\\Colon");
		b_app1(pp+2);
		REDUCE(pp,3,expr,-2,3333);
		}
	else if(cat1==binop && **(pp+1)->trans == (sixteen_bits)@'/')
		SQUASH(pp, 1, expr, PLUS 1, 3334);
	else 
		SQUASH(pp,3,expr,-2,3); /* ``|@r x = y|'' or ``|@r x + y|'' or
				``|@r dimension a(0:100)|'' */ 
else if (cat1==comma && (cat2==expr || cat2==end_like))  
	{ /* Note |end_like|; keyword in I/O. */
	  b_app2(pp);
	OPT9;
	b_app1(pp+2); REDUCE(pp,3,expr,-2,4);
	}
else if (cat1==expr)  SQUASH(pp,2,expr,-2,5); /* ``|@r f(x)|'' */
else if (cat1==semi) SQUASH(pp,2,stmt,-2,6); /* ``|@r x=y;|'' */
else if (cat1==colon && cat2==unorbinop &&
		(cat3==rpar || (active_brackets && cat3==rbracket)))
	SQUASH(pp,3,expr,-2,299);  /* ``|@r 0:*|'' */
else if (cat1==colon && cat2!= lpar) /* label */
	{
	  make_underlined (pp);  SQUASH(pp,2,tag,0,7);
	}
else if (cat1==comma && cat2==int_like) /* For macro usage. */
	{
	  b_app2(pp);
	OPT9;
	b_app1(pp+2); REDUCE(pp,3,int_like,-2,4444);
	}
}

@ This route may be unused now.
@<CASES for |key_wd| (R)@>=
#if FCN_CALLS
	R_key_wd();
#else
	@<Cases for |key_wd| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_key_wd(VOID)
		{
		@<Cases for |key_wd| (R)@>@;
		}
#endif

@
@<Cases for |key_wd| (R)@>=
{
SQUASH(pp,1,expr,-2,4445);
}
 
@ Exponentiation. We have to watch out for constructions like \.{x\^(a+b)},
which must be typeset |@r x^(a+b)|, and also the construction
\.{x\^y(z)}, which must be typeset |@r x^y(z)|.

@<CASES for |exp_op| (R)@>=
#if FCN_CALLS
	R_exp_op();
#else
	@<Cases for |exp_op| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_exp_op(VOID)
		{
		@<Cases for |exp_op| (R)@>@;
		}
#endif

@
@<Cases for |exp_op| (R)@>=
{
if(cat1==lpar) SQUASH(pp,1,exp_op,PLUS 1,2995); /* ``|@r x^(a+b)|'' */
else if(cat1==expr)
	if(cat2==lpar) SQUASH(pp,1,exp_op,PLUS 2,2996); /* Expand array
argument. */
	else if(cat2==expr) SQUASH(pp,1,exp_op,PLUS 1,2997); /* The expr is
the result of expanding the array argument. */
	else
		{ /* It's now of the form |@r x^expr|; insert braces around
argument so \TeX\ understands. */ 
		b_app1(pp);
		b_app(@'{'); @~ b_app1(pp+1); @~ b_app(@'}');
		REDUCE(pp,2,expr,-1,2998);
		}
}

@ Keep track of where we are in the nested hierarchy of \Fortran\ program
units; for helping with |@r9 contains|.
@<Glob...@>=

IN_PROD int fcn_level PSET(0);

@ When we recognize the beginning of a program unit, we increment a counter.
@<CASES for |program_like| (R)@>=
#if FCN_CALLS
	R_program_like();
#else
	@<Cases for |program_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_program_like(VOID)
		{
		@<Cases for |program_like| (R)@>@;
		}
#endif

@
@<Cases for |program_like| (R)@>=

if(is_FORTRAN_(language))
	{
	if(cat1==expr && cat2==semi)
		{
		fcn_level++;
		b_app1(pp); @~ b_app(@' ');
		b_app(indent); @~ b_app2(pp+1); @~ b_app(outdent);
		defined_at(make_underlined(pp+1));
		REDUCE(pp,3,fcn_hd,-1,2999);
		}
	else if(cat1==no_order)
		{ // |@r block data|
		PP_PP(1,1);
		REDUCE(pp,2,program_like,0,2997);
		}
	else if(cat1==semi)
		{ // |@r block data;|
		fcn_level++;
		b_app1(pp);
		REDUCE(pp,2,fcn_hd,-1,2996);
		}
	else if(cat1==proc_like)
		{ // |@n9 module procedure|
		PP_PP(1, 1);
		REDUCE(pp, 2, int_like, 0, 2887);
		}
	}
else
	{
	fcn_level++;
	SQUASH(pp,1,int_like,-1,2998);
	}

@
@<CASES for |fcn_hd| (R)@>=
#if FCN_CALLS
	R_fcn_hd();
#else
	@<Cases for |fcn_hd| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_fcn_hd(VOID)
		{
		@<Cases for |fcn_hd| (R)@>@;
		}
#endif

@
@<Cases for |fcn_hd| (R)@>=
{
if(cat1==END_stmt)
	{
	b_app1(pp); @~ b_app(force);
	b_app1(pp+1);
	REDUCE(pp,2,functn,-1,7172);
	}
else if(cat1==stmt && cat2==END_stmt)
	{
	b_app1(pp); @~ b_app(force);
	b_app(indent);
		b_app1(pp+1); /* Body */

		if(fcn_level==0)
			{
			if(containing) 
				b_app(big_force);

			while(containing)
				{
#if(0)
				b_app(outdent);
#endif
				containing--;
				}
			}

	b_app(outdent);
	b_app(force);

	b_app1(pp+2);
	REDUCE(pp,3,functn,-1,7171);
	}
}

@ The |@r9 module procedure| statement doesn't have an |end| statement.
@<CASES for |proc_like| (R)@>=
#if FCN_CALLS
	R_proc_like();
#else
	@<Cases for |proc_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_proc_like(VOID)
		{
		@<Cases for |proc_like| (R)@>@;
		}
#endif

@
@<Cases for |proc_like| (R)@>=

if(fcn_level == 0) {/* Error message */}
else fcn_level--;

SQUASH(pp,1,int_like,-1,2989);

@ Here we handle Fortran--90's |@r9 private|, |@r9 public|, and |@r9
sequence| statements.
@<CASES for |private_like| (R)@>=
#if FCN_CALLS
	R_private_like();
#else
	@<Cases for |private_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_private_like(VOID)
		{
		@<Cases for |private_like| (R)@>@;
		}
#endif

@
@<Cases for |private_like| (R)@>=
{
if(cat1 == (eight_bits)(language==FORTRAN_90 ? semi : colon) )
	{
	app(backup);
	b_app2(pp);
	REDUCE(pp,2,decl,-1,2988);
	}
else SQUASH(pp,1,int_like,-2,2987);
}

@ 
@<CASES for |int_like| (R)@>=
#if FCN_CALLS
	R_int_like();
#else
	@<Cases for |int_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_int_like(VOID)
		{
		@<Cases for |int_like| (R)@>@;
		}
#endif

@
@<Cases for |int_like| (R)@>=
{
if(cat1==lbrace)
	{
	b_app(indent);
	b_app1(pp);
	REDUCE(pp,1,decl_hd,0,940); /* ``|@r block data{}|'' */
	}
else if(cat1==unorbinop && cat2==expr)
	{  /* ``|@r character*(*)|'' */
	b_app1(pp);
	b_app(@'{'); @~ b_app2(pp+1); @~ b_app(@'}');
	REDUCE(pp,3,int_like,-1,941);
	}
else if (cat1==int_like || cat1==no_order) /* ``|@r double precision|'' or
		F88 things like ``|@r integer, pointer|''; |no_order| takes
		care of \&{data} in |@r block data|. */ 
	{
	PP_PP(1,1);
	REDUCE(pp,2,cat0,0,40);
	}
else if(cat1==comma) 
	SQUASH(pp,2,int_like,0,9001); /* F88: ``|@r logical,|'' */
else if(cat1==binop) 
	{ /* F88: ``|@r integer :: i|'' */
	b_app2(pp);
	b_app(indent);
	REDUCE(pp,2,decl_hd,0,9002);
	}
else if(cat1==slashes)
	{
	b_app1(pp);
	b_app(@' ');
	b_app(indent);
	REDUCE(pp,1,decl_hd,0,9002);
	}
else if(cat1==expr && **indirect((pp+1)->trans)==@'(')
	{
	b_app1(pp); @~ @<Append thinspace@>@; @~ b_app1(pp+1);
	REDUCE(pp,2,int_like,0,9003); /* ``|@r integer (KIND=4)|'' */
	}
else if (cat1==expr || cat1==semi)
	 {
	  b_app1(pp); 

	if(cat1 != semi) app(@'~'); 

	b_app(indent); /* Start long declaration. */

	 REDUCE(pp,1,decl_hd,0,41); /* JAK: -1 changed to 0 */
	}
else if(cat1 == rbrace)
	SQUASH(pp, 1, decl, -1, 411); 
		/* See \.{ratfor} example |@r9 module procedure element;|. */
}

@
@<CASES for |struct_like| (R)@>=
#if FCN_CALLS
	R_struct_like();
#else
	@<Cases for |struct_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_struct_like(VOID)
		{
		@<Cases for |struct_like| (R)@>@;
		}
#endif

@
@<Cases for |struct_like| (R)@>=
if(cat1==lpar) 
	{
	b_app1(pp);
#if(0)
	@<Append thinspace@>@; /* Looks nicer with a bit of space. */
#endif
	REDUCE(pp,1,int_like,0,9075); /* \FORTRAN-88 declaration:
``|@r9 type(triangle)|''. */
	}
else if(cat1==comma && cat2==int_like)
	{ /* ``|@r9 type, private|'' */
	b_app2(pp); @~ b_app(@' '); @~ b_app1(pp+2);
	REDUCE(pp,3,struct_like,0,90750);
	}
else if(cat1==binop && **(pp+1)->trans != (sixteen_bits)@'/') 
	SQUASH(pp,2,struct_like,0,90751); /* ``|@r9 type, public::|''  The
		|!=| precluded the VAX |@n9 structure /stuff/| declaration. */
else if(cat1==expr || cat1==slashes || cat1==struct_like)
	{ /* ``|@r9 type person|'', ``|@r9 type /vaxstruct/|'', or ``|@r9
			interface operator|'' */ 
	PP_PP(1,1);
	make_underlined(pp+1);
	REDUCE(pp,2,language==FORTRAN_90 ? struct_hd : struct_like,0,9076);
	}
else if(cat1==semi) 
	SQUASH(pp,1,struct_hd,0,9077); /* |@r9 interface| */
else if (cat1==lbrace)  /* ``|@r9 type person {integer i;};|'' */
	{
	b_app1(pp); @~ indent_force;	
	b_app1(pp+1); REDUCE(pp,2,struct_hd,0,100);
	}

@
@<CASES for |struct_hd| (R)@>=
#if FCN_CALLS
	R_str_hd();
#else
	@<Cases for |struct_hd| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_str_hd(VOID)
		{
		@<Cases for |struct_hd| (R)@>@;
		}
#endif

@
@<Cases for |struct_hd| (R)@>=
if(is_FORTRAN_(language))
 {
if(cat1==expr)
	{
	b_app1(pp); @~ @<Append thinspace@>@; b_app1(pp+1); /* ``|@r9
interface operator(.not.)|'' */
	REDUCE(pp,2,struct_hd,0,90760);
	}
else if(cat1==semi)
	{
	fcn_level++;
	b_app2(pp);
	b_app(indent);
	REDUCE(pp,2,struct_hd,0,90770);
	}
else if(cat1==decl || cat1==functn)
	{
	b_app1(pp);
	b_app(force);
	b_app1(pp+1);
	REDUCE(pp,2,struct_hd,0,9078);
	}
else if(cat1==END_stmt)
	{
	b_app1(pp);
	b_app(outdent);
	b_app(force);
	b_app1(pp+1);
	REDUCE(pp,2,decl,-1,9079);
	}
 }
else @<Cases for |struct_hd| (C)@>@;

@
@<CASES for |op_like| (R)@>=
#if FCN_CALLS
	R_op_like();
#else
	@<Cases for |op_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_op_like(VOID)
		{
		@<Cases for |op_like| (R)@>@;
		}
#endif

@
@<Cases for |op_like| (R)@>=
@B
short n;

if(cat1==lpar)
	{ /* We'll search for the obligatory right paren that terminates
the list. */
	scrap_pointer q;
	int k; /* Counter. */

/* If the paren is missing, we could end up appending the entire rest of
the code, so we limit the search. */
	for(q=pp+2; q <= scrp_ptr && q-pp < MAX_OP_TOKENS; q++)
		if(q->cat == rpar) break;

	n = (q->cat == rpar) ? PTR_DIFF(short, q, pp) : 0;

	if(n > 0)
		{
		b_app1(pp); @~ b_app(@' '); /* |@r9 operator| */
		b_app1(pp+1); /* Left paren. */
		b_app(@'{');
		APP_STR("\\optrue");

		for(k=2; k<n; k++)
			b_app1(pp+k);

		APP_STR("\\opfalse"); /* We need this here in case we
encounter an operator that \FWEAVE\ doesn't know how to overload. */
		b_app(@'}');
		b_app1(pp+k);

		REDUCE(pp,n+1,expr,-2,6667);
		}
	}
}
	
@ 
@<CASES for |decl_hd| (R)@>=
#if FCN_CALLS
	R_dcl_hd();
#else
	@<Cases for |decl_hd| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_dcl_hd(VOID)
		{
		@<Cases for |decl_hd| (R)@>@;
		}
#endif

@
@<Cases for |decl_hd| (R)@>=
if (cat1==comma)
	{ /* ``|@r integer i,j|'' */
	  b_app2(pp); b_app(@' '); REDUCE(pp,2,decl_hd,0,54);
	}
else if (cat1==expr)
	{
	make_underlined(pp+1);

	if(**(pp+2)->trans == (sixteen_bits)@'=') 
		{ // Initialization coming up.
		SQUASH(pp,1,decl_hd,PLUS 1,55);
		}
	else
		{
		SQUASH(pp,2,decl_hd,0,56); 
		}
	}
else if(cat1==slashes)
	{  /* |@r integer i/1/| */
	SQUASH(pp,2,decl_hd,0,57);
	}
@#if 0
else if(cat1==binop && cat2==expr && (cat3==comma || cat3==semi))
	{
	PP_PP(1,2);
	REDUCE(pp,3,decl_hd,-1,5660); /* Initialization */
	}
@#endif
else if (cat1==lbrace || cat1==int_like || cat1==implicit_like) 
	/* |@r subroutine f {}| or |@r function f(x) real x;| or |@r
program main implicit none;|  */
	{
	b_app1(pp);
	b_app(outdent); /* Turn off |indent|. */
	defined_at(FIRST_ID(pp));
	REDUCE(pp,1,fn_decl,0,58);
	}
else if (cat1==semi && (!auto_semi || (auto_semi && cat2 != lbrace))) 
	{
	b_app2(pp);
	b_app(outdent); /* Finish long declaration. */
	REDUCE(pp,2,
  	  (eight_bits)(intermingle ? (intermingle=NO,ignore_scrap) : decl),
		-1,59); 
	}
else if(cat1==built_in)
	{ /* |@r9 use a, only| */
	PP_PP(1,1);
	REDUCE(pp,2,decl_hd,0,5901);
	}
#if(0)
else if(cat1==lpar && cat2==expr) make_underlined(pp+2); /* For
						|$decl_hd|. */
#endif

@ 
@<CASES for |decl| (R)@>=
#if FCN_CALLS
	R_decl();
#else
	@<Cases for |decl| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_decl(VOID)
		{
		@<Cases for |decl| (R)@>@;
		}
#endif

@
@<Cases for |decl| (R)@>=
if(is_FORTRAN_(language) && cat1==END_like) SQUASH(pp,1,stmt,-1,960); 
		/* `` |@r program main; end;|'' */
else if (cat1==decl) 
	{
	  b_app1(pp); @~ b_app(force); 
	b_app1(pp+1);
	  REDUCE(pp,2,decl,-1,60);
	}
else if (cat1==stmt || cat1==functn) 
	{
	  b_app1(pp); @~ b_app(big_force); 
	  b_app1(pp+1); REDUCE(pp,2,cat1,-1,61);
	}

@ |@r subroutine f1{} subroutine f2{}|.
@<CASES for |functn| (R)@>=
#if FCN_CALLS
	R_functn();
#else
	@<Cases for |functn| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_functn(VOID)
		{
		@<Cases for |functn| (R)@>@;
		}
#endif

@
@<Cases for |functn| (R)@>=

if (cat1==functn || (is_RATFOR_(language) && (cat1==decl || cat1==stmt)))
	 {
	b_app1(pp); @~ b_app(big_force); 
	b_app1(pp+1); REDUCE(pp,2,cat1,0,80);
	}
else if(free_Fortran && cat1==semi)
	{ /* Handle possible auto-inserted pseudo-semi after function. */
	b_app2(pp);
	REDUCE(pp, 2, functn, 0, 8088);
	}
#if(0)
else if(cat1==END_like) 
	{
	b_app1(pp);
	REDUCE(pp,1,stmt,-1,9050);
	}
#endif

@ 
@<CASES for |lpar| (R)@>=
#if FCN_CALLS
	R_lpar();
#else
	@<Cases for |lpar| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_lpar(VOID)
		{
		@<Cases for |lpar| (R)@>@;
		}
#endif

@
@<Cases for |lpar| (R)@>=

if (cat1==expr && cat2==rpar) 
	SQUASH(pp,3,expr,-2,120); /* ``|@r (x)|'' */
else if(cat1==expr && cat2==colon && cat3==rpar) /* ``|@r (lower:)|'' */
	{
	b_app3(pp); @~ @<Append thinspace@>; @~ b_app1(pp+3);
	REDUCE(pp,4,expr,-2,9120);
	}
else if(cat1==colon && cat2 != comma) /* ``|@r (:x)|''; watch out for
			deferred-shape-spec-lists.  */
	{
	b_app1(pp); @~ @<Append thinspace@>; @~ b_app1(pp+1);
	REDUCE(pp,2,lpar,0,9121);
	}
else if (cat1==rpar) /* ``|@r ()|'' */
	{
	  b_app1(pp); @~ @<Append thinspace@>; @~ b_app1(pp+1);
	  REDUCE(pp,2,expr,-2,121);
	}
else if (cat1==stmt) /* `` |@r for(x;y;z)|'' */
	{
	  b_app2(pp); b_app(@' '); REDUCE(pp,2,lpar,0,123);
	}

@ 
@<CASES for |colon| (R)@>=
#if FCN_CALLS
	R_colon();
#else
	@<Cases for |colon| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_colon(VOID)
		{
		@<Cases for |colon| (R)@>@;
		}
#endif

@
@<Cases for |colon| (R)@>=

if(cat1==expr || cat1==unorbinop) 
	SQUASH(pp,2,expr,-2,9500); /* ``|@r (:upper)|'' */
else if(cat1==comma && cat2==colon) 
	SQUASH(pp,3,colon,-2,9502);
	/* Deferred-shape-spec-list: |@n9 (:,:,:)|.
		|colon| used to be |expr| */
else 
	SQUASH(pp,1,expr,0,9501); /* |@r (:)| */

@ 
@<CASES for |lbrace| (R)@>=
#if FCN_CALLS
	R_lbrace();
#else
	@<Cases for |lbrace| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_lbrace(VOID)
		{
		@<Cases for |lbrace| (R)@>@;
		}
#endif

@
@<Cases for |lbrace| (R)@>=
if (cat1==rbrace) /* ``|@r {}|'' */
	{
	  b_app1(pp); @~ @<Append thinspace@>; @~ b_app1(pp+1); 
	  REDUCE(pp,2,stmt,-2,130);
	}
else if ((cat1==stmt || cat1==decl) && cat2==rbrace)  /* ``|@r {x;}|'' */
	{
	  b_app(force);
	  b_app1(pp);  @~  b_app(force);
	  b_app1(pp+1); @~ b_app(force); 
	  b_app1(pp+2); 
	   REDUCE(pp,3,stmt,-2,131);
	}

@ 
@<CASES for |unop| (R)@>=
#if FCN_CALLS
	R_unop();
#else
	@<Cases for |unop| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_unop(VOID)
		{
		@<Cases for |unop| (R)@>@;
		}
#endif

@
@<Cases for |unop| (R)@>=

if (cat1==expr) SQUASH(pp,2,expr,-2,33); /* ``|@r !flag|'' */

@ 
@<CASES for |unorbinop| (R)@>=
#if FCN_CALLS
	R_unorbinop();
#else
	@<Cases for |unorbinop| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_unorbinop(VOID)
		{
		@<Cases for |unorbinop| (R)@>@;
		}
#endif

@
@<Cases for |unorbinop| (R)@>=

if (cat1==expr) /* ``|@r +1.0|'' */
	{
	  b_app(@'{'); @~ b_app1(pp); @~ b_app(@'}'); 
	b_app1(pp+1); 
	REDUCE(pp,2,expr,-2,140);
	}
else if(cat1==binop) 
	@<Reduce cases like |*=|@>@;
else if (cat1== comma || cat1==rpar) 
	SQUASH(pp,1,expr,-2,141); /* ``|@r *,|'' or ``|@r *)|'' */

@ 
@<Append thinspace@>=
{
b_app(@'\\'); @~ b_app(@',');
}

@ 
@<Append thickspace@>=
{
b_app(@'\\'); @~ b_app(@';');
}

@
@<CASES for |slash_like| (R)@>=
#if FCN_CALLS
	R_slash_like();
#else
	@<Cases for |slash_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_slash_like(VOID)
		{
		@<Cases for |slash_like| (R)@>@;
		}
#endif

@
@<Cases for |slash_like| (R)@>=
if(cat1==slash_like)
	{ // The slash already has braces around it (appended by \FWEAVE).ac
	b_app1(pp);
	@<Append thinspace@>;
	b_app1(pp+1);
	REDUCE(pp,2,slashes,-1,1801);
	}
else if(cat1==expr && cat2==slash_like)
	SQUASH(pp,3,slashes,-1,1802);

@ 
@<CASES for |binop| (R)@>=
#if FCN_CALLS
	R_binop();
#else
	@<Cases for |binop| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_binop(VOID)
		{
		@<Cases for |binop| (R)@>@;
		}
#endif

@
@<Cases for |binop| (R)@>=
{
sixteen_bits tok = **pp->trans;

if(cat1==binop) 
	{ /* ``|@r / /|'' */
	if(tok == (sixteen_bits)@'/')
		{
		if(**(pp+1)->trans == tok)
			@<Append empty slashes@>@;
		else
			{
			APP_STR("\\WSl");
			REDUCE(pp, 1, binop, -1, 1803);
			}
		}
	else 
		@<Reduce cases like |+=|@>@;
	}
else 
	{
	if(tok == (sixteen_bits)@'/')
		{
		if(cat1==expr && cat2==binop && **(pp+2)->trans == tok)
				@<Append full slashes@>@; // |@n common/dia/|
		else
			{
			APP_STR("\\WSl");
			REDUCE(pp, 1, binop, -1, 1804);
			}
		}
	}
}

@
@<Append empty slashes@>=
{
b_app(@'{');
b_app1(pp); @~ @<Append thinspace@>; @~ b_app1(pp+1);
b_app(@'}');
REDUCE(pp,2,slashes,-1,180);
}

@
@<Append full slashes@>=
{
#if 0
b_app(@'{');
b_app1(pp);	/* |'/'| */
b_app(@'}');
#endif

make_underlined(pp+1);	/* Index common block name. */
APP_STR("\\WCMN");
b_app1(pp+1); /* expr/common-block name */

#if 0
b_app(@'{');	
b_app1(pp+2); /* |'/'| */
b_app(@'}');
#endif

REDUCE(pp,3,slashes,-1,9181);
}

@ 
@<Glob...@>=

IN_PROD text_pointer label_text_ptr[50];

@ Follow translations until one gets down to the actual tokens.

@<Part 2@>=@[

text_pointer 
indirect FCN((t))
	text_pointer t C1("")@;
{
Token tok_value;

if(t==NULL) return t;

tok_value = **t;

if(tok_value <= tok_flag) return t;

if(tok_value > inner_tok_flag) tok_value -= (inner_tok_flag - tok_flag);

if(tok_value > tok_flag)
	do
		{
		Token tok_value0 = tok_value;

		t = tok_start + (int)(tok_value - tok_flag);
		tok_value = **t;

		if(tok_value == tok_value0) return t; /* Emergency return;
otherwise infinite loop. */
		}
	while(tok_value > tok_flag);

return t;
}

@ The following compares the texts of two translations, and is needed for
labeled loops in Fortran.
@<Part 2@>=@[
boolean 
compare_text FCN((t0,t1))
	text_pointer t0 C0("")@;
	text_pointer t1 C1("")@;
{
token_pointer p0,p0_end,p1;

if(t0==NULL || t1==NULL) return NO;

t0 = indirect(t0); t1 = indirect(t1);

p0 = *t0; @~ p0_end = *(t0+1);
p1 = *t1;

while(p0 < p0_end)
	{
	if(*p0 == @':') return YES; /* Ends label */
	if(*p0++ != *p1++) return NO;
	}

return YES;
}

@ Return the value of a token that may be buried deep in indirection chains.
@<Part 2@>=@[
sixteen_bits 
tok_val FCN((p))
	scrap_pointer p C1("")@;
{
sixteen_bits tok_value;

tok_value = **(p->trans);

if(tok_value > inner_tok_flag)
	tok_value -= (inner_tok_flag- tok_flag);

if(tok_value > tok_flag)
	do
		{
		tok_value = **(tok_start + (int)(tok_value - tok_flag)); 
		}
	while(tok_value > tok_flag);

return tok_value;
}

@ 
@<CASES for |Rdo_like| (R)@>=
#if FCN_CALLS
	R_Rdo_like();
#else
	@<Cases for |Rdo_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_Rdo_like(VOID)
		{
		@<Cases for |Rdo_like| (R)@>@;
		}
#endif

@
@<Cases for |Rdo_like| (R)@>=

if(is_FORTRAN_(language))
  {
  if(cat1==for_like)  /* \&{do} \&{while} */
	{
	PP_PP(1,1);
	REDUCE(pp,2,Rdo_like,0,9600);
	}
  else if(cat1==expr && ( (cat2==expr && cat3==binop) || cat2==if_like) )
	{ /* ``|@r do 10 i=@e|'' */
	label_text_ptr[indent_level] = (pp+1)->trans; /* Pointer to
			a |token_pointer|---namely, index into |tok_start|. */
	b_app1(pp); // |@n do|
	b_app(@' ');
	b_app1(pp+1);	 // Loop number.
	REDUCE(pp,2,Rdo_like,0,9601); /* Swallow only the loop number. */
	}
  else if(cat1==stmt) /* ``|@r do i=1,10;|'' */
	{
	loop_num[indent_level++] = ++max_loop_num;

	b_app1(pp); /* \&{do} */
	b_app(@' ');
	b_app1(pp+1); /* $i=1,10;$ */
	app_loop_num(max_loop_num);

	b_app(indent);
	REDUCE(pp,2,stmt,-2,9602);
	}
  }
/* \Ratfor. */
else if(cat1==stmt || (cat1==expr && cat2==lbrace)) /* ``|@r do i=1,10;|''
or ``|@r do i=1,10{|'' */
	{
	PP_PP(1,1);
	REDUCE(pp,2,for_hd,0,9603);
	}

@ The following flag handles the option |@r until| in a ``|@r
repeat{}until|'' construction.

@<Glob...@>=

IN_PROD boolean found_until PSET(NO);

@ We have to be slightly tricky here, because in ``|@r repeat{}until|'' the
\&{until} is optional. 
@<CASES for |do_like| (R)@>=
#if FCN_CALLS
	R_do_like();
#else
	@<Cases for |do_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_do_like(VOID)
		{
		@<Cases for |do_like| (R)@>@;
		}
#endif

@
@<Cases for |do_like| (R)@>=

if(cat1==stmt)
	{
	if(cat2==until_like) 
		{
		found_until = YES;
		SQUASH(pp,1,do_like,PLUS 2,9190); /* ``|@r repeat
{} until @e@;|''; expand the \&{until}. */
		}
	else 
		{
		  b_app1(pp); 
		  indent_force;
		   b_app1(pp+1);
		  b_app(outdent);
		  b_app(force);

		if(found_until && cat2==stmt) /* Get here by expanding the
\&{until}. */ 
			{ 
			found_until = NO;
			b_app1(pp+2); REDUCE(pp,3,stmt,-2,9191);
			}
		else REDUCE(pp,2,stmt,-2,9192); /* ``|@r repeat {}|'';
no bottom. */
		}
	}

@ Get here from above by expanding the |@r until|.
@<CASES for |until_like| (R)@>=
#if FCN_CALLS
	R_until_like();
#else
	@<Cases for |until_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_until_like(VOID)
		{
		@<Cases for |until_like| (R)@>@;
		}
#endif

@
@<Cases for |until_like| (R)@>=

SQUASH(pp,1,for_like,0,9195);

@ 
@<Glob...@>=

IN_PROD int indent_level PSET(0); // Indent level.
IN_PROD int loop_num[50], max_loop_num PSET(0);

@ 
@<CASES for |if_like| (R)@>=
#if FCN_CALLS
	R_if_like();
#else
	@<Cases for |if_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_if_like(VOID)
		{
		@<Cases for |if_like| (R)@>@;
		}
#endif

@
@<Cases for |if_like| (R)@>=

if(cat1==CASE_like)
	{
	PP_PP(1,1);	/* |@r9 select case| */
	REDUCE(pp,2,if_like,0,9196);
	}
else
if(is_FORTRAN_(language))
  {
 if(cat1==expr)
  {
  boolean if_form;

  if( (if_form=BOOLEAN(cat2==built_in && cat3==semi)) || cat2==semi) 
	{ /* ``|@n if(x) then;|''  or ``|@n where(x); |'' */ 
	short n; /* Number to append. Things are annoying because the |@n if|
and |@n where| statements aren't completely symmetrical. */

	loop_num[indent_level++] = ++max_loop_num;

	b_app1(pp);	/* \&{if} */
	@<Append thinspace@>;
	b_app1(pp+1); /* $(x)$ */
	b_app(@' ');
	
	if(if_form)
		{
		n = 4;
		b_app2(pp+2); /* \&{then}; */
		}
	else
		{ /* |@n where| */
		n = 3;
		b_app1(pp+2); /* semi */
		}

	app_loop_num(max_loop_num);
	b_app(indent);
	REDUCE(pp,n,stmt,-2,9800);
	}
  else if(cat2==stmt) /* ``|@n if(x) a=b;|'' */
	{
	b_app1(pp); /* \&{if} */
	@<Append thinspace@>;
	b_app1(pp+1); /* $(x)$ */
	app(@' ');
	b_app(cancel);
	b_app1(pp+2); /* Statement */
	REDUCE(pp,3,stmt,-2,9801);
	}
  else 
	{
	b_app1(pp);
	@<Append thinspace@>;
	b_app1(pp+1);
	REDUCE(pp,2,if_hd,0,9802);
	}
  }
 }
/* RATFOR\ */
else @<Cases for |if_like| (C)@>@;


@ Attach a comment with the loop number.

@<Part 2@>=@[

SRTN 
app_loop_num FCN((n))
	int n C1("Loop number.")@;
{
char loop_id[100];

if(!block_nums) return; // We're not supposed to number the blocks/loops.

sprintf(loop_id,"\\Wblock{%d}",n); /* Output the block number. */
@.\\Wc@>
APP_STR(loop_id);
}

@ For the |@r go| keyword, we just have to handle optional white space.
@<CASES for |go_like| (R)@>=
#if FCN_CALLS
	R_go_like();
#else
	@<Cases for |go_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_go_like(VOID)
		{
		@<Cases for |go_like| (R)@>@;
		}
#endif

@
@<Cases for |go_like| (R)@>=

if(cat1==built_in) /* ``|@r go to|'' */
	{
	b_app1(pp); /* \&{go} */
	b_app(@' ');
	b_app1(pp+1); /* \&{to} */
	REDUCE(pp,2,case_like,0,9850); /* \&{goto} */
	}
else SQUASH(pp,1,expr,-2,9851);

@ The keyword |@r end| has two possible meanings: end a loop, or end a
function. 
@<CASES for |end_like| (R)@>=
#if FCN_CALLS
	R_end_like();
#else
	@<Cases for |end_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_end_like(VOID)
		{
		@<Cases for |end_like| (R)@>@;
		}
#endif

@
@<Cases for |end_like| (R)@>=
if(cat1==Rdo_like || cat1==if_like) /* ``|@r end do|'' or ``|@r end if|'' */
	{
	b_app1(pp); /* \&{end} */
	b_app(@' ');
	b_app1(pp+1); /* \&{do} or \&{if} */
	REDUCE(pp,2,endif_like,0,9860); /* Now turned into \&{enddo} or
\&{endif} */ 
	}
else 
	{
	fcn_level--;
	SQUASH(pp,1,END_like,-1,9861); /* \&{end} of function. */
	}

@  \Fortran-90??

@<CASES for |END_like| (R)@>=
#if FCN_CALLS
	R_END();
#else
	@<Cases for |END_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_END(VOID)
		{
		@<Cases for |END_like| (R)@>@;
		}
#endif

@
@<Cases for |END_like| (R)@>=
{
if(cat1==program_like || cat1==struct_like)
	{
	PP_PP(1,1);
	
	if(cat2==expr)
		{
		b_app(@' '); @~ b_app1(pp+2);
		REDUCE(pp,3,END_like,0,9860);
		}
	else 
		REDUCE(pp,2,END_like,0,9861);
	}
else if(cat1==semi) 
	SQUASH(pp,2,END_stmt,-2,9862);
}

@ Handle end of loop. Note that in \Fortran-90, the \It{if-construct-name}
is optional.

@<CASES for |endif_like| (R)@>=
#if FCN_CALLS
	R_endif_like();
#else
	@<Cases for |endif_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_endif_like(VOID)
		{
		@<Cases for |endif_like| (R)@>@;
		}
#endif

@
@<Cases for |endif_like| (R)@>=
{
short n;
boolean no_construct_name;

if((no_construct_name=BOOLEAN(cat1==semi)) || (cat1==expr && cat2==semi) )
	{
	b_app(outdent);
	b_app(force);

	if(no_construct_name)
		{
		n = 2;
		b_app2(pp); /* \&{endif}; or \&{enddo}; */
		}
	else
		{ /* Include \It{if-construct-name} */
		n = 3;
		PP_PP(1,2);
		}

	if(--indent_level < 0)
		indent_level = 0;

	app_loop_num(loop_num[indent_level]);
	REDUCE(pp,n,stmt,-2,9880);
	}
}

@ 
@<CASES for |if_hd| (R)@>=
#if FCN_CALLS
	R_if_hd();
#else
	@<Cases for |if_hd| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_if_hd(VOID)
		{
		@<Cases for |if_hd| (R)@>@;
		}
#endif

@
@<Cases for |if_hd| (R)@>=

if(is_FORTRAN_(language))
	{
	if (cat1==stmt) 
		{
#if 0
		b_app1(pp); @~ b_app(break_space); @~ b_app1(pp+1);
#endif
		b_app1(pp);
		indent_force;
		 b_app1(pp+1);
		b_app(outdent);
		REDUCE(pp,2,stmt,-2,9900);
		}
	}
else 
	@<Cases for |if_hd| (C)@>@;

@ 
@<CASES for |else_like| (R)@>=
#if FCN_CALLS
	R_else_like();
#else
	@<Cases for |else_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_else_like(VOID)
		{
		@<Cases for |else_like| (R)@>@;
		}
#endif

@
@<Cases for |else_like| (R)@>=

if(is_FORTRAN_(language))
   {
   if(cat1==if_like) /* ``|@n else if|'' */
	{
	b_app1(pp); /* \&{else} */
	b_app(@' ');
	b_app1(pp+1); /* \&{if} */
	REDUCE(pp,2,else_like,0,9910); /* \&{elseif} */
	}
   else if(cat1==semi) /* \&{else}; */
	{
	b_app(outdent);
	b_app(force);
	b_app2(pp); /* \&{else} or \&{elseif} */
	app_loop_num(loop_num[indent_level-1]);
	b_app(indent);
	REDUCE(pp,2,stmt,-2,9911);
	}
   else if(cat1==expr && cat2==built_in && cat3==semi)  /* ``|@n else if(x)
then;|'' */
	{
	b_app(outdent);
	b_app(force);

	b_app1(pp);	/* \&{elseif} */
	@<Append thinspace@>;
	b_app1(pp+1); /* $(x)$ */
	b_app(@' ');
	b_app2(pp+2); /* \&{then}; */
	app_loop_num(loop_num[indent_level-1]);

	b_app(indent);
	REDUCE(pp,4,stmt,-2,9912);
	}
  }
/* \Ratfor\ */
else @<Cases for |else_like| (C)@>@;

@ 
@<CASES for |stmt| (R)@>=
#if FCN_CALLS
	R_stmt();
#else
	@<Cases for |stmt| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_stmt(VOID)
		{
		@<Cases for |stmt| (R)@>@;
		}
#endif

@
@<Cases for |stmt| (R)@>=

@#if 0
if(is_FORTRAN_(language) && cat1==program_like) 
	SQUASH(pp, 1, functn, PLUS 1, 9960); 
else 
if(is_FORTRAN_(language) && (cat1==END_like && cat2==semi) ) /* Finally
recognized a function. */
	SQUASH(pp,1,stmt,-1,99661);
		{
#if(0)
		b_app(indent); /* The function body will be indented. */
		b_app(backup); /* But not the first line of function. */
#endif
		b_app1(pp); /* The body. */

		if(fcn_level==0)
			{
			if(containing) b_app(big_force);
			while(containing)
				{
#if(0)
				b_app(outdent);
#endif
				containing--;
				}
			}

/* The \&{end} statement. */
		b_app(force);	
		b_app(outdent);
		b_app2(pp+1);

		REDUCE(pp,3,functn,-1,9961);
		}
else 
@#endif
if(cat1==stmt || (free_Fortran && cat1==decl)) 
	{
	b_app1(pp); 
	b_app(break_space);
	b_app(force);
	b_app1(pp+1); 
	REDUCE(pp,2,stmt,-2,2501);
	}
else if (cat1==functn)
	{
	b_app1(pp); @~ b_app(big_force);
	b_app1(pp+1);
	REDUCE(pp,2,stmt,-2,2511);
	}

@
@<CASES for |CASE_like| (R)@>=
#if FCN_CALLS
	R_CASE();
#else
	@<Cases for |CASE_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_CASE(VOID)
		{
		@<Cases for |CASE_like| (R)@>@;
		}
#endif

@
@<Cases for |CASE_like| (R)@>=

if(is_FORTRAN_(language))
	{
	b_app(backup);
	b_app1(pp);
	REDUCE(pp,1,case_like,0,9258);
	}
else SQUASH(pp,1,case_like,0,9259);

@ 
@<CASES for |case_like| (R)@>=
#if FCN_CALLS
	R_case_like();
#else
	@<Cases for |case_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_case_like(VOID)
		{
		@<Cases for |case_like| (R)@>@;
		}
#endif

@
@<Cases for |case_like| (R)@>=
if(cat1==read_like) /* ``|@r call open|'' */
	{
	b_app1(pp);	/* \&{call} */
	b_app(@' ');
	b_app1(pp+1); /* \&{close}, \&{open}, etc. */
	REDUCE(pp,2,case_like,0,9260);
	}
else if (cat1==semi) SQUASH(pp,2,stmt,-2,260); /* ``|@r return;|'' */
else if (cat1==colon) @<Append an ordinary colon@>@;
else if (cat1==expr && cat2==semi)
	{ /* ``|@r return 1;|'' */
	PP_PP(1,2);
	REDUCE(pp,3,stmt,-2,262);
	}
else if ((cat1==expr || cat1==label) && cat2==colon)
	{ /* ``|@r case 1:|'' */
	PP_PP(1,1);
	APP_STR("\\Colon\\ ");
	REDUCE(pp,3,tag,-1,263);
	}

@
@<Append an ordinary colon@>=
{
b_app1(pp); @~ APP_STR("\\Colon\\ ");
REDUCE(pp,2,tag,-1,261);
}

@ 
@<CASES for |tag| (R)@>=
#if FCN_CALLS
	R_tag();
#else
	@<Cases for |tag| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_tag(VOID)
		{
		@<Cases for |tag| (R)@>@;
		}
#endif

@
@<Cases for |tag| (R)@>=

if (cat1==tag) /* ``|@r case 1: case 2:|'' */
	{
  b_app1(pp); @~  b_app(force);
  b_app(backup);
   b_app1(pp+1); REDUCE(pp,2,tag,-1,270);
	}
else if (cat1==stmt || cat1==END_like) /* ``|@r 10 continue;|'' */
	{
	boolean end_of_loop;

	end_of_loop = NO;

/* Unwind indent levels for labeled loops. */
	while(indent_level > 0 && 
           compare_text(pp->trans,label_text_ptr[indent_level-1]) )
		{
		--indent_level;
		b_app(outdent);
		end_of_loop = YES;
		}

	if(is_FORTRAN_(language) && Fortran_label) 
		{ /* ``|@n EXIT: continue@;|'' */
		b_app(force);
		APP_STR("\\Wlbl{"); @~	b_app1(pp); @~ app(@'}'); 
@.\\Wlbl@>
		}
	else
		{ /* Label on separate line. */
		b_app(big_force);
		b_app(backup);
		b_app1(pp); 	/* Tag (Includes colon.) */
		b_app(force);
		}

	b_app1(pp+1); /* Stmt. */

	if(end_of_loop) 
		app_loop_num(loop_num[indent_level]);

	REDUCE(pp,2,cat1,-2,271);
}


@ 
@<CASES for |label| (R)@>=
#if FCN_CALLS
	R_label();
#else
	@<Cases for |label| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_label(VOID)
		{
		@<Cases for |label| (R)@>@;
		}
#endif

@
@<Cases for |label| (R)@>=
if(cat1==colon)
	{
	b_app1(pp);
	REDUCE(pp,2,label,0,9270); /* Swallow the colon. (Numerical
statement labels won't have any.) Then, for all labels, we put a colon in
during the next block. */
	}
else if(cat1==stmt || cat1==END_like)
	{
	b_app1(pp); @~ APP_STR("\\Colon\\ ");

	if(is_FORTRAN_(language) && Fortran_label) 
		b_app(cancel);

	REDUCE(pp,1,tag,0,9271); /* Convert the label into a tag. Don't
					swallow the statement. */
	}

@ 
@<CASES for |semi| (R)@>=
#if FCN_CALLS
	R_semi();
#else
	@<Cases for |semi| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_semi(VOID)
		{
		@<Cases for |semi| (R)@>@;
		}
#endif

@
@<Cases for |semi| (R)@>=
if(is_RATFOR_(language) && auto_semi)
	{ /* Just throw away semi. */
	text_pointer t;

	t = indirect(pp->trans);

	if(**t == @';') **t = 0;
	SQUASH(pp,1,ignore_scrap,-1,9280);
	}
else
	{
	b_app(@' '); b_app1(pp); REDUCE(pp,1,stmt,-2,280);
	}

@ 
@<CASES for |common_like| (R)@>=
#if FCN_CALLS
	R_common_like();
#else
	@<Cases for |common_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_common_like(VOID)
		{
		@<Cases for |common_like| (R)@>@;
		}
#endif

@
@<Glob...@>=

@
@<Cases for |common_like| (R)@>=
if(cat1==expr || cat1==slashes || cat1==semi) 
	{ /* ``|@r common x| or |@r common/dia/|'' */
#if 0
	b_app1(pp);
#if 0
	if(cat1 != semi) 
		b_app(@' ');
#endif
	b_app(indent);
	REDUCE(pp,1,common_hd,0,9950);
#endif
	SQUASH(pp, 1, common_hd, 0, 9950);
	}

@ 
@<CASES for |common_hd| (R)@>=
#if FCN_CALLS
	R_cmn_hd();
#else
	@<Cases for |common_hd| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_cmn_hd(VOID)
		{
		@<Cases for |common_hd| (R)@>@;
		}
#endif

@
@<Cases for |common_hd| (R)@>=

#if 0
if(cat1== expr) 
	SQUASH(pp,2,common_hd,0,9951); /* ``|@r common x|'' */
else if(cat1==slashes) /* ``|@r common/dia/|'' */
	{
	b_app1(pp);
	b_app(@' ');
	b_app1(pp+1);
	b_app(@' ');
	REDUCE(pp,2,common_hd,0,9952);
	}
else if(cat1==comma) /* ``|@r common x,y|'' */
	{
	b_app2(pp);
	b_app(@' ');
	REDUCE(pp,2,common_hd,0,9953);
	}

if(cat1 == expr) 
	{
	b_app1(pp);
	OPT9;
	b_app1(pp+1);
	REDUCE(pp,2,common_hd,0,9951); /* ``|@r common x|'' */
	}
else if(cat1==slashes)
	{ /* ``|@r common/dia/|'' */
	SQUASH(pp,2,common_hd,0,9952);
	}
else if(cat1==comma) /* ``|@r common x,y|'' */
	{
	SQUASH(pp,2,common_hd,0,9953);
	}
else if(cat1==semi) 
	{
	b_app2(pp);
	b_app(outdent);
	REDUCE(pp,2,decl,-1,9954); /* ``|@r common x;|'' */
	}
#endif
if(cat1 == slashes)
	SQUASH(pp, 2, int_like, 0, 9952); // `` |@4 common/dia/|''
else
	SQUASH(pp, 1, int_like, 0, 9951); // ``|@r common x|''

@ 
@<CASES for |read_like| (R)@>=
#if FCN_CALLS
	R_read_like();
#else
	@<Cases for |read_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_read_like(VOID)
		{
		@<Cases for |read_like| (R)@>@;
		}
#endif

@
@<Cases for |read_like| (R)@>=

if(cat1==lpar && cat2==expr && cat3==rpar) /* |@r read(6,100)| */
	{
	b_app1(pp);
	@<Append thinspace@>;
	b_app3(pp+1);
	b_app(@' ');
	REDUCE(pp,4,read_hd,0,9960);
	}
else if(cat1==expr && cat2==comma) /* ``|@r TYPE 100, i@;|'' */
	{
	b_app1(pp);
	b_app(@' ');
	b_app2(pp+1);
	b_app(@' ');
	REDUCE(pp,3,read_hd,0,9961);
	}
else if(cat1==expr || cat1==unorbinop) /* ``|@r TYPE *|'' */
	{
	PP_PP(1,1);

	if(cat2==expr) b_app(@' '); /* Takes care of |"TYPE 100 i"|. */

	REDUCE(pp,2,read_hd,0,9962);
	}
else if(cat1==semi) SQUASH(pp,1,read_hd,0,9963);


@ 
@<CASES for |read_hd| (R)@>=
#if FCN_CALLS
	R_rd_hd();
#else
	@<Cases for |read_hd| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_rd_hd(VOID)
		{
		@<Cases for |read_hd| (R)@>@;
		}
#endif

@
@<Cases for |read_hd| (R)@>=
if(cat1==comma)  /* ``|@r read(6,100),|'' */
	{
	b_app2(pp);
	b_app(@' ');
	REDUCE(pp,2,read_hd,0,9965);
	}
else if(cat1==expr)
	{
	if(cat2==comma || cat2==semi)
		SQUASH(pp,2,read_hd,0,9966); /* ``|@r write(6,100) i,j@;|'' */
	}
else if(cat1==semi && cat2==read_like) /* Two I/O statements back-to-back. */
	{
	b_app1(pp);
@#if 0
	b_app(big_cancel);
@#endif
	b_app1(pp+1);
	b_app(force);
	b_app1(pp+2);
	REDUCE(pp,3,read_like,0,9967);
	}
else if(cat1==semi)
	{
	b_app1(pp);
@#if 0
	b_app(big_cancel); /* Supposed to kill off preceding blanks. */
@#endif
	b_app1(pp+1);
	REDUCE(pp,2,stmt,-2,9968);
	}

@ 

@f implicit_none implicit

@<CASES for |implicit_like| (R)@>=
#if FCN_CALLS
	R_implicit_like();
#else
	@<Cases for |implicit_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_implicit_like(VOID)
		{
		@<Cases for |implicit_like| (R)@>@;
		}
#endif

@
@<Cases for |implicit_like| (R)@>=
if(cat1==int_like || cat1==expr) /* ``|@r implicit integer|'' or 
					``|@r implicit none|'' */
	{
	b_app1(pp);
	b_app(@' ');
	b_app(indent); /* Start possible long declaration. */
	REDUCE(pp,1,implicit_hd,0,9970);
	}
else if(cat1==semi)
	{ /* ``|@r implicit_none;|''. */
	b_app1(pp);
	b_app(indent);
	REDUCE(pp,1,implicit_hd,0,99700);
	}

@ 
@<CASES for |implicit_hd| (R)@>=
#if FCN_CALLS
	R_imp_hd();
#else
	@<Cases for |implicit_hd| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_imp_hd(VOID)
		{
		@<Cases for |implicit_hd| (R)@>@;
		}
#endif

@
@<Cases for |implicit_hd| (R)@>=
if(cat1==unorbinop && cat2==expr) 
	{ /* ``|@r implicit real*8|'' */
	b_app1(pp);
	b_app(@'{'); @~ b_app2(pp+1); @~ b_app(@'}');
	@<Append thinspace@>;
	REDUCE(pp,3,implicit_hd,0,9971);
	}
else if(cat1==expr) SQUASH(pp,2,implicit_hd,0,9972); /* ``|@r implicit
	integer(a-h)|'' */
else if(cat1==comma || cat1==int_like)
	{
	b_app2(pp);

	if(cat2 != unorbinop)
		if(cat2==int_like) b_app(@' '); /* ``|@r implicit real x,
integer i|'' */
		else @<Append thinspace@>;

	REDUCE(pp,2,implicit_hd,0,9973);
	}
else if(cat1==semi) SQUASH(pp,1,decl_hd,0,9974); /* ``|@r implicit
	integer(a-h);|'' */
	
@ 
@<CASES for |assign_like| (R)@>=
#if FCN_CALLS
	R_assign_like();
#else
	@<Cases for |assign_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_assign_like(VOID)
		{
		@<Cases for |assign_like| (R)@>@;
		}
#endif

@
@<Cases for |assign_like| (R)@>=
if(cat1==expr && cat2==built_in && cat3==expr) /* ``|@r assign 100 to k|'' */
	{
	b_app1(pp);
	b_app(@' ');
	b_app1(pp+1);
	b_app(@' ');
	b_app1(pp+2);
	b_app(@' ');
	b_app1(pp+3);
	REDUCE(pp,4,expr,0,9980);
	}

@ The following flag is used  in \FORTRAN-90 to determine whether a |@r9
contains| is in force, and what level in the block structure we're in.

@<Glob...@>=

IN_PROD int containing PSET(0);

@ 
@<CASES for |entry_like| (R)@>=
#if FCN_CALLS
	R_entry_like();
#else
	@<Cases for |entry_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_entry_like(VOID)
		{
		@<Cases for |entry_like| (R)@>@;
		}
#endif

@
@<Cases for |entry_like| (R)@>=
if(cat1==expr && cat2==semi) /* ``|@r entry E(x);|'' */
	{
	b_app(big_force);
	b_app(backup); @~ PP_PP(1,2); @~ b_app(force);
	REDUCE(pp,3,stmt,-2,9990);
	}
else if(cat1== (eight_bits)(language==FORTRAN_90 ? semi : colon)) 
	{ /* ``|@r9 contains:|'' */
	b_app(big_force);
	b_app(backup); @~ b_app2(pp); @~ b_app(force);

	containing++; 
#if(0)
	b_app(indent);
#endif
	REDUCE(pp,2,stmt,-2,9991);
	}

@ 
@<CASES for |define_like| (R)@>=
#if FCN_CALLS
	R_define_like();
#else
	@<Cases for |define_like| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_define_like(VOID)
		{
		@<Cases for |define_like| (R)@>@;
		}
#endif

@
@<Cases for |define_like| (R)@>=
if(cat1==expr)
	{
	b_app(force);
	b_app(backup); @~ b_app2(pp); @~ b_app(force);
	REDUCE(pp,2,ignore_scrap,-1,9995);
	}

@ \&{data} statements can be intermixed with everything. (VAX). For such
statements, we raise a flag.

@<CASES for |no_order| (R)@>=
#if FCN_CALLS
	R_no_order();
#else
	@<Cases for |no_order| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_no_order(VOID)
		{
		@<Cases for |no_order| (R)@>@;
		}
#endif

@
@<Cases for |no_order| (R)@>=
intermingle = YES;
b_app(force);
b_app1(pp); @~ b_app(@' ');
REDUCE(pp,1,int_like,0,9996);


@ 
@<CASES for |built_in| (R)@>=
#if FCN_CALLS
	R_built_in();
#else
	@<Cases for |built_in| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_built_in(VOID)
		{
		@<Cases for |built_in| (R)@>@;
		}
#endif

@
@<Cases for |built_in| (R)@>=
{
b_app1(pp);
@<Append thinspace@>;
REDUCE(pp,1,expr,-2,9998);
}

@ 
@<CASES for |newline| (R)@>=
#if FCN_CALLS
	R_newline();
#else
	@<Cases for |newline| (R)@>@;
#endif

@
@<Part 2@>=
#if FCN_CALLS
	@[SRTN R_newline(VOID)
		{
		@<Cases for |newline| (R)@>@;
		}
#endif

@
@<Cases for |newline| (R)@>=
SQUASH(pp,1,ignore_scrap,-1,9999);

@* PRODUCTIONS for LITERAL.
@<Part 2@>=@[
SRTN 
V_productions(VOID)
{
switch(pp->cat)
	{
	case expr: @<Cases for |expr| (M)@>@; @~ break;
	case stmt: @<Cases for |stmt| (M)@>@; @~ break;
	}
}

@
@<Cases for |expr| (M)@>=

@
@<Cases for |stmt| (M)@>=

@* PRODUCTIONS for TEX. The productions have been made into individual
functions to accomodate memory-starved pc's.
@<Part 2@>=@[
SRTN 
X_productions(VOID)
{
switch (pp->cat) 
	{
	case expr: @<Cases for |expr| (X)@>@; @~ break;
	case stmt: @<Cases for |stmt| (X)@>@; @~ break;
	}
}

@
@<Cases for |expr| (X)@>=
{
if(cat1==expr) SQUASH(pp,2,expr,0,5);
else if(cat1==semi) 
	{
	b_app1(pp);
	REDUCE(pp,2,stmt,-1,6);
	}
}

@
@<Cases for |stmt| (X)@>=
{
if(cat1==stmt)
	{
	b_app1(pp); 
	b_app(force);
	b_app1(pp+1);
	REDUCE(pp,2,stmt,-1,250);
	}
}

@* CHANGING the SCRAP LIST; APPLYING the PRODUCTIONS.
The `|reduce|' procedure makes the appropriate changes to the scrap list. 

@<Typed...@>=

typedef unsigned long RULE_NO; // Rule number for the productions.

@
@d REDUCE(j,k,c,d,n) reduce(j,k,(eight_bits)(c),d,(RULE_NO)(n))
@<Part 2@>=@[ 
SRTN 
reduce FCN((j,k,c,d,n))
	scrap_pointer j C0("")@;
	short k C0("Number of items to be reduced.")@;
	eight_bits c C0("Reduce to this type.")@;
	short d C0("Move by this amount.")@;
	RULE_NO n C1("Rule number.")@;
{
  scrap_pointer i, i1; /* Pointers into scrap memory */

/* Store the translation. */
  j->cat=c; j->trans=text_ptr;
  j->mathness= (eight_bits)(4*last_mathness+ini_mathness);
  freeze_text;

/* More stuff to the left, overwriting the $k$~items that have been
reduced. */
  if (k>1) 
	{
	for (i=j+k, i1=j+1; i<=lo_ptr; i++, i1++) 
		{
	      i1->cat=i->cat; i1->trans=i->trans;
	      i1->mathness=i->mathness;
		    }

	    lo_ptr=lo_ptr-k+1;
	  }

  @<Change |pp| to $\max(|scrp_base|,|pp+d|)$@>;

#ifdef DEBUG
  @<Print a snapshot of the scrap list if debugging @>;
#endif /* |DEBUG| */

  pp--; /* we next say |pp++| */
}

@ 
@<Change |pp| to $\max...@>=

if (pp+d>=scrp_base) pp=pp+d;
else pp=scrp_base;

@ The |squash| procedure takes advantage of the simplification that occurs
when |k=1|.

@d SQUASH(j,k,c,d,n) squash(j,k,c,d,(RULE_NO)(n))

@<Part 2@>=@[ 
SRTN 
squash FCN((j,k,c,d,n))
	scrap_pointer j C0("")@;
	short k C0("Number to be squashed.")@;
	eight_bits c C0("Make it this type.")@;
	short d C0("Move by this amount.")@;
	RULE_NO n C1("Rule number.")@;
{
  scrap_pointer i; /* pointers into scrap memory */

  if (k==1) 
	{
	    j->cat=c; @<Change |pp|...@>;

#ifdef DEBUG
	    @<Print a snapshot...@>;
#endif /* |DEBUG| */

	    pp--; /* we next say |pp++| */
	    return;
	  }

  for (i=j; i<j+k; i++) b_app1(i);

  reduce(j,k,c,d,n);
}

@ 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|).

@<Reduce the scraps using the productions until no more rules apply@>=
{
in_prototype = indented = NO;

WHILE()
	{
	  @<Make sure the entries |pp| through |pp+3| of |cat| are defined@>;

	  if (tok_ptr+8>tok_m_end)
		{
		    if (tok_ptr>mx_tok_ptr) mx_tok_ptr=tok_ptr;
			OVERFLW("tokens","tw");
		}

	if(text_ptr+4>tok_end) 
		{
		    if (text_ptr>mx_text_ptr) mx_text_ptr=text_ptr;
		    OVERFLW("texts",ABBREV(max_texts));
		  }

	  if(pp>lo_ptr) 
		break;

	  @<Match a production...@>;
	  ini_mathness=cur_mathness=last_mathness=maybe_math;
	}
}

@ 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.

@<Make sure the entries...@>=

if (lo_ptr<pp+3) 
	{
	  while (hi_ptr<=scrp_ptr && lo_ptr!=pp+3) 
		{
	    (++lo_ptr)->cat=hi_ptr->cat; lo_ptr->mathness=(hi_ptr)->mathness;
	    lo_ptr->trans=(hi_ptr++)->trans;
		  }

	  for (i=lo_ptr+1;i<=pp+3;i++) i->cat=0;
	}

@
@d MAX_CYCLES 500
@<Check for infinite loop@>=
{
static RULE_NO last_rule = ULONG_MAX;
static int ncycles = 0;

if(n && n == last_rule)
	{
	if(ncycles++ > MAX_CYCLES)
		{
		CONFUSION("reduce", "Infinite production loop, rule %lu", n);
		}
	}
else
	{
	last_rule = n;
	ncycles = 0;
	}
}

@ 
@<Print a snapsh...@>= 
@B
  scrap_pointer k; /* pointer into |scrap_info| */

@b
@<Check for infinite loop@>@;

  if (tracing==VERBOSE) 
	{
	printf("%5lu", n); // The rule number.

	if(in_prototype)
		printf(".%i", in_prototype);

	printf(": ");

    for (k=scrp_base; k<=lo_ptr; k++) 
		{
		if (k==pp) 
			putxchar('*'); // Current one.
		else 
			putxchar(' ');

		prn_math(k);
	    }

	    if (hi_ptr<=scrp_ptr) printf("..."); /* indicate that more is
			coming */ 

		@<Print the last translation@>@;

	}
}

@
@<Part 1@>=

SRTN
prn_math FCN((k))
	scrap_pointer k C1("")@;
{
if (INI_MATHNESS(k) == yes_math) 
	putxchar('+');
else if (INI_MATHNESS(k) == no_math) 
	putxchar('-');

prn_cat(k->cat);

if (LAST_MATHNESS(k) == yes_math) 
	putxchar('+');
else if (LAST_MATHNESS(k) == no_math) 
	putxchar('-');

DFLUSH@;
}

@ For debugging, it's helpful to see the translation of the last several scraps
that's printed explicitly.
@<Print the last trans...@>=
{
printf(" ==\""); 

if(lo_ptr > scrp_base) 
	{ 
	prn_trans(lo_ptr-1); // The second-to-last scrap.
	printf("\" \"");
	}

prn_trans(lo_ptr); // Last scrap.
puts("\"");
}

@ The |translate| function assumes that scraps have been stored in
positions |scrp_base| through |scrp_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<=max_texts| and
|tok_ptr+6<=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
|scrp_ptr<max_scraps|, since |translate| might add a new text and a new
scrap before it checks for overflow.

@<Part 2@>=@[ 
text_pointer 
translate FCN((mode0))
	PARSING_MODE mode0 C1("")@;
{
LANGUAGE saved_language = language;
scrap_pointer i, /* index into |cat| */
	  j; /* runs through final scraps */

translate_mode = mode0;

pp=scrp_base; lo_ptr=pp-1; hi_ptr=pp;
@<If tracing, print an indication of where we are@>;
@<Reduce the scraps...@>@;
@<Combine the irreducible scraps that remain@>;

language = saved_language;
return text_ptr-1;
}

@ 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 scraps whose
category code is |max_math| or less.

@<Combine the irreducible...@>= 
{
EXTERN int math_flag;

  @<If semi-tracing, show the irreducible scraps@>;

  for (j=scrp_base; j<=lo_ptr; j++) 
	{
	    if (j!=scrp_base) 
		app(@' '); // Separate scraps by blanks.

	    if ((INI_MATHNESS(j) == yes_math) && math_flag==NO) 
		{
		app(@'$');
#ifdef DBGM
		app(@'7');
#endif
		}

	    if ((INI_MATHNESS(j) == no_math) && math_flag==YES) 
		{
		app(@' '); 

#ifdef DBGM
		app(@'8');
#endif
		app(@'$');
		}

	    app1(j);

	    if ((LAST_MATHNESS(j) == yes_math) && math_flag==NO) 
		{
#ifdef DBGM
		app(@'9');
#endif
		app(@'$');
		}

	    if ((LAST_MATHNESS(j) == no_math) && math_flag==YES) 
			{
			app(@'$');
#ifdef DBGM
			app(@'0');
#endif
			app(@' ');
			}

	    if (tok_ptr+6>tok_m_end) OVERFLW("tokens","tw");
	  }

  freeze_text; 
}

@ 
@<If semi-tracing, show the irreducible scraps@>=

#ifdef DEBUG
{
scrap_pointer scrap0 = scrp_base;

while(scrap0->cat == ignore_scrap) scrap0++;

if (lo_ptr>scrap0 && tracing==BRIEF) 
	{
	CLR_PRINTF(ALWAYS, warning,
		("\nIrreducible scrap sequence in %s:", 
			MOD_TRANS(module_count)));
	mfree();
	  mark_harmless;

	  for (j=scrap0; j<=lo_ptr; j++) 
		{
		    printf(" "); prn_cat(j->cat);
		  }
	}
}
#endif /* |DEBUG| */

@ Print a header for each section of translated code.
@d OUT_WIDTH 40
@<If tracing,...@>=

#ifdef DEBUG
if (tracing==VERBOSE) 
	{
	CLR_PRINTF(ALWAYS, warning,
		("\nTracing after l. %u (language = %s):  ",
			cur_line,languages[lan_num(language)])); 
	mark_harmless;

	  if (loc>=cur_buffer+OUT_WIDTH) 
		{
		printf("...");
		ASCII_write(loc-OUT_WIDTH,OUT_WIDTH);
		}
	  else ASCII_write(cur_buffer,loc-cur_buffer);

	puts("");
	}
#endif /* |DEBUG| */

@* INDEX.