This commit is contained in:
unintendedfraud
2024-03-17 23:09:12 +01:00
commit b073f8f039
7 changed files with 411 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
package repl
import (
"bufio"
"fmt"
"gointerpreter/lexer"
"gointerpreter/token"
"io"
)
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)
}
}
}