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

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.

   Related Modules:
      None

   Description:
      Analyzes the first two tokens, figures out what statements are
      possible, tries parsing the possible statements by calling on
      the ffestb functions.

   Modifications:
*/

/* Include files. */

#include "proj.h"
#include "sta.h"
#include "bad.h"
#include "implic.h"
#include "lex.h"
#include "malloc.h"
#include "stb.h"
#include "stc.h"
#include "std.h"
#include "str.h"
#include "storag.h"
#include "symbol.h"

/* Externals defined here. */

ffelexToken ffesta_tokens[FFESTA_tokensMAX];	/* For use by a possible. */
ffestrFirst ffesta_first_kw;	/* First NAME(S) looked up. */
ffestrSecond ffesta_second_kw;	/* Second NAME(S) looked up. */
mallocPool ffesta_output_pool;	/* Pool for results of stmt handling. */
mallocPool ffesta_scratch_pool;	/* Pool for stmt scratch handling. */
ffelexToken ffesta_construct_name;
ffelexToken ffesta_label_token;	/* Pending label stuff. */
bool ffesta_seen_first_exec;
bool ffesta_is_entry_valid = FALSE;	/* TRUE only in SUBROUTINE/FUNCTION. */
bool ffesta_line_has_semicolons = FALSE;

/* Simple definitions and enumerations. */

