diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2022-06-26 01:18:27 -0400 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2022-06-26 01:18:27 -0400 |
commit | 289c1fe3dd2f29e2511b6bb376582f8791179a9b (patch) | |
tree | 67c7c2e272f7564e873c8092c9333aa3a5e16c2d /src/tparse/tree.go | |
parent | 6416973e373a3c61aa2b44591799385c5b1b0092 (diff) |
[AST] Parentheticals
+ Add support for parentheticals
+ Add uint as a valid type for the evaluator
Diffstat (limited to 'src/tparse/tree.go')
-rw-r--r-- | src/tparse/tree.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/tparse/tree.go b/src/tparse/tree.go index 30d6b0c..9aaed06 100644 --- a/src/tparse/tree.go +++ b/src/tparse/tree.go @@ -72,3 +72,52 @@ func MakeTree(tokens *[]Token, file string) Node { return out } + +func findClosing(tokens *[]Token, tok int) int { + t := (*tokens)[tok] + var match string + + switch (t.Data) { + case "(": + match = ")" + case "[": + match = "]" + case "{": + match = "}" + default: + errOut("[Internal] Attempted to find closing for a non-delim token.", t) + } + + var curl, brak, parn int = 0, 0, 0 + + for tok++; tok < len(*tokens); tok++ { + t := (*tokens)[tok] + if t.Type == DELIMIT { + switch t.Data { + case "{": + curl++ + case "[": + brak++ + case "(": + parn++ + + case "}": + curl-- + case "]": + brak-- + case ")": + parn-- + } + + if curl < 0 || brak < 0 || parn < 0 { + if (curl < 0 && match == "}") || (brak < 0 && match == "]") || (parn < 0 && match == ")") { + return tok + } else { + errOut("Un-matched closing delimiter when searching for a closing delim.", t) + } + } + } + } + + return -1 +} |