summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/v2/DiceLangEngine.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2017-02-22 12:36:55 -0500
committerbculkin2442 <bjculkin@mix.wvu.edu>2017-02-22 12:36:55 -0500
commitf4845d197c043aaedfd7dc6ee2a00d5843e54eb3 (patch)
tree982df636d5940370e0ed491439ea3e171683f9a1 /dice-lang/src/bjc/dicelang/v2/DiceLangEngine.java
parentfc0a33e00865b6ea66d3e1b8ce785ef02682a23b (diff)
Update to allow backflow during step-evals
Diffstat (limited to 'dice-lang/src/bjc/dicelang/v2/DiceLangEngine.java')
-rw-r--r--dice-lang/src/bjc/dicelang/v2/DiceLangEngine.java44
1 files changed, 40 insertions, 4 deletions
diff --git a/dice-lang/src/bjc/dicelang/v2/DiceLangEngine.java b/dice-lang/src/bjc/dicelang/v2/DiceLangEngine.java
index 07b6b10..aa6d519 100644
--- a/dice-lang/src/bjc/dicelang/v2/DiceLangEngine.java
+++ b/dice-lang/src/bjc/dicelang/v2/DiceLangEngine.java
@@ -15,6 +15,7 @@ import bjc.utils.funcutils.StringUtils;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
+import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.regex.Matcher;
@@ -38,6 +39,8 @@ public class DiceLangEngine {
private boolean postfixMode;
// Should we reverse the token stream
private boolean prefixMode;
+ // Should we do step-by-step evaluation
+ private boolean stepEval;
// Shunter for token postfixing
private Shunter shunt;
@@ -114,6 +117,7 @@ public class DiceLangEngine {
debugMode = true;
postfixMode = false;
prefixMode = false;
+ stepEval = true;
streamEng = new StreamEngine(this);
@@ -394,13 +398,45 @@ public class DiceLangEngine {
for(ITree<Node> ast : astForest) {
System.out.println("\t\tTree " + treeNo + " in forest:\n\t\t " + ast);
- Evaluator.Result res = eval.evaluate(ast);
- System.out.printf("\t\tEvaluates to %s", res);
+ if(stepEval) {
+ int step = 1;
- if(res.type == Evaluator.Result.Type.DICE) {
- System.out.println(" (sample roll " + res.diceVal.value() + ")");
+ for(Iterator<ITree<Node>> itr = eval.stepDebug(ast); itr.hasNext();){
+ ITree<Node> nodeStep = itr.next();
+
+ System.out.printf("\t\tStep %d: Node is %s", step, nodeStep);
+
+ if(nodeStep.getHead().type == Node.Type.RESULT) {
+ Evaluator.Result res = nodeStep.getHead().resultVal;
+
+ System.out.printf(" (result is %s", res);
+
+ if(res.type == Evaluator.Result.Type.DICE) {
+ System.out.printf(" (sample roll %s)", res.diceVal.value());
+ }
+
+ if(res.origVal != null) {
+ System.out.printf(" (original tree is %s)", res.origVal);
+ }
+
+ System.out.printf(")");
+ }
+
+
+ System.out.println();
+ step += 1;
+ }
+ } else {
+ Evaluator.Result res = eval.evaluate(ast);
+ System.out.printf("\t\tEvaluates to %s", res);
+
+ if(res.type == Evaluator.Result.Type.DICE) {
+ System.out.println(" (sample roll " + res.diceVal.value() + ")");
+ }
}
+ System.out.println();
+
treeNo += 1;
}
}