// test: echo "2 + * 3" | calc.exe | grep -q 'error'
// test: echo "2 + cos(3 *)" | calc.exe | grep -q 'error'
// test: echo "2 + (foo)" | calc.exe | grep -q 'error'
-// test: echo "2 + cos (pi" | calc.exe | grep -q 'error'
+// test: echo "2 + cos (pi +" | calc.exe | grep -q 'error'
+// test: echo "2 + cos (pi" | calc.exe | grep -vq 'error'
// test: echo "cos (1, 2)" | calc.exe | grep -q 'error'
// test: echo "sqrt 2" | calc.exe | grep -q 'error'
// test: echo "pow (2)" | calc.exe | grep -q 'error'
// test: echo -e '1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1\n1 + 1' | calc.exe | grep -q 64
// test: echo -e '1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1\n1 + 1' | calc.exe | grep -q 2
// test: echo -e '-cos (1)\n1 + 1\n1 - 1\n1 * 1\n1 / 1\n3%2\n2^2\nsqrt (2)\ncos (0)\nsin (0)\natan (0)\nlog (1)\nexp (1)\nans\ne\npi\nsto (1)\nrcl (2)\ndisp\nhelp\nquit' | calc.exe -v 3 | grep -q bye
-// test: echo -e '1 +\n1 -\n1 * 1\n1 /\n3%\n2^\nsqrt ()\ncos ()\nsin ()\natan ()\nlog ()\nexp ()\n1 + (' | calc.exe | grep -c error | xargs test 11 =
+// test: echo -e '1 +\n1 -\n1 * 1\n1 /\n3%\n2^\nsqrt ()\ncos ()\nsin ()\natan ()\nlog ()\nexp ()\n1 + (' | calc.exe | grep -c error | xargs test 12 =
// test: echo -e '1 + 1\nans' | calc.exe -p 3 | grep -c 2 | xargs test 2 =
// test: echo -e 'sin (pi / 2)' | calc.exe -p 4 | grep -q 1
// test: echo -e 'e ^ 2' | calc.exe | grep -q '7\.38906'
// test: echo -e '(3 == 4) | (2 > 2)' | calc.exe | grep -q '=> 0'
// test: echo -e '!(3 == 4)' | calc.exe | grep -q '=> 1'
// test: echo -e '!(3 == 3)' | calc.exe | grep -q '=> 0'
-// test: echo -e '1 & 1\n1 | 1\n!1\nquit' | calc.exe -v 3 | grep -q bye
+// test: echo -e '1 & 1\n1 | 1\n!(1)\nquit' | calc.exe -v 3 | grep -q bye
// test: echo -e '(3 == 3) & (4 > 2)' | calc.exe | grep -q '=> 1'
// test: echo -e '3 == 3 & 4 > 2' | calc.exe | grep -q '=> 1'
// test: echo -e '1 + quit' | calc.exe 2>&1 | grep -q error
}
new->ops[0] = *proot;
new->ops[1] = parser (*pstr, pstr, new->prio);
- if ((new->ops[1] != NULL) && (new->ops[1] != ERROR_OP) && (new->ops[1]->prio == 9)) {
+ if ((new->ops[1] == NULL) || ((new->ops[1] != ERROR_OP) && (new->ops[1]->prio == 9))) {
delelement (new->ops[1]);
new->ops[1] = ERROR_OP;
}
do {
found = 0;
new = parser (str + 1, &str, 0);
- if ((new != NULL) && (new != ERROR_OP) && (new->prio == 9)) {
+ if ((new == NULL) || ((new != ERROR_OP) && (new->prio == 9))) {
delelement (new);
new = ERROR_OP;
}
- if (new == ERROR_OP) {
+ if ((new == NULL) || (new == ERROR_OP)) {
delelement (root);
return ERROR_OP;
}
return ERROR_OP;
}
new = parser (str + 1, &str, 0);
- if ((new != NULL) && (new != ERROR_OP) && (new->prio == 9)) {
+ if ((new == NULL) || ((new != ERROR_OP) && (new->prio == 9))) {
delelement (new);
new = ERROR_OP;
}
- if ((new == ERROR_OP) || (*str == ',')) {
+ if ((new == NULL) || (new == ERROR_OP) || (*str == ',')) {
delelement (new);
delelement (root);
return ERROR_OP;