// 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 -qv error
// 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
// test: echo -e 'cos (quit)' | calc.exe 2>&1 | grep -q error
// test: echo -e '(quit)' | calc.exe 2>&1 | grep -q error
+// test: echo -e 'cos 3.14\n!\n! 3 4' | calc.exe 2>&1 | grep -c error | xargs test 3 =
/* vim: set ts=4 sw=4 et: */
/* functions */
#define NB_OPERATORS 14
-
keyword_t operators[NB_OPERATORS] = {
{ "+\t", Add, 2, 1, 1},
{ "-\t", Sub, 2, 1, 1},
{ "disp", Disp, 0, 4, 9},
{ "quit", Quit, 0, 4, 9},
{ "help", Help, 0, 4, 9},
- { "!", Not, 1, 1, 5}
+ { "!", Not, 1, 1, 6}
};
#define NB_CONSTANTS 3
double value = strtod (str, &pt);
VERBOSE (INFO, fprintf (stdout, "Value: %f\n", value));
if (str != pt) {
- if (root == NULL) {
+ if ((root == NULL) || (root->prio == 6)) {
new = newelement (Val, 1, 5);
if (new == NULL) {
return ERROR_OP;
}
new->value = value;
- root = new;
+ if (root == NULL) {
+ root = new;
+ } else {
+ for (i = 0; i < root->nbops; i++) {
+ if (root->ops[i] == NULL) {
+ root->ops[i] = new;
+ found = 1;
+ break;
+ }
+ }
+ if (!found) {
+ delelement (new);
+ delelement (root);
+ return ERROR_OP;
+ }
+ }
str = pt;
} else if ((*str == '+') || (*str == '-')) {
if ((prio) && (prio > 1)) {
return ERROR_OP;
}
} else {
+printf("coucou\n"); fflush (stdout);
delelement (root);
return ERROR_OP;
}