-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
60 lines (48 loc) · 950 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"os"
"github.com/emo-lang/emo/evaluator"
"github.com/emo-lang/emo/lexer"
"github.com/emo-lang/emo/object"
"github.com/emo-lang/emo/parser"
"github.com/emo-lang/emo/repl"
)
func main() {
if len(os.Args) == 1 {
fmt.Println("emo [action] [...]")
os.Exit(1)
}
action := os.Args[1]
switch action {
case "run":
run(os.Args[2:])
case "repl":
repl.Start(os.Stdin, os.Stdout)
default:
fmt.Println("Unknown action: ", action)
}
}
func run(args []string) {
if len(args) == 0 {
fmt.Println("emo run [filename]")
os.Exit(1)
}
filename := args[0]
data, err := os.ReadFile(filename)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
l := lexer.New(string(data))
p := parser.New(l)
program := p.ParseProgram()
if len(p.Errors()) != 0 {
for _, msg := range p.Errors() {
fmt.Printf("Err: %s\n", msg)
}
os.Exit(1)
}
env := object.NewEnvironment()
evaluator.Eval(program, env)
}