2024-03-10 22:48:57 +01:00
|
|
|
// The compiler
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) != 2 {
|
|
|
|
log.Fatalln("Usage: " + os.Args[0] + " <file>")
|
|
|
|
}
|
|
|
|
|
|
|
|
content, err := os.ReadFile(os.Args[1])
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("Cannot open input file.", err)
|
|
|
|
}
|
|
|
|
|
2024-03-11 22:05:36 +01:00
|
|
|
tokens, err := lexer(string(content))
|
2024-03-10 22:48:57 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2024-03-11 22:05:36 +01:00
|
|
|
log.Printf("Tokens:\n%+#v\n\n", tokens)
|
|
|
|
|
|
|
|
parsed, err := parser(tokens)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("Parsed:\n%+#v\n\n", parsed)
|
2024-03-10 22:48:57 +01:00
|
|
|
}
|