summaryrefslogtreecommitdiff
path: root/src/tparse
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2021-10-31 22:25:05 -0400
committerKyle Gunger <kgunger12@gmail.com>2021-10-31 22:25:05 -0400
commit25e716cd730992baae64d7906b1d7eb5119f9d19 (patch)
tree0cdaebb25672b33f4d7cbdf4adc8bc8fe633fe96 /src/tparse
parent564c35e9f890d86d9f69e975881bcda4c6761487 (diff)
[AST] Bugfixes
+ Fix negative number parsing + Fix some keyword parsing bugs + Fix some value parsing bugs (self, super)
Diffstat (limited to 'src/tparse')
-rw-r--r--src/tparse/tree-statement.go13
-rw-r--r--src/tparse/tree-value.go11
-rw-r--r--src/tparse/type.go13
3 files changed, 27 insertions, 10 deletions
diff --git a/src/tparse/tree-statement.go b/src/tparse/tree-statement.go
index 718ad52..897f30d 100644
--- a/src/tparse/tree-statement.go
+++ b/src/tparse/tree-statement.go
@@ -62,14 +62,14 @@ func parseBlock(tokens *[]Token, tok, max int) (Node, int) {
switch t.Data {
case "operator":
name = true
- if (*tokens)[tok+1].Type != AUGMENT {
+ if (*tokens)[tok+1].Type != AUGMENT && (*tokens)[tok+1].Data != "delete" {
errOut("You must supply an operator to overload.", t)
} else if (*tokens)[tok+1].Data == "`" || (*tokens)[tok+1].Data == "~" {
errOut("You may not overload the following operators: '~', '`'.", t)
}
tmp.Data = (*tokens)[tok+1]
def.Sub = append(def.Sub, tmp)
- tok += 2
+ tok += 1
case "else":
name = true
sparse = true
@@ -150,7 +150,8 @@ func parseStatement(tokens *[]Token, tok, max int) (Node, int) {
var tmp Node
// Check for keyword, definition, then if none of those apply, assume it's a value.
- if (*tokens)[tok].Type == KEYWORD {
+ t := (*tokens)[tok]
+ if t.Type == KEYWORD && t.Data != "const" && t.Data != "volatile" && t.Data != "static" {
return keywordStatement(tokens, tok, max)
} else {
// do check for definition
@@ -200,6 +201,7 @@ func keywordStatement(tokens *[]Token, tok, max int) (Node, int) {
if (*tokens)[tok].Data == "(" {
tmp, tok = parseValueList(tokens, tok + 1, max)
out.Sub = append(out.Sub, tmp)
+ tok++
}
if (*tokens)[tok].Data != "{" {
@@ -207,6 +209,7 @@ func keywordStatement(tokens *[]Token, tok, max int) (Node, int) {
}
tmp, tok = parseParamList(tokens, tok + 1, max)
+ tok++
case "enum":
if (*tokens)[tok].Type != DEFWORD {
errOut("Expected defword after enum keyword.", (*tokens)[tok])
@@ -217,6 +220,7 @@ func keywordStatement(tokens *[]Token, tok, max int) (Node, int) {
if (*tokens)[tok].Data == "[" {
tmp, tok = parseTypeList(tokens, tok + 1, max)
out.Sub = append(out.Sub, tmp)
+ tok++
}
if (*tokens)[tok].Data != "{" {
@@ -224,6 +228,7 @@ func keywordStatement(tokens *[]Token, tok, max int) (Node, int) {
}
tmp, tok = parseValueList(tokens, tok + 1, max)
+ tok++
case "goto", "label":
if (*tokens)[tok].Type != DEFWORD {
errOut("Expected defword after goto or label keyword.", out.Data)
@@ -242,7 +247,7 @@ func keywordStatement(tokens *[]Token, tok, max int) (Node, int) {
if (*tokens)[tok].Type != DELIMIT || (*tokens)[tok].Data == "{" || (*tokens)[tok].Data == "(" {
tmp, tok = parseValueList(tokens, tok, max)
}
- case "alloc", "salloc":
+ case "alloc", "salloc", "realloc":
// Parse value list
tmp, tok = parseValueList(tokens, tok, max)
case "delete":
diff --git a/src/tparse/tree-value.go b/src/tparse/tree-value.go
index ac91873..d851fdc 100644
--- a/src/tparse/tree-value.go
+++ b/src/tparse/tree-value.go
@@ -24,6 +24,8 @@ var UNARY_PRE = map[string]int {
"++": 2,
"--": 2,
"!": 6,
+ "len": 0,
+ "-": 0,
}
var UNARY_POST = map[string]int {
@@ -211,7 +213,14 @@ func parseBinaryOp(tokens *[]Token, tok, max int) (Node) {
}
} else if t.Type == AUGMENT {
order, prs := ORDER[t.Data]
- if prs == false || curl > 0 || brak > 0 || parn > 0 {
+ if t.Data == "-" {
+ _, prs := ORDER[(*tokens)[tok - 1].Data]
+ if prs || (*tokens)[tok - 1].Data == "return" {
+ continue
+ } else if order > highOrder {
+ high, highOrder = tok, order
+ }
+ } else if prs == false || curl > 0 || brak > 0 || parn > 0 {
continue
} else if order > highOrder {
high, highOrder = tok, order
diff --git a/src/tparse/type.go b/src/tparse/type.go
index 1e51889..8a38527 100644
--- a/src/tparse/type.go
+++ b/src/tparse/type.go
@@ -120,8 +120,8 @@ var RESWORD = map[string]int{
"method": KEYWORD,
"override": KEYWORD,
- "self": KEYWORD,
- "super": KEYWORD,
+ "self": LITERAL,
+ "super": LITERAL,
"operator": KEYWORD,
"raw": KEYWORD,
@@ -131,9 +131,10 @@ var RESWORD = map[string]int{
"true": LITERAL,
"false": LITERAL,
- "alloc": KEYWORD,
- "calloc": KEYWORD,
- "delete": KEYWORD,
+ "alloc": KEYWORD,
+ "salloc": KEYWORD,
+ "realloc": KEYWORD,
+ "delete": KEYWORD,
"module": KEYWORD,
"export": KEYWORD,
@@ -277,6 +278,8 @@ var RESRUNES = map[string]int{
// Increment and De-increment
"++": AUGMENT,
"--": AUGMENT,
+
+ "len": AUGMENT,
}
func maxResRunes() int {