aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorRoman / Linnea Gräf <roman.graef@gmail.com>2023-07-06 12:41:33 +0200
committerGitHub <noreply@github.com>2023-07-06 12:41:33 +0200
commit0c94c8cf85824c2a8798a4c72d345738b1583388 (patch)
treefcf278acc366f05b3355fe786cb0d8dde9fcce8f /src/main/java
parentb3b43eed2fe6677741ee52065016f319b6c9d723 (diff)
downloadNotEnoughUpdates-0c94c8cf85824c2a8798a4c72d345738b1583388.tar.gz
NotEnoughUpdates-0c94c8cf85824c2a8798a4c72d345738b1583388.tar.bz2
NotEnoughUpdates-0c94c8cf85824c2a8798a4c72d345738b1583388.zip
Fix calculator preop operations (#758)
Fix calculator postop operations
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java
index 0762d107..2b741e94 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java
@@ -98,7 +98,7 @@ public class Calculator {
public static List<Token> lex(String source) throws CalculatorException {
List<Token> tokens = new ArrayList<>();
- boolean justParsedNumber = false;
+ boolean doesNotHaveLValue = true;
for (int i = 0; i < source.length(); ) {
char c = source.charAt(i);
if (Character.isWhitespace(c)) {
@@ -107,7 +107,7 @@ public class Calculator {
}
Token token = new Token();
token.tokenStart = i;
- if (!justParsedNumber && c == '-') {
+ if (doesNotHaveLValue && c == '-') {
token.tokenLength = 1;
token.type = TokenType.PREOP;
token.operatorValue = "-";
@@ -175,7 +175,8 @@ public class Calculator {
} else {
throw new CalculatorException("Unknown thing " + c, i, 1);
}
- justParsedNumber = token.type == TokenType.NUMBER || token.type == TokenType.VARIABLE;
+ doesNotHaveLValue =
+ token.type == TokenType.LPAREN || token.type == TokenType.PREOP || token.type == TokenType.BINOP;
tokens.add(token);
i += token.tokenLength;
}
@@ -218,7 +219,7 @@ public class Calculator {
Token l = op.peek();
if (l.type == TokenType.LPAREN)
break;
- assert (l.type == TokenType.BINOP);
+ assert (l.type == TokenType.BINOP || l.type == TokenType.PREOP);
int pl = getPrecedence(l);
if (pl >= p) { // Association order
out.add(op.pop());