holy carp it parses
This commit is contained in:
parent
dc89e81cc5
commit
edcbfde351
3 changed files with 240 additions and 6 deletions
25
main.go
25
main.go
|
|
@ -29,10 +29,10 @@ func runFile(filename string) {
|
|||
bs, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
fmt.Printf("unable to read file '%s':\n\t%s", filename, err.Error())
|
||||
os.Exit(1)
|
||||
os.Exit(64)
|
||||
}
|
||||
|
||||
if run(string(bs)) {
|
||||
if !run(string(bs)) {
|
||||
os.Exit(65)
|
||||
}
|
||||
}
|
||||
|
|
@ -59,20 +59,33 @@ func run(source string) bool {
|
|||
s := newScanner(source)
|
||||
tokens, ok := s.ScanTokens()
|
||||
if !ok {
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
for _, token := range tokens {
|
||||
fmt.Println(token)
|
||||
p := newParser(tokens)
|
||||
expr, err := p.Parse()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
printer := &astPrinter{}
|
||||
fmt.Println(printer.print(expr))
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func reportErr(line int, message string) {
|
||||
report(line, "", message)
|
||||
}
|
||||
|
||||
func reportSyntaxError(token *token, message string) {
|
||||
if token.Type == tokenTypeEOF {
|
||||
report(token.Line, "at EOF", message)
|
||||
} else {
|
||||
report(token.Line, "at \""+token.Lexeme+"\"", message)
|
||||
}
|
||||
}
|
||||
|
||||
func report(line int, where, message string) {
|
||||
fmt.Printf("[line %d] Error%s: %s\n", line, where, message)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue