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 | |
parent | 6416973e373a3c61aa2b44591799385c5b1b0092 (diff) |
[AST] Parentheticals
+ Add support for parentheticals
+ Add uint as a valid type for the evaluator
Diffstat (limited to 'src')
-rw-r--r-- | src/texec/eval.go | 6 | ||||
-rw-r--r-- | src/texec/libtnsl.go | 4 | ||||
-rw-r--r-- | src/tparse/tree-statement.go | 3 | ||||
-rw-r--r-- | src/tparse/tree-value.go | 9 | ||||
-rw-r--r-- | src/tparse/tree.go | 49 |
5 files changed, 67 insertions, 4 deletions
diff --git a/src/texec/eval.go b/src/texec/eval.go index 37341a5..b0f4a47 100644 --- a/src/texec/eval.go +++ b/src/texec/eval.go @@ -563,6 +563,9 @@ func convertValPS(to TType, sk int, dat interface{}) interface{} { case int: numcv = float64(v) goto NCV + case uint: + numcv = float64(v) + goto NCV case byte: numcv = float64(v) goto NCV @@ -583,6 +586,8 @@ func convertValPS(to TType, sk int, dat interface{}) interface{} { NCV: if equateTypePSO(to, tInt, sk) { return int(numcv) + } else if equateTypePSO(to, tUint, sk) { + return uint(numcv) } else if equateTypePSO(to, tFloat, sk) { return float64(numcv) } else if equateTypePSO(to, tByte, sk) || equateTypePSO(to, tCharp, sk) { @@ -696,6 +701,7 @@ func isStruct(t TType, skp int) bool { ch = ch || equateTypePSO(t, tCharp, skp) ch = ch || equateTypePSO(t, tBool, skp) ch = ch || equateTypePSO(t, tNull, skp) + ch = ch || equateTypePSO(t, tUint, skp) return !ch } diff --git a/src/texec/libtnsl.go b/src/texec/libtnsl.go index bb0ce7d..91d65ae 100644 --- a/src/texec/libtnsl.go +++ b/src/texec/libtnsl.go @@ -26,7 +26,8 @@ import ( Parts included: - io.print - io.println - - io.openFile + - io.readFile + - io.writeFile - io.File API for file objects Types included: @@ -46,6 +47,7 @@ var ( tFile = TType{Pre: []string{}, T: TArtifact{Path: []string{"tnsl", "io"}, Name: "File"}, Post: ""} tString = TType{Pre: []string{"{}"}, T: TArtifact{Path: []string{}, Name:"charp"}, Post: ""} tInt = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"int"}, Post: ""} + tUint = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"uint"}, Post: ""} tByte = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"uint8"}, Post: ""} tByteArray = TType{Pre: []string{"{}"}, T: TArtifact{Path: []string{}, Name:"uint8"}, Post: ""} tFloat = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"float"}, Post: ""} diff --git a/src/tparse/tree-statement.go b/src/tparse/tree-statement.go index cf25085..6a5b6e3 100644 --- a/src/tparse/tree-statement.go +++ b/src/tparse/tree-statement.go @@ -117,13 +117,14 @@ func parseBlock(tokens *[]Token, tok, max int) (Node, int) { REBLOCK: tmp, tok = parseBlock(tokens, tok + 1, max) - + if (*tokens)[tok].Data == ";;" { out.Sub = append(out.Sub, tmp) goto REBLOCK } else if (*tokens)[tok].Data == ";/" { tok++ } + case "/:": tmp, tok = parsePreBlock(tokens, tok + 1, max) case ":": diff --git a/src/tparse/tree-value.go b/src/tparse/tree-value.go index 7ae346c..35e94d2 100644 --- a/src/tparse/tree-value.go +++ b/src/tparse/tree-value.go @@ -115,6 +115,11 @@ func parseUnaryOps(tokens *[]Token, tok, max int) (Node) { (*vnode).Data.Data = "comp" val = true comp = true + case "(": //Typecast or paren statement + mx := findClosing(tokens, tok) + (*vnode) = parseBinaryOp(tokens, tok + 1, mx) + tok = mx + val = true default: errOut("Unexpected delimiter when parsing value", t) } @@ -210,7 +215,7 @@ func parseBinaryOp(tokens *[]Token, tok, max int) (Node) { } if curl < 0 || brak < 0 || parn < 0 { - if curl > 0 || brak > 0 || parn > 0 { + if curl > 0 || brak > 0 || parn > 0 || tok < max - 1 { errOut("Un-matched closing delimiter when parsing a type.", t) } } @@ -303,7 +308,7 @@ func parseValue(tokens *[]Token, tok, max int) (Node, int) { if block > 1 { continue } else if block == 1 { - errOut("Error: redefinition of a block from a block as a value is not permitted.", t) + errOut("Error: redefinition of a block from a value block is not permitted.", t) } if curl > 0 || brak > 0 || parn > 0 { errOut("Delimeter pairs not closed before end of value", t) 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 +} |