|
|
|
@ -88,6 +88,20 @@ func eval(v interface{}) {
|
|
|
|
|
fmt.Println(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func evalall(c chan token) {
|
|
|
|
|
for {
|
|
|
|
|
v, err := parse(c)
|
|
|
|
|
switch err {
|
|
|
|
|
case io.EOF:
|
|
|
|
|
return
|
|
|
|
|
case nil:
|
|
|
|
|
eval(v)
|
|
|
|
|
default:
|
|
|
|
|
fmt.Println("error in eval: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func args() {
|
|
|
|
|
filename := os.Args[1]
|
|
|
|
|
f, err := os.Open(filename)
|
|
|
|
@ -99,18 +113,7 @@ func args() {
|
|
|
|
|
|
|
|
|
|
c := make(chan token, 32)
|
|
|
|
|
go lex(bufio.NewReader(f), c)
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
v, err := parse(c)
|
|
|
|
|
switch err {
|
|
|
|
|
case io.EOF:
|
|
|
|
|
return
|
|
|
|
|
case nil:
|
|
|
|
|
eval(v)
|
|
|
|
|
default:
|
|
|
|
|
fmt.Println("error in args(): %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
evalall(c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
@ -139,17 +142,6 @@ func main() {
|
|
|
|
|
|
|
|
|
|
c := make(chan token, 32)
|
|
|
|
|
go lexs(string(line)+"\n", c)
|
|
|
|
|
for {
|
|
|
|
|
v, err := parse(c)
|
|
|
|
|
switch err {
|
|
|
|
|
case io.EOF:
|
|
|
|
|
goto OUT
|
|
|
|
|
case nil:
|
|
|
|
|
eval(v)
|
|
|
|
|
default:
|
|
|
|
|
fmt.Println("error in repl: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
OUT:
|
|
|
|
|
evalall(c)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|