blob: 0757541063de3ffc474cc8846853067a7d240db8 (
plain)
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 st;
import java.util.*;
public class SymbolTable {
private HashMap<String,AbstractInstance> symt;
public SymbolTable() {
this.symt = new HashMap<>();
}
public String toString() {
StringBuilder mapAsString = new StringBuilder("{");
for (String key : this.symt.keySet()) {
mapAsString.append(key + ":" + this.symt.get(key) + ", ");
}
mapAsString.delete(mapAsString.length()-2, mapAsString.length()).append("}");
return mapAsString.toString();
}
public void addMethod() {
this.
}
public void put(String id, AbstractInstance symbol) {
this.symt.put(id, symbol);
}
public TypeInstance getType(String index) {
AbstractInstance symbol;
return ((symbol = this.symt.get(index)) !=
null && symbol.getType() != TypeEnum.classname &&
symbol.getType() != TypeEnum.method) ?
(TypeInstance) symbol : null;
}
public MethodInstance getMethod(String index) {
AbstractInstance symbol;
return ((symbol = this.symt.get(index)) !=
null && symbol.getType() == TypeEnum.method) ?
(MethodInstance) symbol : null;
}
public ClassInstance getClass(String index) {
AbstractInstance symbol;
return ((symbol = this.symt.get(index)) !=
null && symbol.getType() == TypeEnum.classname) ?
(ClassInstance) symbol : null;
}
}
|