-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymbolTable.java
52 lines (42 loc) · 950 Bytes
/
SymbolTable.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
package compiler;
import java.util.ArrayList;
public class SymbolTable {
public ArrayList<DSCP> SYMTB = new ArrayList<DSCP>();
public void insert(DSCP dscp) {
SYMTB.add(dscp);
}
public DSCP get(Entry entry) {
for (DSCP i : SYMTB)
if (entry.equals(i))
return i;
return null;
}
public boolean contains(Entry entry) {
for (DSCP i : SYMTB)
if (entry.equals(i))
return true;
return false;
}
public void remove(Entry entry){
DSCP toBeRemoved=null;
for (DSCP i : SYMTB)
if (entry.equals(i))
toBeRemoved = i;
SYMTB.remove(toBeRemoved);
}
public void update(DSCP dscp){
Entry temp = new Entry();
temp.CV = dscp.CV;
temp.level = dscp.level;
remove(temp);
insert(dscp);
}
public void flush(int level){
ArrayList<DSCP> toBeRemoved= new ArrayList<DSCP>();
for (DSCP i : SYMTB)
if (i.level==(level))
toBeRemoved.add(i);
for(DSCP i : toBeRemoved)
SYMTB.remove(i);
}
}