#define FFESTA_ABORT_ON_CONFIRM_ 1	/* 0=slow, tested way; 1=faster way
					   that might not always work. Here's
					   the old description of what used
					   to not work with ==1: (try
					   "CONTINUE\10
					   FORMAT('hi',I11)\END").  Problem
					   is that the "topology" of the
					   confirmed stmt's tokens with
					   regard to CHARACTER, HOLLERITH,
					   NAME/NAMES/NUMBER tokens (like hex
					   numbers), isn't traced if we abort
					   early, then other stmts might get
					   their grubby hands on those
					   unprocessed tokens and commit them
					   improperly.	Ideal fix is to rerun
					   the confirmed stmt and forget the
					   rest.  */

#define FFESTA_maxPOSSIBLES_ 8/* Never more than this # of possibles. */

/* Internal typedefs. */

typedef struct _ffesta_possible_ *ffestaPossible_;

/* Private include files. */


/* Internal structure definitions. */

struct _ffesta_possible_
  {
    ffestaPossible_ next;
    ffestaPossible_ previous;
    ffelexHandler handler;
    bool named;
  };

struct _ffesta_possible_root_
  {
    ffestaPossible_ first;
    ffestaPossible_ last;
    ffelexHandler nil;
  };

/* Static objects accessed by functions in this module. */

static bool ffesta_is_inhibited_ = FALSE;
static ffelexToken ffesta_token_0_;	/* For use by ffest possibility
					   handling. */
static ffestaPossible_ ffesta_possibles_[FFESTA_maxPOSSIBLES_];
static int ffesta_num_possibles_ = 0;	/* Number of possibilities. */
static struct _ffesta_possible_root_ ffesta_possible_nonexecs_;
static struct _ffesta_possible_root_ ffesta_possible_execs_;
static ffestaPossible_ ffesta_current_possible_;
static ffelexHandler ffesta_current_handler_;
static bool ffesta_confirmed_current_ = FALSE;
static bool ffesta_confirmed_other_ = FALSE;
static ffestaPossible_ ffesta_confirmed_possible_;
static bool ffesta_current_shutdown_ = FALSE;
#if !FFESTA_ABORT_ON_CONFIRM_
static bool ffesta_is_two_into_statement_ = FALSE;	/* For IF, WHERE stmts. */
static ffelexToken ffesta_twotokens_1_;	/* For IF, WHERE stmts. */
static ffelexToken ffesta_twotokens_2_;	/* For IF, WHERE stmts. */
#endif
static ffestaPooldisp ffesta_outpooldisp_;	/* After statement dealt
						   with. */
static bool ffesta_inhibit_confirmation_ = FALSE;

/* Static functions (internal). */

static void ffesta_add_possible_ (ffelexHandler fn, bool exec, bool named);
static bool ffesta_inhibited_exec_transition_ (void);
static void ffesta_reset_possibles_ (void);
static ffelexHandler ffesta_save_ (ffelexToken t);
static ffelexHandler ffesta_second_ (ffelexToken t);
#if !FFESTA_ABORT_ON_CONFIRM_
static ffelexHandler ffesta_send_two_ (ffelexToken t);
#endif

/* Internal macros. */

#define ffesta_add_possible_exec_(fn) (ffesta_add_possible_ (fn, TRUE, TRUE))
#define ffesta_add_possible_nonexec_(fn) (ffesta_add_possible_ (fn, FALSE, TRUE))
#define ffesta_add_possible_unnamed_exec_(fn) (ffesta_add_possible_ (fn, TRUE, FALSE))
#define ffesta_add_possible_unnamed_nonexec_(fn) (ffesta_add_possible_ (fn, FALSE, FALSE))

/* Add possible statement to appropriate list.  */

static void
ffesta_add_possible_ (ffelexHandler fn, bool exec, bool named)
{
  ffestaPossible_ p;

  assert (ffesta_num_possibles_ < FFESTA_maxPOSSIBLES_);

  p = ffesta_possibles_[ffesta_num_possibles_++];

  if (exec)
    {
      p->next = (ffestaPossible_) &ffesta_possible_execs_.first;
      p->previous = ffesta_possible_execs_.last;
    }
  else
    {
      p->next = (ffestaPossible_) &ffesta_possible_nonexecs_.first;
      p->previous = ffesta_possible_nonexecs_.last;
    }
  p->next->previous = p;
  p->previous->next = p;

  p->handler = fn;
  p->named = named;
}

/* ffesta_inhibited_exec_transition_ -- Do exec transition while inhibited

   if (!ffesta_inhibited_exec_transition_())  // couldn't transition...

   Invokes ffestc_exec_transition, but first enables ffebad and ffesta and
   afterwards disables them again.  Then returns the result of the
   invocation of ffestc_exec_transition.  */

static bool
ffesta_inhibited_exec_transition_ ()
{
  bool result;

  assert (ffebad_inhibit ());
  assert (ffesta_is_inhibited_);

  ffebad_set_inhibit (FALSE);
  ffesta_is_inhibited_ = FALSE;

  result = ffestc_exec_transition ();

  ffebad_set_inhibit (TRUE);
  ffesta_is_inhibited_ = TRUE;

  return result;
}

/* ffesta_reset_possibles_ -- Reset (clear) lists of possible statements

   ffesta_reset_possibles_();

   Clears the lists of executable and nonexecutable statements.	 */

static void
ffesta_reset_possibles_ ()
{
  ffesta_num_possibles_ = 0;

  ffesta_possible_execs_.first = ffesta_possible_execs_.last
    = (ffestaPossible_) &ffesta_possible_execs_.first;
  ffesta_possible_nonexecs_.first = ffesta_possible_nonexecs_.last
    = (ffestaPossible_) &ffesta_possible_nonexecs_.first;
}

/* ffesta_save_ -- Save token on list, pass thru to current handler

   return ffesta_save_;	 // to lexer.

   Receives a token from the lexer.  Saves it in the list of tokens.  Calls
   the current handler with the token.

   If no shutdown error occurred (via
   ffest_ffebad_start), then if the token was EOS or SEMICOLON, mark the
   current possible as successful and confirmed but try the next possible
   anyway until ambiguities in the form handling are ironed out.  */

static ffelexHandler
ffesta_save_ (ffelexToken t)
{
  static ffelexToken *saved_tokens = NULL;	/* A variable-sized array. */
  static unsigned int num_saved_tokens = 0;	/* Number currently saved. */
  static unsigned int max_saved_tokens = 0;	/* Maximum to be saved. */
  unsigned int toknum;		/* Index into saved_tokens array. */
  ffelexToken eos;		/* EOS created on-the-fly for shutdown
				   purposes. */
  ffelexToken t2;		/* Another temporary token (no intersect with
				   eos, btw). */

  /* Save the current token. */

  if (saved_tokens == NULL)
    {
      saved_tokens
	= (ffelexToken *) malloc_new_ksr (malloc_pool_image (),
					  "FFEST Saved Tokens",
			     (max_saved_tokens = 8) * sizeof (ffelexToken));
      /* Start off with 8. */
    }
  else if (num_saved_tokens >= max_saved_tokens)
    {
      toknum = max_saved_tokens;
      max_saved_tokens <<= 1;	/* Multiply by two. */
      assert (max_saved_tokens > toknum);
      saved_tokens
	= (ffelexToken *) malloc_resize_ksr (malloc_pool_image (),
					     saved_tokens,
				    max_saved_tokens * sizeof (ffelexToken),
					     toknum * sizeof (ffelexToken));
    }

  *(saved_tokens + num_saved_tokens++) = ffelex_token_use (t);

  /* Transmit the current token to the current handler. */

  ffesta_current_handler_ = (ffelexHandler) (*ffesta_current_handler_) (t);

  /* See if this possible has been shut down, or confirmed in which case we
     might as well shut it down anyway to save time. */

  if ((ffesta_current_shutdown_ || (FFESTA_ABORT_ON_CONFIRM_
				    && ffesta_confirmed_current_))
      && !ffelex_expecting_character ())
    {
      switch (ffelex_token_type (t))
	{
	case FFELEX_typeEOS:
	case FFELEX_typeSEMICOLON:
	  break;

	default:
	  eos = ffelex_token_new_eos (ffelex_token_where_line (t),
				      ffelex_token_where_column (t));
	  ffesta_inhibit_confirmation_ = ffesta_current_shutdown_;
	  (*ffesta_current_handler_) (eos);
	  ffesta_inhibit_confirmation_ = FALSE;
	  ffelex_token_kill (eos);
	  break;
	}
    }
  else
    {

      /* If this is an EOS or SEMICOLON token, switch to next handler, else
	 return self as next handler for lexer. */

      switch (ffelex_token_type (t))
	{
	case FFELEX_typeEOS:
	case FFELEX_typeSEMICOLON:
	  break;

	default:
	  return (ffelexHandler) ffesta_save_;
	}
    }

 next_handler:			/* :::::::::::::::::::: */

  /* Note that a shutdown also happens after seeing the first two tokens
     after "IF (expr)" or "WHERE (expr)" where a statement follows, even
     though there is no error.	This causes the IF or WHERE form to be
     implemented first before ffest_first is called for the first token in
     the following statement. */

  if (ffesta_current_shutdown_)
    ffesta_current_shutdown_ = FALSE;	/* Only after sending EOS! */
  else
    assert (ffesta_confirmed_current_);

  if (ffesta_confirmed_current_)
    {
      ffesta_confirmed_current_ = FALSE;
      ffesta_confirmed_other_ = TRUE;
    }

  /* Pick next handler. */

  ffesta_current_possible_ = ffesta_current_possible_->next;
  ffesta_current_handler_ = ffesta_current_possible_->handler;
  if (ffesta_current_handler_ == NULL)
    {				/* No handler in this list, try exec list if
				   not tried yet. */
      if (ffesta_current_possible_
	  == (ffestaPossible_) &ffesta_possible_nonexecs_)
	{
	  ffesta_current_possible_ = ffesta_possible_execs_.first;
	  ffesta_current_handler_ = ffesta_current_possible_->handler;
	}
      if ((ffesta_current_handler_ == NULL)
	  || (!ffesta_seen_first_exec
	      && ((ffesta_confirmed_possible_ != NULL)
		  || !ffesta_inhibited_exec_transition_ ())))
	/* Don't run execs if:	  (decoding the "if" ^^^ up here ^^^) - we
	   have no exec handler available, or - we haven't seen the first
	   executable statement yet, and - we've confirmed a nonexec
	   (otherwise even a nonexec would cause a transition), or - a
	   nonexec-to-exec transition can't be made at the statement context
	   level (as in an executable statement in the middle of a STRUCTURE
	   definition); if it can be made, ffestc_exec_transition makes the
	   corresponding transition at the statement state level so
	   specification statements are no longer accepted following an
	   unrecognized statement.  (Note: it is valid for f_e_t_ to decide
	   to always return TRUE by "shrieking" away the statement state
	   stack until a transitionable state is reached.  Or it can leave
	   the stack as is and return FALSE.)

	   If we decide not to run execs, enter this block to rerun the
	   confirmed statement, if any. */
	{			/* At end of both lists!  Pick confirmed or
				   first possible. */
	  ffebad_set_inhibit (FALSE);
	  ffesta_is_inhibited_ = FALSE;
	  ffesta_confirmed_other_ = FALSE;
	  ffesta_tokens[0] = ffesta_token_0_;
	  if (ffesta_confirmed_possible_ == NULL)
	    {			/* No confirmed success, just use first
				   named possible, or first possible if
				   no named possibles. */
	      ffestaPossible_ possible = ffesta_possible_nonexecs_.first;
	      ffestaPossible_ first = NULL;
	      ffestaPossible_ first_named = NULL;
	      ffestaPossible_ first_exec = NULL;

	      for (;;)
		{
		  if (possible->handler == NULL)
		    {
		      if (possible == (ffestaPossible_) &ffesta_possible_nonexecs_)
			{
			  possible = first_exec = ffesta_possible_execs_.first;
			  continue;
			}
		      else
			break;
		    }
		  if (first == NULL)
		    first = possible;
		  if (possible->named
		      && (first_named == NULL))
		    first_named = possible;

		  possible = possible->next;
		}

	      if (first_named != NULL)
		ffesta_current_possible_ = first_named;
	      else if (ffesta_seen_first_exec
		       && (first_exec != NULL))
		ffesta_current_possible_ = first_exec;
	      else
		ffesta_current_possible_ = first;

	      ffesta_current_handler_ = ffesta_current_possible_->handler;
	      assert (ffesta_current_handler_ != NULL);
	    }
	  else
	    {			/* Confirmed success, use it. */
	      ffesta_current_possible_ = ffesta_confirmed_possible_;
	      ffesta_current_handler_ = ffesta_confirmed_possible_->handler;
	    }
	  ffesta_reset_possibles_ ();
	}
      else
	{			/* Switching from [empty?] list of nonexecs
				   to nonempty list of execs at this point. */
	  ffesta_tokens[0] = ffelex_token_use (ffesta_token_0_);
	  ffesymbol_set_retractable (ffesta_scratch_pool);
	}
    }
  else
    {
      ffesta_tokens[0] = ffelex_token_use (ffesta_token_0_);
      ffesymbol_set_retractable (ffesta_scratch_pool);
    }

  /* Send saved tokens to current handler until either shut down or all
     tokens sent. */

  for (toknum = 0; toknum < num_saved_tokens; ++toknum)
    {
      t = *(saved_tokens + toknum);
      switch (ffelex_token_type (t))
	{
	case FFELEX_typeCHARACTER:
	  ffelex_set_expecting_hollerith (0, '\0',
					  ffewhere_line_unknown (),
					  ffewhere_column_unknown ());
	  ffesta_current_handler_
	    = (ffelexHandler) (*ffesta_current_handler_) (t);
	  break;

	case FFELEX_typeNAMES:
	  if (ffelex_is_names_expected ())
	    ffesta_current_handler_
	      = (ffelexHandler) (*ffesta_current_handler_) (t);
	  else
	    {
	      t2 = ffelex_token_name_from_names (t, 0, 0);
	      ffesta_current_handler_
		= (ffelexHandler) (*ffesta_current_handler_) (t2);
	      ffelex_token_kill (t2);
	    }
	  break;

	default:
	  ffesta_current_handler_
	    = (ffelexHandler) (*ffesta_current_handler_) (t);
	  break;
	}

      if (!ffesta_is_inhibited_)
	ffelex_token_kill (t);	/* Won't need this any more. */

      /* See if this possible has been shut down. */

      else if ((ffesta_current_shutdown_ || (FFESTA_ABORT_ON_CONFIRM_
					     && ffesta_confirmed_current_))
	       && !ffelex_expecting_character ())
	{
	  switch (ffelex_token_type (t))
	    {
	    case FFELEX_typeEOS:
	    case FFELEX_typeSEMICOLON:
	      break;

	    default:
	      eos = ffelex_token_new_eos (ffelex_token_where_line (t),
					  ffelex_token_where_column (t));
	      ffesta_inhibit_confirmation_ = ffesta_current_shutdown_;
	      (*ffesta_current_handler_) (eos);
	      ffesta_inhibit_confirmation_ = FALSE;
	      ffelex_token_kill (eos);
	      break;
	    }
	  goto next_handler;	/* :::::::::::::::::::: */
	}
    }

  /* Finished sending all the tokens so far.  If still trying possibilities,
     then if we've just sent an EOS or SEMICOLON token through, go to the
     next handler.  Otherwise, return self so we can gather and process more
     tokens. */

  if (ffesta_is_inhibited_)
    {
      switch (ffelex_token_type (t))
	{
	case FFELEX_typeEOS:
	case FFELEX_typeSEMICOLON:
	  goto next_handler;	/* :::::::::::::::::::: */

	default:
#if FFESTA_ABORT_ON_CONFIRM_
	  assert (!ffesta_confirmed_other_);	/* Catch ambiguities. */
#endif
	  return (ffelexHandler) ffesta_save_;
	}
    }

  /* This was the one final possibility, uninhibited, so send the final
     handler it sent. */

  num_saved_tokens = 0;
#if !FFESTA_ABORT_ON_CONFIRM_
  if (ffesta_is_two_into_statement_)
    {				/* End of the line for the previous two
				   tokens, resurrect them. */
      ffelexHandler next;

      ffesta_is_two_into_statement_ = FALSE;
      next = (ffelexHandler) ffesta_first (ffesta_twotokens_1_);
      ffelex_token_kill (ffesta_twotokens_1_);
      next = (ffelexHandler) (*next) (ffesta_twotokens_2_);
      ffelex_token_kill (ffesta_twotokens_2_);
      return (ffelexHandler) next;
    }
#endif

  assert (ffesta_current_handler_ != NULL);
  return (ffelexHandler) ffesta_current_handler_;
}

/* ffesta_second_ -- Parse the token after a NAME/NAMES in a statement

   return ffesta_second_;  // to lexer.

   The second token cannot be a NAMES, since the first token is a NAME or
   NAMES.  If the second token is a NAME, look up its name in the list of
   second names for use by whoever needs it.

   Then make a list of all the possible statements this could be, based on
   looking at the first two tokens.  Two lists of possible statements are
   created, one consisting of nonexecutable statements, the other consisting
   of executable statements.

   If the total number of possibilities is one, just fire up that
   possibility by calling its handler function, passing the first two
   tokens through it and so on.

   Otherwise, start up a process whereby tokens are passed to the first
   possibility on the list until EOS or SEMICOLON is reached or an error
   is detected.	 But inhibit any actual reporting of errors; just record
   their existence in the list.	 If EOS or SEMICOLON is reached with no
   errors (other than non-form errors happening downstream, such as an
   overflowing value for an integer or a GOTO statement identifying a label
   on a FORMAT statement), then that is the only possible statement.  Rerun
   the statement with error-reporting turned on if any non-form errors were
   generated, otherwise just use its results, then erase the list of tokens
   memorized during the search process.	 If a form error occurs, immediately
   cancel that possibility by sending EOS as the next token, remember the
   error code for that possibility, and try the next possibility on the list,
   first sending it the list of tokens memorized while handling the first
   possibility, then continuing on as before.

   Ultimately, either the end of the list of possibilities will be reached
   without any successful forms being detected, in which case we pick one
   based on hueristics (usually the first possibility) and rerun it with
   error reporting turned on using the list of memorized tokens so the user
   sees the error, or one of the possibilities will effectively succeed.  */

static ffelexHandler
ffesta_second_ (ffelexToken t)
{
  ffelexHandler next;
  ffesymbol s;

  assert (ffelex_token_type (t) != FFELEX_typeNAMES);

  if (ffelex_token_type (t) == FFELEX_typeNAME)
    ffesta_second_kw = ffestr_second (t);

  /* Here we use switch on the first keyword name and handle each possible
     recognizable name by looking at the second token, and building the list
     of possible names accordingly.  For now, just put every possible
     statement on the list for ambiguity checking. */

  switch (ffesta_first_kw)
    {
#if FFESTR_VXT
    case FFESTR_firstACCEPT:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_V019);
      break;
#endif

#if FFESTR_F90
    case FFESTR_firstALLOCATABLE:
      ffestb_args.dimlist.len = FFESTR_firstlALLOCATABLE;
      ffestb_args.dimlist.badname = "ALLOCATABLE";
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_dimlist);
      break;
#endif

#if FFESTR_F90
    case FFESTR_firstALLOCATE:
      ffestb_args.heap.len = FFESTR_firstlALLOCATE;
      ffestb_args.heap.badname = "ALLOCATE";
      ffestb_args.heap.ctx = FFEEXPR_contextALLOCATE;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_heap);
      break;
