WIP: int expressions
authorLukas Krickl <lukas@krickl.dev>
Sun, 19 Nov 2023 07:42:22 +0000 (08:42 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sun, 19 Nov 2023 07:42:22 +0000 (08:42 +0100)
include/ulas.h
src/ulas.c

index 950711c24798bb9e60567cb2be08583f55eed397..f6955bcef726e9ad30426924b5fff030999fc048 100644 (file)
@@ -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;
 };
 
 /**
index e61dbc0850049c7b45642dc2470e050fe2c18988..fc63f826bbeda68900092acad6e087e99614e1af 100644 (file)
@@ -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;
 }