-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
77 lines (66 loc) · 1.82 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"github.com/elk-language/elk/repl"
)
// Main entry point to the interpreter.
func main() {
command := os.Args[1]
switch command {
case "repl":
fs := flag.NewFlagSet("repl", flag.ContinueOnError)
disassemble := fs.Bool("disassemble", false, "run the REPL in disassembler mode")
inspectStack := fs.Bool("inspect-stack", false, "print the stack after each iteration of the REPL")
parse := fs.Bool("parse", false, "run the REPL in parser mode")
lex := fs.Bool("lex", false, "run the REPL in lexer mode")
typecheck := fs.Bool("typecheck", false, "run the REPL in type checker mode")
fs.Parse(os.Args[2:])
repl.Run(*disassemble, *inspectStack, *parse, *lex, *typecheck)
case "run":
runFile(os.Args[2])
default:
os.Exit(64)
}
}
// Attempt to execute the given file.
func runFile(fileName string) {
absFileName, err := filepath.Abs(fileName)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not find file `%s`\n", fileName)
os.Exit(1)
}
_, err = os.Stat(absFileName)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not find file `%s`\n", absFileName)
os.Exit(1)
}
source, err := os.ReadFile(absFileName)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not read file `%s`\n", absFileName)
os.Exit(1)
}
runSourceWithName(absFileName, source)
}
// Run the given string of source code with
// the specified name.
func runSourceWithName(sourceName string, source []byte) {
// ast, err := parser.Parse(source)
// pp.Println(ast)
// pp.Println(err)
// lex := lexer.NewWithName(sourceName, source)
// for {
// token := lex.Next()
// pp.Println(token)
// if token.Type == token.END_OF_FILE {
// break
// }
// }
}
// Run the given slice of bytes containing
// Elk source code.
func runSource(source []byte) {
runSourceWithName("(eval)", source)
}