int sig;
while (*ref != '\0') {
- sig = *str++ - *ref++;
+ if (*ref == '\t') {
+ sig = (*str == '.') ? -1 : ((*str >= '0') && (*str <= '9'));
+ } else {
+ sig = *str - *ref;
+ }
if (sig != 0) {
return (sig > 0) ? 1 : -1;
}
+ str++;
+ ref++;
}
return 0;
/* functions */
-#define NB_OPERATORS 7
+#define NB_OPERATORS 5
keyword_t operators[NB_OPERATORS] = {
- { "+ ", Add, 2, 1 },
- { "+\t", Add, 2, 1 },
- { "- ", Sub, 2, 1 },
+ { "+\t", Add, 2, 1 },
{ "-\t", Sub, 2, 1 },
{ "*", Mul, 2, 1 },
{ "/", Div, 2, 1 },
continue;
}
- /* last attend to detect addition and substraction */
-
- if (((*str == '-') || (*str == '+')) &&
- ((*(str + 1) >= '0') && (*(str + 1) <= '9')) &&
- ((root) && (root->func == Val))) {
- VERBOSE (INFO, PRINTOUT ("Oper: %d\n", Add));
- new = newelement (Add, 2);
- if (new == NULL) {
- return ERROR_OP;
- }
- new->ops[0] = root;
- root = new;
- }
-
/* look for number */
- if (((*str >= '0') && (*str <= '9')) || (*str == '.')) {
+ if (((*str >= '0') && (*str <= '9')) ||
+ (*str == '.') || (*str == '+') || (*str == '-')) {
VERBOSE (DEBUG, PRINTOUT ("start processing value\n"));
char *pt;
float value = strtof (str, &pt);
new->value = value;
if (root == NULL) {
root = new;
- } else {
- if (root->func == Val) {
- element_t *set = newelement (Set, MAX_OPERANDS);
- if (set == NULL) {
+ } else if (root->func == Val) {
+ if ((*str == '+') || (*str == '-')) {
+ element_t *add = newelement (Add, 2);
+ if (add == NULL) {
return ERROR_OP;
}
- set->ops[0] = root;
- root = set;
- }
- for (i = 0; i < root->nbops; i++) {
- if (root->ops[i] == NULL) {
- root->ops[i] = new;
- found = 1;
- break;
- }
- }
- if (!found) {
+ add->ops[0] = root;
+ add->ops[1] = new;
+ root = add;
+ } else {
return ERROR_OP;
}
+ } else {
+ return ERROR_OP;
}
str = pt;
found = 1;