-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (45 loc) · 1.01 KB
/
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
package main
import (
"fmt"
"os"
"os/user"
"github.com/yassinebenaid/nishimia/eval"
"github.com/yassinebenaid/nishimia/lexer"
"github.com/yassinebenaid/nishimia/object"
"github.com/yassinebenaid/nishimia/parser"
"github.com/yassinebenaid/nishimia/repl"
)
func main() {
if len(os.Args) < 2 {
Interactive()
os.Exit(0)
}
if len(os.Args) == 2 {
RunFile(os.Args[1])
os.Exit(0)
}
fmt.Println("undefined options", os.Args)
}
func Interactive() {
user, err := user.Current()
if err != nil {
panic(err)
}
fmt.Printf("Welcome %s , this is nishimia lang ready to get you excited ! \n", user.Username)
repl.Start(os.Stdin, os.Stdout)
fmt.Print("\nGood by !\n")
}
func RunFile(fn string) {
file, err := os.ReadFile(fn)
if err != nil {
fmt.Println("Error: \n\t", err)
}
env := object.NewEnvirement()
lex := lexer.New(string(file))
par := parser.New(lex)
program := par.ParseProgram()
result := eval.Eval(program, env)
if result.Type() != object.NULL_OBJ {
fmt.Println(result.Inspect())
}
}