2 // This file contains a slimmed down version of read_complex().
3 // It does not pull in all the complex function code.
9 #include "cl_real_io.h"
15 #include "cl_spushstring.h"
18 // We read an entire token (or even more, if it begins with #C) into a
19 // buffer and then call read_real() on the buffer.
21 class pushstring_hack : public cl_spushstring {
23 char* start_pointer (void) { return buffer; }
24 char* end_pointer (void) { return buffer+index; }
27 static cl_boolean number_char_p (char c)
29 if ((c >= '0') && (c <= '9'))
31 if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))
34 case '+': case '-': case '.': case '_': case '/':
41 const cl_R read_real (cl_istream stream, const cl_read_flags& flags)
43 // One pre-allocated buffer. This reduces the allocation/free cost.
44 static pushstring_hack buffer;
47 // Skip whitespace at the beginning.
49 c = freadchar(stream);
50 if (c == cl_EOF) goto eof;
51 if ((c == ' ') || (c == '\t') || (c == '\n'))
56 // Found first non-whitespace character.
57 // Numbers cannot cross lines. We can treat EOF and '\n' the same way.
60 if (!(flags.lsyntax & lsyntax_commonlisp))
63 // Read some digits, then a letter, then a token.
65 c = freadchar(stream);
66 if (c == cl_EOF) goto eof;
68 if ((c >= '0') && (c <= '9'))
73 if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
76 c = freadchar(stream);
77 if (c == cl_EOF) goto eof;
79 // Read a number token.
80 if (!number_char_p(c))
84 c = freadchar(stream);
87 if (!number_char_p(c)) {
88 funreadchar(stream,c);
93 return read_real(flags,
94 buffer.start_pointer(), buffer.end_pointer(),
98 // Handle syntax error.
99 syntax1: buffer.push(c);
100 read_number_bad_syntax(buffer.start_pointer(),buffer.end_pointer());
102 // Handle premature EOF.
103 eof: read_number_eof();