diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-01 02:25:49 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-01 02:25:49 -0400 |
commit | e2503def53445f74d37fcbc5d67b956bd795092f (patch) | |
tree | dcee8336db27796afef480d78f6d60896152d022 /src/sys/np/core/np_lex.c | |
parent | de12f97c8d41898255c7d9eed2c24b3c567b5747 (diff) |
np: lex: Handle digits in the stream
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys/np/core/np_lex.c')
-rw-r--r-- | src/sys/np/core/np_lex.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/sys/np/core/np_lex.c b/src/sys/np/core/np_lex.c index e6dd07c..620a7ad 100644 --- a/src/sys/np/core/np_lex.c +++ b/src/sys/np/core/np_lex.c @@ -215,6 +215,32 @@ lex_cmpop(struct np_work *work, char c, struct lex_token *res) } /* + * Parse a number and get a token value + * + * @work: Input work + * @c: First character [digit] + * @res: Result + */ +static int +lex_nomnum(struct np_work *work, char c, struct lex_token *res) +{ + uint64_t num = 0; + + if (work == NULL || res == NULL) { + return -EINVAL; + } + + while (is_num(c)) { + num = num * 10 + (c - '0'); + c = lex_pop(work); + } + + res->token = TT_NUMBER; + res->val = num; + return 0; +} + +/* * Nom a token */ int @@ -256,6 +282,11 @@ lex_nom(struct np_work *work, struct lex_token *res) res->token = TT_EQUALS; break; default: + if (is_num(c)) { + lex_nomnum(work, c, res); + break; + } + if (lex_arithop(work, c, res) >= 0) break; if (lex_cmpop(work, c, res) >= 0) |