-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (49 loc) · 913 Bytes
/
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
package main
import (
"os"
"os/signal"
"syscall"
"github.com/dyzsr/mylisp/compiletime"
"github.com/dyzsr/mylisp/parser"
"github.com/dyzsr/mylisp/repl"
"github.com/dyzsr/mylisp/runtime"
"github.com/dyzsr/mylisp/token"
)
func main() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT)
go func() {
for {
sig := <-sigs
println("\n~", sig.String())
}
}()
lex := token.NewLexer(os.Stdin)
par := parser.NewParser(lex)
ct := compiletime.NewCompileTime()
rt := runtime.NewRuntime()
prt := repl.NewPrinter()
eprt := repl.NewErrorPrinter()
for {
expr, ok := par.Next()
if !ok {
err := par.Err()
if err == nil { // EOF
break
}
eprt.Print(err)
continue
}
expr, err := ct.Eval(expr)
if err != nil {
eprt.Print(err)
continue
}
result, err := rt.Eval(expr)
if err != nil {
eprt.Print(err)
} else {
prt.Print(result)
}
}
}