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:
parent
cebc052f32
commit
fec8dd9152
31
repl/repl.go
Normal file
31
repl/repl.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user