1 /* sta.c -- Implementation File (module.c template V1.0)
2 Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc.
3 Contributed by James Craig Burley.
5 This file is part of GNU Fortran.
7 GNU Fortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Fortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Fortran; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 Analyzes the first two tokens, figures out what statements are
27 possible, tries parsing the possible statements by calling on
48 /* Externals defined here. */
50 ffelexToken ffesta_tokens[FFESTA_tokensMAX]; /* For use by a possible. */
51 ffestrFirst ffesta_first_kw; /* First NAME(S) looked up. */
52 ffestrSecond ffesta_second_kw; /* Second NAME(S) looked up. */
53 mallocPool ffesta_output_pool; /* Pool for results of stmt handling. */
54 mallocPool ffesta_scratch_pool; /* Pool for stmt scratch handling. */
55 ffelexToken ffesta_construct_name;
56 ffelexToken ffesta_label_token; /* Pending label stuff. */
57 bool ffesta_seen_first_exec;
58 bool ffesta_is_entry_valid = FALSE; /* TRUE only in SUBROUTINE/FUNCTION. */
59 bool ffesta_line_has_semicolons = FALSE;
61 /* Simple definitions and enumerations. */
63 #define FFESTA_ABORT_ON_CONFIRM_ 1 /* 0=slow, tested way; 1=faster way
64 that might not always work. Here's
65 the old description of what used
66 to not work with ==1: (try
68 FORMAT('hi',I11)\END"). Problem
69 is that the "topology" of the
70 confirmed stmt's tokens with
71 regard to CHARACTER, HOLLERITH,
72 NAME/NAMES/NUMBER tokens (like hex
73 numbers), isn't traced if we abort
74 early, then other stmts might get
75 their grubby hands on those
76 unprocessed tokens and commit them
77 improperly. Ideal fix is to rerun
78 the confirmed stmt and forget the
81 #define FFESTA_maxPOSSIBLES_ 8/* Never more than this # of possibles. */
83 /* Internal typedefs. */
85 typedef struct _ffesta_possible_ *ffestaPossible_;
87 /* Private include files. */
90 /* Internal structure definitions. */
92 struct _ffesta_possible_
95 ffestaPossible_ previous;
96 ffelexHandler handler;
100 struct _ffesta_possible_root_
102 ffestaPossible_ first;
103 ffestaPossible_ last;
107 /* Static objects accessed by functions in this module. */
109 static bool ffesta_is_inhibited_ = FALSE;
110 static ffelexToken ffesta_token_0_; /* For use by ffest possibility
112 static ffestaPossible_ ffesta_possibles_[FFESTA_maxPOSSIBLES_];
113 static int ffesta_num_possibles_ = 0; /* Number of possibilities. */
114 static struct _ffesta_possible_root_ ffesta_possible_nonexecs_;
115 static struct _ffesta_possible_root_ ffesta_possible_execs_;
116 static ffestaPossible_ ffesta_current_possible_;
117 static ffelexHandler ffesta_current_handler_;
118 static bool ffesta_confirmed_current_ = FALSE;
119 static bool ffesta_confirmed_other_ = FALSE;
120 static ffestaPossible_ ffesta_confirmed_possible_;
121 static bool ffesta_current_shutdown_ = FALSE;
122 #if !FFESTA_ABORT_ON_CONFIRM_
123 static bool ffesta_is_two_into_statement_ = FALSE; /* For IF, WHERE stmts. */
124 static ffelexToken ffesta_twotokens_1_; /* For IF, WHERE stmts. */
125 static ffelexToken ffesta_twotokens_2_; /* For IF, WHERE stmts. */
127 static ffestaPooldisp ffesta_outpooldisp_; /* After statement dealt
129 static bool ffesta_inhibit_confirmation_ = FALSE;
131 /* Static functions (internal). */
133 static void ffesta_add_possible_ (ffelexHandler fn, bool exec, bool named);
134 static bool ffesta_inhibited_exec_transition_ (void);
135 static void ffesta_reset_possibles_ (void);
136 static ffelexHandler ffesta_save_ (ffelexToken t);
137 static ffelexHandler ffesta_second_ (ffelexToken t);
138 #if !FFESTA_ABORT_ON_CONFIRM_
139 static ffelexHandler ffesta_send_two_ (ffelexToken t);
142 /* Internal macros. */
144 #define ffesta_add_possible_exec_(fn) (ffesta_add_possible_ (fn, TRUE, TRUE))
145 #define ffesta_add_possible_nonexec_(fn) (ffesta_add_possible_ (fn, FALSE, TRUE))
146 #define ffesta_add_possible_unnamed_exec_(fn) (ffesta_add_possible_ (fn, TRUE, FALSE))
147 #define ffesta_add_possible_unnamed_nonexec_(fn) (ffesta_add_possible_ (fn, FALSE, FALSE))
149 /* Add possible statement to appropriate list. */
152 ffesta_add_possible_ (ffelexHandler fn, bool exec, bool named)
156 assert (ffesta_num_possibles_ < FFESTA_maxPOSSIBLES_);
158 p = ffesta_possibles_[ffesta_num_possibles_++];
162 p->next = (ffestaPossible_) &ffesta_possible_execs_.first;
163 p->previous = ffesta_possible_execs_.last;
167 p->next = (ffestaPossible_) &ffesta_possible_nonexecs_.first;
168 p->previous = ffesta_possible_nonexecs_.last;
170 p->next->previous = p;
171 p->previous->next = p;
177 /* ffesta_inhibited_exec_transition_ -- Do exec transition while inhibited
179 if (!ffesta_inhibited_exec_transition_()) // couldn't transition...
181 Invokes ffestc_exec_transition, but first enables ffebad and ffesta and
182 afterwards disables them again. Then returns the result of the
183 invocation of ffestc_exec_transition. */
186 ffesta_inhibited_exec_transition_ (void)
190 assert (ffebad_inhibit ());
191 assert (ffesta_is_inhibited_);
193 ffebad_set_inhibit (FALSE);
194 ffesta_is_inhibited_ = FALSE;
196 result = ffestc_exec_transition ();
198 ffebad_set_inhibit (TRUE);
199 ffesta_is_inhibited_ = TRUE;
204 /* ffesta_reset_possibles_ -- Reset (clear) lists of possible statements
206 ffesta_reset_possibles_();
208 Clears the lists of executable and nonexecutable statements. */
211 ffesta_reset_possibles_ (void)
213 ffesta_num_possibles_ = 0;
215 ffesta_possible_execs_.first = ffesta_possible_execs_.last
216 = (ffestaPossible_) &ffesta_possible_execs_.first;
217 ffesta_possible_nonexecs_.first = ffesta_possible_nonexecs_.last
218 = (ffestaPossible_) &ffesta_possible_nonexecs_.first;
221 /* ffesta_save_ -- Save token on list, pass thru to current handler
223 return ffesta_save_; // to lexer.
225 Receives a token from the lexer. Saves it in the list of tokens. Calls
226 the current handler with the token.
228 If no shutdown error occurred (via
229 ffest_ffebad_start), then if the token was EOS or SEMICOLON, mark the
230 current possible as successful and confirmed but try the next possible
231 anyway until ambiguities in the form handling are ironed out. */
234 ffesta_save_ (ffelexToken t)
236 static ffelexToken *saved_tokens = NULL; /* A variable-sized array. */
237 static unsigned int num_saved_tokens = 0; /* Number currently saved. */
238 static unsigned int max_saved_tokens = 0; /* Maximum to be saved. */
239 unsigned int toknum; /* Index into saved_tokens array. */
240 ffelexToken eos; /* EOS created on-the-fly for shutdown
242 ffelexToken t2; /* Another temporary token (no intersect with
245 /* Save the current token. */
247 if (saved_tokens == NULL)
250 = (ffelexToken *) malloc_new_ksr (malloc_pool_image (),
251 "FFEST Saved Tokens",
252 (max_saved_tokens = 8) * sizeof (ffelexToken));
253 /* Start off with 8. */
255 else if (num_saved_tokens >= max_saved_tokens)
257 toknum = max_saved_tokens;
258 max_saved_tokens <<= 1; /* Multiply by two. */
259 assert (max_saved_tokens > toknum);
261 = (ffelexToken *) malloc_resize_ksr (malloc_pool_image (),
263 max_saved_tokens * sizeof (ffelexToken),
264 toknum * sizeof (ffelexToken));
267 *(saved_tokens + num_saved_tokens++) = ffelex_token_use (t);
269 /* Transmit the current token to the current handler. */
271 ffesta_current_handler_ = (ffelexHandler) (*ffesta_current_handler_) (t);
273 /* See if this possible has been shut down, or confirmed in which case we
274 might as well shut it down anyway to save time. */
276 if ((ffesta_current_shutdown_ || (FFESTA_ABORT_ON_CONFIRM_
277 && ffesta_confirmed_current_))
278 && !ffelex_expecting_character ())
280 switch (ffelex_token_type (t))
283 case FFELEX_typeSEMICOLON:
287 eos = ffelex_token_new_eos (ffelex_token_where_line (t),
288 ffelex_token_where_column (t));
289 ffesta_inhibit_confirmation_ = ffesta_current_shutdown_;
290 (*ffesta_current_handler_) (eos);
291 ffesta_inhibit_confirmation_ = FALSE;
292 ffelex_token_kill (eos);
299 /* If this is an EOS or SEMICOLON token, switch to next handler, else
300 return self as next handler for lexer. */
302 switch (ffelex_token_type (t))
305 case FFELEX_typeSEMICOLON:
309 return (ffelexHandler) ffesta_save_;
313 next_handler: /* :::::::::::::::::::: */
315 /* Note that a shutdown also happens after seeing the first two tokens
316 after "IF (expr)" or "WHERE (expr)" where a statement follows, even
317 though there is no error. This causes the IF or WHERE form to be
318 implemented first before ffest_first is called for the first token in
319 the following statement. */
321 if (ffesta_current_shutdown_)
322 ffesta_current_shutdown_ = FALSE; /* Only after sending EOS! */
324 assert (ffesta_confirmed_current_);
326 if (ffesta_confirmed_current_)
328 ffesta_confirmed_current_ = FALSE;
329 ffesta_confirmed_other_ = TRUE;
332 /* Pick next handler. */
334 ffesta_current_possible_ = ffesta_current_possible_->next;
335 ffesta_current_handler_ = ffesta_current_possible_->handler;
336 if (ffesta_current_handler_ == NULL)
337 { /* No handler in this list, try exec list if
339 if (ffesta_current_possible_
340 == (ffestaPossible_) &ffesta_possible_nonexecs_)
342 ffesta_current_possible_ = ffesta_possible_execs_.first;
343 ffesta_current_handler_ = ffesta_current_possible_->handler;
345 if ((ffesta_current_handler_ == NULL)
346 || (!ffesta_seen_first_exec
347 && ((ffesta_confirmed_possible_ != NULL)
348 || !ffesta_inhibited_exec_transition_ ())))
349 /* Don't run execs if: (decoding the "if" ^^^ up here ^^^) - we
350 have no exec handler available, or - we haven't seen the first
351 executable statement yet, and - we've confirmed a nonexec
352 (otherwise even a nonexec would cause a transition), or - a
353 nonexec-to-exec transition can't be made at the statement context
354 level (as in an executable statement in the middle of a STRUCTURE
355 definition); if it can be made, ffestc_exec_transition makes the
356 corresponding transition at the statement state level so
357 specification statements are no longer accepted following an
358 unrecognized statement. (Note: it is valid for f_e_t_ to decide
359 to always return TRUE by "shrieking" away the statement state
360 stack until a transitionable state is reached. Or it can leave
361 the stack as is and return FALSE.)
363 If we decide not to run execs, enter this block to rerun the
364 confirmed statement, if any. */
365 { /* At end of both lists! Pick confirmed or
367 ffebad_set_inhibit (FALSE);
368 ffesta_is_inhibited_ = FALSE;
369 ffesta_confirmed_other_ = FALSE;
370 ffesta_tokens[0] = ffesta_token_0_;
371 if (ffesta_confirmed_possible_ == NULL)
372 { /* No confirmed success, just use first
373 named possible, or first possible if
374 no named possibles. */
375 ffestaPossible_ possible = ffesta_possible_nonexecs_.first;
376 ffestaPossible_ first = NULL;
377 ffestaPossible_ first_named = NULL;
378 ffestaPossible_ first_exec = NULL;
382 if (possible->handler == NULL)
384 if (possible == (ffestaPossible_) &ffesta_possible_nonexecs_)
386 possible = first_exec = ffesta_possible_execs_.first;
395 && (first_named == NULL))
396 first_named = possible;
398 possible = possible->next;
401 if (first_named != NULL)
402 ffesta_current_possible_ = first_named;
403 else if (ffesta_seen_first_exec
404 && (first_exec != NULL))
405 ffesta_current_possible_ = first_exec;
407 ffesta_current_possible_ = first;
409 ffesta_current_handler_ = ffesta_current_possible_->handler;
410 assert (ffesta_current_handler_ != NULL);
413 { /* Confirmed success, use it. */
414 ffesta_current_possible_ = ffesta_confirmed_possible_;
415 ffesta_current_handler_ = ffesta_confirmed_possible_->handler;
417 ffesta_reset_possibles_ ();
420 { /* Switching from [empty?] list of nonexecs
421 to nonempty list of execs at this point. */
422 ffesta_tokens[0] = ffelex_token_use (ffesta_token_0_);
423 ffesymbol_set_retractable (ffesta_scratch_pool);
428 ffesta_tokens[0] = ffelex_token_use (ffesta_token_0_);
429 ffesymbol_set_retractable (ffesta_scratch_pool);
432 /* Send saved tokens to current handler until either shut down or all
435 for (toknum = 0; toknum < num_saved_tokens; ++toknum)
437 t = *(saved_tokens + toknum);
438 switch (ffelex_token_type (t))
440 case FFELEX_typeCHARACTER:
441 ffelex_set_expecting_hollerith (0, '\0',
442 ffewhere_line_unknown (),
443 ffewhere_column_unknown ());
444 ffesta_current_handler_
445 = (ffelexHandler) (*ffesta_current_handler_) (t);
448 case FFELEX_typeNAMES:
449 if (ffelex_is_names_expected ())
450 ffesta_current_handler_
451 = (ffelexHandler) (*ffesta_current_handler_) (t);
454 t2 = ffelex_token_name_from_names (t, 0, 0);
455 ffesta_current_handler_
456 = (ffelexHandler) (*ffesta_current_handler_) (t2);
457 ffelex_token_kill (t2);
462 ffesta_current_handler_
463 = (ffelexHandler) (*ffesta_current_handler_) (t);
467 if (!ffesta_is_inhibited_)
468 ffelex_token_kill (t); /* Won't need this any more. */
470 /* See if this possible has been shut down. */
472 else if ((ffesta_current_shutdown_ || (FFESTA_ABORT_ON_CONFIRM_
473 && ffesta_confirmed_current_))
474 && !ffelex_expecting_character ())
476 switch (ffelex_token_type (t))
479 case FFELEX_typeSEMICOLON:
483 eos = ffelex_token_new_eos (ffelex_token_where_line (t),
484 ffelex_token_where_column (t));
485 ffesta_inhibit_confirmation_ = ffesta_current_shutdown_;
486 (*ffesta_current_handler_) (eos);
487 ffesta_inhibit_confirmation_ = FALSE;
488 ffelex_token_kill (eos);
491 goto next_handler; /* :::::::::::::::::::: */
495 /* Finished sending all the tokens so far. If still trying possibilities,
496 then if we've just sent an EOS or SEMICOLON token through, go to the
497 next handler. Otherwise, return self so we can gather and process more
500 if (ffesta_is_inhibited_)
502 switch (ffelex_token_type (t))
505 case FFELEX_typeSEMICOLON:
506 goto next_handler; /* :::::::::::::::::::: */
509 #if FFESTA_ABORT_ON_CONFIRM_
510 assert (!ffesta_confirmed_other_); /* Catch ambiguities. */
512 return (ffelexHandler) ffesta_save_;
516 /* This was the one final possibility, uninhibited, so send the final
519 num_saved_tokens = 0;
520 #if !FFESTA_ABORT_ON_CONFIRM_
521 if (ffesta_is_two_into_statement_)
522 { /* End of the line for the previous two
523 tokens, resurrect them. */
526 ffesta_is_two_into_statement_ = FALSE;
527 next = (ffelexHandler) ffesta_first (ffesta_twotokens_1_);
528 ffelex_token_kill (ffesta_twotokens_1_);
529 next = (ffelexHandler) (*next) (ffesta_twotokens_2_);
530 ffelex_token_kill (ffesta_twotokens_2_);
531 return (ffelexHandler) next;
535 assert (ffesta_current_handler_ != NULL);
536 return (ffelexHandler) ffesta_current_handler_;
539 /* ffesta_second_ -- Parse the token after a NAME/NAMES in a statement
541 return ffesta_second_; // to lexer.
543 The second token cannot be a NAMES, since the first token is a NAME or
544 NAMES. If the second token is a NAME, look up its name in the list of
545 second names for use by whoever needs it.
547 Then make a list of all the possible statements this could be, based on
548 looking at the first two tokens. Two lists of possible statements are
549 created, one consisting of nonexecutable statements, the other consisting
550 of executable statements.
552 If the total number of possibilities is one, just fire up that
553 possibility by calling its handler function, passing the first two
554 tokens through it and so on.
556 Otherwise, start up a process whereby tokens are passed to the first
557 possibility on the list until EOS or SEMICOLON is reached or an error
558 is detected. But inhibit any actual reporting of errors; just record
559 their existence in the list. If EOS or SEMICOLON is reached with no
560 errors (other than non-form errors happening downstream, such as an
561 overflowing value for an integer or a GOTO statement identifying a label
562 on a FORMAT statement), then that is the only possible statement. Rerun
563 the statement with error-reporting turned on if any non-form errors were
564 generated, otherwise just use its results, then erase the list of tokens
565 memorized during the search process. If a form error occurs, immediately
566 cancel that possibility by sending EOS as the next token, remember the
567 error code for that possibility, and try the next possibility on the list,
568 first sending it the list of tokens memorized while handling the first
569 possibility, then continuing on as before.
571 Ultimately, either the end of the list of possibilities will be reached
572 without any successful forms being detected, in which case we pick one
573 based on hueristics (usually the first possibility) and rerun it with
574 error reporting turned on using the list of memorized tokens so the user
575 sees the error, or one of the possibilities will effectively succeed. */
578 ffesta_second_ (ffelexToken t)
583 assert (ffelex_token_type (t) != FFELEX_typeNAMES);
585 if (ffelex_token_type (t) == FFELEX_typeNAME)
586 ffesta_second_kw = ffestr_second (t);
588 /* Here we use switch on the first keyword name and handle each possible
589 recognizable name by looking at the second token, and building the list
590 of possible names accordingly. For now, just put every possible
591 statement on the list for ambiguity checking. */
593 switch (ffesta_first_kw)
595 case FFESTR_firstASSIGN:
596 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R838);
599 case FFESTR_firstBACKSPACE:
600 ffestb_args.beru.len = FFESTR_firstlBACKSPACE;
601 ffestb_args.beru.badname = "BACKSPACE";
602 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_beru);
605 case FFESTR_firstBLOCK:
606 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_block);
609 case FFESTR_firstBLOCKDATA:
610 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_blockdata);
613 case FFESTR_firstBYTE:
614 ffestb_args.decl.len = FFESTR_firstlBYTE;
615 ffestb_args.decl.type = FFESTP_typeBYTE;
616 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
619 case FFESTR_firstCALL:
620 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R1212);
623 case FFESTR_firstCASE:
624 case FFESTR_firstCASEDEFAULT:
625 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R810);
628 case FFESTR_firstCHRCTR:
629 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_chartype);
632 case FFESTR_firstCLOSE:
633 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R907);
636 case FFESTR_firstCOMMON:
637 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R547);
640 case FFESTR_firstCMPLX:
641 ffestb_args.decl.len = FFESTR_firstlCMPLX;
642 ffestb_args.decl.type = FFESTP_typeCOMPLEX;
643 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
646 case FFESTR_firstCONTINUE:
647 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R841);
650 case FFESTR_firstCYCLE:
651 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R834);
654 case FFESTR_firstDATA:
655 if (ffe_is_pedantic_not_90 ())
656 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R528);
658 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R528);
661 case FFESTR_firstDIMENSION:
662 ffestb_args.R524.len = FFESTR_firstlDIMENSION;
663 ffestb_args.R524.badname = "DIMENSION";
664 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R524);
668 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_do);
671 case FFESTR_firstDBL:
672 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_double);
675 case FFESTR_firstDBLCMPLX:
676 ffestb_args.decl.len = FFESTR_firstlDBLCMPLX;
677 ffestb_args.decl.type = FFESTP_typeDBLCMPLX;
678 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_dbltype);
681 case FFESTR_firstDBLPRCSN:
682 ffestb_args.decl.len = FFESTR_firstlDBLPRCSN;
683 ffestb_args.decl.type = FFESTP_typeDBLPRCSN;
684 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_dbltype);
687 case FFESTR_firstDOWHILE:
688 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_dowhile);
691 case FFESTR_firstELSE:
692 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_else);
695 case FFESTR_firstELSEIF:
696 ffestb_args.elsexyz.second = FFESTR_secondIF;
697 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_elsexyz);
700 case FFESTR_firstEND:
701 if ((ffelex_token_type (ffesta_token_0_) == FFELEX_typeNAMES)
702 || (ffelex_token_type (t) != FFELEX_typeNAME))
703 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_end);
706 switch (ffesta_second_kw)
708 case FFESTR_secondBLOCK:
709 case FFESTR_secondBLOCKDATA:
710 case FFESTR_secondDO:
711 case FFESTR_secondFILE:
712 case FFESTR_secondFUNCTION:
713 case FFESTR_secondIF:
714 case FFESTR_secondPROGRAM:
715 case FFESTR_secondSELECT:
716 case FFESTR_secondSUBROUTINE:
717 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_end);
721 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_end);
727 case FFESTR_firstENDBLOCK:
728 ffestb_args.endxyz.len = FFESTR_firstlENDBLOCK;
729 ffestb_args.endxyz.second = FFESTR_secondBLOCK;
730 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
733 case FFESTR_firstENDBLOCKDATA:
734 ffestb_args.endxyz.len = FFESTR_firstlENDBLOCKDATA;
735 ffestb_args.endxyz.second = FFESTR_secondBLOCKDATA;
736 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
739 case FFESTR_firstENDDO:
740 ffestb_args.endxyz.len = FFESTR_firstlENDDO;
741 ffestb_args.endxyz.second = FFESTR_secondDO;
742 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
745 case FFESTR_firstENDFILE:
746 ffestb_args.beru.len = FFESTR_firstlENDFILE;
747 ffestb_args.beru.badname = "ENDFILE";
748 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_beru);
751 case FFESTR_firstENDFUNCTION:
752 ffestb_args.endxyz.len = FFESTR_firstlENDFUNCTION;
753 ffestb_args.endxyz.second = FFESTR_secondFUNCTION;
754 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
757 case FFESTR_firstENDIF:
758 ffestb_args.endxyz.len = FFESTR_firstlENDIF;
759 ffestb_args.endxyz.second = FFESTR_secondIF;
760 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
763 case FFESTR_firstENDPROGRAM:
764 ffestb_args.endxyz.len = FFESTR_firstlENDPROGRAM;
765 ffestb_args.endxyz.second = FFESTR_secondPROGRAM;
766 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
769 case FFESTR_firstENDSELECT:
770 ffestb_args.endxyz.len = FFESTR_firstlENDSELECT;
771 ffestb_args.endxyz.second = FFESTR_secondSELECT;
772 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
775 case FFESTR_firstENDSUBROUTINE:
776 ffestb_args.endxyz.len = FFESTR_firstlENDSUBROUTINE;
777 ffestb_args.endxyz.second = FFESTR_secondSUBROUTINE;
778 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_endxyz);
781 case FFESTR_firstENTRY:
782 ffestb_args.dummy.len = FFESTR_firstlENTRY;
783 ffestb_args.dummy.badname = "ENTRY";
784 ffestb_args.dummy.is_subr = ffestc_is_entry_in_subr ();
785 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_dummy);
788 case FFESTR_firstEQUIVALENCE:
789 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R544);
792 case FFESTR_firstEXIT:
793 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R835);
796 case FFESTR_firstEXTERNAL:
797 ffestb_args.varlist.len = FFESTR_firstlEXTERNAL;
798 ffestb_args.varlist.badname = "EXTERNAL";
799 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_varlist);
802 /* WARNING: don't put anything that might cause an item to precede
803 FORMAT in the list of possible statements (it's added below) without
804 making sure FORMAT still is first. It has to run with
805 ffelex_set_names_pure(TRUE), to make sure the lexer delivers NAMES
808 case FFESTR_firstFORMAT:
809 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R1001);
812 case FFESTR_firstFUNCTION:
813 ffestb_args.dummy.len = FFESTR_firstlFUNCTION;
814 ffestb_args.dummy.badname = "FUNCTION";
815 ffestb_args.dummy.is_subr = FALSE;
816 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_dummy);
820 if ((ffelex_token_type (ffesta_token_0_) == FFELEX_typeNAMES)
821 || (ffelex_token_type (t) != FFELEX_typeNAME))
822 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_goto);
824 switch (ffesta_second_kw)
826 case FFESTR_secondTO:
827 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_goto);
830 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_goto);
835 case FFESTR_firstGOTO:
836 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_goto);
840 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_if);
841 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R840);
844 case FFESTR_firstIMPLICIT:
845 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_R539);
848 case FFESTR_firstINCLUDE:
849 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_S3P4);
850 switch (ffelex_token_type (t))
852 case FFELEX_typeNUMBER:
853 case FFELEX_typeNAME:
854 case FFELEX_typeAPOSTROPHE:
855 case FFELEX_typeQUOTE:
863 case FFESTR_firstINQUIRE:
864 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R923);
867 case FFESTR_firstINTGR:
868 ffestb_args.decl.len = FFESTR_firstlINTGR;
869 ffestb_args.decl.type = FFESTP_typeINTEGER;
870 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
873 case FFESTR_firstINTRINSIC:
874 ffestb_args.varlist.len = FFESTR_firstlINTRINSIC;
875 ffestb_args.varlist.badname = "INTRINSIC";
876 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_varlist);
879 case FFESTR_firstLGCL:
880 ffestb_args.decl.len = FFESTR_firstlLGCL;
881 ffestb_args.decl.type = FFESTP_typeLOGICAL;
882 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
885 case FFESTR_firstNAMELIST:
886 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R542);
889 case FFESTR_firstOPEN:
890 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R904);
893 case FFESTR_firstPARAMETER:
894 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R537);
895 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_V027);
898 case FFESTR_firstPAUSE:
899 ffestb_args.halt.len = FFESTR_firstlPAUSE;
900 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_halt);
903 case FFESTR_firstPRINT:
904 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R911);
907 case FFESTR_firstPROGRAM:
908 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R1102);
911 case FFESTR_firstREAD:
912 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R909);
915 case FFESTR_firstREAL:
916 ffestb_args.decl.len = FFESTR_firstlREAL;
917 ffestb_args.decl.type = FFESTP_typeREAL;
918 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
921 case FFESTR_firstRETURN:
922 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R1227);
925 case FFESTR_firstREWIND:
926 ffestb_args.beru.len = FFESTR_firstlREWIND;
927 ffestb_args.beru.badname = "REWIND";
928 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_beru);
931 case FFESTR_firstSAVE:
932 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R522);
935 case FFESTR_firstSELECT:
936 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R809);
939 case FFESTR_firstSELECTCASE:
940 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R809);
943 case FFESTR_firstSTOP:
944 ffestb_args.halt.len = FFESTR_firstlSTOP;
945 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_halt);
948 case FFESTR_firstSUBROUTINE:
949 ffestb_args.dummy.len = FFESTR_firstlSUBROUTINE;
950 ffestb_args.dummy.badname = "SUBROUTINE";
951 ffestb_args.dummy.is_subr = TRUE;
952 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_dummy);
955 case FFESTR_firstTYPE:
956 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_V020);
959 case FFESTR_firstVIRTUAL:
960 ffestb_args.R524.len = FFESTR_firstlVIRTUAL;
961 ffestb_args.R524.badname = "VIRTUAL";
962 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_R524);
965 case FFESTR_firstVOLATILE:
966 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_V014);
969 case FFESTR_firstWORD:
970 ffestb_args.decl.len = FFESTR_firstlWORD;
971 ffestb_args.decl.type = FFESTP_typeWORD;
972 ffesta_add_possible_nonexec_ ((ffelexHandler) ffestb_decl_gentype);
975 case FFESTR_firstWRITE:
976 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_R910);
983 /* Now check the default cases, which are always "live" (meaning that no
984 other possibility can override them). These are where the second token
985 is OPEN_PAREN, PERCENT, EQUALS, POINTS, or COLON. */
987 switch (ffelex_token_type (t))
989 case FFELEX_typeOPEN_PAREN:
990 s = ffesymbol_lookup_local (ffesta_token_0_);
991 if (((s == NULL) || (ffesymbol_dims (s) == NULL))
992 && !ffesta_seen_first_exec)
993 { /* Not known as array; may be stmt function. */
994 ffesta_add_possible_unnamed_nonexec_ ((ffelexHandler) ffestb_R1229);
996 /* If the symbol is (or will be due to implicit typing) of
997 CHARACTER type, then the statement might be an assignment
998 statement. If so, since it can't be a function invocation nor
999 an array element reference, the open paren following the symbol
1000 name must be followed by an expression and a colon. Without the
1001 colon (which cannot appear in a stmt function definition), the
1002 let stmt rejects. So CHARACTER_NAME(...)=expr, unlike any other
1003 type, is not ambiguous alone. */
1005 if (ffeimplic_peek_symbol_type (s,
1006 ffelex_token_text (ffesta_token_0_))
1007 == FFEINFO_basictypeCHARACTER)
1008 ffesta_add_possible_unnamed_exec_ ((ffelexHandler) ffestb_let);
1010 else /* Not statement function if known as an
1012 ffesta_add_possible_unnamed_exec_ ((ffelexHandler) ffestb_let);
1015 case FFELEX_typeEQUALS:
1016 ffesta_add_possible_unnamed_exec_ ((ffelexHandler) ffestb_let);
1019 case FFELEX_typeCOLON:
1020 ffesta_add_possible_exec_ ((ffelexHandler) ffestb_construct);
1027 /* Now see how many possibilities are on the list. */
1029 switch (ffesta_num_possibles_)
1031 case 0: /* None, so invalid statement. */
1032 no_stmts: /* :::::::::::::::::::: */
1033 ffesta_tokens[0] = ffesta_token_0_;
1034 ffesta_ffebad_2t (FFEBAD_UNREC_STMT, ffesta_token_0_, t);
1035 next = (ffelexHandler) ffelex_swallow_tokens (NULL,
1036 (ffelexHandler) ffesta_zero);
1039 case 1: /* One, so just do it! */
1040 ffesta_tokens[0] = ffesta_token_0_;
1041 next = ffesta_possible_execs_.first->handler;
1043 { /* Have a nonexec stmt. */
1044 next = ffesta_possible_nonexecs_.first->handler;
1045 assert (next != NULL);
1047 else if (ffesta_seen_first_exec)
1048 ; /* Have an exec stmt after exec transition. */
1049 else if (!ffestc_exec_transition ())
1050 /* 1 exec stmt only, but not valid in context, so pretend as though
1051 statement is unrecognized. */
1052 goto no_stmts; /* :::::::::::::::::::: */
1055 default: /* More than one, so try them in order. */
1056 ffesta_confirmed_possible_ = NULL;
1057 ffesta_current_possible_ = ffesta_possible_nonexecs_.first;
1058 ffesta_current_handler_ = ffesta_current_possible_->handler;
1059 if (ffesta_current_handler_ == NULL)
1061 ffesta_current_possible_ = ffesta_possible_execs_.first;
1062 ffesta_current_handler_ = ffesta_current_possible_->handler;
1063 assert (ffesta_current_handler_ != NULL);
1064 if (!ffesta_seen_first_exec)
1065 { /* Need to do exec transition now. */
1066 ffesta_tokens[0] = ffesta_token_0_;
1067 if (!ffestc_exec_transition ())
1068 goto no_stmts; /* :::::::::::::::::::: */
1071 ffesta_tokens[0] = ffelex_token_use (ffesta_token_0_);
1072 next = (ffelexHandler) ffesta_save_;
1073 ffebad_set_inhibit (TRUE);
1074 ffesta_is_inhibited_ = TRUE;
1079 = malloc_pool_new ("Statement Output", ffe_pool_program_unit (), 1024);
1081 = malloc_pool_new ("Statement Scratch", ffe_pool_program_unit (), 1024);
1082 ffesta_outpooldisp_ = FFESTA_pooldispDISCARD;
1084 if (ffesta_is_inhibited_)
1085 ffesymbol_set_retractable (ffesta_scratch_pool);
1087 ffelex_set_names (FALSE); /* Most handlers will want this. If not,
1088 they have to set it TRUE again (its value
1089 at the beginning of a statement). */
1091 return (ffelexHandler) (*next) (t);
1094 /* ffesta_send_two_ -- Send the two tokens saved by ffesta_two after all
1096 return ffesta_send_two_; // to lexer.
1098 Currently, if this function gets called, it means that the two tokens
1099 saved by ffesta_two did not have their handlers derailed by
1100 ffesta_save_, which probably means they weren't sent by ffesta_save_
1101 but directly by the lexer, which probably means the original statement
1102 (which should be IF (expr) or WHERE (expr)) somehow evaluated to only
1103 one possibility in ffesta_second_ or somebody optimized FFEST to
1104 immediately revert to one possibility upon confirmation but forgot to
1105 change this function (and thus perhaps the entire resubmission
1108 #if !FFESTA_ABORT_ON_CONFIRM_
1109 static ffelexHandler
1110 ffesta_send_two_ (ffelexToken t)
1112 assert ("what am I doing here?" == NULL);
1117 /* ffesta_confirmed -- Confirm current possibility as only one
1121 Sets the confirmation flag. During debugging for ambiguous constructs,
1122 asserts that the confirmation flag for a previous possibility has not
1126 ffesta_confirmed (void)
1128 if (ffesta_inhibit_confirmation_)
1130 ffesta_confirmed_current_ = TRUE;
1131 assert (!ffesta_confirmed_other_
1132 || (ffesta_confirmed_possible_ == ffesta_current_possible_));
1133 ffesta_confirmed_possible_ = ffesta_current_possible_;
1136 /* ffesta_eof -- End of (non-INCLUDEd) source file
1140 Call after piping tokens through ffest_first, where the most recent
1141 token sent through must be EOS.
1144 Put new EOF token in ffesta_tokens[0], not NULL, because too much
1145 code expects something there for error reporting and the like. Also,
1146 do basically the same things ffest_second and ffesta_zero do for
1147 processing a statement (make and destroy pools, et cetera). */
1152 ffesta_tokens[0] = ffelex_token_new_eof ();
1155 = malloc_pool_new ("Statement Output", ffe_pool_program_unit (), 1024);
1157 = malloc_pool_new ("Statement Scratch", ffe_pool_program_unit (), 1024);
1158 ffesta_outpooldisp_ = FFESTA_pooldispDISCARD;
1162 if (ffesta_tokens[0] != NULL)
1163 ffelex_token_kill (ffesta_tokens[0]);
1165 if (ffesta_output_pool != NULL)
1167 if (ffesta_outpooldisp_ == FFESTA_pooldispDISCARD)
1168 malloc_pool_kill (ffesta_output_pool);
1169 ffesta_output_pool = NULL;
1172 if (ffesta_scratch_pool != NULL)
1174 malloc_pool_kill (ffesta_scratch_pool);
1175 ffesta_scratch_pool = NULL;
1178 if (ffesta_label_token != NULL)
1180 ffelex_token_kill (ffesta_label_token);
1181 ffesta_label_token = NULL;
1184 if (ffe_is_ffedebug ())
1186 ffestorag_report ();
1190 /* ffesta_ffebad_here_current_stmt -- ffebad_here with ptr to current stmt
1192 ffesta_ffebad_here_current_stmt(0);
1194 Outsiders can call this fn if they have no more convenient place to
1195 point to (via a token or pair of ffewhere objects) and they know a
1196 current, useful statement is being evaluted by ffest (i.e. they are
1197 being called from ffestb, ffestc, ffestd, ... functions). */
1200 ffesta_ffebad_here_current_stmt (ffebadIndex i)
1202 assert (ffesta_tokens[0] != NULL);
1203 ffebad_here (i, ffelex_token_where_line (ffesta_tokens[0]),
1204 ffelex_token_where_column (ffesta_tokens[0]));
1207 /* ffesta_ffebad_start -- Start a possibly inhibited error report
1209 if (ffesta_ffebad_start(FFEBAD_SOME_ERROR))
1211 ffebad_here, ffebad_string ...;
1215 Call if the error might indicate that ffest is evaluating the wrong
1216 statement form, instead of calling ffebad_start directly. If ffest
1217 is choosing between forms, it will return FALSE, send an EOS/SEMICOLON
1218 token through as the next token (if the current one isn't already one
1219 of those), and try another possible form. Otherwise, ffebad_start is
1220 called with the argument and TRUE returned. */
1223 ffesta_ffebad_start (ffebad errnum)
1225 if (!ffesta_is_inhibited_)
1227 ffebad_start (errnum);
1231 if (!ffesta_confirmed_current_)
1232 ffesta_current_shutdown_ = TRUE;
1237 /* ffesta_first -- Parse the first token in a statement
1239 return ffesta_first; // to lexer. */
1242 ffesta_first (ffelexToken t)
1244 switch (ffelex_token_type (t))
1246 case FFELEX_typeSEMICOLON:
1247 case FFELEX_typeEOS:
1248 ffesta_tokens[0] = ffelex_token_use (t);
1249 if (ffesta_label_token != NULL)
1251 ffebad_start (FFEBAD_LABEL_WITHOUT_STMT);
1252 ffebad_here (0, ffelex_token_where_line (ffesta_label_token),
1253 ffelex_token_where_column (ffesta_label_token));
1254 ffebad_string (ffelex_token_text (ffesta_label_token));
1255 ffebad_here (1, ffelex_token_where_line (t), ffelex_token_where_column (t));
1258 return (ffelexHandler) ffesta_zero (t);
1260 case FFELEX_typeNAME:
1261 case FFELEX_typeNAMES:
1262 ffesta_token_0_ = ffelex_token_use (t);
1263 ffesta_first_kw = ffestr_first (t);
1264 return (ffelexHandler) ffesta_second_;
1266 case FFELEX_typeNUMBER:
1267 if (ffesta_line_has_semicolons
1268 && !ffe_is_free_form ()
1269 && ffe_is_pedantic ())
1271 ffebad_start (FFEBAD_LABEL_WRONG_PLACE);
1272 ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
1273 ffebad_string (ffelex_token_text (t));
1276 if (ffesta_label_token == NULL)
1278 ffesta_label_token = ffelex_token_use (t);
1279 return (ffelexHandler) ffesta_first;
1283 ffebad_start (FFEBAD_EXTRA_LABEL_DEF);
1284 ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
1285 ffebad_string (ffelex_token_text (t));
1286 ffebad_here (1, ffelex_token_where_line (ffesta_label_token),
1287 ffelex_token_where_column (ffesta_label_token));
1288 ffebad_string (ffelex_token_text (ffesta_label_token));
1291 return (ffelexHandler) ffesta_first;
1294 default: /* Invalid first token. */
1295 ffesta_tokens[0] = ffelex_token_use (t);
1296 ffebad_start (FFEBAD_STMT_BEGINS_BAD);
1297 ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
1299 return (ffelexHandler) ffelex_swallow_tokens (t,
1300 (ffelexHandler) ffesta_zero);
1304 /* ffesta_init_0 -- Initialize for entire image invocation
1308 Call just once per invocation of the compiler (not once per invocation
1311 Gets memory for the list of possibles once and for all, since this
1312 list never gets larger than a certain size (FFESTA_maxPOSSIBLES_)
1313 and is not particularly large. Initializes the array of pointers to
1314 this list. Initializes the executable and nonexecutable lists. */
1317 ffesta_init_0 (void)
1319 ffestaPossible_ ptr;
1322 ptr = (ffestaPossible_) malloc_new_kp (malloc_pool_image (),
1324 FFESTA_maxPOSSIBLES_
1327 for (i = 0; i < FFESTA_maxPOSSIBLES_; ++i)
1328 ffesta_possibles_[i] = ptr++;
1330 ffesta_possible_execs_.first = ffesta_possible_execs_.last
1331 = (ffestaPossible_) &ffesta_possible_execs_.first;
1332 ffesta_possible_nonexecs_.first = ffesta_possible_nonexecs_.last
1333 = (ffestaPossible_) &ffesta_possible_nonexecs_.first;
1334 ffesta_possible_execs_.nil = ffesta_possible_nonexecs_.nil = NULL;
1337 /* ffesta_init_3 -- Initialize for any program unit
1342 ffesta_init_3 (void)
1344 ffesta_output_pool = NULL; /* May be doing this just before reaching */
1345 ffesta_scratch_pool = NULL; /* ffesta_zero or ffesta_two. */
1346 /* NOTE: we let the ffe_terminate_2 action of killing the program_unit pool
1347 handle the killing of the output and scratch pools for us, which is why
1348 we don't have a terminate_3 action to do so. */
1349 ffesta_construct_name = NULL;
1350 ffesta_label_token = NULL;
1351 ffesta_seen_first_exec = FALSE;
1354 /* ffesta_is_inhibited -- Test whether the current possibility is inhibited
1356 if (!ffesta_is_inhibited())
1357 // implement the statement.
1359 Just make sure the current possibility has been confirmed. If anyone
1360 really needs to test whether the current possibility is inhibited prior
1361 to confirming it, that indicates a need to begin statement processing
1362 before it is certain that the given possibility is indeed the statement
1363 to be processed. As of this writing, there does not appear to be such
1364 a need. If there is, then when confirming a statement would normally
1365 immediately disable the inhibition (whereas currently we leave the
1366 confirmed statement disabled until we've tried the other possibilities,
1367 to check for ambiguities), we must check to see if the possibility has
1368 already tested for inhibition prior to confirmation and, if so, maintain
1369 inhibition until the end of the statement (which may be forced right
1370 away) and then rerun the entire statement from the beginning. Otherwise,
1371 initial calls to ffestb functions won't have been made, but subsequent
1372 calls (after confirmation) will, which is wrong. Of course, this all
1373 applies only to those statements implemented via multiple calls to
1374 ffestb, although if a statement requiring only a single ffestb call
1375 tested for inhibition prior to confirmation, it would likely mean that
1376 the ffestb call would be completely dropped without this mechanism. */
1379 ffesta_is_inhibited (void)
1381 assert (ffesta_confirmed_current_ || ffesta_inhibit_confirmation_);
1382 return ffesta_is_inhibited_;
1385 /* ffesta_ffebad_1p -- Issue diagnostic with one source character
1387 ffelexToken names_token;
1388 ffeTokenLength index;
1389 ffelexToken next_token;
1390 ffesta_ffebad_1p(FFEBAD_SOME_ERROR,names_token,index,next_token);
1392 Equivalent to "if (ffest_ffebad_start(FFEBAD_SOME_ERROR))" followed by
1393 sending one argument, the location of index with names_token, if TRUE is
1394 returned. If index is equal to the length of names_token, meaning it
1395 points to the end of the token, then uses the location in next_token
1396 (which should be the token sent by the lexer after it sent names_token)
1400 ffesta_ffebad_1p (ffebad errnum, ffelexToken names_token, ffeTokenLength index,
1401 ffelexToken next_token)
1406 assert (index <= ffelex_token_length (names_token));
1408 if (ffesta_ffebad_start (errnum))
1410 if (index == ffelex_token_length (names_token))
1412 assert (next_token != NULL);
1413 line = ffelex_token_where_line (next_token);
1414 col = ffelex_token_where_column (next_token);
1415 ffebad_here (0, line, col);
1419 ffewhere_set_from_track (&line, &col,
1420 ffelex_token_where_line (names_token),
1421 ffelex_token_where_column (names_token),
1422 ffelex_token_wheretrack (names_token),
1424 ffebad_here (0, line, col);
1425 ffewhere_line_kill (line);
1426 ffewhere_column_kill (col);
1433 ffesta_ffebad_1sp (ffebad errnum, const char *s, ffelexToken names_token,
1434 ffeTokenLength index, ffelexToken next_token)
1439 assert (index <= ffelex_token_length (names_token));
1441 if (ffesta_ffebad_start (errnum))
1444 if (index == ffelex_token_length (names_token))
1446 assert (next_token != NULL);
1447 line = ffelex_token_where_line (next_token);
1448 col = ffelex_token_where_column (next_token);
1449 ffebad_here (0, line, col);
1453 ffewhere_set_from_track (&line, &col,
1454 ffelex_token_where_line (names_token),
1455 ffelex_token_where_column (names_token),
1456 ffelex_token_wheretrack (names_token),
1458 ffebad_here (0, line, col);
1459 ffewhere_line_kill (line);
1460 ffewhere_column_kill (col);
1467 ffesta_ffebad_1st (ffebad errnum, const char *s, ffelexToken t)
1469 if (ffesta_ffebad_start (errnum))
1472 ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
1477 /* ffesta_ffebad_1t -- Issue diagnostic with one source token
1480 ffesta_ffebad_1t(FFEBAD_SOME_ERROR,t);
1482 Equivalent to "if (ffesta_ffebad_start(FFEBAD_SOME_ERROR))" followed by
1483 sending one argument, the location of the token t, if TRUE is returned. */
1486 ffesta_ffebad_1t (ffebad errnum, ffelexToken t)
1488 if (ffesta_ffebad_start (errnum))
1490 ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
1496 ffesta_ffebad_2st (ffebad errnum, const char *s, ffelexToken t1, ffelexToken t2)
1498 if (ffesta_ffebad_start (errnum))
1501 ffebad_here (0, ffelex_token_where_line (t1), ffelex_token_where_column (t1));
1502 ffebad_here (1, ffelex_token_where_line (t2), ffelex_token_where_column (t2));
1507 /* ffesta_ffebad_2t -- Issue diagnostic with two source tokens
1510 ffesta_ffebad_2t(FFEBAD_SOME_ERROR,t1,t2);
1512 Equivalent to "if (ffesta_ffebad_start(FFEBAD_SOME_ERROR))" followed by
1513 sending two argument, the locations of the tokens t1 and t2, if TRUE is
1517 ffesta_ffebad_2t (ffebad errnum, ffelexToken t1, ffelexToken t2)
1519 if (ffesta_ffebad_start (errnum))
1521 ffebad_here (0, ffelex_token_where_line (t1), ffelex_token_where_column (t1));
1522 ffebad_here (1, ffelex_token_where_line (t2), ffelex_token_where_column (t2));
1528 ffesta_outpooldisp (void)
1530 return ffesta_outpooldisp_;
1534 ffesta_set_outpooldisp (ffestaPooldisp d)
1536 ffesta_outpooldisp_ = d;
1539 /* Shut down current parsing possibility, but without bothering the
1540 user with a diagnostic if we're not inhibited. */
1543 ffesta_shutdown (void)
1545 if (ffesta_is_inhibited_)
1546 ffesta_current_shutdown_ = TRUE;
1549 /* ffesta_two -- Deal with the first two tokens after a swallowed statement
1551 return ffesta_two(first_token,second_token); // to lexer.
1553 Like ffesta_zero, except instead of expecting an EOS or SEMICOLON, it
1554 expects the first two tokens of a statement that is part of another
1555 statement: the first two tokens of statement in "IF (expr) statement" or
1556 "WHERE (expr) statement", in particular. The first token must be a NAME
1557 or NAMES, the second can be basically anything. The statement type MUST
1558 be confirmed by now.
1560 If we're not inhibited, just handle things as if we were ffesta_zero
1561 and saw an EOS just before the two tokens.
1563 If we're inhibited, set ffesta_current_shutdown_ to shut down the current
1564 statement and continue with other possibilities, then (presumably) come
1565 back to this one for real when not inhibited. */
1568 ffesta_two (ffelexToken first, ffelexToken second)
1570 #if FFESTA_ABORT_ON_CONFIRM_
1574 assert ((ffelex_token_type (first) == FFELEX_typeNAME)
1575 || (ffelex_token_type (first) == FFELEX_typeNAMES));
1576 assert (ffesta_tokens[0] != NULL);
1578 if (ffesta_is_inhibited_) /* Oh, not really done with statement. */
1580 ffesta_current_shutdown_ = TRUE;
1581 /* To catch the EOS on shutdown. */
1582 return (ffelexHandler) ffelex_swallow_tokens (second,
1583 (ffelexHandler) ffesta_zero);
1586 ffestw_display_state ();
1588 ffelex_token_kill (ffesta_tokens[0]);
1590 if (ffesta_output_pool != NULL)
1592 if (ffesta_outpooldisp_ == FFESTA_pooldispDISCARD)
1593 malloc_pool_kill (ffesta_output_pool);
1594 ffesta_output_pool = NULL;
1597 if (ffesta_scratch_pool != NULL)
1599 malloc_pool_kill (ffesta_scratch_pool);
1600 ffesta_scratch_pool = NULL;
1603 ffesta_reset_possibles_ ();
1604 ffesta_confirmed_current_ = FALSE;
1606 /* What happens here is somewhat interesting. We effectively derail the
1607 line of handlers for these two tokens, the first two in a statement, by
1608 setting a flag to TRUE. This flag tells ffesta_save_ (or, conceivably,
1609 the lexer via ffesta_second_'s case 1:, where it has only one possible
1610 kind of statement -- someday this will be more likely, i.e. after
1611 confirmation causes an immediate switch to only the one context rather
1612 than just setting a flag and running through the remaining possibles to
1613 look for ambiguities) that the last two tokens it sent did not reach the
1614 truly desired targets (ffest_first and ffesta_second_) since that would
1615 otherwise attempt to recursively invoke ffesta_save_ in most cases,
1616 while the existing ffesta_save_ was still alive and making use of static
1617 (nonrecursive) variables. Instead, ffesta_save_, upon seeing this flag
1618 set TRUE, sets it to FALSE and resubmits the two tokens copied here to
1619 ffest_first and, presumably, ffesta_second_, kills them, and returns the
1620 handler returned by the handler for the second token. Thus, even though
1621 ffesta_save_ is still (likely to be) recursively invoked, the former
1622 invocation is past the use of any static variables possibly changed
1623 during the first-two-token invocation of the latter invocation. */
1625 #if FFESTA_ABORT_ON_CONFIRM_
1626 /* Shouldn't be in ffesta_save_ at all here. */
1628 next = (ffelexHandler) ffesta_first (first);
1629 return (ffelexHandler) (*next) (second);
1631 ffesta_twotokens_1_ = ffelex_token_use (first);
1632 ffesta_twotokens_2_ = ffelex_token_use (second);
1634 ffesta_is_two_into_statement_ = TRUE;
1635 return (ffelexHandler) ffesta_send_two_; /* Shouldn't get called. */
1639 /* ffesta_zero -- Deal with the end of a swallowed statement
1641 return ffesta_zero; // to lexer.
1643 NOTICE that this code is COPIED, largely, into a
1644 similar function named ffesta_two that gets invoked in place of
1645 _zero_ when the end of the statement happens before EOS or SEMICOLON and
1646 to tokens into the next statement have been read (as is the case with the
1647 logical-IF and WHERE-stmt statements). So any changes made here should
1648 probably be made in _two_ at the same time. */
1651 ffesta_zero (ffelexToken t)
1653 assert ((ffelex_token_type (t) == FFELEX_typeEOS)
1654 || (ffelex_token_type (t) == FFELEX_typeSEMICOLON));
1655 assert (ffesta_tokens[0] != NULL);
1657 if (ffesta_is_inhibited_)
1658 ffesymbol_retract (TRUE);
1660 ffestw_display_state ();
1662 /* Do CONTINUE if nothing else. This is done specifically so that "IF
1663 (...) BLAH" causes the same things to happen as if "IF (...) CONTINUE"
1664 was done, so that tracking of labels and such works. (Try a small
1665 program like "DO 10 ...", "IF (...) BLAH", "10 CONTINUE", "END".)
1667 But it turns out that just testing "!ffesta_confirmed_current_"
1668 isn't enough, because then typing "GOTO" instead of "BLAH" above
1669 doesn't work -- the statement is confirmed (we know the user
1670 attempted a GOTO) but ffestc hasn't seen it. So, instead, just
1671 always tell ffestc to do "any" statement it needs to reset. */
1673 if (!ffesta_is_inhibited_
1674 && ffesta_seen_first_exec)
1679 ffelex_token_kill (ffesta_tokens[0]);
1681 if (ffesta_is_inhibited_) /* Oh, not really done with statement. */
1682 return (ffelexHandler) ffesta_zero; /* Call me again when done! */
1684 if (ffesta_output_pool != NULL)
1686 if (ffesta_outpooldisp_ == FFESTA_pooldispDISCARD)
1687 malloc_pool_kill (ffesta_output_pool);
1688 ffesta_output_pool = NULL;
1691 if (ffesta_scratch_pool != NULL)
1693 malloc_pool_kill (ffesta_scratch_pool);
1694 ffesta_scratch_pool = NULL;
1697 ffesta_reset_possibles_ ();
1698 ffesta_confirmed_current_ = FALSE;
1700 if (ffelex_token_type (t) == FFELEX_typeSEMICOLON)
1702 ffesta_line_has_semicolons = TRUE;
1703 if (ffe_is_pedantic_not_90 ())
1705 ffebad_start (FFEBAD_SEMICOLON);
1706 ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
1711 ffesta_line_has_semicolons = FALSE;
1713 if (ffesta_label_token != NULL)
1715 ffelex_token_kill (ffesta_label_token);
1716 ffesta_label_token = NULL;
1719 if (ffe_is_ffedebug ())
1721 ffestorag_report ();
1724 ffelex_set_names (TRUE);
1725 return (ffelexHandler) ffesta_first;