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
|
package bjc.dicelang.v2;
import bjc.dicelang.IDiceExpression;
/**
* Lexer token
*/
public class Token {
public final static Token NIL_TOKEN = new Token(Type.NIL);
/**
* Possible token types
*/
public static enum Type {
ADD, SUBTRACT,
MULTIPLY,
DIVIDE, IDIVIDE,
INT_LIT, FLOAT_LIT, STRING_LIT,
VREF,
DICE_LIT, DICEGROUP, DICECONCAT,
LET, BIND,
OPAREN, CPAREN,
OBRACKET, CBRACKET,
NIL,
}
public final Type type;
// At most one of these is valid
// based on the token type
public int intValue;
public double floatValue;
public DiceBox.Die diceValue;
public Token(Type typ) {
type = typ;
}
public Token(Type typ, int val) {
this(typ);
intValue = val;
}
public Token(Type typ, double val) {
this(typ);
floatValue = val;
}
public Token(Type typ, DiceBox.Die val) {
this(typ);
diceValue = val;
}
public String toString() {
switch(type) {
case INT_LIT:
case STRING_LIT:
case VREF:
return type.toString() + "("
+ intValue + ")";
case FLOAT_LIT:
return type.toString() + "("
+ floatValue + ")";
case DICE_LIT:
return type.toString() + "("
+ diceValue + ")";
default:
return type.toString();
}
}
}
|