summaryrefslogtreecommitdiff
path: root/src/tparse/tree-statement.go
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/tree-statement.go
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/tree-statement.go')
-rw-r--r--src/tparse/tree-statement.go13
1 files changed, 9 insertions, 4 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":