summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/v2/Token.java
diff options
context:
space:
mode:
Diffstat (limited to 'dice-lang/src/bjc/dicelang/v2/Token.java')
-rw-r--r--dice-lang/src/bjc/dicelang/v2/Token.java72
1 files changed, 63 insertions, 9 deletions
diff --git a/dice-lang/src/bjc/dicelang/v2/Token.java b/dice-lang/src/bjc/dicelang/v2/Token.java
index 9825dae..e6f22a5 100644
--- a/dice-lang/src/bjc/dicelang/v2/Token.java
+++ b/dice-lang/src/bjc/dicelang/v2/Token.java
@@ -1,5 +1,7 @@
package bjc.dicelang.v2;
+import bjc.utils.funcdata.IList;
+
/**
* Lexer token
*/
@@ -10,25 +12,33 @@ public class Token {
* Possible token types
*/
public static enum Type {
- ADD, SUBTRACT,
- MULTIPLY,
- DIVIDE, IDIVIDE,
- INT_LIT, FLOAT_LIT, STRING_LIT,
+ // Natural tokens
+ // These are produced from lexemes
+ ADD, SUBTRACT,
+ MULTIPLY,
+ DIVIDE, IDIVIDE,
+ INT_LIT, FLOAT_LIT, STRING_LIT,
VREF,
DICE_LIT, DICEGROUP, DICECONCAT, DICELIST,
- LET, BIND,
- OPAREN, CPAREN,
+ LET, BIND,
+ OPAREN, CPAREN,
OBRACKET, CBRACKET,
- NIL,
+ OBRACE, CBRACE,
+ // Synthetic tokens
+ // These are produced when needed
+ NIL, PRESHUNT, GROUPSEP,
+ TOKGROUP
}
public final Type type;
// At most one of these is valid
// based on the token type
- public long intValue;
- public double floatValue;
+ public long intValue;
+ public double floatValue;
+ public String stringValue;
public DiceBox.DieExpression diceValue;
+ public IList<Token> tokenValues;
public Token(Type typ) {
type = typ;
@@ -46,12 +56,24 @@ public class Token {
floatValue = val;
}
+ public Token(Type typ, String val) {
+ this(typ);
+
+ stringValue = val;
+ }
+
public Token(Type typ, DiceBox.DieExpression val) {
this(typ);
diceValue = val;
}
+ public Token(Type typ, IList<Token> tkVals) {
+ this(typ);
+
+ tokenValues = tkVals;
+ }
+
public String toString() {
switch(type) {
case INT_LIT:
@@ -61,6 +83,8 @@ public class Token {
case CPAREN:
case OBRACKET:
case CBRACKET:
+ case OBRACE:
+ case CBRACE:
return type.toString() + "("
+ intValue + ")";
case FLOAT_LIT:
@@ -69,8 +93,38 @@ public class Token {
case DICE_LIT:
return type.toString() + "("
+ diceValue + ")";
+ case TOKGROUP:
+ return type.toString() + "("
+ + tokenValues + ")";
default:
return type.toString();
}
}
+
+ public boolean equals(Object other) {
+ if(!(other instanceof Token)) return false;
+
+ Token otk = (Token)other;
+
+ if(otk.type != type) return false;
+
+ 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;
+ }
+ }
}