add basic repl

This commit is contained in:
Chuck Smith
2024-01-14 21:35:27 -05:00
parent 1e9bd34a84
commit d1e11bde19
2 changed files with 49 additions and 0 deletions

30
repl/repl.go Normal file
View File

@@ -0,0 +1,30 @@
package repl
import (
"bufio"
"fmt"
"io"
"monkey/lexer"
"monkey/token"
)
const PROMPT = ">> "
func Start(in io.Reader, out io.Writer) {
scanner := bufio.NewScanner(in)
for {
fmt.Fprintf(out, PROMPT)
scanned := scanner.Scan()
if !scanned {
return
}
line := scanner.Text()
l := lexer.New(line)
for tok := l.NextToken(); tok.Type != token.EOF; tok = l.NextToken() {
fmt.Fprintf(out, "%+v\n", tok)
}
}
}