Basic READ-EVALUATE-PRINT-LOOP

git-svn-id: https://svn.tlawal.org/svn/monkey@3 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
This commit is contained in:
Tijani Lawal 2022-05-12 22:15:41 +00:00
parent cebc052f32
commit fec8dd9152

31
repl/repl.go Normal file
View File

@ -0,0 +1,31 @@
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.next_token(); tok.Type != token.EOF; tok = l.next_token(){
fmt.Fprintf(out, "%+v\n", tok)
}
}
}