From aa5db10e7b653d9f6c3bda0c55b770f1f66a922f Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Thu, 15 Dec 2022 02:34:04 -0500 Subject: Change label format + Support modules + Track member types better ~ Remove unused files --- tnslc/ast/ast.tnsl | 48 ------------------------ tnslc/ast/block.tnsl | 15 -------- tnslc/ast/list.tnsl | 75 -------------------------------------- tnslc/ast/statement.tnsl | 95 ------------------------------------------------ tnslc/ast/tree.tnsl | 51 -------------------------- tnslc/ast/value.tnsl | 55 ---------------------------- 6 files changed, 339 deletions(-) delete mode 100644 tnslc/ast/ast.tnsl delete mode 100644 tnslc/ast/block.tnsl delete mode 100644 tnslc/ast/list.tnsl delete mode 100644 tnslc/ast/statement.tnsl delete mode 100644 tnslc/ast/tree.tnsl delete mode 100644 tnslc/ast/value.tnsl (limited to 'tnslc/ast') diff --git a/tnslc/ast/ast.tnsl b/tnslc/ast/ast.tnsl deleted file mode 100644 index 71470f6..0000000 --- a/tnslc/ast/ast.tnsl +++ /dev/null @@ -1,48 +0,0 @@ -/## - Copyright 2021-2022 Kyle Gunger - - This file is licensed under the CDDL 1.0 (the License) - and may only be used in accordance with the License. - You should have received a copy of the License with this - software/source code. If you did not, a copy can be found - at the following URL: - - https://opensource.org/licenses/CDDL-1.0 - - THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO - WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE - EXPRESS OR IMPLIED -#/ - -/; export module ast - :include "ast/block.tnsl" - :include "ast/list.tnsl" - :include "ast/statement.tnsl" - :include "ast/tree.tnsl" - :include "ast/value.tnsl" -;/ - -;{}charp CNULL = "" - -# AST node (non-block) -;struct Node { - tnslc.Token - # associated token to the node - tok, - - ~{}Node - # sub-nodes - sub -} - -;enum NODE_TYPE [int] { - FILE = 9, - TYPE = 10, - VALUE = 11, - DEFN = 12, - - #... - - PREP = 1000 -} - diff --git a/tnslc/ast/block.tnsl b/tnslc/ast/block.tnsl deleted file mode 100644 index 8fa0f27..0000000 --- a/tnslc/ast/block.tnsl +++ /dev/null @@ -1,15 +0,0 @@ -/## - Copyright 2021-2022 Kyle Gunger - - This file is licensed under the CDDL 1.0 (the License) - and may only be used in accordance with the License. - You should have received a copy of the License with this - software/source code. If you did not, a copy can be found - at the following URL: - - https://opensource.org/licenses/CDDL-1.0 - - THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO - WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE - EXPRESS OR IMPLIED -#/ \ No newline at end of file diff --git a/tnslc/ast/list.tnsl b/tnslc/ast/list.tnsl deleted file mode 100644 index b65b336..0000000 --- a/tnslc/ast/list.tnsl +++ /dev/null @@ -1,75 +0,0 @@ -/## - Copyright 2021-2022 Kyle Gunger - - This file is licensed under the CDDL 1.0 (the License) - and may only be used in accordance with the License. - You should have received a copy of the License with this - software/source code. If you did not, a copy can be found - at the following URL: - - https://opensource.org/licenses/CDDL-1.0 - - THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO - WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE - EXPRESS OR IMPLIED -#/ - -/; tree_list_value [{}Node] - ;{}Node out = {} - ;return out -;/ - -/; tree_list_type [{}Node] - ;{}Node out = {} - ;return out -;/ - -/; tree_list_statement (~{}Token tok, ~int cur) [{}Node] - ;{}Node out = {} - - /; loop (cur` < len tok`) [cur` = cur` + 1] - ;Node stmt = tree_statement(tok, cur) - ;out.append(stmt) - - ;Token tmp = tok`{cur`} - /; if (string_equate(tmp.data, "]") || string_equate(tmp.data, ")")) - ;cur` = cur` + 1 - ;break - ;; else if (string_equate(tmp.data, ";") == false) - ;create_panic("Unexpected token in list of statements") - ;/ - ;/ - - ;return out -;/ - -/; tree_list_params (~{}Token tok, ~int cur) [{}Node] - ;{}Node out = {} - - /; if (string_equate(tok`{cur`}.data, ")")) - ;return out - ;/ - - /; if (type_then_name(tok, cur) == false) - ;create_panic("Parameter list must start with a type and name combo.") - ;/ - - /; loop (cur` < len tok`) [cur` = cur` + 1] - ;Node tmp - /; if (type_then_name(tok, cur)) - ;tmp = tree_type(tok, cur) - ;out.append(tmp) - ;/ - - ;tmp = tree_value(tok, cur) - - /; if (string_equate(tok`{cur`}.data, ")")) - ;cur` = cur` + 1 - ;break - ;; else if (string_equate(tok`{cur`}.data, ",") == false) - ;create_panic("A value in a list of params must be followed with a comma") - ;/ - ;/ - - ;return out -;/ diff --git a/tnslc/ast/statement.tnsl b/tnslc/ast/statement.tnsl deleted file mode 100644 index 15f6e26..0000000 --- a/tnslc/ast/statement.tnsl +++ /dev/null @@ -1,95 +0,0 @@ -/## - Copyright 2021-2022 Kyle Gunger - - This file is licensed under the CDDL 1.0 (the License) - and may only be used in accordance with the License. - You should have received a copy of the License with this - software/source code. If you did not, a copy can be found - at the following URL: - - https://opensource.org/licenses/CDDL-1.0 - - THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO - WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE - EXPRESS OR IMPLIED -#/ - -/; is_keyword_statement ({}charp word) [bool] - ;return string_equate(word, "struct") || string_equate(word, "interface") || string_equate(word, "enum") || - string_equate(word, "continue") || string_equate(word, "break") || string_equate(word, "label") || - string_equate(word, "goto") || string_equate(word, "virtual") || string_equate(word, "asm") || - string_equate(word, "delete") -;/ - -/; is_closing (Token t) [bool] - /; if (t.token_type == TOKEN_TYPE.DELIMIT) - ;return string_equate(t.data`, ")") || string_equate(t.data`, "]") || string_equate(t.data`, "}") - ;/ - ;return false -;/ - -/; get_closing (~{}Token tokens, int i) [int] - ;{}charp end = ")" - /; if (string_equate(tokens`{i}.data`, "[")) - ;end = "]" - ;; else if (string_equate(tokens`{i}.data`, "{")) - ;end = "}" - ;/ - - ;int delims = 0 - - /; loop (i++; i < len tokens`) [i++] - /; if (is_closing(tokens`{i})) - /; if (delims > 0) - ;delims-- - ;; else if (string_equate(end, tokens`{i}.data`)) - ;return i - ;; else - ;return -1 - ;/ - ;; else if (tokens`{i}.token_type == TOKEN_TYPE.DELIMIT) - ;delims++ - ;/ - ;/ - - ;return -1 -;/ - - -/; is_definition (~{}Token tokens, ~int i) [bool] - - /; loop (int j = i`; j < len tokens`) [j++] - /; if (tokens`{j}.token_type == TOKEN_TYPE.KEYTYPE) - - ;; else if () - ;/ - ;/ - ;return false -;/ - -/; tree_keyword_statement (~{}Token tokens, ~int i) [Node] - ;Token def_tok = {TOKEN_TYPE.KEYWORD, 0, 0, ~CNULL} - ;{}Node def_sub = {} - - ;return {def_tok, ~def_sub} -;/ - -/; tree_statement (~{}Token tokens, ~int i) [Node] - ;i`++ - /; if (i` !< len tokens`) - ;return make_null_node() - - ;; else if (is_keyword_statement(tokens`{i`}.data`)) - ;return tree_keyword_statement(tokens, i) - - ;; else if (is_definition(tokens, i)) - ;return tree_definition(tokens, i) - - ;/ - - ;return tree_value(tokens, i) -;/ - -/; tree_preproc [Node] - -;/ \ No newline at end of file diff --git a/tnslc/ast/tree.tnsl b/tnslc/ast/tree.tnsl deleted file mode 100644 index 0e8f9dc..0000000 --- a/tnslc/ast/tree.tnsl +++ /dev/null @@ -1,51 +0,0 @@ -/## - Copyright 2021-2022 Kyle Gunger - - This file is licensed under the CDDL 1.0 (the License) - and may only be used in accordance with the License. - You should have received a copy of the License with this - software/source code. If you did not, a copy can be found - at the following URL: - - https://opensource.org/licenses/CDDL-1.0 - - THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO - WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE - EXPRESS OR IMPLIED -#/ - -/; make_null_node [Node] - ;Token null_tok = {0, 0, 0, ~CNULL} - ;{}Node sub = {} - ;return {null_tok, ~sub} -;/ - -/# - # This should be the main entry point into the AST module - # -#; make_tree (~{}Token tokens, {}charp name) [Node] - ;Token root = {0, 0, NODE_TYPE.FILE, ~name} - ;{}Node sub = {} - - /; loop (int i = 0; i < len tokens`) [i++] - ;{}charp to_check = tokens`{i}.data` - - /; if (string_equate(to_check, ";")) - ;sub.append(tree_statement(tokens, ~i)) - - ;; else if (string_equate(to_check, ":")) - ;sub.append(tree_preproc(tokens, ~i)) - - ;; else if (string_equate(to_check, "/;")) - ;sub.append(tree_block(tokens, ~i)) - - ;; else if (string_equate(to_check, "/:")) - ;sub.append(tree_preblock(tokens, ~i)) - - ;; else - ;break - ;/ - ;/ - - ;return {root, ~sub} -;/ diff --git a/tnslc/ast/value.tnsl b/tnslc/ast/value.tnsl deleted file mode 100644 index 59655c7..0000000 --- a/tnslc/ast/value.tnsl +++ /dev/null @@ -1,55 +0,0 @@ -/## - Copyright 2021-2022 Kyle Gunger - - This file is licensed under the CDDL 1.0 (the License) - and may only be used in accordance with the License. - You should have received a copy of the License with this - software/source code. If you did not, a copy can be found - at the following URL: - - https://opensource.org/licenses/CDDL-1.0 - - THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO - WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE - EXPRESS OR IMPLIED -#/ - -/; tree_type (~{}Token tok, ~int cur) [Node] - ;Token type_tok = {NODE_TYPE.TYPE, 0, 0, ~CNULL} - ;{}Node type_sub = {} - - # Pre type keyword checks - /; loop (tok`{cur`}.token_type !== TOKEN_TYPE.DEFWORD && tok`{cur`}.token_type !== TOKEN_TYPE.KEYTYPE) - /; if (tok`{cur`}.token_type == TOKEN_TYPE.KEYWORD) - - ;/ - ;/ - - /; - - ;/ - - ;return {type_tok, ~type_sub} -;/ - -/; tree_value [Node] - ;Token def_tok = {NODE_TYPE.VALUE, 0, 0, ~CNULL} - ;{}Node def_sub = {} - - ;return {def_tok, ~def_sub} -;/ - -/; tree_definition [Node] - ;Token def_tok = {NODE_TYPE.DEFN, 0, 0, ~CNULL} - ;{}Node def_sub = {} - - ;def_sub.append(tree_type()) - - ;{}Node vals = tree_list_value() - - /; loop (int i = 0; i < len vals) [i++] - ;def_sub.append(vals{i}) - ;/ - - ;return {def_tok, ~def_sub} -;/ \ No newline at end of file -- cgit v1.2.3