diff options
Diffstat (limited to 'dice-lang/src/bjc/dicelang/Token.java')
| -rw-r--r-- | dice-lang/src/bjc/dicelang/Token.java | 120 |
1 files changed, 53 insertions, 67 deletions
diff --git a/dice-lang/src/bjc/dicelang/Token.java b/dice-lang/src/bjc/dicelang/Token.java index 4cc3f16..e53cba8 100644 --- a/dice-lang/src/bjc/dicelang/Token.java +++ b/dice-lang/src/bjc/dicelang/Token.java @@ -15,46 +15,34 @@ public class Token { public static enum Type { // Natural tokens // These are produced from lexemes - ADD, SUBTRACT, - MULTIPLY, - DIVIDE, IDIVIDE, - INT_LIT, FLOAT_LIT, STRING_LIT, - VREF, - DICE_LIT, DICESCALAR, DICEFUDGE, - DICEGROUP, DICECONCAT, DICELIST, - LET, BIND, COERCE, - STRCAT, STRREP, - OPAREN, CPAREN, - OBRACKET, CBRACKET, - OBRACE, CBRACE, + ADD, SUBTRACT, MULTIPLY, DIVIDE, IDIVIDE, INT_LIT, FLOAT_LIT, STRING_LIT, VREF, DICE_LIT, DICESCALAR, DICEFUDGE, DICEGROUP, DICECONCAT, DICELIST, LET, BIND, COERCE, STRCAT, STRREP, OPAREN, CPAREN, OBRACKET, CBRACKET, OBRACE, CBRACE, // Synthetic tokens // These are produced when needed - NIL, GROUPSEP, TOKGROUP, - TAGOP, TAGOPR + NIL, GROUPSEP, TOKGROUP, TAGOP, TAGOPR } - public final Type type; + public final Type type; // This is used for the following token types - // INT_LIT (int value) - // STRING_LIT (index into string table) - // VREF (index into sym table) - // O* and C* (sym-count of current token) - public long intValue; + // INT_LIT (int value) + // STRING_LIT (index into string table) + // VREF (index into sym table) + // O* and C* (sym-count of current token) + public long intValue; // This is used for the following token types - // FLOAT_LIT (float value) - public double floatValue; + // FLOAT_LIT (float value) + public double floatValue; // This is used for the following token types - // DICE_LIT (dice value) + // DICE_LIT (dice value) public DieExpression diceValue; // This is used for the following token types - // TOKGROUP (the tokens in the group) - // TAG* (the tagged construct) - public IList<Token> tokenValues; + // TOKGROUP (the tokens in the group) + // TAG* (the tagged construct) + public IList<Token> tokenValues; public Token(Type typ) { type = typ; @@ -85,58 +73,56 @@ public class Token { } public String toString() { - switch(type) { - case INT_LIT: - case STRING_LIT: - case VREF: - case OPAREN: - case CPAREN: - case OBRACKET: - case CBRACKET: - case OBRACE: - case CBRACE: - return type.toString() + "(" - + intValue + ")"; - case FLOAT_LIT: - return type.toString() + "(" - + floatValue + ")"; - case DICE_LIT: - return type.toString() + "(" - + diceValue + ")"; - case TAGOP: - case TAGOPR: - case TOKGROUP: - return type.toString() + "(" - + tokenValues + ")"; - default: - return type.toString(); + switch (type) { + case INT_LIT: + case STRING_LIT: + case VREF: + case OPAREN: + case CPAREN: + case OBRACKET: + case CBRACKET: + case OBRACE: + case CBRACE: + return type.toString() + "(" + intValue + ")"; + case FLOAT_LIT: + return type.toString() + "(" + floatValue + ")"; + case DICE_LIT: + return type.toString() + "(" + diceValue + ")"; + case TAGOP: + case TAGOPR: + case TOKGROUP: + return type.toString() + "(" + tokenValues + ")"; + default: + return type.toString(); } } public boolean equals(Object other) { - if(!(other instanceof Token)) return false; + if (!(other instanceof Token)) + return false; - Token otk = (Token)other; + Token otk = (Token) other; - if(otk.type != type) return false; + if (otk.type != type) + return false; - switch(type) { - case OBRACE: - case OBRACKET: - return intValue == otk.intValue; - default: - return true; + switch (type) { + case OBRACE: + case OBRACKET: + return intValue == otk.intValue; + default: + return true; } } public boolean isGrouper() { - switch(type) { - case OPAREN: - case OBRACE: - case OBRACKET: - return true; - default: - return false; + switch (type) { + case OPAREN: + case OBRACE: + case OBRACKET: + return true; + default: + return false; } } } |
