-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (59 loc) · 1.3 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"bufio"
"os"
"fmt"
"log"
)
var _optMap map[string]bool
func main() {
options := os.Args[1:]
_optMap = make(map[string]bool)
for _, opt := range options {
_optMap[opt] = true
}
if _optMap["--no-interactive"] {
var expPtr *Expression
var exp Expression
// define a custom expression to be evaluated
a := Term("a")
b := Term("b")
c := Term("c")
expPtr = Implication( Implication(a, c), Implication( Implication(b, c), Implication(Disjunction(a, b), c)))
exp = *expPtr
if _optMap["--debug-parse"] {
fmt.Println("expression: ", exp.Printexp(), "\n")
}
valid := exp.Proove()
if valid {
fmt.Println("VALID")
} else {
fmt.Println("INVALID")
}
return
}
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Print(">> ")
scanner.Scan()
err := scanner.Err()
if err != nil {
log.Fatal(err)
}
if scanner.Text() == "" {
continue
}
tokens := Tokenise(scanner.Text())
exp := Parse(tokens)
if _optMap["--debug-parse"] {
fmt.Println("tokens: ", tokens)
fmt.Println("expression: ", exp.Printexp(), "\n")
}
valid := exp.Proove()
if valid {
fmt.Println("VALID")
} else {
fmt.Println("INVALID")
}
}
}