From c39220d39c4f484a3fa6d60a56b9f6de522df243 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 18 Nov 2024 10:19:39 -0800 Subject: [PATCH] improved syntax checking on expr. Laid foundation for expr function. --- Operand.cpp | 15 ++++++++++++--- tests/testexpr.jet | 6 ++++++ tests/testwhile.jet | 4 ++-- 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100755 tests/testexpr.jet diff --git a/Operand.cpp b/Operand.cpp index aee75f0..f24fb93 100644 --- a/Operand.cpp +++ b/Operand.cpp @@ -53,7 +53,16 @@ namespace jet { } else throw coreutils::Exception("Expecting ) at end of LEFT expression."); } else if(in.ifNextIgnoreCase("EXPR")) { - + if(!in.ifNext("(")) + throw coreutils::Exception("Expecting ( for LEFT parameters."); + Operand parm1(in, global, lvariables); + if(in.ifNext(")")) { + Operand op(in, global, lvariables); + string = op.string; + isNumber = op.isNumber; + boolean = op.boolean; + } else + throw coreutils::Exception("Expecting ) at end of EXPR expression."); } else if(in.ifNextIgnoreCase("RIGHT")) { } else if(in.ifNextIgnoreCase("TRIM")) { @@ -90,7 +99,8 @@ namespace jet { string = in.getTokenExclude("'"); in.ifNext("'"); isNumber = false; - } + } else + throw coreutils::Exception("operand is not valid."); in.skipWhitespace(); @@ -284,7 +294,6 @@ namespace jet { throw coreutils::Exception("operand is not a number."); } else return; - } } diff --git a/tests/testexpr.jet b/tests/testexpr.jet new file mode 100755 index 0000000..220ae99 --- /dev/null +++ b/tests/testexpr.jet @@ -0,0 +1,6 @@ +#!../jet-2.0 + + + +$[test2] + diff --git a/tests/testwhile.jet b/tests/testwhile.jet index a3c3628..95b0e3a 100755 --- a/tests/testwhile.jet +++ b/tests/testwhile.jet @@ -1,8 +1,8 @@ #!../jet-2.0 - + -->$[ix]<-- - +