home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / icont / tree.c < prev    next >
C/C++ Source or Header  |  1996-03-22  |  3KB  |  176 lines

  1. /*
  2.  * tree.c -- functions for constructing parse trees
  3.  */
  4.  
  5. #include "::h:gsupport.h"
  6. #include "tproto.h"
  7. #include "tree.h"
  8.  
  9. /*
  10.  *  tree[1-6] construct parse tree nodes with specified values.
  11.  *   Parameters a and b are line and column information,
  12.  *   while parameters c through f are values to be assigned to n_field[0-3].
  13.  *   Note that this could be done with a single routine; a separate routine
  14.  *   for each node size is used for speed and simplicity.
  15.  */
  16.  
  17. nodeptr tree1(type)
  18. int type;
  19.    {
  20.    register nodeptr t;
  21.  
  22.    t = NewNode(0);
  23.    t->n_type = type;
  24.    return t;
  25.    }
  26.  
  27. nodeptr tree2(type, loc_model)
  28. int type;
  29. nodeptr loc_model;
  30.    {
  31.    register nodeptr t;
  32.  
  33.    t = NewNode(0);
  34.    t->n_type = type;
  35.    t->n_file = loc_model->n_file;
  36.    t->n_line = loc_model->n_line;
  37.    t->n_col = loc_model->n_col;
  38.    return t;
  39.    }
  40.  
  41. nodeptr tree3(type, loc_model, c)
  42. int type;
  43. nodeptr loc_model;
  44. nodeptr c;
  45.    {
  46.    register nodeptr t;
  47.  
  48.    t = NewNode(1);
  49.    t->n_type = type;
  50.    t->n_file = loc_model->n_file;
  51.    t->n_line = loc_model->n_line;
  52.    t->n_col = loc_model->n_col;
  53.    t->n_field[0].n_ptr = c;
  54.    return t;
  55.    }
  56.  
  57. nodeptr tree4(type, loc_model, c, d)
  58. int type;
  59. nodeptr loc_model;
  60. nodeptr c, d;
  61.    {
  62.    register nodeptr t;
  63.  
  64.    t = NewNode(2);
  65.    t->n_type = type;
  66.    t->n_file = loc_model->n_file;
  67.    t->n_line = loc_model->n_line;
  68.    t->n_col = loc_model->n_col;
  69.    t->n_field[0].n_ptr = c;
  70.    t->n_field[1].n_ptr = d;
  71.    return t;
  72.    }
  73.  
  74. nodeptr tree5(type, loc_model, c, d, e)
  75. int type;
  76. nodeptr loc_model;
  77. nodeptr c, d, e;
  78.    {
  79.    register nodeptr t;
  80.  
  81.    t = NewNode(3);
  82.    t->n_type = type;
  83.    t->n_file = loc_model->n_file;
  84.    t->n_line = loc_model->n_line;
  85.    t->n_col = loc_model->n_col;
  86.    t->n_field[0].n_ptr = c;
  87.    t->n_field[1].n_ptr = d;
  88.    t->n_field[2].n_ptr = e;
  89.    return t;
  90.    }
  91.  
  92. nodeptr tree6(type, loc_model, c, d, e, f)
  93. int type;
  94. nodeptr loc_model;
  95. nodeptr c, d, e, f;
  96.    {
  97.    register nodeptr t;
  98.  
  99.    t = NewNode(4);
  100.    t->n_type = type;
  101.    t->n_file = loc_model->n_file;
  102.    t->n_line = loc_model->n_line;
  103.    t->n_col = loc_model->n_col;
  104.    t->n_field[0].n_ptr = c;
  105.    t->n_field[1].n_ptr = d;
  106.    t->n_field[2].n_ptr = e;
  107.    t->n_field[3].n_ptr = f;
  108.    return t;
  109.    }
  110.  
  111. nodeptr buildarray(a,lb,e,rb)
  112. nodeptr a, lb, e, rb;
  113.    {
  114.    register nodeptr t, t2;
  115.    if (e->n_type == N_Elist) {
  116.       t2 = int_leaf(lb->n_type, lb, (int)lb->n_field[0].n_val);
  117.       t = tree5(N_Binop, t2, t2, buildarray(a,lb,e->n_field[0].n_ptr,rb),
  118.         e->n_field[1].n_ptr);
  119.       free(e);
  120.       }
  121.    else
  122.       t = tree5(N_Binop, lb, lb, a, e);
  123.    return t;
  124.    }
  125.  
  126. nodeptr int_leaf(type, loc_model, c)
  127. int type;
  128. nodeptr loc_model;
  129. int c;
  130.    {
  131.    register nodeptr t;
  132.  
  133.    t = NewNode(1);
  134.    t->n_type = type;
  135.    t->n_file = loc_model->n_file;
  136.    t->n_line = loc_model->n_line;
  137.    t->n_col = loc_model->n_col;
  138.    t->n_field[0].n_val = c;
  139.    return t;
  140.    }
  141.  
  142. nodeptr c_str_leaf(type, loc_model, c)
  143. int type;
  144. nodeptr loc_model;
  145. char *c;
  146.    {
  147.    register nodeptr t;
  148.  
  149.    t = NewNode(1);
  150.    t->n_type = type;
  151.    t->n_file = loc_model->n_file;
  152.    t->n_line = loc_model->n_line;
  153.    t->n_col = loc_model->n_col;
  154.    t->n_field[0].n_str = c;
  155.    return t;
  156.    }
  157.  
  158. nodeptr i_str_leaf(type, loc_model, c, d)
  159. int type;
  160. nodeptr loc_model;
  161. char *c;
  162. int d;
  163.    {
  164.    register nodeptr t;
  165.  
  166.    t = NewNode(2);
  167.    t->n_type = type;
  168.    t->n_file = loc_model->n_file;
  169.    t->n_line = loc_model->n_line;
  170.    t->n_col = loc_model->n_col;
  171.    t->n_field[0].n_str = c;
  172.    t->n_field[1].n_val = d;
  173.    return t;
  174.    }
  175.  
  176.