summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/scl
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-08 16:38:35 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-08 16:38:35 -0300
commit054643900e7b857cafe123b0b4c03f10a95520ed (patch)
treec289fc397fe79ea0a6792e3f2f39a05ed1315936 /dice-lang/src/bjc/dicelang/scl
parentf40e5a873420d70d01ff7e01b77bdbd64faab00e (diff)
Update
Diffstat (limited to 'dice-lang/src/bjc/dicelang/scl')
-rw-r--r--dice-lang/src/bjc/dicelang/scl/StreamControlConsole.java20
-rw-r--r--dice-lang/src/bjc/dicelang/scl/StreamEngine.java62
2 files changed, 34 insertions, 48 deletions
diff --git a/dice-lang/src/bjc/dicelang/scl/StreamControlConsole.java b/dice-lang/src/bjc/dicelang/scl/StreamControlConsole.java
index 71dacaa..4dc9b82 100644
--- a/dice-lang/src/bjc/dicelang/scl/StreamControlConsole.java
+++ b/dice-lang/src/bjc/dicelang/scl/StreamControlConsole.java
@@ -10,34 +10,32 @@ import java.util.function.Supplier;
public class StreamControlConsole {
public static void main(String[] args) {
- /*
- * We're not using the DiceLangEngine in the streams yet.
- */
+ /* Initialize vars. */
+ /* We're not using the DiceLangEngine in the streams yet. */
StreamEngine sengine = new StreamEngine(null);
-
StreamControlEngine sclengine = new StreamControlEngine(sengine);
-
Scanner scn = new Scanner(System.in);
+ /* Get input from the user. */
System.out.print("Enter a SCL command string (blank to exit): ");
-
while(scn.hasNextLine()) {
String ln = scn.nextLine();
-
if(ln.trim().equals("")) break;
+ /* 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);
if(!succ) continue;
+ /* Run the command through SCL. */
tokens = res.toArray(new String[res.getSize()]);
-
- succ = sclengine.runProgram(tokens);
+ succ = sclengine.runProgram(tokens);
if(!succ) continue;
+ /* Prompt again. */
System.out.print("Command string executed succesfully.\n\n");
System.out.print("Enter a SCL command string (blank to exit): ");
}
diff --git a/dice-lang/src/bjc/dicelang/scl/StreamEngine.java b/dice-lang/src/bjc/dicelang/scl/StreamEngine.java
index 5094283..191ab41 100644
--- a/dice-lang/src/bjc/dicelang/scl/StreamEngine.java
+++ b/dice-lang/src/bjc/dicelang/scl/StreamEngine.java
@@ -27,30 +27,20 @@ import java.util.Arrays;
* @author Ben Culkin
*/
public class StreamEngine {
- /*
- * Whether or not we're doing debugging.
- */
+ /* Whether or not we're doing debugging. */
public final boolean debug = true;
- /*
- * The engine we're attached to.
- */
+ /* The engine we're attached to. */
DiceLangEngine eng;
- /*
- * Our streams.
- */
+ /* Our streams. */
Tape<IList<String>> streams;
IList<String> currStream;
- /*
- * Saved streams
- */
+ /* Saved streams */
TapeLibrary<IList<String>> savedStreams;
- /*
- * Handler for SCL programs
- */
+ /* Handler for SCL programs */
private final StreamControlEngine scleng;
/**
@@ -66,15 +56,12 @@ public class StreamEngine {
scleng = new StreamControlEngine(this);
}
+ /* Do pre-run (re)initialization. */
private void init() {
- /*
- * Reinitialize our list of streams.
- */
+ /* Reinitialize our list of streams. */
streams = new SingleTape<>();
- /*
- * Create an initial stream.
- */
+ /* Create an initial stream. */
currStream = new FunctionalList<>();
streams.insertBefore(currStream);
}
@@ -94,28 +81,29 @@ public class StreamEngine {
return doStreams(Arrays.asList(toks), dest);
}
+ /**
+ * Process a possibly interleaved set of streams.
+ *
+ * @param toks
+ * The raw token to read streams from.
+ *
+ * @param dest
+ * The list to write the final stream to.
+ *
+ * @return Whether or not the streams were successfully processed.
+ */
public boolean doStreams(final Iterable<String> toks, final IList<String> dest) {
- /*
- * Initialize per-run state.
- */
+ /* Initialize per-run state. */
init();
- /*
- * Are we currently quoting things?
- */
+ /* Are we currently quoting things? */
boolean quoteMode = false;
-
- /*
- * Process each token.
- */
+ /* Process each token. */
for (final String tk : toks) {
- /*
- * Process stream commands.
- */
+ /* Process stream commands. */
if (tk.startsWith("{@S") && !quoteMode) {
- if (tk.equals("{@SQ}")) {
- quoteMode = true;
- } else if (!processCommand(tk)) return false;
+ if (tk.equals("{@SQ}")) quoteMode = true;
+ else if (!processCommand(tk)) return false;
} else {
if (tk.equals("{@SU}")) {
quoteMode = false;