full while feature
authorLaurent Mazet <mazet@softndesign.org>
Tue, 24 Jan 2023 22:05:26 +0000 (23:05 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Tue, 24 Jan 2023 22:05:26 +0000 (23:05 +0100)
calc.c
parser.c

diff --git a/calc.c b/calc.c
index 41429cb93771d0871255224aaae06095746a9125..7013673b8600a88e713c0696cddd121dfbbb8a3a 100644 (file)
--- a/calc.c
+++ b/calc.c
@@ -291,6 +291,8 @@ int main (int argc, char *argv[])
 // test: echo -e 'sto (1, 4)\ninc (1)\ninc (1)\ndec (1)\ninc (1)\nrcl (1) == 6' | calc.exe -v 3 | grep -q '=> 1'
 // test: echo -e 'inc\ninc (\ndec\ndec (' | calc.exe 2>&1 | grep -c error | xargs test 4 =
 // test: echo -e 'inc (11)\ndec (0)' | calc.exe 2>&1 | grep -c invalid | xargs test 2 =
-// test: echo -e 'whl (inc (1) < 3, sto (rcl (2) + 3))' | calc.exe | xargs test 16 =
+// test: echo -e 'whl (inc (1) < 100, sto (2, rcl (1) + rcl (2)))' | calc.exe | grep -q '=> 5050'
+// test: echo -e 'whl\nwhl (inc (1) < 3,\nwhl (inc (1) < 100, sto (2, rcl (1) + rcl (2))' 2>&1 | calc.exe | grep -c error | xargs test 3 =
+// test: echo -e 'whl (0, 1)' | calc.exe -v 3 | grep -q While
 
 /* vim: set ts=4 sw=4 et: */
index 8654fa8a78a61a3c6e90bc0c11de5f48566c8120..20f507d014446d92f63cd2bf73dba65f4fda2930 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -677,7 +677,12 @@ double evaluate_element (element_t *root, char mask)
     case Ans:
     case Pi:
     case E:
+        break;
     case While:
+        if (root->ops[0] == NULL) {
+            VERBOSE (WARNING, fprintf (stdout, "error while evaluating (op[0])\n"));
+            return 0;
+        }
         break;
     }