]> Nishi Git Mirror - serenade.git/commitdiff
parsing
authornishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Tue, 23 Apr 2024 05:21:56 +0000 (05:21 +0000)
committernishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Tue, 23 Apr 2024 05:21:56 +0000 (05:21 +0000)
git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@13 0f02c867-ac3d-714e-8a88-971ba1f6efcf

Serenade/parser.c
Serenade/util.c
Serenade/util.h

index 263b8a9cee78885a76382b023ba59fda76d8ac3a..8324c5e3d649ecbba212c9ce1343635e3ae5789d 100644 (file)
@@ -77,7 +77,7 @@ struct sn_generic* sn_expr_parse(char* data, unsigned long long size){
                        op_stack[br - 1] = malloc(1);
                        op_stack[br - 1][0] = 0;
                }else if(c == ')'){
-                       if(br == 1){
+                       if(br > 0){
                                gn_stack[br - 1]->tree->op->name = sn_strdup(op_stack[br - 1]);
                        }
                        br_stack[br - 1] = 0;
@@ -104,6 +104,7 @@ struct sn_generic* sn_expr_parse(char* data, unsigned long long size){
                                char* tmp = op_stack[br - 1];
                                op_stack[br - 1] = sn_strcat(tmp, cbuf);
                                free(tmp);
+                       }else if(br_stack[br - 1] > 0){
                        }
                }
        }
@@ -136,6 +137,7 @@ struct sn_generic** sn_parse(char* data, unsigned long long size){
                                memcpy(d, data + start, i - start + 1);
                                struct sn_generic* gen = sn_expr_parse(d, i - start + 1);
                                if(gen != NULL){
+                                       sn_print_generic(gen);
                                        sn_generic_free(gen);
                                }
                                free(d);
index fdec195c6bfea224380301b3ca2970660e05637e..c82b778cfd393960b3b1b4073babb88d362926b7 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
 
 char* sn_strcat(const char* str1, const char* str2){
        char* str = malloc(strlen(str1) + strlen(str2) + 1);
@@ -47,3 +48,20 @@ char* sn_strdup(const char* str1){
        str[strlen(str1)] = 0;
        return str;
 }
+
+void _sn_print_generic(struct sn_generic* gen, int n){
+       int i;
+       for(i = 0; i < n; i++) fprintf(stderr, "    ");
+       if(gen->type == SN_TYPE_TREE){
+               fprintf(stderr, "%s\n", gen->tree->op->name);
+               if(gen->tree->args != NULL){
+                       for(i = 0; gen->tree->args[i] != NULL; i++){
+                               _sn_print_generic(gen->tree->args[i], n + 1);
+                       }
+               }
+       }
+}
+
+void sn_print_generic(struct sn_generic* gen){
+       _sn_print_generic(gen, 0);
+}
index a658cecbab5ffaaf8ee904b0eff3a168ae11f4ee..d22085009021f387f429643c15917292b473c31e 100644 (file)
 #ifndef __SERENADE_UTIL_H__
 #define __SERENADE_UTIL_H__
 
+#include "parser.h"
+
 char* sn_strcat(const char* str1, const char* str2);
 char* sn_strdup(const char* str1);
+void sn_print_generic(struct sn_generic* gen);
 
 #endif