From 4d69e8b9aaebc253f3ed0864734b8c1db9a1eedd Mon Sep 17 00:00:00 2001 From: bjculkin Date: Mon, 10 Apr 2017 10:44:53 -0400 Subject: Minor changes --- .../java/bjc/pratt/examples/AssignCommand.java | 2 +- .../java/bjc/pratt/examples/BlockEnter.java | 9 ++++--- .../java/bjc/pratt/examples/PrattParserTest.java | 30 ++++++++++++++-------- .../java/bjc/pratt/examples/Tokenizer.java | 3 +++ 4 files changed, 30 insertions(+), 14 deletions(-) (limited to 'JPratt/src/examples/java/bjc') diff --git a/JPratt/src/examples/java/bjc/pratt/examples/AssignCommand.java b/JPratt/src/examples/java/bjc/pratt/examples/AssignCommand.java index eb99350..45aac1a 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/AssignCommand.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/AssignCommand.java @@ -18,7 +18,7 @@ class AssignCommand extends NonBinaryCommand { ParserContext ctx) throws ParserException { Token name = operand.getHead(); - switch(name.getKey()) { + switch (name.getKey()) { case "(literal)": case "(vref)": break; diff --git a/JPratt/src/examples/java/bjc/pratt/examples/BlockEnter.java b/JPratt/src/examples/java/bjc/pratt/examples/BlockEnter.java index 71d4e72..67e560c 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/BlockEnter.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/BlockEnter.java @@ -3,6 +3,7 @@ package bjc.pratt.examples; import bjc.pratt.Token; import bjc.utils.data.ITree; import bjc.utils.esodata.Directory; +import bjc.utils.esodata.Stack; import java.util.function.UnaryOperator; @@ -10,12 +11,14 @@ final class BlockEnter implements UnaryOperator { @Override public TestContext apply(TestContext state) { Directory>> enclosing = state.scopes.top(); - int currBlockNumber = state.blockCount.pop(); + Stack blockCount = state.blockCount; + + int currBlockNumber = blockCount.pop(); state.scopes.push(enclosing.newSubdirectory("block" + currBlockNumber)); - state.blockCount.push(currBlockNumber + 1); - state.blockCount.push(0); + blockCount.push(currBlockNumber + 1); + blockCount.push(0); return state; } diff --git a/JPratt/src/examples/java/bjc/pratt/examples/PrattParserTest.java b/JPratt/src/examples/java/bjc/pratt/examples/PrattParserTest.java index ebf0cc8..b7d31eb 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/PrattParserTest.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/PrattParserTest.java @@ -95,7 +95,7 @@ public class PrattParserTest { lo.addMultiDelimiters("(", ")"); lo.addMultiDelimiters("[", "]"); lo.addMultiDelimiters("{", "}"); - + hi.compile(); lo.compile(); @@ -205,7 +205,8 @@ public class PrattParserTest { parser.addNonInitialCommand(":", infixNon(3)); - parser.addNonInitialCommand("if", ternary(5, 0, "else", litToken("cond"), false)); + NonInitialCommand ifElse = ternary(5, 0, "else", litToken("cond"), false); + parser.addNonInitialCommand("if", ifElse); parser.addNonInitialCommand(":=", new AssignCommand(10)); @@ -246,18 +247,27 @@ public class PrattParserTest { parser.addNonInitialCommand(".", infixLeft(60)); - parser.addNonInitialCommand("[", postCircumfix(60, 0, "]", litToken("idx"))); + NonInitialCommand arrayIdx = postCircumfix(60, 0, "]", litToken("idx")); + parser.addNonInitialCommand("[", arrayIdx); - parser.addInitialCommand("if", preTernary(0, 0, 0, "then", "else", litToken("ifelse"))); + InitialCommand ifThenElse = preTernary(0, 0, 0, "then", "else", + litToken("ifelse")); + parser.addInitialCommand("if", ifThenElse); - parser.addInitialCommand("(", grouping(0, ")", litToken("parens"))); + InitialCommand parens = grouping(0, ")", litToken("parens")); + parser.addInitialCommand("(", parens); - parser.addInitialCommand("begin", delimited(0, ";", "end", litToken("block"), new BlockEnter(), idfun, - new BlockExit(), true)); + InitialCommand scoper = delimited(0, ";", "end", litToken("block"), + new BlockEnter(), idfun, new BlockExit(), true); + parser.addInitialCommand("begin", scoper); - parser.addInitialCommand("[", delimited(0, ",", "]", litToken("array"), idfun, idfun, idfun, false)); + InitialCommand arrayLiteral = delimited(0, ",", "]", litToken("array"), + idfun, idfun, idfun, false); + parser.addInitialCommand("[", arrayLiteral); - parser.addInitialCommand("{", delimited(0, ",", "}", litToken("json"), idfun, idfun, idfun, false)); + InitialCommand jsonLiteral = delimited(0, ",", "}", litToken("json"), + idfun, idfun, idfun, false); + parser.addInitialCommand("{", jsonLiteral); parser.addInitialCommand("case", unary(5)); @@ -277,4 +287,4 @@ public class PrattParserTest { return parser; } -} +} \ No newline at end of file diff --git a/JPratt/src/examples/java/bjc/pratt/examples/Tokenizer.java b/JPratt/src/examples/java/bjc/pratt/examples/Tokenizer.java index f6ecf98..0fccc60 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/Tokenizer.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/Tokenizer.java @@ -26,6 +26,9 @@ final class Tokenizer implements Function> { } else if (ctx.scopes.top().containsKey(strang)) { return new StringToken("(vref)", strang); } else if(strang.matches("(?:[\\u00B2\\u00B3\\u00B9\\u2070]|[\\u2074-\\u2079])+")) { + /* + * This regular expression matches series of unicode super-scripts 1-9. + */ return new StringToken("(superexp)", strang); } else { return new StringToken("(literal)", strang); -- cgit v1.2.3