All pastes #957388 Raw Edit

Someone

public text v1 · immutable
#957388 ·published 2008-03-25 22:55 UTC
rendered paste body
/* struct.h */                                                                                                                                                                                                      
                                                                                                                                                                                                                    
/*   Example:                                                                                                                                                                                                       
 *   s-expression:                                                                                                                                                                                                  
 *       (+ 1 2 3 (* 3 4))                                                                                                                                                                                          
 *   equivalent s-expression, expressed as the data structure:                                                                                                                                                      
 *   (cons                                                                                                                                                                                                          
 *       '+                                                                                                                                                                                                         
 *       (cons                                                                                                                                                                                                      
 *           '1                                                                                                                                                                                                     
 *           (cons                                                                                                                                                                                                  
 *               '2                                                                                                                                                                                                 
 *               (cons                                                                                                                                                                                              
 *                   '3                                                                                                                                                                                             
 *                   (cons                                                                                                                                                                                          
 *                       '*                                                                                                                                                                                         
 *                       (cons                                                                                                                                                                                      
 *                           '3                                                                                                                                                                                     
 *                           '4))))))                                                                                                                                                                               
 *    equivalent binary tree:                                                                                                                                                                                       
 *       a                                                                                                                                                                                                          
 *      /                                                                                                                                                                                                           
 *     b                                                                                                                                                                                                            
 *    / \                                                                                                                                                                                                           
 *   +   c                                                                                                                                                                                                          
 *      / \                                                                                                                                                                                                         
 *     1   d                                                                                                                                                                                                        
 *        / \                                                                                                                                                                                                       
 *       2   e                                                                                                                                                                                                      
 *          / \                                                                                                                                                                                                     
 *         3   f                                                                                                                                                                                                    
 *            /                                                                                                                                                                                                     
 *           g                                                                                                                                                                                                      
 *          / \                                                                                                                                                                                                     
 *         *   h                                                                                                                                                                                                    
 *            / \                                                                                                                                                                                                   
 *           3   i                                                                                                                                                                                                  
 *              /                                                                                                                                                                                                   
 *             4                                                                                                                                                                                                    
 *  */                                                                                                                                                                                                              
                                                                                                                                                                                                                    
struct exp                                                                                                                                                                                                          
{                                                                                                                                                                                                                   
    enum { NIL, B_NODE, L_NODE } e;     /* If L_NODE, v should be null */                                                                                                                                           
    struct exp* car,            /* Points to the first element of a list */                                                                                                                                         
        * cdr;                  /* Points to the rest of the list */                                                                                                                                                
    char* v;                    /* If B_NODE, this should point somewhere */                                                                                                                                        
};                                                                                                                                                                                                                  
                                                                                                                                                                                                                    
void exp_init( struct exp* );                                                                                                                                                                                       
void exp_destroy( struct exp* );