summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/v2/Token.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2017-02-11 08:44:28 -0500
committerbculkin2442 <bjculkin@mix.wvu.edu>2017-02-11 08:44:28 -0500
commit1cf218ba93396c7be7f4b3ee25d8008a41777273 (patch)
tree24fbb7a13c206c75e7c828862e04a5d0ae64cd5a /dice-lang/src/bjc/dicelang/v2/Token.java
parent6ca8c6764a8b8769a7a295c0479962a6588580a2 (diff)
Parse double and some dice
Diffstat (limited to 'dice-lang/src/bjc/dicelang/v2/Token.java')
-rw-r--r--dice-lang/src/bjc/dicelang/v2/Token.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/dice-lang/src/bjc/dicelang/v2/Token.java b/dice-lang/src/bjc/dicelang/v2/Token.java
new file mode 100644
index 0000000..471832e
--- /dev/null
+++ b/dice-lang/src/bjc/dicelang/v2/Token.java
@@ -0,0 +1,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();
+ }
+ }
+}