-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (36 loc) · 863 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"flag"
"fmt"
"github.com/lxdlam/monkey-plus/bin"
"github.com/lxdlam/monkey-plus/evaluator"
"github.com/lxdlam/monkey-plus/repl"
"os"
user2 "os/user"
)
func init() {
evaluator.InitBuiltins()
}
func main() {
user, err := user2.Current()
if err != nil {
panic(err)
}
var code, path string
flag.StringVar(&code, "c", "", "the code should run")
flag.StringVar(&path, "f", "", "the source code file path")
flag.Parse()
if len(os.Args) == 1 {
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)
} else if code != "" {
bin.RunCode(code)
} else if path != "" {
bin.RunFile(path)
} else if len(os.Args) == 2 {
bin.RunFile(os.Args[1])
} else {
fmt.Println("Parsing command line parameter failed!")
}
}