46 lines
755 B
Go
46 lines
755 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("LuaGo Interpreter (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)
|
|
}
|
|
}
|