-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
45 lines (39 loc) · 877 Bytes
/
Copy pathmain.go
File metadata and controls
45 lines (39 loc) · 877 Bytes
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
package main
import (
"fmt"
"io"
"os"
"github.com/aselhid/indoscript/internal/ast"
"github.com/aselhid/indoscript/internal/interpreter"
"github.com/aselhid/indoscript/internal/lexer"
)
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: indoscript [script].indos")
os.Exit(1)
}
filename := os.Args[1]
if err := runFile(filename); err != nil {
reportError(err)
os.Exit(1) // TODO: return exit code based on err
}
}
func runFile(filename string) error {
file, err := os.Open(filename)
if err != nil {
return err
}
run(file)
return nil
}
func run(reader io.Reader) {
scanner := lexer.NewScanner(reader, os.Stderr)
tokens := scanner.ScanTokens()
parser := ast.NewParser(tokens)
stmts, hasError := parser.Parse()
if hasError {
os.Exit(1)
}
interpreter := interpreter.NewInterpreter(os.Stdout, os.Stderr)
interpreter.Interpret(stmts)
}