diff options
-rw-r--r-- | shunting.py | 49 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java | 1 |
2 files changed, 0 insertions, 50 deletions
diff --git a/shunting.py b/shunting.py deleted file mode 100644 index 22d79f11..00000000 --- a/shunting.py +++ /dev/null @@ -1,49 +0,0 @@ -precedence = { - '-': 0, - '+': 0, - '*': 1, - '/': 1, -} - - -def shunting(inss: [str]): - op = [] - out = [] - for ins in inss: - if str.isnumeric(ins): - list.append(out, ins) - elif len(ins) == 1 and ins in "+-*/": - p = precedence[ins] - while op: - l = op[len(op) - 1] - if l == "(": - break - pl = precedence[l] - if pl > p: - out.append(op.pop()) - else: - break - op.append(ins) - elif len(ins) == 1 and ins in "mkbt": - out.append(ins) - elif ins == "(": - op.append(ins) - elif ins == ")": - while True: - if not op: - raise "ILLEGAL PARENTHESIS" - l = op.pop() - if l == "(": - break - out.append(l) - else: - raise f"UNKNOWN OP {ins}" - while op: - l = op.pop() - if l == "(": - raise "ILLEGAL PARENTHESIS" - out.append(l) - return out - - -print(shunting("1 + 22 k * ( 3 + 4 ) k".split())) 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 eb1ba425..89befec7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java @@ -154,7 +154,6 @@ public class Calculator { public static List<Token> shuntingYard(List<Token> toShunt) throws CalculatorException { // IT'S SHUNTING TIME // This is an implementation of the shunting yard algorithm - // Dear god, just thinking about dijkstra makes me wet and hard, such a fucking good mathematician Deque<Token> op = new ArrayDeque<>(); List<Token> out = new ArrayList<>(); |