From e03b3f477bcc160b72af4ab09cd8d12081017d2c Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 19 Feb 2017 08:30:45 -0500 Subject: Lots of things, but mostly evaluation --- dice-lang/src/bjc/dicelang/v2/Node.java | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 dice-lang/src/bjc/dicelang/v2/Node.java (limited to 'dice-lang/src/bjc/dicelang/v2/Node.java') diff --git a/dice-lang/src/bjc/dicelang/v2/Node.java b/dice-lang/src/bjc/dicelang/v2/Node.java new file mode 100644 index 0000000..bd191d2 --- /dev/null +++ b/dice-lang/src/bjc/dicelang/v2/Node.java @@ -0,0 +1,82 @@ +package bjc.dicelang.v2; + +public class Node { + public static enum Type { + ROOT, TOKREF, + UNARYOP, BINOP, + GROUP, OGROUP, + RESULT + } + + public static enum GroupType { + ARRAY, CODE + } + + public final Type type; + + // These can have or not have values based of the node type + public Token tokenVal; + public Token.Type operatorType; + public GroupType groupType; + public Evaluator.Result resultVal; + + public Node(Type typ) { + type = typ; + } + + public Node(Type typ, Token tokenVl) { + this(typ); + + tokenVal = tokenVl; + } + + public Node(Type typ, Token.Type opType) { + this(typ); + + operatorType = opType; + } + + public Node(Type typ, GroupType grupType) { + this(typ); + + groupType = grupType; + } + + public Node(Type typ, Evaluator.Result res) { + this(typ); + + resultVal = res; + } + + public String toString() { + switch(type) { + case UNARYOP: + case BINOP: + return "(" + type.name() + " : " + operatorType + ")"; + case OGROUP: + case TOKREF: + return "(" + type.name() + " : " + tokenVal + ")"; + case GROUP: + return "(" + type.name() + " : " + groupType + ")"; + case RESULT: + return "(" + type.name() + " : " + resultVal + ")"; + default: + return "Unknown node type " + type; + } + } + + public boolean equals(Object other) { + if(!(other instanceof Node)) return false; + + Node otk = (Node)other; + + if(otk.type != type) return false; + + switch(type) { + case OGROUP: + return tokenVal.equals(otk.tokenVal); + default: + return true; + } + } +} -- cgit v1.2.3