element_t *parser (char *str, char **next)
{
element_t *root = NULL;
- int i, j;
+ int i;
VERBOSE (DEBUG, PRINTOUT ("Starting parsing\n"));
continue;
}
- /* skip commas */
-
- if (*str == ',') {
- VERBOSE (DEBUG, PRINTOUT ("start processing coma\n"));
- str++;
- if (root == NULL) {
- return parser (str, &str);
- } else if (root->func != Set) {
- new = newelement (Set, MAX_OPERANDS);
- if (new == NULL) {
- return ERROR_OP;
- }
- new->ops[0] = root;
- root = new;
- VERBOSE (DEBUG, PRINTOUT ("end processing first coma\n"));
- } else /* if (root->func == Set) */ {
- new = parser (str, &str);
- if (!found){
- return ERROR_OP;
- }
- for (i = 0; i < root->nbops; i++) {
- if (root->ops[i] == NULL) {
- root->ops[i] = new;
- found = 1;
- }
- }
- if (!found){
- return ERROR_OP;
- }
- VERBOSE (DEBUG, PRINTOUT ("end processing other coma\n"));
- }
- continue;
- }
-
- /* check for parent */
+ /* check for open bracket */
if (*str == '(') {
VERBOSE (DEBUG, PRINTOUT ("start processing bracket\n"));
- new = parser (str + 1, &str);
- if (new == ERROR_OP) {
- return ERROR_OP;
- }
if (root) {
- for (i = 0, j = 0; i < root->nbops; i++) {
- if (root->ops[i] == NULL) {
- if (new->func == Set) {
- root->ops[i] = new->ops[j++];
- if (new->ops[j] == NULL) {
- found = 1;
- break;
- }
- } else {
+ do {
+ found = 0;
+ new = parser (str + 1, &str);
+ if (new == ERROR_OP) {
+ return ERROR_OP;
+ }
+ for (i = 0; i < root->nbops; i++) {
+ if (root->ops[i] == NULL) {
root->ops[i] = new;
found = 1;
break;
}
}
- }
- if (!found) {
+ if (!found) {
+ return ERROR_OP;
+ }
+ } while (*str == ',');
+ } else {
+ root = newelement (Val, 1);
+ if (root == NULL) {
return ERROR_OP;
}
- } else {
- if (new->func != Set) {
- root = new;
- } else {
+ new = parser (str + 1, &str);
+ if ((new == ERROR_OP) || (*str == ',')) {
return ERROR_OP;
}
+ root->ops[0] = new;
}
+ str++;
VERBOSE (DEBUG, PRINTOUT ("stop processing bracket\n"));
- //if (next != NULL) {
- // *next = str;
- //}
- //return root;
continue;
}
- if (*str == ')') {
+
+ /* check for closing bracket or koma */
+
+ if ((*str == ')') || (*str == ',')) {
if (next != NULL) {
- *next = str + 1;
+ *next = str;
}
return root;
}
PRINTOUT ("Function: %s\n", func);
- if (root->func == Val) {
+ if ((root->func == Val) && (root->ops[0] == NULL)) {
for (i = 0; i < level; i++) {
PRINTOUT (" ");
}