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.h < prev    next >
C/C++ Source or Header  |  1996-03-22  |  4KB  |  110 lines

  1. /*
  2.  * Structure of a tree node.
  3.  */
  4.  
  5. typedef    struct node    *nodeptr;
  6. #define YYSTYPE nodeptr
  7.  
  8. union field {
  9.    long n_val;        /* integer-valued fields */
  10.    char *n_str;        /* string-valued fields */
  11.    nodeptr n_ptr;    /* subtree pointers */
  12.    };
  13.  
  14. struct node {
  15.    int n_type;            /* node type */
  16.    char *n_file;        /* name of file containing source program */
  17.    int n_line;            /* line number in source program */
  18.    int n_col;            /* column number in source program */
  19.    union field n_field[1];      /* variable-content fields */
  20.    };
  21.  
  22. #define NewNode(size) (struct node *)alloc((unsigned int)\
  23.     (sizeof(struct node) + (size-1) * sizeof(union field)))
  24.  
  25. /*
  26.  * Macros to access fields of parse tree nodes.
  27.  */
  28.  
  29. #define TType(t)        t->n_type
  30. #define File(t)        t->n_file
  31. #define Line(t)        t->n_line
  32. #define Col(t)        t->n_col
  33. #define Tree0(t)    t->n_field[0].n_ptr
  34. #define Tree1(t)    t->n_field[1].n_ptr
  35. #define Tree2(t)    t->n_field[2].n_ptr
  36. #define Tree3(t)    t->n_field[3].n_ptr
  37. #define Val0(t)        t->n_field[0].n_val
  38. #define Val1(t)        t->n_field[1].n_val
  39. #define Val2(t)        t->n_field[2].n_val
  40. #define Val3(t)        t->n_field[3].n_val
  41. #define Val4(t)        t->n_field[4].n_val
  42. #define Str0(t)        t->n_field[0].n_str
  43. #define Str1(t)        t->n_field[1].n_str
  44. #define Str2(t)        t->n_field[2].n_str
  45. #define Str3(t)        t->n_field[3].n_str
  46.  
  47. /*
  48.  * External declarations.
  49.  */
  50.  
  51. extern nodeptr yylval;        /* parser's current token value */
  52. extern struct node tok_loc;     /* "model" token holding current location */
  53.  
  54. /*
  55.  * Node types.
  56.  */
  57.  
  58. #define N_Activat     1        /* activation control structure */
  59. #define N_Alt         2        /* alternation operator */
  60. #define N_Augop         3        /* augmented operator */
  61. #define N_Bar         4        /* generator control structure */
  62. #define N_Binop         5        /* other binary operator */
  63. #define N_Break         6        /* break statement */
  64. #define N_Case         7        /* case statement */
  65. #define N_Ccls         8        /* case clause */
  66. #define N_Clist         9        /* list of case clauses */
  67. #define N_Conj        10        /* conjunction operator */
  68. #define N_Create    11        /* create control structure */
  69. #define N_Cset        12        /* cset literal */
  70. #define N_Elist        14        /* list of expressions */
  71. #define N_Empty        15        /* empty expression or statement */
  72. #define N_Field        16        /* record field reference */
  73. #define N_Id        17        /* identifier token */
  74. #define N_If        18        /* if-then-else statement */
  75. #define N_Int        19        /* integer literal */
  76. #define N_Invok        20        /* invocation */
  77. #define N_Key        21        /* keyword */
  78. #define N_Limit        22        /* LIMIT control structure */
  79. #define N_List        23        /* [ ... ] style list */
  80. #define N_Loop        24        /* while, until, every, or repeat */
  81. #define N_Not        25        /* not prefix control structure */
  82. #define N_Next        26        /* next statement */
  83. #define N_Op        27        /* operator token */
  84. #define N_Proc        28        /* procedure */
  85. #define N_Real        29        /* real literal */
  86. #define N_Res        30        /* reserved word token */
  87. #define N_Ret        31        /* fail, return, or succeed */
  88. #define N_Scan        32        /* scan-using statement */
  89. #define N_Sect        33        /* s[i:j] (section) */
  90. #define N_Slist        34        /* list of statements */
  91. #define N_Str        35        /* string literal */
  92. #define N_Susp        36        /* suspend statement */
  93. #define N_To        37        /* TO operator */
  94. #define N_ToBy        38        /* TO-BY operator */
  95. #define N_Unop        39        /* unary operator */
  96. #define N_Apply        40        /* procedure application */
  97.  
  98.  
  99. /*
  100.  * Macros for constructing basic nodes.
  101.  */
  102.  
  103. #define CsetNode(a,b)        i_str_leaf(N_Cset,&tok_loc,a,b) 
  104. #define IdNode(a)        c_str_leaf(N_Id,&tok_loc,a) 
  105. #define IntNode(a)        c_str_leaf(N_Int,&tok_loc,a) 
  106. #define OpNode(a)        int_leaf(N_Op,&tok_loc,optab[a].tok.t_type) 
  107. #define RealNode(a)        c_str_leaf(N_Real,&tok_loc,a) 
  108. #define ResNode(a)        int_leaf(N_Res,&tok_loc,a) 
  109. #define StrNode(a,b)        i_str_leaf(N_Str,&tok_loc,a,b) 
  110.