This commit is contained in:
Tyrel Souza 2021-11-30 16:21:32 -05:00
parent 7e9304ed11
commit b8d8e30f0f
2 changed files with 49 additions and 0 deletions

18
main.go
View File

@ -1 +1,19 @@
package main
import (
"fmt"
"os"
"os/user"
"gitlab.com/Tyrel/monkey/repl"
)
func main() {
user, err := user.Current()
if err != nil {
panic(err)
}
fmt.Printf("Hello %s! This is the Monkey programming language!\n", user.Username)
fmt.Printf("Feel free to type in commands\n")
repl.Start(os.Stdin, os.Stdout)
}

31
repl/repl.go Normal file
View File

@ -0,0 +1,31 @@
package repl
import (
"bufio"
"fmt"
"io"
"gitlab.com/Tyrel/monkey/lexer"
"gitlab.com/Tyrel/monkey/token"
)
const PROMPT = ">> "
func Start(in io.Reader, out io.Writer) {
scanner := bufio.NewScanner(in)
for {
fmt.Printf(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.Printf("%+v\n", tok)
}
}
}