-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperToken.java
100 lines (83 loc) · 2.65 KB
/
SuperToken.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
abstract class SuperToken {
protected static SymbolTable symbolTable;
public static class CurrentFunction{
protected static String currentFunc;
protected static Boolean containsRet = false;
protected static VarType returnType = null;
protected static VarType expectedReturnType = null;
}
public static void setContainsRet(Boolean containsRet) {
CurrentFunction.containsRet = containsRet;
}
public static Boolean getContainsRet() {
return CurrentFunction.containsRet;
}
public static void setReturnType(VarType returnType) {
CurrentFunction.returnType = returnType;
}
public static VarType getReturnType() {
return CurrentFunction.returnType;
}
public static VarType getExpectedReturnType(){
return CurrentFunction.expectedReturnType;
}
public static void setExpectedReturnType(VarType type){
CurrentFunction.expectedReturnType = type;
}
public String toString(int t)
{
return "";
}
public VarType getTypeFromString(String type){
if (type.equals("int"))
return VarType.Int;
if (type.equals("float"))
return VarType.Float;
if (type.equals("bool"))
return VarType.Bool;
if (type.equals("char"))
return VarType.Char;
if (type.equals("string"))
return VarType.String;
if (type.equals("void"))
return VarType.Void;
return null;
}
public boolean isCoercible(VarType type1, VarType type2){
// System.out.println(type1);
// System.out.println(type2);
if (type1.equals(VarType.Float)){
if (type2.equals(VarType.Int) || type2.equals(VarType.Float)){
return true;
}
}
else if (type1.equals(VarType.Int)){
if (type2.equals(VarType.Int)){
return true;
}
}
else if (type1.equals(VarType.Void)){
if (type2 == null || type2.equals(VarType.Void)) {
return true;
}
}
else if (type1.equals(VarType.Bool)){
if (type2.equals(VarType.Bool) || type2.equals(VarType.Int)){
return true;
}
}
else if (type1.equals(VarType.Char)){
if (type2.equals(VarType.Char)){
return true;
}
}
else if (type1.equals(VarType.String)){
// TODO: handle the case of arrays
if (type2.equals(VarType.Void)){
return false;
}
return true;
}
return false;
}
}