From a3ac3a7b214991e3b555145dfc1348c58bf54349 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 1 Oct 2025 18:36:21 -0400 Subject: np: lex: Add the rest of the UINT tokens Signed-off-by: Ian Moffett --- src/sys/include/np/lex.h | 8 +++++++- src/sys/np/core/np_lex.c | 36 +++++++++++++++++++++++++++++++++--- src/sys/np/core/np_parse.c | 3 +++ 3 files changed, 43 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/sys/include/np/lex.h b/src/sys/include/np/lex.h index cbbc403..a11de58 100644 --- a/src/sys/include/np/lex.h +++ b/src/sys/include/np/lex.h @@ -40,7 +40,10 @@ struct np_work; #define TOKEN_END "end" /* Types */ -#define TOKEN_U8 "u8" +#define TOKEN_U8 "u8" +#define TOKEN_U16 "u16" +#define TOKEN_U32 "u32" +#define TOKEN_U64 "u64" /* * Represents the various token types that are @@ -68,6 +71,9 @@ typedef enum { /* Types */ TT_U8, /* 'u8' */ + TT_U16, /* 'u16' */ + TT_U32, /* 'u32' */ + TT_U64, /* 'u64' */ /* Values */ TT_NUMBER, /* */ diff --git a/src/sys/np/core/np_lex.c b/src/sys/np/core/np_lex.c index eb15a52..fffe465 100644 --- a/src/sys/np/core/np_lex.c +++ b/src/sys/np/core/np_lex.c @@ -80,6 +80,37 @@ lex_pop(struct np_work *work) return work->source[lex_st->source_idx++]; } +/* + * Compare a token with existing integer types (used internally) + */ +static void +lex_cmp_itype(const char *tokstr, struct lex_token *res) +{ + switch (*tokstr) { + case 'u': + if (strcmp(tokstr, TOKEN_U8) == 0) { + res->token = TT_U8; + break; + } + + if (strcmp(tokstr, TOKEN_U16) == 0) { + res->token = TT_U16; + break; + } + + if (strcmp(tokstr, TOKEN_U32) == 0) { + res->token = TT_U32; + break; + } + + if (strcmp(tokstr, TOKEN_U64) == 0) { + res->token = TT_U64; + break; + } + break; + } +} + /* * Compare a token with existing tokens (used internally) */ @@ -103,9 +134,8 @@ lex_cmptok(char *tokstr, struct lex_token *res) } return 0; case 'u': - if (strcmp(tokstr, TOKEN_U8) == 0) { - res->token = TT_U8; - } + case 'i': + lex_cmp_itype(tokstr, res); return 0; } diff --git a/src/sys/np/core/np_parse.c b/src/sys/np/core/np_parse.c index 63f93aa..c560294 100644 --- a/src/sys/np/core/np_parse.c +++ b/src/sys/np/core/np_parse.c @@ -62,6 +62,9 @@ static const char *stoktab[] = { /* Types */ [TT_U8] = "", + [TT_U16] = "", + [TT_U32] = "", + [TT_U64] = "", /* Values */ [TT_NUMBER] = "", -- cgit v1.2.3