diff --git a/Operand.cpp b/Operand.cpp index 671a345..67887ea 100644 --- a/Operand.cpp +++ b/Operand.cpp @@ -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; } } diff --git a/Operand.h b/Operand.h index b55dcef..11ddc3b 100644 --- a/Operand.h +++ b/Operand.h @@ -10,8 +10,11 @@ namespace jet { class Operand { public: - Operand(coreutils::ZString &in, Tag &tag); + Operand(coreutils::ZString &in, Tag &tag, bool stop = false); + coreutils::ZString ∈ + Tag &tag; + bool isNumber; /// @@ -23,6 +26,8 @@ namespace jet { coreutils::MString string = ""; double doubleValue; + + int parseOperator(); }; diff --git a/tests/debug.jet b/tests/debug.jet new file mode 100755 index 0000000..6ce13a9 --- /dev/null +++ b/tests/debug.jet @@ -0,0 +1,5 @@ +#!../jet-2.0 + + +$[result]=10 + diff --git a/tests/testexpr.jet b/tests/testexpr.jet index 15a5e21..a8dbafd 100755 --- a/tests/testexpr.jet +++ b/tests/testexpr.jet @@ -12,4 +12,12 @@ $[righty]=56789 $[trim]=this is a test $[integer]=12430 + +$[result]=30 + +$[result]=35 + +$[result]=45 + +$[result]=10