summaryrefslogtreecommitdiff
path: root/stdscan.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 /stdscan.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 'stdscan.c')
-rw-r--r--stdscan.c60
1 files changed, 35 insertions, 25 deletions
diff --git a/stdscan.c b/stdscan.c
index e06fb84..3979144 100644
--- a/stdscan.c
+++ b/stdscan.c
@@ -116,34 +116,44 @@ int stdscan(void *private_data, struct tokenval *tv)
return tv->t_type = TOKEN_HERE;
} else if (isnumstart(*stdscan_bufptr)) { /* now we've got a number */
bool rn_error;
+ bool is_hex = false;
+ bool is_float = false;
+ char c;
r = stdscan_bufptr++;
- while (isnumchar(*stdscan_bufptr))
- stdscan_bufptr++;
- if (*stdscan_bufptr == '.') {
- /*
- * a floating point constant
- */
- stdscan_bufptr++;
- while (isnumchar(*stdscan_bufptr) ||
- ((stdscan_bufptr[-1] == 'e'
- || stdscan_bufptr[-1] == 'E'
- || stdscan_bufptr[-1] == 'p'
- || stdscan_bufptr[-1] == 'P')
- && (*stdscan_bufptr == '-' || *stdscan_bufptr == '+'))) {
- stdscan_bufptr++;
- }
- tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r);
- return tv->t_type = TOKEN_FLOAT;
- }
- r = stdscan_copy(r, stdscan_bufptr - r);
- tv->t_integer = readnum(r, &rn_error);
- stdscan_pop();
- if (rn_error)
- return tv->t_type = TOKEN_ERRNUM; /* some malformation occurred */
- tv->t_charptr = NULL;
- return tv->t_type = TOKEN_NUM;
+ if (r[0] == '$' || (r[0] == '0' || (r[1] == 'x' || r[1] == 'X')))
+ is_hex = true;
+
+ for (;;) {
+ c = *stdscan_bufptr++;
+
+ if ((!is_hex && (c == 'e' || c == 'E')) ||
+ (c == 'P' || c == 'p')) {
+ is_float = true;
+ if (*stdscan_bufptr == '+' || *stdscan_bufptr == '-')
+ stdscan_bufptr++;
+ } else if (isnumchar(c) || c == '_')
+ ; /* just advance */
+ else if (c == '.')
+ is_float = true;
+ else
+ break;
+ }
+ stdscan_bufptr--; /* Point to first character beyond number */
+
+ if (is_float) {
+ tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r);
+ return tv->t_type = TOKEN_FLOAT;
+ } else {
+ r = stdscan_copy(r, stdscan_bufptr - r);
+ tv->t_integer = readnum(r, &rn_error);
+ stdscan_pop();
+ if (rn_error)
+ return tv->t_type = TOKEN_ERRNUM; /* some malformation occurred */
+ tv->t_charptr = NULL;
+ return tv->t_type = TOKEN_NUM;
+ }
} else if (*stdscan_bufptr == '\'' || *stdscan_bufptr == '"') { /* a char constant */
char quote = *stdscan_bufptr++, *r;
bool rn_warn;