diff --git a/main.go b/main.go index 06ab7d0..09c4a11 100644 --- a/main.go +++ b/main.go @@ -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) +} diff --git a/repl/repl.go b/repl/repl.go new file mode 100644 index 0000000..c19bd8a --- /dev/null +++ b/repl/repl.go @@ -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) + } + + } + +}