-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d9c928
commit df50bca
Showing
4 changed files
with
157 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/user" | ||
|
||
"github.com/zizouhuweidi/go-terpreter/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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package repl | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/zizouhuweidi/go-terpreter/lexer" | ||
"github.com/zizouhuweidi/go-terpreter/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) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters