Start supporting numbers and strings

This commit is contained in:
2023-02-25 16:45:54 +00:00
parent cbae1c4629
commit 636101f1fa
15 changed files with 379 additions and 37 deletions

View File

@@ -2,9 +2,42 @@ package main
import (
"fmt"
"log"
)
func translate(code string) {
output, _ := newNumber().SetString("3.1415")
fmt.Println(numberToString(output, 0))
// returns (translateNumber | translateString), success, error
func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine bool) (any, bool, string) {
if isLine {
if isComment(code) {
return nil, true, ""
}
}
if isNumber(code) {
return parseNumber(code)
} else if isString(code) {
return parseString(code)
}
if isLine {
return nil, false, "Syntax Error: invalid code on line " + fmt.Sprint(code.line) + ": " + code.code
}
return nil, false, ""
}
// returns [](translateNumber | translateString), error
func translate(codelines []UNPARSEcode) ([]any, string) {
translated := []any{}
for i, code := range codelines {
val, _, err := translateVal(code, i, codelines, true)
if err != "" {
log.Fatal(err)
return nil, err
}
if val == nil {
continue
}
translated = append(translated, val)
}
return translated, ""
}