/* 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
}
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))) {
+ delelement (new->ops[1]);
+ new->ops[1] = ERROR_OP;
+ }
if (new->ops[1] == ERROR_OP) {
delelement (new);
*proot = NULL;
do {
found = 0;
new = parser (str + 1, &str, 0);
- if (new == ERROR_OP) {
+ if ((new == NULL) || ((new != ERROR_OP) && (new->prio == 9))) {
+ delelement (new);
+ 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 == ERROR_OP) || (*str == ',')) {
+ if ((new == NULL) || ((new != ERROR_OP) && (new->prio == 9))) {
+ delelement (new);
+ new = ERROR_OP;
+ }
+ if ((new == NULL) || (new == ERROR_OP) || (*str == ',')) {
delelement (new);
delelement (root);
return ERROR_OP;
}
root->ops[0] = new;
}
+ if (*str != ')') {
+ delelement (root);
+ return ERROR_OP;
+ }
str++;
VERBOSE (DEBUG, fprintf (stdout, "stop processing bracket\n"));
continue;
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)) {
fprintf (stdout, " + - * / %% ^\n\n");
fprintf (stdout, "camparison operators:\n");
fprintf (stdout, " == != >= <= > <\n\n");
+ fprintf (stdout, "logical operators:\n");
+ fprintf (stdout, " & | !\n\n");
fprintf (stdout, "supported functions:\n");
fprintf (stdout, " pow sqrt cos sin atan log exp\n\n");
fprintf (stdout, "storage functions:\n");