#endif

    case FFESTR_firstASSIGN:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R838);
      break;

    case FFESTR_firstBACKSPACE:
      ffestb_args.beru.len = FFESTR_firstlBACKSPACE;
      ffestb_args.beru.badname = "BACKSPACE";
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_beru);
      break;

    case FFESTR_firstBLOCK:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_block);
      break;

    case FFESTR_firstBLOCKDATA:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_blockdata);
      break;

    case FFESTR_firstBYTE:
      ffestb_args.decl.len = FFESTR_firstlBYTE;
      ffestb_args.decl.type = FFESTP_typeBYTE;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
      break;

    case FFESTR_firstCALL:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R1212);
      break;

    case FFESTR_firstCASE:
    case FFESTR_firstCASEDEFAULT:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R810);
      break;

    case FFESTR_firstCHRCTR:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_chartype);
      break;

    case FFESTR_firstCLOSE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R907);
      break;

    case FFESTR_firstCOMMON:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R547);
      break;

    case FFESTR_firstCMPLX:
      ffestb_args.decl.len = FFESTR_firstlCMPLX;
      ffestb_args.decl.type = FFESTP_typeCOMPLEX;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
      break;

#if FFESTR_F90
    case FFESTR_firstCONTAINS:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R1228);
      break;
#endif

    case FFESTR_firstCONTINUE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R841);
      break;

    case FFESTR_firstCYCLE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R834);
      break;

    case FFESTR_firstDATA:
      if (ffe_is_pedantic_not_90 ())
	ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R528);
      else
	ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R528);
      break;

#if FFESTR_F90
    case FFESTR_firstDEALLOCATE:
      ffestb_args.heap.len = FFESTR_firstlDEALLOCATE;
      ffestb_args.heap.badname = "DEALLOCATE";
      ffestb_args.heap.ctx = FFEEXPR_contextDEALLOCATE;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_heap);
      break;
#endif

#if FFESTR_VXT
    case FFESTR_firstDECODE:
      ffestb_args.vxtcode.len = FFESTR_firstlDECODE;
      ffestb_args.vxtcode.badname = "DECODE";
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_vxtcode);
      break;
#endif

#if FFESTR_VXT
    case FFESTR_firstDEFINEFILE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_V025);
      break;

    case FFESTR_firstDELETE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_V021);
      break;
#endif
    case FFESTR_firstDIMENSION:
      ffestb_args.R524.len = FFESTR_firstlDIMENSION;
      ffestb_args.R524.badname = "DIMENSION";
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R524);
      break;

    case FFESTR_firstDO:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_do);
      break;

    case FFESTR_firstDBL:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_double);
      break;

    case FFESTR_firstDBLCMPLX:
      ffestb_args.decl.len = FFESTR_firstlDBLCMPLX;
      ffestb_args.decl.type = FFESTP_typeDBLCMPLX;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_dbltype);
      break;

    case FFESTR_firstDBLPRCSN:
      ffestb_args.decl.len = FFESTR_firstlDBLPRCSN;
      ffestb_args.decl.type = FFESTP_typeDBLPRCSN;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_dbltype);
      break;

    case FFESTR_firstDOWHILE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_dowhile);
      break;

    case FFESTR_firstELSE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_else);
      break;

    case FFESTR_firstELSEIF:
      ffestb_args.elsexyz.second = FFESTR_secondIF;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_elsexyz);
      break;

