diff options
Diffstat (limited to 'src/tparse')
-rw-r--r-- | src/tparse/tree-list.go | 23 | ||||
-rw-r--r-- | src/tparse/tree-preproc.go | 2 | ||||
-rw-r--r-- | src/tparse/tree-value.go | 15 | ||||
-rw-r--r-- | src/tparse/tree.go | 13 | ||||
-rw-r--r-- | src/tparse/type.go | 7 |
5 files changed, 39 insertions, 21 deletions
diff --git a/src/tparse/tree-list.go b/src/tparse/tree-list.go index 059ef0b..0a98e8c 100644 --- a/src/tparse/tree-list.go +++ b/src/tparse/tree-list.go @@ -31,21 +31,22 @@ func getClosing(start string) string { // Parse a list of values func parseValueList(tokens *[]Token, tok, max int) (Node, int) { - out := Node{} - out.Data = Token{Type: 10, Data: "value"} + out := Node{Data: Token{Type: 10, Data: "list"}, IsBlock: false} var tmp Node - c := getClosing((*tokens)[tok].Data) + tmp, tok = parseValue(tokens, tok, max) + out.Sub = append(out.Sub, tmp) + + for ; tok < max; { - tok++ - - for ; tok < max; tok++ { t := (*tokens)[tok] - - switch t.Data { - case c: - return out, tok - case ",": + + switch t.Type { + case LINESEP: + fallthrough + case DELIMIT: + return out, tok + 1 + case INLNSEP: tok++ default: errOut("Error: unexpected token when parsing a list of values", t) diff --git a/src/tparse/tree-preproc.go b/src/tparse/tree-preproc.go index d0f6637..a3e65f5 100644 --- a/src/tparse/tree-preproc.go +++ b/src/tparse/tree-preproc.go @@ -45,5 +45,7 @@ func parsePre (tokens *[]Token, tok, max int) (Node, int) { tmp := Node{Data: (*tokens)[tok], IsBlock: false} out.Sub = append(out.Sub, tmp) + tok++ + return out, tok }
\ No newline at end of file diff --git a/src/tparse/tree-value.go b/src/tparse/tree-value.go index 1eac252..d7d01ec 100644 --- a/src/tparse/tree-value.go +++ b/src/tparse/tree-value.go @@ -90,7 +90,6 @@ var ORDER = map[string]int{ func parseUnaryOps(tokens *[]Token, tok, max int) (Node) { out := Node{Data: Token{Type: 10, Data: "value"}, IsBlock: false} val := false - // Pre-value op scan for ; tok < max && !val; tok++ { t := (*tokens)[tok] @@ -164,7 +163,7 @@ func parseUnaryOps(tokens *[]Token, tok, max int) (Node) { func parseBinaryOp(tokens *[]Token, tok, max int) (Node) { out := Node{IsBlock: false} first := tok - var high, highOrder, bincount int = first, 8, 0 + var high, highOrder, bincount int = first, 0, 0 var curl, brak, parn int = 0, 0, 0 // Find first high-order op @@ -194,7 +193,7 @@ func parseBinaryOp(tokens *[]Token, tok, max int) (Node) { } } else if t.Type == AUGMENT { order, prs := ORDER[t.Data] - if !prs || curl > 0 || brak > 0 || parn > 0 { + if prs == false || curl > 0 || brak > 0 || parn > 0 { continue } else if order > highOrder { high, highOrder = tok, order @@ -207,9 +206,10 @@ func parseBinaryOp(tokens *[]Token, tok, max int) (Node) { out.Data = (*tokens)[high] if bincount == 0 { - // No binops means we have a value to parse. Parse all unary ops around it. + // No binops means we have a pure value to parse. Parse all unary ops around it. return parseUnaryOps(tokens, first, max) } else { + // Recursive split to lower order operations out.Sub = append(out.Sub, parseBinaryOp(tokens, first, high)) out.Sub = append(out.Sub, parseBinaryOp(tokens, high + 1, max)) @@ -316,8 +316,11 @@ func parseTypeParams(tokens *[]Token, tok, max int) (Node, int) { func parseType(tokens *[]Token, tok, max int, param bool) (Node, int) { out := Node{Data: Token{Type: 10, Data: "type"}, IsBlock: false} + + for ; tok < max; tok++ { t := (*tokens)[tok] + var tmp Node switch t.Type { case AUGMENT: @@ -331,7 +334,9 @@ func parseType(tokens *[]Token, tok, max int, param bool) (Node, int) { tmp, tok = parseTypeParams(tokens, tok, max) } else { tmp.Data = t + tok++ } + out.Sub = append(out.Sub, tmp) return out, tok case DEFWORD: @@ -465,5 +470,5 @@ func isTypeThenValue(tokens *[]Token, tok, max int) (bool) { } } - return true + return stage == 2 }
\ No newline at end of file diff --git a/src/tparse/tree.go b/src/tparse/tree.go index af3e184..00e75fb 100644 --- a/src/tparse/tree.go +++ b/src/tparse/tree.go @@ -27,6 +27,13 @@ func errOut(message string, token Token) { panic("AST Error") } +func errOutV(message string, tok, max int, token Token) { + fmt.Println(message) + fmt.Println(token) + fmt.Println(tok) + fmt.Println(max) + panic("AST Error") +} // MakeTree creates an AST out of a set of tokens func MakeTree(tokens *[]Token, file string) Node { out := Node{} @@ -36,13 +43,13 @@ func MakeTree(tokens *[]Token, file string) Node { max := len(*tokens) - for tok := 0; tok < max; tok++ { + for tok := 0; tok < max; { t := (*tokens)[tok] switch t.Data { case "/;": - tmp, tok = parseBlock(tokens, tok, max) + tmp, tok = parseBlock(tokens, tok + 1, max) case ";": - tmp, tok = parseStatement(tokens, tok, max) + tmp, tok = parseStatement(tokens, tok + 1, max) case "/:": tmp, tok = parsePreBlock(tokens, tok + 1, max) case ":": diff --git a/src/tparse/type.go b/src/tparse/type.go index 7113c0b..b4ab2fe 100644 --- a/src/tparse/type.go +++ b/src/tparse/type.go @@ -72,18 +72,21 @@ func checkPreWord(s string) int { // RESWORD represents all the reserved words and what type of tokens they are. var RESWORD = map[string]int{ "bool": KEYTYPE, - "achar": KEYTYPE, - "uchar": KEYTYPE, + "char": KEYTYPE, + "charp": KEYTYPE, + "int": KEYTYPE, "int8": KEYTYPE, "int16": KEYTYPE, "int32": KEYTYPE, "int64": KEYTYPE, + "uint": KEYTYPE, "uint8": KEYTYPE, "uint16": KEYTYPE, "uint32": KEYTYPE, "uint64": KEYTYPE, + "float": KEYTYPE, "float32": KEYTYPE, "float64": KEYTYPE, |