elysium/main.go

55 lines
1.0 KiB
Go
Raw Normal View History

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 {
2024-03-14 16:42:22 +01:00
if c, ok := err.(CompilerError); ok {
log.Fatalln(err, "\nv- here\n"+string([]rune(string(content))[c.Position:]))
}
2024-03-10 22:48:57 +01:00
log.Fatalln(err)
}
2024-03-11 22:05:36 +01:00
log.Printf("Tokens:\n%+#v\n\n", tokens)
2024-03-13 17:17:09 +01:00
parser := Parser{Tokens: tokens}
2024-03-12 22:47:45 +01:00
parsed, err := parser.parseFile()
2024-03-11 22:05:36 +01:00
if err != nil {
2024-03-13 23:26:20 +01:00
if c, ok := err.(CompilerError); ok {
log.Fatalln(err, "\nv- here\n"+string([]rune(string(content))[c.Position:]))
}
2024-03-11 22:05:36 +01:00
log.Fatalln(err)
}
log.Printf("Parsed:\n%+#v\n\n", parsed)
2024-03-16 20:12:00 +01:00
errors := validator(parsed)
if len(errors) != 0 {
for _, err = range errors {
if c, ok := err.(CompilerError); ok {
log.Fatalln(err, "\nv- here\n"+string([]rune(string(content))[c.Position:]))
}
log.Fatalln(err)
}
}
2024-03-17 19:55:28 +01:00
log.Printf("Validated:\n%+#v\n\n", parsed)
2024-03-10 22:48:57 +01:00
}