summaryrefslogtreecommitdiff
path: root/nasmlib.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-10-19 13:10:46 -0700
committerH. Peter Anvin <hpa@zytor.com>2007-10-19 13:10:46 -0700
commit2ef4aac272ff0d2ac0bf630f11e6d8d3e19b27d5 (patch)
tree1fb0b1e1b0116950ba3836ea9a4fda9edba1f939 /nasmlib.c
parenta8eace2b79b1068e54c4af93c41b6e58ba879b83 (diff)
downloadnasm-2ef4aac272ff0d2ac0bf630f11e6d8d3e19b27d5.tar.gz
nasm-2ef4aac272ff0d2ac0bf630f11e6d8d3e19b27d5.tar.bz2
nasm-2ef4aac272ff0d2ac0bf630f11e6d8d3e19b27d5.zip
Allow underscores in numbers; better detection of FP
- Allow underscores as group separators in numbers, for example: 0x1234_5678 is now a legal number. The underscore is just ignored, it adds no meaning. - Recognize dotless floating-point numbers, such as "1e30". This entails distinguishing hexadecimal numbers in the scanner, since e.g. 0x1e30 is a perfectly legitimate hex constant.
Diffstat (limited to 'nasmlib.c')
-rw-r--r--nasmlib.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/nasmlib.c b/nasmlib.c
index 1951cff..7f7fdef 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -193,7 +193,7 @@ char *nasm_strsep(char **stringp, const char *delim)
#endif
-#define lib_isnumchar(c) ( isalnum(c) || (c) == '$')
+#define lib_isnumchar(c) (isalnum(c) || (c) == '$' || (c) == '_')
#define numvalue(c) ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
int64_t readnum(char *str, bool *error)
@@ -274,16 +274,19 @@ int64_t readnum(char *str, bool *error)
result = 0;
while (*r && r < q) {
- if (*r < '0' || (*r > '9' && *r < 'A')
- || (digit = numvalue(*r)) >= radix) {
- *error = true;
- return 0;
- }
- if (result > checklimit || (result == checklimit && digit >= last)) {
- warn = true;
- }
-
- result = radix * result + digit;
+ if (*r != '_') {
+ if (*r < '0' || (*r > '9' && *r < 'A')
+ || (digit = numvalue(*r)) >= radix) {
+ *error = true;
+ return 0;
+ }
+ if (result > checklimit ||
+ (result == checklimit && digit >= last)) {
+ warn = true;
+ }
+
+ result = radix * result + digit;
+ }
r++;
}