pxasme/main.go

58 lines
734 B
Go
Raw Normal View History

2023-12-09 03:12:45 +00:00
package main
import (
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"os"
)
//
func main() {
src := flag.String("Src", "", "Input file")
flag.Parse()
fh, err := os.OpenFile(*src, os.O_RDONLY, 0644)
if err != nil {
panic(err)
}
assemble(fh, ioutil.Discard)
}
func assemble(src io.Reader, dest io.Writer) {
lx := NewLexer(src)
cc := NewCompiler()
mainloop:
2023-12-09 03:12:45 +00:00
for {
tok, err := lx.Next()
if err != nil {
if errors.Is(err, io.EOF) {
// Reached EOF
// Terminate compilation
break mainloop
2023-12-09 03:12:45 +00:00
}
// Real error
panic(err)
}
fmt.Printf("[line %d] %#v\n", lx.lineno, tok)
err = cc.Compile(tok)
if err != nil {
panic(err)
}
}
err := cc.Finalize(dest)
if err != nil {
panic(err)
}
2023-12-09 03:12:45 +00:00
}