#if FFESTR_F90
    case FFESTR_firstELSEWHERE:
      ffestb_args.elsexyz.second = FFESTR_secondWHERE;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_elsexyz);
      break;
#endif

#if FFESTR_VXT
    case FFESTR_firstENCODE:
      ffestb_args.vxtcode.len = FFESTR_firstlENCODE;
      ffestb_args.vxtcode.badname = "ENCODE";
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_vxtcode);
      break;
#endif

    case FFESTR_firstEND:
      if ((ffelex_token_type (ffesta_token_0_) == FFELEX_typeNAMES)
	  || (ffelex_token_type (t) != FFELEX_typeNAME))
	ffesta_add_possible_exec_ ((ffelexHandler) ffestb_end);
      else
	{
	  switch (ffesta_second_kw)
	    {
	    case FFESTR_secondBLOCK:
	    case FFESTR_secondBLOCKDATA:
	    case FFESTR_secondDO:
	    case FFESTR_secondFILE:
	    case FFESTR_secondFUNCTION:
	    case FFESTR_secondIF:
#if FFESTR_F90
	    case FFESTR_secondMODULE:
#endif
	    case FFESTR_secondPROGRAM:
	    case FFESTR_secondSELECT:
	    case FFESTR_secondSUBROUTINE:
#if FFESTR_F90
	    case FFESTR_secondWHERE:
#endif
	      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_end);
	      break;

	    default:
	      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_end);
	      break;
	    }
	}
      break;

    case FFESTR_firstENDBLOCK:
      ffestb_args.endxyz.len = FFESTR_firstlENDBLOCK;
      ffestb_args.endxyz.second = FFESTR_secondBLOCK;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
      break;

    case FFESTR_firstENDBLOCKDATA:
      ffestb_args.endxyz.len = FFESTR_firstlENDBLOCKDATA;
      ffestb_args.endxyz.second = FFESTR_secondBLOCKDATA;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
      break;

    case FFESTR_firstENDDO:
      ffestb_args.endxyz.len = FFESTR_firstlENDDO;
      ffestb_args.endxyz.second = FFESTR_secondDO;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
      break;

    case FFESTR_firstENDFILE:
      ffestb_args.beru.len = FFESTR_firstlENDFILE;
      ffestb_args.beru.badname = "ENDFILE";
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_beru);
      break;

    case FFESTR_firstENDFUNCTION:
      ffestb_args.endxyz.len = FFESTR_firstlENDFUNCTION;
      ffestb_args.endxyz.second = FFESTR_secondFUNCTION;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
      break;

    case FFESTR_firstENDIF:
      ffestb_args.endxyz.len = FFESTR_firstlENDIF;
      ffestb_args.endxyz.second = FFESTR_secondIF;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
      break;

#if FFESTR_F90
    case FFESTR_firstENDINTERFACE:
      ffestb_args.endxyz.len = FFESTR_firstlENDINTERFACE;
      ffestb_args.endxyz.second = FFESTR_secondINTERFACE;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_endxyz);
      break;
#endif

#if FFESTR_VXT
    case FFESTR_firstENDMAP:
      ffestb_args.endxyz.len = FFESTR_firstlENDMAP;
      ffestb_args.endxyz.second = FFESTR_secondMAP;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_endxyz);
      break;
#endif

#if FFESTR_F90
    case FFESTR_firstENDMODULE:
      ffestb_args.endxyz.len = FFESTR_firstlENDMODULE;
      ffestb_args.endxyz.second = FFESTR_secondMODULE;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
      break;
#endif

    case FFESTR_firstENDPROGRAM:
      ffestb_args.endxyz.len = FFESTR_firstlENDPROGRAM;
      ffestb_args.endxyz.second = FFESTR_secondPROGRAM;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
      break;

    case FFESTR_firstENDSELECT:
      ffestb_args.endxyz.len = FFESTR_firstlENDSELECT;
      ffestb_args.endxyz.second = FFESTR_secondSELECT;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
      break;

#if FFESTR_VXT
    case FFESTR_firstENDSTRUCTURE:
      ffestb_args.endxyz.len = FFESTR_firstlENDSTRUCTURE;
      ffestb_args.endxyz.second = FFESTR_secondSTRUCTURE;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_endxyz);
      break;
#endif

    case FFESTR_firstENDSUBROUTINE:
      ffestb_args.endxyz.len = FFESTR_firstlENDSUBROUTINE;
      ffestb_args.endxyz.second = FFESTR_secondSUBROUTINE;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
      break;

#if FFESTR_F90
    case FFESTR_firstENDTYPE:
      ffestb_args.endxyz.len = FFESTR_firstlENDTYPE;
      ffestb_args.endxyz.second = FFESTR_secondTYPE;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_endxyz);
      break;
#endif

#if FFESTR_VXT
    case FFESTR_firstENDUNION:
      ffestb_args.endxyz.len = FFESTR_firstlENDUNION;
      ffestb_args.endxyz.second = FFESTR_secondUNION;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_endxyz);
      break;
#endif

#if FFESTR_F90
    case FFESTR_firstENDWHERE:
      ffestb_args.endxyz.len = FFESTR_firstlENDWHERE;
      ffestb_args.endxyz.second = FFESTR_secondWHERE;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
      break;
#endif

    case FFESTR_firstENTRY:
      ffestb_args.dummy.len = FFESTR_firstlENTRY;
      ffestb_args.dummy.badname = "ENTRY";
      ffestb_args.dummy.is_subr = ffestc_is_entry_in_subr ();
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_dummy);
      break;

    case FFESTR_firstEQUIVALENCE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R544);
      break;

    case FFESTR_firstEXIT:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R835);
      break;

    case FFESTR_firstEXTERNAL:
      ffestb_args.varlist.len = FFESTR_firstlEXTERNAL;
      ffestb_args.varlist.badname = "EXTERNAL";
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_varlist);
      break;

#if FFESTR_VXT
    case FFESTR_firstFIND:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_V026);
      break;
#endif

      /* WARNING: don't put anything that might cause an item to precede
	 FORMAT in the list of possible statements (it's added below) without
	 making sure FORMAT still is first.  It has to run with
	 ffelex_set_names_pure(TRUE), to make sure the lexer delivers NAMES
	 tokens. */

    case FFESTR_firstFORMAT:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R1001);
      break;

    case FFESTR_firstFUNCTION:
      ffestb_args.dummy.len = FFESTR_firstlFUNCTION;
      ffestb_args.dummy.badname = "FUNCTION";
      ffestb_args.dummy.is_subr = FALSE;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_dummy);
      break;

    case FFESTR_firstGOTO:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_goto);
      break;

    case FFESTR_firstIF:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_if);
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R840);
      break;

    case FFESTR_firstIMPLICIT:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_R539);
      break;

    case FFESTR_firstINCLUDE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_S3P4);
      switch (ffelex_token_type (t))
	{
	case FFELEX_typeNUMBER:
	case FFELEX_typeNAME:
	case FFELEX_typeAPOSTROPHE:
	case FFELEX_typeQUOTE:
	  break;

	default:
	  break;
	}
      break;

    case FFESTR_firstINQUIRE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R923);
      break;

    case FFESTR_firstINTGR:
      ffestb_args.decl.len = FFESTR_firstlINTGR;
      ffestb_args.decl.type = FFESTP_typeINTEGER;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
      break;

#if FFESTR_F90
    case FFESTR_firstINTENT:
      ffestb_args.varlist.len = FFESTR_firstlINTENT;
      ffestb_args.varlist.badname = "INTENT";
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_varlist);
      break;
#endif

#if FFESTR_F90
    case FFESTR_firstINTERFACE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R1202);
      break;
