diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2018-10-14 20:18:35 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2018-10-14 20:18:35 -0400 |
| commit | a5b854189955aed457d4bad9d66203eebae0cd46 (patch) | |
| tree | fa24428203eb72f28da3b81c0a22c568f3b6b8dc | |
| parent | cd7d50ec5a4effb37816595c881a1cd05223cc58 (diff) | |
Remove unused code
13 files changed, 19 insertions, 551 deletions
diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/LeafConverter.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/LeafConverter.java deleted file mode 100644 index 96bc3ae..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/LeafConverter.java +++ /dev/null @@ -1,13 +0,0 @@ -package bjc.pratt.examples.lang; - -import java.util.function.Function; - -import bjc.pratt.examples.lang.ast.LangAST; -import bjc.pratt.tokens.Token; - -final class LeafConverter implements Function<Token<String, String>, LangAST> { - @Override - public LangAST apply(Token<String, String> leaf) { - return LangAST.fromToken(leaf); - } -}
\ No newline at end of file diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/NodeCollapser.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/NodeCollapser.java deleted file mode 100644 index 61041e5..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/NodeCollapser.java +++ /dev/null @@ -1,15 +0,0 @@ -package bjc.pratt.examples.lang; - -import java.util.function.BiFunction; - -import bjc.pratt.examples.lang.ast.LangAST; -import bjc.pratt.tokens.Token; -import bjc.utils.funcdata.IList; - -final class NodeCollapser implements BiFunction<Token<String, String>, IList<LangAST>, LangAST> { - @Override - public LangAST apply(Token<String, String> token, IList<LangAST> children) { - // TODO Auto-generated method stub - return null; - } -}
\ No newline at end of file diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java index 6191f05..b0a1d8b 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java @@ -18,7 +18,6 @@ import java.util.function.UnaryOperator; import bjc.pratt.PrattParser; import bjc.pratt.commands.InitialCommand; import bjc.pratt.commands.NonInitialCommand; -import bjc.pratt.examples.lang.ast.LangAST; import bjc.pratt.tokens.StringToken; import bjc.pratt.tokens.StringTokenStream; import bjc.pratt.tokens.Token; @@ -26,7 +25,6 @@ import bjc.pratt.tokens.Token; import bjc.utils.data.ITree; import bjc.utils.data.TransformIterator; import bjc.utils.funcdata.IList; -import bjc.utils.functypes.ID; import bjc.utils.parserutils.ParserException; import bjc.utils.parserutils.splitter.ConfigurableTokenSplitter; import bjc.utils.parserutils.splitter.ExcludingTokenSplitter; @@ -40,8 +38,8 @@ import bjc.utils.parserutils.splitter.TokenSplitter; * */ public class PrattParserTest { - public final static Set<String> ops; - public final static Set<String> reserved; + private final static Set<String> ops; + private final static Set<String> reserved; static { /* @@ -55,7 +53,7 @@ public class PrattParserTest { ops.add(":="); - ops.add("|>"); + ops.addAll(Arrays.asList("|>", "[|]")); ops.addAll(Arrays.asList("->", "=>")); ops.addAll(Arrays.asList("||", "&&")); @@ -90,12 +88,12 @@ public class PrattParserTest { lo.addSimpleDelimiters(":="); - lo.addSimpleDelimiters("|>"); + lo.addSimpleDelimiters("|>", "[|]"); lo.addSimpleDelimiters("->, =>"); lo.addSimpleDelimiters("||", "&&"); lo.addSimpleDelimiters("<=", ">="); - + lo.addSimpleDelimiters("\u00B1"); // Unicode plus/minus lo.addSimpleDelimiters(".", ",", ";", ":"); lo.addSimpleDelimiters("=", "<", ">"); @@ -142,13 +140,6 @@ public class PrattParserTest { } System.out.printf("\nParsed expression:\n%s", rawTree); - - final LangAST ast = rawTree.collapse(new LeafConverter(), new NodeCollapser(), ID.id()); - - // Remove this once we have LangAST all done. - final ITree<LangAST> tokenTree = rawTree.rebuildTree(LangAST::fromToken, LangAST::fromToken); - - System.out.printf("\nAST-ized expression:\n%s\nNEW:\n%s", tokenTree, ast); } catch (ParserException pex) { pex.printStackTrace(); } @@ -163,9 +154,9 @@ public class PrattParserTest { scn.close(); } - private static Iterator<Token<String, String>> preprocessInput(final Set<String> ops, final Set<String> reserved, + private static Iterator<Token<String, String>> preprocessInput(final Set<String> oops, final Set<String> reservd, final TokenSplitter split, final String ln, final TestContext ctx) { - final String[] rawTokens = ln.split("\\s+"); + final String[] rawTokens = ln.split("\\r\\.\\r"); final List<String> splitTokens = new LinkedList<>(); @@ -175,20 +166,22 @@ public class PrattParserTest { boolean doSplit = false; - for (final String op : ops) { + for (final String op : oops) { if (raw.contains(op)) { doSplit = true; break; } } - if (doSplit) { - IList<String> splitStrangs = split.split(raw); + String strang = raw.replaceAll("\\.(\\.+)", "$1"); + + if (doSplit) { + IList<String> splitStrangs = split.split(strang); splitStrangs.removeMatching(""); splitStrangs.forEach(splitTokens::add); } else { - splitTokens.add(raw); + splitTokens.add(strang); } } @@ -196,7 +189,7 @@ public class PrattParserTest { final Iterator<String> source = splitTokens.iterator(); - final Tokenizer tokenzer = new Tokenizer(ops, reserved, ctx); + final Tokenizer tokenzer = new Tokenizer(oops, reservd, ctx); final Iterator<Token<String, String>> tokens = new TransformIterator<>(source, tokenzer); @@ -288,6 +281,11 @@ public class PrattParserTest { parser.addNonInitialCommand("||", ssRelJoin); /* + * Range operator. + */ + parser.addNonInitialCommand("[|]", infixNon(18)); + + /* * Add/subtracting operators. */ final NonInitialCommand<String, String, TestContext> addSub = infixLeft(20); diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/BooleanAST.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/BooleanAST.java deleted file mode 100644 index e900a93..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/BooleanAST.java +++ /dev/null @@ -1,46 +0,0 @@ -package bjc.pratt.examples.lang.ast; - -import bjc.pratt.examples.lang.evaluator.LangResult; - -public class BooleanAST extends LiteralAST { - public final boolean val; - - public BooleanAST(boolean vl) { - super(LiteralType.BOOLEAN); - - val = vl; - } - - @Override - public LangResult toResult() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (val ? 1231 : 1237); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - BooleanAST other = (BooleanAST) obj; - if (val != other.val) - return false; - return true; - } - - @Override - public String toString() { - return "BooleanAST [val=" + val + "]"; - } -} diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/DoubleAST.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/DoubleAST.java deleted file mode 100644 index 6c74566..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/DoubleAST.java +++ /dev/null @@ -1,48 +0,0 @@ -package bjc.pratt.examples.lang.ast; - -import bjc.pratt.examples.lang.evaluator.LangResult; - -public class DoubleAST extends LiteralAST { - public final double value; - - public DoubleAST(double vl) { - super(LiteralType.DOUBLE); - - value = vl; - } - - @Override - public LangResult toResult() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - long temp; - temp = Double.doubleToLongBits(value); - result = prime * result + (int) (temp ^ (temp >>> 32)); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - DoubleAST other = (DoubleAST) obj; - if (Double.doubleToLongBits(value) != Double.doubleToLongBits(other.value)) - return false; - return true; - } - - @Override - public String toString() { - return "DoubleAST [value=" + value + "]"; - } -} diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/IntegerAST.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/IntegerAST.java deleted file mode 100644 index bd4b2ab..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/IntegerAST.java +++ /dev/null @@ -1,60 +0,0 @@ -package bjc.pratt.examples.lang.ast; - -import bjc.pratt.examples.lang.evaluator.LangResult; - -/** - * AST containing an integer. - * - * @author student - * - */ -public class IntegerAST extends LiteralAST { - /** - * Value of the integer. - */ - public final int val; - - /** - * Create a new integer AST. - * - * @param vl - * The value of the integer. - */ - public IntegerAST(int vl) { - super(LiteralType.INTEGER); - - val = vl; - } - - @Override - public LangResult toResult() { - return null; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + val; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - IntegerAST other = (IntegerAST) obj; - if (val != other.val) - return false; - return true; - } - - @Override - public String toString() { - return "IntegerAST [val=" + val + "]"; - } -} diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java deleted file mode 100644 index 3c6030e..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java +++ /dev/null @@ -1,105 +0,0 @@ -package bjc.pratt.examples.lang.ast; - -import bjc.pratt.examples.lang.evaluator.EvaluatorException; -import bjc.pratt.examples.lang.evaluator.LangResult; -import bjc.pratt.tokens.Token; -import bjc.utils.data.TopDownTransformResult; - -/** - * Represents the AST for the language. - * - * @author student - * - */ -public abstract class LangAST { - /** - * The possible type of the AST nodes. - * - * @author student - * - */ - public static enum ASTType { - /** - * An AST literal - */ - LITERAL, - /** - * An AST operator - */ - OPERATOR - } - - /** - * The type of the node. - */ - public final ASTType type; - - protected LangAST(ASTType typ) { - type = typ; - } - - /** - * Evaluate the AST. - * - * @return The evaluated AST - */ - public abstract LangResult toResult(); - - /** - * Create an AST from a token. - * - * @param token - * The token to create the AST from - * @return The new AST - * @throws EvaluatorException - * If something goes wrong. - */ - public static LangAST fromToken(Token<String, String> token) throws EvaluatorException { - String key = token.getKey(); - - switch (key) { - case "(literal)": - return LiteralAST.fromToken(token.getValue()); - default: - // String msg = String.format("Unknown token type '%s'", key); - - return new StringAST("RAW: " + token.toString()); - } - } - - /** - * Get the way an AST node should be evaluated. - * - * @return The way to evaluate the AST node. - */ - public TopDownTransformResult getEvaluationStrategy() { - return TopDownTransformResult.PUSHDOWN; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - LangAST other = (LangAST) obj; - if (type != other.type) - return false; - return true; - } - - @Override - public String toString() { - return "LangAST [type=" + type + "]"; - } -}
\ No newline at end of file diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java deleted file mode 100644 index 70735c5..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java +++ /dev/null @@ -1,74 +0,0 @@ -package bjc.pratt.examples.lang.ast; - -import bjc.utils.data.TopDownTransformResult; -import bjc.utils.parserutils.TokenUtils; - -/** - * AST node for a literal. - * - * @author student - * - */ -public abstract class LiteralAST extends LangAST { - public static enum LiteralType { - INTEGER, STRING, BOOLEAN, DOUBLE - } - - public final LiteralType type; - - protected LiteralAST(LiteralType typ) { - super(ASTType.LITERAL); - - type = typ; - } - /** - * Create a new literal AST - * - * @param tok - * The token value to build from. - * @return The AST for the token. - */ - public static LiteralAST fromToken(String tok) { - if(tok.equalsIgnoreCase("true")) { - return new BooleanAST(true); - } else if(tok.equalsIgnoreCase("false")) { - return new BooleanAST(false); - } else if(tok.matches("[+-]?\\d+")) { - return new IntegerAST(Integer.parseInt(tok)); - } else if(TokenUtils.isDouble(tok)) { - return new DoubleAST(Double.parseDouble(tok)); - } - - return new StringAST("RAW: " + tok); - } - - @Override - public TopDownTransformResult getEvaluationStrategy() { - return TopDownTransformResult.TRANSFORM; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; - } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - LiteralAST other = (LiteralAST) obj; - if (type != other.type) - return false; - return true; - } - @Override - public String toString() { - return "LiteralAST [type=" + type + "]"; - } -} diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/OperatorAST.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/OperatorAST.java deleted file mode 100644 index 19ae088..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/OperatorAST.java +++ /dev/null @@ -1,32 +0,0 @@ -package bjc.pratt.examples.lang.ast; - -import bjc.pratt.examples.lang.evaluator.LangResult; - -public abstract class OperatorAST extends LangAST { - public static enum OperatorType { - - } - - public final OperatorType type; - - public OperatorAST(OperatorType typ) { - super(ASTType.OPERATOR); - - type = typ; - } - - public static OperatorAST fromToken(String tok) { - switch (tok) { - - } - - return null; - } - - @Override - public LangResult toResult() { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/StringAST.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/StringAST.java deleted file mode 100644 index 891c625..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/StringAST.java +++ /dev/null @@ -1,64 +0,0 @@ -package bjc.pratt.examples.lang.ast; - -import bjc.pratt.examples.lang.evaluator.LangResult; - -/** - * Holds a string value. - * - * @author student - * - */ -public class StringAST extends LiteralAST { - /** - * The value of the string. - */ - public final String val; - - /** - * Create a new string AST. - * - * @param vl - * The string value. - */ - public StringAST(String vl) { - super(LiteralType.STRING); - - val = vl; - } - - @Override - public LangResult toResult() { - // @TODO Auto-generated method stub - return null; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((val == null) ? 0 : val.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - StringAST other = (StringAST) obj; - if (val == null) { - if (other.val != null) - return false; - } else if (!val.equals(other.val)) - return false; - return true; - } - - @Override - public String toString() { - return "StringAST [val=" + val + "]"; - } -} diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/EvaluatorException.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/EvaluatorException.java deleted file mode 100644 index ae53d4f..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/EvaluatorException.java +++ /dev/null @@ -1,33 +0,0 @@ -package bjc.pratt.examples.lang.evaluator; - -/** - * Exception thrown when evaluation goes wrong. - * - * @author EVE - * - */ -public class EvaluatorException extends RuntimeException { - private static final long serialVersionUID = -8610585421069729811L; - - /** - * Create a new evaluator exception with a message and a cause. - * - * @param message - * The message for the exception. - * @param cause - * The cause of the exception. - */ - public EvaluatorException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Create a new evaluator exception with a message. - * - * @param message - * The message for the exception. - */ - public EvaluatorException(String message) { - super(message); - } -}
\ No newline at end of file diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangEvaluator.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangEvaluator.java deleted file mode 100644 index 3ebab16..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangEvaluator.java +++ /dev/null @@ -1,29 +0,0 @@ -package bjc.pratt.examples.lang.evaluator; - -import bjc.pratt.examples.lang.ast.LangAST; -import bjc.utils.data.ITree; - -/** - * Evaluate an AST. - * - * @author student - * - */ -public class LangEvaluator { - /** - * Evaluate an AST - * - * @param ast - * The AST to evaluate - * @return The result of evaluation. - */ - public LangResult evaluate(ITree<LangAST> ast) { - ITree<LangAST> evaluatedTree = ast.topDownTransform(LangAST::getEvaluationStrategy, this::evaluateNode); - - return evaluatedTree.getHead().toResult(); - } - - private ITree<LangAST> evaluateNode(ITree<LangAST> node) { - return node; - } -}
\ No newline at end of file diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangResult.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangResult.java deleted file mode 100644 index 35c5bb3..0000000 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/LangResult.java +++ /dev/null @@ -1,11 +0,0 @@ -package bjc.pratt.examples.lang.evaluator; - -/** - * The result of evaluating an AST. - * - * @author student - * - */ -public class LangResult { - -}
\ No newline at end of file |
