| 1234567891011121314151617181920212223242526272829303132333435363738 |
- package repl
- import (
- "bufio"
- "fmt"
- "github/runnignwater/monkey/lexer"
- "github/runnignwater/monkey/token"
- "io"
- )
- /**
- * @Author: simon
- * @Author: ynwdlxm@163.com
- * @Date: 2022/10/2 下午5:41
- * @Desc: REPL that tokenizes Monkey source code and prints the tokens
- */
- const PROMPT = ">>> "
- func Start(in io.Reader, out io.Writer) {
- scanner := bufio.NewScanner(in)
- for {
- fmt.Printf(PROMPT)
- scan := scanner.Scan()
- if !scan {
- return
- }
- line := scanner.Text()
- l := lexer.New(line)
- for tok := l.NextToken(); tok.Type != token.EOF; tok = l.NextToken() {
- fmt.Printf("%+v\n", tok)
- }
- }
- }
|