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