-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (56 loc) · 1.08 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
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
"github.com/jonbodner/my_lisp/evaluator"
"github.com/jonbodner/my_lisp/global"
"github.com/jonbodner/my_lisp/parser"
"github.com/jonbodner/my_lisp/scanner"
"github.com/jonbodner/my_lisp/types"
)
func main() {
bio := bufio.NewReader(os.Stdin)
done := false
depth := 0
var tokens []types.Token
for !done {
line, err := bio.ReadString('\n')
if err != nil {
if err != io.EOF {
log.Fatal(err)
}
done = true
continue
}
newTokens, newDepth := scanner.Scan(line)
depth = depth + newDepth
if depth < 0 {
fmt.Println("Invalid -- Too many closing parens")
depth = 0
tokens = []types.Token{}
continue
}
tokens = append(tokens, newTokens...)
if depth == 0 {
//global.Log(tokens)
expr, _, err := parser.Parse(tokens)
//global.Log(expr)
//global.Log(pos)
//global.Log(err)
if err != nil {
global.Log(err)
} else {
result, err := evaluator.Eval(expr)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(result)
}
}
tokens = []types.Token{}
}
}
}