kouamano / RECURSIVE-SYSTEM

test for recursive operation
3 stars 1 forks source link

木の外積 #114

Closed kouamano closed 2 years ago

kouamano commented 2 years ago

jsik branchに実装

>> source code
diff --git a/tq.c b/tq.c
index b4921c9..8183a21 100644
--- a/tq.c
+++ b/tq.c
@@ -273,6 +273,7 @@ void put_examples(void){
 }

 /* allocation */
+#include "../include/alloc.c"
 struct options *alloc_options(void){
    struct options *p;
    if((p = malloc(sizeof(struct options) * 1)) == NULL){
@@ -612,6 +613,7 @@ void check_data_options(struct data_options *dopt){
 }

 /* tree functions */
+#include "../include/list_operations.c"
 #include "T-functions.h"
 #include "T-functions_Executor.h"
 #include "T-functions_imex.h"
diff --git a/T-functions.h b/T-functions.h
index a4adf5e..55090f3 100644
--- a/T-functions.h
+++ b/T-functions.h
@@ -1,11 +1,13 @@
 /* README */
 /* //%P : print-function which contains NO converter. */
 /* //%I : incomplete function. */
+//#include "../include/alloc.c"
+//#include "../include/list_operations.c"

 /* prottype */
 struct Tree *Function_Print_Head(struct Tree *, struct function_options *, struct compile_options *);
 //struct Tree *Executor(struct Tree *, struct Tree *, struct Tree *, int, int, struct options *, struct function_options *, struct compile_options *, struct search_options *, FILE *, int);
-struct Tree *ExFunction_Recursive_Print_Tree(struct Tree *, struct Tree *(*)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*)(struct Tree *, struct function_options *, struct compile_options *, int),  struct Tree *(*)(struct Tree *, struct function_options *, struct compile_options *), struct options *, struct function_options *, struct compile_options *, int);
+struct Tree *ExFunction_Recursive_Print_Tree(struct Tree *, struct Tree *(*)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*)(struct Tree *, struct function_options *, struct compile_options *, int),  struct Tree *(*)(struct Tree *, struct function_options *, struct compile_options *), struct options *, struct function_options *, struct compile_options *, struct reform_options *, int);
 struct Tree *ExFunction_Recursive_Ser(struct Tree *, struct Tree *(*)(struct Tree *, int, struct options *), struct options *, struct function_options *, struct compile_options *, int , int);
 struct Tree *ExFunction_Recursive(struct Tree *, struct Tree *(*)(struct Tree *, struct options *), struct options *, struct function_options *, struct compile_options *);
 struct Tree *ExFunction_Recursive_Set_Obj(struct Tree *, struct Tree *(*)(struct Tree *, void *), void *);
@@ -53,6 +55,24 @@ int get_char_pos(char *str, char ch){
    return(i);
 }
 /** tree analysis */
+int *count_node(struct Tree *tree, int *count){
+   //(*count)++;
+   int i;
+   for(i=0;i<(*tree).NextCount;i++){
+       (*count)++;
+       count_node((*tree).Next[i],count);
+   }
+   return(count);
+}
+int *insert_tree(struct Tree *tree, struct Tree **array, int *pos){
+   int i;
+   array[*pos] = tree;
+   (*pos)++;
+   for(i=0;i<(*tree).NextCount;i++){
+       insert_tree((*tree).Next[i],array,pos);
+   }
+   return(pos);
+}
 struct Tree *ExFunction_Get_Node(char *pos_str, struct Tree *tree){
    FC(fprintf(stderr,">ExFunction_Get_Node<\n");)
    int len = 0;
@@ -1169,7 +1189,7 @@ struct Tree *Function_Recursive_Print_nthVal(struct Tree *tree, int nth, struct
            if(((*_fopt).f_skipOnce&1) != 1){
                (*_fopt).f_skipOnce = (*_fopt).f_skipOnce + 1;
            }
-           ExFunction_Recursive_Print_Tree((*tree).Next[nth%(*tree).NextCount], (struct Tree *(*)())Function_Print_Conj_T, (struct Tree *(*)())Function_Print_Head, (struct Tree *(*)())Function_Print_Bopen_T,  (struct Tree *(*)())Function_Print_Bclose_T,NULL,_fopt,_copt,0);
+           ExFunction_Recursive_Print_Tree((*tree).Next[nth%(*tree).NextCount], (struct Tree *(*)())Function_Print_Conj_T, (struct Tree *(*)())Function_Print_Head, (struct Tree *(*)())Function_Print_Bopen_T,  (struct Tree *(*)())Function_Print_Bclose_T,NULL,_fopt,_copt,NULL,0);
            return(tree);
        }
    }
