Mako/repl.go
2025-05-06 12:09:17 -05:00

46 lines
747 B
Go

// File: cmd/main.go
package main
import (
"bufio"
"fmt"
"os"
"git.sharkk.net/Sharkk/Mako/compiler"
"git.sharkk.net/Sharkk/Mako/lexer"
"git.sharkk.net/Sharkk/Mako/parser"
"git.sharkk.net/Sharkk/Mako/vm"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
virtualMachine := vm.New()
fmt.Println("Mako REPL (type 'exit' to quit)")
for {
fmt.Print(">> ")
if !scanner.Scan() {
break
}
input := scanner.Text()
if input == "exit" {
break
}
lex := lexer.New(input)
p := parser.New(lex)
program := p.ParseProgram()
if len(p.Errors()) > 0 {
for _, err := range p.Errors() {
fmt.Printf("Error: %s\n", err)
}
continue
}
bytecode := compiler.Compile(program)
virtualMachine.Run(bytecode)
}
}