From 9745e110b69bcf7e32896c444ddc4acd9ed0f8bf Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 30 Sep 2025 23:21:18 -0400 Subject: lex: np: Add lexer arithmetic operators Signed-off-by: Ian Moffett --- src/sys/include/np/lex.h | 6 ++++++ src/sys/np/core/np_lex.c | 18 ++++++++++++++++++ src/sys/np/core/np_parse.c | 6 ++++++ 3 files changed, 30 insertions(+) (limited to 'src/sys') diff --git a/src/sys/include/np/lex.h b/src/sys/include/np/lex.h index 0381afb..daca954 100644 --- a/src/sys/include/np/lex.h +++ b/src/sys/include/np/lex.h @@ -53,6 +53,12 @@ typedef enum { TT_IDENT, /* '' */ TT_COMMA, /* ',' */ TT_STAR, /* '*' */ + TT_MINUS, /* '-' */ + TT_PLUS, /* '+' */ + TT_SLASH, /* '/' */ + TT_EQUALS, /* '=' */ + TT_GT, /* '>' */ + TT_LT, /* '<' */ /* Types */ TT_U8, /* 'u8' */ diff --git a/src/sys/np/core/np_lex.c b/src/sys/np/core/np_lex.c index f870c0c..6e252a3 100644 --- a/src/sys/np/core/np_lex.c +++ b/src/sys/np/core/np_lex.c @@ -197,6 +197,24 @@ lex_nom(struct np_work *work, struct lex_token *res) case '*': res->token = TT_STAR; break; + case '-': + res->token = TT_MINUS; + break; + case '+': + res->token = TT_PLUS; + break; + case '/': + res->token = TT_SLASH; + break; + case '=': + res->token = TT_EQUALS; + break; + case '>': + res->token = TT_GT; + break; + case '<': + res->token = TT_LT; + break; default: /* Stuff like '1var_name' is invalid */ if (!is_alpha(c)) { diff --git a/src/sys/np/core/np_parse.c b/src/sys/np/core/np_parse.c index 1959b1b..165fed5 100644 --- a/src/sys/np/core/np_parse.c +++ b/src/sys/np/core/np_parse.c @@ -46,6 +46,12 @@ static const char *stoktab[] = { [TT_IDENT] = "", [TT_COMMA] = "", [TT_STAR] = "", + [TT_MINUS] = "", + [TT_PLUS] = "", + [TT_SLASH] = "", + [TT_EQUALS] = "", + [TT_GT] = "", + [TT_LT] = "", /* Types */ [TT_U8] = "", -- cgit v1.2.3