summaryrefslogtreecommitdiff
path: root/JPratt/src/examples/java/bjc
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2023-06-25 15:53:08 -0400
committerBen Culkin <scorpress@gmail.com>2023-06-25 15:53:08 -0400
commitc3a5210cbcda9b5a80f37c31698e35ca6fb5a2d8 (patch)
treef574647ba5a1c09eae588ef3c956862be5fbc8e2 /JPratt/src/examples/java/bjc
parent02af075e89fbdeb22575f235a3acb2607e0b4edf (diff)
Minor cleanups
Diffstat (limited to 'JPratt/src/examples/java/bjc')
-rw-r--r--JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java54
1 files changed, 26 insertions, 28 deletions
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 ac5aa12..a85b664 100644
--- a/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java
+++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java
@@ -127,45 +127,43 @@ public class PrattParserTest {
final TestContext ctx = new TestContext();
- final Scanner scn = new Scanner(System.in);
+ try (Scanner scn = new Scanner(System.in)) {
+ System.out.print("Enter a command (blank line to exit): ");
+ String ln = scn.nextLine();
- 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, reserved, filtered, ln, ctx);
- while (!ln.trim().equals("")) {
- final Iterator<Token<String, String>> tokens = preprocessInput(ops, reserved, filtered, ln, ctx);
+ try {
+ final StringTokenStream tokenStream = new StringTokenStream(tokens);
- try {
- final StringTokenStream tokenStream = new StringTokenStream(tokens);
+ /*
+ * Prime stream.
+ */
+ tokenStream.next();
- /*
- * Prime stream.
- */
- tokenStream.next();
+ final CommandResult<String, String> rawTree = parser.parseExpression(0, tokenStream, ctx, true);
- final CommandResult<String, String> rawTree = parser.parseExpression(0, tokenStream, ctx, true);
+ if (rawTree.status != Status.SUCCESS) {
+ System.out.println("Command parsing failed.");
+ } else {
+ if (!tokenStream.headIs("(end)")) {
+ System.out.println("\nMultiple expressions on line");
+ }
- if (rawTree.status != Status.SUCCESS) {
- System.out.println("Command parsing failed.");
- } else {
- if (!tokenStream.headIs("(end)")) {
- System.out.println("\nMultiple expressions on line");
+ System.out.printf("\nParsed expression:\n%s", rawTree.success());
}
-
- System.out.printf("\nParsed expression:\n%s", rawTree.success());
+ } catch (ParserException pex) {
+ pex.printStackTrace();
}
- } catch (ParserException pex) {
- pex.printStackTrace();
+
+ System.out.print("\nEnter a command (blank line to exit): ");
+ ln = scn.nextLine();
}
- System.out.print("\nEnter a command (blank line to exit): ");
- ln = scn.nextLine();
+ System.out.println();
+ System.out.printf("\nContext is: %s\n", ctx);
}
-
- System.out.println();
- System.out.printf("\nContext is: %s\n", ctx);
-
- scn.close();
}
private static Iterator<Token<String, String>> preprocessInput(final Set<String> oops, final Set<String> reservd,