summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/src/bjc/dicelang/DiceLangEngine.java60
-rw-r--r--base/src/bjc/dicelang/Node.java4
-rw-r--r--base/src/bjc/dicelang/Parser.java46
-rw-r--r--base/src/bjc/dicelang/Shunter.java10
-rw-r--r--base/src/bjc/dicelang/Tokenizer.java8
-rw-r--r--base/src/bjc/dicelang/cli/DiceLangConsole.java4
-rw-r--r--base/src/bjc/dicelang/eval/Evaluator.java132
-rw-r--r--base/src/bjc/dicelang/eval/FailureEvaluatorResult.java8
-rw-r--r--base/src/bjc/dicelang/expr/ExprREPL.java8
-rw-r--r--base/src/bjc/dicelang/expr/Lexer.java6
-rw-r--r--base/src/bjc/dicelang/expr/Parser.java8
-rw-r--r--base/src/bjc/dicelang/expr/Shunter.java6
-rw-r--r--base/src/bjc/dicelang/tokens/Token.java6
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java10
14 files changed, 158 insertions, 158 deletions
diff --git a/base/src/bjc/dicelang/DiceLangEngine.java b/base/src/bjc/dicelang/DiceLangEngine.java
index 549faf6..e0cddb1 100644
--- a/base/src/bjc/dicelang/DiceLangEngine.java
+++ b/base/src/bjc/dicelang/DiceLangEngine.java
@@ -14,12 +14,12 @@ import bjc.dicelang.eval.EvaluatorResult;
import bjc.dicelang.eval.FailureEvaluatorResult;
import bjc.dicelang.scl.StreamEngine;
import bjc.dicelang.tokens.Token;
-import bjc.data.ITree;
+import bjc.data.Tree;
import bjc.funcdata.FunctionalList;
import bjc.funcdata.FunctionalMap;
import bjc.funcdata.FunctionalStringTokenizer;
-import bjc.funcdata.IList;
-import bjc.funcdata.IMap;
+import bjc.funcdata.ListEx;
+import bjc.funcdata.MapEx;
import bjc.utils.funcutils.ListUtils;
import bjc.utils.parserutils.TokenUtils;
import bjc.utils.parserutils.splitter.ConfigurableTokenSplitter;
@@ -71,15 +71,15 @@ public class DiceLangEngine {
/**
* The symbol table.
*/
- public final IMap<Integer, String> symTable;
+ public final MapEx<Integer, String> symTable;
/* String literal tables */
- private final IMap<Integer, String> stringLits;
- private final IMap<String, String> stringLiterals;
+ private final MapEx<Integer, String> stringLits;
+ private final MapEx<String, String> stringLiterals;
/* Lists of defns. */
- private final IList<Define> lineDefns;
- private final IList<Define> tokenDefns;
+ private final ListEx<Define> lineDefns;
+ private final ListEx<Define> tokenDefns;
/* Are defns currently sorted by priority? */
private boolean defnsSorted;
@@ -237,21 +237,21 @@ public class DiceLangEngine {
*
* Instead of strings, this should maybe use a RawToken class or something.
*/
- final IList<String> preprocessedTokens = preprocessCommand(command);
+ final ListEx<String> preprocessedTokens = preprocessCommand(command);
if (preprocessedTokens == null) {
return false;
}
/* Lex the string tokens into token-tokens */
- final IList<Token> lexedTokens = lexTokens(preprocessedTokens);
+ final ListEx<Token> lexedTokens = lexTokens(preprocessedTokens);
if (lexedTokens == null) {
return false;
}
/* Parse the tokens into an AST forest */
- final IList<ITree<Node>> astForest = new FunctionalList<>();
+ final ListEx<Tree<Node>> astForest = new FunctionalList<>();
final boolean succ = Parser.parseTokens(lexedTokens, astForest);
if (!succ) {
@@ -264,8 +264,8 @@ public class DiceLangEngine {
}
/* Lex string tokens into token-tokens */
- private IList<Token> lexTokens(final IList<String> preprocessedTokens) {
- final IList<Token> lexedTokens = new FunctionalList<>();
+ private ListEx<Token> lexTokens(final ListEx<String> preprocessedTokens) {
+ final ListEx<Token> lexedTokens = new FunctionalList<>();
for (final String token : preprocessedTokens) {
String newTok = token;
@@ -308,8 +308,8 @@ public class DiceLangEngine {
}
/* Preshunt preshunt-marked groups of tokens */
- IList<Token> shuntedTokens = lexedTokens;
- final IList<Token> preparedTokens = new FunctionalList<>();
+ ListEx<Token> shuntedTokens = lexedTokens;
+ final ListEx<Token> preparedTokens = new FunctionalList<>();
boolean succ = removePreshuntTokens(lexedTokens, preparedTokens);
@@ -348,7 +348,7 @@ public class DiceLangEngine {
}
/* Expand token groups */
- final IList<Token> readyTokens = shuntedTokens.flatMap(tk -> {
+ final ListEx<Token> readyTokens = shuntedTokens.flatMap(tk -> {
if (tk.type == Token.Type.TOKGROUP || tk.type == Token.Type.TAGOP || tk.type == Token.Type.TAGOPR) {
String msg = String.format("Expanding token group to: %s\n", tk.tokenValues.toString());
LOG.finer(msg);
@@ -396,14 +396,14 @@ public class DiceLangEngine {
}
/* Preprocess a command into a list of string tokens. */
- private IList<String> preprocessCommand(final String command) {
+ private ListEx<String> preprocessCommand(final String command) {
/* Sort the defines if they aren't sorted */
if (!defnsSorted) {
sortDefns();
}
/* Run the tokens through the stream engine */
- final IList<String> streamToks = new FunctionalList<>();
+ final ListEx<String> streamToks = new FunctionalList<>();
final boolean succ = streamEng.doStreams(command.split(" "), streamToks);
if (!succ) {
@@ -486,10 +486,10 @@ public class DiceLangEngine {
/* Split the command into tokens */
final String strang = destringedCommand.toString();
- IList<String> tokens = FunctionalStringTokenizer.fromString(strang).toList();
+ ListEx<String> tokens = FunctionalStringTokenizer.fromString(strang).toList();
/* Temporarily remove non-expanding tokens */
- final IMap<String, String> nonExpandedTokens = new FunctionalMap<>();
+ final MapEx<String, String> nonExpandedTokens = new FunctionalMap<>();
tokens = tokens.map(tk -> {
final Matcher nonExpandMatcher = nonExpandPattern.matcher(tk);
@@ -518,7 +518,7 @@ public class DiceLangEngine {
}
/* Expand tokens */
- IList<String> fullyExpandedTokens = tokens.flatMap(opExpander::split);
+ ListEx<String> fullyExpandedTokens = tokens.flatMap(opExpander::split);
if (debugMode) {
String msg = String.format("\tCommand after token expansion: %s\n", fullyExpandedTokens.toString());
@@ -549,10 +549,10 @@ public class DiceLangEngine {
}
/* Evaluate a forest of AST nodes. */
- private void evaluateForest(final IList<ITree<Node>> astForest) {
+ private void evaluateForest(final ListEx<Tree<Node>> astForest) {
int treeNo = 1;
- for (final ITree<Node> ast : astForest) {
+ for (final Tree<Node> ast : astForest) {
if (debugMode) {
System.out.printf("\t\tTree %d in forest:\n%s\n", treeNo, ast.toString());
}
@@ -564,8 +564,8 @@ public class DiceLangEngine {
int step = 1;
/* Evaluate it step by step */
- for (final Iterator<ITree<Node>> itr = eval.stepDebug(ast); itr.hasNext();) {
- final ITree<Node> nodeStep = itr.next();
+ for (final Iterator<Tree<Node>> itr = eval.stepDebug(ast); itr.hasNext();) {
+ final Tree<Node> nodeStep = itr.next();
System.out.printf("\t\tStep %d: Node is %s", step, nodeStep);
@@ -590,7 +590,7 @@ public class DiceLangEngine {
}
if (res.type == EvaluatorResult.Type.FAILURE) {
- ITree<Node> otree = ((FailureEvaluatorResult) res).origVal;
+ Tree<Node> otree = ((FailureEvaluatorResult) res).origVal;
System.out.printf(" (original tree is %s)", otree);
}
@@ -626,13 +626,13 @@ public class DiceLangEngine {
}
/* Preshunt preshunt-marked groups of tokens. */
- private boolean removePreshuntTokens(final IList<Token> lexedTokens, final IList<Token> preparedTokens) {
+ private boolean removePreshuntTokens(final ListEx<Token> lexedTokens, final ListEx<Token> preparedTokens) {
/* Current nesting level of tokens. */
int curBraceCount = 0;
/* Data storage. */
- final Deque<IList<Token>> bracedTokens = new LinkedList<>();
- IList<Token> curBracedTokens = new FunctionalList<>();
+ final Deque<ListEx<Token>> bracedTokens = new LinkedList<>();
+ ListEx<Token> curBracedTokens = new FunctionalList<>();
for (final Token tk : lexedTokens) {
if (tk.type == Token.Type.OBRACE && tk.intValue == 2) {
@@ -659,7 +659,7 @@ public class DiceLangEngine {
curBraceCount -= 1;
- final IList<Token> preshuntTokens = new FunctionalList<>();
+ final ListEx<Token> preshuntTokens = new FunctionalList<>();
/* Shunt preshunt group. */
final boolean success = shunt.shuntTokens(curBracedTokens, preshuntTokens);
diff --git a/base/src/bjc/dicelang/Node.java b/base/src/bjc/dicelang/Node.java
index 1a3c2d6..d410695 100644
--- a/base/src/bjc/dicelang/Node.java
+++ b/base/src/bjc/dicelang/Node.java
@@ -3,7 +3,7 @@ package bjc.dicelang;
import bjc.dicelang.eval.EvaluatorResult;
import bjc.dicelang.eval.FailureEvaluatorResult;
import bjc.dicelang.tokens.Token;
-import bjc.data.ITree;
+import bjc.data.Tree;
/*
* @TODO 10/09/17 Ben Culkin :NodeReorg
@@ -124,7 +124,7 @@ public class Node {
return new Node(Type.RESULT, res);
}
- public static Node FAIL(final ITree<Node> orig) {
+ public static Node FAIL(final Tree<Node> orig) {
FailureEvaluatorResult res = new FailureEvaluatorResult(orig);
return new Node(Type.RESULT, res);
diff --git a/base/src/bjc/dicelang/Parser.java b/base/src/bjc/dicelang/Parser.java
index 49cc312..6879c4f 100644
--- a/base/src/bjc/dicelang/Parser.java
+++ b/base/src/bjc/dicelang/Parser.java
@@ -17,9 +17,9 @@ import java.util.Deque;
import java.util.LinkedList;
import bjc.dicelang.tokens.Token;
-import bjc.data.ITree;
import bjc.data.Tree;
-import bjc.funcdata.IList;
+import bjc.data.SimpleTree;
+import bjc.funcdata.ListEx;
/**
* Parse a series of tree into tokens.
@@ -44,15 +44,15 @@ public class Parser {
*
* @return Whether or not the parse was successful.
*/
- public static boolean parseTokens(final IList<Token> tokens, final IList<ITree<Node>> results) {
- final Deque<ITree<Node>> working = new LinkedList<>();
+ public static boolean parseTokens(final ListEx<Token> tokens, final ListEx<Tree<Node>> results) {
+ final Deque<Tree<Node>> working = new LinkedList<>();
for(final Token tk : tokens) {
switch(tk.type) {
case OBRACKET:
case OBRACE:
/* Parse opening delims. */
- working.push(new Tree<>(new Node(OGROUP, tk)));
+ working.push(new SimpleTree<>(new Node(OGROUP, tk)));
break;
case CBRACKET:
@@ -90,8 +90,8 @@ public class Parser {
Errors.inst.printError(EK_PARSE_UNOPERAND, tk.toString());
return false;
} else if(working.size() == 1) {
- final ITree<Node> operand = working.pop();
- final ITree<Node> opNode = new Tree<>(new Node(UNARYOP, tk.type));
+ final Tree<Node> operand = working.pop();
+ final Tree<Node> opNode = new SimpleTree<>(new Node(UNARYOP, tk.type));
opNode.addChild(operand);
@@ -108,8 +108,8 @@ public class Parser {
if(working.size() == 0) {
Errors.inst.printError(EK_PARSE_UNOPERAND, tk.toString());
} else {
- final ITree<Node> operand = working.pop();
- final ITree<Node> opNode = new Tree<>(new Node(UNARYOP, tk.type));
+ final Tree<Node> operand = working.pop();
+ final Tree<Node> opNode = new SimpleTree<>(new Node(UNARYOP, tk.type));
opNode.addChild(operand);
@@ -123,7 +123,7 @@ public class Parser {
case VREF:
case DICE_LIT:
/* Handle literals. */
- working.push(new Tree<>(new Node(TOKREF, tk)));
+ working.push(new SimpleTree<>(new Node(TOKREF, tk)));
break;
default:
Errors.inst.printError(EK_PARSE_INVTOKEN, tk.type.toString());
@@ -135,7 +135,7 @@ public class Parser {
* Collect the remaining nodes as the roots of the trees in the
* AST forest.
*/
- for(final ITree<Node> ast : working) {
+ for(final Tree<Node> ast : working) {
/* Make sure that the tree are well-formed */
if(ast.containsMatching((val) -> {
switch(val.type) {
@@ -157,11 +157,11 @@ public class Parser {
}
/* Handle a binary operator. */
- private static void handleBinaryNode(final Deque<ITree<Node>> working, final Token tk) {
- final ITree<Node> right = working.pop();
- final ITree<Node> left = working.pop();
+ private static void handleBinaryNode(final Deque<Tree<Node>> working, final Token tk) {
+ final Tree<Node> right = working.pop();
+ final Tree<Node> left = working.pop();
- final ITree<Node> opNode = new Tree<>(new Node(BINOP, tk.type));
+ final Tree<Node> opNode = new SimpleTree<>(new Node(BINOP, tk.type));
opNode.addChild(left);
opNode.addChild(right);
@@ -170,20 +170,20 @@ public class Parser {
}
/* Parse a closing delimiter. */
- private static boolean parseClosingGrouper(final Deque<ITree<Node>> working, final Token tk) {
+ private static boolean parseClosingGrouper(final Deque<Tree<Node>> working, final Token tk) {
if(working.size() == 0) {
Errors.inst.printError(EK_PARSE_NOCLOSE);
return false;
}
- ITree<Node> groupNode = null;
+ Tree<Node> groupNode = null;
switch(tk.type) {
case CBRACE:
- groupNode = new Tree<>(new Node(GROUP, Node.GroupType.CODE));
+ groupNode = new SimpleTree<>(new Node(GROUP, Node.GroupType.CODE));
break;
case CBRACKET:
- groupNode = new Tree<>(new Node(GROUP, Node.GroupType.ARRAY));
+ groupNode = new SimpleTree<>(new Node(GROUP, Node.GroupType.ARRAY));
break;
default:
Errors.inst.printError(EK_PARSE_UNCLOSE, tk.type.toString());
@@ -198,7 +198,7 @@ public class Parser {
matching = new Token(Token.Type.OBRACE, tk.intValue);
}
- final ITree<Node> matchNode = new Tree<>(new Node(OGROUP, matching));
+ final Tree<Node> matchNode = new SimpleTree<>(new Node(OGROUP, matching));
if(!working.contains(matchNode)) {
Errors.inst.printError(EK_PARSE_UNCLOSE, tk.toString(), matchNode.toString());
@@ -207,14 +207,14 @@ public class Parser {
int treeNo = 1;
- for(final ITree<Node> ast : working) {
+ for(final Tree<Node> ast : working) {
System.out.println("Tree " + treeNo++ + ": " + ast.toString());
}
return false;
}
- final Deque<ITree<Node>> childs = new LinkedList<>();
+ final Deque<Tree<Node>> childs = new LinkedList<>();
while(!working.peek().equals(matchNode)) {
childs.push(working.pop());
@@ -223,7 +223,7 @@ public class Parser {
/* Discard opener */
working.pop();
- for(final ITree<Node> child : childs) {
+ for(final Tree<Node> child : childs) {
groupNode.addChild(child);
}
diff --git a/base/src/bjc/dicelang/Shunter.java b/base/src/bjc/dicelang/Shunter.java
index 0e3cf1d..366c459 100644
--- a/base/src/bjc/dicelang/Shunter.java
+++ b/base/src/bjc/dicelang/Shunter.java
@@ -8,8 +8,8 @@ import java.util.Set;
import bjc.dicelang.tokens.Token;
import bjc.funcdata.FunctionalList;
import bjc.funcdata.FunctionalMap;
-import bjc.funcdata.IList;
-import bjc.funcdata.IMap;
+import bjc.funcdata.ListEx;
+import bjc.funcdata.MapEx;
import static bjc.dicelang.Errors.ErrorKey.EK_SHUNT_INVSEP;
import static bjc.dicelang.Errors.ErrorKey.EK_SHUNT_NOGROUP;
@@ -26,7 +26,7 @@ import static bjc.dicelang.tokens.Token.Type.*;
*/
public class Shunter {
/* The binary operators and their priorities. */
- IMap<Token.Type, Integer> ops;
+ MapEx<Token.Type, Integer> ops;
/* Operators that are right-associative */
Set<Token.Type> rightAssoc;
@@ -116,7 +116,7 @@ public class Shunter {
*
* @return Whether or not the shunt succeeded.
*/
- public boolean shuntTokens(final IList<Token> tks, final IList<Token> returned) {
+ public boolean shuntTokens(final ListEx<Token> tks, final ListEx<Token> returned) {
/* Operator stack for normal and unary operators. */
final Deque<Token> opStack = new LinkedList<>();
final Deque<Token> unaryOps = new LinkedList<>();
@@ -274,7 +274,7 @@ public class Shunter {
opStack.pop();
} else if(tk.type == GROUPSEP) {
/* Add a grouped token. */
- final IList<Token> group = new FunctionalList<>();
+ final ListEx<Token> group = new FunctionalList<>();
while(currReturned.size() != 0 && !currReturned.peek().isGrouper()) {
group.add(currReturned.pop());
diff --git a/base/src/bjc/dicelang/Tokenizer.java b/base/src/bjc/dicelang/Tokenizer.java
index d0e0539..7aed861 100644
--- a/base/src/bjc/dicelang/Tokenizer.java
+++ b/base/src/bjc/dicelang/Tokenizer.java
@@ -8,7 +8,7 @@ import bjc.dicelang.tokens.DiceToken;
import bjc.dicelang.tokens.FloatToken;
import bjc.dicelang.tokens.Token;
import bjc.funcdata.FunctionalMap;
-import bjc.funcdata.IMap;
+import bjc.funcdata.MapEx;
import bjc.utils.funcutils.StringUtils;
import bjc.utils.parserutils.TokenUtils;
@@ -20,7 +20,7 @@ import static bjc.dicelang.tokens.Token.Type.*;
*/
public class Tokenizer {
/* Literal tokens for tokenization */
- private static final IMap<String, Token.Type> litTokens;
+ private static final MapEx<String, Token.Type> litTokens;
private final DiceLangEngine eng;
@@ -67,7 +67,7 @@ public class Tokenizer {
*
* @return A lexed token.
*/
- public Token lexToken(final String token, final IMap<String, String> stringLts) {
+ public Token lexToken(final String token, final MapEx<String, String> stringLts) {
if (token.equals("")) {
return null;
}
@@ -139,7 +139,7 @@ public class Tokenizer {
private final Pattern stringLitMatcher = Pattern.compile("\\AstringLiteral(\\d+)\\Z");
/* Tokenize a literal value. */
- private Token tokenizeLiteral(final String rtoken, final IMap<String, String> stringLts) {
+ private Token tokenizeLiteral(final String rtoken, final MapEx<String, String> stringLts) {
Token tk = Token.NIL_TOKEN;
String token = rtoken.trim();
diff --git a/base/src/bjc/dicelang/cli/DiceLangConsole.java b/base/src/bjc/dicelang/cli/DiceLangConsole.java
index 54dc49d..bd25b9b 100644
--- a/base/src/bjc/dicelang/cli/DiceLangConsole.java
+++ b/base/src/bjc/dicelang/cli/DiceLangConsole.java
@@ -4,7 +4,7 @@ import bjc.dicelang.Define;
import bjc.dicelang.DiceLangEngine;
import bjc.dicelang.Errors;
import bjc.funcdata.FunctionalMap;
-import bjc.funcdata.IMap;
+import bjc.funcdata.MapEx;
import java.io.IOException;
import java.util.LinkedList;
@@ -34,7 +34,7 @@ public class DiceLangConsole {
/* Are we in multi-line mode? */
private boolean multiLine;
- private static IMap<String, DiceLangPragma> pragmas;
+ private static MapEx<String, DiceLangPragma> pragmas;
static {
pragmas = new FunctionalMap<>();
diff --git a/base/src/bjc/dicelang/eval/Evaluator.java b/base/src/bjc/dicelang/eval/Evaluator.java
index fbcdcec..9e41017 100644
--- a/base/src/bjc/dicelang/eval/Evaluator.java
+++ b/base/src/bjc/dicelang/eval/Evaluator.java
@@ -18,11 +18,11 @@ import bjc.dicelang.dice.SimpleDieList;
import bjc.dicelang.tokens.DiceToken;
import bjc.dicelang.tokens.FloatToken;
import bjc.dicelang.tokens.Token;
-import bjc.data.ITree;
+import bjc.data.Tree;
import bjc.data.SingleIterator;
import bjc.data.TopDownTransformIterator;
import bjc.data.TopDownTransformResult;
-import bjc.data.Tree;
+import bjc.data.SimpleTree;
import static bjc.dicelang.Errors.ErrorKey.*;
import static bjc.dicelang.eval.EvaluatorResult.Type.*;
@@ -47,7 +47,7 @@ public class Evaluator {
/* The context during iteration. */
private static class Context {
- public Consumer<Iterator<ITree<Node>>> thunk;
+ public Consumer<Iterator<Tree<Node>>> thunk;
public boolean isDebug;
@@ -77,7 +77,7 @@ public class Evaluator {
*
* @return The result of the tree.
*/
- public EvaluatorResult evaluate(final ITree<Node> comm) {
+ public EvaluatorResult evaluate(final Tree<Node> comm) {
final Context ctx = new Context();
ctx.isDebug = false;
@@ -92,7 +92,7 @@ public class Evaluator {
};
/* The result. */
- final ITree<Node> res = comm.topDownTransform(this::pickEvaluationType, node -> this.evaluateNode(node, ctx));
+ final Tree<Node> res = comm.topDownTransform(this::pickEvaluationType, node -> this.evaluateNode(node, ctx));
return res.getHead().resultVal;
}
@@ -105,7 +105,7 @@ public class Evaluator {
* Make it public once we know it works again.
*/
@SuppressWarnings("javadoc")
- public Iterator<ITree<Node>> stepDebug(final ITree<Node> comm) {
+ public Iterator<Tree<Node>> stepDebug(final Tree<Node> comm) {
final Context ctx = new Context();
ctx.isDebug = true;
@@ -136,7 +136,7 @@ public class Evaluator {
}
/* Evaluate a node. */
- private ITree<Node> evaluateNode(final ITree<Node> ast, final Context ctx) {
+ private Tree<Node> evaluateNode(final Tree<Node> ast, final Context ctx) {
switch (ast.getHead().type) {
case UNARYOP:
return evaluateUnaryOp(ast, ctx);
@@ -150,16 +150,16 @@ public class Evaluator {
return ast;
default:
Errors.inst.printError(EK_EVAL_INVNODE, ast.getHead().type.toString());
- return new Tree<>(Node.FAIL(ast));
+ return new SimpleTree<>(Node.FAIL(ast));
}
}
/* Evaluate a unary operator. */
- private ITree<Node> evaluateUnaryOp(final ITree<Node> ast, final Context ctx) {
+ private Tree<Node> evaluateUnaryOp(final Tree<Node> ast, final Context ctx) {
/* Unary operators only take one operand. */
if (ast.getChildrenCount() != 1) {
Errors.inst.printError(EK_EVAL_UNUNARY, Integer.toString(ast.getChildrenCount()));
- return new Tree<>(Node.FAIL(ast));
+ return new SimpleTree<>(Node.FAIL(ast));
}
switch (ast.getHead().operatorType) {
@@ -179,7 +179,7 @@ public class Evaluator {
final EvaluatorResult sres = new DiceEvaluatorResult(die);
- return new Tree<>(new Node(Node.Type.RESULT, sres));
+ return new SimpleTree<>(new Node(Node.Type.RESULT, sres));
}
case DICEFUDGE: {
final EvaluatorResult oprn = ast.getChild(0).getHead().resultVal;
@@ -194,12 +194,12 @@ public class Evaluator {
final EvaluatorResult fres = new DiceEvaluatorResult(die);
- return new Tree<>(new Node(Node.Type.RESULT, fres));
+ return new SimpleTree<>(new Node(Node.Type.RESULT, fres));
}
default: {
Errors.inst.printError(EK_EVAL_INVUNARY, ast.getHead().operatorType.toString());
- return new Tree<>(Node.FAIL(ast));
+ return new SimpleTree<>(Node.FAIL(ast));
}
}
}
@@ -216,36 +216,36 @@ public class Evaluator {
* Coerce also needs to be able to coerce things to dice and ratios (whenever
* they get added).
*/
- private ITree<Node> doTypeCoercion(final ITree<Node> ast, final Context ctx) {
- final ITree<Node> toCoerce = ast.getChild(0);
- final ITree<Node> retVal = new Tree<>(toCoerce.getHead());
- final Deque<ITree<Node>> children = new LinkedList<>();
+ private Tree<Node> doTypeCoercion(final Tree<Node> ast, final Context ctx) {
+ final Tree<Node> toCoerce = ast.getChild(0);
+ final Tree<Node> retVal = new SimpleTree<>(toCoerce.getHead());
+ final Deque<Tree<Node>> children = new LinkedList<>();
/* The current type we are coercing to. */
CoerceSteps curLevel = CoerceSteps.INTEGER;
for (int i = 0; i < toCoerce.getChildrenCount(); i++) {
- final ITree<Node> child = toCoerce.getChild(i);
- ITree<Node> nChild = null;
+ final Tree<Node> child = toCoerce.getChild(i);
+ Tree<Node> nChild = null;
/* Tell our thunk we processed a node. */
if (ctx.isDebug) {
/* Evaluate each step of the child. */
- final Iterator<ITree<Node>> nd = stepDebug(child);
+ final Iterator<Tree<Node>> nd = stepDebug(child);
for (; nd.hasNext(); nChild = nd.next()) {
ctx.thunk.accept(new SingleIterator<>(child));
}
} else {
/* Evaluate the child. */
- nChild = new Tree<>(new Node(Node.Type.RESULT, evaluate(child)));
+ nChild = new SimpleTree<>(new Node(Node.Type.RESULT, evaluate(child)));
ctx.thunk.accept(new SingleIterator<>(nChild));
}
if (nChild == null) {
Errors.inst.printError(EK_EVAL_INVNODE);
- return new Tree<>(Node.FAIL(ast));
+ return new SimpleTree<>(Node.FAIL(ast));
}
final Node childNode = nChild.getHead();
@@ -259,7 +259,7 @@ public class Evaluator {
children.add(nChild);
}
- for (final ITree<Node> child : children) {
+ for (final Tree<Node> child : children) {
final Node nd = child.getHead();
final EvaluatorResult res = nd.resultVal;
@@ -285,18 +285,18 @@ public class Evaluator {
}
/* Evaluate a binary operator. */
- private static ITree<Node> evaluateBinaryOp(final ITree<Node> ast, final Context ctx) {
+ private static Tree<Node> evaluateBinaryOp(final Tree<Node> ast, final Context ctx) {
final Token.Type binOp = ast.getHead().operatorType;
/* Binary operators always have two children. */
if (ast.getChildrenCount() != 2) {
Errors.inst.printError(EK_EVAL_INVBIN, Integer.toString(ast.getChildrenCount()), ast.toString());
- return new Tree<>(Node.FAIL(ast));
+ return new SimpleTree<>(Node.FAIL(ast));
}
- final ITree<Node> left = ast.getChild(0);
- final ITree<Node> right = ast.getChild(1);
+ final Tree<Node> left = ast.getChild(0);
+ final Tree<Node> right = ast.getChild(1);
final EvaluatorResult leftRes = left.getHead().resultVal;
final EvaluatorResult rightRes = right.getHead().resultVal;
@@ -317,16 +317,16 @@ public class Evaluator {
return evaluateStringBinary(binOp, leftRes, rightRes, ctx);
default:
Errors.inst.printError(EK_EVAL_UNBIN, binOp.toString());
- return new Tree<>(Node.FAIL(ast));
+ return new SimpleTree<>(Node.FAIL(ast));
}
}
/* Evaluate a binary operator on strings. */
- private static ITree<Node> evaluateStringBinary(final Token.Type op, final EvaluatorResult left,
+ private static Tree<Node> evaluateStringBinary(final Token.Type op, final EvaluatorResult left,
final EvaluatorResult right, final Context ctx) {
if (left.type != STRING) {
Errors.inst.printError(EK_EVAL_INVSTRING, left.type.toString());
- return new Tree<>(Node.FAIL(left));
+ return new SimpleTree<>(Node.FAIL(left));
}
final String strang = ((StringEvaluatorResult) left).stringVal;
@@ -335,18 +335,18 @@ public class Evaluator {
case STRCAT: {
if (right.type != STRING) {
Errors.inst.printError(EK_EVAL_UNSTRING, right.type.toString());
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
}
final String strung = ((StringEvaluatorResult) right).stringVal;
final EvaluatorResult cres = new StringEvaluatorResult(strang + strung);
- return new Tree<>(new Node(Node.Type.RESULT, cres));
+ return new SimpleTree<>(new Node(Node.Type.RESULT, cres));
}
case STRREP: {
if (right.type != INT) {
Errors.inst.printError(EK_EVAL_INVSTRING, right.type.toString());
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
}
String res = strang;
@@ -356,16 +356,16 @@ public class Evaluator {
res += strang;
}
- return new Tree<>(new Node(Node.Type.RESULT, new StringEvaluatorResult(res)));
+ return new SimpleTree<>(new Node(Node.Type.RESULT, new StringEvaluatorResult(res)));
}
default:
Errors.inst.printError(EK_EVAL_UNSTRING, op.toString());
- return new Tree<>(Node.FAIL());
+ return new SimpleTree<>(Node.FAIL());
}
}
/* Evaluate dice binary operators. */
- private static ITree<Node> evaluateDiceBinary(final Token.Type op, final EvaluatorResult left,
+ private static Tree<Node> evaluateDiceBinary(final Token.Type op, final EvaluatorResult left,
final EvaluatorResult right, final Context ctx) {
EvaluatorResult res = null;
@@ -391,7 +391,7 @@ public class Evaluator {
res = new DiceEvaluatorResult(new SimpleDie(lhs, ((IntegerEvaluatorResult) right).value));
} else {
Errors.inst.printError(EK_EVAL_INVDGROUP, right.type.toString());
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
}
} else if (left.type == INT) {
IntegerEvaluatorResult irs = (IntegerEvaluatorResult) left;
@@ -404,20 +404,20 @@ public class Evaluator {
res = new DiceEvaluatorResult(new SimpleDie(irs.value, ((IntegerEvaluatorResult) right).value));
} else {
Errors.inst.printError(EK_EVAL_INVDGROUP, right.type.toString());
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
}
} else {
Errors.inst.printError(EK_EVAL_INVDGROUP, left.type.toString());
- return new Tree<>(Node.FAIL(left));
+ return new SimpleTree<>(Node.FAIL(left));
}
}
case DICECONCAT: {
if (left.type != DICE || ((DiceEvaluatorResult) left).diceVal.isList()) {
Errors.inst.printError(EK_EVAL_INVDICE, left.type.toString());
- return new Tree<>(Node.FAIL(left));
+ return new SimpleTree<>(Node.FAIL(left));
} else if (right.type != DICE || ((DiceEvaluatorResult) right).diceVal.isList()) {
Errors.inst.printError(EK_EVAL_INVDICE, right.type.toString());
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
} else {
Die lhs = ((ScalarDiceExpression) ((DiceEvaluatorResult) left).diceVal).scalar;
Die rhs = ((ScalarDiceExpression) ((DiceEvaluatorResult) right).diceVal).scalar;
@@ -430,10 +430,10 @@ public class Evaluator {
case DICELIST: {
if (left.type != DICE || ((DiceEvaluatorResult) left).diceVal.isList()) {
Errors.inst.printError(EK_EVAL_INVDICE, left.type.toString());
- return new Tree<>(Node.FAIL(left));
+ return new SimpleTree<>(Node.FAIL(left));
} else if (right.type != DICE || ((DiceEvaluatorResult) right).diceVal.isList()) {
Errors.inst.printError(EK_EVAL_INVDICE, right.type.toString());
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
} else {
Die lhs = ((ScalarDiceExpression) ((DiceEvaluatorResult) left).diceVal).scalar;
Die rhs = ((ScalarDiceExpression) ((DiceEvaluatorResult) right).diceVal).scalar;
@@ -445,38 +445,38 @@ public class Evaluator {
}
default:
Errors.inst.printError(EK_EVAL_UNDICE, op.toString());
- return new Tree<>(Node.FAIL());
+ return new SimpleTree<>(Node.FAIL());
}
- return new Tree<>(new Node(Node.Type.RESULT, res));
+ return new SimpleTree<>(new Node(Node.Type.RESULT, res));
}
/* Evaluate a binary math operator. */
- private static ITree<Node> evaluateMathBinary(final Token.Type op, final EvaluatorResult left,
+ private static Tree<Node> evaluateMathBinary(final Token.Type op, final EvaluatorResult left,
final EvaluatorResult right, final Context ctx) {
if (left.type == STRING || right.type == STRING) {
Errors.inst.printError(EK_EVAL_STRINGMATH);
- return new Tree<>(Node.FAIL());
+ return new SimpleTree<>(Node.FAIL());
} else if (left.type == FAILURE || right.type == FAILURE) {
- return new Tree<>(Node.FAIL());
+ return new SimpleTree<>(Node.FAIL());
} else if (left.type == INT && right.type != INT) {
Errors.inst.printError(EK_EVAL_MISMATH);
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
} else if (left.type == FLOAT && right.type != FLOAT) {
Errors.inst.printError(EK_EVAL_MISMATH);
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
} else if (left.type == DICE && right.type != DICE) {
Errors.inst.printError(EK_EVAL_MISMATH);
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
} else if (right.type == INT && left.type != INT) {
Errors.inst.printError(EK_EVAL_MISMATH);
- return new Tree<>(Node.FAIL(left));
+ return new SimpleTree<>(Node.FAIL(left));
} else if (right.type == FLOAT && left.type != FLOAT) {
Errors.inst.printError(EK_EVAL_MISMATH);
- return new Tree<>(Node.FAIL(left));
+ return new SimpleTree<>(Node.FAIL(left));
} else if (right.type == DICE && left.type != DICE) {
Errors.inst.printError(EK_EVAL_MISMATH);
- return new Tree<>(Node.FAIL(left));
+ return new SimpleTree<>(Node.FAIL(left));
}
EvaluatorResult res = null;
@@ -491,10 +491,10 @@ public class Evaluator {
} else if (left.type == DICE) {
if (((DiceEvaluatorResult) left).diceVal.isList()) {
Errors.inst.printError(EK_EVAL_INVDICE, left.toString());
- return new Tree<>(Node.FAIL(left));
+ return new SimpleTree<>(Node.FAIL(left));
} else if (((DiceEvaluatorResult) right).diceVal.isList()) {
Errors.inst.printError(EK_EVAL_INVDICE, right.toString());
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
}
Die lhs = ((ScalarDiceExpression) ((DiceEvaluatorResult) left).diceVal).scalar;
@@ -517,10 +517,10 @@ public class Evaluator {
} else if (left.type == DICE) {
if (((DiceEvaluatorResult) left).diceVal.isList()) {
Errors.inst.printError(EK_EVAL_INVDICE, left.toString());
- return new Tree<>(Node.FAIL(left));
+ return new SimpleTree<>(Node.FAIL(left));
} else if (((DiceEvaluatorResult) right).diceVal.isList()) {
Errors.inst.printError(EK_EVAL_INVDICE, right.toString());
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
}
Die lhs = ((ScalarDiceExpression) ((DiceEvaluatorResult) left).diceVal).scalar;
@@ -543,10 +543,10 @@ public class Evaluator {
} else if (left.type == DICE) {
if (((DiceEvaluatorResult) left).diceVal.isList()) {
Errors.inst.printError(EK_EVAL_INVDICE, left.toString());
- return new Tree<>(Node.FAIL(left));
+ return new SimpleTree<>(Node.FAIL(left));
} else if (((DiceEvaluatorResult) right).diceVal.isList()) {
Errors.inst.printError(EK_EVAL_INVDICE, right.toString());
- return new Tree<>(Node.FAIL(right));
+ return new SimpleTree<>(Node.FAIL(right));
}
Die lhs = ((ScalarDiceExpression) ((DiceEvaluatorResult) left).diceVal).scalar;
@@ -581,7 +581,7 @@ public class Evaluator {
}
} else {
Errors.inst.printError(EK_EVAL_DIVDICE);
- return new Tree<>(Node.FAIL());
+ return new SimpleTree<>(Node.FAIL());
}
break;
@@ -607,21 +607,21 @@ public class Evaluator {
}
} else {
Errors.inst.printError(EK_EVAL_DIVDICE);
- return new Tree<>(Node.FAIL());
+ return new SimpleTree<>(Node.FAIL());
}
break;
}
default:
Errors.inst.printError(EK_EVAL_UNMATH, op.toString());
- return new Tree<>(Node.FAIL());
+ return new SimpleTree<>(Node.FAIL());
}
- return new Tree<>(new Node(Node.Type.RESULT, res));
+ return new SimpleTree<>(new Node(Node.Type.RESULT, res));
}
/* Evaluate a token reference. */
- private ITree<Node> evaluateTokenRef(final Token tk, final Context ctx) {
+ private Tree<Node> evaluateTokenRef(final Token tk, final Context ctx) {
EvaluatorResult res = null;
switch (tk.type) {
@@ -643,6 +643,6 @@ public class Evaluator {
res = new EvaluatorResult(FAILURE);
}
- return new Tree<>(new Node(Node.Type.RESULT, res));
+ return new SimpleTree<>(new Node(Node.Type.RESULT, res));
}
}
diff --git a/base/src/bjc/dicelang/eval/FailureEvaluatorResult.java b/base/src/bjc/dicelang/eval/FailureEvaluatorResult.java
index 1d0ad7b..dee725e 100644
--- a/base/src/bjc/dicelang/eval/FailureEvaluatorResult.java
+++ b/base/src/bjc/dicelang/eval/FailureEvaluatorResult.java
@@ -1,8 +1,8 @@
package bjc.dicelang.eval;
import bjc.dicelang.Node;
-import bjc.data.ITree;
import bjc.data.Tree;
+import bjc.data.SimpleTree;
/**
* Represents an evaluation ending in failure.
@@ -14,7 +14,7 @@ public class FailureEvaluatorResult extends EvaluatorResult {
/**
* Original node data
*/
- public ITree<Node> origVal;
+ public Tree<Node> origVal;
/**
* Create a new generic failure.
@@ -29,7 +29,7 @@ public class FailureEvaluatorResult extends EvaluatorResult {
* @param orig
* The tree that caused the failure.
*/
- public FailureEvaluatorResult(final ITree<Node> orig) {
+ public FailureEvaluatorResult(final Tree<Node> orig) {
super(Type.FAILURE);
origVal = orig;
@@ -42,7 +42,7 @@ public class FailureEvaluatorResult extends EvaluatorResult {
* The node that caused the failure.
*/
public FailureEvaluatorResult(final Node orig) {
- this(new Tree<>(orig));
+ this(new SimpleTree<>(orig));
}
/**
diff --git a/base/src/bjc/dicelang/expr/ExprREPL.java b/base/src/bjc/dicelang/expr/ExprREPL.java
index bbfeeb2..7cc53ee 100644
--- a/base/src/bjc/dicelang/expr/ExprREPL.java
+++ b/base/src/bjc/dicelang/expr/ExprREPL.java
@@ -2,8 +2,8 @@ package bjc.dicelang.expr;
import java.util.Scanner;
-import bjc.data.ITree;
-import bjc.funcdata.IList;
+import bjc.data.Tree;
+import bjc.funcdata.ListEx;
import bjc.utils.parserutils.TreeConstructor;
/**
@@ -54,7 +54,7 @@ public class ExprREPL {
System.out.println();
/* Shunt infix tokens to postfix tokens. */
- final IList<Token> postfixTokens = Shunter.shuntTokens(infixTokens);
+ final ListEx<Token> postfixTokens = Shunter.shuntTokens(infixTokens);
System.out.println("Lexed tokens: ");
for(final Token tok : postfixTokens) {
System.out.println("\t" + tok);
@@ -73,7 +73,7 @@ public class ExprREPL {
/*
* Construct a tree from the list of postfixed tokens.
*/
- final ITree<Token> ast = TreeConstructor.constructTree(postfixTokens,
+ final Tree<Token> ast = TreeConstructor.constructTree(postfixTokens,
tok -> tok.typ.isOperator);
/*
diff --git a/base/src/bjc/dicelang/expr/Lexer.java b/base/src/bjc/dicelang/expr/Lexer.java
index 20e2a40..f9a645a 100644
--- a/base/src/bjc/dicelang/expr/Lexer.java
+++ b/base/src/bjc/dicelang/expr/Lexer.java
@@ -3,7 +3,7 @@ package bjc.dicelang.expr;
import java.util.LinkedList;
import java.util.List;
-import bjc.funcdata.IList;
+import bjc.funcdata.ListEx;
import bjc.utils.parserutils.splitter.ConfigurableTokenSplitter;
/*
@@ -50,10 +50,10 @@ public class Lexer {
/* Process each token. */
for(final String spacedToken : spacedTokens) {
/* Split on operators. */
- final IList<String> splitTokens = split.split(spacedToken);
+ final ListEx<String> splitTokens = split.split(spacedToken);
/* Convert strings to tokens. */
- final IList<Token> rawTokens = splitTokens.map(tok -> {
+ final ListEx<Token> rawTokens = splitTokens.map(tok -> {
return tks.lexToken(tok, spacedToken);
});
diff --git a/base/src/bjc/dicelang/expr/Parser.java b/base/src/bjc/dicelang/expr/Parser.java
index 8f02853..990b2c8 100644
--- a/base/src/bjc/dicelang/expr/Parser.java
+++ b/base/src/bjc/dicelang/expr/Parser.java
@@ -1,6 +1,6 @@
package bjc.dicelang.expr;
-import bjc.data.ITree;
+import bjc.data.Tree;
/**
* Parser for simple math expressions.
@@ -16,7 +16,7 @@ public class Parser {
* The AST to canonicalize.
* @return The canonicalized AST.
*/
- public static String toCanonicalExpr(final ITree<Token> ast) {
+ public static String toCanonicalExpr(final Tree<Token> ast) {
final Token data = ast.getHead();
if (ast.getChildrenCount() == 0) {
@@ -25,8 +25,8 @@ public class Parser {
}
/* The left/right children. */
- final ITree<Token> left = ast.getChild(0);
- final ITree<Token> right = ast.getChild(1);
+ final Tree<Token> left = ast.getChild(0);
+ final Tree<Token> right = ast.getChild(1);
/* Recursively canonicalize them. */
String leftExpr = toCanonicalExpr(left);
diff --git a/base/src/bjc/dicelang/expr/Shunter.java b/base/src/bjc/dicelang/expr/Shunter.java
index f1d3414..bfc0a83 100644
--- a/base/src/bjc/dicelang/expr/Shunter.java
+++ b/base/src/bjc/dicelang/expr/Shunter.java
@@ -4,7 +4,7 @@ import java.util.Deque;
import java.util.LinkedList;
import bjc.funcdata.FunctionalList;
-import bjc.funcdata.IList;
+import bjc.funcdata.ListEx;
/**
* Converts a infix series of tokens into a prefix series of tokens.
@@ -20,9 +20,9 @@ public class Shunter {
*
* @return The tokens in postfix order.
*/
- public static IList<Token> shuntTokens(final Token[] infixTokens) {
+ public static ListEx<Token> shuntTokens(final Token[] infixTokens) {
/* The returned tokens. */
- final IList<Token> postfixTokens = new FunctionalList<>();
+ final ListEx<Token> postfixTokens = new FunctionalList<>();
/* The current stack of operators. */
final Deque<Token> opStack = new LinkedList<>();
diff --git a/base/src/bjc/dicelang/tokens/Token.java b/base/src/bjc/dicelang/tokens/Token.java
index e4b97d1..e8fc605 100644
--- a/base/src/bjc/dicelang/tokens/Token.java
+++ b/base/src/bjc/dicelang/tokens/Token.java
@@ -1,6 +1,6 @@
package bjc.dicelang.tokens;
-import bjc.funcdata.IList;
+import bjc.funcdata.ListEx;
/*
* @TODO 10/09/17 Ben Culkin :TokenReorg
@@ -85,7 +85,7 @@ public class Token {
* - TAG* (the tagged construct)
*
*/
- public IList<Token> tokenValues;
+ public ListEx<Token> tokenValues;
public Token(final Type typ) {
type = typ;
@@ -97,7 +97,7 @@ public class Token {
intValue = val;
}
- public Token(final Type typ, final IList<Token> tkVals) {
+ public Token(final Type typ, final ListEx<Token> tkVals) {
this(typ);
tokenValues = tkVals;
diff --git a/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java b/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java
index bcd0e2f..f001d89 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java
@@ -32,7 +32,7 @@ public class DieBoxCLI {
/**
* The current set of variable bindings
*/
- public IMap<String, StatementValue> bindings = new FunctionalMap<>();
+ public MapEx<String, StatementValue> bindings = new FunctionalMap<>();
/**
* The current source of random numbers.
@@ -42,20 +42,20 @@ public class DieBoxCLI {
/**
* The built-in diebox commands.
*/
- public static final IMap<String, Command> builtInCommands;
+ public static final MapEx<String, Command> builtInCommands;
/**
* The built-in diebox literal formers.
*/
- public static final IMap<String, Command> builtInliterals;
+ public static final MapEx<String, Command> builtInliterals;
/**
* The current set of diebox commands.
*/
- public final IMap<String, Command> commands;
+ public final MapEx<String, Command> commands;
/**
* The current set of diebox literal-formers.
*/
- public final IMap<String, Command> literals;
+ public final MapEx<String, Command> literals;
private int numStatements = 0;