-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequent.java
More file actions
103 lines (99 loc) · 2.55 KB
/
Sequent.java
File metadata and controls
103 lines (99 loc) · 2.55 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import java.util.ArrayList;
import java.lang.StringBuilder;
public class Sequent
{
public ArrayList<Formula> lhs;
public ArrayList<Formula> rhs;
public Sequent()
{
lhs = new ArrayList<Formula>();
rhs = new ArrayList<Formula>();
}
public Sequent(ArrayList<Formula> lhs, ArrayList<Formula> rhs)
{
this.lhs = lhs;
this.rhs = rhs;
}
public Sequent(String s)
{
Sequent ans = Sequent.parse(s);
this.lhs = ans.lhs;
this.rhs = ans.rhs;
}
public Sequent deepCopy()
{
ArrayList<Formula> left = new ArrayList<>(), right = new ArrayList<>();
for(Formula f: lhs)
{
left.add(f);
}
for(Formula f: rhs)
{
right.add(f);
}
return new Sequent(left, right);
}
public static Sequent parse(String s)
{
// look for substring "|-"
// if not found append at beginning
// split across "|-"
// split rhs and lhs along ','
// trim individual string for spaces
// run formula.parse on each split string, add to arraylist
String[] sParsed;
Sequent sq = new Sequent();
if(s.contains("|-"))
{
sParsed = s.split("\\|\\-");
}
else
{
sParsed = new String[2];
sParsed[0] = "";
sParsed[1] = s;
}
sParsed[0] = sParsed[0].trim();
sParsed[1] = sParsed[1].trim();
if(sParsed[0].length() == 0) sParsed[0] = "T";
if(sParsed[1].length() == 0) sParsed[1] = "L";
String[] lStr = sParsed[0].split(",");
String[] rStr = sParsed[1].split(",");
for(String i: lStr)
{
sq.lhs.add(new Formula(i));
}
for(String i: rStr)
{
sq.rhs.add(new Formula(i));
}
return sq;
}
public String toString()
{
StringBuilder sb = new StringBuilder();
int i;
try
{
sb.append(lhs.get(0).toString());
for(i = 1; i < lhs.size(); i++)
{
sb.append(", ");
sb.append(lhs.get(i));
}
}
catch(Exception e) {}
sb.append(" |- ");
try
{
sb.append(rhs.get(0).toString());
for(i = 1; i < rhs.size(); i++)
{
sb.append(", ");
sb.append(rhs.get(i));
}
}
catch(Exception e) {}
return sb.toString();
}
}