diff options
author | Ian Moffett <ian@osmora.org> | 2025-09-30 22:30:20 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-09-30 22:30:20 -0400 |
commit | 0ec22cf8ffdc4fba512883a006126962f1ee29d9 (patch) | |
tree | 3fb6854675f922d0547b6029a482106a60ab1d59 /src | |
parent | 56a20074863641eb994e298afb4b38b27a277406 (diff) |
np: lex: Parse identifiers and commas
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/include/np/lex.h | 9 | ||||
-rw-r--r-- | src/sys/np/core/np_lex.c | 13 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/sys/include/np/lex.h b/src/sys/include/np/lex.h index 246769a..2efc14e 100644 --- a/src/sys/include/np/lex.h +++ b/src/sys/include/np/lex.h @@ -34,10 +34,14 @@ struct np_work; +/* Keywords */ #define TOKEN_BEGIN "begin" #define TOKEN_PROC "proc" #define TOKEN_END "end" +/* Types */ +#define TOKEN_U8 "u8" + /* * Represents the various token types that are * possible @@ -46,6 +50,11 @@ typedef enum { /* Symbols */ TT_LPAREN, TT_RPAREN, + TT_IDENT, + TT_COMMA, + + /* Types */ + TT_U8, /* Keywords */ TT_BEGIN, diff --git a/src/sys/np/core/np_lex.c b/src/sys/np/core/np_lex.c index 639e945..436df16 100644 --- a/src/sys/np/core/np_lex.c +++ b/src/sys/np/core/np_lex.c @@ -102,9 +102,15 @@ lex_cmptok(char *tokstr, struct lex_token *res) res->token = TT_PROC; } return 0; + case 'u': + if (strcmp(tokstr, TOKEN_U8) == 0) { + res->token = TT_U8; + } + return 0; } - return -1; + res->token = TT_IDENT; + return 0; } /* @@ -157,7 +163,7 @@ int lex_nom(struct np_work *work, struct lex_token *res) { struct lexer_state *lex_st; - int error = -1; + int error = 0; char c; if (work == NULL || res == NULL) { @@ -183,6 +189,9 @@ lex_nom(struct np_work *work, struct lex_token *res) case ')': res->token = TT_RPAREN; break; + case ',': + res->token = TT_COMMA; + break; default: /* Stuff like '1var_name' is invalid */ if (!is_alpha(c)) { |