supports hex digits now

This commit is contained in:
cozis
2022-05-05 21:58:38 +02:00
parent f2f2db423f
commit 38e8ce9216
+11
View File
@@ -185,16 +185,27 @@ static Token *tokenize(const char *str, long len)
T.len = i - T.off; T.len = i - T.off;
} else if(isdigit(str[i])) { } else if(isdigit(str[i])) {
T.off = i; T.off = i;
// We allow an 'x' if it's after a '0'.
if(i+2 < len && str[i] == '0' && str[i+1] == 'x' && isdigit(str[i+2]))
i += 2; // Skip the '0x'.
while(i < len && isdigit(str[i])) while(i < len && isdigit(str[i]))
i += 1; i += 1;
// If the next character is a dot followed
// by a digit, then we continue to scan.
if(i+1 < len && str[i] == '.' && isdigit(str[i+1])) { if(i+1 < len && str[i] == '.' && isdigit(str[i+1])) {
i += 1; // Skip the '.'. i += 1; // Skip the '.'.
while(i < len && isdigit(str[i])) while(i < len && isdigit(str[i]))
i += 1; i += 1;
T.kind = T_VFLT; T.kind = T_VFLT;
} else T.kind = T_VINT; } else T.kind = T_VINT;
T.len = i - T.off; T.len = i - T.off;
} else if(isalpha(str[i]) || str[i] == '_') { } else if(isalpha(str[i]) || str[i] == '_') {
T.off = i; T.off = i;