From 1cf218ba93396c7be7f4b3ee25d8008a41777273 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sat, 11 Feb 2017 08:44:28 -0500 Subject: Parse double and some dice --- dice-lang/src/bjc/dicelang/v2/Token.java | 74 ++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 dice-lang/src/bjc/dicelang/v2/Token.java (limited to 'dice-lang/src/bjc/dicelang/v2/Token.java') 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(); + } + } +} -- cgit v1.2.3