From 5f726024711e0c803a50e3124820d7d4b214dd93 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sat, 23 May 2026 09:01:18 -0400 Subject: core: lexer: Add operational tokens Signed-off-by: Ian Moffett --- core/lexer.c | 25 +++++++++++++++++++++---- core/parser.c | 5 +++++ include/cescal/token.h | 5 +++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/core/lexer.c b/core/lexer.c index 36818bc..27b395e 100644 --- a/core/lexer.c +++ b/core/lexer.c @@ -304,6 +304,18 @@ lexer_nom(struct cescal_state *state, struct token *res) res->type = TT_COLON; res->c = c; return 0; + case '+': + res->type = TT_PLUS; + res->c = c; + return 0; + case '*': + res->type = TT_STAR; + res->c = c; + return 0; + case '=': + res->type = TT_EQUALS; + res->c = c; + return 0; case '#': if ((c = lexer_consume_single(state, true)) == '\0') { return -1; @@ -318,21 +330,26 @@ lexer_nom(struct cescal_state *state, struct token *res) return 0; case '/': - if (lexer_consume_single(state, true) == '/') { + if ((c = lexer_consume_single(state, true)) == '/') { res->type = TT_COMMENT; res->c = c; lexer_skip_comment(state); return 0; } - return -1; + lexer_putback(state, c); + res->type = TT_SLASH; + return 0; case '-': res->c = c; - if (lexer_consume_single(state, true) == '>') { + if ((c = lexer_consume_single(state, true)) == '>') { res->type = TT_ARROW; return 0; } - return -1; + + lexer_putback(state, c); + res->type = TT_MINUS; + return 0; default: if (lexer_scan_ident(state, c, res) == 0) { lexer_check_kw(state, res); diff --git a/core/parser.c b/core/parser.c index 6720d84..58a1bc5 100644 --- a/core/parser.c +++ b/core/parser.c @@ -39,6 +39,11 @@ static const char *toktab[] = { [TT_COMMA] = qtok(","), [TT_COLON] = qtok(":"), [TT_ARROW] = qtok("->"), + [TT_PLUS] = qtok("+"), + [TT_MINUS] = qtok("-"), + [TT_SLASH] = qtok("/"), + [TT_STAR] = qtok("*"), + [TT_EQUALS] = qtok("="), [TT_DEFINE] = qtok("#define"), [TT_IFNDEF] = qtok("#ifndef"), [TT_IFDEF] = qtok("#ifdef"), diff --git a/include/cescal/token.h b/include/cescal/token.h index 1f214bb..8757841 100644 --- a/include/cescal/token.h +++ b/include/cescal/token.h @@ -19,6 +19,11 @@ typedef enum { TT_COMMA, /* ',' */ TT_COLON, /* ':' */ TT_ARROW, /* '->' */ + TT_PLUS, /* '+' */ + TT_MINUS, /* '-' */ + TT_SLASH, /* '/' */ + TT_STAR, /* '*' */ + TT_EQUALS, /* '=' */ TT_DEFINE, /* '#define' */ TT_IFNDEF, /* '#ifndef' */ TT_IFDEF, /* '#ifdef' */ -- cgit v1.2.3