{ "log", Log, 1, 3, 5}
};
+/* subparser function */
+
+element_t *subparser (element_t **proot, char **pstr, func_t func, int nbops, int prio)
+{
+ element_t *new = newelement (func, nbops, prio);
+ if (new == NULL) {
+ return ERROR_OP;
+ }
+ new->ops[0] = *proot;
+ new->ops[1] = parser (*pstr, pstr, new->prio);
+ if (new->ops[1] == ERROR_OP) {
+ return ERROR_OP;
+ }
+ *proot = newelement (Val, 1, 4);
+ if (*proot == ERROR_OP) {
+ return ERROR_OP;
+ }
+ (*proot)->ops[0] = new;
+
+ return *proot;
+}
+
/* parser function */
element_t *parser (char *str, char **next, int prio)
}
str += operator->offset;
VERBOSE (INFO, PRINTOUT ("Oper: %d\n", operator->func));
- new = newelement (operator->func, operator->nbops, operator->prio);
- if (new == NULL) {
- return ERROR_OP;
- }
- new->ops[0] = root;
- new->ops[1] = parser (str, &str, new->prio);
- if (new->ops[1] == ERROR_OP) {
- return ERROR_OP;
- }
- root = newelement (Val, 1, 4);
- if (root == ERROR_OP) {
+ if (subparser (&root, &str, operator->func, operator->nbops, operator->prio) == ERROR_OP) {
return ERROR_OP;
}
- root->ops[0] = new;
} else {
return ERROR_OP;
}
*next = str;
return root;
}
- new = newelement (Add, 2, 1);
- if (new == NULL) {
- return ERROR_OP;
- }
- new->ops[0] = root;
- new->ops[1] = parser (str, &str, new->prio);
- if (new->ops[1] == ERROR_OP) {
- return ERROR_OP;
- }
- root = newelement (Val, 1, 4);
- if (root == ERROR_OP) {
+ if (subparser (&root, &str, Add, 2, 1) == ERROR_OP) {
return ERROR_OP;
}
- root->ops[0] = new;
} else {
return ERROR_OP;
}