diff options
| author | EVE <EVE@EVE-PC> | 2017-03-13 16:41:45 -0400 |
|---|---|---|
| committer | EVE <EVE@EVE-PC> | 2017-03-13 16:41:45 -0400 |
| commit | 01136c6796e21f023713e026674576d8e623462d (patch) | |
| tree | e77886fe0e0adaf3c0430fba9ce248ef83f74fe4 /dice-lang/src/bjc/dicelang/v1/examples/DiceASTLanguageTest.java | |
| parent | 870d769cfc152171d27b2331a7c590d0b307ad48 (diff) | |
Formatting
Diffstat (limited to 'dice-lang/src/bjc/dicelang/v1/examples/DiceASTLanguageTest.java')
| -rw-r--r-- | dice-lang/src/bjc/dicelang/v1/examples/DiceASTLanguageTest.java | 93 |
1 files changed, 34 insertions, 59 deletions
diff --git a/dice-lang/src/bjc/dicelang/v1/examples/DiceASTLanguageTest.java b/dice-lang/src/bjc/dicelang/v1/examples/DiceASTLanguageTest.java index 117bc98..f20e276 100644 --- a/dice-lang/src/bjc/dicelang/v1/examples/DiceASTLanguageTest.java +++ b/dice-lang/src/bjc/dicelang/v1/examples/DiceASTLanguageTest.java @@ -25,9 +25,9 @@ import bjc.utils.funcdata.IMap; * */ public class DiceASTLanguageTest { - private static IMap<String, DiceASTPragma> actions; + private static IMap<String, DiceASTPragma> actions; - private static DiceASTOptimizer optimizer; + private static DiceASTOptimizer optimizer; // Set up things that need to be configured static { @@ -42,7 +42,7 @@ public class DiceASTLanguageTest { System.out.println(varName + " is bound to " + varValue); }); }); - + // Create and configure the optimizer optimizer = new DiceASTOptimizer(); @@ -50,8 +50,7 @@ public class DiceASTLanguageTest { } // Read in a command - private static String getNextCommand(Scanner inputSource, - int commandNumber) { + private static String getNextCommand(Scanner inputSource, int commandNumber) { // Print a prompt using the current command number System.out.print("\ndice-lang-" + commandNumber + "> "); @@ -59,8 +58,7 @@ public class DiceASTLanguageTest { return inputSource.nextLine(); } - private static void handleInlineAction( - FunctionalStringTokenizer tokenizer, + private static void handleInlineAction(FunctionalStringTokenizer tokenizer, IMap<String, ITree<IDiceASTNode>> enviroment) { // Skip the pragma name tokenizer.nextToken(); @@ -70,11 +68,10 @@ public class DiceASTLanguageTest { if (pragmaArgs.getSize() < 3) { // Complain about pragma arguments not being valid - System.err.println( - "ERROR: Inline requires at least 3 parameters. They are:" - + "\n\t1. The name of the expression to inline." - + "\n\t2. The name of the variable to bind the result to." - + "\n\t3 and onwards. Names of variables to inline in the expression."); + System.err.println("ERROR: Inline requires at least 3 parameters. They are:" + + "\n\t1. The name of the expression to inline." + + "\n\t2. The name of the variable to bind the result to." + + "\n\t3 and onwards. Names of variables to inline in the expression."); } else { // Get arguments String inlineExpression = pragmaArgs.getByIndex(0); @@ -84,9 +81,8 @@ public class DiceASTLanguageTest { IList<String> inlinedVariables = pragmaArgs.tail().tail(); // Actually inline the variable - ITree<IDiceASTNode> inlinedExpression = DiceASTInliner - .selectiveInline(enviroment.get(inlineExpression), - enviroment, inlinedVariables); + ITree<IDiceASTNode> inlinedExpression = DiceASTInliner.selectiveInline( + enviroment.get(inlineExpression), enviroment, inlinedVariables); // Stick the inlined variable into the enviroment enviroment.put(variableName, inlinedExpression); @@ -97,7 +93,7 @@ public class DiceASTLanguageTest { * Main method of class * * @param args - * Unused CLI args + * Unused CLI args */ public static void main(String[] args) { // Prepare the things we need for input @@ -118,12 +114,10 @@ public class DiceASTLanguageTest { // Check and see if we're executing an action if (actions.containsKey(possibleActionName)) { // Execute action - FunctionalStringTokenizer tokenizer = new FunctionalStringTokenizer( - currentLine); + FunctionalStringTokenizer tokenizer = new FunctionalStringTokenizer(currentLine); // Execute the action - actions.get(possibleActionName).accept(tokenizer, - enviroment); + actions.get(possibleActionName).accept(tokenizer, enviroment); // Get the next command currentLine = getNextCommand(inputSource, commandNumber); @@ -138,11 +132,9 @@ public class DiceASTLanguageTest { long time = System.nanoTime(); // Prepare the command - IList<String> preparedTokens = DiceExpressionPreparer - .prepareCommand(currentLine); + IList<String> preparedTokens = DiceExpressionPreparer.prepareCommand(currentLine); - System.out.println("Command prepared in " - + (double) (System.nanoTime() - time) / 1000000000 + System.out.println("Command prepared in " + (double) (System.nanoTime() - time) / 1000000000 + " s"); try { @@ -152,14 +144,9 @@ public class DiceASTLanguageTest { // Create the AST builtAST = DiceASTParser.createFromString(preparedTokens); - System.out - .println( - "Command parsed in " - + (double) (System.nanoTime() - - time) / 1000000000 - + " s"); - } catch (InputMismatchException | IllegalStateException - | UnsupportedOperationException ex) { + System.out.println("Command parsed in " + + (double) (System.nanoTime() - time) / 1000000000 + " s"); + } catch (InputMismatchException | IllegalStateException | UnsupportedOperationException ex) { // Tell the user there was an error in parsing System.out.println("PARSING ERROR: " + ex.getLocalizedMessage()); @@ -176,40 +163,33 @@ public class DiceASTLanguageTest { time = System.nanoTime(); // Transform the AST - ITree<IDiceASTNode> transformedAST = transformAST(builtAST, - enviroment); + ITree<IDiceASTNode> transformedAST = transformAST(builtAST, enviroment); - System.out.println("Command transformed in " - + (double) (System.nanoTime() - time) / 1000000000 + System.out.println("Command transformed in " + (double) (System.nanoTime() - time) / 1000000000 + " s"); // Print out the transformed AST - System.out - .println("\tTransformed: " + transformedAST.toString()); - + System.out.println("\tTransformed: " + transformedAST.toString()); try { // Time the evaluation time = System.nanoTime(); // Evaluate the expression once - IResult sampleResult = DiceASTEvaluator.evaluateAST(transformedAST, - enviroment); + IResult sampleResult = DiceASTEvaluator.evaluateAST(transformedAST, enviroment); - System.out - .println( - "Command evaluated in " - + (double) (System.nanoTime() - - time) / 1000000000 - + " s"); + System.out.println("Command evaluated in " + + (double) (System.nanoTime() - time) / 1000000000 + " s"); - // Print out the result of evaluating the expression + // Print out the result of evaluating the + // expression System.out.println("\t\tSample Result: " + sampleResult); - + // Update the 'last' meta-variable enviroment.put("last", transformedAST); } catch (UnsupportedOperationException usex) { - // Tell the user there was an error in evaluation + // Tell the user there was an error in + // evaluation System.out.println("EVALUATION ERROR: " + usex.getLocalizedMessage()); // Get the next command @@ -219,7 +199,6 @@ public class DiceASTLanguageTest { continue; } - // Increase the number of commands commandNumber++; @@ -234,20 +213,16 @@ public class DiceASTLanguageTest { } // Transform a parsed AST - private static ITree<IDiceASTNode> transformAST( - ITree<IDiceASTNode> builtAST, + private static ITree<IDiceASTNode> transformAST(ITree<IDiceASTNode> builtAST, IMap<String, ITree<IDiceASTNode>> enviroment) { // Optimize the tree first - ITree<IDiceASTNode> optimizedTree = optimizer - .optimizeTree(builtAST, enviroment); + ITree<IDiceASTNode> optimizedTree = optimizer.optimizeTree(builtAST, enviroment); // Then, condense unnecessary operations - ITree<IDiceASTNode> condensedTree = OperationCondenser - .condense(optimizedTree); + ITree<IDiceASTNode> condensedTree = OperationCondenser.condense(optimizedTree); // Next, sanitize references - ITree<IDiceASTNode> sanitizedTree = DiceASTReferenceSanitizer - .sanitize(condensedTree, enviroment); + ITree<IDiceASTNode> sanitizedTree = DiceASTReferenceSanitizer.sanitize(condensedTree, enviroment); // Re-optimize the sanitized & condensed tree optimizedTree = optimizer.optimizeTree(sanitizedTree, enviroment); |
