summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/pom.xml14
-rw-r--r--base/src/bjc/dicelang/CLIArgsParser.java25
-rw-r--r--base/src/bjc/dicelang/CompilerTweaker.java16
-rw-r--r--base/src/bjc/dicelang/Define.java27
-rw-r--r--base/src/bjc/dicelang/DiceLangConsole.java43
-rw-r--r--base/src/bjc/dicelang/DiceLangEngine.java124
-rw-r--r--base/src/bjc/dicelang/Errors.java48
-rw-r--r--base/src/bjc/dicelang/Evaluator.java91
-rw-r--r--base/src/bjc/dicelang/EvaluatorResult.java18
-rw-r--r--base/src/bjc/dicelang/Node.java12
-rw-r--r--base/src/bjc/dicelang/Parser.java21
-rw-r--r--base/src/bjc/dicelang/Shunter.java40
-rw-r--r--base/src/bjc/dicelang/Token.java6
-rw-r--r--base/src/bjc/dicelang/Tokenizer.java35
-rw-r--r--base/src/bjc/dicelang/expr/Lexer.java8
-rw-r--r--base/src/bjc/dicelang/expr/Parser.java22
-rw-r--r--base/src/bjc/dicelang/expr/Shunter.java19
-rw-r--r--base/src/bjc/dicelang/expr/Token.java8
-rw-r--r--base/src/bjc/dicelang/expr/TokenType.java21
-rw-r--r--base/src/bjc/dicelang/expr/Tokens.java9
-rw-r--r--base/src/bjc/dicelang/scl/BooleanSCLToken.java4
-rw-r--r--base/src/bjc/dicelang/scl/FloatSCLToken.java4
-rw-r--r--base/src/bjc/dicelang/scl/IntSCLToken.java2
-rw-r--r--base/src/bjc/dicelang/scl/StreamControlConsole.java19
-rw-r--r--base/src/bjc/dicelang/scl/StreamEngine.java19
-rw-r--r--base/src/bjc/dicelang/scl/StringSCLToken.java6
-rw-r--r--base/src/bjc/dicelang/scl/WordListSCLToken.java4
-rw-r--r--base/src/bjc/dicelang/scl/WordSCLToken.java10
-rw-r--r--base/src/bjc/dicelang/util/ResourceLoader.java5
29 files changed, 301 insertions, 379 deletions
diff --git a/base/pom.xml b/base/pom.xml
index e8c0288..bfea276 100644
--- a/base/pom.xml
+++ b/base/pom.xml
@@ -1,4 +1,6 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -22,7 +24,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
- <version>1.5.0</version>
+ <version>1.5.0</version>
<executions>
<execution>
@@ -39,7 +41,7 @@
<argument>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n</argument>
<argument>-classpath</argument>
- <classpath/>
+ <classpath />
<argument>${main.class}</argument>
</arguments>
@@ -118,5 +120,11 @@
<artifactId>jline</artifactId>
<version>0.9.9</version>
</dependency>
+
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>19.0</version>
+ </dependency>
</dependencies>
</project>
diff --git a/base/src/bjc/dicelang/CLIArgsParser.java b/base/src/bjc/dicelang/CLIArgsParser.java
index 54061bd..0ee3501 100644
--- a/base/src/bjc/dicelang/CLIArgsParser.java
+++ b/base/src/bjc/dicelang/CLIArgsParser.java
@@ -25,9 +25,9 @@ public class CLIArgsParser {
* Parse the provided set of CLI arguments.
*
* @param args
- * The CLI arguments to parse.
+ * The CLI arguments to parse.
* @param eng
- * The engine to affect with parsing.
+ * The engine to affect with parsing.
*
* @return Whether or not to continue to the DiceLang repl.
*/
@@ -48,9 +48,8 @@ public class CLIArgsParser {
final String arg = args[i];
/*
- * @TODO 10/08/17 Ben Culkin :CLIArgRefactor
- * Use whatever library gets added to BJC-Utils for
- * this, and extend these to do more things.
+ * @TODO 10/08/17 Ben Culkin :CLIArgRefactor Use whatever library gets added to
+ * BJC-Utils for this, and extend these to do more things.
*/
switch (arg) {
case "-d":
@@ -117,8 +116,8 @@ public class CLIArgsParser {
break;
case "-ctf":
case "--compiler-tweak-file":
- /* @NOTE
- * Not yet implemented.
+ /*
+ * @NOTE Not yet implemented.
*/
default:
Errors.inst.printError(EK_CLI_UNARG, arg);
@@ -130,8 +129,7 @@ public class CLIArgsParser {
}
/* Handle parsing a simple define. */
- private static int simpleDefine(final int i, final String[] args,
- final DiceLangEngine eng) {
+ private static int simpleDefine(final int i, final String[] args, final DiceLangEngine eng) {
/* :DefineRefactor */
if (i >= args.length - 1) {
@@ -140,8 +138,7 @@ public class CLIArgsParser {
}
if (i >= args.length - 2) {
- final Define dfn = new Define(5, false, false, false, null, args[i + 1],
- Arrays.asList(""));
+ final Define dfn = new Define(5, false, false, false, null, args[i + 1], Arrays.asList(""));
if (dfn.inError) {
return -1;
@@ -151,8 +148,7 @@ public class CLIArgsParser {
return i + 1;
}
- final Define dfn = new Define(5, false, false, false, null, args[i + 1],
- Arrays.asList(args[i + 2]));
+ final Define dfn = new Define(5, false, false, false, null, args[i + 1], Arrays.asList(args[i + 2]));
if (dfn.inError) {
return -1;
@@ -163,8 +159,7 @@ public class CLIArgsParser {
}
/* Load a series of defines from a file. */
- private static int defineFile(final int i, final String[] args,
- final DiceLangEngine eng) {
+ private static int defineFile(final int i, final String[] args, final DiceLangEngine eng) {
if (i >= args.length - 1) {
Errors.inst.printError(EK_CLI_MISARG, "define-file");
return -1;
diff --git a/base/src/bjc/dicelang/CompilerTweaker.java b/base/src/bjc/dicelang/CompilerTweaker.java
index 1154be4..2d0482a 100644
--- a/base/src/bjc/dicelang/CompilerTweaker.java
+++ b/base/src/bjc/dicelang/CompilerTweaker.java
@@ -13,14 +13,14 @@ import bjc.utils.parserutils.splitter.ConfigurableTokenSplitter;
*/
public class CompilerTweaker {
/* Bits of the compiler necessary */
- private final DiceLangEngine eng;
+ private final DiceLangEngine eng;
private final ConfigurableTokenSplitter opExpander;
/**
* Create a new compiler tweaker.
*
* @param engine
- * The engine to tweak.
+ * The engine to tweak.
*/
public CompilerTweaker(final DiceLangEngine engine) {
eng = engine;
@@ -32,7 +32,7 @@ public class CompilerTweaker {
* Add a string literal to the compiler's internal banks.
*
* @param val
- * The string literal to add.
+ * The string literal to add.
*
* @return The key into the string literal table for this string.
*/
@@ -47,7 +47,7 @@ public class CompilerTweaker {
* Add a line defn to the compiler.
*
* @param dfn
- * The defn to add.
+ * The defn to add.
*/
public void addLineDefine(final Define dfn) {
eng.addLineDefine(dfn);
@@ -57,7 +57,7 @@ public class CompilerTweaker {
* Add a token defn to the compiler.
*
* @param dfn
- * The defn to add.
+ * The defn to add.
*/
public void addTokenDefine(final Define dfn) {
eng.addTokenDefine(dfn);
@@ -67,7 +67,7 @@ public class CompilerTweaker {
* Adds delimiters that are expanded from tokens.
*
* @param delims
- * The delimiters to expand on.
+ * The delimiters to expand on.
*/
public void addDelimiter(final String... delims) {
opExpander.addSimpleDelimiters(delims);
@@ -77,7 +77,7 @@ public class CompilerTweaker {
* Adds multi-character delimiters that are expanded from tokens.
*
* @param delims
- * The multi-character delimiters to expand on.
+ * The multi-character delimiters to expand on.
*/
public void addMultiDelimiter(final String... delims) {
opExpander.addMultiDelimiters(delims);
@@ -94,7 +94,7 @@ public class CompilerTweaker {
* Change the max no. of times defines are allowed to recur.
*
* @param times
- * The number of times to allow defines to recur.
+ * The number of times to allow defines to recur.
*/
public static void setDefineRecurLimit(final int times) {
Define.MAX_RECURS = times;
diff --git a/base/src/bjc/dicelang/Define.java b/base/src/bjc/dicelang/Define.java
index 5524477..8d70307 100644
--- a/base/src/bjc/dicelang/Define.java
+++ b/base/src/bjc/dicelang/Define.java
@@ -40,10 +40,10 @@ public class Define implements UnaryOperator<String>, Comparable<Define> {
public static int MAX_RECURS = 10;
/** The priority of this definition. */
- public final int priority;
+ public final int priority;
/** Whether or not this definition is in error. */
- public final boolean inError;
+ public final boolean inError;
/* Whether this define is recurring. */
private boolean doRecur;
@@ -56,37 +56,36 @@ public class Define implements UnaryOperator<String>, Comparable<Define> {
private Pattern searcher;
/* The array of replacement strings to use. */
- private Iterator<String> replacers;
+ private Iterator<String> replacers;
/* The current replacement string to use. */
- private String replacer;
+ private String replacer;
/**
* Create a new define.
*
* @param priorty
- * The priority of the define.
+ * The priority of the define.
*
* @param isSub
- * Whether or not this is a 'sub-define'
+ * Whether or not this is a 'sub-define'
*
* @param recur
- * Whether this define is recursive or not.
+ * Whether this define is recursive or not.
*
* @param isCircular
- * Whether this define is circular or not.
+ * Whether this define is circular or not.
*
* @param predicte
- * The string to use as a predicate.
+ * The string to use as a predicate.
*
* @param searchr
- * The string to use as a search.
+ * The string to use as a search.
*
* @param replacrs
- * The source for replacement strings.
+ * The source for replacement strings.
*/
- public Define(final int priorty, final boolean isSub, final boolean recur,
- final boolean isCircular,
- final String predicte, final String searchr, final Iterable<String> replacrs) {
+ public Define(final int priorty, final boolean isSub, final boolean recur, final boolean isCircular,
+ final String predicte, final String searchr, final Iterable<String> replacrs) {
priority = priorty;
doRecur = recur;
subType = isSub;
diff --git a/base/src/bjc/dicelang/DiceLangConsole.java b/base/src/bjc/dicelang/DiceLangConsole.java
index 296874f..365ab59 100644
--- a/base/src/bjc/dicelang/DiceLangConsole.java
+++ b/base/src/bjc/dicelang/DiceLangConsole.java
@@ -30,7 +30,7 @@ public class DiceLangConsole {
* Create a new console.
*
* @param args
- * The CLI args for the console.
+ * The CLI args for the console.
*/
public DiceLangConsole(final String[] args) {
commandNumber = 0;
@@ -66,9 +66,8 @@ public class DiceLangConsole {
}
/* Run commands. */
- /* @NOTE
- * Should switch this to a do-while loop to reduce code
- * duplication.
+ /*
+ * @NOTE Should switch this to a do-while loop to reduce code duplication.
*/
while (!comm.equals("quit") && !comm.equals("exit")) {
if (comm.startsWith("pragma")) {
@@ -126,9 +125,8 @@ public class DiceLangConsole {
/* Run pragmas. */
/*
- * @TODO 10/09/17 Ben Culkin :PragmaRefactor
- * Swap to using something that makes it easier to add
- * pragmas.
+ * @TODO 10/09/17 Ben Culkin :PragmaRefactor Swap to using something that makes
+ * it easier to add pragmas.
*/
switch (pragmaName) {
case "debug":
@@ -191,16 +189,15 @@ public class DiceLangConsole {
/* Parse a define macro. */
private boolean defineMode(final String defineText) {
/* Grab all of the separator spaces. */
- final int firstIndex = defineText.indexOf(' ');
- final int secondIndex = defineText.indexOf(' ', firstIndex + 1);
- final int thirdIndex = defineText.indexOf(' ', secondIndex + 1);
- final int fourthIndex = defineText.indexOf(' ', thirdIndex + 1);
- final int fifthIndex = defineText.indexOf(' ', fourthIndex + 1);
- final int sixthIndex = defineText.indexOf(' ', fifthIndex + 1);
+ final int firstIndex = defineText.indexOf(' ');
+ final int secondIndex = defineText.indexOf(' ', firstIndex + 1);
+ final int thirdIndex = defineText.indexOf(' ', secondIndex + 1);
+ final int fourthIndex = defineText.indexOf(' ', thirdIndex + 1);
+ final int fifthIndex = defineText.indexOf(' ', fourthIndex + 1);
+ final int sixthIndex = defineText.indexOf(' ', fifthIndex + 1);
/*
- * Error if we got something we didn't need, or didn't get
- * something we need.
+ * Error if we got something we didn't need, or didn't get something we need.
*/
if (firstIndex == -1) {
Errors.inst.printError(EK_CONS_INVDEFINE, "(no priority)");
@@ -251,14 +248,11 @@ public class DiceLangConsole {
}
/* Do we want this to be a recursive pattern? */
- final boolean doRecur = defineText.substring(secondIndex + 1, thirdIndex)
- .equalsIgnoreCase("true");
+ final boolean doRecur = defineText.substring(secondIndex + 1, thirdIndex).equalsIgnoreCase("true");
/* Do we want this pattern to have a guard? */
- final boolean hasGuard = defineText.substring(thirdIndex + 1, fourthIndex)
- .equalsIgnoreCase("true");
+ final boolean hasGuard = defineText.substring(thirdIndex + 1, fourthIndex).equalsIgnoreCase("true");
/* Do we want this pattern to use circular replacements. */
- final boolean isCircular = defineText.substring(thirdIndex + 1, fourthIndex)
- .equalsIgnoreCase("true");
+ final boolean isCircular = defineText.substring(thirdIndex + 1, fourthIndex).equalsIgnoreCase("true");
/* The part of the string that contains patterns. */
final String pats = defineText.substring(fifthIndex + 1).trim();
@@ -289,9 +283,8 @@ public class DiceLangConsole {
replacePatterns.add(patMatcher.group(1));
}
- final Define dfn = new Define(priority, subMode, doRecur,
- isCircular, guardPattern, searchPattern,
- replacePatterns);
+ final Define dfn = new Define(priority, subMode, doRecur, isCircular, guardPattern, searchPattern,
+ replacePatterns);
if (dfn.inError) {
return false;
@@ -311,7 +304,7 @@ public class DiceLangConsole {
* Main method.
*
* @param args
- * CLI arguments.
+ * CLI arguments.
*/
public static void main(final String[] args) {
final DiceLangConsole console = new DiceLangConsole(args);
diff --git a/base/src/bjc/dicelang/DiceLangEngine.java b/base/src/bjc/dicelang/DiceLangEngine.java
index 71e5ee8..b99a141 100644
--- a/base/src/bjc/dicelang/DiceLangEngine.java
+++ b/base/src/bjc/dicelang/DiceLangEngine.java
@@ -38,9 +38,8 @@ public class DiceLangEngine {
private static final Logger LOG = Logger.getLogger(DiceLangEngine.class.getName());
/*
- * The random fields that are package private instead of private-private
- * are for the benefit of the tweaker, so that it can mess around with
- * them.
+ * The random fields that are package private instead of private-private are for
+ * the benefit of the tweaker, so that it can mess around with them.
*/
/* Split tokens around operators with regex */
@@ -74,12 +73,12 @@ public class DiceLangEngine {
public final IMap<Integer, String> symTable;
/* String literal tables */
- private final IMap<Integer, String> stringLits;
- private final IMap<String, String> stringLiterals;
+ private final IMap<Integer, String> stringLits;
+ private final IMap<String, String> stringLiterals;
/* Lists of defns. */
- private final IList<Define> lineDefns;
- private final IList<Define> tokenDefns;
+ private final IList<Define> lineDefns;
+ private final IList<Define> tokenDefns;
/* Are defns currently sorted by priority? */
private boolean defnsSorted;
@@ -121,18 +120,18 @@ public class DiceLangEngine {
nextLiteral = 1;
/* Initial mode settings. */
- debugMode = true;
+ debugMode = true;
postfixMode = false;
- prefixMode = false;
- stepEval = false;
+ prefixMode = false;
+ stepEval = false;
/* Create components. */
- shunt = new Shunter();
- parsr = new Parser();
+ shunt = new Shunter();
+ parsr = new Parser();
streamEng = new StreamEngine(this);
- tokenzer = new Tokenizer(this);
- eval = new Evaluator(this);
+ tokenzer = new Tokenizer(this);
+ eval = new Evaluator(this);
}
/** Sort defns by priority. */
@@ -147,7 +146,7 @@ public class DiceLangEngine {
* Add a defn that's applied to lines.
*
* @param dfn
- * The defn to add.
+ * The defn to add.
*/
public void addLineDefine(final Define dfn) {
lineDefns.add(dfn);
@@ -159,7 +158,7 @@ public class DiceLangEngine {
* Add a defn that's applied to tokens.
*
* @param dfn
- * The defn to add.
+ * The defn to add.
*/
public void addTokenDefine(final Define dfn) {
tokenDefns.add(dfn);
@@ -212,22 +211,21 @@ public class DiceLangEngine {
}
/* Matches double-angle bracketed strings. */
- private final Pattern nonExpandPattern =
- Pattern.compile("<<([^\\>]*(?:\\>(?:[^\\>])*)*)>>");
+ private final Pattern nonExpandPattern = Pattern.compile("<<([^\\>]*(?:\\>(?:[^\\>])*)*)>>");
/**
* Run a command to completion.
*
* @param command
- * The command to run
+ * The command to run
*
* @return Whether or not the command ran successfully
*/
public boolean runCommand(final String command) {
/* Preprocess the command into tokens */
- /* @NOTE
- * Instead of strings, this should maybe use a RawToken
- * class or something.
+ /*
+ * @NOTE Instead of strings, this should maybe use a RawToken class or
+ * something.
*/
final IList<String> preprocessedTokens = preprocessCommand(command);
@@ -264,9 +262,9 @@ public class DiceLangEngine {
/* Apply token defns */
for (final Define dfn : tokenDefns.toIterable()) {
- /* @NOTE
- * What happens with a define that produces
- * multiple tokens from one token?
+ /*
+ * @NOTE What happens with a define that produces multiple tokens from one
+ * token?
*/
newTok = dfn.apply(newTok);
}
@@ -290,7 +288,7 @@ public class DiceLangEngine {
}
if (debugMode) {
- String msg = String.format("\tCommand after tokenization: %s\n", lexedTokens.toString());
+ String msg = String.format("\tCommand after tokenization: %s\n", lexedTokens.toString());
LOG.fine(msg);
System.out.print(msg);
}
@@ -306,8 +304,7 @@ public class DiceLangEngine {
}
if (debugMode && !postfixMode) {
- String msg = String.format("\tCommand after pre-shunter removal: %s\n",
- preparedTokens.toString());
+ String msg = String.format("\tCommand after pre-shunter removal: %s\n", preparedTokens.toString());
LOG.fine(msg);
System.out.print(msg);
}
@@ -324,9 +321,7 @@ public class DiceLangEngine {
} else if (prefixMode) {
/* Reverse directional tokens */
/*
- * @NOTE
- * Merge these two operations into one iteration
- * over the list?
+ * @NOTE Merge these two operations into one iteration over the list?
*/
preparedTokens.reverse();
shuntedTokens = preparedTokens.map(this::reverseToken);
@@ -340,9 +335,7 @@ public class DiceLangEngine {
/* Expand token groups */
final IList<Token> readyTokens = shuntedTokens.flatMap(tk -> {
- if (tk.type == Token.Type.TOKGROUP ||
- tk.type == Token.Type.TAGOP ||
- tk.type == Token.Type.TAGOPR ) {
+ if (tk.type == Token.Type.TOKGROUP || tk.type == Token.Type.TAGOP || tk.type == Token.Type.TAGOPR) {
LOG.finer(String.format("Expanding token group to: %s\n", tk.tokenValues.toString()));
return tk.tokenValues;
} else {
@@ -351,8 +344,7 @@ public class DiceLangEngine {
});
if (debugMode && !postfixMode) {
- String msg = String.format("\tCommand after re-preshunting: %s\n",
- readyTokens.toString());
+ String msg = String.format("\tCommand after re-preshunting: %s\n", readyTokens.toString());
LOG.fine(msg);
System.out.print(msg);
}
@@ -393,8 +385,7 @@ public class DiceLangEngine {
/* Run the tokens through the stream engine */
final IList<String> streamToks = new FunctionalList<>();
- final boolean succ = streamEng.doStreams(command.split(" "),
- streamToks);
+ final boolean succ = streamEng.doStreams(command.split(" "), streamToks);
if (!succ) {
return null;
@@ -420,7 +411,7 @@ public class DiceLangEngine {
}
/* Remove string literals. */
- final List<String> destringedParts = TokenUtils.removeDQuotedStrings(newComm);
+ final List<String> destringedParts = TokenUtils.removeDQuotedStrings(newComm);
final StringBuffer destringedCommand = new StringBuffer();
for (final String part : destringedParts) {
@@ -428,18 +419,16 @@ public class DiceLangEngine {
if (part.startsWith("\"") && part.endsWith("\"")) {
/* Get the actual string. */
final String litName = "stringLiteral" + nextLiteral;
- final String litVal = part.substring(1, part.length() - 1);
+ final String litVal = part.substring(1, part.length() - 1);
/*
- * Insert the string with its escape sequences
- * interpreted.
+ * Insert the string with its escape sequences interpreted.
*/
final String descVal = TokenUtils.descapeString(litVal);
stringLiterals.put(litName, descVal);
if (debugMode)
- LOG.finer(String.format("Replaced string literal '%s' with literal no. %d",
- descVal, nextLiteral));
+ LOG.finer(String.format("Replaced string literal '%s' with literal no. %d", descVal, nextLiteral));
nextLiteral += 1;
@@ -466,7 +455,7 @@ public class DiceLangEngine {
}
/* Split the command into tokens */
- final String strang = destringedCommand.toString();
+ final String strang = destringedCommand.toString();
IList<String> tokens = FunctionalStringTokenizer.fromString(strang).toList();
/* Temporarily remove non-expanding tokens */
@@ -478,8 +467,7 @@ public class DiceLangEngine {
final String tkName = "nonExpandToken" + nextLiteral++;
nonExpandedTokens.put(tkName, nonExpandMatcher.group(1));
- LOG.finer(String.format("Pulled non-expander '%s' to '%s'", nonExpandMatcher.group(1),
- tkName));
+ LOG.finer(String.format("Pulled non-expander '%s' to '%s'", nonExpandMatcher.group(1), tkName));
return tkName;
}
@@ -487,8 +475,7 @@ public class DiceLangEngine {
});
if (debugMode) {
- String msg = String.format("\tCommand after removal of non-expanders: %s\n",
- tokens.toString());
+ String msg = String.format("\tCommand after removal of non-expanders: %s\n", tokens.toString());
LOG.fine(msg);
System.out.print(msg);
}
@@ -497,22 +484,22 @@ public class DiceLangEngine {
IList<String> fullyExpandedTokens = tokens.flatMap(opExpander::split);
if (debugMode) {
- String msg = String.format("\tCommand after token expansion: %s\n",
- fullyExpandedTokens.toString());
+ String msg = String.format("\tCommand after token expansion: %s\n", fullyExpandedTokens.toString());
LOG.fine(msg);
System.out.print(msg);
}
/* Reinsert non-expanded tokens */
fullyExpandedTokens = fullyExpandedTokens.map(tk -> {
- if (tk.startsWith("nonExpandToken")) return nonExpandedTokens.get(tk);
+ if (tk.startsWith("nonExpandToken"))
+ return nonExpandedTokens.get(tk);
return tk;
});
if (debugMode) {
String msg = String.format("\tCommand after non-expander reinsertion: %s\n",
- fullyExpandedTokens.toString());
+ fullyExpandedTokens.toString());
LOG.fine(msg);
System.out.print(msg);
}
@@ -531,9 +518,7 @@ public class DiceLangEngine {
if (debugMode && stepEval) {
/*
- * @NOTE
- * This is broken until stepwise top-down
- * tree transforms are fixed.
+ * @NOTE This is broken until stepwise top-down tree transforms are fixed.
*/
int step = 1;
@@ -592,8 +577,7 @@ public class DiceLangEngine {
}
/* Preshunt preshunt-marked groups of tokens. */
- private boolean removePreshuntTokens(final IList<Token> lexedTokens,
- final IList<Token> preparedTokens) {
+ private boolean removePreshuntTokens(final IList<Token> lexedTokens, final IList<Token> preparedTokens) {
/* Current nesting level of tokens. */
int curBraceCount = 0;
@@ -608,8 +592,7 @@ public class DiceLangEngine {
if (curBraceCount != 1) {
/*
- * Push the old group onto the group
- * stack.
+ * Push the old group onto the group stack.
*/
bracedTokens.push(curBracedTokens);
}
@@ -619,8 +602,7 @@ public class DiceLangEngine {
/* Close a preshunt group. */
if (curBraceCount == 0) {
/*
- * Error if there couldn't have been an
- * opening.
+ * Error if there couldn't have been an opening.
*/
Errors.inst.printError(EK_ENG_NOOPENING);
return false;
@@ -634,8 +616,7 @@ public class DiceLangEngine {
final boolean success = shunt.shuntTokens(curBracedTokens, preshuntTokens);
if (debugMode) {
- System.out.println("\t\tPreshunted " + curBracedTokens + " into "
- + preshuntTokens);
+ System.out.println("\t\tPreshunted " + curBracedTokens + " into " + preshuntTokens);
}
if (!success) {
@@ -644,23 +625,20 @@ public class DiceLangEngine {
if (curBraceCount >= 1) {
/*
- * Add the preshunt group to the
- * previous group.
+ * Add the preshunt group to the previous group.
*/
curBracedTokens = bracedTokens.pop();
curBracedTokens.add(new Token(Token.Type.TOKGROUP, preshuntTokens));
} else {
/*
- * Add the preshunt group to the token
- * stream.
+ * Add the preshunt group to the token stream.
*/
preparedTokens.add(new Token(Token.Type.TOKGROUP, preshuntTokens));
}
} else {
/*
- * Add the token to the active preshunt group,
- * if there is one..
+ * Add the token to the active preshunt group, if there is one..
*/
if (curBraceCount >= 1) {
curBracedTokens.add(tk);
@@ -685,9 +663,9 @@ public class DiceLangEngine {
}
/* Add a string literal to the string literal table. */
- /* @NOTE
- * The string literal table should be abstracted into some kind of
- * auto-numbered map thing.
+ /*
+ * @NOTE The string literal table should be abstracted into some kind of
+ * auto-numbered map thing.
*/
void addStringLiteral(final int key, final String val) {
stringLits.put(key, val);
diff --git a/base/src/bjc/dicelang/Errors.java b/base/src/bjc/dicelang/Errors.java
index 255db75..de82eed 100644
--- a/base/src/bjc/dicelang/Errors.java
+++ b/base/src/bjc/dicelang/Errors.java
@@ -3,9 +3,9 @@ package bjc.dicelang;
/**
* Repository for error messages.
*
- * @TODO 10/08/17 Ben Culkin :ErrorRefactor
- * This way of handling error messages is not easy to deal with. Something
- * else needs to be done, but I'm not sure what at the moment.
+ * @TODO 10/08/17 Ben Culkin :ErrorRefactor This way of handling error messages
+ * is not easy to deal with. Something else needs to be done, but I'm not
+ * sure what at the moment.
*
* @author EVE
*
@@ -272,10 +272,10 @@ public class Errors {
* Print an error.
*
* @param key
- * The key of the error.
+ * The key of the error.
*
* @param args
- * The arguments for the error.
+ * The arguments for the error.
*/
public void printError(final ErrorKey key, final String... args) {
switch (mode) {
@@ -308,10 +308,8 @@ public class Errors {
break;
case EK_DFN_RECUR:
- System.out.printf(
- "\tERROR: Recursive define didn't converge after %s iterations."
- + " Original string was %s, last iteration was %s\n",
- args[0], args[1], args[2]);
+ System.out.printf("\tERROR: Recursive define didn't converge after %s iterations."
+ + " Original string was %s, last iteration was %s\n", args[0], args[1], args[2]);
break;
case EK_CONS_INVPRAG:
@@ -323,8 +321,7 @@ public class Errors {
break;
case EK_ENG_NOOPENING:
- System.out.printf("\tERROR: Encountered closing doublebrace without"
- + " matching opening doublebrace\n");
+ System.out.printf("\tERROR: Encountered closing doublebrace without" + " matching opening doublebrace\n");
break;
case EK_ENG_NOCLOSING:
@@ -340,8 +337,7 @@ public class Errors {
break;
case EK_TOK_INVFLEX:
- System.out.printf("\tERROR: Invalid flexadecimal number %s in base %s\n", args[0],
- args[1]);
+ System.out.printf("\tERROR: Invalid flexadecimal number %s in base %s\n", args[0], args[1]);
break;
case EK_EVAL_INVNODE:
@@ -349,8 +345,8 @@ public class Errors {
break;
case EK_EVAL_INVBIN:
- System.out.printf("\tERROR: Binary operators take 2 operands, not %s\n"
- + "\tProblem node is %s\n", args[0], args[1]);
+ System.out.printf("\tERROR: Binary operators take 2 operands, not %s\n" + "\tProblem node is %s\n", args[0],
+ args[1]);
break;
case EK_EVAL_UNBIN:
@@ -382,14 +378,11 @@ public class Errors {
break;
case EK_EVAL_INVDCREATE:
- System.out.printf("\tERROR: Dice creation operator expects integers," + " not %s\n",
- args[0]);
+ System.out.printf("\tERROR: Dice creation operator expects integers," + " not %s\n", args[0]);
break;
case EK_EVAL_INVDGROUP:
- System.out.printf("\tERROR: Dice group operator expects scalar dice or integers," +
- " not %s\n",
- args[0]);
+ System.out.printf("\tERROR: Dice group operator expects scalar dice or integers," + " not %s\n", args[0]);
break;
case EK_EVAL_INVDICE:
@@ -413,8 +406,8 @@ public class Errors {
break;
case EK_PARSE_UNCLOSE:
- System.out.printf("\tERROR: Found group closer without opener: (closing was %s"
- + ", expected %s)\n", args[0], args[1]);
+ System.out.printf("\tERROR: Found group closer without opener: (closing was %s" + ", expected %s)\n",
+ args[0], args[1]);
break;
case EK_PARSE_BINARY:
@@ -431,22 +424,21 @@ public class Errors {
case EK_SHUNT_NOTADV:
System.out.printf("\tERROR: Unary operator %s is an adjective, not an adverb. It can't be"
- + " applied to the operator %s\n", args[0], args[1]);
+ + " applied to the operator %s\n", args[0], args[1]);
break;
case EK_SHUNT_NOTADJ:
System.out.printf("\tERROR: Unary operator %s is an adjective, not an adverb. It can't be"
- + " applied to the operator %s\n", args[0], args[1]);
+ + " applied to the operator %s\n", args[0], args[1]);
break;
case EK_SHUNT_NOOP:
- System.out.printf("\tERROR: Unary operator %s is an adverb, but there is no operator"
- + " to apply it to\n", args[0]);
+ System.out.printf("\tERROR: Unary operator %s is an adverb, but there is no operator" + " to apply it to\n",
+ args[0]);
break;
case EK_SHUNT_NOGROUP:
- System.out.printf("\tERROR: Couldn't find matching grouping %s (expected %s)\n", args[0],
- args[1]);
+ System.out.printf("\tERROR: Couldn't find matching grouping %s (expected %s)\n", args[0], args[1]);
break;
case EK_SHUNT_NOTASSOC:
diff --git a/base/src/bjc/dicelang/Evaluator.java b/base/src/bjc/dicelang/Evaluator.java
index f3b2450..0981746 100644
--- a/base/src/bjc/dicelang/Evaluator.java
+++ b/base/src/bjc/dicelang/Evaluator.java
@@ -25,7 +25,6 @@ import static bjc.dicelang.EvaluatorResult.Type.FLOAT;
import static bjc.dicelang.EvaluatorResult.Type.INT;
import static bjc.dicelang.EvaluatorResult.Type.STRING;
-
/* @TODO 10/09/17 Ben Culkin :EvaluatorSplit
* Type/sanity checking should be moved into a seperate stage, not part of
* evaluation.
@@ -60,7 +59,7 @@ public class Evaluator {
* Create a new evaluator.
*
* @param en
- * The engine.
+ * The engine.
*/
public Evaluator(final DiceLangEngine en) {
eng = en;
@@ -70,7 +69,7 @@ public class Evaluator {
* Evaluate a AST.
*
* @param comm
- * The AST to evaluate.
+ * The AST to evaluate.
*
* @return The result of the tree.
*/
@@ -80,9 +79,8 @@ public class Evaluator {
ctx.isDebug = false;
ctx.thunk = itr -> {
/*
- * Deliberately finish the iterator, but ignore results.
- * It's only for stepwise evaluation, but we don't know
- * if stepping the iterator has side effects.
+ * Deliberately finish the iterator, but ignore results. It's only for stepwise
+ * evaluation, but we don't know if stepping the iterator has side effects.
*/
while (itr.hasNext()) {
itr.next();
@@ -90,15 +88,14 @@ public class Evaluator {
};
/* The result. */
- final ITree<Node> res = comm.topDownTransform(
- this::pickEvaluationType,
- node -> this.evaluateNode(node, ctx));
+ final ITree<Node> res = comm.topDownTransform(this::pickEvaluationType, node -> this.evaluateNode(node, ctx));
return res.getHead().resultVal;
}
- /* @NOTE
- * This is broken until stepwise top-down transforms are fixed. */
+ /*
+ * @NOTE This is broken until stepwise top-down transforms are fixed.
+ */
public Iterator<ITree<Node>> stepDebug(final ITree<Node> comm) {
final Context ctx = new Context();
@@ -156,16 +153,15 @@ public class Evaluator {
}
switch (ast.getHead().operatorType) {
- /*
- * @TODO 10/09/17 Ben Culkin :CoerceRefactor :EvaluatorSplit
- * Coercing should be moved to its own class, or at the
- * very least its own method. When the evaluator splits,
- * this node type'll be handled exclusively by the
- * type-checker.
- *
- * Coerce also needs to be able to coerce things to
- * dice and ratios (whenever they get added).
- */
+ /*
+ * @TODO 10/09/17 Ben Culkin :CoerceRefactor :EvaluatorSplit Coercing should be
+ * moved to its own class, or at the very least its own method. When the
+ * evaluator splits, this node type'll be handled exclusively by the
+ * type-checker.
+ *
+ * Coerce also needs to be able to coerce things to dice and ratios (whenever
+ * they get added).
+ */
case COERCE:
final ITree<Node> toCoerce = ast.getChild(0);
final ITree<Node> retVal = new Tree<>(toCoerce.getHead());
@@ -258,16 +254,15 @@ public class Evaluator {
/* Binary operators always have two children. */
if (ast.getChildrenCount() != 2) {
- Errors.inst.printError(EK_EVAL_INVBIN, Integer.toString(ast.getChildrenCount()),
- ast.toString());
+ Errors.inst.printError(EK_EVAL_INVBIN, Integer.toString(ast.getChildrenCount()), ast.toString());
return new Tree<>(Node.FAIL(ast));
}
- final ITree<Node> left = ast.getChild(0);
+ final ITree<Node> left = ast.getChild(0);
final ITree<Node> right = ast.getChild(1);
- final EvaluatorResult leftRes = left.getHead().resultVal;
+ final EvaluatorResult leftRes = left.getHead().resultVal;
final EvaluatorResult rightRes = right.getHead().resultVal;
switch (binOp) {
@@ -291,8 +286,7 @@ public class Evaluator {
}
/* Evaluate a binary operator on strings. */
- private static ITree<Node> evaluateStringBinary(final Token.Type op,
- final EvaluatorResult left,
+ private static ITree<Node> evaluateStringBinary(final Token.Type op, final EvaluatorResult left,
final EvaluatorResult right, final Context ctx) {
if (left.type != STRING) {
Errors.inst.printError(EK_EVAL_INVSTRING, left.type.toString());
@@ -333,36 +327,30 @@ public class Evaluator {
}
/* Evaluate dice binary operators. */
- private static ITree<Node> evaluateDiceBinary(final Token.Type op,
- final EvaluatorResult left,
+ private static ITree<Node> evaluateDiceBinary(final Token.Type op, final EvaluatorResult left,
final EvaluatorResult right, final Context ctx) {
EvaluatorResult res = null;
switch (op) {
- /*
- * @TODO 10/09/17 Ben Culkin :DiceSimplify
- * Figure out some way to simplify this sort of
- * thing.
- */
+ /*
+ * @TODO 10/09/17 Ben Culkin :DiceSimplify Figure out some way to simplify this
+ * sort of thing.
+ */
case DICEGROUP:
if (left.type == DICE && !left.diceVal.isList) {
if (right.type == DICE && !right.diceVal.isList) {
- Die simple = new SimpleDie(
- left.diceVal.scalar,
- right.diceVal.scalar);
+ Die simple = new SimpleDie(left.diceVal.scalar, right.diceVal.scalar);
res = new EvaluatorResult(DICE, simple);
} else if (right.type == INT) {
- res = new EvaluatorResult(DICE,
- new SimpleDie(left.diceVal.scalar, right.intVal));
+ res = new EvaluatorResult(DICE, new SimpleDie(left.diceVal.scalar, right.intVal));
} else {
Errors.inst.printError(EK_EVAL_INVDGROUP, right.type.toString());
return new Tree<>(Node.FAIL(right));
}
} else if (left.type == INT) {
if (right.type == DICE && !right.diceVal.isList) {
- res = new EvaluatorResult(DICE,
- new SimpleDie(left.intVal, right.diceVal.scalar));
+ res = new EvaluatorResult(DICE, new SimpleDie(left.intVal, right.diceVal.scalar));
} else if (right.type == INT) {
res = new EvaluatorResult(DICE, new SimpleDie(left.intVal, right.intVal));
} else {
@@ -382,8 +370,7 @@ public class Evaluator {
Errors.inst.printError(EK_EVAL_INVDICE, right.type.toString());
return new Tree<>(Node.FAIL(right));
} else {
- res = new EvaluatorResult(DICE,
- new CompoundDie(left.diceVal.scalar, right.diceVal.scalar));
+ res = new EvaluatorResult(DICE, new CompoundDie(left.diceVal.scalar, right.diceVal.scalar));
}
break;
@@ -396,8 +383,7 @@ public class Evaluator {
Errors.inst.printError(EK_EVAL_INVDICE, right.type.toString());
return new Tree<>(Node.FAIL(right));
} else {
- res = new EvaluatorResult(DICE,
- new SimpleDieList(left.diceVal.scalar, right.diceVal.scalar));
+ res = new EvaluatorResult(DICE, new SimpleDieList(left.diceVal.scalar, right.diceVal.scalar));
}
break;
@@ -411,8 +397,7 @@ public class Evaluator {
}
/* Evaluate a binary math operator. */
- private static ITree<Node> evaluateMathBinary(final Token.Type op,
- final EvaluatorResult left,
+ private static ITree<Node> evaluateMathBinary(final Token.Type op, final EvaluatorResult left,
final EvaluatorResult right, final Context ctx) {
if (left.type == STRING || right.type == STRING) {
Errors.inst.printError(EK_EVAL_STRINGMATH);
@@ -454,8 +439,8 @@ public class Evaluator {
return new Tree<>(Node.FAIL(right));
}
- res = new EvaluatorResult(DICE, new MathDie(MathDie.MathOp.ADD, left.diceVal.scalar,
- right.diceVal.scalar));
+ res = new EvaluatorResult(DICE,
+ new MathDie(MathDie.MathOp.ADD, left.diceVal.scalar, right.diceVal.scalar));
} else {
res = new EvaluatorResult(FLOAT, left.floatVal + right.floatVal);
}
@@ -474,8 +459,8 @@ public class Evaluator {
return new Tree<>(Node.FAIL(right));
}
- res = new EvaluatorResult(DICE, new MathDie(MathDie.MathOp.SUBTRACT,
- left.diceVal.scalar, right.diceVal.scalar));
+ res = new EvaluatorResult(DICE,
+ new MathDie(MathDie.MathOp.SUBTRACT, left.diceVal.scalar, right.diceVal.scalar));
} else {
res = new EvaluatorResult(FLOAT, left.floatVal - right.floatVal);
}
@@ -494,8 +479,8 @@ public class Evaluator {
return new Tree<>(Node.FAIL(right));
}
- res = new EvaluatorResult(DICE, new MathDie(MathDie.MathOp.MULTIPLY,
- left.diceVal.scalar, right.diceVal.scalar));
+ res = new EvaluatorResult(DICE,
+ new MathDie(MathDie.MathOp.MULTIPLY, left.diceVal.scalar, right.diceVal.scalar));
} else {
res = new EvaluatorResult(FLOAT, left.floatVal * right.floatVal);
}
diff --git a/base/src/bjc/dicelang/EvaluatorResult.java b/base/src/bjc/dicelang/EvaluatorResult.java
index 3ceee9b..e28ebe7 100644
--- a/base/src/bjc/dicelang/EvaluatorResult.java
+++ b/base/src/bjc/dicelang/EvaluatorResult.java
@@ -56,19 +56,19 @@ public class EvaluatorResult {
/**
* The integer value of the result.
*/
- public long intVal;
+ public long intVal;
/**
* The float value of the result.
*/
- public double floatVal;
+ public double floatVal;
/**
* The dice value of the result.
*/
- public DieExpression diceVal;
+ public DieExpression diceVal;
/**
* The string value of the result.
*/
- public String stringVal;
+ public String stringVal;
/**
* Original node data
@@ -79,7 +79,7 @@ public class EvaluatorResult {
* Create a new result.
*
* @param typ
- * The type of the result.
+ * The type of the result.
*/
public EvaluatorResult(final EvaluatorResult.Type typ) {
type = typ;
@@ -89,10 +89,10 @@ public class EvaluatorResult {
* Create a new result.
*
* @param typ
- * The type of the result.
+ * The type of the result.
*
* @param orig
- * The original value of the result.
+ * The original value of the result.
*/
public EvaluatorResult(final EvaluatorResult.Type typ, final ITree<Node> orig) {
this(typ);
@@ -104,10 +104,10 @@ public class EvaluatorResult {
* Create a new result.
*
* @param typ
- * The type of the result.
+ * The type of the result.
*
* @param orig
- * The original value of the result.
+ * The original value of the result.
*/
public EvaluatorResult(final EvaluatorResult.Type typ, final Node orig) {
this(typ, new Tree<>(orig));
diff --git a/base/src/bjc/dicelang/Node.java b/base/src/bjc/dicelang/Node.java
index 746ba34..55273e8 100644
--- a/base/src/bjc/dicelang/Node.java
+++ b/base/src/bjc/dicelang/Node.java
@@ -26,10 +26,10 @@ public class Node {
public final Type type;
// These can have or not have values based of the node type
- public Token tokenVal;
- public Token.Type operatorType;
- public GroupType groupType;
- public EvaluatorResult resultVal;
+ public Token tokenVal;
+ public Token.Type operatorType;
+ public GroupType groupType;
+ public EvaluatorResult resultVal;
public Node(final Type typ) {
type = typ;
@@ -120,8 +120,8 @@ public class Node {
return new Node(Type.RESULT, new EvaluatorResult(FAILURE, orig));
}
- /* @TODO 10/09/17 Ben Culkin :NodeFAIL
- * These methods should be moved to Node.
+ /*
+ * @TODO 10/09/17 Ben Culkin :NodeFAIL These methods should be moved to Node.
*/
/* Create a failing node. */
static Node FAIL() {
diff --git a/base/src/bjc/dicelang/Parser.java b/base/src/bjc/dicelang/Parser.java
index 0861e96..76730b9 100644
--- a/base/src/bjc/dicelang/Parser.java
+++ b/base/src/bjc/dicelang/Parser.java
@@ -36,15 +36,14 @@ public class Parser {
* Parse a series of tokens to a forest of ASTs.
*
* @param tokens
- * The list of tokens to parse.
+ * The list of tokens to parse.
*
* @param results
- * The place to set results.
+ * The place to set results.
*
* @return Whether or not the parse was successful.
*/
- public static boolean parseTokens(final IList<Token> tokens,
- final IList<ITree<Node>> results) {
+ public static boolean parseTokens(final IList<Token> tokens, final IList<ITree<Node>> results) {
final Deque<ITree<Node>> working = new LinkedList<>();
for (final Token tk : tokens) {
@@ -91,7 +90,7 @@ public class Parser {
return false;
} else if (working.size() == 1) {
final ITree<Node> operand = working.pop();
- final ITree<Node> opNode = new Tree<>(new Node(UNARYOP, tk.type));
+ final ITree<Node> opNode = new Tree<>(new Node(UNARYOP, tk.type));
opNode.addChild(operand);
@@ -109,7 +108,7 @@ public class Parser {
Errors.inst.printError(EK_PARSE_UNOPERAND, tk.toString());
} else {
final ITree<Node> operand = working.pop();
- final ITree<Node> opNode = new Tree<>(new Node(UNARYOP, tk.type));
+ final ITree<Node> opNode = new Tree<>(new Node(UNARYOP, tk.type));
opNode.addChild(operand);
@@ -131,9 +130,8 @@ public class Parser {
}
}
- /*
- * Collect the remaining nodes as the roots of the trees in the
- * AST forest.
+ /*
+ * Collect the remaining nodes as the roots of the trees in the AST forest.
*/
for (final ITree<Node> ast : working) {
results.add(ast);
@@ -145,7 +143,7 @@ public class Parser {
/* Handle a binary operator. */
private static void handleBinaryNode(final Deque<ITree<Node>> working, final Token tk) {
final ITree<Node> right = working.pop();
- final ITree<Node> left = working.pop();
+ final ITree<Node> left = working.pop();
final ITree<Node> opNode = new Tree<>(new Node(BINOP, tk.type));
@@ -156,8 +154,7 @@ public class Parser {
}
/* Parse a closing delimiter. */
- private static boolean parseClosingGrouper(final Deque<ITree<Node>> working,
- final Token tk) {
+ private static boolean parseClosingGrouper(final Deque<ITree<Node>> working, final Token tk) {
if (working.size() == 0) {
Errors.inst.printError(EK_PARSE_NOCLOSE);
return false;
diff --git a/base/src/bjc/dicelang/Shunter.java b/base/src/bjc/dicelang/Shunter.java
index 9d63b41..01029cd 100644
--- a/base/src/bjc/dicelang/Shunter.java
+++ b/base/src/bjc/dicelang/Shunter.java
@@ -34,8 +34,8 @@ public class Shunter {
Set<Token.Type> notAssoc;
/*
- * Unary operators that can only be applied to non-operator tokens and
- * yield operator tokens.
+ * Unary operators that can only be applied to non-operator tokens and yield
+ * operator tokens.
*/
Set<Token.Type> unaryAdjectives;
@@ -46,8 +46,8 @@ public class Shunter {
Set<Token.Type> unaryAdverbs;
/*
- * Unary operators that can only be applied to operator tokens and yield
- * data tokens
+ * Unary operators that can only be applied to operator tokens and yield data
+ * tokens
*/
Set<Token.Type> unaryGerunds;
@@ -56,7 +56,7 @@ public class Shunter {
/** Precedence for dice operators. */
public final int DICE_PREC = 20;
/** Precedence for string operators. */
- public final int STR_PREC = 10;
+ public final int STR_PREC = 10;
/** Precedence for expression operators. */
public final int EXPR_PREC = 0;
@@ -67,24 +67,24 @@ public class Shunter {
/* Create association maps. */
rightAssoc = new HashSet<>();
- notAssoc = new HashSet<>();
+ notAssoc = new HashSet<>();
/* Create unary maps. */
unaryAdjectives = new HashSet<>();
- unaryAdverbs = new HashSet<>();
- unaryGerunds = new HashSet<>();
+ unaryAdverbs = new HashSet<>();
+ unaryGerunds = new HashSet<>();
/* Set up unary adverbs. */
unaryAdverbs.add(COERCE);
/* Setup operators. */
/* Math operators. */
- ops.put(ADD, 0 + MATH_PREC);
+ ops.put(ADD, 0 + MATH_PREC);
ops.put(SUBTRACT, 0 + MATH_PREC);
ops.put(MULTIPLY, 1 + MATH_PREC);
- ops.put(IDIVIDE, 1 + MATH_PREC);
- ops.put(DIVIDE, 1 + MATH_PREC);
+ ops.put(IDIVIDE, 1 + MATH_PREC);
+ ops.put(DIVIDE, 1 + MATH_PREC);
/* Dice operators. */
ops.put(DICEGROUP, 0 + DICE_PREC);
@@ -108,16 +108,16 @@ public class Shunter {
* Shunt a set of tokens from infix to postfix.
*
* @param tks
- * The tokens to input.
+ * The tokens to input.
*
* @param returned
- * The postfix tokens.
+ * The postfix tokens.
*
* @return Whether or not the shunt succeeded.
*/
public boolean shuntTokens(final IList<Token> tks, final IList<Token> returned) {
/* Operator stack for normal and unary operators. */
- final Deque<Token> opStack = new LinkedList<>();
+ final Deque<Token> opStack = new LinkedList<>();
final Deque<Token> unaryOps = new LinkedList<>();
/* Currently returned lists. */
@@ -159,9 +159,8 @@ public class Shunter {
}
/* Shunt a token. */
- private boolean shuntToken(final Token tk, final Deque<Token> opStack,
- final Deque<Token> unaryStack,
- final Deque<Token> currReturned, final Deque<Token> feed) {
+ private boolean shuntToken(final Token tk, final Deque<Token> opStack, final Deque<Token> unaryStack,
+ final Deque<Token> currReturned, final Deque<Token> feed) {
/* Handle unary operators. */
if (unaryStack.size() != 0) {
if (isUnary(tk)) {
@@ -174,9 +173,8 @@ public class Shunter {
final Token.Type unaryType = unaryOp.type;
if (unaryAdjectives.contains(unaryType)) {
- /*
- * Handle unary adjectives that take a
- * non-operator.
+ /*
+ * Handle unary adjectives that take a non-operator.
*/
if (isOp(tk)) {
Errors.inst.printError(EK_SHUNT_NOTADV, unaryOp.toString(), tk.toString());
@@ -296,7 +294,7 @@ public class Shunter {
/* Check if an operator has higher precedence. */
private boolean isHigherPrec(final Token lft, final Token rght) {
- final Token.Type left = lft.type;
+ final Token.Type left = lft.type;
final Token.Type right = rght.type;
boolean exists = ops.containsKey(right);
diff --git a/base/src/bjc/dicelang/Token.java b/base/src/bjc/dicelang/Token.java
index 2841973..f1bca6c 100644
--- a/base/src/bjc/dicelang/Token.java
+++ b/base/src/bjc/dicelang/Token.java
@@ -140,10 +140,4 @@ public class Token {
return false;
}
}
-
- @Override
- public int hashCode() {
- // TODO Auto-generated method stub
- return super.hashCode();
- }
}
diff --git a/base/src/bjc/dicelang/Tokenizer.java b/base/src/bjc/dicelang/Tokenizer.java
index 3e4a490..0de8c53 100644
--- a/base/src/bjc/dicelang/Tokenizer.java
+++ b/base/src/bjc/dicelang/Tokenizer.java
@@ -30,21 +30,21 @@ public class Tokenizer {
litTokens = new FunctionalMap<>();
- litTokens.put("+", ADD);
- litTokens.put("-", SUBTRACT);
- litTokens.put("*", MULTIPLY);
- litTokens.put("/", DIVIDE);
- litTokens.put("//", IDIVIDE);
- litTokens.put("sd", DICESCALAR);
- litTokens.put("df", DICEFUDGE);
- litTokens.put("dg", DICEGROUP);
- litTokens.put("dc", DICECONCAT);
- litTokens.put("dl", DICELIST);
- litTokens.put("=>", LET);
- litTokens.put(":=", BIND);
+ litTokens.put("+", ADD);
+ litTokens.put("-", SUBTRACT);
+ litTokens.put("*", MULTIPLY);
+ litTokens.put("/", DIVIDE);
+ litTokens.put("//", IDIVIDE);
+ litTokens.put("sd", DICESCALAR);
+ litTokens.put("df", DICEFUDGE);
+ litTokens.put("dg", DICEGROUP);
+ litTokens.put("dc", DICECONCAT);
+ litTokens.put("dl", DICELIST);
+ litTokens.put("=>", LET);
+ litTokens.put(":=", BIND);
litTokens.put(".+.", STRCAT);
litTokens.put(".*.", STRREP);
- litTokens.put(",", GROUPSEP);
+ litTokens.put(",", GROUPSEP);
litTokens.put("crc", COERCE);
}
@@ -115,12 +115,9 @@ public class Tokenizer {
}
/* Patterns for matching. */
- private final Pattern hexadecimalMatcher =
- Pattern.compile("\\A[\\-\\+]?0x[0-9A-Fa-f]+\\Z");
- private final Pattern flexadecimalMatcher =
- Pattern.compile("\\A[\\-\\+]?[0-9][0-9A-Za-z]+B\\d{1,2}\\Z");
- private final Pattern stringLitMatcher =
- Pattern.compile("\\AstringLiteral(\\d+)\\Z");
+ private final Pattern hexadecimalMatcher = Pattern.compile("\\A[\\-\\+]?0x[0-9A-Fa-f]+\\Z");
+ private final Pattern flexadecimalMatcher = Pattern.compile("\\A[\\-\\+]?[0-9][0-9A-Za-z]+B\\d{1,2}\\Z");
+ private final Pattern stringLitMatcher = Pattern.compile("\\AstringLiteral(\\d+)\\Z");
/* Tokenize a literal value. */
private Token tokenizeLiteral(final String rtoken, final IMap<String, String> stringLts) {
diff --git a/base/src/bjc/dicelang/expr/Lexer.java b/base/src/bjc/dicelang/expr/Lexer.java
index dfa0f76..a8fbcaa 100644
--- a/base/src/bjc/dicelang/expr/Lexer.java
+++ b/base/src/bjc/dicelang/expr/Lexer.java
@@ -33,10 +33,10 @@ public class Lexer {
* Convert a string from a input command to a series of infix tokens.
*
* @param inp
- * The input command.
+ * The input command.
*
* @param tks
- * The token state.
+ * The token state.
*
* @return A series of infix tokens representing the command.
*/
@@ -44,14 +44,14 @@ public class Lexer {
/* Split tokens on whitespace. */
final String[] spacedTokens = inp.split("[ \t]");
/* Tokens to return. */
- final List<Token> tokens = new LinkedList<>();
+ final List<Token> tokens = new LinkedList<>();
/* Process each token. */
for (final String spacedToken : spacedTokens) {
/* Split on operators. */
final IList<String> splitTokens = split.split(spacedToken);
/* Convert strings to tokens. */
- final IList<Token> rawTokens = splitTokens.map(tok -> tks.lexToken(tok, spacedToken));
+ final IList<Token> rawTokens = splitTokens.map(tok -> tks.lexToken(tok, spacedToken));
/* Add tokens to results. */
rawTokens.forEach(tokens::add);
diff --git a/base/src/bjc/dicelang/expr/Parser.java b/base/src/bjc/dicelang/expr/Parser.java
index 5fa2d3d..3dc10ea 100644
--- a/base/src/bjc/dicelang/expr/Parser.java
+++ b/base/src/bjc/dicelang/expr/Parser.java
@@ -14,14 +14,14 @@ import bjc.utils.parserutils.TreeConstructor;
*/
public class Parser {
/*
- * @TODO 10/08/17 Ben Culkin :MainSeperation
- * This main method should be moved to its own class.
+ * @TODO 10/08/17 Ben Culkin :MainSeperation This main method should be moved to
+ * its own class.
*/
/**
* Main method.
*
* @param args
- * Unused CLI args.
+ * Unused CLI args.
*/
public static void main(final String[] args) {
/* Create our objects. */
@@ -76,12 +76,10 @@ public class Parser {
System.out.println();
/* Construct a list from the array of tokens. */
- final FunctionalList<Token> tokList = new FunctionalList<>(
- Arrays.asList(postfixTokens));
+ final FunctionalList<Token> tokList = new FunctionalList<>(Arrays.asList(postfixTokens));
/* Construct a tree from the list of postfixed tokens. */
- final ITree<Token> ast = TreeConstructor.constructTree(tokList,
- tok -> tok.typ.isOperator);
+ final ITree<Token> ast = TreeConstructor.constructTree(tokList, tok -> tok.typ.isOperator);
/* Print the tree, then the canonical expression for it. */
System.out.println("Parsed tree");
@@ -103,8 +101,8 @@ public class Parser {
}
/*
- * Convert an expression to one that uses the smallest necessary amount
- * of parens.
+ * Convert an expression to one that uses the smallest necessary amount of
+ * parens.
*/
private static String toCanonicalExpr(final ITree<Token> ast) {
final Token data = ast.getHead();
@@ -115,11 +113,11 @@ public class Parser {
}
/* The left/right children. */
- final ITree<Token> left = ast.getChild(0);
+ final ITree<Token> left = ast.getChild(0);
final ITree<Token> right = ast.getChild(1);
/* Recursively canonicalize them. */
- String leftExpr = toCanonicalExpr(left);
+ String leftExpr = toCanonicalExpr(left);
String rightExpr = toCanonicalExpr(right);
/* Add parens if the left was higher priority. */
@@ -135,7 +133,7 @@ public class Parser {
/* Add parens if the right was higher priority. */
if (right.getChildrenCount() == 0) {
int rightPriority = right.getHead().typ.operatorPriority;
- int dataPriority = data.typ.operatorPriority;
+ int dataPriority = data.typ.operatorPriority;
if (rightPriority >= dataPriority) {
rightExpr = String.format("(%s)", rightExpr);
diff --git a/base/src/bjc/dicelang/expr/Shunter.java b/base/src/bjc/dicelang/expr/Shunter.java
index 213e473..031962a 100644
--- a/base/src/bjc/dicelang/expr/Shunter.java
+++ b/base/src/bjc/dicelang/expr/Shunter.java
@@ -12,15 +12,13 @@ import java.util.List;
*/
public class Shunter {
/*
- * @NOTE
- * Why does this method return an array, and not the list of
- * tokens?
+ * @NOTE Why does this method return an array, and not the list of tokens?
*/
/**
* Convert a infix series of tokens to a postfix series of tokens.
*
* @param infixTokens
- * The tokens in infix order.
+ * The tokens in infix order.
*
* @return The tokens in postfix order.
*/
@@ -38,12 +36,9 @@ public class Shunter {
Token curOp = opStack.peek();
/*
- * Check if an operator is higher priority,
- * respecting their left associativity.
+ * Check if an operator is higher priority, respecting their left associativity.
*
- * @NOTE
- * Should this be factored out into a
- * method?
+ * @NOTE Should this be factored out into a method?
*/
int leftPriority = tok.typ.operatorPriority;
int rightPriority;
@@ -57,8 +52,7 @@ public class Shunter {
boolean isHigherPrec = leftPriority >= rightPriority;
/*
- * Pop all operators that are lower precedence
- * than us.
+ * Pop all operators that are lower precedence than us.
*/
while (!opStack.isEmpty() && isHigherPrec) {
postfixTokens.add(opStack.pop());
@@ -81,8 +75,7 @@ public class Shunter {
Token curOp = opStack.peek();
/*
- * Pop things until we find the matching
- * parenthesis.
+ * Pop things until we find the matching parenthesis.
*/
while (curOp.typ != TokenType.OPAREN) {
final Token tk = opStack.pop();
diff --git a/base/src/bjc/dicelang/expr/Token.java b/base/src/bjc/dicelang/expr/Token.java
index bf92f97..dc6247b 100644
--- a/base/src/bjc/dicelang/expr/Token.java
+++ b/base/src/bjc/dicelang/expr/Token.java
@@ -32,13 +32,13 @@ public class Token {
* Create a new token.
*
* @param type
- * The type of this token.
+ * The type of this token.
*
* @param raw
- * The string this token came from.
+ * The string this token came from.
*
* @param toks
- * The state for this token
+ * The state for this token
*/
public Token(final TokenType type, final String raw, final Tokens toks) {
this.typ = type;
@@ -50,7 +50,7 @@ public class Token {
@Override
public String toString() {
String typeStr = typ.toString();
- typeStr = String.format("%s (%s)", typeStr, typ.name());
+ typeStr = String.format("%s (%s)", typeStr, typ.name());
if (typ == TokenType.VREF) {
typeStr += " (ind. " + intValue;
diff --git a/base/src/bjc/dicelang/expr/TokenType.java b/base/src/bjc/dicelang/expr/TokenType.java
index ad01917..9462139 100644
--- a/base/src/bjc/dicelang/expr/TokenType.java
+++ b/base/src/bjc/dicelang/expr/TokenType.java
@@ -6,21 +6,20 @@ package bjc.dicelang.expr;
* @author Ben Culkin
*/
public enum TokenType {
- /*
- * @NOTE
- * Do we want to switch to auto-numbering the tokens? They were
- * manually numbered because this was an assignment for PoPL and
- * that was what Dr. Naz wanted.
+ /*
+ * @NOTE Do we want to switch to auto-numbering the tokens? They were manually
+ * numbered because this was an assignment for PoPL and that was what Dr. Naz
+ * wanted.
*/
/** Represents + */
- ADD( 14, true, 0),
+ ADD(14, true, 0),
/** Represents - */
SUBTRACT(15, true, 0),
/** Represents * */
MULTIPLY(16, true, 1),
/** Represents / */
- DIVIDE( 17, true, 1),
+ DIVIDE(17, true, 1),
/** Represents variable names. */
VREF(11),
@@ -34,14 +33,14 @@ public enum TokenType {
public final int nVal;
/** Whether or not this type of token is an operator. */
- public final boolean isOperator;
+ public final boolean isOperator;
/** The priority of this operator, if it is one. */
- public final int operatorPriority;
+ public final int operatorPriority;
/* Create a new token. */
private TokenType(final int num, final boolean isOp, final int priority) {
- nVal = num;
- isOperator = isOp;
+ nVal = num;
+ isOperator = isOp;
operatorPriority = priority;
}
diff --git a/base/src/bjc/dicelang/expr/Tokens.java b/base/src/bjc/dicelang/expr/Tokens.java
index 287d2b4..0e31ebf 100644
--- a/base/src/bjc/dicelang/expr/Tokens.java
+++ b/base/src/bjc/dicelang/expr/Tokens.java
@@ -37,11 +37,10 @@ public class Tokens {
/* Set sym ID. */
nextSym = 0;
- /*
+ /*
* Setup literal mappings.
*
- * @NOTE
- * Should this be a static member?
+ * @NOTE Should this be a static member?
*/
litTokens = new HashMap<>();
litTokens.put("+", TokenType.ADD);
@@ -56,9 +55,9 @@ public class Tokens {
* Convert the string representation of a token into a token.
*
* @param tok
- * The string representation of the token.
+ * The string representation of the token.
* @param raw
- * The original string the token came from.
+ * The original string the token came from.
*
* @return The token the string represents.
*/
diff --git a/base/src/bjc/dicelang/scl/BooleanSCLToken.java b/base/src/bjc/dicelang/scl/BooleanSCLToken.java
index 5f89ce0..e2e8e12 100644
--- a/base/src/bjc/dicelang/scl/BooleanSCLToken.java
+++ b/base/src/bjc/dicelang/scl/BooleanSCLToken.java
@@ -3,10 +3,10 @@ package bjc.dicelang.scl;
public class BooleanSCLToken extends SCLToken {
/* Used for BLIT */
public boolean boolVal;
-
+
public BooleanSCLToken(boolean val) {
super(Type.BLIT);
-
+
boolVal = val;
}
diff --git a/base/src/bjc/dicelang/scl/FloatSCLToken.java b/base/src/bjc/dicelang/scl/FloatSCLToken.java
index 46db4c5..f02c796 100644
--- a/base/src/bjc/dicelang/scl/FloatSCLToken.java
+++ b/base/src/bjc/dicelang/scl/FloatSCLToken.java
@@ -3,10 +3,10 @@ package bjc.dicelang.scl;
public class FloatSCLToken extends SCLToken {
/* Used for FLIT */
public double floatVal;
-
+
public FloatSCLToken(double val) {
super(Type.FLIT);
-
+
floatVal = val;
}
diff --git a/base/src/bjc/dicelang/scl/IntSCLToken.java b/base/src/bjc/dicelang/scl/IntSCLToken.java
index b90aa83..9e88dbe 100644
--- a/base/src/bjc/dicelang/scl/IntSCLToken.java
+++ b/base/src/bjc/dicelang/scl/IntSCLToken.java
@@ -12,7 +12,7 @@ public class IntSCLToken extends SCLToken {
/* Create a new token. */
public IntSCLToken(final long iVal) {
super(Type.ILIT);
-
+
intVal = iVal;
}
} \ No newline at end of file
diff --git a/base/src/bjc/dicelang/scl/StreamControlConsole.java b/base/src/bjc/dicelang/scl/StreamControlConsole.java
index 78b1d49..ca61244 100644
--- a/base/src/bjc/dicelang/scl/StreamControlConsole.java
+++ b/base/src/bjc/dicelang/scl/StreamControlConsole.java
@@ -12,26 +12,25 @@ import java.util.Scanner;
*/
public class StreamControlConsole {
/*
- * @TODO 10/08/17 :SCLArgs
- * Do something useful with the CLI args.
+ * @TODO 10/08/17 :SCLArgs Do something useful with the CLI args.
*
*/
/**
* Main method
*
* @param args
- * Unused CLI args.
+ * Unused CLI args.
*/
public static void main(String[] args) {
/*
* Initialize vars.
- *
- * We can get away with passing the null, because StreamEngine
- * doesn't reference any parts of DiceLangEngine.
+ *
+ * We can get away with passing the null, because StreamEngine doesn't reference
+ * any parts of DiceLangEngine.
*/
- StreamEngine sengine = new StreamEngine(null);
+ StreamEngine sengine = new StreamEngine(null);
StreamControlEngine sclengine = new StreamControlEngine(sengine);
- Scanner scn = new Scanner(System.in);
+ Scanner scn = new Scanner(System.in);
/* Get input from the user. */
System.out.print("Enter a SCL command string (blank to exit): ");
@@ -47,7 +46,7 @@ public class StreamControlConsole {
/* Break the token into strings. */
IList<String> res = new FunctionalList<>();
- String[] tokens = ln.split(" ");
+ String[] tokens = ln.split(" ");
/* Run the stream engine on the tokens. */
boolean succ = sengine.doStreams(tokens, res);
@@ -58,7 +57,7 @@ public class StreamControlConsole {
/* Run the command through SCL. */
tokens = res.toArray(new String[res.getSize()]);
- succ = sclengine.runProgram(tokens);
+ succ = sclengine.runProgram(tokens);
if (!succ) {
System.out.printf("ERROR: SCL engine failed for line '%s'\n", ln);
continue;
diff --git a/base/src/bjc/dicelang/scl/StreamEngine.java b/base/src/bjc/dicelang/scl/StreamEngine.java
index 2e0a6d7..2d931b9 100644
--- a/base/src/bjc/dicelang/scl/StreamEngine.java
+++ b/base/src/bjc/dicelang/scl/StreamEngine.java
@@ -30,8 +30,8 @@ public class StreamEngine {
DiceLangEngine eng;
/* Our streams. */
- Tape<IList<String>> streams;
- IList<String> currStream;
+ Tape<IList<String>> streams;
+ IList<String> currStream;
/* Saved streams */
TapeLibrary<IList<String>> savedStreams;
@@ -43,7 +43,7 @@ public class StreamEngine {
* Create a new stream engine.
*
* @param engine
- * The dice engine we're attached to.
+ * The dice engine we're attached to.
*/
public StreamEngine(final DiceLangEngine engine) {
eng = engine;
@@ -66,10 +66,10 @@ public class StreamEngine {
* Process a possibly interleaved set of streams.
*
* @param toks
- * The raw token to read streams from.
+ * The raw token to read streams from.
*
* @param dest
- * The list to write the final stream to.
+ * The list to write the final stream to.
*
* @return Whether or not the streams were successfully processed.
*/
@@ -81,10 +81,10 @@ public class StreamEngine {
* Process a possibly interleaved set of streams.
*
* @param toks
- * The raw token to read streams from.
+ * The raw token to read streams from.
*
* @param dest
- * The list to write the final stream to.
+ * The list to write the final stream to.
*
* @return Whether or not the streams were successfully processed.
*/
@@ -212,9 +212,8 @@ public class StreamEngine {
/* Process each command. */
/*
- * @TODO 10/09/17 Ben Culkin :StreamCommands
- * This should probably be refactored in some way, so as to
- * make it easier to add new commands.
+ * @TODO 10/09/17 Ben Culkin :StreamCommands This should probably be refactored
+ * in some way, so as to make it easier to add new commands.
*/
for (final char comm : comms) {
switch (comm) {
diff --git a/base/src/bjc/dicelang/scl/StringSCLToken.java b/base/src/bjc/dicelang/scl/StringSCLToken.java
index f594c4c..1436bc3 100644
--- a/base/src/bjc/dicelang/scl/StringSCLToken.java
+++ b/base/src/bjc/dicelang/scl/StringSCLToken.java
@@ -3,14 +3,14 @@ package bjc.dicelang.scl;
public class StringSCLToken extends SCLToken {
/* Used for SYMBOL & SLIT */
public String stringVal;
-
+
protected StringSCLToken(boolean isSymbol, String val) {
- if(isSymbol) {
+ if (isSymbol) {
type = Type.SYMBOL;
} else {
type = Type.SLIT;
}
-
+
stringVal = val;
}
diff --git a/base/src/bjc/dicelang/scl/WordListSCLToken.java b/base/src/bjc/dicelang/scl/WordListSCLToken.java
index d13f7ab..ffa0e85 100644
--- a/base/src/bjc/dicelang/scl/WordListSCLToken.java
+++ b/base/src/bjc/dicelang/scl/WordListSCLToken.java
@@ -7,12 +7,12 @@ public class WordListSCLToken extends SCLToken {
public IList<SCLToken> tokenVals;
protected WordListSCLToken(boolean isArray, IList<SCLToken> tokens) {
- if(isArray) {
+ if (isArray) {
type = Type.ARRAY;
} else {
type = Type.WORDS;
}
-
+
tokenVals = tokens;
}
diff --git a/base/src/bjc/dicelang/scl/WordSCLToken.java b/base/src/bjc/dicelang/scl/WordSCLToken.java
index 3fe78b3..ea3118e 100644
--- a/base/src/bjc/dicelang/scl/WordSCLToken.java
+++ b/base/src/bjc/dicelang/scl/WordSCLToken.java
@@ -16,14 +16,14 @@ public class WordSCLToken extends SCLToken {
}
public Word wordVal;
-
+
public WordSCLToken(String wrd) {
this(builtinWords.get(wrd));
}
-
+
public WordSCLToken(Word wrd) {
super(Type.WORD);
-
+
wordVal = wrd;
}
@@ -57,9 +57,9 @@ public class WordSCLToken extends SCLToken {
public static boolean isBuiltinWord(String wrd) {
return builtinWords.containsKey(wrd);
}
-
+
private static final Map<String, WordSCLToken.Word> builtinWords;
-
+
static {
/* Init builtin words. */
builtinWords = new HashMap<>();
diff --git a/base/src/bjc/dicelang/util/ResourceLoader.java b/base/src/bjc/dicelang/util/ResourceLoader.java
index db5c6fc..085081f 100644
--- a/base/src/bjc/dicelang/util/ResourceLoader.java
+++ b/base/src/bjc/dicelang/util/ResourceLoader.java
@@ -22,10 +22,9 @@ public class ResourceLoader {
* Loads a .help file from the data/help directory.
*
* @param name
- * The name of the help file to load.
+ * The name of the help file to load.
*
- * @return The contents of the help file, or null if it could not be
- * opened.
+ * @return The contents of the help file, or null if it could not be opened.
*/
public static String[] loadHelpFile(final String name) {
final URL fle = ResourceLoader.class.getResource("/data/help/" + name + ".help");