1 /* Implementation of Fortran lexer
2 Copyright (C) 1995, 1996, 1997, 1998, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Contributed by James Craig Burley.
6 This file is part of GNU Fortran.
8 GNU Fortran is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU Fortran is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Fortran; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
37 static void ffelex_append_to_token_ (char c);
38 static int ffelex_backslash_ (int c, ffewhereColumnNumber col);
39 static void ffelex_bad_1_ (ffebad errnum, ffewhereLineNumber ln0,
40 ffewhereColumnNumber cn0);
41 static void ffelex_bad_2_ (ffebad errnum, ffewhereLineNumber ln0,
42 ffewhereColumnNumber cn0, ffewhereLineNumber ln1,
43 ffewhereColumnNumber cn1);
44 static void ffelex_bad_here_ (int num, ffewhereLineNumber ln0,
45 ffewhereColumnNumber cn0);
46 static void ffelex_finish_statement_ (void);
47 static int ffelex_get_directive_line_ (char **text, FILE *finput);
48 static int ffelex_hash_ (FILE *f);
49 static ffewhereColumnNumber ffelex_image_char_ (int c,
50 ffewhereColumnNumber col);
51 static void ffelex_include_ (void);
52 static bool ffelex_is_free_char_ctx_contin_ (ffewhereColumnNumber col);
53 static bool ffelex_is_free_nonc_ctx_contin_ (ffewhereColumnNumber col);
54 static void ffelex_next_line_ (void);
55 static void ffelex_prepare_eos_ (void);
56 static void ffelex_send_token_ (void);
57 static ffelexHandler ffelex_swallow_tokens_ (ffelexToken t);
58 static ffelexToken ffelex_token_new_ (void);
60 /* Pertaining to the geometry of the input file. */
62 /* Initial size for card image to be allocated. */
63 #define FFELEX_columnINITIAL_SIZE_ 255
65 /* The card image itself, which grows as source lines get longer. It
66 has room for ffelex_card_size_ + 8 characters, and the length of the
67 current image is ffelex_card_length_. (The + 8 characters are made
68 available for easy handling of tabs and such.) */
69 static char *ffelex_card_image_;
70 static ffewhereColumnNumber ffelex_card_size_;
71 static ffewhereColumnNumber ffelex_card_length_;
73 /* Max width for free-form lines (ISO F90). */
74 #define FFELEX_FREE_MAX_COLUMNS_ 132
76 /* True if we saw a tab on the current line, as this (currently) means
77 the line is therefore treated as though final_nontab_column_ were
79 static bool ffelex_saw_tab_;
81 /* TRUE if current line is known to be erroneous, so don't bother
82 expanding room for it just to display it. */
83 static bool ffelex_bad_line_ = FALSE;
85 /* Last column for vanilla, i.e. non-tabbed, line. Usually 72 or 132. */
86 static ffewhereColumnNumber ffelex_final_nontab_column_;
88 /* Array for quickly deciding what kind of line the current card has,
89 based on its first character. */
90 static ffelexType ffelex_first_char_[256];
92 /* Pertaining to file management. */
94 /* The wf argument of the most recent active ffelex_file_(fixed,free)
96 static GTY (()) ffewhereFile ffelex_current_wf_;
98 /* TRUE if an INCLUDE statement can be processed (ffelex_set_include
100 static bool ffelex_permit_include_;
102 /* TRUE if an INCLUDE statement is pending (ffelex_set_include has been
104 static bool ffelex_set_include_;
106 /* Information on the pending INCLUDE file. */
107 static FILE *ffelex_include_file_;
108 static bool ffelex_include_free_form_;
109 static GTY(()) ffewhereFile ffelex_include_wherefile_;
111 /* Current master line count. */
112 static ffewhereLineNumber ffelex_linecount_current_;
113 /* Next master line count. */
114 static ffewhereLineNumber ffelex_linecount_next_;
116 /* ffewhere info on the latest (currently active) line read from the
117 active source file. */
118 static ffewhereLine ffelex_current_wl_;
119 static ffewhereColumn ffelex_current_wc_;
121 /* Pertaining to tokens in general. */
123 /* Initial capacity for text in a CHARACTER/HOLLERITH/NAME/NAMES/NUMBER
125 #define FFELEX_columnTOKEN_SIZE_ 63
126 #if FFELEX_columnTOKEN_SIZE_ < FFEWHERE_indexMAX
127 #error "token size too small!"
130 /* Current token being lexed. */
131 static ffelexToken ffelex_token_;
133 /* Handler for current token. */
134 static ffelexHandler ffelex_handler_;
136 /* TRUE if fixed-form lexer is to generate NAMES instead of NAME tokens. */
137 static bool ffelex_names_;
139 /* TRUE if both lexers are to generate NAMES instead of NAME tokens. */
140 static bool ffelex_names_pure_;
142 /* TRUE if 0-9 starts a NAME token instead of NUMBER, for parsing hex
144 static bool ffelex_hexnum_;
146 /* For ffelex_swallow_tokens(). */
147 static ffelexHandler ffelex_eos_handler_;
149 /* Number of tokens sent since last EOS or beginning of input file
150 (include INCLUDEd files). */
151 static unsigned long int ffelex_number_of_tokens_;
153 /* Number of labels sent (as NUMBER tokens) since last reset of
154 ffelex_number_of_tokens_ to 0, should be 0 or 1 in most cases.
155 (Fixed-form source only.) */
156 static unsigned long int ffelex_label_tokens_;
158 /* Metering for token management, to catch token-memory leaks. */
159 static long int ffelex_total_tokens_ = 0;
160 static long int ffelex_old_total_tokens_ = 1;
161 static long int ffelex_token_nextid_ = 0;
163 /* Pertaining to lexing CHARACTER and HOLLERITH tokens. */
165 /* >0 if a Hollerith constant of that length might be in mid-lex, used
166 when the next character seen is 'H' or 'h' to enter HOLLERITH lexing
167 mode (see ffelex_raw_mode_). */
168 static long int ffelex_expecting_hollerith_;
170 /* -3: Backslash (escape) sequence being lexed in CHARACTER.
171 -2: Possible closing apostrophe/quote seen in CHARACTER.
172 -1: Lexing CHARACTER.
173 0: Not lexing CHARACTER or HOLLERITH.
174 >0: Lexing HOLLERITH, value is # chars remaining to expect. */
175 static long int ffelex_raw_mode_;
177 /* When lexing CHARACTER, open quote/apostrophe (either ' or "). */
178 static char ffelex_raw_char_;
180 /* TRUE when backslash processing had to use most recent character
181 to finish its state engine, but that character is not part of
182 the backslash sequence, so must be reconsidered as a "normal"
183 character in CHARACTER/HOLLERITH lexing. */
184 static bool ffelex_backslash_reconsider_ = FALSE;
186 /* Characters preread before lexing happened (might include EOF). */
187 static int *ffelex_kludge_chars_ = NULL;
189 /* Doing the kludge processing, so not initialized yet. */
190 static bool ffelex_kludge_flag_ = FALSE;
192 /* The beginning of a (possible) CHARACTER/HOLLERITH token. */
193 static ffewhereLine ffelex_raw_where_line_;
194 static ffewhereColumn ffelex_raw_where_col_;
197 /* Call this to append another character to the current token. If it isn't
198 currently big enough for it, it will be enlarged. The current token
199 must be a CHARACTER, HOLLERITH, NAME, NAMES, or NUMBER. */
202 ffelex_append_to_token_ (char c)
204 if (ffelex_token_->text == NULL)
207 = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
208 FFELEX_columnTOKEN_SIZE_ + 1);
209 ffelex_token_->size = FFELEX_columnTOKEN_SIZE_;
210 ffelex_token_->length = 0;
212 else if (ffelex_token_->length >= ffelex_token_->size)
215 = malloc_resize_ksr (malloc_pool_image (),
217 (ffelex_token_->size << 1) + 1,
218 ffelex_token_->size + 1);
219 ffelex_token_->size <<= 1;
220 assert (ffelex_token_->length < ffelex_token_->size);
222 ffelex_token_->text[ffelex_token_->length++] = c;
225 /* Do backslash (escape) processing for a CHARACTER/HOLLERITH token
229 ffelex_backslash_ (int c, ffewhereColumnNumber col)
231 static int state = 0;
232 static unsigned int count;
234 static unsigned int firstdig = 0;
236 static ffewhereLineNumber line;
237 static ffewhereColumnNumber column;
239 /* See gcc/c-lex.c readescape() for a straightforward version
240 of this state engine for handling backslashes in character/
241 hollerith constants. */
249 && (ffelex_raw_mode_ != 0)
250 && ffe_is_backslash ())
254 line = ffelex_linecount_current_;
260 state = 0; /* Assume simple case. */
270 case '0': case '1': case '2': case '3': case '4':
271 case '5': case '6': case '7':
277 case '\\': case '\'': case '"':
280 #if 0 /* Inappropriate for Fortran. */
282 ffelex_next_line_ ();
288 return TARGET_NEWLINE;
320 /* xgettext:no-c-format */
321 ffebad_start_msg_lex ("Non-ISO-C-standard escape sequence `\\%A' at %0",
322 FFEBAD_severityPEDANTIC);
323 ffelex_bad_here_ (0, line, column);
327 return (c == 'E' || c == 'e') ? 033 : c;
333 if (c >= 040 && c < 0177)
339 /* xgettext:no-c-format */
340 ffebad_start_msg_lex ("Unknown escape sequence `\\%A' at %0",
341 FFEBAD_severityPEDANTIC);
342 ffelex_bad_here_ (0, line, column);
348 /* xgettext:no-c-format */
349 ffebad_start_msg_lex ("Unterminated escape sequence `\\' at %0",
350 FFEBAD_severityPEDANTIC);
351 ffelex_bad_here_ (0, line, column);
358 sprintf (&m[0], "%x", c);
359 /* xgettext:no-c-format */
360 ffebad_start_msg_lex ("Unknown escape sequence `\\' followed by char code 0x%A at %0",
361 FFEBAD_severityPEDANTIC);
362 ffelex_bad_here_ (0, line, column);
372 code = (code * 16) + hex_value (c);
373 if (code != 0 || count != 0)
387 /* xgettext:no-c-format */
388 ffebad_start_msg_lex ("\\x used at %0 with no following hex digits",
389 FFEBAD_severityFATAL);
390 ffelex_bad_here_ (0, line, column);
394 /* Digits are all 0's. Ok. */
396 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
398 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
401 /* xgettext:no-c-format */
402 ffebad_start_msg_lex ("Hex escape at %0 out of range",
403 FFEBAD_severityPEDANTIC);
404 ffelex_bad_here_ (0, line, column);
410 if ((c <= '7') && (c >= '0') && (count++ < 3))
412 code = (code * 8) + (c - '0');
419 assert ("bad backslash state" == NULL);
423 /* Come here when code has a built character, and c is the next
424 character that might (or might not) be the next one in the constant. */
426 /* Don't bother doing this check for each character going into
427 CHARACTER or HOLLERITH constants, just the escaped-value ones.
428 gcc apparently checks every single character, which seems
429 like it'd be kinda slow and not worth doing anyway. */
432 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
433 && code >= (1 << TYPE_PRECISION (char_type_node)))
435 /* xgettext:no-c-format */
436 ffebad_start_msg_lex ("Escape sequence at %0 out of range for character",
437 FFEBAD_severityFATAL);
438 ffelex_bad_here_ (0, line, column);
444 /* Known end of constant, just append this character. */
445 ffelex_append_to_token_ (code);
446 if (ffelex_raw_mode_ > 0)
451 /* Have two characters to handle. Do the first, then leave it to the
452 caller to detect anything special about the second. */
454 ffelex_append_to_token_ (code);
455 if (ffelex_raw_mode_ > 0)
457 ffelex_backslash_reconsider_ = TRUE;
461 /* ffelex_bad_1_ -- Issue diagnostic with one source point
463 ffelex_bad_1_(FFEBAD_SOME_ERROR,ffelex_linecount_current_,column + 1);
465 Creates ffewhere line and column objects for the source point, sends them
466 along with the error code to ffebad, then kills the line and column
467 objects before returning. */
470 ffelex_bad_1_ (ffebad errnum, ffewhereLineNumber ln0, ffewhereColumnNumber cn0)
475 wl0 = ffewhere_line_new (ln0);
476 wc0 = ffewhere_column_new (cn0);
477 ffebad_start_lex (errnum);
478 ffebad_here (0, wl0, wc0);
480 ffewhere_line_kill (wl0);
481 ffewhere_column_kill (wc0);
484 /* ffelex_bad_2_ -- Issue diagnostic with two source points
486 ffelex_bad_2_(FFEBAD_SOME_ERROR,ffelex_linecount_current_,column + 1,
487 otherline,othercolumn);
489 Creates ffewhere line and column objects for the source points, sends them
490 along with the error code to ffebad, then kills the line and column
491 objects before returning. */
494 ffelex_bad_2_ (ffebad errnum, ffewhereLineNumber ln0, ffewhereColumnNumber cn0,
495 ffewhereLineNumber ln1, ffewhereColumnNumber cn1)
497 ffewhereLine wl0, wl1;
498 ffewhereColumn wc0, wc1;
500 wl0 = ffewhere_line_new (ln0);
501 wc0 = ffewhere_column_new (cn0);
502 wl1 = ffewhere_line_new (ln1);
503 wc1 = ffewhere_column_new (cn1);
504 ffebad_start_lex (errnum);
505 ffebad_here (0, wl0, wc0);
506 ffebad_here (1, wl1, wc1);
508 ffewhere_line_kill (wl0);
509 ffewhere_column_kill (wc0);
510 ffewhere_line_kill (wl1);
511 ffewhere_column_kill (wc1);
515 ffelex_bad_here_ (int n, ffewhereLineNumber ln0,
516 ffewhereColumnNumber cn0)
521 wl0 = ffewhere_line_new (ln0);
522 wc0 = ffewhere_column_new (cn0);
523 ffebad_here (n, wl0, wc0);
524 ffewhere_line_kill (wl0);
525 ffewhere_column_kill (wc0);
529 ffelex_getc_ (FILE *finput)
533 if (ffelex_kludge_chars_ == NULL)
534 return getc (finput);
536 c = *ffelex_kludge_chars_++;
540 ffelex_kludge_chars_ = NULL;
541 return getc (finput);
545 ffelex_cfebackslash_ (int *use_d, int *d, FILE *finput)
547 register int c = getc (finput);
549 register unsigned count;
550 unsigned firstdig = 0;
570 code = (code * 16) + hex_value (c);
571 if (code != 0 || count != 0)
580 error ("\\x used with no following hex digits");
582 /* Digits are all 0's. Ok. */
584 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
587 << (TYPE_PRECISION (integer_type_node) - (count - 1)
590 pedwarn ("hex escape out of range");
593 case '0': case '1': case '2': case '3': case '4':
594 case '5': case '6': case '7':
597 while ((c <= '7') && (c >= '0') && (count++ < 3))
599 code = (code * 8) + (c - '0');
606 case '\\': case '\'': case '"':
610 ffelex_next_line_ ();
620 return TARGET_NEWLINE;
643 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
649 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
653 /* `\%' is used to prevent SCCS from getting confused. */
656 pedwarn ("non-ISO escape sequence `\\%c'", c);
659 if (c >= 040 && c < 0177)
660 pedwarn ("unknown escape sequence `\\%c'", c);
662 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
666 /* A miniature version of the C front-end lexer. */
669 ffelex_cfelex_ (ffelexToken *xtoken, FILE *finput, int c)
676 register unsigned buffer_length;
678 if ((*xtoken != NULL) && !ffelex_kludge_flag_)
679 ffelex_token_kill (*xtoken);
683 case '0': case '1': case '2': case '3': case '4':
684 case '5': case '6': case '7': case '8': case '9':
685 buffer_length = ARRAY_SIZE (buff);
688 r = &buff[buffer_length];
694 register unsigned bytes_used = (p - q);
699 q = xmalloc (buffer_length);
700 memcpy (q, buff, bytes_used);
703 q = xrealloc (q, buffer_length);
705 r = &q[buffer_length];
707 c = ffelex_getc_ (finput);
712 token = ffelex_token_new_number (q, ffewhere_line_unknown (),
713 ffewhere_column_unknown ());
721 buffer_length = ARRAY_SIZE (buff);
724 r = &buff[buffer_length];
725 c = ffelex_getc_ (finput);
739 case '\\': /* ~~~~~ */
740 c = ffelex_cfebackslash_ (&use_d, &d, finput);
745 error ("badly formed directive -- no closing quote");
755 if (use_d != 2) /* 0=>c, 1=>cd, 2=>nil. */
760 register unsigned bytes_used = (p - q);
762 buffer_length = bytes_used * 2;
765 q = xmalloc (buffer_length);
766 memcpy (q, buff, bytes_used);
769 q = xrealloc (q, buffer_length);
771 r = &q[buffer_length];
780 token = ffelex_token_new_character (q, ffewhere_line_unknown (),
781 ffewhere_column_unknown ());
798 ffelex_file_pop_ (const char *filename)
800 if (input_file_stack->next)
802 struct file_stack *p = input_file_stack;
803 input_file_stack = p->next;
805 input_file_stack_tick++;
806 (*debug_hooks->end_source_file) (input_file_stack->location.line);
809 error ("#-lines for entering and leaving files don't match");
811 /* Now that we've pushed or popped the input stack,
812 update the name in the top element. */
813 if (input_file_stack)
814 input_file_stack->location.file = filename;
818 ffelex_file_push_ (int old_lineno, const char *filename)
820 struct file_stack *p = xmalloc (sizeof (struct file_stack));
822 input_file_stack->location.line = old_lineno;
823 p->next = input_file_stack;
824 p->location.file = filename;
825 input_file_stack = p;
826 input_file_stack_tick++;
828 (*debug_hooks->start_source_file) (0, filename);
830 /* Now that we've pushed or popped the input stack,
831 update the name in the top element. */
832 if (input_file_stack)
833 input_file_stack->location.file = filename;
836 /* Prepare to finish a statement-in-progress by sending the current
837 token, if any, then setting up EOS as the current token with the
838 appropriate current pointer. The caller can then move the current
839 pointer before actually sending EOS, if desired, as it is in
840 typical fixed-form cases. */
843 ffelex_prepare_eos_ (void)
845 if (ffelex_token_->type != FFELEX_typeNONE)
847 ffelex_backslash_ (EOF, 0);
849 switch (ffelex_raw_mode_)
855 ffebad_start_lex ((ffelex_raw_char_ == '\'') ? FFEBAD_NO_CLOSING_APOSTROPHE
856 : FFEBAD_NO_CLOSING_QUOTE);
857 ffebad_here (0, ffelex_token_->where_line, ffelex_token_->where_col);
858 ffebad_here (1, ffelex_current_wl_, ffelex_current_wc_);
869 ffebad_start_lex (FFEBAD_NOT_ENOUGH_HOLLERITH_CHARS);
870 ffebad_here (0, ffelex_token_->where_line, ffelex_token_->where_col);
871 ffebad_here (1, ffelex_current_wl_, ffelex_current_wc_);
872 sprintf (num, "%lu", (unsigned long) ffelex_raw_mode_);
875 /* Make sure the token has some text, might as well fill up with spaces. */
878 ffelex_append_to_token_ (' ');
879 } while (--ffelex_raw_mode_ > 0);
883 ffelex_raw_mode_ = 0;
884 ffelex_send_token_ ();
886 ffelex_token_->type = FFELEX_typeEOS;
887 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
888 ffelex_token_->where_col = ffewhere_column_use (ffelex_current_wc_);
892 ffelex_finish_statement_ (void)
894 if ((ffelex_number_of_tokens_ == 0)
895 && (ffelex_token_->type == FFELEX_typeNONE))
896 return; /* Don't have a statement pending. */
898 if (ffelex_token_->type != FFELEX_typeEOS)
899 ffelex_prepare_eos_ ();
901 ffelex_permit_include_ = TRUE;
902 ffelex_send_token_ ();
903 ffelex_permit_include_ = FALSE;
904 ffelex_number_of_tokens_ = 0;
905 ffelex_label_tokens_ = 0;
906 ffelex_names_ = TRUE;
907 ffelex_names_pure_ = FALSE; /* Probably not necessary. */
908 ffelex_hexnum_ = FALSE;
910 if (!ffe_is_ffedebug ())
913 /* For debugging purposes only. */
915 if (ffelex_total_tokens_ != ffelex_old_total_tokens_)
917 fprintf (dmpout, "; token_track had %ld tokens, now have %ld.\n",
918 ffelex_old_total_tokens_, ffelex_total_tokens_);
919 ffelex_old_total_tokens_ = ffelex_total_tokens_;
923 /* Copied from gcc/c-common.c get_directive_line. */
926 ffelex_get_directive_line_ (char **text, FILE *finput)
928 static char *directive_buffer = NULL;
929 static unsigned buffer_length = 0;
931 register char *buffer_limit;
932 register int looking_for = 0;
933 register int char_escaped = 0;
935 if (buffer_length == 0)
937 directive_buffer = xmalloc (128);
941 buffer_limit = &directive_buffer[buffer_length];
943 for (p = directive_buffer; ; )
947 /* Make buffer bigger if it is full. */
948 if (p >= buffer_limit)
950 register unsigned bytes_used = (p - directive_buffer);
953 directive_buffer = xrealloc (directive_buffer, buffer_length);
954 p = &directive_buffer[bytes_used];
955 buffer_limit = &directive_buffer[buffer_length];
960 /* Discard initial whitespace. */
961 if ((c == ' ' || c == '\t') && p == directive_buffer)
964 /* Detect the end of the directive. */
965 if ((c == '\n' && looking_for == 0)
968 if (looking_for != 0)
969 error ("bad directive -- missing close-quote");
972 *text = directive_buffer;
978 ffelex_next_line_ ();
980 /* Handle string and character constant syntax. */
983 if (looking_for == c && !char_escaped)
984 looking_for = 0; /* Found terminator... stop looking. */
987 if (c == '\'' || c == '"')
988 looking_for = c; /* Don't stop buffering until we see another
989 one of these (or an EOF). */
991 /* Handle backslash. */
992 char_escaped = (c == '\\' && ! char_escaped);
996 /* Handle # directives that make it through (or are generated by) the
997 preprocessor. As much as reasonably possible, emulate the behavior
998 of the gcc compiler phase cc1, though interactions between #include
999 and INCLUDE might possibly produce bizarre results in terms of
1000 error reporting and the generation of debugging info vis-a-vis the
1001 locations of some things.
1003 Returns the next character unhandled, which is always newline or EOF. */
1006 ffelex_hash_ (FILE *finput)
1009 ffelexToken token = NULL;
1011 /* Read first nonwhite char after the `#'. */
1013 c = ffelex_getc_ (finput);
1014 while (c == ' ' || c == '\t')
1015 c = ffelex_getc_ (finput);
1017 /* If a letter follows, then if the word here is `line', skip
1018 it and ignore it; otherwise, ignore the line, with an error
1019 if the word isn't `pragma', `ident', `define', or `undef'. */
1025 if (getc (finput) == 'r'
1026 && getc (finput) == 'a'
1027 && getc (finput) == 'g'
1028 && getc (finput) == 'm'
1029 && getc (finput) == 'a'
1030 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'
1038 if (getc (finput) == 'e'
1039 && getc (finput) == 'f'
1040 && getc (finput) == 'i'
1041 && getc (finput) == 'n'
1042 && getc (finput) == 'e'
1043 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'
1048 c = ffelex_get_directive_line_ (&text, finput);
1050 if (debug_info_level == DINFO_LEVEL_VERBOSE)
1051 (*debug_hooks->define) (input_line, text);
1058 if (getc (finput) == 'n'
1059 && getc (finput) == 'd'
1060 && getc (finput) == 'e'
1061 && getc (finput) == 'f'
1062 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'
1067 c = ffelex_get_directive_line_ (&text, finput);
1069 if (debug_info_level == DINFO_LEVEL_VERBOSE)
1070 (*debug_hooks->undef) (input_line, text);
1077 if (getc (finput) == 'i'
1078 && getc (finput) == 'n'
1079 && getc (finput) == 'e'
1080 && ((c = getc (finput)) == ' ' || c == '\t'))
1085 if (getc (finput) == 'd'
1086 && getc (finput) == 'e'
1087 && getc (finput) == 'n'
1088 && getc (finput) == 't'
1089 && ((c = getc (finput)) == ' ' || c == '\t'))
1091 /* #ident. The pedantic warning is now in cpp. */
1093 /* Here we have just seen `#ident '.
1094 A string constant should follow. */
1096 while (c == ' ' || c == '\t')
1099 /* If no argument, ignore the line. */
1100 if (c == '\n' || c == EOF)
1103 c = ffelex_cfelex_ (&token, finput, c);
1106 || (ffelex_token_type (token) != FFELEX_typeCHARACTER))
1108 error ("invalid #ident");
1112 if (! flag_no_ident)
1114 #ifdef ASM_OUTPUT_IDENT
1115 ASM_OUTPUT_IDENT (asm_out_file,
1116 ffelex_token_text (token));
1120 /* Skip the rest of this line. */
1125 error ("undefined or invalid # directive");
1130 /* Here we have either `#line' or `# <nonletter>'.
1131 In either case, it should be a line number; a digit should follow. */
1133 while (c == ' ' || c == '\t')
1134 c = ffelex_getc_ (finput);
1136 /* If the # is the only nonwhite char on the line,
1137 just ignore it. Check the new newline. */
1138 if (c == '\n' || c == EOF)
1141 /* Something follows the #; read a token. */
1143 c = ffelex_cfelex_ (&token, finput, c);
1146 && (ffelex_token_type (token) == FFELEX_typeNUMBER))
1148 location_t old_loc = input_location;
1151 /* subtract one, because it is the following line that
1152 gets the specified number */
1153 int l = atoi (ffelex_token_text (token)) - 1;
1155 /* Is this the last nonwhite stuff on the line? */
1156 while (c == ' ' || c == '\t')
1157 c = ffelex_getc_ (finput);
1158 if (c == '\n' || c == EOF)
1160 /* No more: store the line number and check following line. */
1162 if (!ffelex_kludge_flag_)
1164 ffewhere_file_set (NULL, TRUE, (ffewhereLineNumber) l);
1167 ffelex_token_kill (token);
1172 /* More follows: it must be a string constant (filename). */
1174 /* Read the string constant. */
1175 c = ffelex_cfelex_ (&token, finput, c);
1178 || (ffelex_token_type (token) != FFELEX_typeCHARACTER))
1180 error ("invalid #line");
1186 if (ffelex_kludge_flag_)
1187 input_filename = ggc_strdup (ffelex_token_text (token));
1190 wf = ffewhere_file_new (ffelex_token_text (token),
1191 ffelex_token_length (token));
1192 input_filename = ffewhere_file_name (wf);
1193 ffewhere_file_set (wf, TRUE, (ffewhereLineNumber) l);
1196 #if 0 /* Not sure what g77 should do with this yet. */
1197 /* Each change of file name
1198 reinitializes whether we are now in a system header. */
1199 in_system_header = 0;
1202 if (main_input_filename == 0)
1203 main_input_filename = input_filename;
1205 /* Is this the last nonwhite stuff on the line? */
1206 while (c == ' ' || c == '\t')
1208 if (c == '\n' || c == EOF)
1210 if (!ffelex_kludge_flag_)
1212 /* Update the name in the top element of input_file_stack. */
1213 if (input_file_stack)
1214 input_file_stack->location.file = input_filename;
1217 ffelex_token_kill (token);
1222 c = ffelex_cfelex_ (&token, finput, c);
1224 /* `1' after file name means entering new file.
1225 `2' after file name means just left a file. */
1228 && (ffelex_token_type (token) == FFELEX_typeNUMBER))
1230 int num = atoi (ffelex_token_text (token));
1232 if (ffelex_kludge_flag_)
1235 input_filename = old_loc.file;
1236 error ("use `#line ...' instead of `# ...' in first line");
1241 /* Pushing to a new file. */
1242 ffelex_file_push_ (old_loc.line, input_filename);
1246 /* Popping out of a file. */
1247 ffelex_file_pop_ (input_filename);
1250 /* Is this the last nonwhite stuff on the line? */
1251 while (c == ' ' || c == '\t')
1253 if (c == '\n' || c == EOF)
1256 ffelex_token_kill (token);
1260 c = ffelex_cfelex_ (&token, finput, c);
1263 /* `3' after file name means this is a system header file. */
1265 #if 0 /* Not sure what g77 should do with this yet. */
1267 && (ffelex_token_type (token) == FFELEX_typeNUMBER)
1268 && (atoi (ffelex_token_text (token)) == 3))
1269 in_system_header = 1;
1272 while (c == ' ' || c == '\t')
1274 if (((token != NULL)
1275 || (c != '\n' && c != EOF))
1276 && ffelex_kludge_flag_)
1279 input_filename = old_loc.file;
1280 error ("use `#line ...' instead of `# ...' in first line");
1282 if (c == '\n' || c == EOF)
1284 if (token != NULL && !ffelex_kludge_flag_)
1285 ffelex_token_kill (token);
1290 error ("invalid #-line");
1292 /* skip the rest of this line. */
1294 if ((token != NULL) && !ffelex_kludge_flag_)
1295 ffelex_token_kill (token);
1296 while ((c = getc (finput)) != EOF && c != '\n')
1301 /* "Image" a character onto the card image, return incremented column number.
1303 Normally invoking this function as in
1304 column = ffelex_image_char_ (c, column);
1305 is the same as doing:
1306 ffelex_card_image_[column++] = c;
1308 However, tabs and carriage returns are handled specially, to preserve
1309 the visual "image" of the input line (in most editors) in the card
1312 Carriage returns are ignored, as they are assumed to be followed
1315 A tab is handled by first doing:
1316 ffelex_card_image_[column++] = ' ';
1317 That is, it translates to at least one space. Then, as many spaces
1318 are imaged as necessary to bring the column number to the next tab
1319 position, where tab positions start in the ninth column and each
1320 eighth column afterwards. ALSO, a static var named ffelex_saw_tab_
1321 is set to TRUE to notify the lexer that a tab was seen.
1323 Columns are numbered and tab stops set as illustrated below:
1325 012345670123456701234567...
1329 xxxxxxx yyyyyyy zzzzzzz
1330 xxxxxxxx yyyyyyyy... */
1332 static ffewhereColumnNumber
1333 ffelex_image_char_ (int c, ffewhereColumnNumber column)
1335 ffewhereColumnNumber old_column = column;
1337 if (column >= ffelex_card_size_)
1339 ffewhereColumnNumber newmax = ffelex_card_size_ << 1;
1341 if (ffelex_bad_line_)
1344 if ((newmax >> 1) != ffelex_card_size_)
1345 { /* Overflowed column number. */
1346 overflow: /* :::::::::::::::::::: */
1348 ffelex_bad_line_ = TRUE;
1349 strcpy (&ffelex_card_image_[column - 3], "...");
1350 ffelex_card_length_ = column;
1351 ffelex_bad_1_ (FFEBAD_LINE_TOO_LONG,
1352 ffelex_linecount_current_, column + 1);
1357 = malloc_resize_ksr (malloc_pool_image (),
1360 ffelex_card_size_ + 9);
1361 ffelex_card_size_ = newmax;
1370 ffelex_saw_tab_ = TRUE;
1371 ffelex_card_image_[column++] = ' ';
1372 while ((column & 7) != 0)
1373 ffelex_card_image_[column++] = ' ';
1377 if (!ffelex_bad_line_)
1379 ffelex_bad_line_ = TRUE;
1380 strcpy (&ffelex_card_image_[column], "[\\0]");
1381 ffelex_card_length_ = column + 4;
1382 /* xgettext:no-c-format */
1383 ffebad_start_msg_lex ("Null character at %0 -- line ignored",
1384 FFEBAD_severityFATAL);
1385 ffelex_bad_here_ (0, ffelex_linecount_current_, column + 1);
1392 ffelex_card_image_[column++] = c;
1396 if (column < old_column)
1398 column = old_column;
1399 goto overflow; /* :::::::::::::::::::: */
1406 ffelex_include_ (void)
1408 ffewhereFile include_wherefile = ffelex_include_wherefile_;
1409 FILE *include_file = ffelex_include_file_;
1410 /* The rest of this is to push, and after the INCLUDE file is processed,
1411 pop, the static lexer state info that pertains to each particular
1414 ffewhereColumnNumber card_size = ffelex_card_size_;
1415 ffewhereColumnNumber card_length = ffelex_card_length_;
1416 ffewhereLine current_wl = ffelex_current_wl_;
1417 ffewhereColumn current_wc = ffelex_current_wc_;
1418 bool saw_tab = ffelex_saw_tab_;
1419 ffewhereColumnNumber final_nontab_column = ffelex_final_nontab_column_;
1420 ffewhereFile current_wf = ffelex_current_wf_;
1421 ffewhereLineNumber linecount_current = ffelex_linecount_current_;
1422 ffewhereLineNumber linecount_offset
1423 = ffewhere_line_filelinenum (current_wl);
1424 location_t old_loc = input_location;
1426 if (card_length != 0)
1428 card_image = malloc_new_ks (malloc_pool_image (),
1429 "FFELEX saved card image",
1431 memcpy (card_image, ffelex_card_image_, card_length);
1436 ffelex_set_include_ = FALSE;
1438 ffelex_next_line_ ();
1440 ffewhere_file_set (include_wherefile, TRUE, 0);
1442 ffelex_file_push_ (old_loc.line, ffewhere_file_name (include_wherefile));
1444 if (ffelex_include_free_form_)
1445 ffelex_file_free (include_wherefile, include_file);
1447 ffelex_file_fixed (include_wherefile, include_file);
1449 ffelex_file_pop_ (ffewhere_file_name (current_wf));
1451 ffewhere_file_set (current_wf, TRUE, linecount_offset);
1453 ffecom_close_include (include_file);
1455 if (card_length != 0)
1457 assert (ffelex_card_size_ >= card_length); /* It shrunk?? */
1458 memcpy (ffelex_card_image_, card_image, card_length);
1460 ffelex_card_image_[card_length] = '\0';
1462 input_location = old_loc;
1463 ffelex_linecount_current_ = linecount_current;
1464 ffelex_current_wf_ = current_wf;
1465 ffelex_final_nontab_column_ = final_nontab_column;
1466 ffelex_saw_tab_ = saw_tab;
1467 ffelex_current_wc_ = current_wc;
1468 ffelex_current_wl_ = current_wl;
1469 ffelex_card_length_ = card_length;
1470 ffelex_card_size_ = card_size;
1473 /* ffelex_is_free_char_ctx_contin_ -- Character Context Continuation?
1475 ffewhereColumnNumber col;
1476 int c; // Char at col.
1477 if ((c == '&') && ffelex_is_free_char_ctx_contin_(col + 1))
1478 // We have a continuation indicator.
1480 If there are <n> spaces starting at ffelex_card_image_[col] up through
1481 the null character, where <n> is 0 or greater, returns TRUE. */
1484 ffelex_is_free_char_ctx_contin_ (ffewhereColumnNumber col)
1486 while (ffelex_card_image_[col] != '\0')
1488 if (ffelex_card_image_[col++] != ' ')
1494 /* ffelex_is_free_nonc_ctx_contin_ -- Noncharacter Context Continuation?
1496 ffewhereColumnNumber col;
1497 int c; // Char at col.
1498 if ((c == '&') && ffelex_is_free_nonc_ctx_contin_(col + 1))
1499 // We have a continuation indicator.
1501 If there are <n> spaces starting at ffelex_card_image_[col] up through
1502 the null character or '!', where <n> is 0 or greater, returns TRUE. */
1505 ffelex_is_free_nonc_ctx_contin_ (ffewhereColumnNumber col)
1507 while ((ffelex_card_image_[col] != '\0') && (ffelex_card_image_[col] != '!'))
1509 if (ffelex_card_image_[col++] != ' ')
1516 ffelex_next_line_ (void)
1518 ffelex_linecount_current_ = ffelex_linecount_next_;
1519 ++ffelex_linecount_next_;
1524 ffelex_send_token_ (void)
1526 ++ffelex_number_of_tokens_;
1528 ffelex_backslash_ (EOF, 0);
1530 if (ffelex_token_->text == NULL)
1532 if (ffelex_token_->type == FFELEX_typeCHARACTER)
1534 ffelex_append_to_token_ ('\0');
1535 ffelex_token_->length = 0;
1539 ffelex_token_->text[ffelex_token_->length] = '\0';
1541 assert (ffelex_raw_mode_ == 0);
1543 if (ffelex_token_->type == FFELEX_typeNAMES)
1545 ffewhere_line_kill (ffelex_token_->currentnames_line);
1546 ffewhere_column_kill (ffelex_token_->currentnames_col);
1549 assert (ffelex_handler_ != NULL);
1550 ffelex_handler_ = (ffelexHandler) (*ffelex_handler_) (ffelex_token_);
1551 assert (ffelex_handler_ != NULL);
1553 ffelex_token_kill (ffelex_token_);
1555 ffelex_token_ = ffelex_token_new_ ();
1556 ffelex_token_->uses = 1;
1557 ffelex_token_->text = NULL;
1558 if (ffelex_raw_mode_ < 0)
1560 ffelex_token_->type = FFELEX_typeCHARACTER;
1561 ffelex_token_->where_line = ffelex_raw_where_line_;
1562 ffelex_token_->where_col = ffelex_raw_where_col_;
1563 ffelex_raw_where_line_ = ffewhere_line_unknown ();
1564 ffelex_raw_where_col_ = ffewhere_column_unknown ();
1568 ffelex_token_->type = FFELEX_typeNONE;
1569 ffelex_token_->where_line = ffewhere_line_unknown ();
1570 ffelex_token_->where_col = ffewhere_column_unknown ();
1573 if (ffelex_set_include_)
1577 /* ffelex_swallow_tokens_ -- Eat all tokens delivered to me
1579 return ffelex_swallow_tokens_;
1581 Return this handler when you don't want to look at any more tokens in the
1582 statement because you've encountered an unrecoverable error in the
1585 static ffelexHandler
1586 ffelex_swallow_tokens_ (ffelexToken t)
1588 assert (ffelex_eos_handler_ != NULL);
1590 if ((ffelex_token_type (t) == FFELEX_typeEOS)
1591 || (ffelex_token_type (t) == FFELEX_typeSEMICOLON))
1592 return (ffelexHandler) (*ffelex_eos_handler_) (t);
1594 return (ffelexHandler) ffelex_swallow_tokens_;
1598 ffelex_token_new_ (void)
1602 ++ffelex_total_tokens_;
1604 t = malloc_new_ks (malloc_pool_image (), "FFELEX token", sizeof (*t));
1605 t->id_ = ffelex_token_nextid_++;
1610 ffelex_type_string_ (ffelexType type)
1612 static const char *const types[] = {
1614 "FFELEX_typeCOMMENT",
1620 "FFELEX_typeDOLLAR",
1622 "FFELEX_typePERCENT",
1623 "FFELEX_typeAMPERSAND",
1624 "FFELEX_typeAPOSTROPHE",
1625 "FFELEX_typeOPEN_PAREN",
1626 "FFELEX_typeCLOSE_PAREN",
1627 "FFELEX_typeASTERISK",
1630 "FFELEX_typePERIOD",
1632 "FFELEX_typeNUMBER",
1633 "FFELEX_typeOPEN_ANGLE",
1634 "FFELEX_typeEQUALS",
1635 "FFELEX_typeCLOSE_ANGLE",
1639 "FFELEX_typeCONCAT",
1642 "FFELEX_typeHOLLERITH",
1643 "FFELEX_typeCHARACTER",
1645 "FFELEX_typeSEMICOLON",
1646 "FFELEX_typeUNDERSCORE",
1647 "FFELEX_typeQUESTION",
1648 "FFELEX_typeOPEN_ARRAY",
1649 "FFELEX_typeCLOSE_ARRAY",
1650 "FFELEX_typeCOLONCOLON",
1651 "FFELEX_typeREL_LE",
1652 "FFELEX_typeREL_NE",
1653 "FFELEX_typeREL_EQ",
1654 "FFELEX_typePOINTS",
1658 if (type >= ARRAY_SIZE (types))
1664 ffelex_display_token (ffelexToken t)
1669 fprintf (dmpout, "; Token #%lu is %s (line %" ffewhereLineNumber_f "u, col %"
1670 ffewhereColumnNumber_f "u)",
1672 ffelex_type_string_ (t->type),
1673 ffewhere_line_number (t->where_line),
1674 ffewhere_column_number (t->where_col));
1676 if (t->text != NULL)
1677 fprintf (dmpout, ": \"%.*s\"\n",
1681 fprintf (dmpout, ".\n");
1684 /* ffelex_expecting_character -- Tells if next token expected to be CHARACTER
1686 if (ffelex_expecting_character())
1687 // next token delivered by lexer will be CHARACTER.
1689 If the most recent call to ffelex_set_expecting_hollerith since the last
1690 token was delivered by the lexer passed a length of -1, then we return
1691 TRUE, because the next token we deliver will be typeCHARACTER, else we
1695 ffelex_expecting_character (void)
1697 return (ffelex_raw_mode_ != 0);
1700 /* ffelex_file_fixed -- Lex a given file in fixed source form
1704 ffelex_file_fixed(wf,f);
1706 Lexes the file according to Fortran 90 ANSI + VXT specifications. */
1709 ffelex_file_fixed (ffewhereFile wf, FILE *f)
1711 register int c = 0; /* Character currently under consideration. */
1712 register ffewhereColumnNumber column = 0; /* Not really; 0 means column 1... */
1713 bool disallow_continuation_line;
1714 bool ignore_disallowed_continuation = FALSE;
1715 int latest_char_in_file = 0; /* For getting back into comment-skipping
1718 ffewhereColumnNumber first_label_char; /* First char of label --
1720 char label_string[6]; /* Text of label. */
1721 int labi; /* Length of label text. */
1722 bool finish_statement; /* Previous statement finished? */
1723 bool have_content; /* This line have content? */
1724 bool just_do_label; /* Nothing but label (and continuation?) on
1727 /* Lex is called for a particular file, not for a particular program unit.
1728 Yet the two events do share common characteristics. The first line in a
1729 file or in a program unit cannot be a continuation line. No token can
1730 be in mid-formation. No current label for the statement exists, since
1731 there is no current statement. */
1733 assert (ffelex_handler_ != NULL);
1736 input_filename = ffewhere_file_name (wf);
1737 ffelex_current_wf_ = wf;
1738 disallow_continuation_line = TRUE;
1739 ignore_disallowed_continuation = FALSE;
1740 ffelex_token_->type = FFELEX_typeNONE;
1741 ffelex_number_of_tokens_ = 0;
1742 ffelex_label_tokens_ = 0;
1743 ffelex_current_wl_ = ffewhere_line_unknown ();
1744 ffelex_current_wc_ = ffewhere_column_unknown ();
1745 latest_char_in_file = '\n';
1747 goto first_line; /* :::::::::::::::::::: */
1749 /* Come here to get a new line. */
1751 beginning_of_line: /* :::::::::::::::::::: */
1753 disallow_continuation_line = FALSE;
1755 /* Come here directly when last line didn't clarify the continuation issue. */
1757 beginning_of_line_again: /* :::::::::::::::::::: */
1759 first_line: /* :::::::::::::::::::: */
1761 c = latest_char_in_file;
1762 if ((c == EOF) || ((c = ffelex_getc_ (f)) == EOF))
1765 end_of_file: /* :::::::::::::::::::: */
1767 /* Line ending in EOF instead of \n still counts as a whole line. */
1769 ffelex_finish_statement_ ();
1770 ffewhere_line_kill (ffelex_current_wl_);
1771 ffewhere_column_kill (ffelex_current_wc_);
1772 return (ffelexHandler) ffelex_handler_;
1775 ffelex_next_line_ ();
1777 ffelex_bad_line_ = FALSE;
1779 /* Skip over comment (and otherwise ignored) lines as quickly as possible! */
1781 while (((lextype = ffelex_first_char_[c]) == FFELEX_typeCOMMENT)
1782 || (lextype == FFELEX_typeERROR)
1783 || (lextype == FFELEX_typeSLASH)
1784 || (lextype == FFELEX_typeHASH))
1786 /* Test most frequent type of line first, etc. */
1787 if ((lextype == FFELEX_typeCOMMENT)
1788 || ((lextype == FFELEX_typeSLASH)
1789 && ((c = getc (f)) == '*'))) /* NOTE SIDE-EFFECT. */
1791 /* Typical case (straight comment), just ignore rest of line. */
1792 comment_line: /* :::::::::::::::::::: */
1794 while ((c != '\n') && (c != EOF))
1797 else if (lextype == FFELEX_typeHASH)
1798 c = ffelex_hash_ (f);
1799 else if (lextype == FFELEX_typeSLASH)
1801 /* SIDE-EFFECT ABOVE HAS HAPPENED. */
1802 ffelex_card_image_[0] = '/';
1803 ffelex_card_image_[1] = c;
1805 goto bad_first_character; /* :::::::::::::::::::: */
1808 /* typeERROR or unsupported typeHASH. */
1809 { /* Bad first character, get line and display
1811 column = ffelex_image_char_ (c, 0);
1813 bad_first_character: /* :::::::::::::::::::: */
1815 ffelex_bad_line_ = TRUE;
1816 while (((c = getc (f)) != '\n') && (c != EOF))
1817 column = ffelex_image_char_ (c, column);
1818 ffelex_card_image_[column] = '\0';
1819 ffelex_card_length_ = column;
1820 ffelex_bad_1_ (FFEBAD_FIRST_CHAR_INVALID,
1821 ffelex_linecount_current_, 1);
1824 /* Read past last char in line. */
1828 ffelex_next_line_ ();
1829 goto end_of_file; /* :::::::::::::::::::: */
1834 ffelex_next_line_ ();
1837 goto end_of_file; /* :::::::::::::::::::: */
1839 ffelex_bad_line_ = FALSE;
1840 } /* while [c, first char, means comment] */
1844 || (ffelex_final_nontab_column_ == 0);
1846 if (lextype == FFELEX_typeDEBUG)
1847 c = ' '; /* A 'D' or 'd' in column 1 with the
1848 debug-lines option on. */
1850 column = ffelex_image_char_ (c, 0);
1852 /* Read the entire line in as is (with whitespace processing). */
1854 while (((c = getc (f)) != '\n') && (c != EOF))
1855 column = ffelex_image_char_ (c, column);
1857 if (ffelex_bad_line_)
1859 ffelex_card_image_[column] = '\0';
1860 ffelex_card_length_ = column;
1861 goto comment_line; /* :::::::::::::::::::: */
1864 /* If no tab, cut off line after column 72/132. */
1866 if (!ffelex_saw_tab_ && (column > ffelex_final_nontab_column_))
1868 /* Technically, we should now fill ffelex_card_image_ up thru column
1869 72/132 with spaces, since character/hollerith constants must count
1870 them in that manner. To save CPU time in several ways (avoid a loop
1871 here that would be used only when we actually end a line in
1872 character-constant mode; avoid writing memory unnecessarily; avoid a
1873 loop later checking spaces when not scanning for character-constant
1874 characters), we don't do this, and we do the appropriate thing when
1875 we encounter end-of-line while actually processing a character
1878 column = ffelex_final_nontab_column_;
1881 ffelex_card_image_[column] = '\0';
1882 ffelex_card_length_ = column;
1884 /* Save next char in file so we can use register-based c while analyzing
1885 line we just read. */
1887 latest_char_in_file = c; /* Should be either '\n' or EOF. */
1889 have_content = FALSE;
1891 /* Handle label, if any. */
1894 first_label_char = FFEWHERE_columnUNKNOWN;
1895 for (column = 0; column < 5; ++column)
1897 switch (c = ffelex_card_image_[column])
1901 goto stop_looking; /* :::::::::::::::::::: */
1916 label_string[labi++] = c;
1917 if (first_label_char == FFEWHERE_columnUNKNOWN)
1918 first_label_char = column + 1;
1924 ffelex_bad_1_ (FFEBAD_LABEL_FIELD_NOT_NUMERIC,
1925 ffelex_linecount_current_,
1927 goto beginning_of_line_again; /* :::::::::::::::::::: */
1929 if (ffe_is_pedantic ())
1930 ffelex_bad_1_ (FFEBAD_AMPERSAND,
1931 ffelex_linecount_current_, 1);
1932 finish_statement = FALSE;
1933 just_do_label = FALSE;
1934 goto got_a_continuation; /* :::::::::::::::::::: */
1937 if (ffelex_card_image_[column + 1] == '*')
1938 goto stop_looking; /* :::::::::::::::::::: */
1941 ffelex_bad_1_ (FFEBAD_LABEL_FIELD_NOT_NUMERIC,
1942 ffelex_linecount_current_, column + 1);
1943 goto beginning_of_line_again; /* :::::::::::::::::::: */
1947 stop_looking: /* :::::::::::::::::::: */
1949 label_string[labi] = '\0';
1951 /* Find first nonblank char starting with continuation column. */
1953 if (column == 5) /* In which case we didn't see end of line in
1955 while ((c = ffelex_card_image_[column]) == ' ')
1958 /* Now we're trying to figure out whether this is a continuation line and
1959 whether there's anything else of substance on the line. The cases are
1962 1. If a line has an explicit continuation character (other than the digit
1963 zero), then if it also has a label, the label is ignored and an error
1964 message is printed. Any remaining text on the line is passed to the
1965 parser tasks, thus even an all-blank line (possibly with an ignored
1966 label) aside from a positive continuation character might have meaning
1967 in the midst of a character or hollerith constant.
1969 2. If a line has no explicit continuation character (that is, it has a
1970 space in column 6 and the first non-space character past column 6 is
1971 not a digit 0-9), then there are two possibilities:
1973 A. A label is present and/or a non-space (and non-comment) character
1974 appears somewhere after column 6. Terminate processing of the previous
1975 statement, if any, send the new label for the next statement, if any,
1976 and start processing a new statement with this non-blank character, if
1979 B. The line is essentially blank, except for a possible comment character.
1980 Don't terminate processing of the previous statement and don't pass any
1981 characters to the parser tasks, since the line is not flagged as a
1982 continuation line. We treat it just like a completely blank line.
1984 3. If a line has a continuation character of zero (0), then we terminate
1985 processing of the previous statement, if any, send the new label for the
1986 next statement, if any, and start processing a new statement, if any
1987 non-blank characters are present.
1989 If, when checking to see if we should terminate the previous statement, it
1990 is found that there is no previous statement but that there is an
1991 outstanding label, substitute CONTINUE as the statement for the label
1992 and display an error message. */
1994 finish_statement = FALSE;
1995 just_do_label = FALSE;
1999 case '!': /* ANSI Fortran 90 says ! in column 6 is
2001 /* VXT Fortran says ! anywhere is comment, even column 6. */
2002 if (ffe_is_vxt () || (column != 5))
2003 goto no_tokens_on_line; /* :::::::::::::::::::: */
2004 goto got_a_continuation; /* :::::::::::::::::::: */
2007 if (ffelex_card_image_[column + 1] != '*')
2008 goto some_other_character; /* :::::::::::::::::::: */
2012 /* This seems right to do. But it is close to call, since / * starting
2013 in column 6 will thus be interpreted as a continuation line
2014 beginning with '*'. */
2016 goto got_a_continuation;/* :::::::::::::::::::: */
2020 /* End of line. Therefore may be continued-through line, so handle
2021 pending label as possible to-be-continued and drive end-of-statement
2022 for any previous statement, else treat as blank line. */
2024 no_tokens_on_line: /* :::::::::::::::::::: */
2026 if (ffe_is_pedantic () && (c == '/'))
2027 ffelex_bad_1_ (FFEBAD_NON_ANSI_COMMENT,
2028 ffelex_linecount_current_, column + 1);
2029 if (first_label_char != FFEWHERE_columnUNKNOWN)
2030 { /* Can't be a continued-through line if it
2032 finish_statement = TRUE;
2033 have_content = TRUE;
2034 just_do_label = TRUE;
2037 goto beginning_of_line_again; /* :::::::::::::::::::: */
2040 if (ffe_is_pedantic () && (column != 5))
2041 ffelex_bad_1_ (FFEBAD_NON_ANSI_CONTINUATION_COLUMN,
2042 ffelex_linecount_current_, column + 1);
2043 finish_statement = TRUE;
2044 goto check_for_content; /* :::::::::::::::::::: */
2056 /* NOTE: This label can be reached directly from the code
2057 that lexes the label field in columns 1-5. */
2058 got_a_continuation: /* :::::::::::::::::::: */
2060 if (first_label_char != FFEWHERE_columnUNKNOWN)
2062 ffelex_bad_2_ (FFEBAD_LABEL_ON_CONTINUATION,
2063 ffelex_linecount_current_,
2065 ffelex_linecount_current_,
2067 first_label_char = FFEWHERE_columnUNKNOWN;
2069 if (disallow_continuation_line)
2071 if (!ignore_disallowed_continuation)
2072 ffelex_bad_1_ (FFEBAD_INVALID_CONTINUATION,
2073 ffelex_linecount_current_, column + 1);
2074 goto beginning_of_line_again; /* :::::::::::::::::::: */
2076 if (ffe_is_pedantic () && (column != 5))
2077 ffelex_bad_1_ (FFEBAD_NON_ANSI_CONTINUATION_COLUMN,
2078 ffelex_linecount_current_, column + 1);
2079 if ((ffelex_raw_mode_ != 0)
2080 && (((c = ffelex_card_image_[column + 1]) != '\0')
2081 || !ffelex_saw_tab_))
2084 have_content = TRUE;
2088 check_for_content: /* :::::::::::::::::::: */
2090 while ((c = ffelex_card_image_[++column]) == ' ')
2095 && (ffelex_card_image_[column + 1] == '*')))
2097 if (ffe_is_pedantic () && (c == '/'))
2098 ffelex_bad_1_ (FFEBAD_NON_ANSI_COMMENT,
2099 ffelex_linecount_current_, column + 1);
2100 just_do_label = TRUE;
2103 have_content = TRUE;
2108 some_other_character: /* :::::::::::::::::::: */
2111 goto got_a_continuation;/* :::::::::::::::::::: */
2113 /* Here is the very normal case of a regular character starting in
2114 column 7 or beyond with a blank in column 6. */
2116 finish_statement = TRUE;
2117 have_content = TRUE;
2122 || (first_label_char != FFEWHERE_columnUNKNOWN))
2124 /* The line has content of some kind, install new end-statement
2125 point for error messages. Note that "content" includes cases
2126 where there's little apparent content but enough to finish
2127 a statement. That's because finishing a statement can trigger
2128 an impending INCLUDE, and that requires accurate line info being
2129 maintained by the lexer. */
2131 if (finish_statement)
2132 ffelex_prepare_eos_ (); /* Prepare EOS before we move current pointer. */
2134 ffewhere_line_kill (ffelex_current_wl_);
2135 ffewhere_column_kill (ffelex_current_wc_);
2136 ffelex_current_wl_ = ffewhere_line_new (ffelex_linecount_current_);
2137 ffelex_current_wc_ = ffewhere_column_new (ffelex_card_length_ + 1);
2140 /* We delay this for a combination of reasons. Mainly, it can start
2141 INCLUDE processing, and we want to delay that until the lexer's
2142 info on the line is coherent. And we want to delay that until we're
2143 sure there's a reason to make that info coherent, to avoid saving
2144 lots of useless lines. */
2146 if (finish_statement)
2147 ffelex_finish_statement_ ();
2149 /* If label is present, enclose it in a NUMBER token and send it along. */
2151 if (first_label_char != FFEWHERE_columnUNKNOWN)
2153 assert (ffelex_token_->type == FFELEX_typeNONE);
2154 ffelex_token_->type = FFELEX_typeNUMBER;
2155 ffelex_append_to_token_ ('\0'); /* Make room for label text. */
2156 strcpy (ffelex_token_->text, label_string);
2157 ffelex_token_->where_line
2158 = ffewhere_line_use (ffelex_current_wl_);
2159 ffelex_token_->where_col = ffewhere_column_new (first_label_char);
2160 ffelex_token_->length = labi;
2161 ffelex_send_token_ ();
2162 ++ffelex_label_tokens_;
2166 goto beginning_of_line; /* :::::::::::::::::::: */
2168 /* Here is the main engine for parsing. c holds the character at column.
2169 It is already known that c is not a blank, end of line, or shriek,
2170 unless ffelex_raw_mode_ is not 0 (indicating we are in a
2171 character/hollerith constant). A partially filled token may already
2172 exist in ffelex_token_. One special case: if, when the end of the line
2173 is reached, continuation_line is FALSE and the only token on the line is
2174 END, then it is indeed the last statement. We don't look for
2175 continuation lines during this program unit in that case. This is
2176 according to ANSI. */
2178 if (ffelex_raw_mode_ != 0)
2181 parse_raw_character: /* :::::::::::::::::::: */
2185 ffewhereColumnNumber i;
2187 if (ffelex_saw_tab_ || (column >= ffelex_final_nontab_column_))
2188 goto beginning_of_line; /* :::::::::::::::::::: */
2190 /* Pad out line with "virtual" spaces. */
2192 for (i = column; i < ffelex_final_nontab_column_; ++i)
2193 ffelex_card_image_[i] = ' ';
2194 ffelex_card_image_[i] = '\0';
2195 ffelex_card_length_ = i;
2199 switch (ffelex_raw_mode_)
2202 c = ffelex_backslash_ (c, column);
2206 if (!ffelex_backslash_reconsider_)
2207 ffelex_append_to_token_ (c);
2208 ffelex_raw_mode_ = -1;
2212 if (c == ffelex_raw_char_)
2214 ffelex_raw_mode_ = -1;
2215 ffelex_append_to_token_ (c);
2219 ffelex_raw_mode_ = 0;
2220 ffelex_backslash_reconsider_ = TRUE;
2225 if (c == ffelex_raw_char_)
2226 ffelex_raw_mode_ = -2;
2229 c = ffelex_backslash_ (c, column);
2232 ffelex_raw_mode_ = -3;
2236 ffelex_append_to_token_ (c);
2241 c = ffelex_backslash_ (c, column);
2245 if (!ffelex_backslash_reconsider_)
2247 ffelex_append_to_token_ (c);
2253 if (ffelex_backslash_reconsider_)
2254 ffelex_backslash_reconsider_ = FALSE;
2256 c = ffelex_card_image_[++column];
2258 if (ffelex_raw_mode_ == 0)
2260 ffelex_send_token_ ();
2261 assert (ffelex_raw_mode_ == 0);
2263 c = ffelex_card_image_[++column];
2267 && (ffelex_card_image_[column + 1] == '*')))
2268 goto beginning_of_line; /* :::::::::::::::::::: */
2269 goto parse_nonraw_character; /* :::::::::::::::::::: */
2271 goto parse_raw_character; /* :::::::::::::::::::: */
2274 parse_nonraw_character: /* :::::::::::::::::::: */
2276 switch (ffelex_token_->type)
2278 case FFELEX_typeNONE:
2282 ffelex_token_->type = FFELEX_typeQUOTE;
2283 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2284 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2285 ffelex_send_token_ ();
2289 ffelex_token_->type = FFELEX_typeDOLLAR;
2290 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2291 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2292 ffelex_send_token_ ();
2296 ffelex_token_->type = FFELEX_typePERCENT;
2297 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2298 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2299 ffelex_send_token_ ();
2303 ffelex_token_->type = FFELEX_typeAMPERSAND;
2304 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2305 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2306 ffelex_send_token_ ();
2310 ffelex_token_->type = FFELEX_typeAPOSTROPHE;
2311 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2312 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2313 ffelex_send_token_ ();
2317 ffelex_token_->type = FFELEX_typeOPEN_PAREN;
2318 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2319 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2323 ffelex_token_->type = FFELEX_typeCLOSE_PAREN;
2324 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2325 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2326 ffelex_send_token_ ();
2330 ffelex_token_->type = FFELEX_typeASTERISK;
2331 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2332 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2336 ffelex_token_->type = FFELEX_typePLUS;
2337 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2338 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2339 ffelex_send_token_ ();
2343 ffelex_token_->type = FFELEX_typeCOMMA;
2344 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2345 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2346 ffelex_send_token_ ();
2350 ffelex_token_->type = FFELEX_typeMINUS;
2351 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2352 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2353 ffelex_send_token_ ();
2357 ffelex_token_->type = FFELEX_typePERIOD;
2358 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2359 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2360 ffelex_send_token_ ();
2364 ffelex_token_->type = FFELEX_typeSLASH;
2365 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2366 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2380 = ffelex_hexnum_ ? FFELEX_typeNAME : FFELEX_typeNUMBER;
2381 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2382 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2383 ffelex_append_to_token_ (c);
2387 ffelex_token_->type = FFELEX_typeCOLON;
2388 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2389 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2393 ffelex_token_->type = FFELEX_typeSEMICOLON;
2394 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2395 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2396 ffelex_permit_include_ = TRUE;
2397 ffelex_send_token_ ();
2398 ffelex_permit_include_ = FALSE;
2402 ffelex_token_->type = FFELEX_typeOPEN_ANGLE;
2403 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2404 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2408 ffelex_token_->type = FFELEX_typeEQUALS;
2409 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2410 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2414 ffelex_token_->type = FFELEX_typeCLOSE_ANGLE;
2415 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2416 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2420 ffelex_token_->type = FFELEX_typeQUESTION;
2421 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
2422 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2423 ffelex_send_token_ ();
2427 if (1 || ffe_is_90 ())
2429 ffelex_token_->type = FFELEX_typeUNDERSCORE;
2430 ffelex_token_->where_line
2431 = ffewhere_line_use (ffelex_current_wl_);
2432 ffelex_token_->where_col
2433 = ffewhere_column_new (column + 1);
2434 ffelex_send_token_ ();
2490 c = ffesrc_char_source (c);
2492 if (ffesrc_char_match_init (c, 'H', 'h')
2493 && ffelex_expecting_hollerith_ != 0)
2495 ffelex_raw_mode_ = ffelex_expecting_hollerith_;
2496 ffelex_token_->type = FFELEX_typeHOLLERITH;
2497 ffelex_token_->where_line = ffelex_raw_where_line_;
2498 ffelex_token_->where_col = ffelex_raw_where_col_;
2499 ffelex_raw_where_line_ = ffewhere_line_unknown ();
2500 ffelex_raw_where_col_ = ffewhere_column_unknown ();
2501 c = ffelex_card_image_[++column];
2502 goto parse_raw_character; /* :::::::::::::::::::: */
2507 ffelex_token_->where_line
2508 = ffewhere_line_use (ffelex_token_->currentnames_line
2509 = ffewhere_line_use (ffelex_current_wl_));
2510 ffelex_token_->where_col
2511 = ffewhere_column_use (ffelex_token_->currentnames_col
2512 = ffewhere_column_new (column + 1));
2513 ffelex_token_->type = FFELEX_typeNAMES;
2517 ffelex_token_->where_line
2518 = ffewhere_line_use (ffelex_current_wl_);
2519 ffelex_token_->where_col = ffewhere_column_new (column + 1);
2520 ffelex_token_->type = FFELEX_typeNAME;
2522 ffelex_append_to_token_ (c);
2526 ffelex_bad_1_ (FFEBAD_UNRECOGNIZED_CHARACTER,
2527 ffelex_linecount_current_, column + 1);
2528 ffelex_finish_statement_ ();
2529 disallow_continuation_line = TRUE;
2530 ignore_disallowed_continuation = TRUE;
2531 goto beginning_of_line_again; /* :::::::::::::::::::: */
2535 case FFELEX_typeNAME:
2590 c = ffesrc_char_source (c);
2605 && !ffe_is_dollar_ok ())
2607 ffelex_send_token_ ();
2608 goto parse_next_character; /* :::::::::::::::::::: */
2610 ffelex_append_to_token_ (c);
2614 ffelex_send_token_ ();
2615 goto parse_next_character; /* :::::::::::::::::::: */
2619 case FFELEX_typeNAMES:
2674 c = ffesrc_char_source (c);
2689 && !ffe_is_dollar_ok ())
2691 ffelex_send_token_ ();
2692 goto parse_next_character; /* :::::::::::::::::::: */
2694 if (ffelex_token_->length < FFEWHERE_indexMAX)
2696 ffewhere_track (&ffelex_token_->currentnames_line,
2697 &ffelex_token_->currentnames_col,
2698 ffelex_token_->wheretrack,
2699 ffelex_token_->length,
2700 ffelex_linecount_current_,
2703 ffelex_append_to_token_ (c);
2707 ffelex_send_token_ ();
2708 goto parse_next_character; /* :::::::::::::::::::: */
2712 case FFELEX_typeNUMBER:
2725 ffelex_append_to_token_ (c);
2729 ffelex_send_token_ ();
2730 goto parse_next_character; /* :::::::::::::::::::: */
2734 case FFELEX_typeASTERISK:
2738 ffelex_token_->type = FFELEX_typePOWER;
2739 ffelex_send_token_ ();
2742 default: /* * not followed by another *. */
2743 ffelex_send_token_ ();
2744 goto parse_next_character; /* :::::::::::::::::::: */
2748 case FFELEX_typeCOLON:
2752 ffelex_token_->type = FFELEX_typeCOLONCOLON;
2753 ffelex_send_token_ ();
2756 default: /* : not followed by another :. */
2757 ffelex_send_token_ ();
2758 goto parse_next_character; /* :::::::::::::::::::: */
2762 case FFELEX_typeSLASH:
2766 ffelex_token_->type = FFELEX_typeCONCAT;
2767 ffelex_send_token_ ();
2771 ffelex_token_->type = FFELEX_typeCLOSE_ARRAY;
2772 ffelex_send_token_ ();
2776 ffelex_token_->type = FFELEX_typeREL_NE;
2777 ffelex_send_token_ ();
2781 ffelex_send_token_ ();
2782 goto parse_next_character; /* :::::::::::::::::::: */
2786 case FFELEX_typeOPEN_PAREN:
2790 ffelex_token_->type = FFELEX_typeOPEN_ARRAY;
2791 ffelex_send_token_ ();
2795 ffelex_send_token_ ();
2796 goto parse_next_character; /* :::::::::::::::::::: */
2800 case FFELEX_typeOPEN_ANGLE:
2804 ffelex_token_->type = FFELEX_typeREL_LE;
2805 ffelex_send_token_ ();
2809 ffelex_send_token_ ();
2810 goto parse_next_character; /* :::::::::::::::::::: */
2814 case FFELEX_typeEQUALS:
2818 ffelex_token_->type = FFELEX_typeREL_EQ;
2819 ffelex_send_token_ ();
2823 ffelex_token_->type = FFELEX_typePOINTS;
2824 ffelex_send_token_ ();
2828 ffelex_send_token_ ();
2829 goto parse_next_character; /* :::::::::::::::::::: */
2833 case FFELEX_typeCLOSE_ANGLE:
2837 ffelex_token_->type = FFELEX_typeREL_GE;
2838 ffelex_send_token_ ();
2842 ffelex_send_token_ ();
2843 goto parse_next_character; /* :::::::::::::::::::: */
2848 assert ("Serious error!!" == NULL);
2853 c = ffelex_card_image_[++column];
2855 parse_next_character: /* :::::::::::::::::::: */
2857 if (ffelex_raw_mode_ != 0)
2858 goto parse_raw_character; /* :::::::::::::::::::: */
2861 c = ffelex_card_image_[++column];
2866 && (ffelex_card_image_[column + 1] == '*')))
2868 if ((ffelex_number_of_tokens_ == ffelex_label_tokens_)
2869 && (ffelex_token_->type == FFELEX_typeNAMES)
2870 && (ffelex_token_->length == 3)
2871 && (ffesrc_strncmp_2c (ffe_case_match (),
2872 ffelex_token_->text,
2873 "END", "end", "End",
2877 ffelex_finish_statement_ ();
2878 disallow_continuation_line = TRUE;
2879 ignore_disallowed_continuation = FALSE;
2880 goto beginning_of_line_again; /* :::::::::::::::::::: */
2882 goto beginning_of_line; /* :::::::::::::::::::: */
2884 goto parse_nonraw_character; /* :::::::::::::::::::: */
2887 /* ffelex_file_free -- Lex a given file in free source form
2891 ffelex_file_free(wf,f);
2893 Lexes the file according to Fortran 90 ANSI + VXT specifications. */
2896 ffelex_file_free (ffewhereFile wf, FILE *f)
2898 register int c = 0; /* Character currently under consideration. */
2899 register ffewhereColumnNumber column = 0; /* Not really; 0 means column 1... */
2900 bool continuation_line = FALSE;
2901 ffewhereColumnNumber continuation_column;
2902 int latest_char_in_file = 0; /* For getting back into comment-skipping
2905 /* Lex is called for a particular file, not for a particular program unit.
2906 Yet the two events do share common characteristics. The first line in a
2907 file or in a program unit cannot be a continuation line. No token can
2908 be in mid-formation. No current label for the statement exists, since
2909 there is no current statement. */
2911 assert (ffelex_handler_ != NULL);
2914 input_filename = ffewhere_file_name (wf);
2915 ffelex_current_wf_ = wf;
2916 continuation_line = FALSE;
2917 ffelex_token_->type = FFELEX_typeNONE;
2918 ffelex_number_of_tokens_ = 0;
2919 ffelex_current_wl_ = ffewhere_line_unknown ();
2920 ffelex_current_wc_ = ffewhere_column_unknown ();
2921 latest_char_in_file = '\n';
2923 /* Come here to get a new line. */
2925 beginning_of_line: /* :::::::::::::::::::: */
2927 c = latest_char_in_file;
2928 if ((c == EOF) || ((c = ffelex_getc_ (f)) == EOF))
2931 end_of_file: /* :::::::::::::::::::: */
2933 /* Line ending in EOF instead of \n still counts as a whole line. */
2935 ffelex_finish_statement_ ();
2936 ffewhere_line_kill (ffelex_current_wl_);
2937 ffewhere_column_kill (ffelex_current_wc_);
2938 return (ffelexHandler) ffelex_handler_;
2941 ffelex_next_line_ ();
2943 ffelex_bad_line_ = FALSE;
2945 /* Skip over initial-comment and empty lines as quickly as possible! */
2952 c = ffelex_hash_ (f);
2954 comment_line: /* :::::::::::::::::::: */
2956 while ((c != '\n') && (c != EOF))
2961 ffelex_next_line_ ();
2962 goto end_of_file; /* :::::::::::::::::::: */
2967 ffelex_next_line_ ();
2970 goto end_of_file; /* :::::::::::::::::::: */
2973 ffelex_saw_tab_ = FALSE;
2975 column = ffelex_image_char_ (c, 0);
2977 /* Read the entire line in as is (with whitespace processing). */
2979 while (((c = getc (f)) != '\n') && (c != EOF))
2980 column = ffelex_image_char_ (c, column);
2982 if (ffelex_bad_line_)
2984 ffelex_card_image_[column] = '\0';
2985 ffelex_card_length_ = column;
2986 goto comment_line; /* :::::::::::::::::::: */
2989 /* If no tab, cut off line after column 132. */
2991 if (!ffelex_saw_tab_ && (column > FFELEX_FREE_MAX_COLUMNS_))
2992 column = FFELEX_FREE_MAX_COLUMNS_;
2994 ffelex_card_image_[column] = '\0';
2995 ffelex_card_length_ = column;
2997 /* Save next char in file so we can use register-based c while analyzing
2998 line we just read. */
3000 latest_char_in_file = c; /* Should be either '\n' or EOF. */
3003 continuation_column = 0;
3005 /* Skip over initial spaces to see if the first nonblank character
3006 is exclamation point, newline, or EOF (line is therefore a comment) or
3007 ampersand (line is therefore a continuation line). */
3009 while ((c = ffelex_card_image_[column]) == ' ')
3016 goto beginning_of_line; /* :::::::::::::::::::: */
3019 continuation_column = column + 1;
3026 /* The line definitely has content of some kind, install new end-statement
3027 point for error messages. */
3029 ffewhere_line_kill (ffelex_current_wl_);
3030 ffewhere_column_kill (ffelex_current_wc_);
3031 ffelex_current_wl_ = ffewhere_line_new (ffelex_linecount_current_);
3032 ffelex_current_wc_ = ffewhere_column_new (ffelex_card_length_ + 1);
3034 /* Figure out which column to start parsing at. */
3036 if (continuation_line)
3038 if (continuation_column == 0)
3040 if (ffelex_raw_mode_ != 0)
3042 ffelex_bad_1_ (FFEBAD_BAD_CHAR_CONTINUE,
3043 ffelex_linecount_current_, column + 1);
3045 else if (ffelex_token_->type != FFELEX_typeNONE)
3047 ffelex_bad_1_ (FFEBAD_BAD_LEXTOK_CONTINUE,
3048 ffelex_linecount_current_, column + 1);
3051 else if (ffelex_is_free_char_ctx_contin_ (continuation_column))
3052 { /* Line contains only a single "&" as only
3053 nonblank character. */
3054 ffelex_bad_1_ (FFEBAD_BAD_FREE_CONTINUE,
3055 ffelex_linecount_current_, continuation_column);
3056 goto beginning_of_line; /* :::::::::::::::::::: */
3058 column = continuation_column;
3063 c = ffelex_card_image_[column];
3064 continuation_line = FALSE;
3066 /* Here is the main engine for parsing. c holds the character at column.
3067 It is already known that c is not a blank, end of line, or shriek,
3068 unless ffelex_raw_mode_ is not 0 (indicating we are in a
3069 character/hollerith constant). A partially filled token may already
3070 exist in ffelex_token_. */
3072 if (ffelex_raw_mode_ != 0)
3075 parse_raw_character: /* :::::::::::::::::::: */
3080 if (ffelex_is_free_char_ctx_contin_ (column + 1))
3082 continuation_line = TRUE;
3083 goto beginning_of_line; /* :::::::::::::::::::: */
3088 ffelex_finish_statement_ ();
3089 goto beginning_of_line; /* :::::::::::::::::::: */
3095 switch (ffelex_raw_mode_)
3098 c = ffelex_backslash_ (c, column);
3102 if (!ffelex_backslash_reconsider_)
3103 ffelex_append_to_token_ (c);
3104 ffelex_raw_mode_ = -1;
3108 if (c == ffelex_raw_char_)
3110 ffelex_raw_mode_ = -1;
3111 ffelex_append_to_token_ (c);
3115 ffelex_raw_mode_ = 0;
3116 ffelex_backslash_reconsider_ = TRUE;
3121 if (c == ffelex_raw_char_)
3122 ffelex_raw_mode_ = -2;
3125 c = ffelex_backslash_ (c, column);
3128 ffelex_raw_mode_ = -3;
3132 ffelex_append_to_token_ (c);
3137 c = ffelex_backslash_ (c, column);
3141 if (!ffelex_backslash_reconsider_)
3143 ffelex_append_to_token_ (c);
3149 if (ffelex_backslash_reconsider_)
3150 ffelex_backslash_reconsider_ = FALSE;
3152 c = ffelex_card_image_[++column];
3154 if (ffelex_raw_mode_ == 0)
3156 ffelex_send_token_ ();
3157 assert (ffelex_raw_mode_ == 0);
3159 c = ffelex_card_image_[++column];
3160 if ((c == '\0') || (c == '!'))
3162 ffelex_finish_statement_ ();
3163 goto beginning_of_line; /* :::::::::::::::::::: */
3165 if ((c == '&') && ffelex_is_free_nonc_ctx_contin_ (column + 1))
3167 continuation_line = TRUE;
3168 goto beginning_of_line; /* :::::::::::::::::::: */
3170 goto parse_nonraw_character_noncontin; /* :::::::::::::::::::: */
3172 goto parse_raw_character; /* :::::::::::::::::::: */
3175 parse_nonraw_character: /* :::::::::::::::::::: */
3177 if ((c == '&') && ffelex_is_free_nonc_ctx_contin_ (column + 1))
3179 continuation_line = TRUE;
3180 goto beginning_of_line; /* :::::::::::::::::::: */
3183 parse_nonraw_character_noncontin: /* :::::::::::::::::::: */
3185 switch (ffelex_token_->type)
3187 case FFELEX_typeNONE:
3190 finish-statement/continue-statement
3193 c = ffelex_card_image_[++column];
3194 if ((c == '\0') || (c == '!'))
3196 ffelex_finish_statement_ ();
3197 goto beginning_of_line; /* :::::::::::::::::::: */
3199 if ((c == '&') && ffelex_is_free_nonc_ctx_contin_ (column + 1))
3201 continuation_line = TRUE;
3202 goto beginning_of_line; /* :::::::::::::::::::: */
3209 ffelex_token_->type = FFELEX_typeQUOTE;
3210 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3211 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3212 ffelex_send_token_ ();
3216 ffelex_token_->type = FFELEX_typeDOLLAR;
3217 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3218 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3219 ffelex_send_token_ ();
3223 ffelex_token_->type = FFELEX_typePERCENT;
3224 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3225 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3226 ffelex_send_token_ ();
3230 ffelex_token_->type = FFELEX_typeAMPERSAND;
3231 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3232 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3233 ffelex_send_token_ ();
3237 ffelex_token_->type = FFELEX_typeAPOSTROPHE;
3238 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3239 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3240 ffelex_send_token_ ();
3244 ffelex_token_->type = FFELEX_typeOPEN_PAREN;
3245 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3246 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3250 ffelex_token_->type = FFELEX_typeCLOSE_PAREN;
3251 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3252 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3253 ffelex_send_token_ ();
3257 ffelex_token_->type = FFELEX_typeASTERISK;
3258 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3259 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3263 ffelex_token_->type = FFELEX_typePLUS;
3264 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3265 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3266 ffelex_send_token_ ();
3270 ffelex_token_->type = FFELEX_typeCOMMA;
3271 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3272 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3273 ffelex_send_token_ ();
3277 ffelex_token_->type = FFELEX_typeMINUS;
3278 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3279 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3280 ffelex_send_token_ ();
3284 ffelex_token_->type = FFELEX_typePERIOD;
3285 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3286 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3287 ffelex_send_token_ ();
3291 ffelex_token_->type = FFELEX_typeSLASH;
3292 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3293 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3307 = ffelex_hexnum_ ? FFELEX_typeNAME : FFELEX_typeNUMBER;
3308 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3309 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3310 ffelex_append_to_token_ (c);
3314 ffelex_token_->type = FFELEX_typeCOLON;
3315 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3316 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3320 ffelex_token_->type = FFELEX_typeSEMICOLON;
3321 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3322 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3323 ffelex_permit_include_ = TRUE;
3324 ffelex_send_token_ ();
3325 ffelex_permit_include_ = FALSE;
3329 ffelex_token_->type = FFELEX_typeOPEN_ANGLE;
3330 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3331 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3335 ffelex_token_->type = FFELEX_typeEQUALS;
3336 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3337 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3341 ffelex_token_->type = FFELEX_typeCLOSE_ANGLE;
3342 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3343 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3347 ffelex_token_->type = FFELEX_typeQUESTION;
3348 ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_);
3349 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3350 ffelex_send_token_ ();
3354 if (1 || ffe_is_90 ())
3356 ffelex_token_->type = FFELEX_typeUNDERSCORE;
3357 ffelex_token_->where_line
3358 = ffewhere_line_use (ffelex_current_wl_);
3359 ffelex_token_->where_col
3360 = ffewhere_column_new (column + 1);
3361 ffelex_send_token_ ();
3417 c = ffesrc_char_source (c);
3419 if (ffesrc_char_match_init (c, 'H', 'h')
3420 && ffelex_expecting_hollerith_ != 0)
3422 ffelex_raw_mode_ = ffelex_expecting_hollerith_;
3423 ffelex_token_->type = FFELEX_typeHOLLERITH;
3424 ffelex_token_->where_line = ffelex_raw_where_line_;
3425 ffelex_token_->where_col = ffelex_raw_where_col_;
3426 ffelex_raw_where_line_ = ffewhere_line_unknown ();
3427 ffelex_raw_where_col_ = ffewhere_column_unknown ();
3428 c = ffelex_card_image_[++column];
3429 goto parse_raw_character; /* :::::::::::::::::::: */
3432 if (ffelex_names_pure_)
3434 ffelex_token_->where_line
3435 = ffewhere_line_use (ffelex_token_->currentnames_line
3436 = ffewhere_line_use (ffelex_current_wl_));
3437 ffelex_token_->where_col
3438 = ffewhere_column_use (ffelex_token_->currentnames_col
3439 = ffewhere_column_new (column + 1));
3440 ffelex_token_->type = FFELEX_typeNAMES;
3444 ffelex_token_->where_line
3445 = ffewhere_line_use (ffelex_current_wl_);
3446 ffelex_token_->where_col = ffewhere_column_new (column + 1);
3447 ffelex_token_->type = FFELEX_typeNAME;
3449 ffelex_append_to_token_ (c);
3453 ffelex_bad_1_ (FFEBAD_UNRECOGNIZED_CHARACTER,
3454 ffelex_linecount_current_, column + 1);
3455 ffelex_finish_statement_ ();
3456 goto beginning_of_line; /* :::::::::::::::::::: */
3460 case FFELEX_typeNAME:
3515 c = ffesrc_char_source (c);
3530 && !ffe_is_dollar_ok ())
3532 ffelex_send_token_ ();
3533 goto parse_next_character; /* :::::::::::::::::::: */
3535 ffelex_append_to_token_ (c);
3539 ffelex_send_token_ ();
3540 goto parse_next_character; /* :::::::::::::::::::: */
3544 case FFELEX_typeNAMES:
3599 c = ffesrc_char_source (c);
3614 && !ffe_is_dollar_ok ())
3616 ffelex_send_token_ ();
3617 goto parse_next_character; /* :::::::::::::::::::: */
3619 if (ffelex_token_->length < FFEWHERE_indexMAX)
3621 ffewhere_track (&ffelex_token_->currentnames_line,
3622 &ffelex_token_->currentnames_col,
3623 ffelex_token_->wheretrack,
3624 ffelex_token_->length,
3625 ffelex_linecount_current_,
3628 ffelex_append_to_token_ (c);
3632 ffelex_send_token_ ();
3633 goto parse_next_character; /* :::::::::::::::::::: */
3637 case FFELEX_typeNUMBER:
3650 ffelex_append_to_token_ (c);
3654 ffelex_send_token_ ();
3655 goto parse_next_character; /* :::::::::::::::::::: */
3659 case FFELEX_typeASTERISK:
3663 ffelex_token_->type = FFELEX_typePOWER;
3664 ffelex_send_token_ ();
3667 default: /* * not followed by another *. */
3668 ffelex_send_token_ ();
3669 goto parse_next_character; /* :::::::::::::::::::: */
3673 case FFELEX_typeCOLON:
3677 ffelex_token_->type = FFELEX_typeCOLONCOLON;
3678 ffelex_send_token_ ();
3681 default: /* : not followed by another :. */
3682 ffelex_send_token_ ();
3683 goto parse_next_character; /* :::::::::::::::::::: */
3687 case FFELEX_typeSLASH:
3691 ffelex_token_->type = FFELEX_typeCONCAT;
3692 ffelex_send_token_ ();
3696 ffelex_token_->type = FFELEX_typeCLOSE_ARRAY;
3697 ffelex_send_token_ ();
3701 ffelex_token_->type = FFELEX_typeREL_NE;
3702 ffelex_send_token_ ();
3706 ffelex_send_token_ ();
3707 goto parse_next_character; /* :::::::::::::::::::: */
3711 case FFELEX_typeOPEN_PAREN:
3715 ffelex_token_->type = FFELEX_typeOPEN_ARRAY;
3716 ffelex_send_token_ ();
3720 ffelex_send_token_ ();
3721 goto parse_next_character; /* :::::::::::::::::::: */
3725 case FFELEX_typeOPEN_ANGLE:
3729 ffelex_token_->type = FFELEX_typeREL_LE;
3730 ffelex_send_token_ ();
3734 ffelex_send_token_ ();
3735 goto parse_next_character; /* :::::::::::::::::::: */
3739 case FFELEX_typeEQUALS:
3743 ffelex_token_->type = FFELEX_typeREL_EQ;
3744 ffelex_send_token_ ();
3748 ffelex_token_->type = FFELEX_typePOINTS;
3749 ffelex_send_token_ ();
3753 ffelex_send_token_ ();
3754 goto parse_next_character; /* :::::::::::::::::::: */
3758 case FFELEX_typeCLOSE_ANGLE:
3762 ffelex_token_->type = FFELEX_typeREL_GE;
3763 ffelex_send_token_ ();
3767 ffelex_send_token_ ();
3768 goto parse_next_character; /* :::::::::::::::::::: */
3773 assert ("Serious error!" == NULL);
3778 c = ffelex_card_image_[++column];
3780 parse_next_character: /* :::::::::::::::::::: */
3782 if (ffelex_raw_mode_ != 0)
3783 goto parse_raw_character; /* :::::::::::::::::::: */
3785 if ((c == '\0') || (c == '!'))
3787 ffelex_finish_statement_ ();
3788 goto beginning_of_line; /* :::::::::::::::::::: */
3790 goto parse_nonraw_character; /* :::::::::::::::::::: */
3793 /* See the code in com.c that calls this to understand why. */
3796 ffelex_hash_kludge (FILE *finput)
3798 /* If you change this constant string, you have to change whatever
3799 code might thus be affected by it in terms of having to use
3800 ffelex_getc_() instead of getc() in the lexers and _hash_. */
3801 static const char match[] = "# 1 \"";
3802 static int kludge[ARRAY_SIZE (match) + 1];
3807 /* Read chars as long as they match the target string.
3808 Copy them into an array that will serve as a record
3809 of what we read (essentially a multi-char ungetc(),
3810 for code that uses ffelex_getc_ instead of getc() elsewhere
3812 for (p = &match[0], q = &kludge[0], c = getc (finput);
3813 (c == *p) && (*p != '\0') && (c != EOF);
3814 ++p, ++q, c = getc (finput))
3817 *q = c; /* Might be EOF, which requires int. */
3820 ffelex_kludge_chars_ = &kludge[0];
3824 ffelex_kludge_flag_ = TRUE;
3825 ++ffelex_kludge_chars_;
3826 ffelex_hash_ (finput); /* Handle it NOW rather than later. */
3827 ffelex_kludge_flag_ = FALSE;
3832 ffelex_init_1 (void)
3836 ffelex_final_nontab_column_ = ffe_fixed_line_length ();
3837 ffelex_card_size_ = FFELEX_columnINITIAL_SIZE_;
3838 ffelex_card_image_ = malloc_new_ksr (malloc_pool_image (),
3839 "FFELEX card image",
3840 FFELEX_columnINITIAL_SIZE_ + 9);
3841 ffelex_card_image_[0] = '\0';
3843 for (i = 0; i < 256; ++i)
3844 ffelex_first_char_[i] = FFELEX_typeERROR;
3846 ffelex_first_char_['\t'] = FFELEX_typeRAW;
3847 ffelex_first_char_['\n'] = FFELEX_typeCOMMENT;
3848 ffelex_first_char_['\v'] = FFELEX_typeCOMMENT;
3849 ffelex_first_char_['\f'] = FFELEX_typeCOMMENT;
3850 ffelex_first_char_['\r'] = FFELEX_typeRAW;
3851 ffelex_first_char_[' '] = FFELEX_typeRAW;
3852 ffelex_first_char_['!'] = FFELEX_typeCOMMENT;
3853 ffelex_first_char_['*'] = FFELEX_typeCOMMENT;
3854 ffelex_first_char_['/'] = FFELEX_typeSLASH;
3855 ffelex_first_char_['&'] = FFELEX_typeRAW;
3856 ffelex_first_char_['#'] = FFELEX_typeHASH;
3858 for (i = '0'; i <= '9'; ++i)
3859 ffelex_first_char_[i] = FFELEX_typeRAW;
3861 if ((ffe_case_match () == FFE_caseNONE)
3862 || ((ffe_case_match () == FFE_caseUPPER)
3863 && (ffe_case_source () != FFE_caseLOWER)) /* Idiot! :-) */
3864 || ((ffe_case_match () == FFE_caseLOWER)
3865 && (ffe_case_source () == FFE_caseLOWER)))
3867 ffelex_first_char_['C'] = FFELEX_typeCOMMENT;
3868 ffelex_first_char_['D'] = FFELEX_typeCOMMENT;
3870 if ((ffe_case_match () == FFE_caseNONE)
3871 || ((ffe_case_match () == FFE_caseLOWER)
3872 && (ffe_case_source () != FFE_caseUPPER)) /* Idiot! :-) */
3873 || ((ffe_case_match () == FFE_caseUPPER)
3874 && (ffe_case_source () == FFE_caseUPPER)))
3876 ffelex_first_char_['c'] = FFELEX_typeCOMMENT;
3877 ffelex_first_char_['d'] = FFELEX_typeCOMMENT;
3880 ffelex_linecount_current_ = 0;
3881 ffelex_linecount_next_ = 1;
3882 ffelex_raw_mode_ = 0;
3883 ffelex_set_include_ = FALSE;
3884 ffelex_permit_include_ = FALSE;
3885 ffelex_names_ = TRUE; /* First token in program is a names. */
3886 ffelex_names_pure_ = FALSE; /* Free-form lexer does NAMES only for
3888 ffelex_hexnum_ = FALSE;
3889 ffelex_expecting_hollerith_ = 0;
3890 ffelex_raw_where_line_ = ffewhere_line_unknown ();
3891 ffelex_raw_where_col_ = ffewhere_column_unknown ();
3893 ffelex_token_ = ffelex_token_new_ ();
3894 ffelex_token_->type = FFELEX_typeNONE;
3895 ffelex_token_->uses = 1;
3896 ffelex_token_->where_line = ffewhere_line_unknown ();
3897 ffelex_token_->where_col = ffewhere_column_unknown ();
3898 ffelex_token_->text = NULL;
3900 ffelex_handler_ = NULL;
3903 /* ffelex_is_names_expected -- Is the current parser expecting NAMES vs. NAME?
3905 if (ffelex_is_names_expected())
3906 // Deliver NAMES token
3908 // Deliver NAME token
3910 Must be called while lexer is active, obviously. */
3913 ffelex_is_names_expected (void)
3915 return ffelex_names_;
3918 /* Current card image, which has the master linecount number
3919 ffelex_linecount_current_. */
3924 return ffelex_card_image_;
3927 /* ffelex_line_length -- Return length of current lexer line
3929 printf("Length is %lu\n",ffelex_line_length());
3931 Must be called while lexer is active, obviously. */
3933 ffewhereColumnNumber
3934 ffelex_line_length (void)
3936 return ffelex_card_length_;
3939 /* Master line count of current card image, or 0 if no card image
3943 ffelex_line_number (void)
3945 return ffelex_linecount_current_;
3948 /* ffelex_set_expecting_hollerith -- Set hollerith expectation status
3950 ffelex_set_expecting_hollerith(0);
3952 Lex initially assumes no hollerith constant is about to show up. If
3953 syntactic analysis expects one, it should call this function with the
3954 number of characters expected in the constant immediately after recognizing
3955 the decimal number preceding the "H" and the constant itself. Then, if
3956 the next character is indeed H, the lexer will interpret it as beginning
3957 a hollerith constant and ship the token formed by reading the specified
3958 number of characters (interpreting blanks and otherwise-comments too)
3959 from the input file. It is up to syntactic analysis to call this routine
3960 again with 0 to turn hollerith detection off immediately upon receiving
3961 the token that might or might not be HOLLERITH.
3963 Also call this after seeing an APOSTROPHE or QUOTE token that begins a
3964 character constant. Pass the expected termination character (apostrophe
3967 Pass for length either the length of the hollerith (must be > 0), -1
3968 meaning expecting a character constant, or 0 to cancel expectation of
3969 a hollerith only after calling it with a length of > 0 and receiving the
3970 next token (which may or may not have been a HOLLERITH token).
3972 Pass for which either an apostrophe or quote when passing length of -1.
3973 Else which is a don't-care.
3975 Pass for line and column the line/column info for the token beginning the
3976 character or hollerith constant, for use in error messages, when passing
3977 a length of -1 -- this function will invoke ffewhere_line/column_use to
3978 make its own copies. Else line and column are don't-cares (when length
3979 is 0) and the outstanding copies of the previous line/column info, if
3980 still around, are killed.
3983 When called with length of 0, also zero ffelex_raw_mode_. This is
3984 so ffest_save_ can undo the effects of replaying tokens like
3985 APOSTROPHE and QUOTE.
3987 New line, column arguments allow error messages to point to the true
3988 beginning of a character/hollerith constant, rather than the beginning
3989 of the content part, which makes them more consistent and helpful.
3991 New "which" argument allows caller to specify termination character,
3992 which should be apostrophe or double-quote, to support Fortran 90. */
3995 ffelex_set_expecting_hollerith (long length, char which,
3996 ffewhereLine line, ffewhereColumn column)
3999 /* First kill the pending line/col info, if any (should only be pending
4000 when this call has length==0, the previous call had length>0, and a
4001 non-HOLLERITH token was sent in between the calls, but play it safe). */
4003 ffewhere_line_kill (ffelex_raw_where_line_);
4004 ffewhere_column_kill (ffelex_raw_where_col_);
4006 /* Now handle the length function. */
4010 ffelex_expecting_hollerith_ = 0;
4011 ffelex_raw_mode_ = 0;
4012 ffelex_raw_where_line_ = ffewhere_line_unknown ();
4013 ffelex_raw_where_col_ = ffewhere_column_unknown ();
4014 return; /* Don't set new line/column info from args. */
4017 ffelex_raw_mode_ = -1;
4018 ffelex_raw_char_ = which;
4021 default: /* length > 0 */
4022 ffelex_expecting_hollerith_ = length;
4026 /* Now set new line/column information from passed args. */
4028 ffelex_raw_where_line_ = ffewhere_line_use (line);
4029 ffelex_raw_where_col_ = ffewhere_column_use (column);
4032 /* ffelex_set_handler -- Set handler for tokens before calling _fixed or _free
4034 ffelex_set_handler((ffelexHandler) my_first_handler);
4036 Must be called before calling ffelex_file_fixed or ffelex_file_free or
4037 after they return, but not while they are active. */
4040 ffelex_set_handler (ffelexHandler first)
4042 ffelex_handler_ = first;
4045 /* ffelex_set_hexnum -- Set hexnum flag
4047 ffelex_set_hexnum(TRUE);
4049 Lex normally interprets a token starting with [0-9] as a NUMBER token,
4050 so if it sees a [A-Za-z] in it, it stops parsing the NUMBER and leaves
4051 the character as the first of the next token. But when parsing a
4052 hexadecimal number, by calling this function with TRUE before starting
4053 the parse of the token itself, lex will interpret [0-9] as the start
4057 ffelex_set_hexnum (bool f)
4062 /* ffelex_set_include -- Set INCLUDE file to be processed next
4064 ffewhereFile wf; // The ffewhereFile object for the file.
4065 bool free_form; // TRUE means read free-form file, FALSE fixed-form.
4066 FILE *fi; // The file to INCLUDE.
4067 ffelex_set_include(wf,free_form,fi);
4069 Must be called only after receiving the EOS token following a valid
4070 INCLUDE statement specifying a file that has already been successfully
4074 ffelex_set_include (ffewhereFile wf, bool free_form, FILE *fi)
4076 assert (ffelex_permit_include_);
4077 assert (!ffelex_set_include_);
4078 ffelex_set_include_ = TRUE;
4079 ffelex_include_free_form_ = free_form;
4080 ffelex_include_file_ = fi;
4081 ffelex_include_wherefile_ = wf;
4084 /* ffelex_set_names -- Set names/name flag, names = TRUE
4086 ffelex_set_names(FALSE);
4088 Lex initially assumes multiple names should be formed. If this function is
4089 called with FALSE, then single names are formed instead. The differences
4090 are a difference in the token type (FFELEX_typeNAMES vs. FFELEX_typeNAME)
4091 and in whether full source-location tracking is performed (it is for
4092 multiple names, not for single names), which is more expensive in terms of
4096 ffelex_set_names (bool f)
4100 ffelex_names_pure_ = FALSE;
4103 /* ffelex_set_names_pure -- Set names/name (pure) flag, names = TRUE
4105 ffelex_set_names_pure(FALSE);
4107 Like ffelex_set_names, except affects both lexers. Normally, the
4108 free-form lexer need not generate NAMES tokens because adjacent NAME
4109 tokens must be separated by spaces which causes the lexer to generate
4110 separate tokens for analysis (whereas in fixed-form the spaces are
4111 ignored resulting in one long token). But in FORMAT statements, for
4112 some reason, the Fortran 90 standard specifies that spaces can occur
4113 anywhere within a format-item-list with no effect on the format spec
4114 (except of course within character string edit descriptors), which means
4115 that "1PE14.2" and "1 P E 1 4 . 2" are equivalent. For the FORMAT
4116 statement handling, the existence of spaces makes it hard to deal with,
4117 because each token is seen distinctly (i.e. seven tokens in the latter
4118 example). But when no spaces are provided, as in the former example,
4119 then only four tokens are generated, NUMBER("1"), NAME("PE14"), PERIOD,
4120 NUMBER ("2"). By generating a NAMES instead of NAME, three things happen:
4121 One, ffest_kw_format_ does a substring rather than full-string match,
4122 and thus matches "PE14" to "PE"; two, ffelex_token_xyz_from_names functions
4123 may be used to pull NAME/NAMES and NUMBER tokens out of the NAMES token;
4124 and three, error reporting can point to the actual character rather than
4125 at or prior to it. The first two things could be resolved by providing
4126 alternate functions fairly easy, thus allowing FORMAT handling to expect
4127 both lexers to generate NAME tokens instead of NAMES (with otherwise minor
4128 changes to FORMAT parsing), but the third, error reporting, would suffer,
4129 and when one makes mistakes in a FORMAT, believe me, one wants a pointer
4130 to exactly where the compilers thinks the problem is, to even begin to get
4131 a handle on it. So there. */
4134 ffelex_set_names_pure (bool f)
4136 ffelex_names_pure_ = f;
4140 /* ffelex_splice_tokens -- Splice off and send tokens from a NAMES
4142 return (ffelexHandler) ffelex_splice_tokens(first_handler,master_token,
4145 Returns first_handler if start_char_index chars into master_token (which
4146 must be a NAMES token) is '\0'. Else, creates a subtoken from that
4147 char, either NUMBER (if it is a digit), a NAME (if a valid firstnamechar),
4148 an UNDERSCORE (if an underscore), or DOLLAR (if a dollar sign)
4149 and sends it to first_handler. If anything other than NAME is sent, the
4150 character at the end of it in the master token is examined to see if it
4151 begins a NAME, NUMBER, UNDERSCORE, or DOLLAR, and, if so,
4152 the handler returned by first_handler is invoked with that token, and
4153 this process is repeated until the end of the master token or a NAME
4154 token is reached. */
4157 ffelex_splice_tokens (ffelexHandler first, ffelexToken master,
4158 ffeTokenLength start)
4164 p = ffelex_token_text (master) + (i = start);
4170 t = ffelex_token_number_from_names (master, i);
4171 p += ffelex_token_length (t);
4172 i += ffelex_token_length (t);
4174 else if (ffesrc_is_name_init (*p))
4176 t = ffelex_token_name_from_names (master, i, 0);
4177 p += ffelex_token_length (t);
4178 i += ffelex_token_length (t);
4182 t = ffelex_token_dollar_from_names (master, i);
4188 t = ffelex_token_uscore_from_names (master, i);
4194 assert ("not a valid NAMES character" == NULL);
4197 assert (first != NULL);
4198 first = (ffelexHandler) (*first) (t);
4199 ffelex_token_kill (t);
4205 /* ffelex_swallow_tokens -- Eat all tokens delivered to me
4207 return ffelex_swallow_tokens;
4209 Return this handler when you don't want to look at any more tokens in the
4210 statement because you've encountered an unrecoverable error in the
4214 ffelex_swallow_tokens (ffelexToken t, ffelexHandler handler)
4216 assert (handler != NULL);
4218 if ((t != NULL) && ((ffelex_token_type (t) == FFELEX_typeEOS)
4219 || (ffelex_token_type (t) == FFELEX_typeSEMICOLON)))
4220 return (ffelexHandler) (*handler) (t);
4222 ffelex_eos_handler_ = handler;
4223 return (ffelexHandler) ffelex_swallow_tokens_;
4226 /* ffelex_token_dollar_from_names -- Return a dollar from within a names token
4229 t = ffelex_token_dollar_from_names(t,6);
4231 It's as if you made a new token of dollar type having the dollar
4232 at, in the example above, the sixth character of the NAMES token. */
4235 ffelex_token_dollar_from_names (ffelexToken t, ffeTokenLength start)
4240 assert (ffelex_token_type (t) == FFELEX_typeNAMES);
4241 assert (start < t->length);
4242 assert (t->text[start] == '$');
4244 /* Now make the token. */
4246 nt = ffelex_token_new_ ();
4247 nt->type = FFELEX_typeDOLLAR;
4250 ffewhere_set_from_track (&nt->where_line, &nt->where_col, t->where_line,
4251 t->where_col, t->wheretrack, start);
4256 /* ffelex_token_kill -- Decrement use count for token, kill if no uses left
4259 ffelex_token_kill(t);
4261 Complements a call to ffelex_token_use or ffelex_token_new_.... */
4264 ffelex_token_kill (ffelexToken t)
4268 assert (t->uses > 0);
4273 --ffelex_total_tokens_;
4275 if (t->type == FFELEX_typeNAMES)
4276 ffewhere_track_kill (t->where_line, t->where_col,
4277 t->wheretrack, t->length);
4278 ffewhere_line_kill (t->where_line);
4279 ffewhere_column_kill (t->where_col);
4280 if (t->text != NULL)
4281 malloc_kill_ksr (malloc_pool_image (), t->text, t->size + 1);
4282 malloc_kill_ks (malloc_pool_image (), t, sizeof (*t));
4285 /* Make a new NAME token that is a substring of a NAMES token. */
4288 ffelex_token_name_from_names (ffelexToken t, ffeTokenLength start,
4294 assert (ffelex_token_type (t) == FFELEX_typeNAMES);
4295 assert (start < t->length);
4297 len = t->length - start;
4301 assert ((start + len) <= t->length);
4303 assert (ffelex_is_firstnamechar ((unsigned char)(t->text[start])));
4305 nt = ffelex_token_new_ ();
4306 nt->type = FFELEX_typeNAME;
4307 nt->size = len; /* Assume nobody's gonna fiddle with token
4311 ffewhere_set_from_track (&nt->where_line, &nt->where_col, t->where_line,
4312 t->where_col, t->wheretrack, start);
4313 nt->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4315 strncpy (nt->text, t->text + start, len);
4316 nt->text[len] = '\0';
4320 /* Make a new NAMES token that is a substring of another NAMES token. */
4323 ffelex_token_names_from_names (ffelexToken t, ffeTokenLength start,
4329 assert (ffelex_token_type (t) == FFELEX_typeNAMES);
4330 assert (start < t->length);
4332 len = t->length - start;
4336 assert ((start + len) <= t->length);
4338 assert (ffelex_is_firstnamechar ((unsigned char)(t->text[start])));
4340 nt = ffelex_token_new_ ();
4341 nt->type = FFELEX_typeNAMES;
4342 nt->size = len; /* Assume nobody's gonna fiddle with token
4346 ffewhere_set_from_track (&nt->where_line, &nt->where_col, t->where_line,
4347 t->where_col, t->wheretrack, start);
4348 ffewhere_track_copy (nt->wheretrack, t->wheretrack, start, len);
4349 nt->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4351 strncpy (nt->text, t->text + start, len);
4352 nt->text[len] = '\0';
4356 /* Make a new CHARACTER token. */
4359 ffelex_token_new_character (const char *s, ffewhereLine l, ffewhereColumn c)
4363 t = ffelex_token_new_ ();
4364 t->type = FFELEX_typeCHARACTER;
4365 t->length = t->size = strlen (s); /* Assume it won't get bigger. */
4367 t->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4369 strcpy (t->text, s);
4370 t->where_line = ffewhere_line_use (l);
4371 t->where_col = ffewhere_column_new (c);
4375 /* Make a new EOF token right after end of file. */
4378 ffelex_token_new_eof (void)
4382 t = ffelex_token_new_ ();
4383 t->type = FFELEX_typeEOF;
4386 t->where_line = ffewhere_line_new (ffelex_linecount_current_);
4387 t->where_col = ffewhere_column_new (1);
4391 /* Make a new NAME token. */
4394 ffelex_token_new_name (const char *s, ffewhereLine l, ffewhereColumn c)
4398 assert (ffelex_is_firstnamechar ((unsigned char)*s));
4400 t = ffelex_token_new_ ();
4401 t->type = FFELEX_typeNAME;
4402 t->length = t->size = strlen (s); /* Assume it won't get bigger. */
4404 t->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4406 strcpy (t->text, s);
4407 t->where_line = ffewhere_line_use (l);
4408 t->where_col = ffewhere_column_new (c);
4412 /* Make a new NAMES token. */
4415 ffelex_token_new_names (const char *s, ffewhereLine l, ffewhereColumn c)
4419 assert (ffelex_is_firstnamechar ((unsigned char)*s));
4421 t = ffelex_token_new_ ();
4422 t->type = FFELEX_typeNAMES;
4423 t->length = t->size = strlen (s); /* Assume it won't get bigger. */
4425 t->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4427 strcpy (t->text, s);
4428 t->where_line = ffewhere_line_use (l);
4429 t->where_col = ffewhere_column_new (c);
4430 ffewhere_track_clear (t->wheretrack, t->length); /* Assume contiguous
4435 /* Make a new NUMBER token.
4437 The first character of the string must be a digit, and only the digits
4438 are copied into the new number. So this may be used to easily extract
4439 a NUMBER token from within any text string. Then the length of the
4440 resulting token may be used to calculate where the digits stopped
4441 in the original string. */
4444 ffelex_token_new_number (const char *s, ffewhereLine l, ffewhereColumn c)
4449 /* How long is the string of decimal digits at s? */
4451 len = strspn (s, "0123456789");
4453 /* Make sure there is at least one digit. */
4457 /* Now make the token. */
4459 t = ffelex_token_new_ ();
4460 t->type = FFELEX_typeNUMBER;
4461 t->length = t->size = len; /* Assume it won't get bigger. */
4463 t->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4465 strncpy (t->text, s, len);
4466 t->text[len] = '\0';
4467 t->where_line = ffewhere_line_use (l);
4468 t->where_col = ffewhere_column_new (c);
4472 /* Make a new token of any type that doesn't contain text. A private
4473 function that is used by public macros in the interface file. */
4476 ffelex_token_new_simple_ (ffelexType type, ffewhereLine l, ffewhereColumn c)
4480 t = ffelex_token_new_ ();
4484 t->where_line = ffewhere_line_use (l);
4485 t->where_col = ffewhere_column_new (c);
4489 /* Make a new NUMBER token from an existing NAMES token.
4491 Like ffelex_token_new_number, this function calculates the length
4492 of the digit string itself. */
4495 ffelex_token_number_from_names (ffelexToken t, ffeTokenLength start)
4501 assert (ffelex_token_type (t) == FFELEX_typeNAMES);
4502 assert (start < t->length);
4504 /* How long is the string of decimal digits at s? */
4506 len = strspn (t->text + start, "0123456789");
4508 /* Make sure there is at least one digit. */
4512 /* Now make the token. */
4514 nt = ffelex_token_new_ ();
4515 nt->type = FFELEX_typeNUMBER;
4516 nt->size = len; /* Assume nobody's gonna fiddle with token
4520 ffewhere_set_from_track (&nt->where_line, &nt->where_col, t->where_line,
4521 t->where_col, t->wheretrack, start);
4522 nt->text = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4524 strncpy (nt->text, t->text + start, len);
4525 nt->text[len] = '\0';
4529 /* Make a new UNDERSCORE token from a NAMES token. */
4532 ffelex_token_uscore_from_names (ffelexToken t, ffeTokenLength start)
4537 assert (ffelex_token_type (t) == FFELEX_typeNAMES);
4538 assert (start < t->length);
4539 assert (t->text[start] == '_');
4541 /* Now make the token. */
4543 nt = ffelex_token_new_ ();
4544 nt->type = FFELEX_typeUNDERSCORE;
4546 ffewhere_set_from_track (&nt->where_line, &nt->where_col, t->where_line,
4547 t->where_col, t->wheretrack, start);
4552 /* ffelex_token_use -- Return another instance of a token
4555 t = ffelex_token_use(t);
4557 In a sense, the new token is a copy of the old, though it might be the
4558 same with just a new use count.
4560 We use the use count method (easy). */
4563 ffelex_token_use (ffelexToken t)
4566 assert ("_token_use: null token" == NULL);
4571 #include "gt-f-lex.h"