From d6f576102ef0accce5b79efa2ce714fe82c470ad Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 2 Feb 2020 22:06:28 +0100 Subject: [PATCH] java: examples: fix the tracking of locations * examples/java/calc/Calc.y: The StreamTokenizer cannot "peek" for the next character, it reads it, and keeps it for the next call. So the current location is one passed the end of the current token. To avoid this, keep the previous position, and use it to end the current token. * examples/java/calc/Calc.test: Adjust. --- examples/java/calc/Calc.test | 7 ++++++- examples/java/calc/Calc.y | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/examples/java/calc/Calc.test b/examples/java/calc/Calc.test index b0d238f1..8664e314 100644 --- a/examples/java/calc/Calc.test +++ b/examples/java/calc/Calc.test @@ -30,4 +30,9 @@ run 0 '7 cat >input <input < -1) { char c = (char)res; @@ -206,4 +211,8 @@ class PositionReader extends BufferedReader { public Position getPosition () { return position; } + + public Position getPreviousPosition () { + return previousPosition; + } }