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
|
/* Implementation of Fortran lexer
Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
Contributed by James Craig Burley.
This file is part of GNU Fortran.
GNU Fortran is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Fortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Fortran; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#include "proj.h"
#include "top.h"
#include "bad.h"
#include "com.h"
#include "lex.h"
#include "malloc.h"
#include "src.h"
#if FFECOM_targetCURRENT == FFECOM_targetGCC
#include "flags.h"
#include "input.h"
#include "toplev.h"
#include "output.h"
#include "ggc.h"
#endif
#ifdef DWARF_DEBUGGING_INFO
#include "dwarfout.h"
#endif
static void ffelex_append_to_token_ (char c);
static int ffelex_backslash_ (int c, ffewhereColumnNumber col);
static void ffelex_bad_1_ (ffebad errnum, ffewhereLineNumber ln0,
ffewhereColumnNumber cn0);
static void ffelex_bad_2_ (ffebad errnum, ffewhereLineNumber ln0,
ffewhereColumnNumber cn0, ffewhereLineNumber ln1,
ffewhereColumnNumber cn1);
static void ffelex_bad_here_ (int num, ffewhereLineNumber ln0,
ffewhereColumnNumber cn0);
static void ffelex_finish_statement_ (void);
#if FFECOM_targetCURRENT == FFECOM_targetGCC
static int ffelex_get_directive_line_ (char **text, FILE *finput);
static int ffelex_hash_ (FILE *f);
#endif
static ffewhereColumnNumber ffelex_image_char_ (int c,
ffewhereColumnNumber col);
static void ffelex_include_ (void);
static bool ffelex_is_free_char_ctx_contin_ (ffewhereColumnNumber col);
static bool ffelex_is_free_nonc_ctx_contin_ (ffewhereColumnNumber col);
static void ffelex_next_line_ (void);
static void ffelex_prepare_eos_ (void);
static void ffelex_send_token_ (void);
static ffelexHandler ffelex_swallow_tokens_ (ffelexToken t);
static ffelexToken ffelex_token_new_ (void);
/* Pertaining to the geometry of the input file. */
/* Initial size for card image to be allocated. */
#define FFELEX_columnINITIAL_SIZE_ 255
/* The card image itself, which grows as source lines get longer. It
has room for ffelex_card_size_ + 8 characters, and the length of the
current image is ffelex_card_length_. (The + 8 characters are made
available for easy handling of tabs and such.) */
static char *ffelex_card_image_;
static ffewhereColumnNumber ffelex_card_size_;
static ffewhereColumnNumber ffelex_card_length_;
/* Max width for free-form lines (ISO F90). */
#define FFELEX_FREE_MAX_COLUMNS_ 132
/* True if we saw a tab on the current line, as this (currently) means
the line is therefore treated as though final_nontab_column_ were
infinite. */
static bool ffelex_saw_tab_;
/* TRUE if current line is known to be erroneous, so don't bother
expanding room for it just to display it. */
static bool ffelex_bad_line_ = FALSE;
/* Last column for vanilla, i.e. non-tabbed, line. Usually 72 or 132. */
static ffewhereColumnNumber ffelex_final_nontab_column_;
/* Array for quickly deciding what kind of line the current card has,
based on its first character. */
static ffelexType ffelex_first_char_[256];
/* Pertaining to file management. */
/* The wf argument of the most recent active ffelex_file_(fixed,free)
function. */
static ffewhereFile ffelex_current_wf_;
/* TRUE if an INCLUDE statement can be processed (ffelex_set_include
can be called). */
static bool ffelex_permit_include_;
/* TRUE if an INCLUDE statement is pending (ffelex_set_include has been
called). */
static bool ffelex_set_include_;
/* Information on the pending INCLUDE file. */
static FILE *ffelex_include_file_;
static bool ffelex_include_free_form_;
static ffewhereFile ffelex_include_wherefile_;
/* Current master line count. */
static ffewhereLineNumber ffelex_linecount_current_;
/* Next master line count. */
static ffewhereLineNumber ffelex_linecount_next_;
/* ffewhere info on the latest (currently active) line read from the
active source file. */
static ffewhereLine ffelex_current_wl_;
static ffewhereColumn ffelex_current_wc_;
/* Pertaining to tokens in general. */
/* Initial capacity for text in a CHARACTER/HOLLERITH/NAME/NAMES/NUMBER
token. */
#define FFELEX_columnTOKEN_SIZE_ 63
#if FFELEX_columnTOKEN_SIZE_ < FFEWHERE_indexMAX
#error "token size too small!"
#endif
/* Current token being lexed. */
static ffelexToken ffelex_token_;
/* Handler for current token. */
static ffelexHandler ffelex_handler_;
/* TRUE if fixed-form lexer is to generate NAMES instead of NAME tokens. */
static bool ffelex_names_;
/* TRUE if both lexers are to generate NAMES instead of NAME tokens. */
static bool ffelex_names_pure_;
/* TRUE if 0-9 starts a NAME token instead of NUMBER, for parsing hex
numbers. */
static bool ffelex_hexnum_;
/* For ffelex_swallow_tokens(). */
static ffelexHandler ffelex_eos_handler_;
/* Number of tokens sent since last EOS or beginning of input file
(include INCLUDEd files). */
static unsigned long int ffelex_number_of_tokens_;
/* Number of labels sent (as NUMBER tokens) since last reset of
ffelex_number_of_tokens_ to 0, should be 0 or 1 in most cases.
(Fixed-form source only.) */
static unsigned long int ffelex_label_tokens_;
/* Metering for token management, to catch token-memory leaks. */
static long int ffelex_total_tokens_ = 0;
static long int ffelex_old_total_tokens_ = 1;
static long int ffelex_token_nextid_ = 0;
/* Pertaining to lexing CHARACTER and HOLLERITH tokens. */
/* >0 if a Hollerith constant of that length might be in mid-lex, used
when the next character seen is 'H' or 'h' to enter HOLLERITH lexing
mode (see ffelex_raw_mode_). */
static long int ffelex_expecting_hollerith_;
/* -3: Backslash (escape) sequence being lexed in CHARACTER.
-2: Possible closing apostrophe/quote seen in CHARACTER.
-1: Lexing CHARACTER.
0: Not lexing CHARACTER or HOLLERITH.
>0: Lexing HOLLERITH, value is # chars remaining to expect. */
static long int ffelex_raw_mode_;
/* When lexing CHARACTER, open quote/apostrophe (either ' or "). */
static char ffelex_raw_char_;
/* TRUE when backslash processing had to use most recent character
to finish its state engine, but that character is not part of
the backslash sequence, so must be reconsidered as a "normal"
character in CHARACTER/HOLLERITH lexing. */
static bool ffelex_backslash_reconsider_ = FALSE;
/* Characters preread before lexing happened (might include EOF). */
static int *ffelex_kludge_chars_ = NULL;
/* Doing the kludge processing, so not initialized yet. */
static bool ffelex_kludge_flag_ = FALSE;
/* The beginning of a (possible) CHARACTER/HOLLERITH token. */
static ffewhereLine ffelex_raw_where_line_;
static ffewhereColumn ffelex_raw_where_col_;
/* Call this to append another character to the current token. If it isn't
currently big enough for it, it will be enlarged. The current token
must be a CHARACTER, HOLLERITH, NAME, NAMES, or NUMBER. */
static void
ffelex_append_to_token_ (char c)
{
if (ffelex_token_->text == NULL)
{
ffelex_token_->text
= malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
FFELEX_columnTOKEN_SIZE_ + 1);
ffelex_token_->size = FFELEX_columnTOKEN_SIZE_;
ffelex_token_->length = 0;
}
else if (ffelex_token_->length >= ffelex_token_->size)
{
ffelex_token_->text
= malloc_resize_ksr (malloc_pool_image (),
ffelex_token_->text,
(ffelex_token_->size << 1) + 1,
ffelex_token_->size + 1);
ffelex_token_->size <<= 1;
assert (ffelex_token_->length < ffelex_token_->size);
}
#ifdef MAP_CHARACTER
Sorry, MAP_CHARACTER is not going to work as expected in GNU Fortran,
please contact fortran@gnu.org if you wish to fund work to
port g77 to non-ASCII machines.
#endif
ffelex_token_->text[ffelex_token_->length++] = c;
}
/* Do backslash (escape) processing for a CHARACTER/HOLLERITH token
being lexed. */
static int
ffelex_backslash_ (int c, ffewhereColumnNumber col)
{
static int state = 0;
static unsigned int count;
static int code;
static unsigned int firstdig = 0;
static int nonnull;
static ffewhereLineNumber line;
static ffewhereColumnNumber column;
/* See gcc/c-lex.c readescape() for a straightforward version
of this state engine for handling backslashes in character/
hollerith constants. */
#define wide_flag 0
#define warn_traditional 0
#define flag_traditional 0
switch (state)
{
case 0:
if ((c == '\\')
&& (ffelex_raw_mode_ != 0)
&& ffe_is_backslash ())
{
state = 1;
column = col + 1;
line = ffelex_linecount_current_;
return EOF;
}
return c;
case 1:
state = 0; /* Assume simple case. */
switch (c)
{
case 'x':
if (warn_traditional)
{
ffebad_start_msg_lex ("The meaning of `\\x' (at %0) varies with -traditional",
FFEBAD_severityWARNING);
ffelex_bad_here_ (0, line, column);
ffebad_finish ();
}
if (flag_traditional)
return c;
code = 0;
count = 0;
nonnull = 0;
state = 2;
return EOF;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7':
code = c - '0';
count = 1;
state = 3;
return EOF;
case '\\': case '\'': case '"':
return c;
#if 0 /* Inappropriate for Fortran. */
case '\n':
ffelex_next_line_ ();
*ignore_ptr = 1;
return 0;
#endif
case 'n':
return TARGET_NEWLINE;
case 't':
return TARGET_TAB;
case 'r':
return TARGET_CR;
case 'f':
return TARGET_FF;
case 'b':
return TARGET_BS;
case 'a':
if (warn_traditional)
{
ffebad_start_msg_lex ("The meaning of `\\a' (at %0) varies with -traditional",
FFEBAD_severityWARNING);
ffelex_bad_here_ (0, line, column);
ffebad_finish ();
}
if (flag_traditional)
return c;
return TARGET_BELL;
case 'v':
#if 0 /* Vertical tab is present in common usage compilers. */
if (flag_traditional)
return c;
#endif
return TARGET_VT;
case 'e':
case 'E':
case '(':
case '{':
case '[':
case '%':
if (pedantic)
{
char m[2];
m[0] = c;
m[1] = '\0';
ffebad_start_msg_lex ("Non-ANSI-C-standard escape sequence `\\%A' at %0",
FFEBAD_severityPEDANTIC);
ffelex_bad_here_ (0, line, column);
ffebad_string (m);
ffebad_finish ();
}
return (c == 'E' || c == 'e') ? 033 : c;
case '?':
return c;
default:
if (c >= 040 && c < 0177)
{
char m[2];
m[0] = c;
m[1] = '\0';
ffebad_start_msg_lex ("Unknown escape sequence `\\%A' at %0",
FFEBAD_severityPEDANTIC);
ffelex_bad_here_ (0, line, column);
ffebad_string (m);
ffebad_finish ();
}
else if (c == EOF)
{
ffebad_start_msg_lex ("Unterminated escape sequence `\\' at %0",
FFEBAD_severityPEDANTIC);
ffelex_bad_here_ (0, line, column);
ffebad_finish ();
}
else
{
char m[20];
sprintf (&m[0], "%x", c);
ffebad_start_msg_lex ("Unknown escape sequence `\\' followed by char code 0x%A at %0",
FFEBAD_severityPEDANTIC);
ffelex_bad_here_ (0, line, column);
ffebad_string (m);
ffebad_finish ();
}
}
return c;
case 2:
if ((c >= 'a' && c <= 'f')
|| (c >= 'A' && c <= 'F')
|| (c >= '0' && c <= '9'))
{
code *= 16;
if (c >= 'a' && c <= 'f')
code += c - 'a' + 10;
if (c >= 'A' && c <= 'F')
code += c - 'A' + 10;
if (c >= '0' && c <= '9')
code += c - '0';
if (code != 0 || count != 0)
{
if (count == 0)
firstdig = code;
count++;
}
nonnull = 1;
return EOF;
}
state = 0;
if (! nonnull)
{
ffebad_start_msg_lex ("\\x used at %0 with no following hex digits",
FFEBAD_severityFATAL);
ffelex_bad_here_ (0, line, column);
ffebad_finish ();
}
else if (count == 0)
/* Digits are all 0's. Ok. */
;
else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
|| (count > 1
&& ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
<= (int) firstdig)))
{
ffebad_start_msg_lex ("Hex escape at %0 out of range",
FFEBAD_severityPEDANTIC);
ffelex_bad_here_ (0, line, column);
ffebad_finish ();
}
break;
case 3:
if ((c <= '7') && (c >= '0') && (count++ < 3))
{
code = (code * 8) + (c - '0');
return EOF;
}
state = 0;
break;
default:
assert ("bad backslash state" == NULL);
abort ();
}
/* Come here when code has a built character, and c is the next
character that might (or might not) be the next one in the constant. */
/* Don't bother doing this check for each character going into
CHARACTER or HOLLERITH constants, just the escaped-value ones.
gcc apparently checks every single character, which seems
like it'd be kinda slow and not worth doing anyway. */
if (!wide_flag
&& TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
&& code >= (1 << TYPE_PRECISION (char_type_node)))
{
ffebad_start_msg_lex ("Escape sequence at %0 out of range for character",
FFEBAD_severityFATAL);
ffelex_bad_here_ (0, line, column);
ffebad_finish ();
}
if (c == EOF)
{
/* Known end of constant, just append this character. */
ffelex_append_to_token_ (code);
if (ffelex_raw_mode_ > 0)
--ffelex_raw_mode_;
return EOF;
}
/* Have two characters to handle. Do the first, then leave it to the
caller to detect anything special about the second. */
ffelex_append_to_token_ (code);
if (ffelex_raw_mode_ > 0)
--ffelex_raw_mode_;
ffelex_backslash_reconsider_ = TRUE;
return c;
}
/* ffelex_bad_1_ -- Issue diagnostic with one source point
ffelex_bad_1_(FFEBAD_SOME_ERROR,ffelex_linecount_current_,column + 1);
Creates ffewhere line and column objects for the source point, sends them
along with the error code to ffebad, then kills the line and column
objects before returning. */
static void
ffelex_bad_1_ (ffebad errnum, ffewhereLineNumber ln0, ffewhereColumnNumber cn0)
{
ffewhereLine wl0;
ffewhereColumn wc0;
wl0 = ffewhere_line_new (ln0);
wc0 = ffewhere_column_new (cn0);
ffebad_start_lex (errnum);
ffebad_here (0, wl0, wc0);
ffebad_finish ();
ffewhere_line_kill (wl0);
ffewhere_column_kill (wc0);
}
/* ffelex_bad_2_ -- Issue diagnostic with two source points
ffelex_bad_2_(FFEBAD_SOME_ERROR,ffelex_linecount_current_,column + 1,
otherline,othercolumn);
Creates ffewhere line and column objects for the source points, sends them
along with the error code to ffebad, then kills the line and column
objects before returning. */
static void
ffelex_bad_2_ (ffebad errnum, ffewhereLineNumber ln0, ffewhereColumnNumber cn0,
ffewhereLineNumber ln1, ffewhereColumnNumber cn1)
{
ffewhereLine wl0, wl1;
ffewhereColumn wc0, wc1;
wl0 = ffewhere_line_new (ln0);
wc0 = ffewhere_column_new (cn0);
wl1 = ffewhere_line_new (ln1);
wc1 = ffewhere_column_new (cn1);
ffebad_start_lex (errnum);
ffebad_here (0, wl0, wc0);
ffebad_here (1, wl1, wc1);
ffebad_finish ();
ffewhere_line_kill (wl0);
ffewhere_column_kill (wc0);
ffewhere_line_kill (wl1);
ffewhere_column_kill (wc1);
}
static void
ffelex_bad_here_ (int n, ffewhereLineNumber ln0,
ffewhereColumnNumber cn0)
{
ffewhereLine wl0;
ffewhereColumn wc0;
wl0 = ffewhere_line_new (ln0);
wc0 = ffewhere_column_new (cn0);
ffebad_here (n, wl0, wc0);
ffewhere_line_kill (wl0);
ffewhere_column_kill (wc0);
}
#if FFECOM_targetCURRENT == FFECOM_targetGCC
static int
ffelex_getc_ (FILE *finput)
{
int c;
if (ffelex_kludge_chars_ == NULL)
return getc (finput);
c = *ffelex_kludge_chars_++;
if (c != 0)
return c;
ffelex_kludge_chars_ = NULL;
return getc (finput);
}
#endif
#if FFECOM_targetCURRENT == FFECOM_targetGCC
static int
ffelex_cfebackslash_ (int *use_d, int *d, FILE *finput)
{
register int c = getc (finput);
register int code;
register unsigned count;
unsigned firstdig = 0;
int nonnull;
*use_d = 0;
switch (c)
{
case 'x':
if (warn_traditional)
warning ("the meaning of `\\x' varies with -traditional");
if (flag_traditional)
return c;
code = 0;
count = 0;
nonnull = 0;
while (1)
{
c = getc (finput);
if (!(c >= 'a' && c <= 'f')
&& !(c >= 'A' && c <= 'F')
&& !(c >= '0' && c <= '9'))
{
*use_d = 1;
*d = c;
break;
}
code *= 16;
if (c >= 'a' && c <= 'f')
code += c - 'a' + 10;
if (c >= 'A' && c <= 'F')
code += c - 'A' + 10;
if (c >= '0' && c <= '9')
code += c - '0';
if (code != 0 || count != 0)
{
if (count == 0)
firstdig = code;
count++;
}
nonnull = 1;
}
if (! nonnull)
error ("\\x used with no following hex digits");
else if (count == 0)
/* Digits are all 0's. Ok. */
;
else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
|| (count > 1
&& (((unsigned) 1
<< (TYPE_PRECISION (integer_type_node) - (count - 1)
* 4))
<= firstdig)))
pedwarn ("hex escape out of range");
return code;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7':
code = 0;
count = 0;
while ((c <= '7') && (c >= '0') && (count++ < 3))
{
code = (code * 8) + (c - '0');
c = getc (finput);
}
*use_d = 1;
*d = c;
return code;
case '\\': case '\'': case '"':
return c;
case '\n':
ffelex_next_line_ ();
*use_d = 2;
return 0;
case EOF:
*use_d = 1;
*d = EOF;
return EOF;
case 'n':
return TARGET_NEWLINE;
case 't':
return TARGET_TAB;
case 'r':
return TARGET_CR;
case 'f':
return TARGET_FF;
case 'b':
return TARGET_BS;
case 'a':
if (warn_traditional)
warning ("the meaning of `\\a' varies with -traditional");
if (flag_traditional)
return c;
return TARGET_BELL;
case 'v':
#if 0 /* Vertical tab is present in common usage compilers. */
if (flag_traditional)
return c;
#endif
return TARGET_VT;
case 'e':
case 'E':
if (pedantic)
pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
return 033;
case '?':
return c;
/* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
case '(':
case '{':
case '[':
/* `\%' is used to prevent SCCS from getting confused. */
case '%':
if (pedantic)
pedwarn ("non-ANSI escape sequence `\\%c'", c);
return c;
}
if (c >= 040 && c < 0177)
pedwarn ("unknown escape sequence `\\%c'", c);
else
pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
return c;
}
#endif
/* A miniature version of the C front-end lexer. */
#if FFECOM_targetCURRENT == FFECOM_targetGCC
static int
ffelex_cfelex_ (ffelexToken *xtoken, FILE *finput, int c)
{
ffelexToken token;
char buff[129];
char *p;
char *q;
char *r;
register unsigned buffer_length;
if ((*xtoken != NULL) && !ffelex_kludge_flag_)
ffelex_token_kill (*xtoken);
switch (c)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
buffer_length = ARRAY_SIZE (buff);
p = &buff[0];
q = p;
r = &buff[buffer_length];
for (;;)
{
*p++ = c;
if (p >= r)
{
register unsigned bytes_used = (p - q);
buffer_length *= 2;
q = (char *)xrealloc (q, buffer_length);
p = &q[bytes_used];
r = &q[buffer_length];
}
c = ffelex_getc_ (finput);
if (! ISDIGIT (c))
break;
}
*p = '\0';
token = ffelex_token_new_number (q, ffewhere_line_unknown (),
ffewhere_column_unknown ());
if (q != &buff[0])
free (q);
break;
case '\"':
buffer_length = ARRAY_SIZE (buff);
p = &buff[0];
q = p;
r = &buff[buffer_length];
c = ffelex_getc_ (finput);
for (;;)
{
bool done = FALSE;
int use_d = 0;
int d;
switch (c)
{
case '\"':
c = getc (finput);
done = TRUE;
break;
case '\\': /* ~~~~~ */
c = ffelex_cfebackslash_ (&use_d, &d, finput);
break;
case EOF:
case '\n':
error ("Badly formed directive -- no closing quote");
done = TRUE;
break;
default:
break;
}
if (done)
break;
if (use_d != 2) /* 0=>c, 1=>cd, 2=>nil. */
{
*p++ = c;
if (p >= r)
{
register unsigned bytes_used = (p - q);
buffer_length = bytes_used * 2;
q = (char *)xrealloc (q, buffer_length);
p = &q[bytes_used];
r = &q[buffer_length];
}
}
if (use_d == 1)
c = d;
else
c = getc (finput);
}
*p = '\0';
token = ffelex_token_new_character (q, ffewhere_line_unknown (),
ffewhere_column_unknown ());
if (q != &buff[0])
free (q);
break;
default:
token = NULL;
break;
}
*xtoken = token;
return c;
}
#endif
#if FFECOM_targetCURRENT == FFECOM_targetGCC
static void
ffelex_file_pop_ (const char *input_filename)
{
if (input_file_stack->next)
{
struct file_stack *p = input_file_stack;
input_file_stack = p->next;
free (p);
input_file_stack_tick++;
#ifdef DWARF_DEBUGGING_INFO
if (debug_info_level == DINFO_LEVEL_VERBOSE
&& write_symbols == DWARF_DEBUG)
dwarfout_resume_previous_source_file (input_file_stack->line);
#endif /* DWARF_DEBUGGING_INFO */
}
else
error ("#-lines for entering and leaving files don't match");
/* Now that we've pushed or popped the input stack,
update the name in the top element. */
if (input_file_stack)
input_file_stack->name = input_filename;
}
#endif
#if FFECOM_targetCURRENT == FFECOM_targetGCC
static void
ffelex_file_push_ (int old_lineno, const char *input_filename)
{
struct file_stack *p
= (struct file_stack *) xmalloc (sizeof (struct file_stack));
input_file_stack->line = old_lineno;
p->next = input_file_stack;
p->name = input_filename;
input_file_stack = p;
input_file_stack_tick++;
#ifdef DWARF_DEBUGGING_INFO
if (debug_info_level == DINFO_LEVEL_VERBOSE
&& write_symbols == DWARF_DEBUG)
dwarfout_start_new_source_file (input_filename);
#endif /* DWARF_DEBUGGING_INFO */
/* Now that we've pushed or popped the input stack,
update the name in the top element. */
if (input_file_stack)
input_file_stack->name = input_filename;
}
#endif
/* Prepare to finish a statement-in-progress by sending the current
token, if any, then setting up EOS as the current token with the
appropriate current pointer. The caller can then move the current
pointer before actually sending EOS, if desired, as it is in
typical fixed-form cases. */
static void
ffelex_prepare_eos_ ()
{
if (ffelex_token_->type != FFELEX_typeNONE)
{
ffelex_backslash_ (EOF, 0);
switch (ffelex_raw_mode_)
{
case -2:
break;
case -1:
ffebad_start_lex ((ffelex_raw_char_ == '\'') ? FFEBAD_NO_CLOSING_APOSTROPHE
: FFEBAD_NO_CLOSING_QUOTE);
ffebad_here (0, ffelex_token_->where_line, ffelex_token_->where_col);
ffebad_here (1, ffelex_current_wl_, ffelex_current_wc_);
ffebad_finish ();
break;
case 0:
break;
default:
{
char num[20];
ffebad_start_lex (FFEBAD_NOT_ENOUGH_HOLLERITH_CHARS);
ffebad_here (0, ffelex_token_->where_line, ffelex_token_->where_col);
ffebad_here (1, ffelex_current_wl_, ffelex_current_wc_);
sprintf (num, "%lu", (unsigned long) ffelex_raw_mode_);
ffebad_string (num);
ffebad_finish ();
/* Make sure the token has some text, might as well fill up with spaces. */
do
{
ffelex_append_to_token_ (' ');
} while (--ffelex_raw_mode_ > 0);
break;
}
}
ffelex_raw_mode_ = 0;
ffelex_send_token_ ();
}
ffelex_token_->type = FFELEX_typeEOS;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_use (ffelex_current_wc_);
}
static void
ffelex_finish_statement_ ()
{
if ((ffelex_number_of_tokens_ == 0)
&& (ffelex_token_->type == FFELEX_typeNONE))
return; /* Don't have a statement pending. */
if (ffelex_token_->type != FFELEX_typeEOS)
ffelex_prepare_eos_ ();
ffelex_permit_include_ = TRUE;
ffelex_send_token_ ();
ffelex_permit_include_ = FALSE;
ffelex_number_of_tokens_ = 0;
ffelex_label_tokens_ = 0;
ffelex_names_ = TRUE;
ffelex_names_pure_ = FALSE; /* Probably not necessary. */
ffelex_hexnum_ = FALSE;
if (!ffe_is_ffedebug ())
return;
/* For debugging purposes only. */
if (ffelex_total_tokens_ != ffelex_old_total_tokens_)
{
fprintf (dmpout, "; token_track had %ld tokens, now have %ld.\n",
ffelex_old_total_tokens_, ffelex_total_tokens_);
ffelex_old_total_tokens_ = ffelex_total_tokens_;
}
}
/* Copied from gcc/c-common.c get_directive_line. */
#if FFECOM_targetCURRENT == FFECOM_targetGCC
static int
ffelex_get_directive_line_ (char **text, FILE *finput)
{
static char *directive_buffer = NULL;
static unsigned buffer_length = 0;
register char *p;
register char *buffer_limit;
register int looking_for = 0;
register int char_escaped = 0;
if (buffer_length == 0)
{
directive_buffer = (char *)xmalloc (128);
buffer_length = 128;
}
buffer_limit = &directive_buffer[buffer_length];
for (p = directive_buffer; ; )
{
int c;
/* Make buffer bigger if it is full. */
if (p >= buffer_limit)
{
register unsigned bytes_used = (p - directive_buffer);
buffer_length *= 2;
directive_buffer
= (char *)xrealloc (directive_buffer, buffer_length);
p = &directive_buffer[bytes_used];
buffer_limit = &directive_buffer[buffer_length];
}
c = getc (finput);
/* Discard initial whitespace. */
if ((c == ' ' || c == '\t') && p == directive_buffer)
continue;
/* Detect the end of the directive. */
if ((c == '\n' && looking_for == 0)
|| c == EOF)
{
if (looking_for != 0)
error ("Bad directive -- missing close-quote");
*p++ = '\0';
*text = directive_buffer;
return c;
}
*p++ = c;
if (c == '\n')
ffelex_next_line_ ();
/* Handle string and character constant syntax. */
if (looking_for)
{
if (looking_for == c && !char_escaped)
looking_for = 0; /* Found terminator... stop looking. */
}
else
if (c == '\'' || c == '"')
looking_for = c; /* Don't stop buffering until we see another
one of these (or an EOF). */
/* Handle backslash. */
char_escaped = (c == '\\' && ! char_escaped);
}
}
#endif
/* Handle # directives that make it through (or are generated by) the
preprocessor. As much as reasonably possible, emulate the behavior
of the gcc compiler phase cc1, though interactions between #include
and INCLUDE might possibly produce bizarre results in terms of
error reporting and the generation of debugging info vis-a-vis the
locations of some things.
Returns the next character unhandled, which is always newline or EOF. */
#if FFECOM_targetCURRENT == FFECOM_targetGCC
#if defined HANDLE_PRAGMA
/* Local versions of these macros, that can be passed as function pointers. */
static int
pragma_getc ()
{
return getc (finput);
}
static void
pragma_ungetc (arg)
int arg;
{
ungetc (arg, finput);
}
#endif /* HANDLE_PRAGMA */
static int
ffelex_hash_ (FILE *finput)
{
register int c;
ffelexToken token = NULL;
/* Read first nonwhite char after the `#'. */
c = ffelex_getc_ (finput);
while (c == ' ' || c == '\t')
c = ffelex_getc_ (finput);
/* If a letter follows, then if the word here is `line', skip
it and ignore it; otherwise, ignore the line, with an error
if the word isn't `pragma', `ident', `define', or `undef'. */
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
if (c == 'p')
{
if (getc (finput) == 'r'
&& getc (finput) == 'a'
&& getc (finput) == 'g'
&& getc (finput) == 'm'
&& getc (finput) == 'a'
&& ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'
|| c == EOF))
{
#if 0 /* g77 doesn't handle pragmas, so ignores them FOR NOW. */
static char buffer [128];
char * buff = buffer;
/* Read the pragma name into a buffer.
ISSPACE() may evaluate its argument more than once! */
while (((c = getc (finput)), ISSPACE(c)))
continue;
do
{
* buff ++ = c;
c = getc (finput);
}
while (c != EOF && ! ISSPACE (c) && c != '\n'
&& buff < buffer + 128);
pragma_ungetc (c);
* -- buff = 0;
#ifdef HANDLE_PRAGMA
if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc, buffer))
goto skipline;
#endif /* HANDLE_PRAGMA */
#ifdef HANDLE_GENERIC_PRAGMAS
if (handle_generic_pragma (buffer))
goto skipline;
#endif /* !HANDLE_GENERIC_PRAGMAS */
/* Issue a warning message if we have been asked to do so.
Ignoring unknown pragmas in system header file unless
an explcit -Wunknown-pragmas has been given. */
if (warn_unknown_pragmas > 1
|| (warn_unknown_pragmas && ! in_system_header))
warning ("ignoring pragma: %s", token_buffer);
#endif /* 0 */
goto skipline;
}
}
else if (c == 'd')
{
if (getc (finput) == 'e'
&& getc (finput) == 'f'
&& getc (finput) == 'i'
&& getc (finput) == 'n'
&& getc (finput) == 'e'
&& ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'
|| c == EOF))
{
char *text;
c = ffelex_get_directive_line_ (&text, finput);
#ifdef DWARF_DEBUGGING_INFO
if ((debug_info_level == DINFO_LEVEL_VERBOSE)
&& (write_symbols == DWARF_DEBUG))
dwarfout_define (lineno, text);
#endif /* DWARF_DEBUGGING_INFO */
goto skipline;
}
}
else if (c == 'u')
{
if (getc (finput) == 'n'
&& getc (finput) == 'd'
&& getc (finput) == 'e'
&& getc (finput) == 'f'
&& ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'
|| c == EOF))
{
char *text;
c = ffelex_get_directive_line_ (&text, finput);
#ifdef DWARF_DEBUGGING_INFO
if ((debug_info_level == DINFO_LEVEL_VERBOSE)
&& (write_symbols == DWARF_DEBUG))
dwarfout_undef (lineno, text);
#endif /* DWARF_DEBUGGING_INFO */
goto skipline;
}
}
else if (c == 'l')
{
if (getc (finput) == 'i'
&& getc (finput) == 'n'
&& getc (finput) == 'e'
&& ((c = getc (finput)) == ' ' || c == '\t'))
goto linenum;
}
else if (c == 'i')
{
if (getc (finput) == 'd'
&& getc (finput) == 'e'
&& getc (finput) == 'n'
&& getc (finput) == 't'
&& ((c = getc (finput)) == ' ' || c == '\t'))
{
/* #ident. The pedantic warning is now in cpp. */
/* Here we have just seen `#ident '.
A string constant should follow. */
while (c == ' ' || c == '\t')
c = getc (finput);
/* If no argument, ignore the line. */
if (c == '\n' || c == EOF)
return c;
c = ffelex_cfelex_ (&token, finput, c);
if ((token == NULL)
|| (ffelex_token_type (token) != FFELEX_typeCHARACTER))
{
error ("invalid #ident");
goto skipline;
}
if (! flag_no_ident)
{
#ifdef ASM_OUTPUT_IDENT
ASM_OUTPUT_IDENT (asm_out_file,
ffelex_token_text (token));
#endif
}
/* Skip the rest of this line. */
goto skipline;
}
}
error ("undefined or invalid # directive");
goto skipline;
}
linenum:
/* Here we have either `#line' or `# <nonletter>'.
In either case, it should be a line number; a digit should follow. */
while (c == ' ' || c == '\t')
c = ffelex_getc_ (finput);
/* If the # is the only nonwhite char on the line,
just ignore it. Check the new newline. */
if (c == '\n' || c == EOF)
return c;
/* Something follows the #; read a token. */
c = ffelex_cfelex_ (&token, finput, c);
if ((token != NULL)
&& (ffelex_token_type (token) == FFELEX_typeNUMBER))
{
int old_lineno = lineno;
const char *old_input_filename = input_filename;
ffewhereFile wf;
/* subtract one, because it is the following line that
gets the specified number */
int l = atoi (ffelex_token_text (token)) - 1;
/* Is this the last nonwhite stuff on the line? */
while (c == ' ' || c == '\t')
c = ffelex_getc_ (finput);
if (c == '\n' || c == EOF)
{
/* No more: store the line number and check following line. */
lineno = l;
if (!ffelex_kludge_flag_)
{
ffewhere_file_set (NULL, TRUE, (ffewhereLineNumber) l);
if (token != NULL)
ffelex_token_kill (token);
}
return c;
}
/* More follows: it must be a string constant (filename). */
/* Read the string constant. */
c = ffelex_cfelex_ (&token, finput, c);
if ((token == NULL)
|| (ffelex_token_type (token) != FFELEX_typeCHARACTER))
{
error ("invalid #line");
goto skipline;
}
lineno = l;
if (ffelex_kludge_flag_)
input_filename = ggc_strdup (ffelex_token_text (token));
else
{
wf = ffewhere_file_new (ffelex_token_text (token),
ffelex_token_length (token));
input_filename = ffewhere_file_name (wf);
ffewhere_file_set (wf, TRUE, (ffewhereLineNumber) l);
}
#if 0 /* Not sure what g77 should do with this yet. */
/* Each change of file name
reinitializes whether we are now in a system header. */
in_system_header = 0;
#endif
if (main_input_filename == 0)
main_input_filename = input_filename;
/* Is this the last nonwhite stuff on the line? */
while (c == ' ' || c == '\t')
c = getc (finput);
if (c == '\n' || c == EOF)
{
if (!ffelex_kludge_flag_)
{
/* Update the name in the top element of input_file_stack. */
if (input_file_stack)
input_file_stack->name = input_filename;
if (token != NULL)
ffelex_token_kill (token);
}
return c;
}
c = ffelex_cfelex_ (&token, finput, c);
/* `1' after file name means entering new file.
`2' after file name means just left a file. */
if ((token != NULL)
&& (ffelex_token_type (token) == FFELEX_typeNUMBER))
{
int num = atoi (ffelex_token_text (token));
if (ffelex_kludge_flag_)
{
lineno = 1;
input_filename = old_input_filename;
error ("Use `#line ...' instead of `# ...' in first line");
}
if (num == 1)
{
/* Pushing to a new file. */
ffelex_file_push_ (old_lineno, input_filename);
}
else if (num == 2)
{
/* Popping out of a file. */
ffelex_file_pop_ (input_filename);
}
/* Is this the last nonwhite stuff on the line? */
while (c == ' ' || c == '\t')
c = getc (finput);
if (c == '\n' || c == EOF)
{
if (token != NULL)
ffelex_token_kill (token);
return c;
}
c = ffelex_cfelex_ (&token, finput, c);
}
/* `3' after file name means this is a system header file. */
#if 0 /* Not sure what g77 should do with this yet. */
if ((token != NULL)
&& (ffelex_token_type (token) == FFELEX_typeNUMBER)
&& (atoi (ffelex_token_text (token)) == 3))
in_system_header = 1;
#endif
while (c == ' ' || c == '\t')
c = getc (finput);
if (((token != NULL)
|| (c != '\n' && c != EOF))
&& ffelex_kludge_flag_)
{
lineno = 1;
input_filename = old_input_filename;
error ("Use `#line ...' instead of `# ...' in first line");
}
if (c == '\n' || c == EOF)
{
if (token != NULL && !ffelex_kludge_flag_)
ffelex_token_kill (token);
return c;
}
}
else
error ("invalid #-line");
/* skip the rest of this line. */
skipline:
if ((token != NULL) && !ffelex_kludge_flag_)
ffelex_token_kill (token);
while ((c = getc (finput)) != EOF && c != '\n')
;
return c;
}
#endif /* FFECOM_targetCURRENT == FFECOM_targetGCC */
/* "Image" a character onto the card image, return incremented column number.
Normally invoking this function as in
column = ffelex_image_char_ (c, column);
is the same as doing:
ffelex_card_image_[column++] = c;
However, tabs and carriage returns are handled specially, to preserve
the visual "image" of the input line (in most editors) in the card
image.
Carriage returns are ignored, as they are assumed to be followed
by newlines.
A tab is handled by first doing:
ffelex_card_image_[column++] = ' ';
That is, it translates to at least one space. Then, as many spaces
are imaged as necessary to bring the column number to the next tab
position, where tab positions start in the ninth column and each
eighth column afterwards. ALSO, a static var named ffelex_saw_tab_
is set to TRUE to notify the lexer that a tab was seen.
Columns are numbered and tab stops set as illustrated below:
012345670123456701234567...
x y z
xx yy zz
...
xxxxxxx yyyyyyy zzzzzzz
xxxxxxxx yyyyyyyy... */
static ffewhereColumnNumber
ffelex_image_char_ (int c, ffewhereColumnNumber column)
{
ffewhereColumnNumber old_column = column;
if (column >= ffelex_card_size_)
{
ffewhereColumnNumber newmax = ffelex_card_size_ << 1;
if (ffelex_bad_line_)
return column;
if ((newmax >> 1) != ffelex_card_size_)
{ /* Overflowed column number. */
overflow: /* :::::::::::::::::::: */
ffelex_bad_line_ = TRUE;
strcpy (&ffelex_card_image_[column - 3], "...");
ffelex_card_length_ = column;
ffelex_bad_1_ (FFEBAD_LINE_TOO_LONG,
ffelex_linecount_current_, column + 1);
return column;
}
ffelex_card_image_
= malloc_resize_ksr (malloc_pool_image (),
ffelex_card_image_,
newmax + 9,
ffelex_card_size_ + 9);
ffelex_card_size_ = newmax;
}
switch (c)
{
case '\r':
break;
case '\t':
ffelex_saw_tab_ = TRUE;
ffelex_card_image_[column++] = ' ';
while ((column & 7) != 0)
ffelex_card_image_[column++] = ' ';
break;
case '\0':
if (!ffelex_bad_line_)
{
ffelex_bad_line_ = TRUE;
strcpy (&ffelex_card_image_[column], "[\\0]");
ffelex_card_length_ = column + 4;
ffebad_start_msg_lex ("Null character at %0 -- line ignored",
FFEBAD_severityFATAL);
ffelex_bad_here_ (0, ffelex_linecount_current_, column + 1);
ffebad_finish ();
column += 4;
}
break;
default:
ffelex_card_image_[column++] = c;
break;
}
if (column < old_column)
{
column = old_column;
goto overflow; /* :::::::::::::::::::: */
}
return column;
}
static void
ffelex_include_ ()
{
ffewhereFile include_wherefile = ffelex_include_wherefile_;
FILE *include_file = ffelex_include_file_;
/* The rest of this is to push, and after the INCLUDE file is processed,
pop, the static lexer state info that pertains to each particular
input file. */
char *card_image;
ffewhereColumnNumber card_size = ffelex_card_size_;
ffewhereColumnNumber card_length = ffelex_card_length_;
ffewhereLine current_wl = ffelex_current_wl_;
ffewhereColumn current_wc = ffelex_current_wc_;
bool saw_tab = ffelex_saw_tab_;
ffewhereColumnNumber final_nontab_column = ffelex_final_nontab_column_;
ffewhereFile current_wf = ffelex_current_wf_;
ffewhereLineNumber linecount_current = ffelex_linecount_current_;
ffewhereLineNumber linecount_offset
= ffewhere_line_filelinenum (current_wl);
#if FFECOM_targetCURRENT == FFECOM_targetGCC
int old_lineno = lineno;
const char *old_input_filename = input_filename;
#endif
if (card_length != 0)
{
card_image = malloc_new_ks (malloc_pool_image (),
"FFELEX saved card image",
card_length);
memcpy (card_image, ffelex_card_image_, card_length);
}
else
card_image = NULL;
ffelex_set_include_ = FALSE;
ffelex_next_line_ ();
ffewhere_file_set (include_wherefile, TRUE, 0);
#if FFECOM_targetCURRENT == FFECOM_targetGCC
ffelex_file_push_ (old_lineno, ffewhere_file_name (include_wherefile));
#endif /* FFECOM_targetCURRENT == FFECOM_targetGCC */
if (ffelex_include_free_form_)
ffelex_file_free (include_wherefile, include_file);
else
ffelex_file_fixed (include_wherefile, include_file);
#if FFECOM_targetCURRENT == FFECOM_targetGCC
ffelex_file_pop_ (ffewhere_file_name (current_wf));
#endif /* FFECOM_targetCURRENT == FFECOM_targetGCC */
ffewhere_file_set (current_wf, TRUE, linecount_offset);
ffecom_close_include (include_file);
if (card_length != 0)
{
#ifdef REDUCE_CARD_SIZE_AFTER_BIGGY /* Define if occasional large lines. */
#error "need to handle possible reduction of card size here!!"
#endif
assert (ffelex_card_size_ >= card_length); /* It shrunk?? */
memcpy (ffelex_card_image_, card_image, card_length);
}
ffelex_card_image_[card_length] = '\0';
#if FFECOM_targetCURRENT == FFECOM_targetGCC
input_filename = old_input_filename;
lineno = old_lineno;
#endif
ffelex_linecount_current_ = linecount_current;
ffelex_current_wf_ = current_wf;
ffelex_final_nontab_column_ = final_nontab_column;
ffelex_saw_tab_ = saw_tab;
ffelex_current_wc_ = current_wc;
ffelex_current_wl_ = current_wl;
ffelex_card_length_ = card_length;
ffelex_card_size_ = card_size;
}
/* ffelex_is_free_char_ctx_contin_ -- Character Context Continuation?
ffewhereColumnNumber col;
int c; // Char at col.
if ((c == '&') && ffelex_is_free_char_ctx_contin_(col + 1))
// We have a continuation indicator.
If there are <n> spaces starting at ffelex_card_image_[col] up through
the null character, where <n> is 0 or greater, returns TRUE. */
static bool
ffelex_is_free_char_ctx_contin_ (ffewhereColumnNumber col)
{
while (ffelex_card_image_[col] != '\0')
{
if (ffelex_card_image_[col++] != ' ')
return FALSE;
}
return TRUE;
}
/* ffelex_is_free_nonc_ctx_contin_ -- Noncharacter Context Continuation?
ffewhereColumnNumber col;
int c; // Char at col.
if ((c == '&') && ffelex_is_free_nonc_ctx_contin_(col + 1))
// We have a continuation indicator.
If there are <n> spaces starting at ffelex_card_image_[col] up through
the null character or '!', where <n> is 0 or greater, returns TRUE. */
static bool
ffelex_is_free_nonc_ctx_contin_ (ffewhereColumnNumber col)
{
while ((ffelex_card_image_[col] != '\0') && (ffelex_card_image_[col] != '!'))
{
if (ffelex_card_image_[col++] != ' ')
return FALSE;
}
return TRUE;
}
static void
ffelex_next_line_ ()
{
ffelex_linecount_current_ = ffelex_linecount_next_;
++ffelex_linecount_next_;
#if FFECOM_targetCURRENT == FFECOM_targetGCC
++lineno;
#endif
}
static void
ffelex_send_token_ ()
{
++ffelex_number_of_tokens_;
ffelex_backslash_ (EOF, 0);
if (ffelex_token_->text == NULL)
{
if (ffelex_token_->type == FFELEX_typeCHARACTER)
{
ffelex_append_to_token_ ('\0');
ffelex_token_->length = 0;
}
}
else
ffelex_token_->text[ffelex_token_->length] = '\0';
assert (ffelex_raw_mode_ == 0);
if (ffelex_token_->type == FFELEX_typeNAMES)
{
ffewhere_line_kill (ffelex_token_->currentnames_line);
ffewhere_column_kill (ffelex_token_->currentnames_col);
}
assert (ffelex_handler_ != NULL);
ffelex_handler_ = (ffelexHandler) (*ffelex_handler_) (ffelex_token_);
assert (ffelex_handler_ != NULL);
ffelex_token_kill (ffelex_token_);
ffelex_token_ = ffelex_token_new_ ();
ffelex_token_->uses = 1;
ffelex_token_->text = NULL;
if (ffelex_raw_mode_ < 0)
{
ffelex_token_->type = FFELEX_typeCHARACTER;
ffelex_token_->where_line = ffelex_raw_where_line_;
ffelex_token_->where_col = ffelex_raw_where_col_;
ffelex_raw_where_line_ = ffewhere_line_unknown ();
ffelex_raw_where_col_ = ffewhere_column_unknown ();
}
else
{
ffelex_token_->type = FFELEX_typeNONE;
ffelex_token_->where_line = ffewhere_line_unknown ();
ffelex_token_->where_col = ffewhere_column_unknown ();
}
if (ffelex_set_include_)
ffelex_include_ ();
}
/* ffelex_swallow_tokens_ -- Eat all tokens delivered to me
return ffelex_swallow_tokens_;
Return this handler when you don't want to look at any more tokens in the
statement because you've encountered an unrecoverable error in the
statement. */
static ffelexHandler
ffelex_swallow_tokens_ (ffelexToken t)
{
assert (ffelex_eos_handler_ != NULL);
if ((ffelex_token_type (t) == FFELEX_typeEOS)
|| (ffelex_token_type (t) == FFELEX_typeSEMICOLON))
return (ffelexHandler) (*ffelex_eos_handler_) (t);
return (ffelexHandler) ffelex_swallow_tokens_;
}
static ffelexToken
ffelex_token_new_ ()
{
ffelexToken t;
++ffelex_total_tokens_;
t = (ffelexToken) malloc_new_ks (malloc_pool_image (),
"FFELEX token", sizeof (*t));
t->id_ = ffelex_token_nextid_++;
return t;
}
static const char *
ffelex_type_string_ (ffelexType type)
{
static const char *types[] = {
"FFELEX_typeNONE",
"FFELEX_typeCOMMENT",
"FFELEX_typeEOS",
"FFELEX_typeEOF",
"FFELEX_typeERROR",
"FFELEX_typeRAW",
"FFELEX_typeQUOTE",
"FFELEX_typeDOLLAR",
"FFELEX_typeHASH",
"FFELEX_typePERCENT",
"FFELEX_typeAMPERSAND",
"FFELEX_typeAPOSTROPHE",
"FFELEX_typeOPEN_PAREN",
"FFELEX_typeCLOSE_PAREN",
"FFELEX_typeASTERISK",
"FFELEX_typePLUS",
"FFELEX_typeMINUS",
"FFELEX_typePERIOD",
"FFELEX_typeSLASH",
"FFELEX_typeNUMBER",
"FFELEX_typeOPEN_ANGLE",
"FFELEX_typeEQUALS",
"FFELEX_typeCLOSE_ANGLE",
"FFELEX_typeNAME",
"FFELEX_typeCOMMA",
"FFELEX_typePOWER",
"FFELEX_typeCONCAT",
"FFELEX_typeDEBUG",
"FFELEX_typeNAMES",
"FFELEX_typeHOLLERITH",
"FFELEX_typeCHARACTER",
"FFELEX_typeCOLON",
"FFELEX_typeSEMICOLON",
"FFELEX_typeUNDERSCORE",
"FFELEX_typeQUESTION",
"FFELEX_typeOPEN_ARRAY",
"FFELEX_typeCLOSE_ARRAY",
"FFELEX_typeCOLONCOLON",
"FFELEX_typeREL_LE",
"FFELEX_typeREL_NE",
"FFELEX_typeREL_EQ",
"FFELEX_typePOINTS",
"FFELEX_typeREL_GE"
};
if (type >= ARRAY_SIZE (types))
return "???";
return types[type];
}
void
ffelex_display_token (ffelexToken t)
{
if (t == NULL)
t = ffelex_token_;
fprintf (dmpout, "; Token #%lu is %s (line %" ffewhereLineNumber_f "u, col %"
ffewhereColumnNumber_f "u)",
t->id_,
ffelex_type_string_ (t->type),
ffewhere_line_number (t->where_line),
ffewhere_column_number (t->where_col));
if (t->text != NULL)
fprintf (dmpout, ": \"%.*s\"\n",
(int) t->length,
t->text);
else
fprintf (dmpout, ".\n");
}
/* ffelex_expecting_character -- Tells if next token expected to be CHARACTER
if (ffelex_expecting_character())
// next token delivered by lexer will be CHARACTER.
If the most recent call to ffelex_set_expecting_hollerith since the last
token was delivered by the lexer passed a length of -1, then we return
TRUE, because the next token we deliver will be typeCHARACTER, else we
return FALSE. */
bool
ffelex_expecting_character ()
{
return (ffelex_raw_mode_ != 0);
}
/* ffelex_file_fixed -- Lex a given file in fixed source form
ffewhere wf;
FILE *f;
ffelex_file_fixed(wf,f);
Lexes the file according to Fortran 90 ANSI + VXT specifications. */
ffelexHandler
ffelex_file_fixed (ffewhereFile wf, FILE *f)
{
register int c = 0; /* Character currently under consideration. */
register ffewhereColumnNumber column = 0; /* Not really; 0 means column 1... */
bool disallow_continuation_line;
bool ignore_disallowed_continuation = FALSE;
int latest_char_in_file = 0; /* For getting back into comment-skipping
code. */
ffelexType lextype;
ffewhereColumnNumber first_label_char; /* First char of label --
column number. */
char label_string[6]; /* Text of label. */
int labi; /* Length of label text. */
bool finish_statement; /* Previous statement finished? */
bool have_content; /* This line have content? */
bool just_do_label; /* Nothing but label (and continuation?) on
line. */
/* Lex is called for a particular file, not for a particular program unit.
Yet the two events do share common characteristics. The first line in a
file or in a program unit cannot be a continuation line. No token can
be in mid-formation. No current label for the statement exists, since
there is no current statement. */
assert (ffelex_handler_ != NULL);
#if FFECOM_targetCURRENT == FFECOM_targetGCC
lineno = 0;
input_filename = ffewhere_file_name (wf);
#endif
ffelex_current_wf_ = wf;
disallow_continuation_line = TRUE;
ignore_disallowed_continuation = FALSE;
ffelex_token_->type = FFELEX_typeNONE;
ffelex_number_of_tokens_ = 0;
ffelex_label_tokens_ = 0;
ffelex_current_wl_ = ffewhere_line_unknown ();
ffelex_current_wc_ = ffewhere_column_unknown ();
latest_char_in_file = '\n';
if (ffe_is_null_version ())
{
/* Just substitute a "program" directly here. */
char line[] = " call g77__fvers;call g77__ivers;call g77__uvers;end";
char *p;
column = 0;
for (p = &line[0]; *p != '\0'; ++p)
column = ffelex_image_char_ (*p, column);
c = EOF;
goto have_line; /* :::::::::::::::::::: */
}
goto first_line; /* :::::::::::::::::::: */
/* Come here to get a new line. */
beginning_of_line: /* :::::::::::::::::::: */
disallow_continuation_line = FALSE;
/* Come here directly when last line didn't clarify the continuation issue. */
beginning_of_line_again: /* :::::::::::::::::::: */
#ifdef REDUCE_CARD_SIZE_AFTER_BIGGY /* Define if occasional large lines. */
if (ffelex_card_size_ != FFELEX_columnINITIAL_SIZE_)
{
ffelex_card_image_
= malloc_resize_ks (malloc_pool_image (),
ffelex_card_image_,
FFELEX_columnINITIAL_SIZE_ + 9,
ffelex_card_size_ + 9);
ffelex_card_size_ = FFELEX_columnINITIAL_SIZE_;
}
#endif
first_line: /* :::::::::::::::::::: */
c = latest_char_in_file;
if ((c == EOF) || ((c = ffelex_getc_ (f)) == EOF))
{
end_of_file: /* :::::::::::::::::::: */
/* Line ending in EOF instead of \n still counts as a whole line. */
ffelex_finish_statement_ ();
ffewhere_line_kill (ffelex_current_wl_);
ffewhere_column_kill (ffelex_current_wc_);
return (ffelexHandler) ffelex_handler_;
}
ffelex_next_line_ ();
ffelex_bad_line_ = FALSE;
/* Skip over comment (and otherwise ignored) lines as quickly as possible! */
while (((lextype = ffelex_first_char_[c]) == FFELEX_typeCOMMENT)
|| (lextype == FFELEX_typeERROR)
|| (lextype == FFELEX_typeSLASH)
|| (lextype == FFELEX_typeHASH))
{
/* Test most frequent type of line first, etc. */
if ((lextype == FFELEX_typeCOMMENT)
|| ((lextype == FFELEX_typeSLASH)
&& ((c = getc (f)) == '*'))) /* NOTE SIDE-EFFECT. */
{
/* Typical case (straight comment), just ignore rest of line. */
comment_line: /* :::::::::::::::::::: */
while ((c != '\n') && (c != EOF))
c = getc (f);
}
#if FFECOM_targetCURRENT == FFECOM_targetGCC
else if (lextype == FFELEX_typeHASH)
c = ffelex_hash_ (f);
#endif
else if (lextype == FFELEX_typeSLASH)
{
/* SIDE-EFFECT ABOVE HAS HAPPENED. */
ffelex_card_image_[0] = '/';
ffelex_card_image_[1] = c;
column = 2;
goto bad_first_character; /* :::::::::::::::::::: */
}
else
/* typeERROR or unsupported typeHASH. */
{ /* Bad first character, get line and display
it with message. */
column = ffelex_image_char_ (c, 0);
bad_first_character: /* :::::::::::::::::::: */
ffelex_bad_line_ = TRUE;
while (((c = getc (f)) != '\n') && (c != EOF))
column = ffelex_image_char_ (c, column);
ffelex_card_image_[column] = '\0';
ffelex_card_length_ = column;
ffelex_bad_1_ (FFEBAD_FIRST_CHAR_INVALID,
ffelex_linecount_current_, 1);
}
/* Read past last char in line. */
if (c == EOF)
{
ffelex_next_line_ ();
goto end_of_file; /* :::::::::::::::::::: */
}
c = getc (f);
ffelex_next_line_ ();
if (c == EOF)
goto end_of_file; /* :::::::::::::::::::: */
ffelex_bad_line_ = FALSE;
} /* while [c, first char, means comment] */
ffelex_saw_tab_
= (c == '&')
|| (ffelex_final_nontab_column_ == 0);
if (lextype == FFELEX_typeDEBUG)
c = ' '; /* A 'D' or 'd' in column 1 with the
debug-lines option on. */
column = ffelex_image_char_ (c, 0);
/* Read the entire line in as is (with whitespace processing). */
while (((c = getc (f)) != '\n') && (c != EOF))
column = ffelex_image_char_ (c, column);
if (ffelex_bad_line_)
{
ffelex_card_image_[column] = '\0';
ffelex_card_length_ = column;
goto comment_line; /* :::::::::::::::::::: */
}
/* If no tab, cut off line after column 72/132. */
if (!ffelex_saw_tab_ && (column > ffelex_final_nontab_column_))
{
/* Technically, we should now fill ffelex_card_image_ up thru column
72/132 with spaces, since character/hollerith constants must count
them in that manner. To save CPU time in several ways (avoid a loop
here that would be used only when we actually end a line in
character-constant mode; avoid writing memory unnecessarily; avoid a
loop later checking spaces when not scanning for character-constant
characters), we don't do this, and we do the appropriate thing when
we encounter end-of-line while actually processing a character
constant. */
column = ffelex_final_nontab_column_;
}
have_line: /* :::::::::::::::::::: */
ffelex_card_image_[column] = '\0';
ffelex_card_length_ = column;
/* Save next char in file so we can use register-based c while analyzing
line we just read. */
latest_char_in_file = c; /* Should be either '\n' or EOF. */
have_content = FALSE;
/* Handle label, if any. */
labi = 0;
first_label_char = FFEWHERE_columnUNKNOWN;
for (column = 0; column < 5; ++column)
{
switch (c = ffelex_card_image_[column])
{
case '\0':
case '!':
goto stop_looking; /* :::::::::::::::::::: */
case ' ':
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
label_string[labi++] = c;
if (first_label_char == FFEWHERE_columnUNKNOWN)
first_label_char = column + 1;
break;
case '&':
if (column != 0)
{
ffelex_bad_1_ (FFEBAD_LABEL_FIELD_NOT_NUMERIC,
ffelex_linecount_current_,
column + 1);
goto beginning_of_line_again; /* :::::::::::::::::::: */
}
if (ffe_is_pedantic ())
ffelex_bad_1_ (FFEBAD_AMPERSAND,
ffelex_linecount_current_, 1);
finish_statement = FALSE;
just_do_label = FALSE;
goto got_a_continuation; /* :::::::::::::::::::: */
case '/':
if (ffelex_card_image_[column + 1] == '*')
goto stop_looking; /* :::::::::::::::::::: */
/* Fall through. */
default:
ffelex_bad_1_ (FFEBAD_LABEL_FIELD_NOT_NUMERIC,
ffelex_linecount_current_, column + 1);
goto beginning_of_line_again; /* :::::::::::::::::::: */
}
}
stop_looking: /* :::::::::::::::::::: */
label_string[labi] = '\0';
/* Find first nonblank char starting with continuation column. */
if (column == 5) /* In which case we didn't see end of line in
label field. */
while ((c = ffelex_card_image_[column]) == ' ')
++column;
/* Now we're trying to figure out whether this is a continuation line and
whether there's anything else of substance on the line. The cases are
as follows:
1. If a line has an explicit continuation character (other than the digit
zero), then if it also has a label, the label is ignored and an error
message is printed. Any remaining text on the line is passed to the
parser tasks, thus even an all-blank line (possibly with an ignored
label) aside from a positive continuation character might have meaning
in the midst of a character or hollerith constant.
2. If a line has no explicit continuation character (that is, it has a
space in column 6 and the first non-space character past column 6 is
not a digit 0-9), then there are two possibilities:
A. A label is present and/or a non-space (and non-comment) character
appears somewhere after column 6. Terminate processing of the previous
statement, if any, send the new label for the next statement, if any,
and start processing a new statement with this non-blank character, if
any.
B. The line is essentially blank, except for a possible comment character.
Don't terminate processing of the previous statement and don't pass any
characters to the parser tasks, since the line is not flagged as a
continuation line. We treat it just like a completely blank line.
3. If a line has a continuation character of zero (0), then we terminate
processing of the previous statement, if any, send the new label for the
next statement, if any, and start processing a new statement, if any
non-blank characters are present.
If, when checking to see if we should terminate the previous statement, it
is found that there is no previous statement but that there is an
outstanding label, substitute CONTINUE as the statement for the label
and display an error message. */
finish_statement = FALSE;
just_do_label = FALSE;
switch (c)
{
case '!': /* ANSI Fortran 90 says ! in column 6 is
continuation. */
/* VXT Fortran says ! anywhere is comment, even column 6. */
if (ffe_is_vxt () || (column != 5))
goto no_tokens_on_line; /* :::::::::::::::::::: */
goto got_a_continuation; /* :::::::::::::::::::: */
case '/':
if (ffelex_card_image_[column + 1] != '*')
goto some_other_character; /* :::::::::::::::::::: */
/* Fall through. */
if (column == 5)
{
/* This seems right to do. But it is close to call, since / * starting
in column 6 will thus be interpreted as a continuation line
beginning with '*'. */
goto got_a_continuation;/* :::::::::::::::::::: */
}
/* Fall through. */
case '\0':
/* End of line. Therefore may be continued-through line, so handle
pending label as possible to-be-continued and drive end-of-statement
for any previous statement, else treat as blank line. */
no_tokens_on_line: /* :::::::::::::::::::: */
if (ffe_is_pedantic () && (c == '/'))
ffelex_bad_1_ (FFEBAD_NON_ANSI_COMMENT,
ffelex_linecount_current_, column + 1);
if (first_label_char != FFEWHERE_columnUNKNOWN)
{ /* Can't be a continued-through line if it
has a label. */
finish_statement = TRUE;
have_content = TRUE;
just_do_label = TRUE;
break;
}
goto beginning_of_line_again; /* :::::::::::::::::::: */
case '0':
if (ffe_is_pedantic () && (column != 5))
ffelex_bad_1_ (FFEBAD_NON_ANSI_CONTINUATION_COLUMN,
ffelex_linecount_current_, column + 1);
finish_statement = TRUE;
goto check_for_content; /* :::::::::::::::::::: */
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
/* NOTE: This label can be reached directly from the code
that lexes the label field in columns 1-5. */
got_a_continuation: /* :::::::::::::::::::: */
if (first_label_char != FFEWHERE_columnUNKNOWN)
{
ffelex_bad_2_ (FFEBAD_LABEL_ON_CONTINUATION,
ffelex_linecount_current_,
first_label_char,
ffelex_linecount_current_,
column + 1);
first_label_char = FFEWHERE_columnUNKNOWN;
}
if (disallow_continuation_line)
{
if (!ignore_disallowed_continuation)
ffelex_bad_1_ (FFEBAD_INVALID_CONTINUATION,
ffelex_linecount_current_, column + 1);
goto beginning_of_line_again; /* :::::::::::::::::::: */
}
if (ffe_is_pedantic () && (column != 5))
ffelex_bad_1_ (FFEBAD_NON_ANSI_CONTINUATION_COLUMN,
ffelex_linecount_current_, column + 1);
if ((ffelex_raw_mode_ != 0)
&& (((c = ffelex_card_image_[column + 1]) != '\0')
|| !ffelex_saw_tab_))
{
++column;
have_content = TRUE;
break;
}
check_for_content: /* :::::::::::::::::::: */
while ((c = ffelex_card_image_[++column]) == ' ')
;
if ((c == '\0')
|| (c == '!')
|| ((c == '/')
&& (ffelex_card_image_[column + 1] == '*')))
{
if (ffe_is_pedantic () && (c == '/'))
ffelex_bad_1_ (FFEBAD_NON_ANSI_COMMENT,
ffelex_linecount_current_, column + 1);
just_do_label = TRUE;
}
else
have_content = TRUE;
break;
default:
some_other_character: /* :::::::::::::::::::: */
if (column == 5)
goto got_a_continuation;/* :::::::::::::::::::: */
/* Here is the very normal case of a regular character starting in
column 7 or beyond with a blank in column 6. */
finish_statement = TRUE;
have_content = TRUE;
break;
}
if (have_content
|| (first_label_char != FFEWHERE_columnUNKNOWN))
{
/* The line has content of some kind, install new end-statement
point for error messages. Note that "content" includes cases
where there's little apparent content but enough to finish
a statement. That's because finishing a statement can trigger
an impending INCLUDE, and that requires accurate line info being
maintained by the lexer. */
if (finish_statement)
ffelex_prepare_eos_ (); /* Prepare EOS before we move current pointer. */
ffewhere_line_kill (ffelex_current_wl_);
ffewhere_column_kill (ffelex_current_wc_);
ffelex_current_wl_ = ffewhere_line_new (ffelex_linecount_current_);
ffelex_current_wc_ = ffewhere_column_new (ffelex_card_length_ + 1);
}
/* We delay this for a combination of reasons. Mainly, it can start
INCLUDE processing, and we want to delay that until the lexer's
info on the line is coherent. And we want to delay that until we're
sure there's a reason to make that info coherent, to avoid saving
lots of useless lines. */
if (finish_statement)
ffelex_finish_statement_ ();
/* If label is present, enclose it in a NUMBER token and send it along. */
if (first_label_char != FFEWHERE_columnUNKNOWN)
{
assert (ffelex_token_->type == FFELEX_typeNONE);
ffelex_token_->type = FFELEX_typeNUMBER;
ffelex_append_to_token_ ('\0'); /* Make room for label text. */
strcpy (ffelex_token_->text, label_string);
ffelex_token_->where_line
= ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (first_label_char);
ffelex_token_->length = labi;
ffelex_send_token_ ();
++ffelex_label_tokens_;
}
if (just_do_label)
goto beginning_of_line; /* :::::::::::::::::::: */
/* Here is the main engine for parsing. c holds the character at column.
It is already known that c is not a blank, end of line, or shriek,
unless ffelex_raw_mode_ is not 0 (indicating we are in a
character/hollerith constant). A partially filled token may already
exist in ffelex_token_. One special case: if, when the end of the line
is reached, continuation_line is FALSE and the only token on the line is
END, then it is indeed the last statement. We don't look for
continuation lines during this program unit in that case. This is
according to ANSI. */
if (ffelex_raw_mode_ != 0)
{
parse_raw_character: /* :::::::::::::::::::: */
if (c == '\0')
{
ffewhereColumnNumber i;
if (ffelex_saw_tab_ || (column >= ffelex_final_nontab_column_))
goto beginning_of_line; /* :::::::::::::::::::: */
/* Pad out line with "virtual" spaces. */
for (i = column; i < ffelex_final_nontab_column_; ++i)
ffelex_card_image_[i] = ' ';
ffelex_card_image_[i] = '\0';
ffelex_card_length_ = i;
c = ' ';
}
switch (ffelex_raw_mode_)
{
case -3:
c = ffelex_backslash_ (c, column);
if (c == EOF)
break;
if (!ffelex_backslash_reconsider_)
ffelex_append_to_token_ (c);
ffelex_raw_mode_ = -1;
break;
case -2:
if (c == ffelex_raw_char_)
{
ffelex_raw_mode_ = -1;
ffelex_append_to_token_ (c);
}
else
{
ffelex_raw_mode_ = 0;
ffelex_backslash_reconsider_ = TRUE;
}
break;
case -1:
if (c == ffelex_raw_char_)
ffelex_raw_mode_ = -2;
else
{
c = ffelex_backslash_ (c, column);
if (c == EOF)
{
ffelex_raw_mode_ = -3;
break;
}
ffelex_append_to_token_ (c);
}
break;
default:
c = ffelex_backslash_ (c, column);
if (c == EOF)
break;
if (!ffelex_backslash_reconsider_)
{
ffelex_append_to_token_ (c);
--ffelex_raw_mode_;
}
break;
}
if (ffelex_backslash_reconsider_)
ffelex_backslash_reconsider_ = FALSE;
else
c = ffelex_card_image_[++column];
if (ffelex_raw_mode_ == 0)
{
ffelex_send_token_ ();
assert (ffelex_raw_mode_ == 0);
while (c == ' ')
c = ffelex_card_image_[++column];
if ((c == '\0')
|| (c == '!')
|| ((c == '/')
&& (ffelex_card_image_[column + 1] == '*')))
goto beginning_of_line; /* :::::::::::::::::::: */
goto parse_nonraw_character; /* :::::::::::::::::::: */
}
goto parse_raw_character; /* :::::::::::::::::::: */
}
parse_nonraw_character: /* :::::::::::::::::::: */
switch (ffelex_token_->type)
{
case FFELEX_typeNONE:
switch (c)
{
case '\"':
ffelex_token_->type = FFELEX_typeQUOTE;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '$':
ffelex_token_->type = FFELEX_typeDOLLAR;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '%':
ffelex_token_->type = FFELEX_typePERCENT;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '&':
ffelex_token_->type = FFELEX_typeAMPERSAND;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '\'':
ffelex_token_->type = FFELEX_typeAPOSTROPHE;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '(':
ffelex_token_->type = FFELEX_typeOPEN_PAREN;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case ')':
ffelex_token_->type = FFELEX_typeCLOSE_PAREN;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '*':
ffelex_token_->type = FFELEX_typeASTERISK;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case '+':
ffelex_token_->type = FFELEX_typePLUS;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case ',':
ffelex_token_->type = FFELEX_typeCOMMA;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '-':
ffelex_token_->type = FFELEX_typeMINUS;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '.':
ffelex_token_->type = FFELEX_typePERIOD;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '/':
ffelex_token_->type = FFELEX_typeSLASH;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
ffelex_token_->type
= ffelex_hexnum_ ? FFELEX_typeNAME : FFELEX_typeNUMBER;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_append_to_token_ (c);
break;
case ':':
ffelex_token_->type = FFELEX_typeCOLON;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case ';':
ffelex_token_->type = FFELEX_typeSEMICOLON;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_permit_include_ = TRUE;
ffelex_send_token_ ();
ffelex_permit_include_ = FALSE;
break;
case '<':
ffelex_token_->type = FFELEX_typeOPEN_ANGLE;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case '=':
ffelex_token_->type = FFELEX_typeEQUALS;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case '>':
ffelex_token_->type = FFELEX_typeCLOSE_ANGLE;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case '?':
ffelex_token_->type = FFELEX_typeQUESTION;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '_':
if (1 || ffe_is_90 ())
{
ffelex_token_->type = FFELEX_typeUNDERSCORE;
ffelex_token_->where_line
= ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col
= ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
}
/* Fall through. */
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
c = ffesrc_char_source (c);
if (ffesrc_char_match_init (c, 'H', 'h')
&& ffelex_expecting_hollerith_ != 0)
{
ffelex_raw_mode_ = ffelex_expecting_hollerith_;
ffelex_token_->type = FFELEX_typeHOLLERITH;
ffelex_token_->where_line = ffelex_raw_where_line_;
ffelex_token_->where_col = ffelex_raw_where_col_;
ffelex_raw_where_line_ = ffewhere_line_unknown ();
ffelex_raw_where_col_ = ffewhere_column_unknown ();
c = ffelex_card_image_[++column];
goto parse_raw_character; /* :::::::::::::::::::: */
}
if (ffelex_names_)
{
ffelex_token_->where_line
= ffewhere_line_use (ffelex_token_->currentnames_line
= ffewhere_line_use (ffelex_current_wl_));
ffelex_token_->where_col
= ffewhere_column_use (ffelex_token_->currentnames_col
= ffewhere_column_new (column + 1));
ffelex_token_->type = FFELEX_typeNAMES;
}
else
{
ffelex_token_->where_line
= ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_token_->type = FFELEX_typeNAME;
}
ffelex_append_to_token_ (c);
break;
default:
ffelex_bad_1_ (FFEBAD_UNRECOGNIZED_CHARACTER,
ffelex_linecount_current_, column + 1);
ffelex_finish_statement_ ();
disallow_continuation_line = TRUE;
ignore_disallowed_continuation = TRUE;
goto beginning_of_line_again; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeNAME:
switch (c)
{
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
c = ffesrc_char_source (c);
/* Fall through. */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '_':
case '$':
if ((c == '$')
&& !ffe_is_dollar_ok ())
{
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
ffelex_append_to_token_ (c);
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeNAMES:
switch (c)
{
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
c = ffesrc_char_source (c);
/* Fall through. */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '_':
case '$':
if ((c == '$')
&& !ffe_is_dollar_ok ())
{
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
if (ffelex_token_->length < FFEWHERE_indexMAX)
{
ffewhere_track (&ffelex_token_->currentnames_line,
&ffelex_token_->currentnames_col,
ffelex_token_->wheretrack,
ffelex_token_->length,
ffelex_linecount_current_,
column + 1);
}
ffelex_append_to_token_ (c);
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeNUMBER:
switch (c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
ffelex_append_to_token_ (c);
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeASTERISK:
switch (c)
{
case '*': /* ** */
ffelex_token_->type = FFELEX_typePOWER;
ffelex_send_token_ ();
break;
default: /* * not followed by another *. */
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeCOLON:
switch (c)
{
case ':': /* :: */
ffelex_token_->type = FFELEX_typeCOLONCOLON;
ffelex_send_token_ ();
break;
default: /* : not followed by another :. */
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeSLASH:
switch (c)
{
case '/': /* // */
ffelex_token_->type = FFELEX_typeCONCAT;
ffelex_send_token_ ();
break;
case ')': /* /) */
ffelex_token_->type = FFELEX_typeCLOSE_ARRAY;
ffelex_send_token_ ();
break;
case '=': /* /= */
ffelex_token_->type = FFELEX_typeREL_NE;
ffelex_send_token_ ();
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeOPEN_PAREN:
switch (c)
{
case '/': /* (/ */
ffelex_token_->type = FFELEX_typeOPEN_ARRAY;
ffelex_send_token_ ();
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeOPEN_ANGLE:
switch (c)
{
case '=': /* <= */
ffelex_token_->type = FFELEX_typeREL_LE;
ffelex_send_token_ ();
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeEQUALS:
switch (c)
{
case '=': /* == */
ffelex_token_->type = FFELEX_typeREL_EQ;
ffelex_send_token_ ();
break;
case '>': /* => */
ffelex_token_->type = FFELEX_typePOINTS;
ffelex_send_token_ ();
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeCLOSE_ANGLE:
switch (c)
{
case '=': /* >= */
ffelex_token_->type = FFELEX_typeREL_GE;
ffelex_send_token_ ();
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
default:
assert ("Serious error!!" == NULL);
abort ();
break;
}
c = ffelex_card_image_[++column];
parse_next_character: /* :::::::::::::::::::: */
if (ffelex_raw_mode_ != 0)
goto parse_raw_character; /* :::::::::::::::::::: */
while (c == ' ')
c = ffelex_card_image_[++column];
if ((c == '\0')
|| (c == '!')
|| ((c == '/')
&& (ffelex_card_image_[column + 1] == '*')))
{
if ((ffelex_number_of_tokens_ == ffelex_label_tokens_)
&& (ffelex_token_->type == FFELEX_typeNAMES)
&& (ffelex_token_->length == 3)
&& (ffesrc_strncmp_2c (ffe_case_match (),
ffelex_token_->text,
"END", "end", "End",
3)
== 0))
{
ffelex_finish_statement_ ();
disallow_continuation_line = TRUE;
ignore_disallowed_continuation = FALSE;
goto beginning_of_line_again; /* :::::::::::::::::::: */
}
goto beginning_of_line; /* :::::::::::::::::::: */
}
goto parse_nonraw_character; /* :::::::::::::::::::: */
}
/* ffelex_file_free -- Lex a given file in free source form
ffewhere wf;
FILE *f;
ffelex_file_free(wf,f);
Lexes the file according to Fortran 90 ANSI + VXT specifications. */
ffelexHandler
ffelex_file_free (ffewhereFile wf, FILE *f)
{
register int c = 0; /* Character currently under consideration. */
register ffewhereColumnNumber column = 0; /* Not really; 0 means column 1... */
bool continuation_line = FALSE;
ffewhereColumnNumber continuation_column;
int latest_char_in_file = 0; /* For getting back into comment-skipping
code. */
/* Lex is called for a particular file, not for a particular program unit.
Yet the two events do share common characteristics. The first line in a
file or in a program unit cannot be a continuation line. No token can
be in mid-formation. No current label for the statement exists, since
there is no current statement. */
assert (ffelex_handler_ != NULL);
#if FFECOM_targetCURRENT == FFECOM_targetGCC
lineno = 0;
input_filename = ffewhere_file_name (wf);
#endif
ffelex_current_wf_ = wf;
continuation_line = FALSE;
ffelex_token_->type = FFELEX_typeNONE;
ffelex_number_of_tokens_ = 0;
ffelex_current_wl_ = ffewhere_line_unknown ();
ffelex_current_wc_ = ffewhere_column_unknown ();
latest_char_in_file = '\n';
/* Come here to get a new line. */
beginning_of_line: /* :::::::::::::::::::: */
c = latest_char_in_file;
if ((c == EOF) || ((c = ffelex_getc_ (f)) == EOF))
{
end_of_file: /* :::::::::::::::::::: */
/* Line ending in EOF instead of \n still counts as a whole line. */
ffelex_finish_statement_ ();
ffewhere_line_kill (ffelex_current_wl_);
ffewhere_column_kill (ffelex_current_wc_);
return (ffelexHandler) ffelex_handler_;
}
ffelex_next_line_ ();
ffelex_bad_line_ = FALSE;
/* Skip over initial-comment and empty lines as quickly as possible! */
while ((c == '\n')
|| (c == '!')
|| (c == '#'))
{
if (c == '#')
{
#if FFECOM_targetCURRENT == FFECOM_targetGCC
c = ffelex_hash_ (f);
#else
/* Don't skip over # line after all. */
break;
#endif
}
comment_line: /* :::::::::::::::::::: */
while ((c != '\n') && (c != EOF))
c = getc (f);
if (c == EOF)
{
ffelex_next_line_ ();
goto end_of_file; /* :::::::::::::::::::: */
}
c = getc (f);
ffelex_next_line_ ();
if (c == EOF)
goto end_of_file; /* :::::::::::::::::::: */
}
ffelex_saw_tab_ = FALSE;
column = ffelex_image_char_ (c, 0);
/* Read the entire line in as is (with whitespace processing). */
while (((c = getc (f)) != '\n') && (c != EOF))
column = ffelex_image_char_ (c, column);
if (ffelex_bad_line_)
{
ffelex_card_image_[column] = '\0';
ffelex_card_length_ = column;
goto comment_line; /* :::::::::::::::::::: */
}
/* If no tab, cut off line after column 132. */
if (!ffelex_saw_tab_ && (column > FFELEX_FREE_MAX_COLUMNS_))
column = FFELEX_FREE_MAX_COLUMNS_;
ffelex_card_image_[column] = '\0';
ffelex_card_length_ = column;
/* Save next char in file so we can use register-based c while analyzing
line we just read. */
latest_char_in_file = c; /* Should be either '\n' or EOF. */
column = 0;
continuation_column = 0;
/* Skip over initial spaces to see if the first nonblank character
is exclamation point, newline, or EOF (line is therefore a comment) or
ampersand (line is therefore a continuation line). */
while ((c = ffelex_card_image_[column]) == ' ')
++column;
switch (c)
{
case '!':
case '\0':
goto beginning_of_line; /* :::::::::::::::::::: */
case '&':
continuation_column = column + 1;
break;
default:
break;
}
/* The line definitely has content of some kind, install new end-statement
point for error messages. */
ffewhere_line_kill (ffelex_current_wl_);
ffewhere_column_kill (ffelex_current_wc_);
ffelex_current_wl_ = ffewhere_line_new (ffelex_linecount_current_);
ffelex_current_wc_ = ffewhere_column_new (ffelex_card_length_ + 1);
/* Figure out which column to start parsing at. */
if (continuation_line)
{
if (continuation_column == 0)
{
if (ffelex_raw_mode_ != 0)
{
ffelex_bad_1_ (FFEBAD_BAD_CHAR_CONTINUE,
ffelex_linecount_current_, column + 1);
}
else if (ffelex_token_->type != FFELEX_typeNONE)
{
ffelex_bad_1_ (FFEBAD_BAD_LEXTOK_CONTINUE,
ffelex_linecount_current_, column + 1);
}
}
else if (ffelex_is_free_char_ctx_contin_ (continuation_column))
{ /* Line contains only a single "&" as only
nonblank character. */
ffelex_bad_1_ (FFEBAD_BAD_FREE_CONTINUE,
ffelex_linecount_current_, continuation_column);
goto beginning_of_line; /* :::::::::::::::::::: */
}
column = continuation_column;
}
else
column = 0;
c = ffelex_card_image_[column];
continuation_line = FALSE;
/* Here is the main engine for parsing. c holds the character at column.
It is already known that c is not a blank, end of line, or shriek,
unless ffelex_raw_mode_ is not 0 (indicating we are in a
character/hollerith constant). A partially filled token may already
exist in ffelex_token_. */
if (ffelex_raw_mode_ != 0)
{
parse_raw_character: /* :::::::::::::::::::: */
switch (c)
{
case '&':
if (ffelex_is_free_char_ctx_contin_ (column + 1))
{
continuation_line = TRUE;
goto beginning_of_line; /* :::::::::::::::::::: */
}
break;
case '\0':
ffelex_finish_statement_ ();
goto beginning_of_line; /* :::::::::::::::::::: */
default:
break;
}
switch (ffelex_raw_mode_)
{
case -3:
c = ffelex_backslash_ (c, column);
if (c == EOF)
break;
if (!ffelex_backslash_reconsider_)
ffelex_append_to_token_ (c);
ffelex_raw_mode_ = -1;
break;
case -2:
if (c == ffelex_raw_char_)
{
ffelex_raw_mode_ = -1;
ffelex_append_to_token_ (c);
}
else
{
ffelex_raw_mode_ = 0;
ffelex_backslash_reconsider_ = TRUE;
}
break;
case -1:
if (c == ffelex_raw_char_)
ffelex_raw_mode_ = -2;
else
{
c = ffelex_backslash_ (c, column);
if (c == EOF)
{
ffelex_raw_mode_ = -3;
break;
}
ffelex_append_to_token_ (c);
}
break;
default:
c = ffelex_backslash_ (c, column);
if (c == EOF)
break;
if (!ffelex_backslash_reconsider_)
{
ffelex_append_to_token_ (c);
--ffelex_raw_mode_;
}
break;
}
if (ffelex_backslash_reconsider_)
ffelex_backslash_reconsider_ = FALSE;
else
c = ffelex_card_image_[++column];
if (ffelex_raw_mode_ == 0)
{
ffelex_send_token_ ();
assert (ffelex_raw_mode_ == 0);
while (c == ' ')
c = ffelex_card_image_[++column];
if ((c == '\0') || (c == '!'))
{
ffelex_finish_statement_ ();
goto beginning_of_line; /* :::::::::::::::::::: */
}
if ((c == '&') && ffelex_is_free_nonc_ctx_contin_ (column + 1))
{
continuation_line = TRUE;
goto beginning_of_line; /* :::::::::::::::::::: */
}
goto parse_nonraw_character_noncontin; /* :::::::::::::::::::: */
}
goto parse_raw_character; /* :::::::::::::::::::: */
}
parse_nonraw_character: /* :::::::::::::::::::: */
if ((c == '&') && ffelex_is_free_nonc_ctx_contin_ (column + 1))
{
continuation_line = TRUE;
goto beginning_of_line; /* :::::::::::::::::::: */
}
parse_nonraw_character_noncontin: /* :::::::::::::::::::: */
switch (ffelex_token_->type)
{
case FFELEX_typeNONE:
if (c == ' ')
{ /* Otherwise
finish-statement/continue-statement
already checked. */
while (c == ' ')
c = ffelex_card_image_[++column];
if ((c == '\0') || (c == '!'))
{
ffelex_finish_statement_ ();
goto beginning_of_line; /* :::::::::::::::::::: */
}
if ((c == '&') && ffelex_is_free_nonc_ctx_contin_ (column + 1))
{
continuation_line = TRUE;
goto beginning_of_line; /* :::::::::::::::::::: */
}
}
switch (c)
{
case '\"':
ffelex_token_->type = FFELEX_typeQUOTE;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '$':
ffelex_token_->type = FFELEX_typeDOLLAR;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '%':
ffelex_token_->type = FFELEX_typePERCENT;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '&':
ffelex_token_->type = FFELEX_typeAMPERSAND;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '\'':
ffelex_token_->type = FFELEX_typeAPOSTROPHE;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '(':
ffelex_token_->type = FFELEX_typeOPEN_PAREN;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case ')':
ffelex_token_->type = FFELEX_typeCLOSE_PAREN;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '*':
ffelex_token_->type = FFELEX_typeASTERISK;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case '+':
ffelex_token_->type = FFELEX_typePLUS;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case ',':
ffelex_token_->type = FFELEX_typeCOMMA;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '-':
ffelex_token_->type = FFELEX_typeMINUS;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '.':
ffelex_token_->type = FFELEX_typePERIOD;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '/':
ffelex_token_->type = FFELEX_typeSLASH;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
ffelex_token_->type
= ffelex_hexnum_ ? FFELEX_typeNAME : FFELEX_typeNUMBER;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_append_to_token_ (c);
break;
case ':':
ffelex_token_->type = FFELEX_typeCOLON;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case ';':
ffelex_token_->type = FFELEX_typeSEMICOLON;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_permit_include_ = TRUE;
ffelex_send_token_ ();
ffelex_permit_include_ = FALSE;
break;
case '<':
ffelex_token_->type = FFELEX_typeOPEN_ANGLE;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case '=':
ffelex_token_->type = FFELEX_typeEQUALS;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case '>':
ffelex_token_->type = FFELEX_typeCLOSE_ANGLE;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
break;
case '?':
ffelex_token_->type = FFELEX_typeQUESTION;
ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
case '_':
if (1 || ffe_is_90 ())
{
ffelex_token_->type = FFELEX_typeUNDERSCORE;
ffelex_token_->where_line
= ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col
= ffewhere_column_new (column + 1);
ffelex_send_token_ ();
break;
}
/* Fall through. */
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
c = ffesrc_char_source (c);
if (ffesrc_char_match_init (c, 'H', 'h')
&& ffelex_expecting_hollerith_ != 0)
{
ffelex_raw_mode_ = ffelex_expecting_hollerith_;
ffelex_token_->type = FFELEX_typeHOLLERITH;
ffelex_token_->where_line = ffelex_raw_where_line_;
ffelex_token_->where_col = ffelex_raw_where_col_;
ffelex_raw_where_line_ = ffewhere_line_unknown ();
ffelex_raw_where_col_ = ffewhere_column_unknown ();
c = ffelex_card_image_[++column];
goto parse_raw_character; /* :::::::::::::::::::: */
}
if (ffelex_names_pure_)
{
ffelex_token_->where_line
= ffewhere_line_use (ffelex_token_->currentnames_line
= ffewhere_line_use (ffelex_current_wl_));
ffelex_token_->where_col
= ffewhere_column_use (ffelex_token_->currentnames_col
= ffewhere_column_new (column + 1));
ffelex_token_->type = FFELEX_typeNAMES;
}
else
{
ffelex_token_->where_line
= ffewhere_line_use (ffelex_current_wl_);
ffelex_token_->where_col = ffewhere_column_new (column + 1);
ffelex_token_->type = FFELEX_typeNAME;
}
ffelex_append_to_token_ (c);
break;
default:
ffelex_bad_1_ (FFEBAD_UNRECOGNIZED_CHARACTER,
ffelex_linecount_current_, column + 1);
ffelex_finish_statement_ ();
goto beginning_of_line; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeNAME:
switch (c)
{
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
c = ffesrc_char_source (c);
/* Fall through. */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '_':
case '$':
if ((c == '$')
&& !ffe_is_dollar_ok ())
{
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
ffelex_append_to_token_ (c);
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeNAMES:
switch (c)
{
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
c = ffesrc_char_source (c);
/* Fall through. */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '_':
case '$':
if ((c == '$')
&& !ffe_is_dollar_ok ())
{
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
if (ffelex_token_->length < FFEWHERE_indexMAX)
{
ffewhere_track (&ffelex_token_->currentnames_line,
&ffelex_token_->currentnames_col,
ffelex_token_->wheretrack,
ffelex_token_->length,
ffelex_linecount_current_,
column + 1);
}
ffelex_append_to_token_ (c);
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeNUMBER:
switch (c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
ffelex_append_to_token_ (c);
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeASTERISK:
switch (c)
{
case '*': /* ** */
ffelex_token_->type = FFELEX_typePOWER;
ffelex_send_token_ ();
break;
default: /* * not followed by another *. */
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeCOLON:
switch (c)
{
case ':': /* :: */
ffelex_token_->type = FFELEX_typeCOLONCOLON;
ffelex_send_token_ ();
break;
default: /* : not followed by another :. */
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeSLASH:
switch (c)
{
case '/': /* // */
ffelex_token_->type = FFELEX_typeCONCAT;
ffelex_send_token_ ();
break;
case ')': /* /) */
ffelex_token_->type = FFELEX_typeCLOSE_ARRAY;
ffelex_send_token_ ();
break;
case '=': /* /= */
ffelex_token_->type = FFELEX_typeREL_NE;
ffelex_send_token_ ();
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeOPEN_PAREN:
switch (c)
{
case '/': /* (/ */
ffelex_token_->type = FFELEX_typeOPEN_ARRAY;
ffelex_send_token_ ();
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeOPEN_ANGLE:
switch (c)
{
case '=': /* <= */
ffelex_token_->type = FFELEX_typeREL_LE;
ffelex_send_token_ ();
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeEQUALS:
switch (c)
{
case '=': /* == */
ffelex_token_->type = FFELEX_typeREL_EQ;
ffelex_send_token_ ();
break;
case '>': /* => */
ffelex_token_->type = FFELEX_typePOINTS;
ffelex_send_token_ ();
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
case FFELEX_typeCLOSE_ANGLE:
switch (c)
{
case '=': /* >= */
ffelex_token_->type = FFELEX_typeREL_GE;
ffelex_send_token_ ();
break;
default:
ffelex_send_token_ ();
goto parse_next_character; /* :::::::::::::::::::: */
}
break;
default:
assert ("Serious error!" == NULL);
abort ();
break;
}
c = ffelex_card_image_[++column];
parse_next_character: /* :::::::::::::::::::: */
if (ffelex_raw_mode_ != 0)
goto parse_raw_character; /* :::::::::::::::::::: */
if ((c == '\0') || (c == '!'))
{
ffelex_finish_statement_ ();
goto beginning_of_line; /* :::::::::::::::::::: */
}
goto parse_nonraw_character; /* :::::::::::::::::::: */
}
/* See the code in com.c that calls this to understand why. */
#if FFECOM_targetCURRENT == FFECOM_targetGCC
void
ffelex_hash_kludge (FILE *finput)
{
/* If you change this constant string, you have to change whatever
code might thus be affected by it in terms of having to use
ffelex_getc_() instead of getc() in the lexers and _hash_. */
static char match[] = "# 1 \"";
static int kludge[ARRAY_SIZE (match) + 1];
int c;
char *p;
int *q;
/* Read chars as long as they match the target string.
Copy them into an array that will serve as a record
of what we read (essentially a multi-char ungetc(),
for code that uses ffelex_getc_ instead of getc() elsewhere
in the lexer. */
for (p = &match[0], q = &kludge[0], c = getc (finput);
(c == *p) && (*p != '\0') && (c != EOF);
++p, ++q, c = getc (finput))
*q = c;
*q = c; /* Might be EOF, which requires int. */
*++q = 0;
ffelex_kludge_chars_ = &kludge[0];
if (*p == 0)
{
ffelex_kludge_flag_ = TRUE;
++ffelex_kludge_chars_;
ffelex_hash_ (finput); /* Handle it NOW rather than later. */
ffelex_kludge_flag_ = FALSE;
}
}
#endif
void
ffelex_init_1 ()
{
unsigned int i;
ffelex_final_nontab_column_ = ffe_fixed_line_length ();
ffelex_card_size_ = FFELEX_columnINITIAL_SIZE_;
ffelex_card_image_ = malloc_new_ksr (malloc_pool_image (),
"FFELEX card image",
FFELEX_columnINITIAL_SIZE_ + 9);
ffelex_card_image_[0] = '\0';
for (i = 0; i < 256; ++i)
ffelex_first_char_[i] = FFELEX_typeERROR;
ffelex_first_char_['\t'] = FFELEX_typeRAW;
ffelex_first_char_['\n'] = FFELEX_typeCOMMENT;
ffelex_first_char_['\v'] = FFELEX_typeCOMMENT;
ffelex_first_char_['\f'] = FFELEX_typeCOMMENT;
ffelex_first_char_['\r'] = FFELEX_typeRAW;
ffelex_first_char_[' '] = FFELEX_typeRAW;
ffelex_first_char_['!'] = FFELEX_typeCOMMENT;
ffelex_first_char_['*'] = FFELEX_typeCOMMENT;
ffelex_first_char_['/'] = FFELEX_typeSLASH;
ffelex_first_char_['&'] = FFELEX_typeRAW;
ffelex_first_char_['#'] = FFELEX_typeHASH;
for (i = '0'; i <= '9'; ++i)
ffelex_first_char_[i] = FFELEX_typeRAW;
if ((ffe_case_match () == FFE_caseNONE)
|| ((ffe_case_match () == FFE_caseUPPER)
&& (ffe_case_source () != FFE_caseLOWER)) /* Idiot! :-) */
|| ((ffe_case_match () == FFE_caseLOWER)
&& (ffe_case_source () == FFE_caseLOWER)))
{
ffelex_first_char_['C'] = FFELEX_typeCOMMENT;
ffelex_first_char_['D'] = FFELEX_typeCOMMENT;
}
if ((ffe_case_match () == FFE_caseNONE)
|| ((ffe_case_match () == FFE_caseLOWER)
&& (ffe_case_source () != FFE_caseUPPER)) /* Idiot! :-) */
|| ((ffe_case_match () == FFE_caseUPPER)
&& (ffe_case_source () == FFE_caseUPPER)))
{
ffelex_first_char_['c'] = FFELEX_typeCOMMENT;
ffelex_first_char_['d'] = FFELEX_typeCOMMENT;
}
ffelex_linecount_current_ = 0;
ffelex_linecount_next_ = 1;
ffelex_raw_mode_ = 0;
ffelex_set_include_ = FALSE;
ffelex_permit_include_ = FALSE;
ffelex_names_ = TRUE; /* First token in program is a names. */
ffelex_names_pure_ = FALSE; /* Free-form lexer does NAMES only for
FORMAT. */
ffelex_hexnum_ = FALSE;
ffelex_expecting_hollerith_ = 0;
ffelex_raw_where_line_ = ffewhere_line_unknown ();
ffelex_raw_where_col_ = ffewhere_column_unknown ();
ffelex_token_ = ffelex_token_new_ ();
ffelex_token_->type = FFELEX_typeNONE;
ffelex_token_->uses = 1;
ffelex_token_->where_line = ffewhere_line_unknown ();
ffelex_token_->where_col = ffewhere_column_unknown ();
ffelex_token_->text = NULL;
ffelex_handler_ = NULL;
}
/* ffelex_is_names_expected -- Is the current parser expecting NAMES vs. NAME?
if (ffelex_is_names_expected())
// Deliver NAMES token
else
// Deliver NAME token
Must be called while lexer is active, obviously. */
bool
ffelex_is_names_expected ()
{
return ffelex_names_;
}
/* Current card image, which has the master linecount number
ffelex_linecount_current_. */
char *
ffelex_line ()
{
return ffelex_card_image_;
}
/* ffelex_line_length -- Return length of current lexer line
printf("Length is %lu\n",ffelex_line_length());
Must be called while lexer is active, obviously. */
ffewhereColumnNumber
ffelex_line_length ()
{
return ffelex_card_length_;
}
/* Master line count of current card image, or 0 if no card image
is current. */
ffewhereLineNumber
ffelex_line_number ()
{
return ffelex_linecount_current_;
}
/* ffelex_set_expecting_hollerith -- Set hollerith expectation status
ffelex_set_expecting_hollerith(0);
Lex initially assumes no hollerith constant is about to show up. If
syntactic analysis expects one, it should call this function with the
number of characters expected in the constant immediately after recognizing
the decimal number preceding the "H" and the constant itself. Then, if
the next character is indeed H, the lexer will interpret it as beginning
a hollerith constant and ship the token formed by reading the specified
number of characters (interpreting blanks and otherwise-comments too)
from the input file. It is up to syntactic analysis to call this routine
again with 0 to turn hollerith detection off immediately upon receiving
the token that might or might not be HOLLERITH.
Also call this after seeing an APOSTROPHE or QUOTE token that begins a
character constant. Pass the expected termination character (apostrophe
or quote).
Pass for length either the length of the hollerith (must be > 0), -1
meaning expecting a character constant, or 0 to cancel expectation of
a hollerith only after calling it with a length of > 0 and receiving the
next token (which may or may not have been a HOLLERITH token).
Pass for which either an apostrophe or quote when passing length of -1.
Else which is a don't-care.
Pass for line and column the line/column info for the token beginning the
character or hollerith constant, for use in error messages, when passing
a length of -1 -- this function will invoke ffewhere_line/column_use to
make its own copies. Else line and column are don't-cares (when length
is 0) and the outstanding copies of the previous line/column info, if
still around, are killed.
21-Feb-90 JCB 3.1
When called with length of 0, also zero ffelex_raw_mode_. This is
so ffest_save_ can undo the effects of replaying tokens like
APOSTROPHE and QUOTE.
25-Jan-90 JCB 3.0
New line, column arguments allow error messages to point to the true
beginning of a character/hollerith constant, rather than the beginning
of the content part, which makes them more consistent and helpful.
05-Nov-89 JCB 2.0
New "which" argument allows caller to specify termination character,
which should be apostrophe or double-quote, to support Fortran 90. */
void
ffelex_set_expecting_hollerith (long length, char which,
ffewhereLine line, ffewhereColumn column)
{
/* First kill the pending line/col info, if any (should only be pending
when this call has length==0, the previous call had length>0, and a
non-HOLLERITH token was sent in between the calls, but play it safe). */
ffewhere_line_kill (ffelex_raw_where_line_);
ffewhere_column_kill (ffelex_raw_where_col_);
/* Now handle the length function. */
switch (length)
{
case 0:
ffelex_expecting_hollerith_ = 0;
ffelex_raw_mode_ = 0;
ffelex_raw_where_line_ = ffewhere_line_unknown ();
ffelex_raw_where_col_ = ffewhere_column_unknown ();
return; /* Don't set new line/column info from args. */
case -1:
ffelex_raw_mode_ = -1;
ffelex_raw_char_ = which;
break;
default: /* length > 0 */
ffelex_expecting_hollerith_ = length;
break;
}
/* Now set new line/column information from passed args. */
ffelex_raw_where_line_ = ffewhere_line_use (line);
ffelex_raw_where_col_ = ffewhere_column_use (column);
}
/* ffelex_set_handler -- Set handler for tokens before calling _fixed or _free
ffelex_set_handler((ffelexHandler) my_first_handler);
Must be called before calling ffelex_file_fixed or ffelex_file_free or
after they return, but not while they are active. */
void
ffelex_set_handler (ffelexHandler first)
{
ffelex_handler_ = first;
}
/* ffelex_set_hexnum -- Set hexnum flag
ffelex_set_hexnum(TRUE);
Lex normally interprets a token starting with [0-9] as a NUMBER token,
so if it sees a [A-Za-z] in it, it stops parsing the NUMBER and leaves
the character as the first of the next token. But when parsing a
hexadecimal number, by calling this function with TRUE before starting
the parse of the token itself, lex will interpret [0-9] as the start
of a NAME token. */
void
ffelex_set_hexnum (bool f)
{
ffelex_hexnum_ = f;
}
/* ffelex_set_include -- Set INCLUDE file to be processed next
ffewhereFile wf; // The ffewhereFile object for the file.
bool free_form; // TRUE means read free-form file, FALSE fixed-form.
FILE *fi; // The file to INCLUDE.
ffelex_set_include(wf,free_form,fi);
Must be called only after receiving the EOS token following a valid
INCLUDE statement specifying a file that has already been successfully
opened. */
void
ffelex_set_include (ffewhereFile wf, bool free_form, FILE *fi)
{
assert (ffelex_permit_include_);
assert (!ffelex_set_include_);
ffelex_set_include_ = TRUE;
ffelex_include_free_form_ = free_form;
ffelex_include_file_ = fi;
ffelex_include_wherefile_ = wf;
}
/* ffelex_set_names -- Set names/name flag, names = TRUE
ffelex_set_names(FALSE);
Lex initially assumes multiple names should be formed. If this function is
called with FALSE, then single names are formed instead. The differences
are a difference in the token type (FFELEX_typeNAMES vs. FFELEX_typeNAME)
and in whether full source-location tracking is performed (it is for
multiple names, not for single names), which is more expensive in terms of
CPU time. */
void
ffelex_set_names (bool f)
{
ffelex_names_ = f;
if (!f)
ffelex_names_pure_ = FALSE;
}
/* ffelex_set_names_pure -- Set names/name (pure) flag, names = TRUE
ffelex_set_names_pure(FALSE);
Like ffelex_set_names, except affects both lexers. Normally, the
free-form lexer need not generate NAMES tokens because adjacent NAME
tokens must be separated by spaces which causes the lexer to generate
separate tokens for analysis (whereas in fixed-form the spaces are
ignored resulting in one long token). But in FORMAT statements, for
some reason, the Fortran 90 standard specifies that spaces can occur
anywhere within a format-item-list with no effect on the format spec
(except of course within character string edit descriptors), which means
that "1PE14.2" and "1 P E 1 4 . 2" are equivalent. For the FORMAT
statement handling, the existence of spaces makes it hard to deal with,
because each token is seen distinctly (i.e. seven tokens in the latter
example). But when no spaces are provided, as in the former example,
then only four tokens are generated, NUMBER("1"), NAME("PE14"), PERIOD,
NUMBER ("2"). By generating a NAMES instead of NAME, three things happen:
One, ffest_kw_format_ does a substring rather than full-string match,
and thus matches "PE14" to "PE"; two, ffelex_token_xyz_from_names functions
may be used to pull NAME/NAMES and NUMBER tokens out of the NAMES token;
and three, error reporting can point to the actual character rather than
at or prior to it. The first two things could be resolved by providing
alternate functions fairly easy, thus allowing FORMAT handling to expect
both lexers to generate NAME tokens instead of NAMES (with otherwise minor
changes to FORMAT parsing), but the third, error reporting, would suffer,
and when one makes mistakes in a FORMAT, believe me, one wants a pointer
to exactly where the compilers thinks the problem is, to even begin to get
a handle on it. So there. */
void
ffelex_set_names_pure (bool f)
{
ffelex_names_pure_ = f;
ffelex_names_ = f;
}
/* ffelex_splice_tokens -- Splice off and send tokens from a NAMES
return (ffelexHandler) ffelex_splice_tokens(first_handler,master_token,
start_char_index);
Returns first_handler if start_char_index chars into master_token (which
must be a NAMES token) is '\0'. Else, creates a subtoken from that
char, either NUMBER (if it is a digit), a NAME (if a valid firstnamechar),
an UNDERSCORE (if an underscore), or DOLLAR (if a dollar sign)
and sends it to first_handler. If anything other than NAME is sent, the
character at the end of it in the master token is examined to see if it
begins a NAME, NUMBER, UNDERSCORE, or DOLLAR, and, if so,
the handler returned by first_handler is invoked with that token, and
this process is repeated until the end of the master token or a NAME
token is reached. */
ffelexHandler
ffelex_splice_tokens (ffelexHandler first, ffelexToken master,
ffeTokenLength start)
{
unsigned char *p;
ffeTokenLength i;
ffelexToken t;
p = ffelex_token_text (master) + (i = start);
while (*p != '\0')
{
if (ISDIGIT (*p))
{
t = ffelex_token_number_from_names (master, i);
p += ffelex_token_length (t);
i += ffelex_token_length (t);
}
else if (ffesrc_is_name_init (*p))
{
t = ffelex_token_name_from_names (master, i, 0);
p += ffelex_token_length (t);
i += ffelex_token_length (t);
}
else if (*p == '$')
{
t = ffelex_token_dollar_from_names (master, i);
++p;
++i;
}
else if (*p == '_')
{
t = ffelex_token_uscore_from_names (master, i);
++p;
++i;
}
else
{
assert ("not a valid NAMES character" == NULL);
t = NULL;
}
assert (first != NULL);
first = (ffelexHandler) (*first) (t);
ffelex_token_kill (t);
}
return first;
}
/* ffelex_swallow_tokens -- Eat all tokens delivered to me
return ffelex_swallow_tokens;
Return this handler when you don't want to look at any more tokens in the
statement because you've encountered an unrecoverable error in the
statement. */
ffelexHandler
ffelex_swallow_tokens (ffelexToken t, ffelexHandler handler)
{
assert (handler != NULL);
if ((t != NULL) && ((ffelex_token_type (t) == FFELEX_typeEOS)
|| (ffelex_token_type (t) == FFELEX_typeSEMICOLON)))
return (ffelexHandler) (*handler) (t);
ffelex_eos_handler_ = handler;
return (ffelexHandler) ffelex_swallow_tokens_;
}
/* ffelex_token_dollar_from_names -- Return a dollar from within a names token
ffelexToken t;
t = ffelex_token_dollar_from_names(t,6);
It's as if you made a new token of dollar type having the dollar
at, in the example above, the sixth character of the NAMES token. */
ffelexToken
ffelex_token_dollar_from_names (ffelexToken t, ffeTokenLength start)
{
ffelexToken nt;
assert (t != NULL);
assert (ffelex_token_type (t) == FFELEX_typeNAMES);
assert (start < t->length);
assert (t->text[start] == '$');
/* Now make the token. */
nt = ffelex_token_new_ ();
nt->type = FFELEX_typeDOLLAR;
nt->length = 0;
nt->uses = 1;
ffewhere_set_from_track (&nt->where_line, &nt->where_col, t->where_line,
t->where_col, t->wheretrack, start);
nt->text = NULL;
return nt;
}
/* ffelex_token_kill -- Decrement use count for token, kill if no uses left
ffelexToken t;
ffelex_token_kill(t);
Complements a call to ffelex_token_use or ffelex_token_new_.... */
void
ffelex_token_kill (ffelexToken t)
{
assert (t != NULL);
assert (t->uses > 0);
if (--t->uses != 0)
return;
--ffelex_total_tokens_;
if (t->type == FFELEX_typeNAMES)
ffewhere_track_kill (t->where_line, t->where_col,
t->wheretrack, t->length);
ffewhere_line_kill (t->where_line);
ffewhere_column_kill (t->where_col);
if (t->text != NULL)
malloc_kill_ksr (malloc_pool_image (), t->text, t->size + 1);
malloc_kill_ks (malloc_pool_image (), t, sizeof (*t));
}
/* Make a new NAME token that is a substring of a NAMES token. */
ffelexToken
ffelex_token_name_from_names (ffelexToken t, ffeTokenLength start,
ffeTokenLength len)
{
ffelexToken nt;
assert (t != NULL);
assert (ffelex_token_type (t) == FFELEX_typeNAMES);
assert (start < t->length);
if (len == 0)
len = t->length - start;
else
{
assert (len > 0);
assert ((start + len) <= t->length);
}
assert (ffelex_is_firstnamechar ((unsigned char)(t->text[start])));
nt = ffelex_token_new_ ();
nt->type = FFELEX_typeNAME;
nt->size = len; /* Assume nobody's gonna fiddle with token
text. */
nt->length = len;
nt->uses = 1;
ffewhere_set_from_track (&nt->where_line, &nt->where_col, t->where_line,
t->where_col, t->wheretrack, start);
nt->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
len + 1);
strncpy (nt->text, t->text + start, len);
nt->text[len] = '\0';
return nt;
}
/* Make a new NAMES token that is a substring of another NAMES token. */
ffelexToken
ffelex_token_names_from_names (ffelexToken t, ffeTokenLength start,
ffeTokenLength len)
{
ffelexToken nt;
assert (t != NULL);
assert (ffelex_token_type (t) == FFELEX_typeNAMES);
assert (start < t->length);
if (len == 0)
len = t->length - start;
else
{
assert (len > 0);
assert ((start + len) <= t->length);
}
assert (ffelex_is_firstnamechar ((unsigned char)(t->text[start])));
nt = ffelex_token_new_ ();
nt->type = FFELEX_typeNAMES;
nt->size = len; /* Assume nobody's gonna fiddle with token
text. */
nt->length = len;
nt->uses = 1;
ffewhere_set_from_track (&nt->where_line, &nt->where_col, t->where_line,
t->where_col, t->wheretrack, start);
ffewhere_track_copy (nt->wheretrack, t->wheretrack, start, len);
nt->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
len + 1);
strncpy (nt->text, t->text + start, len);
nt->text[len] = '\0';
return nt;
}
/* Make a new CHARACTER token. */
ffelexToken
ffelex_token_new_character (const char *s, ffewhereLine l, ffewhereColumn c)
{
ffelexToken t;
t = ffelex_token_new_ ();
t->type = FFELEX_typeCHARACTER;
t->length = t->size = strlen (s); /* Assume it won't get bigger. */
t->uses = 1;
t->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
t->size + 1);
strcpy (t->text, s);
t->where_line = ffewhere_line_use (l);
t->where_col = ffewhere_column_new (c);
return t;
}
/* Make a new EOF token right after end of file. */
ffelexToken
ffelex_token_new_eof ()
{
ffelexToken t;
t = ffelex_token_new_ ();
t->type = FFELEX_typeEOF;
t->uses = 1;
t->text = NULL;
t->where_line = ffewhere_line_new (ffelex_linecount_current_);
t->where_col = ffewhere_column_new (1);
return t;
}
/* Make a new NAME token. */
ffelexToken
ffelex_token_new_name (const char *s, ffewhereLine l, ffewhereColumn c)
{
ffelexToken t;
assert (ffelex_is_firstnamechar ((unsigned char)*s));
t = ffelex_token_new_ ();
t->type = FFELEX_typeNAME;
t->length = t->size = strlen (s); /* Assume it won't get bigger. */
t->uses = 1;
t->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
t->size + 1);
strcpy (t->text, s);
t->where_line = ffewhere_line_use (l);
t->where_col = ffewhere_column_new (c);
return t;
}
/* Make a new NAMES token. */
ffelexToken
ffelex_token_new_names (const char *s, ffewhereLine l, ffewhereColumn c)
{
ffelexToken t;
assert (ffelex_is_firstnamechar ((unsigned char)*s));
t = ffelex_token_new_ ();
t->type = FFELEX_typeNAMES;
t->length = t->size = strlen (s); /* Assume it won't get bigger. */
t->uses = 1;
t->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
t->size + 1);
strcpy (t->text, s);
t->where_line = ffewhere_line_use (l);
t->where_col = ffewhere_column_new (c);
ffewhere_track_clear (t->wheretrack, t->length); /* Assume contiguous
names. */
return t;
}
/* Make a new NUMBER token.
The first character of the string must be a digit, and only the digits
are copied into the new number. So this may be used to easily extract
a NUMBER token from within any text string. Then the length of the
resulting token may be used to calculate where the digits stopped
in the original string. */
ffelexToken
ffelex_token_new_number (const char *s, ffewhereLine l, ffewhereColumn c)
{
ffelexToken t;
ffeTokenLength len;
/* How long is the string of decimal digits at s? */
len = strspn (s, "0123456789");
/* Make sure there is at least one digit. */
assert (len != 0);
/* Now make the token. */
t = ffelex_token_new_ ();
t->type = FFELEX_typeNUMBER;
t->length = t->size = len; /* Assume it won't get bigger. */
t->uses = 1;
t->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
len + 1);
strncpy (t->text, s, len);
t->text[len] = '\0';
t->where_line = ffewhere_line_use (l);
t->where_col = ffewhere_column_new (c);
return t;
}
/* Make a new token of any type that doesn't contain text. A private
function that is used by public macros in the interface file. */
ffelexToken
ffelex_token_new_simple_ (ffelexType type, ffewhereLine l, ffewhereColumn c)
{
ffelexToken t;
t = ffelex_token_new_ ();
t->type = type;
t->uses = 1;
t->text = NULL;
t->where_line = ffewhere_line_use (l);
t->where_col = ffewhere_column_new (c);
return t;
}
/* Make a new NUMBER token from an existing NAMES token.
Like ffelex_token_new_number, this function calculates the length
of the digit string itself. */
ffelexToken
ffelex_token_number_from_names (ffelexToken t, ffeTokenLength start)
{
ffelexToken nt;
ffeTokenLength len;
assert (t != NULL);
assert (ffelex_token_type (t) == FFELEX_typeNAMES);
assert (start < t->length);
/* How long is the string of decimal digits at s? */
len = strspn (t->text + start, "0123456789");
/* Make sure there is at least one digit. */
assert (len != 0);
/* Now make the token. */
nt = ffelex_token_new_ ();
nt->type = FFELEX_typeNUMBER;
nt->size = len; /* Assume nobody's gonna fiddle with token
text. */
nt->length = len;
nt->uses = 1;
ffewhere_set_from_track (&nt->where_line, &nt->where_col, t->where_line,
t->where_col, t->wheretrack, start);
nt->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
len + 1);
strncpy (nt->text, t->text + start, len);
nt->text[len] = '\0';
return nt;
}
/* Make a new UNDERSCORE token from a NAMES token. */
ffelexToken
ffelex_token_uscore_from_names (ffelexToken t, ffeTokenLength start)
{
ffelexToken nt;
assert (t != NULL);
assert (ffelex_token_type (t) == FFELEX_typeNAMES);
assert (start < t->length);
assert (t->text[start] == '_');
/* Now make the token. */
nt = ffelex_token_new_ ();
nt->type = FFELEX_typeUNDERSCORE;
nt->uses = 1;
ffewhere_set_from_track (&nt->where_line, &nt->where_col, t->where_line,
t->where_col, t->wheretrack, start);
nt->text = NULL;
return nt;
}
/* ffelex_token_use -- Return another instance of a token
ffelexToken t;
t = ffelex_token_use(t);
In a sense, the new token is a copy of the old, though it might be the
same with just a new use count.
We use the use count method (easy). */
ffelexToken
ffelex_token_use (ffelexToken t)
{
if (t == NULL)
assert ("_token_use: null token" == NULL);
t->uses++;
return t;
}
|