From 7ac470c22e9e179daf0a10579a9f9e347cf6f94f Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Mon, 28 May 2018 13:42:11 -0300 Subject: Move SCL into new project SCL is now independant of dicelang, and thus deserving of its own repo. --- .../bjc/dicelang/scl/StreamControlConsole.java | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/main/java/bjc/dicelang/scl/StreamControlConsole.java (limited to 'src/main/java/bjc/dicelang/scl/StreamControlConsole.java') diff --git a/src/main/java/bjc/dicelang/scl/StreamControlConsole.java b/src/main/java/bjc/dicelang/scl/StreamControlConsole.java new file mode 100644 index 0000000..78c8c5e --- /dev/null +++ b/src/main/java/bjc/dicelang/scl/StreamControlConsole.java @@ -0,0 +1,73 @@ +package bjc.dicelang.scl; + +import bjc.utils.funcdata.FunctionalList; +import bjc.utils.funcdata.IList; + +import java.util.Scanner; + +/** + * Implement a SCL REPL + * + * @author Ben Culkin + */ +public class StreamControlConsole { + /* + * @TODO 10/08/17 :SCLArgs + * + * Do something useful with the CLI args. + * + */ + /** + * Main method + * + * @param args + * Unused CLI args. + */ + public static void main(String[] args) { + /* + * Initialize vars. + * + */ + StreamEngine sengine = new StreamEngine(); + 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): "); + + /* Process it. */ + while(scn.hasNextLine()) { + String ln = scn.nextLine().trim(); + + if(ln.equals("")) { + /* Ignore empty lines. */ + break; + } + + /* Break the token into strings. */ + IList res = new FunctionalList<>(); + String[] tokens = ln.split(" "); + + /* Run the stream engine on the tokens. */ + boolean succ = sengine.doStreams(tokens, res); + if(!succ) { + System.out.printf("ERROR: Stream engine failed for line '%s'\n", ln); + continue; + } + + /* Run the command through SCL. */ + tokens = res.toArray(new String[res.getSize()]); + succ = sclengine.runProgram(tokens); + if(!succ) { + System.out.printf("ERROR: SCL engine failed for line '%s'\n", ln); + continue; + } + + /* Prompt again. */ + System.out.print("Command string executed succesfully.\n\n"); + System.out.print("Enter a SCL command string (blank to exit): "); + } + + scn.close(); + } +} -- cgit v1.2.3