#endif

    case FFESTR_firstINTRINSIC:
      ffestb_args.varlist.len = FFESTR_firstlINTRINSIC;
      ffestb_args.varlist.badname = "INTRINSIC";
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_varlist);
      break;

    case FFESTR_firstLGCL:
      ffestb_args.decl.len = FFESTR_firstlLGCL;
      ffestb_args.decl.type = FFESTP_typeLOGICAL;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
      break;

#if FFESTR_VXT
    case FFESTR_firstMAP:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_V012);
      break;
#endif

#if FFESTR_F90
    case FFESTR_firstMODULE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_module);
      break;
#endif

    case FFESTR_firstNAMELIST:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R542);
      break;

#if FFESTR_F90
    case FFESTR_firstNULLIFY:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R624);
      break;
#endif

    case FFESTR_firstOPEN:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R904);
      break;

#if FFESTR_F90
    case FFESTR_firstOPTIONAL:
      ffestb_args.varlist.len = FFESTR_firstlOPTIONAL;
      ffestb_args.varlist.badname = "OPTIONAL";
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_varlist);
      break;
#endif

    case FFESTR_firstPARAMETER:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R537);
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_V027);
      break;

    case FFESTR_firstPAUSE:
      ffestb_args.halt.len = FFESTR_firstlPAUSE;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_halt);
      break;

#if FFESTR_F90
    case FFESTR_firstPOINTER:
      ffestb_args.dimlist.len = FFESTR_firstlPOINTER;
      ffestb_args.dimlist.badname = "POINTER";
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_dimlist);
      break;
#endif

    case FFESTR_firstPRINT:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R911);
      break;

#if HARD_F90
    case FFESTR_firstPRIVATE:
      ffestb_args.varlist.len = FFESTR_firstlPRIVATE;
      ffestb_args.varlist.badname = "ACCESS";
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_varlist);
      break;
#endif

    case FFESTR_firstPROGRAM:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R1102);
      break;

#if HARD_F90
    case FFESTR_firstPUBLIC:
      ffestb_args.varlist.len = FFESTR_firstlPUBLIC;
      ffestb_args.varlist.badname = "ACCESS";
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_varlist);
      break;
#endif

    case FFESTR_firstREAD:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R909);
      break;

    case FFESTR_firstREAL:
      ffestb_args.decl.len = FFESTR_firstlREAL;
      ffestb_args.decl.type = FFESTP_typeREAL;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
      break;

#if FFESTR_VXT
    case FFESTR_firstRECORD:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_V016);
      break;
#endif

#if FFESTR_F90
    case FFESTR_firstRECURSIVE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_recursive);
      break;
#endif

    case FFESTR_firstRETURN:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R1227);
      break;

    case FFESTR_firstREWIND:
      ffestb_args.beru.len = FFESTR_firstlREWIND;
      ffestb_args.beru.badname = "REWIND";
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_beru);
      break;

#if FFESTR_VXT
    case FFESTR_firstREWRITE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_V018);
      break;
#endif

    case FFESTR_firstSAVE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R522);
      break;

    case FFESTR_firstSELECT:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R809);
      break;

    case FFESTR_firstSELECTCASE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R809);
      break;

#if HARD_F90
    case FFESTR_firstSEQUENCE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R423B);
      break;
#endif

    case FFESTR_firstSTOP:
      ffestb_args.halt.len = FFESTR_firstlSTOP;
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_halt);
      break;

#if FFESTR_VXT
    case FFESTR_firstSTRUCTURE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_V003);
      break;
#endif

    case FFESTR_firstSUBROUTINE:
      ffestb_args.dummy.len = FFESTR_firstlSUBROUTINE;
      ffestb_args.dummy.badname = "SUBROUTINE";
      ffestb_args.dummy.is_subr = TRUE;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_dummy);
      break;

#if FFESTR_F90
    case FFESTR_firstTARGET:
      ffestb_args.dimlist.len = FFESTR_firstlTARGET;
      ffestb_args.dimlist.badname = "TARGET";
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_dimlist);
      break;
#endif

    case FFESTR_firstTYPE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_V020);
      break;

#if FFESTR_F90
    case FFESTR_firstTYPE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_type);
      break;
#endif

#if HARD_F90
    case FFESTR_firstTYPE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_typetype);
      break;
#endif

#if FFESTR_VXT
    case FFESTR_firstUNLOCK:
      ffestb_args.beru.len = FFESTR_firstlUNLOCK;
      ffestb_args.beru.badname = "UNLOCK";
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_beru);
      break;
#endif

#if FFESTR_VXT
    case FFESTR_firstUNION:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_V009);
      break;
#endif

#if FFESTR_F90
    case FFESTR_firstUSE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R1107);
      break;
#endif

    case FFESTR_firstVIRTUAL:
      ffestb_args.R524.len = FFESTR_firstlVIRTUAL;
      ffestb_args.R524.badname = "VIRTUAL";
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R524);
      break;

    case FFESTR_firstVOLATILE:
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_V014);
      break;

#if HARD_F90
    case FFESTR_firstWHERE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_where);
      break;
#endif

    case FFESTR_firstWORD:
      ffestb_args.decl.len = FFESTR_firstlWORD;
      ffestb_args.decl.type = FFESTP_typeWORD;
      ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
      break;

    case FFESTR_firstWRITE:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R910);
      break;

    default:
      break;
    }

  /* Now check the default cases, which are always "live" (meaning that no
     other possibility can override them).  These are where the second token
     is OPEN_PAREN, PERCENT, EQUALS, POINTS, or COLON. */

  switch (ffelex_token_type (t))
    {
    case FFELEX_typeOPEN_PAREN:
      s = ffesymbol_lookup_local (ffesta_token_0_);
      if (((s == NULL) || (ffesymbol_dims (s) == NULL))
	  && !ffesta_seen_first_exec)
	{			/* Not known as array; may be stmt function. */
	  ffesta_add_possible_unnamed_nonexec_ ((ffelexHandler) ffestb_R1229);

	  /* If the symbol is (or will be due to implicit typing) of
	     CHARACTER type, then the statement might be an assignment
	     statement.	 If so, since it can't be a function invocation nor
	     an array element reference, the open paren following the symbol
	     name must be followed by an expression and a colon.  Without the
	     colon (which cannot appear in a stmt function definition), the
	     let stmt rejects.	So CHARACTER_NAME(...)=expr, unlike any other
	     type, is not ambiguous alone. */

	  if (ffeimplic_peek_symbol_type (s,
					ffelex_token_text (ffesta_token_0_))
	      == FFEINFO_basictypeCHARACTER)
	    ffesta_add_possible_unnamed_exec_ ((ffelexHandler) ffestb_let);
	}
      else			/* Not statement function if known as an
				   array. */
	ffesta_add_possible_unnamed_exec_ ((ffelexHandler) ffestb_let);
      break;

#if FFESTR_F90
    case FFELEX_typePERCENT:
#endif
    case FFELEX_typeEQUALS:
#if FFESTR_F90
    case FFELEX_typePOINTS:
#endif
      ffesta_add_possible_unnamed_exec_ ((ffelexHandler) ffestb_let);
      break;

    case FFELEX_typeCOLON:
      ffesta_add_possible_exec_ ((ffelexHandler) ffestb_construct);
      break;

    default:
      ;
    }

  /* Now see how many possibilities are on the list. */

  switch (ffesta_num_possibles_)
    {
    case 0:			/* None, so invalid statement. */
    no_stmts:			/* :::::::::::::::::::: */
      ffesta_tokens[0] = ffesta_token_0_;
      ffesta_ffebad_2t (FFEBAD_UNREC_STMT, ffesta_token_0_, t);
      next = (ffelexHandler) ffelex_swallow_tokens (NULL,
					       (ffelexHandler) ffesta_zero);
      break;

    case 1:			/* One, so just do it! */
      ffesta_tokens[0] = ffesta_token_0_;
      next = ffesta_possible_execs_.first->handler;
      if (next == NULL)
	{			/* Have a nonexec stmt. */
	  next = ffesta_possible_nonexecs_.first->handler;
	  assert (next != NULL);
	}
      else if (ffesta_seen_first_exec)
	;			/* Have an exec stmt after exec transition. */
      else if (!ffestc_exec_transition ())
	/* 1 exec stmt only, but not valid in context, so pretend as though
	   statement is unrecognized. */
	goto no_stmts;		/* :::::::::::::::::::: */
      break;

    default:			/* More than one, so try them in order. */
      ffesta_confirmed_possible_ = NULL;
      ffesta_current_possible_ = ffesta_possible_nonexecs_.first;
      ffesta_current_handler_ = ffesta_current_possible_->handler;
      if (ffesta_current_handler_ == NULL)
	{
	  ffesta_current_possible_ = ffesta_possible_execs_.first;
	  ffesta_current_handler_ = ffesta_current_possible_->handler;
	  assert (ffesta_current_handler_ != NULL);
	  if (!ffesta_seen_first_exec)
	    {			/* Need to do exec transition now. */
	      ffesta_tokens[0] = ffesta_token_0_;
	      if (!ffestc_exec_transition ())
		goto no_stmts;	/* :::::::::::::::::::: */
	    }
	}
      ffesta_tokens[0] = ffelex_token_use (ffesta_token_0_);
      next = (ffelexHandler) ffesta_save_;
      ffebad_set_inhibit (TRUE);
      ffesta_is_inhibited_ = TRUE;
      break;
    }

  ffesta_output_pool
    = malloc_pool_new ("Statement Output", ffe_pool_program_unit (), 1024);
  ffesta_scratch_pool
    = malloc_pool_new ("Statement Scratch", ffe_pool_program_unit (), 1024);
  ffesta_outpooldisp_ = FFESTA_pooldispDISCARD;

  if (ffesta_is_inhibited_)
    ffesymbol_set_retractable (ffesta_scratch_pool);

  ffelex_set_names (FALSE);	/* Most handlers will want this.  If not,
				   they have to set it TRUE again (its value
				   at the beginning of a statement). */

  return (ffelexHandler) (*next) (t);
}

