-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
47 lines (42 loc) · 743 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 (
"fmt"
"io/ioutil"
"os"
"github.com/samertm/chompy/lex"
"github.com/samertm/chompy/parse"
"github.com/samertm/chompy/semantic"
)
var _ = fmt.Print // debugging
func main() {
if len(os.Args) < 2 {
fmt.Println("Expected filename")
return
}
filename := os.Args[1]
file, err := os.Open(filename)
if err != nil {
fmt.Println(err)
return
}
source, err := ioutil.ReadAll(file)
if err != nil {
fmt.Println(err)
return
}
compile(source)
}
func compile(src []byte) {
_, tokens := lex.Lex("bro", string(src))
tree, err := parse.Start(tokens)
if err != nil {
fmt.Println(err)
return
}
code, err := semantic.Gen(tree)
if err != nil {
fmt.Println(err)
return
}
fmt.Print(string(code))
}