-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
87 lines (71 loc) · 1.33 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"sht/lang"
"sht/lang/runtime"
"sht/lang/utils"
)
// var sample1 = `a++`
// var sample1 = `a!`
var sample1 = `a?`
var sample2 = `
a := List {}
a.push(1)
a.push(2)
a.push(3)
a.push(4)
a.pop()
a.pop(0)
print(a)
`
func main() {
input := []byte(sample2)
fmt.Println("")
fmt.Println("-----------------------------------")
fmt.Println(" oh SHT! ")
fmt.Println("-----------------------------------")
fmt.Println("")
testTokens(input)
fmt.Println("")
fmt.Println("-----------------------------------")
fmt.Println("")
testParser(input)
fmt.Println("")
fmt.Println("-----------------------------------")
fmt.Println("")
testRuntime(input)
fmt.Println("")
fmt.Println("-----------------------------------")
}
func testTokens(input []byte) {
tokens, err := lang.Tokenize(input)
if err != nil {
fmt.Println(err)
return
}
for _, token := range tokens {
fmt.Println(token.Pretty())
}
}
func testParser(input []byte) {
tree, err := lang.Parse(input)
if err != nil {
fmt.Println(err)
return
}
utils.PrintAst(tree)
}
func testRuntime(input []byte) {
tree, err := lang.Parse(input)
if err != nil {
fmt.Println(err)
return
}
runtime := runtime.CreateRuntime()
res, err := runtime.Run(tree)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("<<<", res)
}