From 05c17c6e0e8e5e9015da4d1396587c4af0ea09d3 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 10 Apr 2016 21:39:05 -0400 Subject: Removed old code that wasn't being used --- .../java/bjc/dicelang/old/ast/DiceASTParser.java | 119 --------------------- 1 file changed, 119 deletions(-) delete mode 100644 dice-lang/src/main/java/bjc/dicelang/old/ast/DiceASTParser.java (limited to 'dice-lang/src/main/java/bjc/dicelang/old/ast/DiceASTParser.java') diff --git a/dice-lang/src/main/java/bjc/dicelang/old/ast/DiceASTParser.java b/dice-lang/src/main/java/bjc/dicelang/old/ast/DiceASTParser.java deleted file mode 100644 index c9b48c8..0000000 --- a/dice-lang/src/main/java/bjc/dicelang/old/ast/DiceASTParser.java +++ /dev/null @@ -1,119 +0,0 @@ -package bjc.dicelang.old.ast; - -import java.util.Deque; -import java.util.LinkedList; -import java.util.function.Function; - -import bjc.dicelang.old.ast.nodes.IDiceASTNode; -import bjc.dicelang.old.ast.nodes.LiteralDiceNode; -import bjc.dicelang.old.ast.nodes.OperatorDiceNode; -import bjc.dicelang.old.ast.nodes.VariableDiceNode; -import bjc.utils.data.IPair; -import bjc.utils.data.Pair; -import bjc.utils.funcdata.FunctionalStringTokenizer; -import bjc.utils.funcdata.IFunctionalList; -import bjc.utils.funcutils.ListUtils; -import bjc.utils.parserutils.AST; -import bjc.utils.parserutils.ShuntingYard; -import bjc.utils.parserutils.TreeConstructor; - -/** - * Create an AST from a string expression - * - * @author ben - * - */ -public class DiceASTParser { - private static final class NodeBaker - implements Function { - @Override - public IDiceASTNode apply(String tok) { - if (isOperator(tok)) { - return OperatorDiceNode.fromString(tok); - } else if (LiteralDiceNode.isLiteral(tok)) { - return new LiteralDiceNode(tok); - } else { - return new VariableDiceNode(tok); - } - } - } - - /** - * The yard to use for shunting expressions - */ - private static ShuntingYard yard; - - static { - yard = new ShuntingYard<>(); - - yard.addOp("d", 5); // dice operator: use for creating variable - // size dice groups - yard.addOp("c", 6); // compound operator: use for creating compound - // dice from expressions - yard.addOp(":=", 0); // binding operator: Bind a name to a variable - // expression - } - - /** - * Build an AST from a string expression - * - * @param exp - * The string to build from - * @return An AST built from the passed in string - */ - public static AST buildAST(String exp) { - IFunctionalList tokens = FunctionalStringTokenizer - .fromString(exp).toList(); - - Deque> ops = new LinkedList<>(); - - ops.add(new Pair<>("+", "\\+")); - ops.add(new Pair<>("-", "-")); - ops.add(new Pair<>("*", "\\*")); - ops.add(new Pair<>("/", "/")); - ops.add(new Pair<>(":=", ":=")); - - IFunctionalList semiExpandedTokens = ListUtils - .splitTokens(tokens, ops); - - ops = new LinkedList<>(); - - ops.add(new Pair<>("(", "\\(")); - ops.add(new Pair<>(")", "\\)")); - - IFunctionalList fullyExpandedTokens = ListUtils - .deAffixTokens(semiExpandedTokens, ops); - - IFunctionalList shunted = yard.postfix(fullyExpandedTokens, - (s) -> s); - - AST rawAST = TreeConstructor.constructTree(shunted, - DiceASTParser::isOperator); - - AST bakedAST = rawAST.transmuteAST(new NodeBaker()); - - return bakedAST; - } - - /** - * Check if a token represents an operator - * - * @param tok - * The token to check if it represents an operator - * @return Whether or not the token represents an operator - */ - private static boolean isOperator(String tok) { - switch (tok) { - case ":=": - case "+": - case "-": - case "*": - case "/": - case "c": - case "d": - return true; - default: - return false; - } - } -} -- cgit v1.2.3