]>
gcc.gnu.org Git - gcc.git/blob - gcc/bi-lexer.c
1 /* Lexer for scanner of bytecode definition file.
2 Copyright (C) 1993, 1995 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include "bi-parser.h"
26 /* Safely allocate NBYTES bytes of memory. Returns pointer to block of
33 char *tmp
= (char *) malloc (nbytes
);
37 fprintf (stderr
, "can't allocate %d bytes (out of virtual memory)\n", nbytes
);
38 exit (FATAL_EXIT_CODE
);
45 /* Safely reallocate BLOCK so its size becomes NBYTES.
46 The block returned may be different from the one supplied. */
49 xrealloc (block
, nbytes
)
54 ? (char *) realloc (block
, nbytes
)
55 : (char *) malloc (nbytes
));
59 fprintf (stderr
, "can't reallocate %d bytes (out of virtual memory)\n", nbytes
);
60 exit (FATAL_EXIT_CODE
);
67 /* Scan for string token on standard input. A string is, for our
68 purposes here, a sequence of characters that starts with the regexp
69 ``[^ #\t\n(),]'' and is then followed by the regexp ``[^#(),]*''. Any
70 character is accepted if preceded by a backslash, "\\". It is assumed
71 that the first character has already been checked by the main loop. */
81 while ((c
= getc (stdin
)) != EOF
82 && c
!= '#' && c
!= '(' && c
!= ')' && c
!= ',')
84 /* Extend buffer, if necessary (minus two so there's room for the NUL
85 trailer as well as another character if this one is a backslash). */
86 if (!buffer_size
|| (point
- buffer
>= buffer_size
-2))
88 int previous_point_index
= point
- buffer
;
90 buffer_size
= (!buffer_size
? 32 : buffer_size
* 2);
92 buffer
= xmalloc (buffer_size
);
94 buffer
= xrealloc (buffer
, buffer_size
);
96 point
= buffer
+ previous_point_index
;
104 /* Catch special case: backslash at end of file */
127 /* First char determines what token we're looking at */
140 /* Ignore whitespace */
144 /* Comments advance to next line */
145 while ((c
= getc (stdin
)) != '\n' && c
!= EOF
);
149 if (c
!= '(' && c
!= ')' && c
!= '\\' && c
!= ',')
152 yylval
.string
= scan_string ();
154 /* Check if string is "define_operator"; if so, return
155 a DEFOP token instead. */
156 if (!strcmp (yylval
.string
, "define_operator"))
158 free (yylval
.string
);
This page took 0.041273 seconds and 5 git commands to generate.