summaryrefslogtreecommitdiff
path: root/tnslc
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-08-02 11:52:50 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-08-02 11:52:50 -0400
commit7793ee1739ccb239819c6664c89727697be4bf97 (patch)
tree5f550966fef53e9062734307d2fe44f85f8fc1da /tnslc
parentbc22cfdb3eb3c39b647cb02e9b0c50f8d0ffb158 (diff)
type_helper_pre
Diffstat (limited to 'tnslc')
-rw-r--r--tnslc/parse/ast.tnsl85
-rw-r--r--tnslc/parse/tokenizer.tnsl8
-rw-r--r--tnslc/test.tnsl2
3 files changed, 81 insertions, 14 deletions
diff --git a/tnslc/parse/ast.tnsl b/tnslc/parse/ast.tnsl
index 9011de1..3cdf269 100644
--- a/tnslc/parse/ast.tnsl
+++ b/tnslc/parse/ast.tnsl
@@ -49,10 +49,10 @@ struct Node {
return ';'
;; else if (ch == '(')
return ')'
- ;; else if (ch == '{')
- return '}'
;; else if (ch == '[')
return ']'
+ ;; else if (ch == '{')
+ return '}'
;/
return 0
;/
@@ -85,10 +85,53 @@ struct Node {
-# AST types
+# AST types
/; _type_helper_pre (~utils.File fin, ~Node mod, ~Token first)
+ /; loop (bool run = true; first`._type !== TTYPE_ERR && run == true)
+ /; if (first`._type == TTYPE_AUG && first`.eq("~\0") == true)
+ # Pointer
+ Node ptr
+ ptr.init(NTYPE_PRE_OP, first`.data)
+ mod`.sub.push(~ptr)
+ first` = produce_next_token(fin, first`)
+ ;; else if (first`._type == TTYPE_DELIM && first`.eq("{\0") == true)
+ # Array
+ Node arr
+ arr.init(NTYPE_PRE_OP, first`.data)
+ first` = produce_next_token(fin, first`)
+
+ /; if (first`._type == TTYPE_LITRL && is_numeric(first`.data`) == true)
+ Node num
+ num.init(NTYPE_LITERAL, first`.data)
+ arr.sub.push(~num)
+
+ first` = produce_next_token(fin, first`)
+ /; if (first`.eq("}\0") == true)
+ Token tmp = produce_next_token(fin, first`)
+ first`.end()
+ first` = tmp
+ ;; else
+ _ast_print_err(first, "Expected closing '}' after integer in type declaration\0")
+ run = false
+ ;/
+ ;; else if (first`.eq("}\0") == true)
+ Token tmp = produce_next_token(fin, first`)
+ first`.end()
+ first` = tmp
+ ;; else
+ _ast_print_err(first, "Expected integer or '}' to define either a fixed sized array or pointer to unknown sized array\0")
+ run = false
+ ;/
+
+ mod`.sub.push(~arr)
+
+ ;; else
+ run = false
+ ;/
+ ;/
+
;/
/; _type_helper_func (~utils.File fin, ~Node mod, ~Token first)
@@ -502,25 +545,41 @@ struct Node {
/; print_node_type (~Node n)
/; if (n`._type == NTYPE_MODULE)
- _printf("Mod\0")
+ _printf("NTYPE_MODULE\0")
;; else if (n`._type == NTYPE_EXPORT)
- _printf("Exported Module\0")
+ _printf("NTYPE_EXPORT\0")
;; else if (n`._type == NTYPE_STRUCT)
- _printf("Struct\0")
+ _printf("NTYPE_STRUCT\0")
+ ;; else if (n`._type == NTYPE_TYPE)
+ _printf("NTYPE_TYPE\0")
;; else if (n`._type == NTYPE_ID)
- _printf("ID\0")
+ _printf("NTYPE_ID\0")
;; else if (n`._type == NTYPE_BIN_OP)
- _printf("Binary OP\0")
+ _printf("NTYPE_BIN_OP\0")
;; else if (n`._type == NTYPE_PRE_OP)
- _printf("Pre OP\0")
+ _printf("NTYPE_PRE_OP\0")
;; else if (n`._type == NTYPE_POST_OP)
- _printf("Post OP\0")
+ _printf("NTYPE_POST_OP\0")
;; else if (n`._type == NTYPE_FUNCTION)
- _printf("Function\0")
+ _printf("NTYPE_FUNCTION\0")
;; else if (n`._type == NTYPE_METHOD)
- _printf("Method\0")
+ _printf("NTYPE_METHOD\0")
+ ;; else if (n`._type == NTYPE_TLIST)
+ _printf("NTYPE_TLIST\0")
+ ;; else if (n`._type == NTYPE_DLIST)
+ _printf("NTYPE_DLIST\0")
+ ;; else if (n`._type == NTYPE_ELIST)
+ _printf("NTYPE_ELIST\0")
+ ;; else if (n`._type == NTYPE_LITERAL)
+ _printf("NTYPE_LITERAL\0")
+ ;; else if (n`._type == NTYPE_KEY_TYPE)
+ _printf("NTYPE_KEY_TYPE\0")
+ ;; else if (n`._type == NTYPE_ENUM)
+ _printf("NTYPE_ENUM\0")
+ ;; else if (n`._type == NTYPE_DECL)
+ _printf("NTYPE_DECL\0")
;; else if (n`._type == NTYPE_ASM)
- _printf("ASM\0")
+ _printf("NTYPE_ASM\0")
;/
;/
diff --git a/tnslc/parse/tokenizer.tnsl b/tnslc/parse/tokenizer.tnsl
index 745100c..e44e648 100644
--- a/tnslc/parse/tokenizer.tnsl
+++ b/tnslc/parse/tokenizer.tnsl
@@ -333,7 +333,13 @@ uint MAX_MULTI = 3
/; if (first == '\'' || first == '\"')
return produce_string_token(fin, prev)
;; else if (is_reserved(first) == true)
- return produce_reserved_token(fin, prev)
+ Token out = produce_reserved_token(fin, prev)
+ /; loop (out._type == TTYPE_COMNT)
+ Token tmp = produce_next_token(fin, out)
+ out.end()
+ out = tmp
+ ;/
+ return out
;; else if (is_numeric(first) == true)
return produce_numeric_token(fin, prev)
;; else if (first !== 0)
diff --git a/tnslc/test.tnsl b/tnslc/test.tnsl
index 28f0917..3eff47d 100644
--- a/tnslc/test.tnsl
+++ b/tnslc/test.tnsl
@@ -1,5 +1,7 @@
# should not be included
+~uint lmao
+
/; whatev (~uint8 a) [uint8]
return a{0}
;/