summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/exec.go46
-rw-r--r--src/parse.go (renamed from src/main.go)14
-rw-r--r--src/tparse/token.go6
-rw-r--r--src/tparse/tree-statement.go10
-rw-r--r--src/tparse/tree.go2
-rw-r--r--src/tparse/type.go4
6 files changed, 72 insertions, 10 deletions
diff --git a/src/exec.go b/src/exec.go
new file mode 100644
index 0000000..f92f435
--- /dev/null
+++ b/src/exec.go
@@ -0,0 +1,46 @@
+/*
+ Copyright 2020 Kyle Gunger
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package main
+
+import "fmt"
+import "tparse"
+import "texec"
+import "flag"
+
+func main() {
+ inputFile := flag.String("in", "", "The file to execute")
+ progFlags := flag.String("flags", "", "Flags for the executing program")
+
+ flag.Parse()
+
+ if err != nil {
+ fmt.Println(err.Error())
+ return
+ }
+
+ tokens := tparse.TokenizeFile(*inputFile)
+
+ switch *writeLevel {
+ case 0:
+ fd.WriteString(fmt.Sprint(tokens) + "\n")
+ case 1:
+ tree := tparse.MakeTree(&tokens, *inputFile)
+ fd.WriteString(fmt.Sprint(tree) + "\n")
+ }
+
+ fd.Close()
+} \ No newline at end of file
diff --git a/src/main.go b/src/parse.go
index e6efcd9..7849857 100644
--- a/src/main.go
+++ b/src/parse.go
@@ -24,6 +24,7 @@ import "os"
func main() {
inputFile := flag.String("in", "", "The file to parse")
outputFile := flag.String("out", "out.tnt", "The file to store the node tree")
+ writeLevel := flag.Int("writelevel", 1, "The level of parsing to write to the file (for debugging)")
flag.Parse()
@@ -35,9 +36,14 @@ func main() {
}
tokens := tparse.TokenizeFile(*inputFile)
- tree := tparse.MakeTree(&tokens, *inputFile)
-
- fd.WriteString(fmt.Sprint(tree) + "\n")
-
+
+ switch *writeLevel {
+ case 0:
+ fd.WriteString(fmt.Sprint(tokens) + "\n")
+ case 1:
+ tree := tparse.MakeTree(&tokens, *inputFile)
+ fd.WriteString(fmt.Sprint(tree) + "\n")
+ }
+
fd.Close()
}
diff --git a/src/tparse/token.go b/src/tparse/token.go
index 182b2e0..02502eb 100644
--- a/src/tparse/token.go
+++ b/src/tparse/token.go
@@ -27,6 +27,12 @@ type Token struct {
// Node represents a node in an AST
type Node struct {
Data Token
+
+ IsBlock bool
+ BlockQs []Token
+ BlockIn []Node
+ BlockOut []Node
+
Sub []Node
}
diff --git a/src/tparse/tree-statement.go b/src/tparse/tree-statement.go
index 874528a..167cee2 100644
--- a/src/tparse/tree-statement.go
+++ b/src/tparse/tree-statement.go
@@ -23,6 +23,9 @@ func parseBlock(tokens *[]Token, tok, max int) (Node, int) {
tok++
+ def := Node{}
+ def.Data = Token{Type: 10, Data: "blockdef"}
+
for ;tok < max; tok++{
t := (*tokens)[tok]
@@ -30,14 +33,15 @@ func parseBlock(tokens *[]Token, tok, max int) (Node, int) {
case DELIMIT:
if t.Data == "(" {
tmp, tok = parseParamList(tokens, tok, max)
- out.Sub = append(out.Sub, tmp)
+ def.Sub = append(out.Sub, tmp)
} else if t.Data == "[" {
tmp, tok = parseTypeList(tokens, tok, max)
- out.Sub = append(out.Sub, tmp)
+ def.Sub = append(out.Sub, tmp)
} else {
goto BREAK
}
case DEFWORD:
+
case KEYWORD:
case LINESEP:
goto BREAK
@@ -46,6 +50,8 @@ func parseBlock(tokens *[]Token, tok, max int) (Node, int) {
BREAK:
+ out.Sub = append(out.Sub, def)
+
for ;tok < max; {
t := (*tokens)[tok]
diff --git a/src/tparse/tree.go b/src/tparse/tree.go
index 9e9e554..08c94bf 100644
--- a/src/tparse/tree.go
+++ b/src/tparse/tree.go
@@ -19,7 +19,7 @@ package tparse
import "fmt"
// ID 9 = ast root
-// ID 10 = ast list
+// ID 10 = ast token
func errOut(message string, token Token) {
fmt.Println(message)
diff --git a/src/tparse/type.go b/src/tparse/type.go
index 73bb94d..b860f02 100644
--- a/src/tparse/type.go
+++ b/src/tparse/type.go
@@ -50,7 +50,7 @@ var PREWORDS = []string{
"extern",
"size",
"align",
- "origin",
+ "address",
"rootfile",
"if",
"else",
@@ -130,8 +130,6 @@ var RESWORD = map[string]int{
"module": KEYWORD,
"export": KEYWORD,
-
- "drop": KEYWORD,
}
func checkResWord(s string) int {