aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2024-06-21 22:53:50 -0400
committerGravatar Peter McGoron 2024-06-21 22:53:50 -0400
commit0647b65712e7aaf1de050393ea18194194088c68 (patch)
treebd3f27ed3b767ec69bf0820665368092607fb6e5
parentimproper lists, floats (diff)
fix float parsing
-rw-r--r--main.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/main.c b/main.c
index 6ba589f..d817e15 100644
--- a/main.c
+++ b/main.c
@@ -156,11 +156,11 @@ static void tok_num(FILE *input, struct token *tok, int c)
uns_string_alloc(&gc, &tok->dat, 32);
do {
- if (c == '.' || c == 'e' || c == 'E')
+ if (c == '.' || c == 'e' || c == 'E' || c == '-' || c == '+')
is_float = 1;
uns_string_append_char(&gc, &tok->dat, c);
c = getc(input);
- } while (tonum(c) >= 0);
+ } while (tonum(c) >= 0 || c == '.' || c == 'e' || c == 'E' || c == '-' || c == '+');
ungetc(c, input);
if (is_float) {
@@ -242,10 +242,12 @@ static void tokenize(FILE *input, struct token *tok)
if (c == '.') {
c2 = getc(input);
/* Flatrate does not have floating point. */
- if (part_of_ident(c2)) {
- tok_ident(input, tok, c);
- } else if (tonum(c2) >= 0) {
+ if (tonum(c2) >= 0) {
+ ungetc(c2, input);
tok_num(input, tok, c);
+ } else if (part_of_ident(c2)) {
+ ungetc(c2, input);
+ tok_ident(input, tok, c);
} else {
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 STRING: fields = 1; break;
case SYMBOL: fields = 1; break;
+ case FLOAT: fields = 1; break;
case EMPTY_LIST: fields = 0; break;
case LISP_NULL: fields = 0; break;
}
@@ -554,7 +557,7 @@ static void display(struct uns_ctr *ctr)
printf("%ld ", l);
return;
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);
return;
case STRING: