-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolTable.java
More file actions
69 lines (58 loc) · 1.81 KB
/
Copy pathSymbolTable.java
File metadata and controls
69 lines (58 loc) · 1.81 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
package FinalProject;
import java.util.*;
public class SymbolTable{
HashMap<String, SymbolTE> globalvars;
HashMap<String, SymbolTE> methods;
HashMap<String, SymbolTE> classes;
SymbolTable(){
globalvars = new HashMap<String, SymbolTE>();
methods = new HashMap<String, SymbolTE>();
classes = new HashMap<String, SymbolTE>();
}
boolean addVar(Variable m){
if (!containsVar(m.name)){
globalvars.put(m.name, m);
return true;
}
return false;
}
boolean containsVar(String id){
return globalvars.containsKey(id);
}
Variable getVar(String id){
return (Variable)(globalvars.get(id));
//throw new Exception("method not yet created");
//return new Variable("error", "error");
}
boolean addMethod(Method m){
if (!containsMethod(m.name)){
methods.put(m.name, m);
return true;
}
return false;
}
boolean containsMethod(String id){
return methods.containsKey(id);
}
Method getMethod(String id){
return (Method)(methods.get(id));
//throw new Exception("method not yet created");
//return new Method("error", "error");
}
public void print(){
System.out.println("globalvars");
Variable[] arr = globalvars.values().toArray(new Variable[0]);
System.out.println("{");
for (int i = 0; i < arr.length; i++){
System.out.println(arr[i].print());
}
System.out.println("}");
System.out.println("methods");
Method[] arr2 = methods.values().toArray(new Method[0]);
System.out.println("{");
for (int i = 0; i < arr2.length; i++){
System.out.println(arr2[i].print());
}
System.out.println("}");
}
}