@@ -1323,7 +1343,7 @@ struct Tree *Function_Print_Head(struct Tree *tree, struct function_options *_fo
                (*_fopt).f_skipOnce = (*_fopt).f_skipOnce + 1;
            }
            DB(fprintf(stderr," print_head:skip:%d:\n",(*_fopt).f_skipOnce);)
-           ExFunction_Recursive_Print_Tree((*tree).RefNode, (struct Tree *(*)())Function_Print_Conj_T, (struct Tree *(*)())Function_Print_Head, (struct Tree *(*)())Function_Print_Bopen_T,  (struct Tree *(*)())Function_Print_Bclose_T,NULL,_fopt,_copt,0);
+           ExFunction_Recursive_Print_Tree((*tree).RefNode, (struct Tree *(*)())Function_Print_Conj_T, (struct Tree *(*)())Function_Print_Head, (struct Tree *(*)())Function_Print_Bopen_T,  (struct Tree *(*)())Function_Print_Bclose_T,NULL,_fopt,_copt,NULL,0);
        }else if((*tree).RefNode->LabelType == 't' && target_type == 'h'){
            DB(fprintf(stderr," LT:t:,TG:h:\n");)
            printf("@");
@@ -1517,7 +1537,85 @@ struct Tree *ExFunction_Recursive_Ser(struct Tree *tree, struct Tree *(*e_functi
    }
    return(out);
 }
-struct Tree *ExFunction_Recursive_Print_Tree(struct Tree *tree, struct Tree *(*print_conj)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*print_head)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*print_bopen)(struct Tree *, struct function_options *, struct compile_options *, int),  struct Tree *(*print_bclose)(struct Tree *, struct function_options *, struct compile_options *), struct options *_opt, struct function_options *_fopt, struct compile_options *_copt, int _ser){
+/*
+struct Tree *print_path_tree(struct Tree *tree, struct Tree *(*print_conj)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*print_head)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*print_bopen)(struct Tree *, struct function_options *, struct compile_options *, int),  struct Tree *(*print_bclose)(struct Tree *, struct function_options *, struct compile_options *), struct options *_opt, struct function_options *_fopt, struct compile_options *_copt, int _ser){
+   int i;
+   int count = 0;
+   struct Tree **array = NULL;
+   count_node(tree,&count);
+   count++;
+   printf(" count:%d; ",count);
+   if((array = malloc(sizeof(struct Tree *) * (count+1))) == NULL){
+       perror("Fail:malloc\n");
+   }
+   int pos = 0;
+   insert_tree(tree,array,&pos);
+   for(i=0;iHead);
+       ExFunction_Recursive_Print_Tree(array[i],print_conj,print_head,print_bopen,print_bclose,_opt,_fopt,_copt,NULL,_ser);
+   }
+   free(array);
+   return(tree);
+}
+*/
+struct Tree *Function_Print_OTree(struct Tree *tree, struct Tree *(*print_conj)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*print_head)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*print_bopen)(struct Tree *, struct function_options *, struct compile_options *, int),  struct Tree *(*print_bclose)(struct Tree *, struct function_options *, struct compile_options *), struct options *_opt, struct function_options *_fopt, struct compile_options *_copt, int _ser){
+   //printf("Under construction -> $TO$の組出力における最初の要素のカンマの抑制,\n");
+   //needs:
+   int i;
+   int j;
+   struct Tree ***array = NULL;
+   if((array = malloc(sizeof(struct Tree **) * (*tree).NextCount)) == NULL){
+       perror("Failed:malloc\n");
+   }
+   int *node_count_array = 0;
+   if((node_count_array = malloc(sizeof(int) * (*tree).NextCount)) == NULL){
+       perror("Failed:malloc\n");
+   }
+   for(i=0;i<(*tree).NextCount;i++){
+       node_count_array[i] = 0;
+       count_node((*tree).Next[i], &node_count_array[i]);
+       node_count_array[i]++;
+       if((array[i] = malloc(sizeof(struct Tree *) * node_count_array[i])) == NULL){
+           perror("Failed:malloc\n");
+       }
+       int pos = 0;
+       for(j=0;jNCself == 1){
+               printf(",");
+           }
+           ExFunction_Recursive_Print_Tree(array[counter][outer_list[i][j]],print_conj,print_head,print_bopen,print_bclose,_opt,_fopt,_copt,NULL,_ser);
+           counter++;
+       }
+       printf(")");
+   }
+   return(tree);
+}
+struct Tree *ExFunction_Recursive_Print_Tree(struct Tree *tree, struct Tree *(*print_conj)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*print_head)(struct Tree *, struct function_options *, struct compile_options *), struct Tree *(*print_bopen)(struct Tree *, struct function_options *, struct compile_options *, int),  struct Tree *(*print_bclose)(struct Tree *, struct function_options *, struct compile_options *), struct options *_opt, struct function_options *_fopt, struct compile_options *_copt, struct reform_options *_ropt, int _ser){
    FC(fprintf(stderr,">ExFunction_Recursive_Print_Tree<\n");)
    int i;
    struct Tree *out = tree;
@@ -1526,7 +1624,15 @@ struct Tree *ExFunction_Recursive_Print_Tree(struct Tree *tree, struct Tree *(*p
        exit(1);
    }
    /*print conj*/
-   print_conj(tree,_fopt,_copt);
+   if(_ropt == NULL){
+       print_conj(tree,_fopt,_copt);
+   }else{
+       if((*_ropt).sup_print_conj != 1){
+           print_conj(tree,_fopt,_copt);
+       }else{
+           ;
+       }
+   }
    /*print Bopen pre*/
    print_bopen(tree,_fopt,_copt,0);
    /*print head*/
@@ -1534,11 +1640,16 @@ struct Tree *ExFunction_Recursive_Print_Tree(struct Tree *tree, struct Tree *(*p
    /*print Bopen post*/
    print_bopen(tree,_fopt,_copt,1);
    // $UU$ : if Tree.builtin_flag&2 == 2 then skip for-loop.
-   if(((*tree).builtin_flag&2) == 2 && (*_copt).c_counter > 0){
+   if(((*tree).builtin_flag&64) == 64 && (*_copt).c_counter > 0){
+       Function_Print_OTree(tree,print_conj,print_head,print_bopen,print_bclose,_opt,_fopt,_copt,_ser);
+   }else if(((*tree).builtin_flag&32) == 32 && (*_copt).c_counter > 0){
+       //Function_Print_OProductVal(tree,_fopt,_copt);
+       printf("Under construction");
+   }else if(((*tree).builtin_flag&2) == 2 && (*_copt).c_counter > 0){
        Function_Cyclic_Print_IProductVal(tree,_fopt,_copt);
    }else{
        for(i=0;i<(*tree).NextCount;i++){
-           ExFunction_Recursive_Print_Tree((*tree).Next[i],print_conj,print_head,print_bopen,print_bclose,_opt,_fopt,_copt,_ser);
+           ExFunction_Recursive_Print_Tree((*tree).Next[i],print_conj,print_head,print_bopen,print_bclose,_opt,_fopt,_copt,NULL,_ser);
        }
    }
    /*print Bclose*/
diff --git a/T-functions_Executor.h b/T-functions_Executor.h
index f6642ea..3891377 100644
--- a/T-functions_Executor.h
+++ b/T-functions_Executor.h
@@ -43,7 +43,7 @@ struct Tree *Executor(struct Tree *top, struct Tree *refTree, struct Tree *null_
            /*** apply formated print */
            (*_fopt).f_print_self_stat = 1;
            if((*_fopt).f_print_N == 1){
-               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_T, (struct Tree *(*)())Function_Print_Head_SN, (struct Tree *(*)())Function_Print_Bopen_T, (struct Tree *(*)())Function_Print_Bclose_T, _opt,_fopt,_copt,SN);
+               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_T, (struct Tree *(*)())Function_Print_Head_SN, (struct Tree *(*)())Function_Print_Bopen_T, (struct Tree *(*)())Function_Print_Bclose_T, _opt,_fopt,_copt,NULL,SN);
                if((*_copt).c_restrict == 1){
                    printf(";");
                }
@@ -53,7 +53,7 @@ struct Tree *Executor(struct Tree *top, struct Tree *refTree, struct Tree *null_
                if((*_fopt).f_print_hierarchy == 1){
                    printf("====multiline====>");
                }
-               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_T, (struct Tree *(*)())Function_Print_Head, (struct Tree *(*)())Function_Print_Bopen_T,  (struct Tree *(*)())Function_Print_Bclose_T,_opt,_fopt,_copt,SN);
+               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_T, (struct Tree *(*)())Function_Print_Head, (struct Tree *(*)())Function_Print_Bopen_T,  (struct Tree *(*)())Function_Print_Bclose_T,_opt,_fopt,_copt,NULL,SN);
                if((*_copt).c_restrict == 1){
                    printf(";");
                }
@@ -63,33 +63,33 @@ struct Tree *Executor(struct Tree *top, struct Tree *refTree, struct Tree *null_
                }
            }
            if((*_fopt).f_print_S == 1){
-               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_S, (struct Tree *(*)())Function_Print_Head, (struct Tree *(*)())Function_Print_Bopen_S, (struct Tree *(*)())Function_Print_Bclose_S, _opt,_fopt,_copt,SN);
+               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_S, (struct Tree *(*)())Function_Print_Head, (struct Tree *(*)())Function_Print_Bopen_S, (struct Tree *(*)())Function_Print_Bclose_S, _opt,_fopt,_copt,NULL,SN);
                if((*_copt).c_restrict == 1){
                    printf(";");
                }
                printf("\n");
            }
            if((*_fopt).f_print_W >= 1){
-               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_WL, (struct Tree *(*)())Function_Print_Head_WL, (struct Tree *(*)())Function_Print_Bopen_WL, (struct Tree *(*)())Function_Print_Bclose_WL, _opt,_fopt,_copt, SN);
+               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_WL, (struct Tree *(*)())Function_Print_Head_WL, (struct Tree *(*)())Function_Print_Bopen_WL, (struct Tree *(*)())Function_Print_Bclose_WL,_opt,_fopt,_copt,NULL,SN);
                if((*_copt).c_restrict == 1){
                    printf(";");
                }
                printf("\n");
            }
            if((*_fopt).f_print_X == 1){
-               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_X, (struct Tree *(*)())Function_Print_Head_X, (struct Tree *(*)())Function_Print_Bopen_X, (struct Tree *(*)())Function_Print_Bclose_X, _opt,_fopt,_copt,SN);
+               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_X, (struct Tree *(*)())Function_Print_Head_X, (struct Tree *(*)())Function_Print_Bopen_X, (struct Tree *(*)())Function_Print_Bclose_X,_opt,_fopt,_copt,NULL,SN);
                if((*_copt).c_restrict == 1){
                    printf("<;/>");
                }
                printf("\n");
            }
            if((*_fopt).f_print_J == 1){
-               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_JS, (struct Tree *(*)())Function_Print_Head_JS, (struct Tree *(*)())Function_Print_Bopen_JS, (struct Tree *(*)())Function_Print_Bclose_WL, _opt,_fopt,_copt,SN);
+               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_JS, (struct Tree *(*)())Function_Print_Head_JS, (struct Tree *(*)())Function_Print_Bopen_JS, (struct Tree *(*)())Function_Print_Bclose_WL,_opt,_fopt,_copt,NULL,SN);
                printf("\n");
            }
            if((*_fopt).f_print_C == 1){
                printf("====multiline====>\n");
-               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_C, (struct Tree *(*)())Function_Print_Head, (struct Tree *(*)())Function_Print_Bopen_C, (struct Tree *(*)())Function_Print_Bclose_C, _opt,_fopt,_copt,SN);
+               ExFunction_Recursive_Print_Tree(hit_tree, (struct Tree *(*)())Function_Print_Conj_C, (struct Tree *(*)())Function_Print_Head, (struct Tree *(*)())Function_Print_Bopen_C, (struct Tree *(*)())Function_Print_Bclose_C,_opt,_fopt,_copt,NULL,SN);
                printf("<====multiline====\n");
            }
            /*** apply status print */
kouamano commented 2 years ago

cqに反映。一旦close。