summaryrefslogtreecommitdiff
path: root/tnslc/compile
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-06-25 00:19:17 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-06-25 00:19:17 -0400
commit3b5de0beed36c10798f96972ec9c9eeb142561c2 (patch)
treed3d02830118992d229717e4657ff87d77ff01c1e /tnslc/compile
parentc4c595fe22bc76aa4d27f2383ec68a0aa74da37c (diff)
Start work on ast gen
Diffstat (limited to 'tnslc/compile')
-rw-r--r--tnslc/compile/ast.tnsl86
-rw-r--r--tnslc/compile/generator.tnsl22
2 files changed, 90 insertions, 18 deletions
diff --git a/tnslc/compile/ast.tnsl b/tnslc/compile/ast.tnsl
index 139597f..ebe44cb 100644
--- a/tnslc/compile/ast.tnsl
+++ b/tnslc/compile/ast.tnsl
@@ -1,2 +1,88 @@
+int NT_MODULE = 0
+int NT_BLOCK = 1
+int NT_FUNC = 2
+int NT_PARAM = 3
+int NT_RESULT = 4
+int NT_DATA = 5
+int NT_TYPE = 6
+int NT_STRUCT = 7
+
+struct Node {
+ int _type,
+ ~uint8 data,
+ utils.Vector sub
+}
+
+/; method Node
+ /; init (int typ, ~uint8 dat)
+ self._type = typ
+ self.data = dat
+ Node sub
+ self.sub.init(len sub)
+ ;/
+
+ /; end
+ _delete(self.data)
+
+ ~Node n
+ /; loop (int i = 0; i < self.sub.count) [i++]
+ n = self.sub.get(i)
+ n`.end()
+ ;/
+ self.sub.end()
+ ;/
+
+;/
+
+/; build_struct (utils.Iterator it)
+;/
+
+/; build_module ()
+;/
+
+/; build_block (utils.Iterator it)
+;/
+
+/; build_preproc (utils.Iterator it)
+;/
+
+/; build_vardef (utils.Iterator it)
+;/
+
+/; at_defn (utils.Iterator it) [bool]
+ return false
+;/
+
+~uint8 TOKEN_COUNT = "Token count: %d\n\0"
+
+/; build_file (~utils.File fin, ~Node mod)
+ utils.Vector tokens = tokenize(fin)
+ _print_num(TOKEN_COUNT, tokens.count)
+
+ utils.Iterator tokit
+ tokit.init(~tokens)
+
+ /; loop (tokit.at_end() == false)
+ ~Token t = tokit.get()
+ /; if (utils.strcmp(t`.data, "/;\0") == true)
+ _printf("Block detected!\n\0")
+ build_block(tokit)
+ ;; else if (utils.strcmp(t`.data, "struct\0") == true)
+ _printf("Struct detected!\n\0")
+ build_struct(tokit)
+ ;; else if (utils.strcmp(t`.data, ":\0") == true)
+ _printf("Preproc detected!\n\0")
+ build_preproc(tokit)
+ ;; else if (at_defn(tokit) == true)
+ _printf("Defn detected!\n\0")
+ build_vardef(tokit)
+ ;; else
+ # _printf("Error detected!\n\0")
+ # TODO: ERROR
+ ;/
+
+ tokit.next()
+ ;/
+;/
diff --git a/tnslc/compile/generator.tnsl b/tnslc/compile/generator.tnsl
index eedc552..10c75f8 100644
--- a/tnslc/compile/generator.tnsl
+++ b/tnslc/compile/generator.tnsl
@@ -1,25 +1,11 @@
-~uint8 TOKEN_COUNT = "Token count: %d\n\0"
/; generate (~utils.File fin, fout)
- utils.Vector tokens = tokenize(fin)
-
- _print_num(TOKEN_COUNT, tokens.count)
-
- fout`.create()
-
- /; loop (int i = 0; i < tokens.count) [i++]
- ~Token tok = tokens.get(i)
- ~uint8 buf = tok`.sprint()
- fout`.write_cstr(buf)
- fout`.write('\n')
- _delete(buf)
- ;/
-
- fout`.close()
-
- free_token_list(~tokens)
+ Node root
+ root.init(NT_MODULE, NULL)
+ build_file(fin, ~root)
+ root.end()
;/