-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (41 loc) · 839 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/CaptainCarpensir/AutomatonEncoder/packages/automaton"
)
func main() {
var (
input string
machine *automaton.Automaton
)
if len(os.Args) != 2 {
fmt.Println("command requires one filename argument")
return
}
data, err := ioutil.ReadFile(os.Args[1])
if err != nil {
fmt.Printf("read file: %e\n", err)
return
}
machine, err = automaton.EncodeAutomaton(data)
if err != nil {
fmt.Println(err)
return
}
fmt.Print("Enter a word to be recognized by the automaton: ")
for {
fmt.Print("\033[s")
fmt.Scanln(&input)
inLang := machine.Recognize(input)
color := 32
if !inLang {
color = 31
}
fmt.Printf("Automaton recognizes '%s': \033[%vm%v", input, color, inLang)
fmt.Print("\033[K")
fmt.Print("\033[u")
fmt.Print("\033[K")
}
}