-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathToken.java
80 lines (61 loc) · 1.38 KB
/
Token.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
class Token{
protected Sym sym;
public Token(Sym sym){
this.sym=sym;
}
public Sym getSym(){
return this.sym;
}
public String toString(){
return (" "+sym);
}
}
class NumberToken extends Token{
protected int value;
public NumberToken(int value){
super(Sym.NUM);
this.value=value;
}
public int getValue(){
return this.value;
}
}
class WordToken extends Token{
protected String content;
public WordToken(Sym sym,String content){
super(sym);
this.content=content;
}
public String getContent(){
return content;
}
public String toString(){
return super.toString() + " " + content;
}
}
class ColorToken extends Token{
protected String color;
protected int red;
protected int green;
protected int blue;
public ColorToken(String color){
super(Sym.COL);
this.color=color;
fillColors();
}
private void fillColors(){
String r = color.substring(1,3);
String g = color.substring(3,5);
String b = color.substring(5,7);
this.red = Integer.parseInt(r, 16);
this.green = Integer.parseInt(g, 16);
this.blue = Integer.parseInt(b, 16);
}
public int[] rgb(){
int[] rgb={red,green,blue};
return rgb;
}
public String toString(){
return super.toString()+" "+red+" "+green+" "+blue;
}
}