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;
char* tmp = op_stack[br - 1];
op_stack[br - 1] = sn_strcat(tmp, cbuf);
free(tmp);
+ }else if(br_stack[br - 1] > 0){
}
}
}
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);
#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);
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);
+}
#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