From 0fa4f162f4e42a455dbb7e7459854b9467337863 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Fri, 22 Apr 2016 14:48:25 -0400 Subject: Formatting changes --- .../java/bjc/dicelang/ast/DiceASTEvaluator.java | 104 ++++++++++----------- 1 file changed, 52 insertions(+), 52 deletions(-) (limited to 'dice-lang/src/main/java/bjc/dicelang/ast/DiceASTEvaluator.java') diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTEvaluator.java b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTEvaluator.java index 6044602..4e7d6fb 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTEvaluator.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTEvaluator.java @@ -31,6 +31,21 @@ import bjc.dicelang.ast.nodes.VariableDiceNode; * */ public class DiceASTEvaluator { + private static IResult bindLiteralValue(IDiceASTNode leafNode, + IFunctionalMap> enviroment) { + String variableName = ((VariableDiceNode) leafNode).getVariable(); + + if (enviroment.containsKey(variableName)) { + IResult result = evaluateAST(enviroment.get(variableName), + enviroment); + + return result; + } + + throw new UnsupportedOperationException( + "Attempted to deref unbound variable " + variableName); + } + /** * Build the map of operations to use when collapsing the AST * @@ -106,29 +121,24 @@ public class DiceASTEvaluator { return operatorCollapsers; } - private static IPair> parseLet( + private static void doArrayAssign( IFunctionalMap> enviroment, - IFunctionalList>> nodes) { - if (nodes.getSize() != 2) { + IPair> nameNode, + ITree nameTree, ITree valueTree, + IHolder childCount, ITree child) { + if (nameTree.getHead().getType() != DiceASTType.VARIABLE) { throw new UnsupportedOperationException( - "Can only use let with two expressions."); + "Assigning to complex variables isn't supported. Problem node is " + + nameNode.getRight()); } - ITree bindTree = nodes.getByIndex(0).getRight(); - ITree expressionTree = nodes.getByIndex(1) - .getRight(); - - IFunctionalMap> letEnviroment = enviroment - .extend(); - - evaluateAST(bindTree, letEnviroment); - IResult exprResult = evaluateAST(expressionTree, letEnviroment); + String varName = child.transformHead((nameNod) -> { + return ((VariableDiceNode) nameNod).getVariable(); + }); - IFunctionalList> childrn = nodes - .map((pair) -> pair.getRight()); + enviroment.put(varName, valueTree.getChild(childCount.getValue())); - return new Pair<>(exprResult, - new Tree<>(OperatorDiceNode.LET, childrn)); + childCount.transform(val -> val + 1); } /** @@ -171,21 +181,6 @@ public class DiceASTEvaluator { } } - private static IResult bindLiteralValue(IDiceASTNode leafNode, - IFunctionalMap> enviroment) { - String variableName = ((VariableDiceNode) leafNode).getVariable(); - - if (enviroment.containsKey(variableName)) { - IResult result = evaluateAST(enviroment.get(variableName), - enviroment); - - return result; - } - - throw new UnsupportedOperationException( - "Attempted to deref unbound variable " + variableName); - } - private static IResult evaluateLiteral(IDiceASTNode leafNode) { DiceLiteralType literalType = ((ILiteralDiceNode) leafNode) .getLiteralType(); @@ -269,26 +264,6 @@ public class DiceASTEvaluator { }); } - private static void doArrayAssign( - IFunctionalMap> enviroment, - IPair> nameNode, - ITree nameTree, ITree valueTree, - IHolder childCount, ITree child) { - if (nameTree.getHead().getType() != DiceASTType.VARIABLE) { - throw new UnsupportedOperationException( - "Assigning to complex variables isn't supported. Problem node is " - + nameNode.getRight()); - } - - String varName = child.transformHead((nameNod) -> { - return ((VariableDiceNode) nameNod).getVariable(); - }); - - enviroment.put(varName, valueTree.getChild(childCount.getValue())); - - childCount.transform(val -> val + 1); - } - private static IPair> parseGroup( IFunctionalList>> nodes) { if (nodes.getSize() != 2) { @@ -313,4 +288,29 @@ public class DiceASTEvaluator { }); }); } + + private static IPair> parseLet( + IFunctionalMap> enviroment, + IFunctionalList>> nodes) { + if (nodes.getSize() != 2) { + throw new UnsupportedOperationException( + "Can only use let with two expressions."); + } + + ITree bindTree = nodes.getByIndex(0).getRight(); + ITree expressionTree = nodes.getByIndex(1) + .getRight(); + + IFunctionalMap> letEnviroment = enviroment + .extend(); + + evaluateAST(bindTree, letEnviroment); + IResult exprResult = evaluateAST(expressionTree, letEnviroment); + + IFunctionalList> childrn = nodes + .map((pair) -> pair.getRight()); + + return new Pair<>(exprResult, + new Tree<>(OperatorDiceNode.LET, childrn)); + } } -- cgit v1.2.3