diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-16 00:48:37 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-16 00:48:37 +0000 |
commit | de3bbbc0981bde7a02f7f5398ce921e0beb4c174 (patch) | |
tree | 88813af01d0d16a19a205f4bd0f07fcc555d5a81 /lexer.c | |
parent | f02e90b27e37f91d4409842dd21cd00c999c805d (diff) |
Implement floats
Diffstat (limited to 'lexer.c')
-rw-r--r-- | lexer.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -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]; |