fix float parsing

This commit is contained in:
Peter McGoron 2024-06-21 22:53:50 -04:00
parent 413b9614d2
commit 0647b65712
1 changed files with 9 additions and 6 deletions

15
main.c
View File

@ -156,11 +156,11 @@ static void tok_num(FILE *input, struct token *tok, int c)
uns_string_alloc(&gc, &tok->dat, 32); uns_string_alloc(&gc, &tok->dat, 32);
do { do {
if (c == '.' || c == 'e' || c == 'E') if (c == '.' || c == 'e' || c == 'E' || c == '-' || c == '+')
is_float = 1; is_float = 1;
uns_string_append_char(&gc, &tok->dat, c); uns_string_append_char(&gc, &tok->dat, c);
c = getc(input); c = getc(input);
} while (tonum(c) >= 0); } while (tonum(c) >= 0 || c == '.' || c == 'e' || c == 'E' || c == '-' || c == '+');
ungetc(c, input); ungetc(c, input);
if (is_float) { if (is_float) {
@ -242,10 +242,12 @@ static void tokenize(FILE *input, struct token *tok)
if (c == '.') { if (c == '.') {
c2 = getc(input); c2 = getc(input);
/* Flatrate does not have floating point. */ /* Flatrate does not have floating point. */
if (part_of_ident(c2)) { if (tonum(c2) >= 0) {
tok_ident(input, tok, c); ungetc(c2, input);
} else if (tonum(c2) >= 0) {
tok_num(input, tok, c); tok_num(input, tok, c);
} else if (part_of_ident(c2)) {
ungetc(c2, input);
tok_ident(input, tok, c);
} else { } else {
tok->typ = T_DOT; tok->typ = T_DOT;
} }
@ -281,6 +283,7 @@ static void alloc_of_type(struct uns_ctr *ctr, int typ)
case INTEGER: fields = 1; break; case INTEGER: fields = 1; break;
case STRING: fields = 1; break; case STRING: fields = 1; break;
case SYMBOL: fields = 1; break; case SYMBOL: fields = 1; break;
case FLOAT: fields = 1; break;
case EMPTY_LIST: fields = 0; break; case EMPTY_LIST: fields = 0; break;
case LISP_NULL: fields = 0; break; case LISP_NULL: fields = 0; break;
} }
@ -554,7 +557,7 @@ static void display(struct uns_ctr *ctr)
printf("%ld ", l); printf("%ld ", l);
return; return;
case FLOAT: case FLOAT:
memcpy(&f, gc.record_get_ptr(ctr->p, 1), sizeof(float)); memcpy(&f, gc.record_get_ptr(ctr->p, 1), sizeof(double));
printf("%f ", f); printf("%f ", f);
return; return;
case STRING: case STRING: