-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathType.java
More file actions
118 lines (107 loc) · 3.71 KB
/
Type.java
File metadata and controls
118 lines (107 loc) · 3.71 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.util.*;
public class Type {
String name;
List<Type> genericTypes = new ArrayList<Type>();
public Type(String name) {
this.name = name;
}
public static Type charType = new Type("char");
public static Type stringType = new Type("String");
public static Type intType = new Type("int");
public static Type booleanType = new Type("boolean");
public static Type arrayType = new Type("array");
public static Type errorType = new Type("error");
public static Type stateType = new Type("State");
public static Type rangeType = new Type("Range");
public static Type transitionType = new Type("Transition");
public static Type epsilonTransitionType = new Type("epsilonTransition");
public static Type finiteAutomataType = new Type("FA");
public static Type regularExpressionType = new Type("RE");
public static Type setType = new Type("Set");
public static Type mapType = new Type("Map");
//RE-Types aus der Klasse RegularExpression.java
public static Type orType = new Type("Or");
public static Type concatType = new Type("Concat");
public static Type starType = new Type("Star");
public static Type rangeExprType = new Type("RangeExpr");
public static Type emptyWordType = new Type("EmptyWord");
public String toString() {
return name;
}
public static Type getType(String name) {
switch(name)
{
case("char"):
return charType;
case("string"):
return stringType;
case("int"):
return intType;
case("boolean"):
return booleanType;
case("State"):
return stateType;
case("Range"):
return rangeType;
case("Transition"):
return transitionType;
case("epsilonTransition"):
return epsilonTransitionType;
case("FA"):
return finiteAutomataType;
case("RE"):
return regularExpressionType;
case("Set"):
return setType;
case("Map"):
return mapType;
case("Or"):
return orType;
case("Concat"):
return concatType;
case("Star"):
return starType;
case("RangeExpr"):
return rangeExprType;
case("EmptyWord"):
return emptyWordType;
default:
return errorType;
}
}
public static Type kgT(Type t1, Type t2) {
if (t1==errorType || t2==errorType) return errorType;
if (t1.equals(t2)) return t1;
else if (t1==charType&&t2==intType) return charType;
else if (t1==finiteAutomataType && t2==transitionType) return finiteAutomataType; // fa + transition = fa
else return errorType;
}
//Typ wird der Generic-Liste hinzugefügt
public void addGenTyp(Type t){
genericTypes.add(t);
}
//Kopie des Value-Objekts
public Type copy(){
return new Type(this.name);
}
//Prüfung, ob zwei Objekte Type-Objekte gleich sind ("Operator-Überladung ==")
@Override
public boolean equals(Object obj){
Type t = (Type) obj;
boolean ret = false;
if(t.name == this.name)
ret = true;
if(t.genericTypes.size() == this.genericTypes.size()){
for(int i = 0; i<t.genericTypes.size();i++){
if(t.genericTypes.get(i) == this.genericTypes.get(i))
ret = true;
else
return false;
}
}else if(t.genericTypes.size()==0)
ret = true;
else
return false;
return ret;
}
}