From abb547ac1786619d3bbfab3beb822e61bbc89664 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 19 Nov 2023 08:42:22 +0100 Subject: [PATCH] WIP: int expressions --- include/ulas.h | 9 +++++++++ src/ulas.c | 28 ++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/include/ulas.h b/include/ulas.h index 950711c..f6955bc 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -240,6 +240,15 @@ union ulas_expval { struct ulas_expr { enum ulas_exprs type; union ulas_expval val; + // link to the next expression, 0 indicates + // there is no next expression + long next; +}; + +struct ulas_exprbuf { + struct ulas_expr *exprs; + unsigned long len; + unsigned long maxlen; }; /** diff --git a/src/ulas.c b/src/ulas.c index e61dbc0..fc63f82 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -931,30 +931,50 @@ int ulas_tokexpr(const char **line, unsigned long n) { int tokrc = 0; while ((tokrc = ulas_tok(&ulas.tok, line, n) > 0)) { if (tokrc == -1) { - goto fail; + goto end; } // interpret the token struct ulas_tok tok = ulas_totok( ulas.tok.buf, strnlen(ulas.tok.buf, ulas.tok.maxlen), &tokrc); if (tokrc == -1) { - goto fail; + goto end; + } + + // check for any expression terminators here + if (tok.type == ',') { + goto end; } // now we can loop token type, add all tokens to the token buffer ulas_tokbufpush(&ulas.toks, tok); } -fail: +end: return tokrc; } +// parses tokens to expression tree +int ulas_parseexpr(struct ulas_tokbuf *toks) { + int rc = 0; + for (long i = 0; i < toks->len; i++) { + } + +fail: + return rc; +} + int ulas_intexpr(const char **line, unsigned long n, int *rc) { if (ulas_tokexpr(line, n) == -1) { *rc = -1; return -1; } - // now that we have all tokens in the buffer, create the tree strucute + if (ulas_parseexpr(&ulas.toks) == -1) { + *rc = -1; + return -1; + } + + // execute the tree of expressions return -1; } -- 2.30.2