/* ffesta_send_two_ -- Send the two tokens saved by ffesta_two after all

   return ffesta_send_two_;  // to lexer.

   Currently, if this function gets called, it means that the two tokens
   saved by ffesta_two did not have their handlers derailed by
   ffesta_save_, which probably means they weren't sent by ffesta_save_
   but directly by the lexer, which probably means the original statement
   (which should be IF (expr) or WHERE (expr)) somehow evaluated to only
   one possibility in ffesta_second_ or somebody optimized FFEST to
   immediately revert to one possibility upon confirmation but forgot to
   change this function (and thus perhaps the entire resubmission
   mechanism).	*/

#if !FFESTA_ABORT_ON_CONFIRM_
static ffelexHandler
ffesta_send_two_ (ffelexToken t)
{
  assert ("what am I doing here?" == NULL);
  return NULL;
}

#endif
/* ffesta_confirmed -- Confirm current possibility as only one

   ffesta_confirmed();

   Sets the confirmation flag.	During debugging for ambiguous constructs,
   asserts that the confirmation flag for a previous possibility has not
   yet been set.  */

void
ffesta_confirmed ()
{
  if (ffesta_inhibit_confirmation_)
    return;
  ffesta_confirmed_current_ = TRUE;
  assert (!ffesta_confirmed_other_
	  || (ffesta_confirmed_possible_ == ffesta_current_possible_));
  ffesta_confirmed_possible_ = ffesta_current_possible_;
}

/* ffesta_eof -- End of (non-INCLUDEd) source file

   ffesta_eof();

   Call after piping tokens through ffest_first, where the most recent
   token sent through must be EOS.

   20-Feb-91  JCB  1.1
      Put new EOF token in ffesta_tokens[0], not NULL, because too much
      code expects something there for error reporting and the like.  Also,
      do basically the same things ffest_second and ffesta_zero do for
      processing a statement (make and destroy pools, et cetera).  */

void
ffesta_eof ()
{
  ffesta_tokens[0] = ffelex_token_new_eof ();

  ffesta_output_pool
    = malloc_pool_new ("Statement Output", ffe_pool_program_unit (), 1024);
  ffesta_scratch_pool
    = malloc_pool_new ("Statement Scratch", ffe_pool_program_unit (), 1024);
  ffesta_outpooldisp_ = FFESTA_pooldispDISCARD;

  ffestc_eof ();

  if (ffesta_tokens[0] != NULL)
    ffelex_token_kill (ffesta_tokens[0]);

  if (ffesta_output_pool != NULL)
    {
      if (ffesta_outpooldisp_ == FFESTA_pooldispDISCARD)
	malloc_pool_kill (ffesta_output_pool);
      ffesta_output_pool = NULL;
    }

  if (ffesta_scratch_pool != NULL)
    {
      malloc_pool_kill (ffesta_scratch_pool);
      ffesta_scratch_pool = NULL;
    }

  if (ffesta_label_token != NULL)
    {
      ffelex_token_kill (ffesta_label_token);
      ffesta_label_token = NULL;
    }

  if (ffe_is_ffedebug ())
    {
      ffestorag_report ();
#if FFECOM_targetCURRENT == FFECOM_targetFFE
      ffesymbol_report_all ();
#endif
    }
}

/* ffesta_ffebad_here_current_stmt -- ffebad_here with ptr to current stmt

   ffesta_ffebad_here_current_stmt(0);

   Outsiders can call this fn if they have no more convenient place to
   point to (via a token or pair of ffewhere objects) and they know a
   current, useful statement is being evaluted by ffest (i.e. they are
   being called from ffestb, ffestc, ffestd, ... functions).  */

void
ffesta_ffebad_here_current_stmt (ffebadIndex i)
{
  assert (ffesta_tokens[0] != NULL);
  ffebad_here (i, ffelex_token_where_line (ffesta_tokens[0]),
	       ffelex_token_where_column (ffesta_tokens[0]));
}

/* ffesta_ffebad_start -- Start a possibly inhibited error report

   if (ffesta_ffebad_start(FFEBAD_SOME_ERROR))
       {
       ffebad_here, ffebad_string ...;
       ffebad_finish();
       }

   Call if the error might indicate that ffest is evaluating the wrong
   statement form, instead of calling ffebad_start directly.  If ffest
   is choosing between forms, it will return FALSE, send an EOS/SEMICOLON
   token through as the next token (if the current one isn't already one
   of those), and try another possible form.  Otherwise, ffebad_start is
   called with the argument and TRUE returned.	*/

bool
ffesta_ffebad_start (ffebad errnum)
{
  if (!ffesta_is_inhibited_)
    {
      ffebad_start (errnum);
      return TRUE;
    }

  if (!ffesta_confirmed_current_)
    ffesta_current_shutdown_ = TRUE;

  return FALSE;
}

/* ffesta_first -- Parse the first token in a statement

   return ffesta_first;	 // to lexer.  */

ffelexHandler
ffesta_first (ffelexToken t)
{
  switch (ffelex_token_type (t))
    {
    case FFELEX_typeSEMICOLON:
    case FFELEX_typeEOS:
      ffesta_tokens[0] = ffelex_token_use (t);
      if (ffesta_label_token != NULL)
	{
	  ffebad_start (FFEBAD_LABEL_WITHOUT_STMT);
	  ffebad_here (0, ffelex_token_where_line (ffesta_label_token),
		       ffelex_token_where_column (ffesta_label_token));
	  ffebad_string (ffelex_token_text (ffesta_label_token));
	  ffebad_here (1, ffelex_token_where_line (t), ffelex_token_where_column (t));
	  ffebad_finish ();
	}
      return (ffelexHandler) ffesta_zero (t);

    case FFELEX_typeNAME:
    case FFELEX_typeNAMES:
      ffesta_token_0_ = ffelex_token_use (t);
      ffesta_first_kw = ffestr_first (t);
      return (ffelexHandler) ffesta_second_;

    case FFELEX_typeNUMBER:
      if (ffesta_line_has_semicolons
	  && !ffe_is_free_form ()
	  && ffe_is_pedantic ())
	{
	  ffebad_start (FFEBAD_LABEL_WRONG_PLACE);
	  ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
	  ffebad_string (ffelex_token_text (t));
	  ffebad_finish ();
	}
      if (ffesta_label_token == NULL)
	{
	  ffesta_label_token = ffelex_token_use (t);
	  return (ffelexHandler) ffesta_first;
	}
      else
	{
	  ffebad_start (FFEBAD_EXTRA_LABEL_DEF);
	  ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
	  ffebad_string (ffelex_token_text (t));
	  ffebad_here (1, ffelex_token_where_line (ffesta_label_token),
		       ffelex_token_where_column (ffesta_label_token));
	  ffebad_string (ffelex_token_text (ffesta_label_token));
	  ffebad_finish ();

	  return (ffelexHandler) ffesta_first;
	}

    default:			/* Invalid first token. */
      ffesta_tokens[0] = ffelex_token_use (t);
      ffebad_start (FFEBAD_STMT_BEGINS_BAD);
      ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
      ffebad_finish ();
      return (ffelexHandler) ffelex_swallow_tokens (t,
					       (ffelexHandler) ffesta_zero);
    }
}

