-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKCFA.java
More file actions
81 lines (64 loc) · 1.68 KB
/
Copy pathKCFA.java
File metadata and controls
81 lines (64 loc) · 1.68 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
package kcfa;
import java.util.Deque;
import java.util.ArrayDeque;
import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;
import data.Contour;
import data.Env;
import data.Store;
import syntaxtree.*;
public class KCFA{
static int k = 1;
static NextState nextStateVisitor;
public static void setK(int i){
nextStateVisitor = new NextState();
k = i;
}
public static int getK(){
return k;
}
public static State makeInitalState(Program p){
Env env = new Env();
State state = new State(p,env, new Store(), new Contour());
p.accept(nextStateVisitor, state); // Set intitalState
return state;
}
public static Set<State> explore(State state){
Set<State> seen = new HashSet<State>();
Deque<State> todo = new ArrayDeque<State>();
todo.push(state);
while(!todo.isEmpty()){
try {
State nextState = todo.pop();
System.out.println("====Next====");
System.out.println(nextState);
/*System.out.println("====Seen====BEGIN");
System.out.println(seen);
System.out.println("====Seen====End");
*/
if (seen.contains(nextState)){
System.out.println("SAME!!");
continue;
}
seen.add(nextState);
Set<State> newStates = nextState.next(nextStateVisitor);
if ( newStates != null ) { // Not End of Program
todo.addAll(newStates);
}
} catch (GrammarException e){
System.err.print(e);
}
}
return seen;
}
public static Store summarize(Set<State> states){
Iterator<State> iter = states.iterator();
if ( !iter.hasNext() ) return null;
Store firstStore = iter.next().getStore();
while(iter.hasNext()){
firstStore.join(iter.next().getStore());
}
return firstStore;
}
}