Fixed * and / operators to prioritize over + and -.
This commit is contained in:
1 parent
61216a2296
commit
a91d78f524
4 files changed
+36
-6
No files matched your search
+17
-5
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
Operand::Operand(coreutils::ZString &in, Tag &tag) {
|
||||
Operand::Operand(coreutils::ZString &in, Tag &tag, bool stop) : in(in), tag(tag) {
|
||||
|
||||
doubleValue = 0;
|
||||
|
||||
@@ -378,7 +378,15 @@ namespace jet {
|
||||
throw coreutils::Exception("operand is not valid.");
|
||||
|
||||
in.skipWhitespace();
|
||||
|
||||
if(!stop)
|
||||
parseOperator();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int Operand::parseOperator() {
|
||||
|
||||
if(in.ifNext("!=") || in.ifNext("<>")) {
|
||||
Operand op(in, tag);
|
||||
if(isNumber && op.isNumber) {
|
||||
@@ -523,6 +531,8 @@ namespace jet {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(in.ifNext("+")) {
|
||||
if(isNumber) {
|
||||
Operand op(in, tag);
|
||||
@@ -547,28 +557,30 @@ namespace jet {
|
||||
throw coreutils::Exception("operand is not a number.");
|
||||
} else if(in.ifNext("*")) {
|
||||
if(isNumber) {
|
||||
Operand op(in, tag);
|
||||
Operand op(in, tag, true);
|
||||
if(op.isNumber) {
|
||||
doubleValue *= op.doubleValue;
|
||||
string = std::format("{:.12f}", doubleValue);
|
||||
string.removeTrailingZeros();
|
||||
parseOperator();
|
||||
} else
|
||||
throw coreutils::Exception("operand is not a number.");
|
||||
} else
|
||||
throw coreutils::Exception("operand is not a number.");
|
||||
} else if(in.ifNext("/")) {
|
||||
if(isNumber) {
|
||||
Operand op(in, tag);
|
||||
Operand op(in, tag, true);
|
||||
if(op.isNumber) {
|
||||
doubleValue /= op.doubleValue;
|
||||
string = std::format("{:.12f}", doubleValue);
|
||||
string.removeTrailingZeros();
|
||||
parseOperator();
|
||||
} else
|
||||
throw coreutils::Exception("operand is not a number.");
|
||||
} else
|
||||
throw coreutils::Exception("operand is not a number.");
|
||||
} else
|
||||
return;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user