aboutsummaryrefslogblamecommitdiff
path: root/ast.c
blob: b76790e7b103dd627ceb436cea4d1bc5537f3830 (plain) (tree)
1
2
3
4
5
6
7
8
9

                   






                                                  





















                                         











                                                                          
                                


                                           
                  
                                     
      





                                

                                                    
     
                   

                    
                       



















                                           
                                           



                                 
                          



















































                                                               
                       




                                                           



                                      
                      


                             




                                                                                      





                                     
                          
                      
                     







                                                            



                                
                                  
                            






                                                                   



                                    
                        
                       






                                                                



                                    
                             
                       




                            





                                               


                                         

                                          



                                             

                                                  
                                             


                                                     


                                                   
                                                      

                                            









                                                          
                                                          




                                                              
                                          
                                            
                                      


                        
                  
                   
                               


































































                                                    
                                        


























                                                     





                         
                      

                                            


                     
                                                     
                                            
     


                  
                                          
                                                       

                                              
                             
                                     
     
                         

 




                                                   
                                                       
            

                                                          











                                               

             






                                                
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include "ast.h"
#include "cibic.tab.h"
#define NEW_CNODE ((CNode *)malloc(sizeof(CNode)))

CNode *ast_root;

void cnode_reverse_chd(CNode *node) {
    static CNode *chdn[MAX_CHDN];
    CNode *p;
    int n = 0;
    for (p = node->chd; p; p = p->next)
        cnode_reverse_chd(p);
    for (p = node->chd; p; p = p->next)
        chdn[n++] = p;
    if (n)
    {
        node->chd = chdn[--n];
        for (; n; n--)
            chdn[n]->next = chdn[n - 1];
        chdn[0]->next = NULL;
    }
}

CNode *cnode_create_ast(CNode *wrapped) {
    cnode_reverse_chd(wrapped);
    return wrapped;
}

CNode *cnode_create_nop()