diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2018-02-15 15:25:09 -0500 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2018-02-15 15:25:09 -0500 |
| commit | 5028ad9a1faad0e363d017f18363e8062ba59871 (patch) | |
| tree | 80df30dc24a2cd79abf7533b98fcfcd28b1f4fee /JPratt/src/examples | |
| parent | 1112bb1b44bb3aabe439a2b9f88a51a9c1e435de (diff) | |
Formatting and things
Diffstat (limited to 'JPratt/src/examples')
7 files changed, 49 insertions, 25 deletions
diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/AssignCommand.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/AssignCommand.java index 8b96850..1800043 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/AssignCommand.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/AssignCommand.java @@ -19,7 +19,7 @@ class AssignCommand extends NonBinaryCommand<String, String, TestContext> { throws ParserException { final Token<String, String> name = operand.getHead(); - switch (name.getKey()) { + switch(name.getKey()) { case "(literal)": case "(vref)": break; 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 2d04440..cf5e521 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java @@ -53,7 +53,7 @@ public class PrattParserTest { * Main method. * * @param args - * Unused CLI arguments. + * Unused CLI arguments. */ public static void main(final String[] args) { /* @@ -124,8 +124,9 @@ public class PrattParserTest { System.out.print("Enter a command (blank line to exit): "); String ln = scn.nextLine(); - while (!ln.trim().equals("")) { - final Iterator<Token<String, String>> tokens = preprocessInput(ops, filtered, ln, reserved, ctx); + while(!ln.trim().equals("")) { + final Iterator<Token<String, String>> tokens = preprocessInput(ops, filtered, ln, reserved, + ctx); try { final StringTokenStream tokenStream = new StringTokenStream(tokens); @@ -135,18 +136,20 @@ public class PrattParserTest { */ tokenStream.next(); - final ITree<Token<String, String>> rawTree = parser.parseExpression(0, tokenStream, ctx, true); + final ITree<Token<String, String>> rawTree = parser.parseExpression(0, tokenStream, ctx, + true); - if (!tokenStream.headIs("(end)")) { + if(!tokenStream.headIs("(end)")) { System.out.println("\nMultiple expressions on line"); } System.out.printf("\nParsed expression:\n%s", rawTree); - final ITree<LangAST> tokenTree = rawTree.rebuildTree(LangAST::fromToken, LangAST::fromToken); + final ITree<LangAST> tokenTree = rawTree.rebuildTree(LangAST::fromToken, + LangAST::fromToken); System.out.printf("\nAST-ized expression:\n%s", tokenTree); - } catch (ParserException pex) { + } catch(ParserException pex) { pex.printStackTrace(); } @@ -166,20 +169,19 @@ public class PrattParserTest { final List<String> splitTokens = new LinkedList<>(); - for (final String raw : rawTokens) { - if (raw.equals("")) - continue; + for(final String raw : rawTokens) { + if(raw.equals("")) continue; boolean doSplit = false; - for (final String op : ops) { - if (raw.contains(op)) { + for(final String op : ops) { + if(raw.contains(op)) { doSplit = true; break; } } - if (doSplit) { + if(doSplit) { IList<String> splitStrangs = split.split(raw); splitStrangs.removeMatching(""); @@ -242,7 +244,8 @@ public class PrattParserTest { /* * Inline conditional. */ - final NonInitialCommand<String, String, TestContext> ifElse = ternary(6, 0, "else", litToken("cond"), false); + final NonInitialCommand<String, String, TestContext> ifElse = ternary(6, 0, "else", litToken("cond"), + false); parser.addNonInitialCommand("if", ifElse); /* @@ -316,7 +319,8 @@ public class PrattParserTest { /* * Array indexing. */ - final NonInitialCommand<String, String, TestContext> arrayIdx = postCircumfix(60, 0, "]", litToken("idx")); + final NonInitialCommand<String, String, TestContext> arrayIdx = postCircumfix(60, 0, "]", + litToken("idx")); parser.addNonInitialCommand("[", arrayIdx); /* @@ -342,15 +346,15 @@ public class PrattParserTest { /* * Array literals. */ - final InitialCommand<String, String, TestContext> arrayLiteral = delimited(0, ",", "]", litToken("array"), - idfun, idfun, idfun, false); + final InitialCommand<String, String, TestContext> arrayLiteral = delimited(0, ",", "]", + litToken("array"), idfun, idfun, idfun, false); parser.addInitialCommand("[", arrayLiteral); /* * JSON literals. */ - final InitialCommand<String, String, TestContext> jsonLiteral = delimited(0, ",", "}", litToken("json"), idfun, - idfun, idfun, false); + final InitialCommand<String, String, TestContext> jsonLiteral = delimited(0, ",", "}", litToken("json"), + idfun, idfun, idfun, false); parser.addInitialCommand("{", jsonLiteral); /* diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/Tokenizer.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/Tokenizer.java index f84dd7d..052c521 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/Tokenizer.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/Tokenizer.java @@ -23,9 +23,9 @@ final class Tokenizer implements Function<String, Token<String, String>> { @Override public Token<String, String> apply(final String strang) { - if (ops.contains(strang) || reserved.contains(strang)) + if(ops.contains(strang) || reserved.contains(strang)) return litToken(strang); - else if (strang.matches("(?:[\\u00B2\\u00B3\\u00B9\\u2070]|[\\u2074-\\u2079])+")) { + else if(strang.matches("(?:[\\u00B2\\u00B3\\u00B9\\u2070]|[\\u2074-\\u2079])+")) { /* * This regular expression matches series of unicode * super - scripts 1 - 9. diff --git a/JPratt/src/examples/java/bjc/pratt/examples/lang/VarCommand.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/VarCommand.java index 0ca72cf..4b212b8 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/VarCommand.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/VarCommand.java @@ -15,7 +15,7 @@ class VarCommand extends AbstractInitialCommand<String, String, TestContext> { final ParserContext<String, String, TestContext> ctx) throws ParserException { final Token<String, String> name = ctx.tokens.current(); - switch (name.getKey()) { + switch(name.getKey()) { case "(literal)": case "(vref)": ctx.tokens.next(); 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 index 753276a..4fa84b8 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LangAST.java @@ -11,7 +11,7 @@ public interface LangAST { static LangAST fromToken(Token<String, String> token) throws EvaluatorException { String key = token.getKey(); - switch (key) { + switch(key) { case "(literal)": return LiteralAST.fromToken(token); default: 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 index cf12fe9..d9a7ad2 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/ast/LiteralAST.java @@ -7,7 +7,7 @@ public interface LiteralAST extends LangAST { static LiteralAST fromToken(Token<String, String> tok) { return null; } - + @Override default TopDownTransformResult getEvaluationStrategy() { return TopDownTransformResult.TRANSFORM; 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 index 56fc719..ae53d4f 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/EvaluatorException.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/evaluator/EvaluatorException.java @@ -1,12 +1,32 @@ 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); } |
