bracket supported
authorLaurent Mazet <mazet@softndesign.org>
Tue, 27 Dec 2022 21:50:38 +0000 (22:50 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Tue, 27 Dec 2022 21:50:38 +0000 (22:50 +0100)
parser.c

index e7c91888f15cec4380aabf2d6b65537a06ca200a..2ed8d9d845dd4f6749b021f582703fe9a92a168c 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -67,7 +67,7 @@ keyword_t functions[NB_FUNCTIONS] = {
 element_t *parser (char *str, char **next)
 {
     element_t *root = NULL;
-    int i, j;
+    int i;
 
     VERBOSE (DEBUG, PRINTOUT ("Starting parsing\n"));
 
@@ -84,84 +84,49 @@ element_t *parser (char *str, char **next)
             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;
         }
@@ -326,7 +291,7 @@ void print_element (element_t *root, int level)
 
     PRINTOUT ("Function: %s\n", func);
 
-    if (root->func == Val) {
+    if ((root->func == Val) && (root->ops[0] == NULL)) {
         for (i = 0; i < level; i++) {
             PRINTOUT (" ");
         }