-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (37 loc) · 850 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
package main
import (
"bufio"
"fmt"
"os"
"github.com/nomad-software/bfg/cli"
"github.com/nomad-software/bfg/compiler/c"
"github.com/nomad-software/bfg/compiler/golang"
"github.com/nomad-software/bfg/compiler/nasm"
"github.com/nomad-software/bfg/evaluator"
"github.com/nomad-software/bfg/lexer"
)
func main() {
opt := cli.ParseOptions()
if opt.Help {
opt.PrintUsage()
return
}
program, err := os.ReadFile(opt.File)
if err != nil {
fmt.Printf("Can't read program file. %s\n", err.Error())
os.Exit(1)
}
tokens := lexer.New(program).Tokens
if opt.Go {
golang.Compile(tokens)
} else if opt.Nasm {
nasm.Compile(tokens)
} else if opt.C {
c.Compile(tokens)
} else {
input := bufio.NewReader(os.Stdin)
output := bufio.NewWriter(os.Stdout)
defer output.Flush()
evaluator.Evaluate(tokens, input, output)
}
}