-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (49 loc) · 1.26 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
// naiveconcat is a minimal concatenative programming language, built for fun.
// Work in progress.
package main
import (
"bufio"
_ "embed"
"flag"
"io/ioutil"
"log"
"os"
"github.com/brendantang/naiveconcat/data"
"github.com/brendantang/naiveconcat/eval"
"github.com/brendantang/naiveconcat/interpret"
)
//go:embed interpret/prelude.naiveconcat
var prelude string
func main() {
verbose := flag.Bool("verbose", false, "Print out the stack at each REPL loop")
coreOnly := flag.Bool("core", false, "Skip the standard library, start with built-ins only")
flag.Parse()
dict := eval.CoreDict()
stack := data.NewStack()
if !*coreOnly {
err := interpret.Interpret(prelude, dict, stack)
if err != nil {
log.Fatalf("error interpreting the standard library: %v", err)
}
}
cfg := interpret.Config{
Prompt: "> ",
Verbose: *verbose,
Input: bufio.NewReader(os.Stdin),
InitialDict: dict,
InitialStack: stack,
}
filepath := flag.Arg(0)
if filepath != "" {
content, err := ioutil.ReadFile(filepath)
if err != nil {
log.Fatalf("error reading input file: %s", err)
}
err = interpret.Interpret(string(content), dict, stack)
if err != nil {
log.Fatalf("interpreter error: %s", err)
}
} else {
log.Fatal(interpret.REPL(cfg))
}
}