From 1352aaa4741bf9e558070150ae7b223ad8aa62e8 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Mon, 30 Sep 2024 12:42:21 -0400 Subject: [tnslc] finish decl --- tnslc/parse/ast.tnsl | 56 ++++++++++++++++++++++++++++++++++++++++++++-------- tnslc/test.tnsl | 16 +-------------- 2 files changed, 49 insertions(+), 23 deletions(-) (limited to 'tnslc') diff --git a/tnslc/parse/ast.tnsl b/tnslc/parse/ast.tnsl index 89b9238..712a3df 100644 --- a/tnslc/parse/ast.tnsl +++ b/tnslc/parse/ast.tnsl @@ -34,6 +34,7 @@ struct Node { /; init (uint16 _type, ~uint8 data) self.data = data self._type = _type + self.parent = NULL Node n self.sub.init(len n) @@ -392,7 +393,7 @@ struct Node { bool gt = false /; if (cur`._type == NTYPE_BIN_OP) int j = _op_order(cur`.data) - gt = i > j + gt = _assoc(first`.data, i, j) ;/ # Start from the top and work our way down @@ -402,7 +403,7 @@ struct Node { /; if (sub`._type == NTYPE_BIN_OP) int j = _op_order(sub`.data) - gt = j !< i + gt = _assoc(first`.data, i, j) ;/ /; if (gt) @@ -411,12 +412,19 @@ struct Node { ;/ ;/ - # Replace the last value in the current - bin.sub.push(cur`.sub.get(cur`.sub.count - 1)) - cur`.sub.pop() - cur`.sub.push(~bin) - cur = cur`.sub.get(cur`.sub.count - 1) - + /; if (_assoc_right(first`.data) == true) + # Replace the last value in the current subnode + bin.sub.push(cur`.sub.get(cur`.sub.count - 1)) + cur`.sub.pop() + cur`.sub.push(~bin) + cur = cur`.sub.get(cur`.sub.count - 1) + ;; else + # Replace the subnode itself + bin.sub.push(cur) + cur`.data = bin.data + cur`.sub = bin.sub + ;/ + first` = produce_next_token(fin, first`) /; if (utils.strcmp(bin.data, "is\0")) _ast_type(fin, cur, first) @@ -1056,6 +1064,38 @@ struct Node { ;/ /; _mhf_finish_decl (~utils.File fin, ~Node mod, ~Token first) + + /; loop (bool run = true; run == true) + /; if (first`._type == TTYPE_USRWD) + Node var + var.init(NTYPE_ID, first`.data) + int ln = first`.line + + first` = produce_next_token(fin, first`) + /; if (first`.eq("=\0") && first`.line == ln) + Token tmp = produce_next_token(fin, first`) + first`.end() + first` = tmp + _ast_value(fin, ~var, first) + ;; else if (first`.line !== ln) + run = false + ;/ + + mod`.add_child(~var) + + /; if (first`.eq(",\0") == false) + run = false + ;; else if (run == true) + Token tmp = produce_next_token(fin, first`) + first`.end() + first` = tmp + ;/ + ;; else + _ast_print_err(first, "Expected variable name in declaration\0") + run = false + ;/ + ;/ + ;/ /; _maybe_helper_fun (~utils.File fin, ~Node mod, ~Token first) diff --git a/tnslc/test.tnsl b/tnslc/test.tnsl index 0d54258..c1b44cd 100644 --- a/tnslc/test.tnsl +++ b/tnslc/test.tnsl @@ -1,17 +1,3 @@ -struct Fin { - ~void fd, - int state -} - -/; main (int argc, {}{}uint8 argv) [int] - uint8 a = 1 - ~uint8 b = ~a - Fin c - ~Fin d = ~c - b` = 2 - c.state = a - d`.state = 0 - return c.state -;/ +int i = 1 + 2 * 4 - 3 + 4 -- cgit v1.2.3