1 /* Implementation of Fortran lexer
2 Copyright (C) 1995-1997 Free Software Foundation, Inc.
3 Contributed by James Craig Burley (burley@gnu.ai.mit.edu).
5 This file is part of GNU Fortran.
7 GNU Fortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Fortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Fortran; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 #if FFECOM_targetCURRENT == FFECOM_targetGCC
37 #ifdef DWARF_DEBUGGING_INFO
38 void dwarfout_resume_previous_source_file (register unsigned);
39 void dwarfout_start_new_source_file (register char *);
40 void dwarfout_define (register unsigned, register char *);
41 void dwarfout_undef (register unsigned, register char *);
42 #endif DWARF_DEBUGGING_INFO
44 static void ffelex_append_to_token_ (char c
);
45 static int ffelex_backslash_ (int c
, ffewhereColumnNumber col
);
46 static void ffelex_bad_1_ (ffebad errnum
, ffewhereLineNumber ln0
,
47 ffewhereColumnNumber cn0
);
48 static void ffelex_bad_2_ (ffebad errnum
, ffewhereLineNumber ln0
,
49 ffewhereColumnNumber cn0
, ffewhereLineNumber ln1
,
50 ffewhereColumnNumber cn1
);
51 static void ffelex_bad_here_ (int num
, ffewhereLineNumber ln0
,
52 ffewhereColumnNumber cn0
);
53 static void ffelex_finish_statement_ (void);
54 #if FFECOM_targetCURRENT == FFECOM_targetGCC
55 static int ffelex_get_directive_line_ (char **text
, FILE *finput
);
56 static int ffelex_hash_ (FILE *f
);
58 static ffewhereColumnNumber
ffelex_image_char_ (int c
,
59 ffewhereColumnNumber col
);
60 static void ffelex_include_ (void);
61 static bool ffelex_is_free_char_ctx_contin_ (ffewhereColumnNumber col
);
62 static bool ffelex_is_free_nonc_ctx_contin_ (ffewhereColumnNumber col
);
63 static void ffelex_next_line_ (void);
64 static void ffelex_prepare_eos_ (void);
65 static void ffelex_send_token_ (void);
66 static ffelexHandler
ffelex_swallow_tokens_ (ffelexToken t
);
67 static ffelexToken
ffelex_token_new_ (void);
69 /* Pertaining to the geometry of the input file. */
71 /* Initial size for card image to be allocated. */
72 #define FFELEX_columnINITIAL_SIZE_ 255
74 /* The card image itself, which grows as source lines get longer. It
75 has room for ffelex_card_size_ + 8 characters, and the length of the
76 current image is ffelex_card_length_. (The + 8 characters are made
77 available for easy handling of tabs and such.) */
78 static char *ffelex_card_image_
;
79 static ffewhereColumnNumber ffelex_card_size_
;
80 static ffewhereColumnNumber ffelex_card_length_
;
82 /* Max width for free-form lines (ISO F90). */
83 #define FFELEX_FREE_MAX_COLUMNS_ 132
85 /* True if we saw a tab on the current line, as this (currently) means
86 the line is therefore treated as though final_nontab_column_ were
88 static bool ffelex_saw_tab_
;
90 /* TRUE if current line is known to be erroneous, so don't bother
91 expanding room for it just to display it. */
92 static bool ffelex_bad_line_
= FALSE
;
94 /* Last column for vanilla, i.e. non-tabbed, line. Usually 72 or 132. */
95 static ffewhereColumnNumber ffelex_final_nontab_column_
;
97 /* Array for quickly deciding what kind of line the current card has,
98 based on its first character. */
99 static ffelexType ffelex_first_char_
[256];
101 /* Pertaining to file management. */
103 /* The wf argument of the most recent active ffelex_file_(fixed,free)
105 static ffewhereFile ffelex_current_wf_
;
107 /* TRUE if an INCLUDE statement can be processed (ffelex_set_include
109 static bool ffelex_permit_include_
;
111 /* TRUE if an INCLUDE statement is pending (ffelex_set_include has been
113 static bool ffelex_set_include_
;
115 /* Information on the pending INCLUDE file. */
116 static FILE *ffelex_include_file_
;
117 static bool ffelex_include_free_form_
;
118 static ffewhereFile ffelex_include_wherefile_
;
120 /* Current master line count. */
121 static ffewhereLineNumber ffelex_linecount_current_
;
122 /* Next master line count. */
123 static ffewhereLineNumber ffelex_linecount_next_
;
125 /* ffewhere info on the latest (currently active) line read from the
126 active source file. */
127 static ffewhereLine ffelex_current_wl_
;
128 static ffewhereColumn ffelex_current_wc_
;
130 /* Pertaining to tokens in general. */
132 /* Initial capacity for text in a CHARACTER/HOLLERITH/NAME/NAMES/NUMBER
134 #define FFELEX_columnTOKEN_SIZE_ 63
135 #if FFELEX_columnTOKEN_SIZE_ < FFEWHERE_indexMAX
136 #error "token size too small!"
139 /* Current token being lexed. */
140 static ffelexToken ffelex_token_
;
142 /* Handler for current token. */
143 static ffelexHandler ffelex_handler_
;
145 /* TRUE if fixed-form lexer is to generate NAMES instead of NAME tokens. */
146 static bool ffelex_names_
;
148 /* TRUE if both lexers are to generate NAMES instead of NAME tokens. */
149 static bool ffelex_names_pure_
;
151 /* TRUE if 0-9 starts a NAME token instead of NUMBER, for parsing hex
153 static bool ffelex_hexnum_
;
155 /* For ffelex_swallow_tokens(). */
156 static ffelexHandler ffelex_eos_handler_
;
158 /* Number of tokens sent since last EOS or beginning of input file
159 (include INCLUDEd files). */
160 static unsigned long int ffelex_number_of_tokens_
;
162 /* Number of labels sent (as NUMBER tokens) since last reset of
163 ffelex_number_of_tokens_ to 0, should be 0 or 1 in most cases.
164 (Fixed-form source only.) */
165 static unsigned long int ffelex_label_tokens_
;
167 /* Metering for token management, to catch token-memory leaks. */
168 static long int ffelex_total_tokens_
= 0;
169 static long int ffelex_old_total_tokens_
= 1;
170 static long int ffelex_token_nextid_
= 0;
172 /* Pertaining to lexing CHARACTER and HOLLERITH tokens. */
174 /* >0 if a Hollerith constant of that length might be in mid-lex, used
175 when the next character seen is 'H' or 'h' to enter HOLLERITH lexing
176 mode (see ffelex_raw_mode_). */
177 static long int ffelex_expecting_hollerith_
;
179 /* -3: Backslash (escape) sequence being lexed in CHARACTER.
180 -2: Possible closing apostrophe/quote seen in CHARACTER.
181 -1: Lexing CHARACTER.
182 0: Not lexing CHARACTER or HOLLERITH.
183 >0: Lexing HOLLERITH, value is # chars remaining to expect. */
184 static long int ffelex_raw_mode_
;
186 /* When lexing CHARACTER, open quote/apostrophe (either ' or "). */
187 static char ffelex_raw_char_
;
189 /* TRUE when backslash processing had to use most recent character
190 to finish its state engine, but that character is not part of
191 the backslash sequence, so must be reconsidered as a "normal"
192 character in CHARACTER/HOLLERITH lexing. */
193 static bool ffelex_backslash_reconsider_
= FALSE
;
195 /* Characters preread before lexing happened (might include EOF). */
196 static int *ffelex_kludge_chars_
= NULL
;
198 /* Doing the kludge processing, so not initialized yet. */
199 static bool ffelex_kludge_flag_
= FALSE
;
201 /* The beginning of a (possible) CHARACTER/HOLLERITH token. */
202 static ffewhereLine ffelex_raw_where_line_
;
203 static ffewhereColumn ffelex_raw_where_col_
;
206 /* Call this to append another character to the current token. If it isn't
207 currently big enough for it, it will be enlarged. The current token
208 must be a CHARACTER, HOLLERITH, NAME, NAMES, or NUMBER. */
211 ffelex_append_to_token_ (char c
)
213 if (ffelex_token_
->text
== NULL
)
216 = malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
217 FFELEX_columnTOKEN_SIZE_
+ 1);
218 ffelex_token_
->size
= FFELEX_columnTOKEN_SIZE_
;
219 ffelex_token_
->length
= 0;
221 else if (ffelex_token_
->length
>= ffelex_token_
->size
)
224 = malloc_resize_ksr (malloc_pool_image (),
226 (ffelex_token_
->size
<< 1) + 1,
227 ffelex_token_
->size
+ 1);
228 ffelex_token_
->size
<<= 1;
229 assert (ffelex_token_
->length
< ffelex_token_
->size
);
232 Sorry
, MAP_CHARACTER is
not going to work as expected in GNU Fortran
,
233 please contact fortran@gnu
.org
if you wish to fund work to
234 port g77 to non
-ASCII machines
.
236 ffelex_token_
->text
[ffelex_token_
->length
++] = c
;
239 /* Do backslash (escape) processing for a CHARACTER/HOLLERITH token
243 ffelex_backslash_ (int c
, ffewhereColumnNumber col
)
245 static int state
= 0;
246 static unsigned int count
;
248 static unsigned int firstdig
= 0;
250 static ffewhereLineNumber line
;
251 static ffewhereColumnNumber column
;
253 /* See gcc/c-lex.c readescape() for a straightforward version
254 of this state engine for handling backslashes in character/
255 hollerith constants. */
258 #define warn_traditional 0
259 #define flag_traditional 0
265 && (ffelex_raw_mode_
!= 0)
266 && ffe_is_backslash ())
270 line
= ffelex_linecount_current_
;
276 state
= 0; /* Assume simple case. */
280 if (warn_traditional
)
282 ffebad_start_msg_lex ("The meaning of `\\x' (at %0) varies with -traditional",
283 FFEBAD_severityWARNING
);
284 ffelex_bad_here_ (0, line
, column
);
288 if (flag_traditional
)
297 case '0': case '1': case '2': case '3': case '4':
298 case '5': case '6': case '7':
304 case '\\': case '\'': case '"':
307 #if 0 /* Inappropriate for Fortran. */
309 ffelex_next_line_ ();
315 return TARGET_NEWLINE
;
330 if (warn_traditional
)
332 ffebad_start_msg_lex ("The meaning of `\\a' (at %0) varies with -traditional",
333 FFEBAD_severityWARNING
);
334 ffelex_bad_here_ (0, line
, column
);
338 if (flag_traditional
)
343 #if 0 /* Vertical tab is present in common usage compilers. */
344 if (flag_traditional
)
361 ffebad_start_msg_lex ("Non-ANSI-C-standard escape sequence `\\%A' at %0",
362 FFEBAD_severityPEDANTIC
);
363 ffelex_bad_here_ (0, line
, column
);
367 return (c
== 'E' || c
== 'e') ? 033 : c
;
373 if (c
>= 040 && c
< 0177)
379 ffebad_start_msg_lex ("Unknown escape sequence `\\%A' at %0",
380 FFEBAD_severityPEDANTIC
);
381 ffelex_bad_here_ (0, line
, column
);
387 ffebad_start_msg_lex ("Unterminated escape sequence `\\' at %0",
388 FFEBAD_severityPEDANTIC
);
389 ffelex_bad_here_ (0, line
, column
);
396 sprintf (&m
[0], "%x", c
);
397 ffebad_start_msg_lex ("Unknown escape sequence `\\' followed by char code 0x%A at %0",
398 FFEBAD_severityPEDANTIC
);
399 ffelex_bad_here_ (0, line
, column
);
407 if ((c
>= 'a' && c
<= 'f')
408 || (c
>= 'A' && c
<= 'F')
409 || (c
>= '0' && c
<= '9'))
412 if (c
>= 'a' && c
<= 'f')
413 code
+= c
- 'a' + 10;
414 if (c
>= 'A' && c
<= 'F')
415 code
+= c
- 'A' + 10;
416 if (c
>= '0' && c
<= '9')
418 if (code
!= 0 || count
!= 0)
432 ffebad_start_msg_lex ("\\x used at %0 with no following hex digits",
433 FFEBAD_severityFATAL
);
434 ffelex_bad_here_ (0, line
, column
);
438 /* Digits are all 0's. Ok. */
440 else if ((count
- 1) * 4 >= TYPE_PRECISION (integer_type_node
)
442 && ((1 << (TYPE_PRECISION (integer_type_node
) - (count
- 1) * 4))
445 ffebad_start_msg_lex ("Hex escape at %0 out of range",
446 FFEBAD_severityPEDANTIC
);
447 ffelex_bad_here_ (0, line
, column
);
453 if ((c
<= '7') && (c
>= '0') && (count
++ < 3))
455 code
= (code
* 8) + (c
- '0');
462 assert ("bad backslash state" == NULL
);
466 /* Come here when code has a built character, and c is the next
467 character that might (or might not) be the next one in the constant. */
469 /* Don't bother doing this check for each character going into
470 CHARACTER or HOLLERITH constants, just the escaped-value ones.
471 gcc apparently checks every single character, which seems
472 like it'd be kinda slow and not worth doing anyway. */
475 && TYPE_PRECISION (char_type_node
) < HOST_BITS_PER_INT
476 && code
>= (1 << TYPE_PRECISION (char_type_node
)))
478 ffebad_start_msg_lex ("Escape sequence at %0 out of range for character",
479 FFEBAD_severityFATAL
);
480 ffelex_bad_here_ (0, line
, column
);
486 /* Known end of constant, just append this character. */
487 ffelex_append_to_token_ (code
);
488 if (ffelex_raw_mode_
> 0)
493 /* Have two characters to handle. Do the first, then leave it to the
494 caller to detect anything special about the second. */
496 ffelex_append_to_token_ (code
);
497 if (ffelex_raw_mode_
> 0)
499 ffelex_backslash_reconsider_
= TRUE
;
503 /* ffelex_bad_1_ -- Issue diagnostic with one source point
505 ffelex_bad_1_(FFEBAD_SOME_ERROR,ffelex_linecount_current_,column + 1);
507 Creates ffewhere line and column objects for the source point, sends them
508 along with the error code to ffebad, then kills the line and column
509 objects before returning. */
512 ffelex_bad_1_ (ffebad errnum
, ffewhereLineNumber ln0
, ffewhereColumnNumber cn0
)
517 wl0
= ffewhere_line_new (ln0
);
518 wc0
= ffewhere_column_new (cn0
);
519 ffebad_start_lex (errnum
);
520 ffebad_here (0, wl0
, wc0
);
522 ffewhere_line_kill (wl0
);
523 ffewhere_column_kill (wc0
);
526 /* ffelex_bad_2_ -- Issue diagnostic with two source points
528 ffelex_bad_2_(FFEBAD_SOME_ERROR,ffelex_linecount_current_,column + 1,
529 otherline,othercolumn);
531 Creates ffewhere line and column objects for the source points, sends them
532 along with the error code to ffebad, then kills the line and column
533 objects before returning. */
536 ffelex_bad_2_ (ffebad errnum
, ffewhereLineNumber ln0
, ffewhereColumnNumber cn0
,
537 ffewhereLineNumber ln1
, ffewhereColumnNumber cn1
)
539 ffewhereLine wl0
, wl1
;
540 ffewhereColumn wc0
, wc1
;
542 wl0
= ffewhere_line_new (ln0
);
543 wc0
= ffewhere_column_new (cn0
);
544 wl1
= ffewhere_line_new (ln1
);
545 wc1
= ffewhere_column_new (cn1
);
546 ffebad_start_lex (errnum
);
547 ffebad_here (0, wl0
, wc0
);
548 ffebad_here (1, wl1
, wc1
);
550 ffewhere_line_kill (wl0
);
551 ffewhere_column_kill (wc0
);
552 ffewhere_line_kill (wl1
);
553 ffewhere_column_kill (wc1
);
557 ffelex_bad_here_ (int n
, ffewhereLineNumber ln0
,
558 ffewhereColumnNumber cn0
)
563 wl0
= ffewhere_line_new (ln0
);
564 wc0
= ffewhere_column_new (cn0
);
565 ffebad_here (n
, wl0
, wc0
);
566 ffewhere_line_kill (wl0
);
567 ffewhere_column_kill (wc0
);
570 #if FFECOM_targetCURRENT == FFECOM_targetGCC
572 ffelex_getc_ (FILE *finput
)
576 if (ffelex_kludge_chars_
== NULL
)
577 return getc (finput
);
579 c
= *ffelex_kludge_chars_
++;
583 ffelex_kludge_chars_
= NULL
;
584 return getc (finput
);
588 #if FFECOM_targetCURRENT == FFECOM_targetGCC
590 ffelex_cfebackslash_ (int *use_d
, int *d
, FILE *finput
)
592 register int c
= getc (finput
);
594 register unsigned count
;
595 unsigned firstdig
= 0;
603 if (warn_traditional
)
604 warning ("the meaning of `\\x' varies with -traditional");
606 if (flag_traditional
)
615 if (!(c
>= 'a' && c
<= 'f')
616 && !(c
>= 'A' && c
<= 'F')
617 && !(c
>= '0' && c
<= '9'))
624 if (c
>= 'a' && c
<= 'f')
625 code
+= c
- 'a' + 10;
626 if (c
>= 'A' && c
<= 'F')
627 code
+= c
- 'A' + 10;
628 if (c
>= '0' && c
<= '9')
630 if (code
!= 0 || count
!= 0)
639 error ("\\x used with no following hex digits");
641 /* Digits are all 0's. Ok. */
643 else if ((count
- 1) * 4 >= TYPE_PRECISION (integer_type_node
)
646 << (TYPE_PRECISION (integer_type_node
) - (count
- 1)
649 pedwarn ("hex escape out of range");
652 case '0': case '1': case '2': case '3': case '4':
653 case '5': case '6': case '7':
656 while ((c
<= '7') && (c
>= '0') && (count
++ < 3))
658 code
= (code
* 8) + (c
- '0');
665 case '\\': case '\'': case '"':
669 ffelex_next_line_ ();
679 return TARGET_NEWLINE
;
694 if (warn_traditional
)
695 warning ("the meaning of `\\a' varies with -traditional");
697 if (flag_traditional
)
702 #if 0 /* Vertical tab is present in common usage compilers. */
703 if (flag_traditional
)
711 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c
);
717 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
721 /* `\%' is used to prevent SCCS from getting confused. */
724 pedwarn ("non-ANSI escape sequence `\\%c'", c
);
727 if (c
>= 040 && c
< 0177)
728 pedwarn ("unknown escape sequence `\\%c'", c
);
730 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c
);
735 /* A miniature version of the C front-end lexer. */
737 #if FFECOM_targetCURRENT == FFECOM_targetGCC
739 ffelex_cfelex_ (ffelexToken
*xtoken
, FILE *finput
, int c
)
746 register unsigned buffer_length
;
748 if ((*xtoken
!= NULL
) && !ffelex_kludge_flag_
)
749 ffelex_token_kill (*xtoken
);
753 case '0': case '1': case '2': case '3': case '4':
754 case '5': case '6': case '7': case '8': case '9':
755 buffer_length
= ARRAY_SIZE (buff
);
758 r
= &buff
[buffer_length
];
764 register unsigned bytes_used
= (p
- q
);
767 q
= (char *)xrealloc (q
, buffer_length
);
769 r
= &q
[buffer_length
];
771 c
= ffelex_getc_ (finput
);
776 token
= ffelex_token_new_number (q
, ffewhere_line_unknown (),
777 ffewhere_column_unknown ());
785 buffer_length
= ARRAY_SIZE (buff
);
788 r
= &buff
[buffer_length
];
789 c
= ffelex_getc_ (finput
);
803 case '\\': /* ~~~~~ */
804 c
= ffelex_cfebackslash_ (&use_d
, &d
, finput
);
809 fatal ("Badly formed directive -- no closing quote");
819 if (use_d
!= 2) /* 0=>c, 1=>cd, 2=>nil. */
824 register unsigned bytes_used
= (p
- q
);
826 buffer_length
= bytes_used
* 2;
827 q
= (char *)xrealloc (q
, buffer_length
);
829 r
= &q
[buffer_length
];
838 token
= ffelex_token_new_character (q
, ffewhere_line_unknown (),
839 ffewhere_column_unknown ());
856 #if FFECOM_targetCURRENT == FFECOM_targetGCC
858 ffelex_file_pop_ (char *input_filename
)
860 if (input_file_stack
->next
)
862 struct file_stack
*p
= input_file_stack
;
863 input_file_stack
= p
->next
;
865 input_file_stack_tick
++;
866 #ifdef DWARF_DEBUGGING_INFO
867 if (debug_info_level
== DINFO_LEVEL_VERBOSE
868 && write_symbols
== DWARF_DEBUG
)
869 dwarfout_resume_previous_source_file (input_file_stack
->line
);
870 #endif /* DWARF_DEBUGGING_INFO */
873 error ("#-lines for entering and leaving files don't match");
875 /* Now that we've pushed or popped the input stack,
876 update the name in the top element. */
877 if (input_file_stack
)
878 input_file_stack
->name
= input_filename
;
882 #if FFECOM_targetCURRENT == FFECOM_targetGCC
884 ffelex_file_push_ (int old_lineno
, char *input_filename
)
887 = (struct file_stack
*) xmalloc (sizeof (struct file_stack
));
889 input_file_stack
->line
= old_lineno
;
890 p
->next
= input_file_stack
;
891 p
->name
= input_filename
;
892 input_file_stack
= p
;
893 input_file_stack_tick
++;
894 #ifdef DWARF_DEBUGGING_INFO
895 if (debug_info_level
== DINFO_LEVEL_VERBOSE
896 && write_symbols
== DWARF_DEBUG
)
897 dwarfout_start_new_source_file (input_filename
);
898 #endif /* DWARF_DEBUGGING_INFO */
900 /* Now that we've pushed or popped the input stack,
901 update the name in the top element. */
902 if (input_file_stack
)
903 input_file_stack
->name
= input_filename
;
907 /* Prepare to finish a statement-in-progress by sending the current
908 token, if any, then setting up EOS as the current token with the
909 appropriate current pointer. The caller can then move the current
910 pointer before actually sending EOS, if desired, as it is in
911 typical fixed-form cases. */
914 ffelex_prepare_eos_ ()
916 if (ffelex_token_
->type
!= FFELEX_typeNONE
)
918 ffelex_backslash_ (EOF
, 0);
920 switch (ffelex_raw_mode_
)
926 ffebad_start_lex ((ffelex_raw_char_
== '\'') ? FFEBAD_NO_CLOSING_APOSTROPHE
927 : FFEBAD_NO_CLOSING_QUOTE
);
928 ffebad_here (0, ffelex_token_
->where_line
, ffelex_token_
->where_col
);
929 ffebad_here (1, ffelex_current_wl_
, ffelex_current_wc_
);
940 ffebad_start_lex (FFEBAD_NOT_ENOUGH_HOLLERITH_CHARS
);
941 ffebad_here (0, ffelex_token_
->where_line
, ffelex_token_
->where_col
);
942 ffebad_here (1, ffelex_current_wl_
, ffelex_current_wc_
);
943 sprintf (num
, "%lu", (unsigned long) ffelex_raw_mode_
);
946 /* Make sure the token has some text, might as well fill up with spaces. */
949 ffelex_append_to_token_ (' ');
950 } while (--ffelex_raw_mode_
> 0);
954 ffelex_raw_mode_
= 0;
955 ffelex_send_token_ ();
957 ffelex_token_
->type
= FFELEX_typeEOS
;
958 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
959 ffelex_token_
->where_col
= ffewhere_column_use (ffelex_current_wc_
);
963 ffelex_finish_statement_ ()
965 if ((ffelex_number_of_tokens_
== 0)
966 && (ffelex_token_
->type
== FFELEX_typeNONE
))
967 return; /* Don't have a statement pending. */
969 if (ffelex_token_
->type
!= FFELEX_typeEOS
)
970 ffelex_prepare_eos_ ();
972 ffelex_permit_include_
= TRUE
;
973 ffelex_send_token_ ();
974 ffelex_permit_include_
= FALSE
;
975 ffelex_number_of_tokens_
= 0;
976 ffelex_label_tokens_
= 0;
977 ffelex_names_
= TRUE
;
978 ffelex_names_pure_
= FALSE
; /* Probably not necessary. */
979 ffelex_hexnum_
= FALSE
;
981 if (!ffe_is_ffedebug ())
984 /* For debugging purposes only. */
986 if (ffelex_total_tokens_
!= ffelex_old_total_tokens_
)
988 fprintf (dmpout
, "; token_track had %ld tokens, now have %ld.\n",
989 ffelex_old_total_tokens_
, ffelex_total_tokens_
);
990 ffelex_old_total_tokens_
= ffelex_total_tokens_
;
994 /* Copied from gcc/c-common.c get_directive_line. */
996 #if FFECOM_targetCURRENT == FFECOM_targetGCC
998 ffelex_get_directive_line_ (char **text
, FILE *finput
)
1000 static char *directive_buffer
= NULL
;
1001 static unsigned buffer_length
= 0;
1003 register char *buffer_limit
;
1004 register int looking_for
= 0;
1005 register int char_escaped
= 0;
1007 if (buffer_length
== 0)
1009 directive_buffer
= (char *)xmalloc (128);
1010 buffer_length
= 128;
1013 buffer_limit
= &directive_buffer
[buffer_length
];
1015 for (p
= directive_buffer
; ; )
1019 /* Make buffer bigger if it is full. */
1020 if (p
>= buffer_limit
)
1022 register unsigned bytes_used
= (p
- directive_buffer
);
1026 = (char *)xrealloc (directive_buffer
, buffer_length
);
1027 p
= &directive_buffer
[bytes_used
];
1028 buffer_limit
= &directive_buffer
[buffer_length
];
1033 /* Discard initial whitespace. */
1034 if ((c
== ' ' || c
== '\t') && p
== directive_buffer
)
1037 /* Detect the end of the directive. */
1038 if ((c
== '\n' && looking_for
== 0)
1041 if (looking_for
!= 0)
1042 fatal ("Bad directive -- missing close-quote");
1045 *text
= directive_buffer
;
1051 ffelex_next_line_ ();
1053 /* Handle string and character constant syntax. */
1056 if (looking_for
== c
&& !char_escaped
)
1057 looking_for
= 0; /* Found terminator... stop looking. */
1060 if (c
== '\'' || c
== '"')
1061 looking_for
= c
; /* Don't stop buffering until we see another
1062 another one of these (or an EOF). */
1064 /* Handle backslash. */
1065 char_escaped
= (c
== '\\' && ! char_escaped
);
1070 /* Handle # directives that make it through (or are generated by) the
1071 preprocessor. As much as reasonably possible, emulate the behavior
1072 of the gcc compiler phase cc1, though interactions between #include
1073 and INCLUDE might possibly produce bizarre results in terms of
1074 error reporting and the generation of debugging info vis-a-vis the
1075 locations of some things.
1077 Returns the next character unhandled, which is always newline or EOF. */
1079 #if FFECOM_targetCURRENT == FFECOM_targetGCC
1081 ffelex_hash_ (FILE *finput
)
1084 ffelexToken token
= NULL
;
1086 /* Read first nonwhite char after the `#'. */
1088 c
= ffelex_getc_ (finput
);
1089 while (c
== ' ' || c
== '\t')
1090 c
= ffelex_getc_ (finput
);
1092 /* If a letter follows, then if the word here is `line', skip
1093 it and ignore it; otherwise, ignore the line, with an error
1094 if the word isn't `pragma', `ident', `define', or `undef'. */
1096 if ((c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z'))
1100 if (getc (finput
) == 'r'
1101 && getc (finput
) == 'a'
1102 && getc (finput
) == 'g'
1103 && getc (finput
) == 'm'
1104 && getc (finput
) == 'a'
1105 && ((c
= getc (finput
)) == ' ' || c
== '\t' || c
== '\n'
1109 #if 0 /* g77 doesn't handle pragmas, so ignores them FOR NOW. */
1110 #ifdef HANDLE_SYSV_PRAGMA
1111 return handle_sysv_pragma (finput
, c
);
1112 #else /* !HANDLE_SYSV_PRAGMA */
1113 #ifdef HANDLE_PRAGMA
1114 HANDLE_PRAGMA (finput
);
1115 #endif /* HANDLE_PRAGMA */
1117 #endif /* !HANDLE_SYSV_PRAGMA */
1124 if (getc (finput
) == 'e'
1125 && getc (finput
) == 'f'
1126 && getc (finput
) == 'i'
1127 && getc (finput
) == 'n'
1128 && getc (finput
) == 'e'
1129 && ((c
= getc (finput
)) == ' ' || c
== '\t' || c
== '\n'
1134 c
= ffelex_get_directive_line_ (&text
, finput
);
1136 #ifdef DWARF_DEBUGGING_INFO
1137 if ((debug_info_level
== DINFO_LEVEL_VERBOSE
)
1138 && (write_symbols
== DWARF_DEBUG
))
1139 dwarfout_define (lineno
, text
);
1140 #endif /* DWARF_DEBUGGING_INFO */
1147 if (getc (finput
) == 'n'
1148 && getc (finput
) == 'd'
1149 && getc (finput
) == 'e'
1150 && getc (finput
) == 'f'
1151 && ((c
= getc (finput
)) == ' ' || c
== '\t' || c
== '\n'
1156 c
= ffelex_get_directive_line_ (&text
, finput
);
1158 #ifdef DWARF_DEBUGGING_INFO
1159 if ((debug_info_level
== DINFO_LEVEL_VERBOSE
)
1160 && (write_symbols
== DWARF_DEBUG
))
1161 dwarfout_undef (lineno
, text
);
1162 #endif /* DWARF_DEBUGGING_INFO */
1169 if (getc (finput
) == 'i'
1170 && getc (finput
) == 'n'
1171 && getc (finput
) == 'e'
1172 && ((c
= getc (finput
)) == ' ' || c
== '\t'))
1177 if (getc (finput
) == 'd'
1178 && getc (finput
) == 'e'
1179 && getc (finput
) == 'n'
1180 && getc (finput
) == 't'
1181 && ((c
= getc (finput
)) == ' ' || c
== '\t'))
1183 /* #ident. The pedantic warning is now in cccp.c. */
1185 /* Here we have just seen `#ident '.
1186 A string constant should follow. */
1188 while (c
== ' ' || c
== '\t')
1191 /* If no argument, ignore the line. */
1192 if (c
== '\n' || c
== EOF
)
1195 c
= ffelex_cfelex_ (&token
, finput
, c
);
1198 || (ffelex_token_type (token
) != FFELEX_typeCHARACTER
))
1200 error ("invalid #ident");
1204 if (ffe_is_ident ())
1206 #ifdef ASM_OUTPUT_IDENT
1207 ASM_OUTPUT_IDENT (asm_out_file
,
1208 ffelex_token_text (token
));
1212 /* Skip the rest of this line. */
1217 error ("undefined or invalid # directive");
1222 /* Here we have either `#line' or `# <nonletter>'.
1223 In either case, it should be a line number; a digit should follow. */
1225 while (c
== ' ' || c
== '\t')
1226 c
= ffelex_getc_ (finput
);
1228 /* If the # is the only nonwhite char on the line,
1229 just ignore it. Check the new newline. */
1230 if (c
== '\n' || c
== EOF
)
1233 /* Something follows the #; read a token. */
1235 c
= ffelex_cfelex_ (&token
, finput
, c
);
1238 && (ffelex_token_type (token
) == FFELEX_typeNUMBER
))
1240 int old_lineno
= lineno
;
1241 char *old_input_filename
= input_filename
;
1244 /* subtract one, because it is the following line that
1245 gets the specified number */
1246 int l
= atoi (ffelex_token_text (token
)) - 1;
1248 /* Is this the last nonwhite stuff on the line? */
1249 while (c
== ' ' || c
== '\t')
1250 c
= ffelex_getc_ (finput
);
1251 if (c
== '\n' || c
== EOF
)
1253 /* No more: store the line number and check following line. */
1255 if (!ffelex_kludge_flag_
)
1257 ffewhere_file_set (NULL
, TRUE
, (ffewhereLineNumber
) l
);
1260 ffelex_token_kill (token
);
1265 /* More follows: it must be a string constant (filename). */
1267 /* Read the string constant. */
1268 c
= ffelex_cfelex_ (&token
, finput
, c
);
1271 || (ffelex_token_type (token
) != FFELEX_typeCHARACTER
))
1273 error ("invalid #line");
1279 if (ffelex_kludge_flag_
)
1280 input_filename
= ffelex_token_text (token
);
1283 wf
= ffewhere_file_new (ffelex_token_text (token
),
1284 ffelex_token_length (token
));
1285 input_filename
= ffewhere_file_name (wf
);
1286 ffewhere_file_set (wf
, TRUE
, (ffewhereLineNumber
) l
);
1289 #if 0 /* Not sure what g77 should do with this yet. */
1290 /* Each change of file name
1291 reinitializes whether we are now in a system header. */
1292 in_system_header
= 0;
1295 if (main_input_filename
== 0)
1296 main_input_filename
= input_filename
;
1298 /* Is this the last nonwhite stuff on the line? */
1299 while (c
== ' ' || c
== '\t')
1301 if (c
== '\n' || c
== EOF
)
1303 if (!ffelex_kludge_flag_
)
1305 /* Update the name in the top element of input_file_stack. */
1306 if (input_file_stack
)
1307 input_file_stack
->name
= input_filename
;
1310 ffelex_token_kill (token
);
1315 c
= ffelex_cfelex_ (&token
, finput
, c
);
1317 /* `1' after file name means entering new file.
1318 `2' after file name means just left a file. */
1321 && (ffelex_token_type (token
) == FFELEX_typeNUMBER
))
1323 int num
= atoi (ffelex_token_text (token
));
1325 if (ffelex_kludge_flag_
)
1328 input_filename
= old_input_filename
;
1329 fatal ("Use `#line ...' instead of `# ...' in first line");
1334 /* Pushing to a new file. */
1335 ffelex_file_push_ (old_lineno
, input_filename
);
1339 /* Popping out of a file. */
1340 ffelex_file_pop_ (input_filename
);
1343 /* Is this the last nonwhite stuff on the line? */
1344 while (c
== ' ' || c
== '\t')
1346 if (c
== '\n' || c
== EOF
)
1349 ffelex_token_kill (token
);
1353 c
= ffelex_cfelex_ (&token
, finput
, c
);
1356 /* `3' after file name means this is a system header file. */
1358 #if 0 /* Not sure what g77 should do with this yet. */
1360 && (ffelex_token_type (token
) == FFELEX_typeNUMBER
)
1361 && (atoi (ffelex_token_text (token
)) == 3))
1362 in_system_header
= 1;
1365 while (c
== ' ' || c
== '\t')
1367 if (((token
!= NULL
)
1368 || (c
!= '\n' && c
!= EOF
))
1369 && ffelex_kludge_flag_
)
1372 input_filename
= old_input_filename
;
1373 fatal ("Use `#line ...' instead of `# ...' in first line");
1377 error ("invalid #-line");
1379 /* skip the rest of this line. */
1381 if ((token
!= NULL
) && !ffelex_kludge_flag_
)
1382 ffelex_token_kill (token
);
1383 while ((c
= getc (finput
)) != EOF
&& c
!= '\n')
1387 #endif /* FFECOM_targetCURRENT == FFECOM_targetGCC */
1389 /* "Image" a character onto the card image, return incremented column number.
1391 Normally invoking this function as in
1392 column = ffelex_image_char_ (c, column);
1393 is the same as doing:
1394 ffelex_card_image_[column++] = c;
1396 However, tabs and carriage returns are handled specially, to preserve
1397 the visual "image" of the input line (in most editors) in the card
1400 Carriage returns are ignored, as they are assumed to be followed
1403 A tab is handled by first doing:
1404 ffelex_card_image_[column++] = ' ';
1405 That is, it translates to at least one space. Then, as many spaces
1406 are imaged as necessary to bring the column number to the next tab
1407 position, where tab positions start in the ninth column and each
1408 eighth column afterwards. ALSO, a static var named ffelex_saw_tab_
1409 is set to TRUE to notify the lexer that a tab was seen.
1411 Columns are numbered and tab stops set as illustrated below:
1413 012345670123456701234567...
1417 xxxxxxx yyyyyyy zzzzzzz
1418 xxxxxxxx yyyyyyyy... */
1420 static ffewhereColumnNumber
1421 ffelex_image_char_ (int c
, ffewhereColumnNumber column
)
1423 ffewhereColumnNumber old_column
= column
;
1425 if (column
>= ffelex_card_size_
)
1427 ffewhereColumnNumber newmax
= ffelex_card_size_
<< 1;
1429 if (ffelex_bad_line_
)
1432 if ((newmax
>> 1) != ffelex_card_size_
)
1433 { /* Overflowed column number. */
1434 overflow
: /* :::::::::::::::::::: */
1436 ffelex_bad_line_
= TRUE
;
1437 strcpy (&ffelex_card_image_
[column
- 3], "...");
1438 ffelex_card_length_
= column
;
1439 ffelex_bad_1_ (FFEBAD_LINE_TOO_LONG
,
1440 ffelex_linecount_current_
, column
+ 1);
1445 = malloc_resize_ksr (malloc_pool_image (),
1448 ffelex_card_size_
+ 9);
1449 ffelex_card_size_
= newmax
;
1458 ffelex_saw_tab_
= TRUE
;
1459 ffelex_card_image_
[column
++] = ' ';
1460 while ((column
& 7) != 0)
1461 ffelex_card_image_
[column
++] = ' ';
1465 if (!ffelex_bad_line_
)
1467 ffelex_bad_line_
= TRUE
;
1468 strcpy (&ffelex_card_image_
[column
], "[\\0]");
1469 ffelex_card_length_
= column
+ 4;
1470 ffebad_start_msg_lex ("Null character at %0 -- line ignored",
1471 FFEBAD_severityFATAL
);
1472 ffelex_bad_here_ (0, ffelex_linecount_current_
, column
+ 1);
1479 ffelex_card_image_
[column
++] = c
;
1483 if (column
< old_column
)
1485 column
= old_column
;
1486 goto overflow
; /* :::::::::::::::::::: */
1495 ffewhereFile include_wherefile
= ffelex_include_wherefile_
;
1496 FILE *include_file
= ffelex_include_file_
;
1497 /* The rest of this is to push, and after the INCLUDE file is processed,
1498 pop, the static lexer state info that pertains to each particular
1501 ffewhereColumnNumber card_size
= ffelex_card_size_
;
1502 ffewhereColumnNumber card_length
= ffelex_card_length_
;
1503 ffewhereLine current_wl
= ffelex_current_wl_
;
1504 ffewhereColumn current_wc
= ffelex_current_wc_
;
1505 bool saw_tab
= ffelex_saw_tab_
;
1506 ffewhereColumnNumber final_nontab_column
= ffelex_final_nontab_column_
;
1507 ffewhereFile current_wf
= ffelex_current_wf_
;
1508 ffewhereLineNumber linecount_current
= ffelex_linecount_current_
;
1509 ffewhereLineNumber linecount_offset
1510 = ffewhere_line_filelinenum (current_wl
);
1511 #if FFECOM_targetCURRENT == FFECOM_targetGCC
1512 int old_lineno
= lineno
;
1513 char *old_input_filename
= input_filename
;
1516 if (card_length
!= 0)
1518 card_image
= malloc_new_ks (malloc_pool_image (),
1519 "FFELEX saved card image",
1521 memcpy (card_image
, ffelex_card_image_
, card_length
);
1526 ffelex_set_include_
= FALSE
;
1528 ffelex_next_line_ ();
1530 ffewhere_file_set (include_wherefile
, TRUE
, 0);
1532 #if FFECOM_targetCURRENT == FFECOM_targetGCC
1533 ffelex_file_push_ (old_lineno
, ffewhere_file_name (include_wherefile
));
1534 #endif /* FFECOM_targetCURRENT == FFECOM_targetGCC */
1536 if (ffelex_include_free_form_
)
1537 ffelex_file_free (include_wherefile
, include_file
);
1539 ffelex_file_fixed (include_wherefile
, include_file
);
1541 #if FFECOM_targetCURRENT == FFECOM_targetGCC
1542 ffelex_file_pop_ (ffewhere_file_name (current_wf
));
1543 #endif /* FFECOM_targetCURRENT == FFECOM_targetGCC */
1545 ffewhere_file_set (current_wf
, TRUE
, linecount_offset
);
1547 ffecom_close_include (include_file
);
1549 if (card_length
!= 0)
1551 #ifdef REDUCE_CARD_SIZE_AFTER_BIGGY /* Define if occasional large lines. */
1552 #error "need to handle possible reduction of card size here!!"
1554 assert (ffelex_card_size_
>= card_length
); /* It shrunk?? */
1555 memcpy (ffelex_card_image_
, card_image
, card_length
);
1557 ffelex_card_image_
[card_length
] = '\0';
1559 #if FFECOM_targetCURRENT == FFECOM_targetGCC
1560 input_filename
= old_input_filename
;
1561 lineno
= old_lineno
;
1563 ffelex_linecount_current_
= linecount_current
;
1564 ffelex_current_wf_
= current_wf
;
1565 ffelex_final_nontab_column_
= final_nontab_column
;
1566 ffelex_saw_tab_
= saw_tab
;
1567 ffelex_current_wc_
= current_wc
;
1568 ffelex_current_wl_
= current_wl
;
1569 ffelex_card_length_
= card_length
;
1570 ffelex_card_size_
= card_size
;
1573 /* ffelex_is_free_char_ctx_contin_ -- Character Context Continuation?
1575 ffewhereColumnNumber col;
1576 int c; // Char at col.
1577 if ((c == '&') && ffelex_is_free_char_ctx_contin_(col + 1))
1578 // We have a continuation indicator.
1580 If there are <n> spaces starting at ffelex_card_image_[col] up through
1581 the null character, where <n> is 0 or greater, returns TRUE. */
1584 ffelex_is_free_char_ctx_contin_ (ffewhereColumnNumber col
)
1586 while (ffelex_card_image_
[col
] != '\0')
1588 if (ffelex_card_image_
[col
++] != ' ')
1594 /* ffelex_is_free_nonc_ctx_contin_ -- Noncharacter Context Continuation?
1596 ffewhereColumnNumber col;
1597 int c; // Char at col.
1598 if ((c == '&') && ffelex_is_free_nonc_ctx_contin_(col + 1))
1599 // We have a continuation indicator.
1601 If there are <n> spaces starting at ffelex_card_image_[col] up through
1602 the null character or '!', where <n> is 0 or greater, returns TRUE. */
1605 ffelex_is_free_nonc_ctx_contin_ (ffewhereColumnNumber col
)
1607 while ((ffelex_card_image_
[col
] != '\0') && (ffelex_card_image_
[col
] != '!'))
1609 if (ffelex_card_image_
[col
++] != ' ')
1616 ffelex_next_line_ ()
1618 ffelex_linecount_current_
= ffelex_linecount_next_
;
1619 ++ffelex_linecount_next_
;
1620 #if FFECOM_targetCURRENT == FFECOM_targetGCC
1626 ffelex_send_token_ ()
1628 ++ffelex_number_of_tokens_
;
1630 ffelex_backslash_ (EOF
, 0);
1632 if (ffelex_token_
->text
== NULL
)
1634 if (ffelex_token_
->type
== FFELEX_typeCHARACTER
)
1636 ffelex_append_to_token_ ('\0');
1637 ffelex_token_
->length
= 0;
1641 ffelex_token_
->text
[ffelex_token_
->length
] = '\0';
1643 assert (ffelex_raw_mode_
== 0);
1645 if (ffelex_token_
->type
== FFELEX_typeNAMES
)
1647 ffewhere_line_kill (ffelex_token_
->currentnames_line
);
1648 ffewhere_column_kill (ffelex_token_
->currentnames_col
);
1651 assert (ffelex_handler_
!= NULL
);
1652 ffelex_handler_
= (ffelexHandler
) (*ffelex_handler_
) (ffelex_token_
);
1653 assert (ffelex_handler_
!= NULL
);
1655 ffelex_token_kill (ffelex_token_
);
1657 ffelex_token_
= ffelex_token_new_ ();
1658 ffelex_token_
->uses
= 1;
1659 ffelex_token_
->text
= NULL
;
1660 if (ffelex_raw_mode_
< 0)
1662 ffelex_token_
->type
= FFELEX_typeCHARACTER
;
1663 ffelex_token_
->where_line
= ffelex_raw_where_line_
;
1664 ffelex_token_
->where_col
= ffelex_raw_where_col_
;
1665 ffelex_raw_where_line_
= ffewhere_line_unknown ();
1666 ffelex_raw_where_col_
= ffewhere_column_unknown ();
1670 ffelex_token_
->type
= FFELEX_typeNONE
;
1671 ffelex_token_
->where_line
= ffewhere_line_unknown ();
1672 ffelex_token_
->where_col
= ffewhere_column_unknown ();
1675 if (ffelex_set_include_
)
1679 /* ffelex_swallow_tokens_ -- Eat all tokens delivered to me
1681 return ffelex_swallow_tokens_;
1683 Return this handler when you don't want to look at any more tokens in the
1684 statement because you've encountered an unrecoverable error in the
1687 static ffelexHandler
1688 ffelex_swallow_tokens_ (ffelexToken t
)
1690 assert (ffelex_eos_handler_
!= NULL
);
1692 if ((ffelex_token_type (t
) == FFELEX_typeEOS
)
1693 || (ffelex_token_type (t
) == FFELEX_typeSEMICOLON
))
1694 return (ffelexHandler
) (*ffelex_eos_handler_
) (t
);
1696 return (ffelexHandler
) ffelex_swallow_tokens_
;
1700 ffelex_token_new_ ()
1704 ++ffelex_total_tokens_
;
1706 t
= (ffelexToken
) malloc_new_ks (malloc_pool_image (),
1707 "FFELEX token", sizeof (*t
));
1708 t
->id_
= ffelex_token_nextid_
++;
1713 ffelex_type_string_ (ffelexType type
)
1715 static char *types
[] = {
1717 "FFELEX_typeCOMMENT",
1723 "FFELEX_typeDOLLAR",
1725 "FFELEX_typePERCENT",
1726 "FFELEX_typeAMPERSAND",
1727 "FFELEX_typeAPOSTROPHE",
1728 "FFELEX_typeOPEN_PAREN",
1729 "FFELEX_typeCLOSE_PAREN",
1730 "FFELEX_typeASTERISK",
1733 "FFELEX_typePERIOD",
1735 "FFELEX_typeNUMBER",
1736 "FFELEX_typeOPEN_ANGLE",
1737 "FFELEX_typeEQUALS",
1738 "FFELEX_typeCLOSE_ANGLE",
1742 "FFELEX_typeCONCAT",
1745 "FFELEX_typeHOLLERITH",
1746 "FFELEX_typeCHARACTER",
1748 "FFELEX_typeSEMICOLON",
1749 "FFELEX_typeUNDERSCORE",
1750 "FFELEX_typeQUESTION",
1751 "FFELEX_typeOPEN_ARRAY",
1752 "FFELEX_typeCLOSE_ARRAY",
1753 "FFELEX_typeCOLONCOLON",
1754 "FFELEX_typeREL_LE",
1755 "FFELEX_typeREL_NE",
1756 "FFELEX_typeREL_EQ",
1757 "FFELEX_typePOINTS",
1761 if (type
>= ARRAY_SIZE (types
))
1767 ffelex_display_token (ffelexToken t
)
1772 fprintf (dmpout
, "; Token #%lu is %s (line %" ffewhereLineNumber_f
"u, col %"
1773 ffewhereColumnNumber_f
"u)",
1775 ffelex_type_string_ (t
->type
),
1776 ffewhere_line_number (t
->where_line
),
1777 ffewhere_column_number (t
->where_col
));
1779 if (t
->text
!= NULL
)
1780 fprintf (dmpout
, ": \"%.*s\"\n",
1784 fprintf (dmpout
, ".\n");
1787 /* ffelex_expecting_character -- Tells if next token expected to be CHARACTER
1789 if (ffelex_expecting_character())
1790 // next token delivered by lexer will be CHARACTER.
1792 If the most recent call to ffelex_set_expecting_hollerith since the last
1793 token was delivered by the lexer passed a length of -1, then we return
1794 TRUE, because the next token we deliver will be typeCHARACTER, else we
1798 ffelex_expecting_character ()
1800 return (ffelex_raw_mode_
!= 0);
1803 /* ffelex_file_fixed -- Lex a given file in fixed source form
1807 ffelex_file_fixed(wf,f);
1809 Lexes the file according to Fortran 90 ANSI + VXT specifications. */
1812 ffelex_file_fixed (ffewhereFile wf
, FILE *f
)
1814 register int c
; /* Character currently under consideration. */
1815 register ffewhereColumnNumber column
; /* Not really; 0 means column 1... */
1816 bool disallow_continuation_line
;
1817 bool ignore_disallowed_continuation
;
1818 int latest_char_in_file
= 0; /* For getting back into comment-skipping
1821 ffewhereColumnNumber first_label_char
; /* First char of label --
1823 char label_string
[6]; /* Text of label. */
1824 int labi
; /* Length of label text. */
1825 bool finish_statement
; /* Previous statement finished? */
1826 bool have_content
; /* This line have content? */
1827 bool just_do_label
; /* Nothing but label (and continuation?) on
1830 /* Lex is called for a particular file, not for a particular program unit.
1831 Yet the two events do share common characteristics. The first line in a
1832 file or in a program unit cannot be a continuation line. No token can
1833 be in mid-formation. No current label for the statement exists, since
1834 there is no current statement. */
1836 assert (ffelex_handler_
!= NULL
);
1838 #if FFECOM_targetCURRENT == FFECOM_targetGCC
1840 input_filename
= ffewhere_file_name (wf
);
1842 ffelex_current_wf_
= wf
;
1843 disallow_continuation_line
= TRUE
;
1844 ignore_disallowed_continuation
= FALSE
;
1845 ffelex_token_
->type
= FFELEX_typeNONE
;
1846 ffelex_number_of_tokens_
= 0;
1847 ffelex_label_tokens_
= 0;
1848 ffelex_current_wl_
= ffewhere_line_unknown ();
1849 ffelex_current_wc_
= ffewhere_column_unknown ();
1850 latest_char_in_file
= '\n';
1851 goto first_line
; /* :::::::::::::::::::: */
1853 /* Come here to get a new line. */
1855 beginning_of_line
: /* :::::::::::::::::::: */
1857 disallow_continuation_line
= FALSE
;
1859 /* Come here directly when last line didn't clarify the continuation issue. */
1861 beginning_of_line_again
: /* :::::::::::::::::::: */
1863 #ifdef REDUCE_CARD_SIZE_AFTER_BIGGY /* Define if occasional large lines. */
1864 if (ffelex_card_size_
!= FFELEX_columnINITIAL_SIZE_
)
1867 = malloc_resize_ks (malloc_pool_image (),
1869 FFELEX_columnINITIAL_SIZE_
+ 9,
1870 ffelex_card_size_
+ 9);
1871 ffelex_card_size_
= FFELEX_columnINITIAL_SIZE_
;
1875 first_line
: /* :::::::::::::::::::: */
1877 c
= latest_char_in_file
;
1878 if ((c
== EOF
) || ((c
= ffelex_getc_ (f
)) == EOF
))
1881 end_of_file
: /* :::::::::::::::::::: */
1883 /* Line ending in EOF instead of \n still counts as a whole line. */
1885 ffelex_finish_statement_ ();
1886 ffewhere_line_kill (ffelex_current_wl_
);
1887 ffewhere_column_kill (ffelex_current_wc_
);
1888 return (ffelexHandler
) ffelex_handler_
;
1891 ffelex_next_line_ ();
1893 ffelex_bad_line_
= FALSE
;
1895 /* Skip over comment (and otherwise ignored) lines as quickly as possible! */
1897 while (((lextype
= ffelex_first_char_
[c
]) == FFELEX_typeCOMMENT
)
1898 || (lextype
== FFELEX_typeERROR
)
1899 || (lextype
== FFELEX_typeSLASH
)
1900 || (lextype
== FFELEX_typeHASH
))
1902 /* Test most frequent type of line first, etc. */
1903 if ((lextype
== FFELEX_typeCOMMENT
)
1904 || ((lextype
== FFELEX_typeSLASH
)
1905 && ((c
= getc (f
)) == '*'))) /* NOTE SIDE-EFFECT. */
1907 /* Typical case (straight comment), just ignore rest of line. */
1908 comment_line
: /* :::::::::::::::::::: */
1910 while ((c
!= '\n') && (c
!= EOF
))
1913 #if FFECOM_targetCURRENT == FFECOM_targetGCC
1914 else if (lextype
== FFELEX_typeHASH
)
1915 c
= ffelex_hash_ (f
);
1917 else if (lextype
== FFELEX_typeSLASH
)
1919 /* SIDE-EFFECT ABOVE HAS HAPPENED. */
1920 ffelex_card_image_
[0] = '/';
1921 ffelex_card_image_
[1] = c
;
1923 goto bad_first_character
; /* :::::::::::::::::::: */
1926 /* typeERROR or unsupported typeHASH. */
1927 { /* Bad first character, get line and display
1929 column
= ffelex_image_char_ (c
, 0);
1931 bad_first_character
: /* :::::::::::::::::::: */
1933 ffelex_bad_line_
= TRUE
;
1934 while (((c
= getc (f
)) != '\n') && (c
!= EOF
))
1935 column
= ffelex_image_char_ (c
, column
);
1936 ffelex_card_image_
[column
] = '\0';
1937 ffelex_card_length_
= column
;
1938 ffelex_bad_1_ (FFEBAD_FIRST_CHAR_INVALID
,
1939 ffelex_linecount_current_
, 1);
1942 /* Read past last char in line. */
1946 ffelex_next_line_ ();
1947 goto end_of_file
; /* :::::::::::::::::::: */
1952 ffelex_next_line_ ();
1955 goto end_of_file
; /* :::::::::::::::::::: */
1957 ffelex_bad_line_
= FALSE
;
1958 } /* while [c, first char, means comment] */
1962 || (ffelex_final_nontab_column_
== 0);
1964 if (lextype
== FFELEX_typeDEBUG
)
1965 c
= ' '; /* A 'D' or 'd' in column 1 with the
1966 debug-lines option on. */
1968 column
= ffelex_image_char_ (c
, 0);
1970 /* Read the entire line in as is (with whitespace processing). */
1972 while (((c
= getc (f
)) != '\n') && (c
!= EOF
))
1973 column
= ffelex_image_char_ (c
, column
);
1975 if (ffelex_bad_line_
)
1977 ffelex_card_image_
[column
] = '\0';
1978 ffelex_card_length_
= column
;
1979 goto comment_line
; /* :::::::::::::::::::: */
1982 /* If no tab, cut off line after column 72/132. */
1984 if (!ffelex_saw_tab_
&& (column
> ffelex_final_nontab_column_
))
1986 /* Technically, we should now fill ffelex_card_image_ up thru column
1987 72/132 with spaces, since character/hollerith constants must count
1988 them in that manner. To save CPU time in several ways (avoid a loop
1989 here that would be used only when we actually end a line in
1990 character-constant mode; avoid writing memory unnecessarily; avoid a
1991 loop later checking spaces when not scanning for character-constant
1992 characters), we don't do this, and we do the appropriate thing when
1993 we encounter end-of-line while actually processing a character
1996 column
= ffelex_final_nontab_column_
;
1998 ffelex_card_image_
[column
] = '\0';
1999 ffelex_card_length_
= column
;
2001 /* Save next char in file so we can use register-based c while analyzing
2002 line we just read. */
2004 latest_char_in_file
= c
; /* Should be either '\n' or EOF. */
2006 have_content
= FALSE
;
2008 /* Handle label, if any. */
2011 first_label_char
= FFEWHERE_columnUNKNOWN
;
2012 for (column
= 0; column
< 5; ++column
)
2014 switch (c
= ffelex_card_image_
[column
])
2018 goto stop_looking
; /* :::::::::::::::::::: */
2033 label_string
[labi
++] = c
;
2034 if (first_label_char
== FFEWHERE_columnUNKNOWN
)
2035 first_label_char
= column
+ 1;
2041 ffelex_bad_1_ (FFEBAD_LABEL_FIELD_NOT_NUMERIC
,
2042 ffelex_linecount_current_
,
2044 goto beginning_of_line_again
; /* :::::::::::::::::::: */
2046 if (ffe_is_pedantic ())
2047 ffelex_bad_1_ (FFEBAD_AMPERSAND
,
2048 ffelex_linecount_current_
, 1);
2049 finish_statement
= FALSE
;
2050 just_do_label
= FALSE
;
2051 goto got_a_continuation
; /* :::::::::::::::::::: */
2054 if (ffelex_card_image_
[column
+ 1] == '*')
2055 goto stop_looking
; /* :::::::::::::::::::: */
2058 ffelex_bad_1_ (FFEBAD_LABEL_FIELD_NOT_NUMERIC
,
2059 ffelex_linecount_current_
, column
+ 1);
2060 goto beginning_of_line_again
; /* :::::::::::::::::::: */
2064 stop_looking
: /* :::::::::::::::::::: */
2066 label_string
[labi
] = '\0';
2068 /* Find first nonblank char starting with continuation column. */
2070 if (column
== 5) /* In which case we didn't see end of line in
2072 while ((c
= ffelex_card_image_
[column
]) == ' ')
2075 /* Now we're trying to figure out whether this is a continuation line and
2076 whether there's anything else of substance on the line. The cases are
2079 1. If a line has an explicit continuation character (other than the digit
2080 zero), then if it also has a label, the label is ignored and an error
2081 message is printed. Any remaining text on the line is passed to the
2082 parser tasks, thus even an all-blank line (possibly with an ignored
2083 label) aside from a positive continuation character might have meaning
2084 in the midst of a character or hollerith constant.
2086 2. If a line has no explicit continuation character (that is, it has a
2087 space in column 6 and the first non-space character past column 6 is
2088 not a digit 0-9), then there are two possibilities:
2090 A. A label is present and/or a non-space (and non-comment) character
2091 appears somewhere after column 6. Terminate processing of the previous
2092 statement, if any, send the new label for the next statement, if any,
2093 and start processing a new statement with this non-blank character, if
2096 B. The line is essentially blank, except for a possible comment character.
2097 Don't terminate processing of the previous statement and don't pass any
2098 characters to the parser tasks, since the line is not flagged as a
2099 continuation line. We treat it just like a completely blank line.
2101 3. If a line has a continuation character of zero (0), then we terminate
2102 processing of the previous statement, if any, send the new label for the
2103 next statement, if any, and start processing a new statement, if any
2104 non-blank characters are present.
2106 If, when checking to see if we should terminate the previous statement, it
2107 is found that there is no previous statement but that there is an
2108 outstanding label, substitute CONTINUE as the statement for the label
2109 and display an error message. */
2111 finish_statement
= FALSE
;
2112 just_do_label
= FALSE
;
2116 case '!': /* ANSI Fortran 90 says ! in column 6 is
2118 /* VXT Fortran says ! anywhere is comment, even column 6. */
2119 if (ffe_is_vxt () || (column
!= 5))
2120 goto no_tokens_on_line
; /* :::::::::::::::::::: */
2121 goto got_a_continuation
; /* :::::::::::::::::::: */
2124 if (ffelex_card_image_
[column
+ 1] != '*')
2125 goto some_other_character
; /* :::::::::::::::::::: */
2129 /* This seems right to do. But it is close to call, since / * starting
2130 in column 6 will thus be interpreted as a continuation line
2131 beginning with '*'. */
2133 goto got_a_continuation
;/* :::::::::::::::::::: */
2137 /* End of line. Therefore may be continued-through line, so handle
2138 pending label as possible to-be-continued and drive end-of-statement
2139 for any previous statement, else treat as blank line. */
2141 no_tokens_on_line
: /* :::::::::::::::::::: */
2143 if (ffe_is_pedantic () && (c
== '/'))
2144 ffelex_bad_1_ (FFEBAD_NON_ANSI_COMMENT
,
2145 ffelex_linecount_current_
, column
+ 1);
2146 if (first_label_char
!= FFEWHERE_columnUNKNOWN
)
2147 { /* Can't be a continued-through line if it
2149 finish_statement
= TRUE
;
2150 have_content
= TRUE
;
2151 just_do_label
= TRUE
;
2154 goto beginning_of_line_again
; /* :::::::::::::::::::: */
2157 if (ffe_is_pedantic () && (column
!= 5))
2158 ffelex_bad_1_ (FFEBAD_NON_ANSI_CONTINUATION_COLUMN
,
2159 ffelex_linecount_current_
, column
+ 1);
2160 finish_statement
= TRUE
;
2161 goto check_for_content
; /* :::::::::::::::::::: */
2173 /* NOTE: This label can be reached directly from the code
2174 that lexes the label field in columns 1-5. */
2175 got_a_continuation
: /* :::::::::::::::::::: */
2177 if (first_label_char
!= FFEWHERE_columnUNKNOWN
)
2179 ffelex_bad_2_ (FFEBAD_LABEL_ON_CONTINUATION
,
2180 ffelex_linecount_current_
,
2182 ffelex_linecount_current_
,
2184 first_label_char
= FFEWHERE_columnUNKNOWN
;
2186 if (disallow_continuation_line
)
2188 if (!ignore_disallowed_continuation
)
2189 ffelex_bad_1_ (FFEBAD_INVALID_CONTINUATION
,
2190 ffelex_linecount_current_
, column
+ 1);
2191 goto beginning_of_line_again
; /* :::::::::::::::::::: */
2193 if (ffe_is_pedantic () && (column
!= 5))
2194 ffelex_bad_1_ (FFEBAD_NON_ANSI_CONTINUATION_COLUMN
,
2195 ffelex_linecount_current_
, column
+ 1);
2196 if ((ffelex_raw_mode_
!= 0)
2197 && (((c
= ffelex_card_image_
[column
+ 1]) != '\0')
2198 || !ffelex_saw_tab_
))
2201 have_content
= TRUE
;
2205 check_for_content
: /* :::::::::::::::::::: */
2207 while ((c
= ffelex_card_image_
[++column
]) == ' ')
2212 && (ffelex_card_image_
[column
+ 1] == '*')))
2214 if (ffe_is_pedantic () && (c
== '/'))
2215 ffelex_bad_1_ (FFEBAD_NON_ANSI_COMMENT
,
2216 ffelex_linecount_current_
, column
+ 1);
2217 just_do_label
= TRUE
;
2220 have_content
= TRUE
;
2225 some_other_character
: /* :::::::::::::::::::: */
2228 goto got_a_continuation
;/* :::::::::::::::::::: */
2230 /* Here is the very normal case of a regular character starting in
2231 column 7 or beyond with a blank in column 6. */
2233 finish_statement
= TRUE
;
2234 have_content
= TRUE
;
2239 || (first_label_char
!= FFEWHERE_columnUNKNOWN
))
2241 /* The line has content of some kind, install new end-statement
2242 point for error messages. Note that "content" includes cases
2243 where there's little apparent content but enough to finish
2244 a statement. That's because finishing a statement can trigger
2245 an impending INCLUDE, and that requires accurate line info being
2246 maintained by the lexer. */
2248 if (finish_statement
)
2249 ffelex_prepare_eos_ (); /* Prepare EOS before we move current pointer. */
2251 ffewhere_line_kill (ffelex_current_wl_
);
2252 ffewhere_column_kill (ffelex_current_wc_
);
2253 ffelex_current_wl_
= ffewhere_line_new (ffelex_linecount_current_
);
2254 ffelex_current_wc_
= ffewhere_column_new (ffelex_card_length_
+ 1);
2257 /* We delay this for a combination of reasons. Mainly, it can start
2258 INCLUDE processing, and we want to delay that until the lexer's
2259 info on the line is coherent. And we want to delay that until we're
2260 sure there's a reason to make that info coherent, to avoid saving
2261 lots of useless lines. */
2263 if (finish_statement
)
2264 ffelex_finish_statement_ ();
2266 /* If label is present, enclose it in a NUMBER token and send it along. */
2268 if (first_label_char
!= FFEWHERE_columnUNKNOWN
)
2270 assert (ffelex_token_
->type
== FFELEX_typeNONE
);
2271 ffelex_token_
->type
= FFELEX_typeNUMBER
;
2272 ffelex_append_to_token_ ('\0'); /* Make room for label text. */
2273 strcpy (ffelex_token_
->text
, label_string
);
2274 ffelex_token_
->where_line
2275 = ffewhere_line_use (ffelex_current_wl_
);
2276 ffelex_token_
->where_col
= ffewhere_column_new (first_label_char
);
2277 ffelex_token_
->length
= labi
;
2278 ffelex_send_token_ ();
2279 ++ffelex_label_tokens_
;
2283 goto beginning_of_line
; /* :::::::::::::::::::: */
2285 /* Here is the main engine for parsing. c holds the character at column.
2286 It is already known that c is not a blank, end of line, or shriek,
2287 unless ffelex_raw_mode_ is not 0 (indicating we are in a
2288 character/hollerith constant). A partially filled token may already
2289 exist in ffelex_token_. One special case: if, when the end of the line
2290 is reached, continuation_line is FALSE and the only token on the line is
2291 END, then it is indeed the last statement. We don't look for
2292 continuation lines during this program unit in that case. This is
2293 according to ANSI. */
2295 if (ffelex_raw_mode_
!= 0)
2298 parse_raw_character
: /* :::::::::::::::::::: */
2302 ffewhereColumnNumber i
;
2304 if (ffelex_saw_tab_
|| (column
>= ffelex_final_nontab_column_
))
2305 goto beginning_of_line
; /* :::::::::::::::::::: */
2307 /* Pad out line with "virtual" spaces. */
2309 for (i
= column
; i
< ffelex_final_nontab_column_
; ++i
)
2310 ffelex_card_image_
[i
] = ' ';
2311 ffelex_card_image_
[i
] = '\0';
2312 ffelex_card_length_
= i
;
2316 switch (ffelex_raw_mode_
)
2319 c
= ffelex_backslash_ (c
, column
);
2323 if (!ffelex_backslash_reconsider_
)
2324 ffelex_append_to_token_ (c
);
2325 ffelex_raw_mode_
= -1;
2329 if (c
== ffelex_raw_char_
)
2331 ffelex_raw_mode_
= -1;
2332 ffelex_append_to_token_ (c
);
2336 ffelex_raw_mode_
= 0;
2337 ffelex_backslash_reconsider_
= TRUE
;
2342 if (c
== ffelex_raw_char_
)
2343 ffelex_raw_mode_
= -2;
2346 c
= ffelex_backslash_ (c
, column
);
2349 ffelex_raw_mode_
= -3;
2353 ffelex_append_to_token_ (c
);
2358 c
= ffelex_backslash_ (c
, column
);
2362 if (!ffelex_backslash_reconsider_
)
2364 ffelex_append_to_token_ (c
);
2370 if (ffelex_backslash_reconsider_
)
2371 ffelex_backslash_reconsider_
= FALSE
;
2373 c
= ffelex_card_image_
[++column
];
2375 if (ffelex_raw_mode_
== 0)
2377 ffelex_send_token_ ();
2378 assert (ffelex_raw_mode_
== 0);
2380 c
= ffelex_card_image_
[++column
];
2384 && (ffelex_card_image_
[column
+ 1] == '*')))
2385 goto beginning_of_line
; /* :::::::::::::::::::: */
2386 goto parse_nonraw_character
; /* :::::::::::::::::::: */
2388 goto parse_raw_character
; /* :::::::::::::::::::: */
2391 parse_nonraw_character
: /* :::::::::::::::::::: */
2393 switch (ffelex_token_
->type
)
2395 case FFELEX_typeNONE
:
2399 ffelex_token_
->type
= FFELEX_typeQUOTE
;
2400 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2401 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2402 ffelex_send_token_ ();
2406 ffelex_token_
->type
= FFELEX_typeDOLLAR
;
2407 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2408 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2409 ffelex_send_token_ ();
2413 ffelex_token_
->type
= FFELEX_typePERCENT
;
2414 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2415 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2416 ffelex_send_token_ ();
2420 ffelex_token_
->type
= FFELEX_typeAMPERSAND
;
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 ffelex_token_
->type
= FFELEX_typeAPOSTROPHE
;
2428 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2429 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2430 ffelex_send_token_ ();
2434 ffelex_token_
->type
= FFELEX_typeOPEN_PAREN
;
2435 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2436 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2440 ffelex_token_
->type
= FFELEX_typeCLOSE_PAREN
;
2441 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2442 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2443 ffelex_send_token_ ();
2447 ffelex_token_
->type
= FFELEX_typeASTERISK
;
2448 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2449 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2453 ffelex_token_
->type
= FFELEX_typePLUS
;
2454 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2455 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2456 ffelex_send_token_ ();
2460 ffelex_token_
->type
= FFELEX_typeCOMMA
;
2461 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2462 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2463 ffelex_send_token_ ();
2467 ffelex_token_
->type
= FFELEX_typeMINUS
;
2468 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2469 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2470 ffelex_send_token_ ();
2474 ffelex_token_
->type
= FFELEX_typePERIOD
;
2475 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2476 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2477 ffelex_send_token_ ();
2481 ffelex_token_
->type
= FFELEX_typeSLASH
;
2482 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2483 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2497 = ffelex_hexnum_
? FFELEX_typeNAME
: FFELEX_typeNUMBER
;
2498 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2499 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2500 ffelex_append_to_token_ (c
);
2504 ffelex_token_
->type
= FFELEX_typeCOLON
;
2505 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2506 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2510 ffelex_token_
->type
= FFELEX_typeSEMICOLON
;
2511 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2512 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2513 ffelex_permit_include_
= TRUE
;
2514 ffelex_send_token_ ();
2515 ffelex_permit_include_
= FALSE
;
2519 ffelex_token_
->type
= FFELEX_typeOPEN_ANGLE
;
2520 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2521 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2525 ffelex_token_
->type
= FFELEX_typeEQUALS
;
2526 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2527 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2531 ffelex_token_
->type
= FFELEX_typeCLOSE_ANGLE
;
2532 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2533 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2537 ffelex_token_
->type
= FFELEX_typeQUESTION
;
2538 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
2539 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2540 ffelex_send_token_ ();
2544 if (1 || ffe_is_90 ())
2546 ffelex_token_
->type
= FFELEX_typeUNDERSCORE
;
2547 ffelex_token_
->where_line
2548 = ffewhere_line_use (ffelex_current_wl_
);
2549 ffelex_token_
->where_col
2550 = ffewhere_column_new (column
+ 1);
2551 ffelex_send_token_ ();
2607 c
= ffesrc_char_source (c
);
2609 if (ffesrc_char_match_init (c
, 'H', 'h')
2610 && ffelex_expecting_hollerith_
!= 0)
2612 ffelex_raw_mode_
= ffelex_expecting_hollerith_
;
2613 ffelex_token_
->type
= FFELEX_typeHOLLERITH
;
2614 ffelex_token_
->where_line
= ffelex_raw_where_line_
;
2615 ffelex_token_
->where_col
= ffelex_raw_where_col_
;
2616 ffelex_raw_where_line_
= ffewhere_line_unknown ();
2617 ffelex_raw_where_col_
= ffewhere_column_unknown ();
2618 c
= ffelex_card_image_
[++column
];
2619 goto parse_raw_character
; /* :::::::::::::::::::: */
2624 ffelex_token_
->where_line
2625 = ffewhere_line_use (ffelex_token_
->currentnames_line
2626 = ffewhere_line_use (ffelex_current_wl_
));
2627 ffelex_token_
->where_col
2628 = ffewhere_column_use (ffelex_token_
->currentnames_col
2629 = ffewhere_column_new (column
+ 1));
2630 ffelex_token_
->type
= FFELEX_typeNAMES
;
2634 ffelex_token_
->where_line
2635 = ffewhere_line_use (ffelex_current_wl_
);
2636 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
2637 ffelex_token_
->type
= FFELEX_typeNAME
;
2639 ffelex_append_to_token_ (c
);
2643 ffelex_bad_1_ (FFEBAD_UNRECOGNIZED_CHARACTER
,
2644 ffelex_linecount_current_
, column
+ 1);
2645 ffelex_finish_statement_ ();
2646 disallow_continuation_line
= TRUE
;
2647 ignore_disallowed_continuation
= TRUE
;
2648 goto beginning_of_line_again
; /* :::::::::::::::::::: */
2652 case FFELEX_typeNAME
:
2707 c
= ffesrc_char_source (c
);
2722 && !ffe_is_dollar_ok ())
2724 ffelex_send_token_ ();
2725 goto parse_next_character
; /* :::::::::::::::::::: */
2727 ffelex_append_to_token_ (c
);
2731 ffelex_send_token_ ();
2732 goto parse_next_character
; /* :::::::::::::::::::: */
2736 case FFELEX_typeNAMES
:
2791 c
= ffesrc_char_source (c
);
2806 && !ffe_is_dollar_ok ())
2808 ffelex_send_token_ ();
2809 goto parse_next_character
; /* :::::::::::::::::::: */
2811 if (ffelex_token_
->length
< FFEWHERE_indexMAX
)
2813 ffewhere_track (&ffelex_token_
->currentnames_line
,
2814 &ffelex_token_
->currentnames_col
,
2815 ffelex_token_
->wheretrack
,
2816 ffelex_token_
->length
,
2817 ffelex_linecount_current_
,
2820 ffelex_append_to_token_ (c
);
2824 ffelex_send_token_ ();
2825 goto parse_next_character
; /* :::::::::::::::::::: */
2829 case FFELEX_typeNUMBER
:
2842 ffelex_append_to_token_ (c
);
2846 ffelex_send_token_ ();
2847 goto parse_next_character
; /* :::::::::::::::::::: */
2851 case FFELEX_typeASTERISK
:
2855 ffelex_token_
->type
= FFELEX_typePOWER
;
2856 ffelex_send_token_ ();
2859 default: /* * not followed by another *. */
2860 ffelex_send_token_ ();
2861 goto parse_next_character
; /* :::::::::::::::::::: */
2865 case FFELEX_typeCOLON
:
2869 ffelex_token_
->type
= FFELEX_typeCOLONCOLON
;
2870 ffelex_send_token_ ();
2873 default: /* : not followed by another :. */
2874 ffelex_send_token_ ();
2875 goto parse_next_character
; /* :::::::::::::::::::: */
2879 case FFELEX_typeSLASH
:
2883 ffelex_token_
->type
= FFELEX_typeCONCAT
;
2884 ffelex_send_token_ ();
2888 ffelex_token_
->type
= FFELEX_typeCLOSE_ARRAY
;
2889 ffelex_send_token_ ();
2893 ffelex_token_
->type
= FFELEX_typeREL_NE
;
2894 ffelex_send_token_ ();
2898 ffelex_send_token_ ();
2899 goto parse_next_character
; /* :::::::::::::::::::: */
2903 case FFELEX_typeOPEN_PAREN
:
2907 ffelex_token_
->type
= FFELEX_typeOPEN_ARRAY
;
2908 ffelex_send_token_ ();
2912 ffelex_send_token_ ();
2913 goto parse_next_character
; /* :::::::::::::::::::: */
2917 case FFELEX_typeOPEN_ANGLE
:
2921 ffelex_token_
->type
= FFELEX_typeREL_LE
;
2922 ffelex_send_token_ ();
2926 ffelex_send_token_ ();
2927 goto parse_next_character
; /* :::::::::::::::::::: */
2931 case FFELEX_typeEQUALS
:
2935 ffelex_token_
->type
= FFELEX_typeREL_EQ
;
2936 ffelex_send_token_ ();
2940 ffelex_token_
->type
= FFELEX_typePOINTS
;
2941 ffelex_send_token_ ();
2945 ffelex_send_token_ ();
2946 goto parse_next_character
; /* :::::::::::::::::::: */
2950 case FFELEX_typeCLOSE_ANGLE
:
2954 ffelex_token_
->type
= FFELEX_typeREL_GE
;
2955 ffelex_send_token_ ();
2959 ffelex_send_token_ ();
2960 goto parse_next_character
; /* :::::::::::::::::::: */
2965 assert ("Serious error!!" == NULL
);
2970 c
= ffelex_card_image_
[++column
];
2972 parse_next_character
: /* :::::::::::::::::::: */
2974 if (ffelex_raw_mode_
!= 0)
2975 goto parse_raw_character
; /* :::::::::::::::::::: */
2978 c
= ffelex_card_image_
[++column
];
2983 && (ffelex_card_image_
[column
+ 1] == '*')))
2985 if ((ffelex_number_of_tokens_
== ffelex_label_tokens_
)
2986 && (ffelex_token_
->type
== FFELEX_typeNAMES
)
2987 && (ffelex_token_
->length
== 3)
2988 && (ffesrc_strncmp_2c (ffe_case_match (),
2989 ffelex_token_
->text
,
2990 "END", "end", "End",
2994 ffelex_finish_statement_ ();
2995 disallow_continuation_line
= TRUE
;
2996 ignore_disallowed_continuation
= FALSE
;
2997 goto beginning_of_line_again
; /* :::::::::::::::::::: */
2999 goto beginning_of_line
; /* :::::::::::::::::::: */
3001 goto parse_nonraw_character
; /* :::::::::::::::::::: */
3004 /* ffelex_file_free -- Lex a given file in free source form
3008 ffelex_file_free(wf,f);
3010 Lexes the file according to Fortran 90 ANSI + VXT specifications. */
3013 ffelex_file_free (ffewhereFile wf
, FILE *f
)
3015 register int c
; /* Character currently under consideration. */
3016 register ffewhereColumnNumber column
; /* Not really; 0 means column 1... */
3017 bool continuation_line
;
3018 ffewhereColumnNumber continuation_column
;
3019 int latest_char_in_file
; /* For getting back into comment-skipping
3022 /* Lex is called for a particular file, not for a particular program unit.
3023 Yet the two events do share common characteristics. The first line in a
3024 file or in a program unit cannot be a continuation line. No token can
3025 be in mid-formation. No current label for the statement exists, since
3026 there is no current statement. */
3028 assert (ffelex_handler_
!= NULL
);
3030 #if FFECOM_targetCURRENT == FFECOM_targetGCC
3032 input_filename
= ffewhere_file_name (wf
);
3034 ffelex_current_wf_
= wf
;
3035 continuation_line
= FALSE
;
3036 ffelex_token_
->type
= FFELEX_typeNONE
;
3037 ffelex_number_of_tokens_
= 0;
3038 ffelex_current_wl_
= ffewhere_line_unknown ();
3039 ffelex_current_wc_
= ffewhere_column_unknown ();
3040 latest_char_in_file
= '\n';
3042 /* Come here to get a new line. */
3044 beginning_of_line
: /* :::::::::::::::::::: */
3046 c
= latest_char_in_file
;
3047 if ((c
== EOF
) || ((c
= ffelex_getc_ (f
)) == EOF
))
3050 end_of_file
: /* :::::::::::::::::::: */
3052 /* Line ending in EOF instead of \n still counts as a whole line. */
3054 ffelex_finish_statement_ ();
3055 ffewhere_line_kill (ffelex_current_wl_
);
3056 ffewhere_column_kill (ffelex_current_wc_
);
3057 return (ffelexHandler
) ffelex_handler_
;
3060 ffelex_next_line_ ();
3062 ffelex_bad_line_
= FALSE
;
3064 /* Skip over initial-comment and empty lines as quickly as possible! */
3072 #if FFECOM_targetCURRENT == FFECOM_targetGCC
3073 c
= ffelex_hash_ (f
);
3075 /* Don't skip over # line after all. */
3080 comment_line
: /* :::::::::::::::::::: */
3082 while ((c
!= '\n') && (c
!= EOF
))
3087 ffelex_next_line_ ();
3088 goto end_of_file
; /* :::::::::::::::::::: */
3093 ffelex_next_line_ ();
3096 goto end_of_file
; /* :::::::::::::::::::: */
3099 ffelex_saw_tab_
= FALSE
;
3101 column
= ffelex_image_char_ (c
, 0);
3103 /* Read the entire line in as is (with whitespace processing). */
3105 while (((c
= getc (f
)) != '\n') && (c
!= EOF
))
3106 column
= ffelex_image_char_ (c
, column
);
3108 if (ffelex_bad_line_
)
3110 ffelex_card_image_
[column
] = '\0';
3111 ffelex_card_length_
= column
;
3112 goto comment_line
; /* :::::::::::::::::::: */
3115 /* If no tab, cut off line after column 132. */
3117 if (!ffelex_saw_tab_
&& (column
> FFELEX_FREE_MAX_COLUMNS_
))
3118 column
= FFELEX_FREE_MAX_COLUMNS_
;
3120 ffelex_card_image_
[column
] = '\0';
3121 ffelex_card_length_
= column
;
3123 /* Save next char in file so we can use register-based c while analyzing
3124 line we just read. */
3126 latest_char_in_file
= c
; /* Should be either '\n' or EOF. */
3129 continuation_column
= 0;
3131 /* Skip over initial spaces to see if the first nonblank character
3132 is exclamation point, newline, or EOF (line is therefore a comment) or
3133 ampersand (line is therefore a continuation line). */
3135 while ((c
= ffelex_card_image_
[column
]) == ' ')
3142 goto beginning_of_line
; /* :::::::::::::::::::: */
3145 continuation_column
= column
+ 1;
3152 /* The line definitely has content of some kind, install new end-statement
3153 point for error messages. */
3155 ffewhere_line_kill (ffelex_current_wl_
);
3156 ffewhere_column_kill (ffelex_current_wc_
);
3157 ffelex_current_wl_
= ffewhere_line_new (ffelex_linecount_current_
);
3158 ffelex_current_wc_
= ffewhere_column_new (ffelex_card_length_
+ 1);
3160 /* Figure out which column to start parsing at. */
3162 if (continuation_line
)
3164 if (continuation_column
== 0)
3166 if (ffelex_raw_mode_
!= 0)
3168 ffelex_bad_1_ (FFEBAD_BAD_CHAR_CONTINUE
,
3169 ffelex_linecount_current_
, column
+ 1);
3171 else if (ffelex_token_
->type
!= FFELEX_typeNONE
)
3173 ffelex_bad_1_ (FFEBAD_BAD_LEXTOK_CONTINUE
,
3174 ffelex_linecount_current_
, column
+ 1);
3177 else if (ffelex_is_free_char_ctx_contin_ (continuation_column
))
3178 { /* Line contains only a single "&" as only
3179 nonblank character. */
3180 ffelex_bad_1_ (FFEBAD_BAD_FREE_CONTINUE
,
3181 ffelex_linecount_current_
, continuation_column
);
3182 goto beginning_of_line
; /* :::::::::::::::::::: */
3184 column
= continuation_column
;
3189 c
= ffelex_card_image_
[column
];
3190 continuation_line
= FALSE
;
3192 /* Here is the main engine for parsing. c holds the character at column.
3193 It is already known that c is not a blank, end of line, or shriek,
3194 unless ffelex_raw_mode_ is not 0 (indicating we are in a
3195 character/hollerith constant). A partially filled token may already
3196 exist in ffelex_token_. */
3198 if (ffelex_raw_mode_
!= 0)
3201 parse_raw_character
: /* :::::::::::::::::::: */
3206 if (ffelex_is_free_char_ctx_contin_ (column
+ 1))
3208 continuation_line
= TRUE
;
3209 goto beginning_of_line
; /* :::::::::::::::::::: */
3214 ffelex_finish_statement_ ();
3215 goto beginning_of_line
; /* :::::::::::::::::::: */
3221 switch (ffelex_raw_mode_
)
3224 c
= ffelex_backslash_ (c
, column
);
3228 if (!ffelex_backslash_reconsider_
)
3229 ffelex_append_to_token_ (c
);
3230 ffelex_raw_mode_
= -1;
3234 if (c
== ffelex_raw_char_
)
3236 ffelex_raw_mode_
= -1;
3237 ffelex_append_to_token_ (c
);
3241 ffelex_raw_mode_
= 0;
3242 ffelex_backslash_reconsider_
= TRUE
;
3247 if (c
== ffelex_raw_char_
)
3248 ffelex_raw_mode_
= -2;
3251 c
= ffelex_backslash_ (c
, column
);
3254 ffelex_raw_mode_
= -3;
3258 ffelex_append_to_token_ (c
);
3263 c
= ffelex_backslash_ (c
, column
);
3267 if (!ffelex_backslash_reconsider_
)
3269 ffelex_append_to_token_ (c
);
3275 if (ffelex_backslash_reconsider_
)
3276 ffelex_backslash_reconsider_
= FALSE
;
3278 c
= ffelex_card_image_
[++column
];
3280 if (ffelex_raw_mode_
== 0)
3282 ffelex_send_token_ ();
3283 assert (ffelex_raw_mode_
== 0);
3285 c
= ffelex_card_image_
[++column
];
3286 if ((c
== '\0') || (c
== '!'))
3288 ffelex_finish_statement_ ();
3289 goto beginning_of_line
; /* :::::::::::::::::::: */
3291 if ((c
== '&') && ffelex_is_free_nonc_ctx_contin_ (column
+ 1))
3293 continuation_line
= TRUE
;
3294 goto beginning_of_line
; /* :::::::::::::::::::: */
3296 goto parse_nonraw_character_noncontin
; /* :::::::::::::::::::: */
3298 goto parse_raw_character
; /* :::::::::::::::::::: */
3301 parse_nonraw_character
: /* :::::::::::::::::::: */
3303 if ((c
== '&') && ffelex_is_free_nonc_ctx_contin_ (column
+ 1))
3305 continuation_line
= TRUE
;
3306 goto beginning_of_line
; /* :::::::::::::::::::: */
3309 parse_nonraw_character_noncontin
: /* :::::::::::::::::::: */
3311 switch (ffelex_token_
->type
)
3313 case FFELEX_typeNONE
:
3316 finish-statement/continue-statement
3319 c
= ffelex_card_image_
[++column
];
3320 if ((c
== '\0') || (c
== '!'))
3322 ffelex_finish_statement_ ();
3323 goto beginning_of_line
; /* :::::::::::::::::::: */
3325 if ((c
== '&') && ffelex_is_free_nonc_ctx_contin_ (column
+ 1))
3327 continuation_line
= TRUE
;
3328 goto beginning_of_line
; /* :::::::::::::::::::: */
3335 ffelex_token_
->type
= FFELEX_typeQUOTE
;
3336 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3337 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3338 ffelex_send_token_ ();
3342 ffelex_token_
->type
= FFELEX_typeDOLLAR
;
3343 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3344 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3345 ffelex_send_token_ ();
3349 ffelex_token_
->type
= FFELEX_typePERCENT
;
3350 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3351 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3352 ffelex_send_token_ ();
3356 ffelex_token_
->type
= FFELEX_typeAMPERSAND
;
3357 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3358 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3359 ffelex_send_token_ ();
3363 ffelex_token_
->type
= FFELEX_typeAPOSTROPHE
;
3364 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3365 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3366 ffelex_send_token_ ();
3370 ffelex_token_
->type
= FFELEX_typeOPEN_PAREN
;
3371 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3372 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3376 ffelex_token_
->type
= FFELEX_typeCLOSE_PAREN
;
3377 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3378 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3379 ffelex_send_token_ ();
3383 ffelex_token_
->type
= FFELEX_typeASTERISK
;
3384 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3385 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3389 ffelex_token_
->type
= FFELEX_typePLUS
;
3390 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3391 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3392 ffelex_send_token_ ();
3396 ffelex_token_
->type
= FFELEX_typeCOMMA
;
3397 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3398 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3399 ffelex_send_token_ ();
3403 ffelex_token_
->type
= FFELEX_typeMINUS
;
3404 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3405 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3406 ffelex_send_token_ ();
3410 ffelex_token_
->type
= FFELEX_typePERIOD
;
3411 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3412 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3413 ffelex_send_token_ ();
3417 ffelex_token_
->type
= FFELEX_typeSLASH
;
3418 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3419 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3433 = ffelex_hexnum_
? FFELEX_typeNAME
: FFELEX_typeNUMBER
;
3434 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3435 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3436 ffelex_append_to_token_ (c
);
3440 ffelex_token_
->type
= FFELEX_typeCOLON
;
3441 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3442 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3446 ffelex_token_
->type
= FFELEX_typeSEMICOLON
;
3447 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3448 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3449 ffelex_permit_include_
= TRUE
;
3450 ffelex_send_token_ ();
3451 ffelex_permit_include_
= FALSE
;
3455 ffelex_token_
->type
= FFELEX_typeOPEN_ANGLE
;
3456 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3457 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3461 ffelex_token_
->type
= FFELEX_typeEQUALS
;
3462 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3463 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3467 ffelex_token_
->type
= FFELEX_typeCLOSE_ANGLE
;
3468 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3469 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3473 ffelex_token_
->type
= FFELEX_typeQUESTION
;
3474 ffelex_token_
->where_line
= ffewhere_line_use (ffelex_current_wl_
);
3475 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3476 ffelex_send_token_ ();
3480 if (1 || ffe_is_90 ())
3482 ffelex_token_
->type
= FFELEX_typeUNDERSCORE
;
3483 ffelex_token_
->where_line
3484 = ffewhere_line_use (ffelex_current_wl_
);
3485 ffelex_token_
->where_col
3486 = ffewhere_column_new (column
+ 1);
3487 ffelex_send_token_ ();
3543 c
= ffesrc_char_source (c
);
3545 if (ffesrc_char_match_init (c
, 'H', 'h')
3546 && ffelex_expecting_hollerith_
!= 0)
3548 ffelex_raw_mode_
= ffelex_expecting_hollerith_
;
3549 ffelex_token_
->type
= FFELEX_typeHOLLERITH
;
3550 ffelex_token_
->where_line
= ffelex_raw_where_line_
;
3551 ffelex_token_
->where_col
= ffelex_raw_where_col_
;
3552 ffelex_raw_where_line_
= ffewhere_line_unknown ();
3553 ffelex_raw_where_col_
= ffewhere_column_unknown ();
3554 c
= ffelex_card_image_
[++column
];
3555 goto parse_raw_character
; /* :::::::::::::::::::: */
3558 if (ffelex_names_pure_
)
3560 ffelex_token_
->where_line
3561 = ffewhere_line_use (ffelex_token_
->currentnames_line
3562 = ffewhere_line_use (ffelex_current_wl_
));
3563 ffelex_token_
->where_col
3564 = ffewhere_column_use (ffelex_token_
->currentnames_col
3565 = ffewhere_column_new (column
+ 1));
3566 ffelex_token_
->type
= FFELEX_typeNAMES
;
3570 ffelex_token_
->where_line
3571 = ffewhere_line_use (ffelex_current_wl_
);
3572 ffelex_token_
->where_col
= ffewhere_column_new (column
+ 1);
3573 ffelex_token_
->type
= FFELEX_typeNAME
;
3575 ffelex_append_to_token_ (c
);
3579 ffelex_bad_1_ (FFEBAD_UNRECOGNIZED_CHARACTER
,
3580 ffelex_linecount_current_
, column
+ 1);
3581 ffelex_finish_statement_ ();
3582 goto beginning_of_line
; /* :::::::::::::::::::: */
3586 case FFELEX_typeNAME
:
3641 c
= ffesrc_char_source (c
);
3656 && !ffe_is_dollar_ok ())
3658 ffelex_send_token_ ();
3659 goto parse_next_character
; /* :::::::::::::::::::: */
3661 ffelex_append_to_token_ (c
);
3665 ffelex_send_token_ ();
3666 goto parse_next_character
; /* :::::::::::::::::::: */
3670 case FFELEX_typeNAMES
:
3725 c
= ffesrc_char_source (c
);
3740 && !ffe_is_dollar_ok ())
3742 ffelex_send_token_ ();
3743 goto parse_next_character
; /* :::::::::::::::::::: */
3745 if (ffelex_token_
->length
< FFEWHERE_indexMAX
)
3747 ffewhere_track (&ffelex_token_
->currentnames_line
,
3748 &ffelex_token_
->currentnames_col
,
3749 ffelex_token_
->wheretrack
,
3750 ffelex_token_
->length
,
3751 ffelex_linecount_current_
,
3754 ffelex_append_to_token_ (c
);
3758 ffelex_send_token_ ();
3759 goto parse_next_character
; /* :::::::::::::::::::: */
3763 case FFELEX_typeNUMBER
:
3776 ffelex_append_to_token_ (c
);
3780 ffelex_send_token_ ();
3781 goto parse_next_character
; /* :::::::::::::::::::: */
3785 case FFELEX_typeASTERISK
:
3789 ffelex_token_
->type
= FFELEX_typePOWER
;
3790 ffelex_send_token_ ();
3793 default: /* * not followed by another *. */
3794 ffelex_send_token_ ();
3795 goto parse_next_character
; /* :::::::::::::::::::: */
3799 case FFELEX_typeCOLON
:
3803 ffelex_token_
->type
= FFELEX_typeCOLONCOLON
;
3804 ffelex_send_token_ ();
3807 default: /* : not followed by another :. */
3808 ffelex_send_token_ ();
3809 goto parse_next_character
; /* :::::::::::::::::::: */
3813 case FFELEX_typeSLASH
:
3817 ffelex_token_
->type
= FFELEX_typeCONCAT
;
3818 ffelex_send_token_ ();
3822 ffelex_token_
->type
= FFELEX_typeCLOSE_ARRAY
;
3823 ffelex_send_token_ ();
3827 ffelex_token_
->type
= FFELEX_typeREL_NE
;
3828 ffelex_send_token_ ();
3832 ffelex_send_token_ ();
3833 goto parse_next_character
; /* :::::::::::::::::::: */
3837 case FFELEX_typeOPEN_PAREN
:
3841 ffelex_token_
->type
= FFELEX_typeOPEN_ARRAY
;
3842 ffelex_send_token_ ();
3846 ffelex_send_token_ ();
3847 goto parse_next_character
; /* :::::::::::::::::::: */
3851 case FFELEX_typeOPEN_ANGLE
:
3855 ffelex_token_
->type
= FFELEX_typeREL_LE
;
3856 ffelex_send_token_ ();
3860 ffelex_send_token_ ();
3861 goto parse_next_character
; /* :::::::::::::::::::: */
3865 case FFELEX_typeEQUALS
:
3869 ffelex_token_
->type
= FFELEX_typeREL_EQ
;
3870 ffelex_send_token_ ();
3874 ffelex_token_
->type
= FFELEX_typePOINTS
;
3875 ffelex_send_token_ ();
3879 ffelex_send_token_ ();
3880 goto parse_next_character
; /* :::::::::::::::::::: */
3884 case FFELEX_typeCLOSE_ANGLE
:
3888 ffelex_token_
->type
= FFELEX_typeREL_GE
;
3889 ffelex_send_token_ ();
3893 ffelex_send_token_ ();
3894 goto parse_next_character
; /* :::::::::::::::::::: */
3899 assert ("Serious error!" == NULL
);
3904 c
= ffelex_card_image_
[++column
];
3906 parse_next_character
: /* :::::::::::::::::::: */
3908 if (ffelex_raw_mode_
!= 0)
3909 goto parse_raw_character
; /* :::::::::::::::::::: */
3911 if ((c
== '\0') || (c
== '!'))
3913 ffelex_finish_statement_ ();
3914 goto beginning_of_line
; /* :::::::::::::::::::: */
3916 goto parse_nonraw_character
; /* :::::::::::::::::::: */
3919 /* See the code in com.c that calls this to understand why. */
3921 #if FFECOM_targetCURRENT == FFECOM_targetGCC
3923 ffelex_hash_kludge (FILE *finput
)
3925 /* If you change this constant string, you have to change whatever
3926 code might thus be affected by it in terms of having to use
3927 ffelex_getc_() instead of getc() in the lexers and _hash_. */
3928 static char match
[] = "# 1 \"";
3929 static int kludge
[ARRAY_SIZE (match
) + 1];
3934 /* Read chars as long as they match the target string.
3935 Copy them into an array that will serve as a record
3936 of what we read (essentially a multi-char ungetc(),
3937 for code that uses ffelex_getc_ instead of getc() elsewhere
3939 for (p
= &match
[0], q
= &kludge
[0], c
= getc (finput
);
3940 (c
== *p
) && (*p
!= '\0') && (c
!= EOF
);
3941 ++p
, ++q
, c
= getc (finput
))
3944 *q
= c
; /* Might be EOF, which requires int. */
3947 ffelex_kludge_chars_
= &kludge
[0];
3951 ffelex_kludge_flag_
= TRUE
;
3952 ++ffelex_kludge_chars_
;
3953 ffelex_hash_ (finput
); /* Handle it NOW rather than later. */
3954 ffelex_kludge_flag_
= FALSE
;
3964 ffelex_final_nontab_column_
= ffe_fixed_line_length ();
3965 ffelex_card_size_
= FFELEX_columnINITIAL_SIZE_
;
3966 ffelex_card_image_
= malloc_new_ksr (malloc_pool_image (),
3967 "FFELEX card image",
3968 FFELEX_columnINITIAL_SIZE_
+ 9);
3969 ffelex_card_image_
[0] = '\0';
3971 for (i
= 0; i
< 256; ++i
)
3972 ffelex_first_char_
[i
] = FFELEX_typeERROR
;
3974 ffelex_first_char_
['\t'] = FFELEX_typeRAW
;
3975 ffelex_first_char_
['\n'] = FFELEX_typeCOMMENT
;
3976 ffelex_first_char_
['\v'] = FFELEX_typeCOMMENT
;
3977 ffelex_first_char_
['\f'] = FFELEX_typeCOMMENT
;
3978 ffelex_first_char_
['\r'] = FFELEX_typeRAW
;
3979 ffelex_first_char_
[' '] = FFELEX_typeRAW
;
3980 ffelex_first_char_
['!'] = FFELEX_typeCOMMENT
;
3981 ffelex_first_char_
['*'] = FFELEX_typeCOMMENT
;
3982 ffelex_first_char_
['/'] = FFELEX_typeSLASH
;
3983 ffelex_first_char_
['&'] = FFELEX_typeRAW
;
3984 ffelex_first_char_
['#'] = FFELEX_typeHASH
;
3986 for (i
= '0'; i
<= '9'; ++i
)
3987 ffelex_first_char_
[i
] = FFELEX_typeRAW
;
3989 if ((ffe_case_match () == FFE_caseNONE
)
3990 || ((ffe_case_match () == FFE_caseUPPER
)
3991 && (ffe_case_source () != FFE_caseLOWER
)) /* Idiot! :-) */
3992 || ((ffe_case_match () == FFE_caseLOWER
)
3993 && (ffe_case_source () == FFE_caseLOWER
)))
3995 ffelex_first_char_
['C'] = FFELEX_typeCOMMENT
;
3996 ffelex_first_char_
['D'] = FFELEX_typeCOMMENT
;
3998 if ((ffe_case_match () == FFE_caseNONE
)
3999 || ((ffe_case_match () == FFE_caseLOWER
)
4000 && (ffe_case_source () != FFE_caseUPPER
)) /* Idiot! :-) */
4001 || ((ffe_case_match () == FFE_caseUPPER
)
4002 && (ffe_case_source () == FFE_caseUPPER
)))
4004 ffelex_first_char_
['c'] = FFELEX_typeCOMMENT
;
4005 ffelex_first_char_
['d'] = FFELEX_typeCOMMENT
;
4008 ffelex_linecount_current_
= 0;
4009 ffelex_linecount_next_
= 1;
4010 ffelex_raw_mode_
= 0;
4011 ffelex_set_include_
= FALSE
;
4012 ffelex_permit_include_
= FALSE
;
4013 ffelex_names_
= TRUE
; /* First token in program is a names. */
4014 ffelex_names_pure_
= FALSE
; /* Free-form lexer does NAMES only for
4016 ffelex_hexnum_
= FALSE
;
4017 ffelex_expecting_hollerith_
= 0;
4018 ffelex_raw_where_line_
= ffewhere_line_unknown ();
4019 ffelex_raw_where_col_
= ffewhere_column_unknown ();
4021 ffelex_token_
= ffelex_token_new_ ();
4022 ffelex_token_
->type
= FFELEX_typeNONE
;
4023 ffelex_token_
->uses
= 1;
4024 ffelex_token_
->where_line
= ffewhere_line_unknown ();
4025 ffelex_token_
->where_col
= ffewhere_column_unknown ();
4026 ffelex_token_
->text
= NULL
;
4028 ffelex_handler_
= NULL
;
4031 /* ffelex_is_names_expected -- Is the current parser expecting NAMES vs. NAME?
4033 if (ffelex_is_names_expected())
4034 // Deliver NAMES token
4036 // Deliver NAME token
4038 Must be called while lexer is active, obviously. */
4041 ffelex_is_names_expected ()
4043 return ffelex_names_
;
4046 /* Current card image, which has the master linecount number
4047 ffelex_linecount_current_. */
4052 return ffelex_card_image_
;
4055 /* ffelex_line_length -- Return length of current lexer line
4057 printf("Length is %lu\n",ffelex_line_length());
4059 Must be called while lexer is active, obviously. */
4061 ffewhereColumnNumber
4062 ffelex_line_length ()
4064 return ffelex_card_length_
;
4067 /* Master line count of current card image, or 0 if no card image
4071 ffelex_line_number ()
4073 return ffelex_linecount_current_
;
4076 /* ffelex_set_expecting_hollerith -- Set hollerith expectation status
4078 ffelex_set_expecting_hollerith(0);
4080 Lex initially assumes no hollerith constant is about to show up. If
4081 syntactic analysis expects one, it should call this function with the
4082 number of characters expected in the constant immediately after recognizing
4083 the decimal number preceding the "H" and the constant itself. Then, if
4084 the next character is indeed H, the lexer will interpret it as beginning
4085 a hollerith constant and ship the token formed by reading the specified
4086 number of characters (interpreting blanks and otherwise-comments too)
4087 from the input file. It is up to syntactic analysis to call this routine
4088 again with 0 to turn hollerith detection off immediately upon receiving
4089 the token that might or might not be HOLLERITH.
4091 Also call this after seeing an APOSTROPHE or QUOTE token that begins a
4092 character constant. Pass the expected termination character (apostrophe
4095 Pass for length either the length of the hollerith (must be > 0), -1
4096 meaning expecting a character constant, or 0 to cancel expectation of
4097 a hollerith only after calling it with a length of > 0 and receiving the
4098 next token (which may or may not have been a HOLLERITH token).
4100 Pass for which either an apostrophe or quote when passing length of -1.
4101 Else which is a don't-care.
4103 Pass for line and column the line/column info for the token beginning the
4104 character or hollerith constant, for use in error messages, when passing
4105 a length of -1 -- this function will invoke ffewhere_line/column_use to
4106 make its own copies. Else line and column are don't-cares (when length
4107 is 0) and the outstanding copies of the previous line/column info, if
4108 still around, are killed.
4111 When called with length of 0, also zero ffelex_raw_mode_. This is
4112 so ffest_save_ can undo the effects of replaying tokens like
4113 APOSTROPHE and QUOTE.
4115 New line, column arguments allow error messages to point to the true
4116 beginning of a character/hollerith constant, rather than the beginning
4117 of the content part, which makes them more consistent and helpful.
4119 New "which" argument allows caller to specify termination character,
4120 which should be apostrophe or double-quote, to support Fortran 90. */
4123 ffelex_set_expecting_hollerith (long length
, char which
,
4124 ffewhereLine line
, ffewhereColumn column
)
4127 /* First kill the pending line/col info, if any (should only be pending
4128 when this call has length==0, the previous call had length>0, and a
4129 non-HOLLERITH token was sent in between the calls, but play it safe). */
4131 ffewhere_line_kill (ffelex_raw_where_line_
);
4132 ffewhere_column_kill (ffelex_raw_where_col_
);
4134 /* Now handle the length function. */
4138 ffelex_expecting_hollerith_
= 0;
4139 ffelex_raw_mode_
= 0;
4140 ffelex_raw_where_line_
= ffewhere_line_unknown ();
4141 ffelex_raw_where_col_
= ffewhere_column_unknown ();
4142 return; /* Don't set new line/column info from args. */
4145 ffelex_raw_mode_
= -1;
4146 ffelex_raw_char_
= which
;
4149 default: /* length > 0 */
4150 ffelex_expecting_hollerith_
= length
;
4154 /* Now set new line/column information from passed args. */
4156 ffelex_raw_where_line_
= ffewhere_line_use (line
);
4157 ffelex_raw_where_col_
= ffewhere_column_use (column
);
4160 /* ffelex_set_handler -- Set handler for tokens before calling _fixed or _free
4162 ffelex_set_handler((ffelexHandler) my_first_handler);
4164 Must be called before calling ffelex_file_fixed or ffelex_file_free or
4165 after they return, but not while they are active. */
4168 ffelex_set_handler (ffelexHandler first
)
4170 ffelex_handler_
= first
;
4173 /* ffelex_set_hexnum -- Set hexnum flag
4175 ffelex_set_hexnum(TRUE);
4177 Lex normally interprets a token starting with [0-9] as a NUMBER token,
4178 so if it sees a [A-Za-z] in it, it stops parsing the NUMBER and leaves
4179 the character as the first of the next token. But when parsing a
4180 hexadecimal number, by calling this function with TRUE before starting
4181 the parse of the token itself, lex will interpret [0-9] as the start
4185 ffelex_set_hexnum (bool f
)
4190 /* ffelex_set_include -- Set INCLUDE file to be processed next
4192 ffewhereFile wf; // The ffewhereFile object for the file.
4193 bool free_form; // TRUE means read free-form file, FALSE fixed-form.
4194 FILE *fi; // The file to INCLUDE.
4195 ffelex_set_include(wf,free_form,fi);
4197 Must be called only after receiving the EOS token following a valid
4198 INCLUDE statement specifying a file that has already been successfully
4202 ffelex_set_include (ffewhereFile wf
, bool free_form
, FILE *fi
)
4204 assert (ffelex_permit_include_
);
4205 assert (!ffelex_set_include_
);
4206 ffelex_set_include_
= TRUE
;
4207 ffelex_include_free_form_
= free_form
;
4208 ffelex_include_file_
= fi
;
4209 ffelex_include_wherefile_
= wf
;
4212 /* ffelex_set_names -- Set names/name flag, names = TRUE
4214 ffelex_set_names(FALSE);
4216 Lex initially assumes multiple names should be formed. If this function is
4217 called with FALSE, then single names are formed instead. The differences
4218 are a difference in the token type (FFELEX_typeNAMES vs. FFELEX_typeNAME)
4219 and in whether full source-location tracking is performed (it is for
4220 multiple names, not for single names), which is more expensive in terms of
4224 ffelex_set_names (bool f
)
4228 ffelex_names_pure_
= FALSE
;
4231 /* ffelex_set_names_pure -- Set names/name (pure) flag, names = TRUE
4233 ffelex_set_names_pure(FALSE);
4235 Like ffelex_set_names, except affects both lexers. Normally, the
4236 free-form lexer need not generate NAMES tokens because adjacent NAME
4237 tokens must be separated by spaces which causes the lexer to generate
4238 separate tokens for analysis (whereas in fixed-form the spaces are
4239 ignored resulting in one long token). But in FORMAT statements, for
4240 some reason, the Fortran 90 standard specifies that spaces can occur
4241 anywhere within a format-item-list with no effect on the format spec
4242 (except of course within character string edit descriptors), which means
4243 that "1PE14.2" and "1 P E 1 4 . 2" are equivalent. For the FORMAT
4244 statement handling, the existence of spaces makes it hard to deal with,
4245 because each token is seen distinctly (i.e. seven tokens in the latter
4246 example). But when no spaces are provided, as in the former example,
4247 then only four tokens are generated, NUMBER("1"), NAME("PE14"), PERIOD,
4248 NUMBER ("2"). By generating a NAMES instead of NAME, three things happen:
4249 One, ffest_kw_format_ does a substring rather than full-string match,
4250 and thus matches "PE14" to "PE"; two, ffelex_token_xyz_from_names functions
4251 may be used to pull NAME/NAMES and NUMBER tokens out of the NAMES token;
4252 and three, error reporting can point to the actual character rather than
4253 at or prior to it. The first two things could be resolved by providing
4254 alternate functions fairly easy, thus allowing FORMAT handling to expect
4255 both lexers to generate NAME tokens instead of NAMES (with otherwise minor
4256 changes to FORMAT parsing), but the third, error reporting, would suffer,
4257 and when one makes mistakes in a FORMAT, believe me, one wants a pointer
4258 to exactly where the compilers thinks the problem is, to even begin to get
4259 a handle on it. So there. */
4262 ffelex_set_names_pure (bool f
)
4264 ffelex_names_pure_
= f
;
4268 /* ffelex_splice_tokens -- Splice off and send tokens from a NAMES
4270 return (ffelexHandler) ffelex_splice_tokens(first_handler,master_token,
4273 Returns first_handler if start_char_index chars into master_token (which
4274 must be a NAMES token) is '\0'. Else, creates a subtoken from that
4275 char, either NUMBER (if it is a digit), a NAME (if a valid firstnamechar),
4276 an UNDERSCORE (if an underscore), or DOLLAR (if a dollar sign)
4277 and sends it to first_handler. If anything other than NAME is sent, the
4278 character at the end of it in the master token is examined to see if it
4279 begins a NAME, NUMBER, UNDERSCORE, or DOLLAR, and, if so,
4280 the handler returned by first_handler is invoked with that token, and
4281 this process is repeated until the end of the master token or a NAME
4282 token is reached. */
4285 ffelex_splice_tokens (ffelexHandler first
, ffelexToken master
,
4286 ffeTokenLength start
)
4292 p
= ffelex_token_text (master
) + (i
= start
);
4298 t
= ffelex_token_number_from_names (master
, i
);
4299 p
+= ffelex_token_length (t
);
4300 i
+= ffelex_token_length (t
);
4302 else if (ffesrc_is_name_init (*p
))
4304 t
= ffelex_token_name_from_names (master
, i
, 0);
4305 p
+= ffelex_token_length (t
);
4306 i
+= ffelex_token_length (t
);
4310 t
= ffelex_token_dollar_from_names (master
, i
);
4316 t
= ffelex_token_uscore_from_names (master
, i
);
4322 assert ("not a valid NAMES character" == NULL
);
4325 assert (first
!= NULL
);
4326 first
= (ffelexHandler
) (*first
) (t
);
4327 ffelex_token_kill (t
);
4333 /* ffelex_swallow_tokens -- Eat all tokens delivered to me
4335 return ffelex_swallow_tokens;
4337 Return this handler when you don't want to look at any more tokens in the
4338 statement because you've encountered an unrecoverable error in the
4342 ffelex_swallow_tokens (ffelexToken t
, ffelexHandler handler
)
4344 assert (handler
!= NULL
);
4346 if ((t
!= NULL
) && ((ffelex_token_type (t
) == FFELEX_typeEOS
)
4347 || (ffelex_token_type (t
) == FFELEX_typeSEMICOLON
)))
4348 return (ffelexHandler
) (*handler
) (t
);
4350 ffelex_eos_handler_
= handler
;
4351 return (ffelexHandler
) ffelex_swallow_tokens_
;
4354 /* ffelex_token_dollar_from_names -- Return a dollar from within a names token
4357 t = ffelex_token_dollar_from_names(t,6);
4359 It's as if you made a new token of dollar type having the dollar
4360 at, in the example above, the sixth character of the NAMES token. */
4363 ffelex_token_dollar_from_names (ffelexToken t
, ffeTokenLength start
)
4368 assert (ffelex_token_type (t
) == FFELEX_typeNAMES
);
4369 assert (start
< t
->length
);
4370 assert (t
->text
[start
] == '$');
4372 /* Now make the token. */
4374 nt
= ffelex_token_new_ ();
4375 nt
->type
= FFELEX_typeDOLLAR
;
4378 ffewhere_set_from_track (&nt
->where_line
, &nt
->where_col
, t
->where_line
,
4379 t
->where_col
, t
->wheretrack
, start
);
4384 /* ffelex_token_kill -- Decrement use count for token, kill if no uses left
4387 ffelex_token_kill(t);
4389 Complements a call to ffelex_token_use or ffelex_token_new_.... */
4392 ffelex_token_kill (ffelexToken t
)
4396 assert (t
->uses
> 0);
4401 --ffelex_total_tokens_
;
4403 if (t
->type
== FFELEX_typeNAMES
)
4404 ffewhere_track_kill (t
->where_line
, t
->where_col
,
4405 t
->wheretrack
, t
->length
);
4406 ffewhere_line_kill (t
->where_line
);
4407 ffewhere_column_kill (t
->where_col
);
4408 if (t
->text
!= NULL
)
4409 malloc_kill_ksr (malloc_pool_image (), t
->text
, t
->size
+ 1);
4410 malloc_kill_ks (malloc_pool_image (), t
, sizeof (*t
));
4413 /* Make a new NAME token that is a substring of a NAMES token. */
4416 ffelex_token_name_from_names (ffelexToken t
, ffeTokenLength start
,
4422 assert (ffelex_token_type (t
) == FFELEX_typeNAMES
);
4423 assert (start
< t
->length
);
4425 len
= t
->length
- start
;
4429 assert ((start
+ len
) <= t
->length
);
4431 assert (ffelex_is_firstnamechar (t
->text
[start
]));
4433 nt
= ffelex_token_new_ ();
4434 nt
->type
= FFELEX_typeNAME
;
4435 nt
->size
= len
; /* Assume nobody's gonna fiddle with token
4439 ffewhere_set_from_track (&nt
->where_line
, &nt
->where_col
, t
->where_line
,
4440 t
->where_col
, t
->wheretrack
, start
);
4441 nt
->text
= malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4443 strncpy (nt
->text
, t
->text
+ start
, len
);
4444 nt
->text
[len
] = '\0';
4448 /* Make a new NAMES token that is a substring of another NAMES token. */
4451 ffelex_token_names_from_names (ffelexToken t
, ffeTokenLength start
,
4457 assert (ffelex_token_type (t
) == FFELEX_typeNAMES
);
4458 assert (start
< t
->length
);
4460 len
= t
->length
- start
;
4464 assert ((start
+ len
) <= t
->length
);
4466 assert (ffelex_is_firstnamechar (t
->text
[start
]));
4468 nt
= ffelex_token_new_ ();
4469 nt
->type
= FFELEX_typeNAMES
;
4470 nt
->size
= len
; /* Assume nobody's gonna fiddle with token
4474 ffewhere_set_from_track (&nt
->where_line
, &nt
->where_col
, t
->where_line
,
4475 t
->where_col
, t
->wheretrack
, start
);
4476 ffewhere_track_copy (nt
->wheretrack
, t
->wheretrack
, start
, len
);
4477 nt
->text
= malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4479 strncpy (nt
->text
, t
->text
+ start
, len
);
4480 nt
->text
[len
] = '\0';
4484 /* Make a new CHARACTER token. */
4487 ffelex_token_new_character (char *s
, ffewhereLine l
, ffewhereColumn c
)
4491 t
= ffelex_token_new_ ();
4492 t
->type
= FFELEX_typeCHARACTER
;
4493 t
->length
= t
->size
= strlen (s
); /* Assume it won't get bigger. */
4495 t
->text
= malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4497 strcpy (t
->text
, s
);
4498 t
->where_line
= ffewhere_line_use (l
);
4499 t
->where_col
= ffewhere_column_new (c
);
4503 /* Make a new EOF token right after end of file. */
4506 ffelex_token_new_eof ()
4510 t
= ffelex_token_new_ ();
4511 t
->type
= FFELEX_typeEOF
;
4514 t
->where_line
= ffewhere_line_new (ffelex_linecount_current_
);
4515 t
->where_col
= ffewhere_column_new (1);
4519 /* Make a new NAME token. */
4522 ffelex_token_new_name (char *s
, ffewhereLine l
, ffewhereColumn c
)
4526 assert (ffelex_is_firstnamechar (*s
));
4528 t
= ffelex_token_new_ ();
4529 t
->type
= FFELEX_typeNAME
;
4530 t
->length
= t
->size
= strlen (s
); /* Assume it won't get bigger. */
4532 t
->text
= malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4534 strcpy (t
->text
, s
);
4535 t
->where_line
= ffewhere_line_use (l
);
4536 t
->where_col
= ffewhere_column_new (c
);
4540 /* Make a new NAMES token. */
4543 ffelex_token_new_names (char *s
, ffewhereLine l
, ffewhereColumn c
)
4547 assert (ffelex_is_firstnamechar (*s
));
4549 t
= ffelex_token_new_ ();
4550 t
->type
= FFELEX_typeNAMES
;
4551 t
->length
= t
->size
= strlen (s
); /* Assume it won't get bigger. */
4553 t
->text
= malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4555 strcpy (t
->text
, s
);
4556 t
->where_line
= ffewhere_line_use (l
);
4557 t
->where_col
= ffewhere_column_new (c
);
4558 ffewhere_track_clear (t
->wheretrack
, t
->length
); /* Assume contiguous
4563 /* Make a new NUMBER token.
4565 The first character of the string must be a digit, and only the digits
4566 are copied into the new number. So this may be used to easily extract
4567 a NUMBER token from within any text string. Then the length of the
4568 resulting token may be used to calculate where the digits stopped
4569 in the original string. */
4572 ffelex_token_new_number (char *s
, ffewhereLine l
, ffewhereColumn c
)
4577 /* How long is the string of decimal digits at s? */
4579 len
= strspn (s
, "0123456789");
4581 /* Make sure there is at least one digit. */
4585 /* Now make the token. */
4587 t
= ffelex_token_new_ ();
4588 t
->type
= FFELEX_typeNUMBER
;
4589 t
->length
= t
->size
= len
; /* Assume it won't get bigger. */
4591 t
->text
= malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4593 strncpy (t
->text
, s
, len
);
4594 t
->text
[len
] = '\0';
4595 t
->where_line
= ffewhere_line_use (l
);
4596 t
->where_col
= ffewhere_column_new (c
);
4600 /* Make a new token of any type that doesn't contain text. A private
4601 function that is used by public macros in the interface file. */
4604 ffelex_token_new_simple_ (ffelexType type
, ffewhereLine l
, ffewhereColumn c
)
4608 t
= ffelex_token_new_ ();
4612 t
->where_line
= ffewhere_line_use (l
);
4613 t
->where_col
= ffewhere_column_new (c
);
4617 /* Make a new NUMBER token from an existing NAMES token.
4619 Like ffelex_token_new_number, this function calculates the length
4620 of the digit string itself. */
4623 ffelex_token_number_from_names (ffelexToken t
, ffeTokenLength start
)
4629 assert (ffelex_token_type (t
) == FFELEX_typeNAMES
);
4630 assert (start
< t
->length
);
4632 /* How long is the string of decimal digits at s? */
4634 len
= strspn (t
->text
+ start
, "0123456789");
4636 /* Make sure there is at least one digit. */
4640 /* Now make the token. */
4642 nt
= ffelex_token_new_ ();
4643 nt
->type
= FFELEX_typeNUMBER
;
4644 nt
->size
= len
; /* Assume nobody's gonna fiddle with token
4648 ffewhere_set_from_track (&nt
->where_line
, &nt
->where_col
, t
->where_line
,
4649 t
->where_col
, t
->wheretrack
, start
);
4650 nt
->text
= malloc_new_ksr (malloc_pool_image (), "FFELEX token text",
4652 strncpy (nt
->text
, t
->text
+ start
, len
);
4653 nt
->text
[len
] = '\0';
4657 /* Make a new UNDERSCORE token from a NAMES token. */
4660 ffelex_token_uscore_from_names (ffelexToken t
, ffeTokenLength start
)
4665 assert (ffelex_token_type (t
) == FFELEX_typeNAMES
);
4666 assert (start
< t
->length
);
4667 assert (t
->text
[start
] == '_');
4669 /* Now make the token. */
4671 nt
= ffelex_token_new_ ();
4672 nt
->type
= FFELEX_typeUNDERSCORE
;
4674 ffewhere_set_from_track (&nt
->where_line
, &nt
->where_col
, t
->where_line
,
4675 t
->where_col
, t
->wheretrack
, start
);
4680 /* ffelex_token_use -- Return another instance of a token
4683 t = ffelex_token_use(t);
4685 In a sense, the new token is a copy of the old, though it might be the
4686 same with just a new use count.
4688 We use the use count method (easy). */
4691 ffelex_token_use (ffelexToken t
)
4694 assert ("_token_use: null token" == NULL
);