diff options
Diffstat (limited to 'tnslc/ast')
-rw-r--r-- | tnslc/ast/ast.tnsl | 30 | ||||
-rw-r--r-- | tnslc/ast/block.tnsl | 15 | ||||
-rw-r--r-- | tnslc/ast/list.tnsl (renamed from tnslc/ast/node.tnsl) | 13 | ||||
-rw-r--r-- | tnslc/ast/statement.tnsl | 48 | ||||
-rw-r--r-- | tnslc/ast/tree.tnsl | 52 | ||||
-rw-r--r-- | tnslc/ast/value.tnsl | 40 |
6 files changed, 188 insertions, 10 deletions
diff --git a/tnslc/ast/ast.tnsl b/tnslc/ast/ast.tnsl index 466fe08..bece84e 100644 --- a/tnslc/ast/ast.tnsl +++ b/tnslc/ast/ast.tnsl @@ -15,5 +15,33 @@ #/ /; export module ast - :include "ast/node.tnsl" + :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 +}
\ No newline at end of file diff --git a/tnslc/ast/block.tnsl b/tnslc/ast/block.tnsl new file mode 100644 index 0000000..17a9e22 --- /dev/null +++ b/tnslc/ast/block.tnsl @@ -0,0 +1,15 @@ +/## + Copyright 2021 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/node.tnsl b/tnslc/ast/list.tnsl index d1db325..ee5d0cf 100644 --- a/tnslc/ast/node.tnsl +++ b/tnslc/ast/list.tnsl @@ -14,13 +14,8 @@ EXPRESS OR IMPLIED #/ -# AST node (non-block) -;struct Node { - tnslc.parse.Token - # associated token to the node - tok, +/; tree_list_value [{}Node] + ;{}Node out = {} - ~{}Node - # sub-nodes - sub -} + ;return out +;/ diff --git a/tnslc/ast/statement.tnsl b/tnslc/ast/statement.tnsl new file mode 100644 index 0000000..d8b4877 --- /dev/null +++ b/tnslc/ast/statement.tnsl @@ -0,0 +1,48 @@ +/## + Copyright 2021 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_definition (~{}Token tokens, ~int i) [bool] ;/ + +/; tree_keyword_statement (~{}Token tokens, ~int i) [Node] + +;/ + +/; 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 new file mode 100644 index 0000000..fe6baab --- /dev/null +++ b/tnslc/ast/tree.tnsl @@ -0,0 +1,52 @@ +/## + Copyright 2021 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] + ;{}charp null_str = "" + ;Token null_tok = {0, 0, 0, ~null_str} + ;{}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 new file mode 100644 index 0000000..2cefb62 --- /dev/null +++ b/tnslc/ast/value.tnsl @@ -0,0 +1,40 @@ +/## + Copyright 2021 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 [Node] + ;Token type_tok = {NODE_TYPE.TYPE, 0, 0, ~CNULL} + ;{}Node type_sub = {} + ;return {type_tok, ~type_sub} +;/ + +/; tree_value [Node] + +;/ + +/; 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 |