-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolTable.java
More file actions
67 lines (52 loc) · 1.31 KB
/
SymbolTable.java
File metadata and controls
67 lines (52 loc) · 1.31 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
package ParserPackage;
import java.util.ArrayList;
import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory.Default;
public class SymbolTable {
private ArrayList<SymbolT> Symbols = new ArrayList();
public void add(Token name, Token typeName){
SymbolT newSy = new SymbolT(name.toString(), typeName.toString());
if(!check(newSy)) {
Symbols.add(newSy);
}
}
public void printList(){
System.out.println("In Printlist");
for(int i = 0; i< Symbols.size() ; i++){
System.out.println(Symbols.get(i).name + " " + Symbols.get(i).type +" "+ i);
}
}
private boolean check(SymbolT newSy ){
for(int i = 0; i< Symbols.size(); i++){
if(Symbols.get(i).name.equals(newSy.name)){
return true;
}
}
return false;
}
public enum VarType {
INT, VOID, BOOLEAN, FUNCTION, PROGRAM, NON
}
public class SymbolT {
public String name;
public VarType type;
public SymbolT(String Name, String typeName){
this.name = Name;
this.type = mapType(typeName);
}
}
private VarType mapType(String typeName){
switch(typeName){
case "void":
return VarType.VOID;
case "int":
return VarType.INT;
case "boolean":
return VarType.BOOLEAN;
case "function":
return VarType.FUNCTION;
case "program":
return VarType.PROGRAM;
default: return VarType.NON;
}
}
}