From de3bbbc0981bde7a02f7f5398ce921e0beb4c174 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Sun, 16 Jan 2022 00:48:37 +0000 Subject: Implement floats --- lexer.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lexer.c') diff --git a/lexer.c b/lexer.c index d72cdd7..5318924 100644 --- a/lexer.c +++ b/lexer.c @@ -88,13 +88,18 @@ lexline(Rune *line) }else if(isdigitrune(line[offset])){ char buf[64]; char *p = buf; - while(isdigitrune(line[offset])){ - p += runetochar(p, &line[offset]); - offset++; + int floating = 0; +get_digits: + while(isdigitrune(line[offset])) + p += runetochar(p, &line[offset++]); + if(!floating && line[offset] == '.'){ + p += runetochar(p, &line[offset++]); + floating = 1; + goto get_digits; } *p = 0; stmt->toks[stmt->ntoks].tag = ArrayTag; - stmt->toks[stmt->ntoks].array = mkscalarint(atoll(buf)); + stmt->toks[stmt->ntoks].array = floating ? mkscalarfloat(atof(buf)) : mkscalarint(atoll(buf)); }else if(runestrchr(L"⍺⍵", line[offset])){ Rune *name = L"?"; name[0] = line[offset]; -- cgit v1.2.3