-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSequentProver.java
86 lines (64 loc) · 1.96 KB
/
SequentProver.java
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
76
77
78
79
80
81
82
83
84
85
86
import java.util.*;
abstract class Formula {}
class AtomicFormula extends Formula {
Character c;
public AtomicFormula(Character c) {
this.c = c;
}
public String toString() {
return c.toString();
}
}
class NegationFormula extends Formula {
Formula formula;
public NegationFormula(Formula formula) {
this.formula = formula;
}
public String toString() {
return "-" + formula;
}
}
class ConjunctionFormula extends Formula {
Formula formula1, formula2;
public ConjunctionFormula(Formula formula1, Formula formula2) {
this.formula1 = formula1;
this.formula2 = formula2;
}
public String toString() {
return "&" + formula1 + formula2;
}
}
public class SequentProver {
public static Formula parse(Deque<Character> input) throws Exception {
if (input.size() == 0) {
throw new Exception("parse error");
}
Character token = input.pop();
if (Character.isLowerCase(token)) {
return new AtomicFormula(token);
} else if (token == '-') {
return new NegationFormula(parse(input));
} else if (token == '&') {
return new ConjunctionFormula(parse(input), parse(input));
} else {
throw new Exception("parse error");
}
}
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
Deque<Character> input = new ArrayDeque<Character>();
while (in.hasNextLine()) {
String line = in.nextLine();
line = line.replaceAll("\\s+", "");
for (int i=0; i<line.length(); i++) {
input.add(line.charAt(i));
}
}
Formula f = parse(input);
if (input.size() > 0) {
throw new Exception("parse error");
}
System.out.println(f);
// Run theorem prover on sequent made from formula `f` here.
}
}