/* ffesta_init_0 -- Initialize for entire image invocation

   ffesta_init_0();

   Call just once per invocation of the compiler (not once per invocation
   of the front end).

   Gets memory for the list of possibles once and for all, since this
   list never gets larger than a certain size (FFESTA_maxPOSSIBLES_)
   and is not particularly large.  Initializes the array of pointers to
   this list.  Initializes the executable and nonexecutable lists.  */

void
ffesta_init_0 ()
{
  ffestaPossible_ ptr;
  int i;

  ptr = (ffestaPossible_) malloc_new_kp (malloc_pool_image (),
					 "FFEST possibles",
					 FFESTA_maxPOSSIBLES_
					 * sizeof (*ptr));

  for (i = 0; i < FFESTA_maxPOSSIBLES_; ++i)
    ffesta_possibles_[i] = ptr++;

  ffesta_possible_execs_.first = ffesta_possible_execs_.last
    = (ffestaPossible_) &ffesta_possible_execs_.first;
  ffesta_possible_nonexecs_.first = ffesta_possible_nonexecs_.last
    = (ffestaPossible_) &ffesta_possible_nonexecs_.first;
  ffesta_possible_execs_.nil = ffesta_possible_nonexecs_.nil = NULL;
}

/* ffesta_init_3 -- Initialize for any program unit

   ffesta_init_3();  */

void
ffesta_init_3 ()
{
  ffesta_output_pool = NULL;	/* May be doing this just before reaching */
  ffesta_scratch_pool = NULL;	/* ffesta_zero or ffesta_two. */
  /* NOTE: we let the ffe_terminate_2 action of killing the program_unit pool
     handle the killing of the output and scratch pools for us, which is why
     we don't have a terminate_3 action to do so. */
  ffesta_construct_name = NULL;
  ffesta_label_token = NULL;
  ffesta_seen_first_exec = FALSE;
}

/* ffesta_is_inhibited -- Test whether the current possibility is inhibited

   if (!ffesta_is_inhibited())
       // implement the statement.

   Just make sure the current possibility has been confirmed.  If anyone
   really needs to test whether the current possibility is inhibited prior
   to confirming it, that indicates a need to begin statement processing
   before it is certain that the given possibility is indeed the statement
   to be processed.  As of this writing, there does not appear to be such
   a need.  If there is, then when confirming a statement would normally
   immediately disable the inhibition (whereas currently we leave the
   confirmed statement disabled until we've tried the other possibilities,
   to check for ambiguities), we must check to see if the possibility has
   already tested for inhibition prior to confirmation and, if so, maintain
   inhibition until the end of the statement (which may be forced right
   away) and then rerun the entire statement from the beginning.  Otherwise,
   initial calls to ffestb functions won't have been made, but subsequent
   calls (after confirmation) will, which is wrong.  Of course, this all
   applies only to those statements implemented via multiple calls to
   ffestb, although if a statement requiring only a single ffestb call
   tested for inhibition prior to confirmation, it would likely mean that
   the ffestb call would be completely dropped without this mechanism.	*/

bool
ffesta_is_inhibited ()
{
  assert (ffesta_confirmed_current_ || ffesta_inhibit_confirmation_);
  return ffesta_is_inhibited_;
}

/* ffesta_ffebad_1p -- Issue diagnostic with one source character

   ffelexToken names_token;
   ffeTokenLength index;
   ffelexToken next_token;
   ffesta_ffebad_1p(FFEBAD_SOME_ERROR,names_token,index,next_token);

   Equivalent to "if (ffest_ffebad_start(FFEBAD_SOME_ERROR))" followed by
   sending one argument, the location of index with names_token, if TRUE is
   returned.  If index is equal to the length of names_token, meaning it
   points to the end of the token, then uses the location in next_token
   (which should be the token sent by the lexer after it sent names_token)
   instead.  */

void
ffesta_ffebad_1p (ffebad errnum, ffelexToken names_token, ffeTokenLength index,
		  ffelexToken next_token)
{
  ffewhereLine line;
  ffewhereColumn col;

  assert (index <= ffelex_token_length (names_token));

  if (ffesta_ffebad_start (errnum))
    {
      if (index == ffelex_token_length (names_token))
	{
	  assert (next_token != NULL);
	  line = ffelex_token_where_line (next_token);
	  col = ffelex_token_where_column (next_token);
	  ffebad_here (0, line, col);
	}
      else
	{
	  ffewhere_set_from_track (&line, &col,
				   ffelex_token_where_line (names_token),
				   ffelex_token_where_column (names_token),
				   ffelex_token_wheretrack (names_token),
				   index);
	  ffebad_here (0, line, col);
	  ffewhere_line_kill (line);
	  ffewhere_column_kill (col);
	}
      ffebad_finish ();
    }
}

void
ffesta_ffebad_1sp (ffebad errnum, char *s, ffelexToken names_token,
		   ffeTokenLength index, ffelexToken next_token)
{
  ffewhereLine line;
  ffewhereColumn col;

  assert (index <= ffelex_token_length (names_token));

  if (ffesta_ffebad_start (errnum))
    {
      ffebad_string (s);
      if (index == ffelex_token_length (names_token))
	{
	  assert (next_token != NULL);
	  line = ffelex_token_where_line (next_token);
	  col = ffelex_token_where_column (next_token);
	  ffebad_here (0, line, col);
	}
      else
	{
	  ffewhere_set_from_track (&line, &col,
				   ffelex_token_where_line (names_token),
				   ffelex_token_where_column (names_token),
				   ffelex_token_wheretrack (names_token),
				   index);
	  ffebad_here (0, line, col);
	  ffewhere_line_kill (line);
	  ffewhere_column_kill (col);
	}
      ffebad_finish ();
    }
}

void
ffesta_ffebad_1st (ffebad errnum, char *s, ffelexToken t)
{
  if (ffesta_ffebad_start (errnum))
    {
      ffebad_string (s);
      ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
      ffebad_finish ();
    }
}

/* ffesta_ffebad_1t -- Issue diagnostic with one source token

   ffelexToken t;
   ffesta_ffebad_1t(FFEBAD_SOME_ERROR,t);

   Equivalent to "if (ffesta_ffebad_start(FFEBAD_SOME_ERROR))" followed by
   sending one argument, the location of the token t, if TRUE is returned.  */

void
ffesta_ffebad_1t (ffebad errnum, ffelexToken t)
{
  if (ffesta_ffebad_start (errnum))
    {
      ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
      ffebad_finish ();
    }
}

void
ffesta_ffebad_2st (ffebad errnum, char *s, ffelexToken t1, ffelexToken t2)
{
  if (ffesta_ffebad_start (errnum))
    {
      ffebad_string (s);
      ffebad_here (0, ffelex_token_where_line (t1), ffelex_token_where_column (t1));
      ffebad_here (1, ffelex_token_where_line (t2), ffelex_token_where_column (t2));
      ffebad_finish ();
    }
}

