static S dumbCalc(S s) {
L<S> tok = javaTok(s);
int i;
BigInteger result = null;
for (S op : litlist("+", "-", "*", "/", "^")) {
while ((i = matchMetaNoStar(tok, "<number>", op, "<number>")) >= 0) {
BigInteger a = new BigInteger(tok.get(i)), b = new BigInteger(tok.get(i+4));
result = mathOp(op, a, b);
clearAllTokens(tok.subList(i, i+5));
tok.set(i, "" + result);
tok = javaTok(tok);
}
}
if (result != null) ret "" + result;
ret null;
}download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1003608 |
| Snippet name: | dumbCalc - calculator with wrong precedence ^^ |
| Eternal ID of this version: | #1003608/1 |
| Text MD5: | 8573b890abc06ab0ef4e69e646282b48 |
| Author: | stefan |
| Category: | javax / talking robots |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-07-24 18:00:08 |
| Source code size: | 504 bytes / 16 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 978 / 967 |
| Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |