home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / icon / dos / src / icont / tree.h < prev    next >
C/C++ Source or Header  |  1992-02-10  |  4KB  |  111 lines

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