/* ffesta_ffebad_2t -- Issue diagnostic with two source tokens

   ffelexToken t1, t2;
   ffesta_ffebad_2t(FFEBAD_SOME_ERROR,t1,t2);

   Equivalent to "if (ffesta_ffebad_start(FFEBAD_SOME_ERROR))" followed by
   sending two argument, the locations of the tokens t1 and t2, if TRUE is
   returned.  */

void
ffesta_ffebad_2t (ffebad errnum, ffelexToken t1, ffelexToken t2)
{
  if (ffesta_ffebad_start (errnum))
    {
      ffebad_here (0, ffelex_token_where_line (t1), ffelex_token_where_column (t1));
      ffebad_here (1, ffelex_token_where_line (t2), ffelex_token_where_column (t2));
      ffebad_finish ();
    }
}

ffestaPooldisp
ffesta_outpooldisp ()
{
  return ffesta_outpooldisp_;
}

void
ffesta_set_outpooldisp (ffestaPooldisp d)
{
  ffesta_outpooldisp_ = d;
}

/* Shut down current parsing possibility, but without bothering the
   user with a diagnostic if we're not inhibited.  */

void
ffesta_shutdown ()
{
  if (ffesta_is_inhibited_)
    ffesta_current_shutdown_ = TRUE;
}

/* ffesta_two -- Deal with the first two tokens after a swallowed statement

   return ffesta_two(first_token,second_token);	 // to lexer.

   Like ffesta_zero, except instead of expecting an EOS or SEMICOLON, it
   expects the first two tokens of a statement that is part of another
   statement: the first two tokens of statement in "IF (expr) statement" or
   "WHERE (expr) statement", in particular.  The first token must be a NAME
   or NAMES, the second can be basically anything.  The statement type MUST
   be confirmed by now.

   If we're not inhibited, just handle things as if we were ffesta_zero
   and saw an EOS just before the two tokens.

   If we're inhibited, set ffesta_current_shutdown_ to shut down the current
   statement and continue with other possibilities, then (presumably) come
   back to this one for real when not inhibited.  */

ffelexHandler
ffesta_two (ffelexToken first, ffelexToken second)
{
#if FFESTA_ABORT_ON_CONFIRM_
  ffelexHandler next;
#endif

  assert ((ffelex_token_type (first) == FFELEX_typeNAME)
	  || (ffelex_token_type (first) == FFELEX_typeNAMES));
  assert (ffesta_tokens[0] != NULL);

  if (ffesta_is_inhibited_)	/* Oh, not really done with statement. */
    {
      ffesta_current_shutdown_ = TRUE;
      /* To catch the EOS on shutdown. */
      return (ffelexHandler) ffelex_swallow_tokens (second,
					       (ffelexHandler) ffesta_zero);
    }

  ffestw_display_state ();

  ffelex_token_kill (ffesta_tokens[0]);

  if (ffesta_output_pool != NULL)
    {
      if (ffesta_outpooldisp_ == FFESTA_pooldispDISCARD)
	malloc_pool_kill (ffesta_output_pool);
      ffesta_output_pool = NULL;
    }

  if (ffesta_scratch_pool != NULL)
    {
      malloc_pool_kill (ffesta_scratch_pool);
      ffesta_scratch_pool = NULL;
    }

  ffesta_reset_possibles_ ();
  ffesta_confirmed_current_ = FALSE;

  /* What happens here is somewhat interesting.	 We effectively derail the
     line of handlers for these two tokens, the first two in a statement, by
     setting a flag to TRUE.  This flag tells ffesta_save_ (or, conceivably,
     the lexer via ffesta_second_'s case 1:, where it has only one possible
     kind of statement -- someday this will be more likely, i.e. after
     confirmation causes an immediate switch to only the one context rather
     than just setting a flag and running through the remaining possibles to
     look for ambiguities) that the last two tokens it sent did not reach the
     truly desired targets (ffest_first and ffesta_second_) since that would
     otherwise attempt to recursively invoke ffesta_save_ in most cases,
     while the existing ffesta_save_ was still alive and making use of static
     (nonrecursive) variables.	Instead, ffesta_save_, upon seeing this flag
     set TRUE, sets it to FALSE and resubmits the two tokens copied here to
     ffest_first and, presumably, ffesta_second_, kills them, and returns the
     handler returned by the handler for the second token.  Thus, even though
     ffesta_save_ is still (likely to be) recursively invoked, the former
     invocation is past the use of any static variables possibly changed
     during the first-two-token invocation of the latter invocation. */

#if FFESTA_ABORT_ON_CONFIRM_
  /* Shouldn't be in ffesta_save_ at all here. */

  next = (ffelexHandler) ffesta_first (first);
  return (ffelexHandler) (*next) (second);
#else
  ffesta_twotokens_1_ = ffelex_token_use (first);
  ffesta_twotokens_2_ = ffelex_token_use (second);

  ffesta_is_two_into_statement_ = TRUE;
  return (ffelexHandler) ffesta_send_two_;	/* Shouldn't get called. */
#endif
}

/* ffesta_zero -- Deal with the end of a swallowed statement

   return ffesta_zero;	// to lexer.

   NOTICE that this code is COPIED, largely, into a
   similar function named ffesta_two that gets invoked in place of
   _zero_ when the end of the statement happens before EOS or SEMICOLON and
   to tokens into the next statement have been read (as is the case with the
   logical-IF and WHERE-stmt statements).  So any changes made here should
   probably be made in _two_ at the same time.	*/

ffelexHandler
ffesta_zero (ffelexToken t)
{
  assert ((ffelex_token_type (t) == FFELEX_typeEOS)
	  || (ffelex_token_type (t) == FFELEX_typeSEMICOLON));
  assert (ffesta_tokens[0] != NULL);

  if (ffesta_is_inhibited_)
    ffesymbol_retract (TRUE);
  else
    ffestw_display_state ();

  /* Do CONTINUE if nothing else.  This is done specifically so that "IF
     (...) BLAH" causes the same things to happen as if "IF (...) CONTINUE"
     was done, so that tracking of labels and such works.  (Try a small
     program like "DO 10 ...", "IF (...) BLAH", "10 CONTINUE", "END".)

     But it turns out that just testing "!ffesta_confirmed_current_"
     isn't enough, because then typing "GOTO" instead of "BLAH" above
     doesn't work -- the statement is confirmed (we know the user
     attempted a GOTO) but ffestc hasn't seen it.  So, instead, just
     always tell ffestc to do "any" statement it needs to reset.  */

  if (!ffesta_is_inhibited_
      && ffesta_seen_first_exec)
    {
      ffestc_any ();
    }

  ffelex_token_kill (ffesta_tokens[0]);

  if (ffesta_is_inhibited_)	/* Oh, not really done with statement. */
    return (ffelexHandler) ffesta_zero;	/* Call me again when done! */

  if (ffesta_output_pool != NULL)
    {
      if (ffesta_outpooldisp_ == FFESTA_pooldispDISCARD)
	malloc_pool_kill (ffesta_output_pool);
      ffesta_output_pool = NULL;
    }

  if (ffesta_scratch_pool != NULL)
    {
      malloc_pool_kill (ffesta_scratch_pool);
      ffesta_scratch_pool = NULL;
    }

  ffesta_reset_possibles_ ();
  ffesta_confirmed_current_ = FALSE;

  if (ffelex_token_type (t) == FFELEX_typeSEMICOLON)
    {
      ffesta_line_has_semicolons = TRUE;
      if (ffe_is_pedantic_not_90 ())
	{
	  ffebad_start (FFEBAD_SEMICOLON);
	  ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
	  ffebad_finish ();
	}
    }
  else
    ffesta_line_has_semicolons = FALSE;

  if (ffesta_label_token != NULL)
    {
      ffelex_token_kill (ffesta_label_token);
      ffesta_label_token = NULL;
    }

  if (ffe_is_ffedebug ())
    {
      ffestorag_report ();
#if FFECOM_targetCURRENT == FFECOM_targetFFE
      ffesymbol_report_all ();
#endif
    }

  ffelex_set_names (TRUE);
  return (ffelexHandler) ffesta_first;
}