From e2503def53445f74d37fcbc5d67b956bd795092f Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 1 Oct 2025 02:25:49 -0400 Subject: np: lex: Handle digits in the stream Signed-off-by: Ian Moffett --- src/sys/np/core/np_lex.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/sys/np/core/np_lex.c') 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 @@ -214,6 +214,32 @@ lex_cmpop(struct np_work *work, char c, struct lex_token *res) return res->token; } +/* + * 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 */ @@ -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) -- cgit v1.2.3