home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pccts1.zip / H / AST.H < prev    next >
C/C++ Source or Header  |  1993-09-01  |  3KB  |  104 lines

  1. /* Abstract syntax tree
  2.  *
  3.  * Macros, definitions
  4.  *
  5.  * SOFTWARE RIGHTS
  6.  *
  7.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  8.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  9.  * company may do whatever they wish with source code distributed with
  10.  * PCCTS or the code generated by PCCTS, including the incorporation of
  11.  * PCCTS, or its output, into commerical software.
  12.  * 
  13.  * We encourage users to develop software with PCCTS.  However, we do ask
  14.  * that credit is given to us for developing PCCTS.  By "credit",
  15.  * we mean that if you incorporate our source code into one of your
  16.  * programs (commercial product, research project, or otherwise) that you
  17.  * acknowledge this fact somewhere in the documentation, research report,
  18.  * etc...  If you like PCCTS and have developed a nice tool with the
  19.  * output, please mention that you developed it using PCCTS.  In
  20.  * addition, we ask that this header remain intact in our source code.
  21.  * As long as these guidelines are kept, we expect to continue enhancing
  22.  * this system and expect to make other tools available as they are
  23.  * completed.
  24.  *
  25.  * ANTLR 1.10
  26.  * Terence Parr
  27.  * Purdue University
  28.  * 1989-1993
  29.  */
  30.  
  31. #ifndef ZZAST_H
  32. #define ZZAST_H
  33.  
  34. #define zzastOvfChk                                                        \
  35.             if ( zzast_sp <= 0 )                                        \
  36.             {                                                           \
  37.                 fprintf(stderr, zzStackOvfMsg, __FILE__, __LINE__);        \
  38.                 exit(-1);                                               \
  39.             }
  40.  
  41. #ifndef AST_FIELDS
  42. #define AST_FIELDS
  43. #endif
  44.  
  45. typedef struct _ast {
  46.             struct _ast *right, *down;
  47. #ifdef zzAST_DOUBLE
  48.             struct _ast *left, *up;
  49. #endif
  50.             AST_FIELDS
  51.         } AST;
  52.  
  53.  
  54. /* N o d e  a c c e s s  m a c r o s */
  55. #define zzchild(t)        (((t)==NULL)?NULL:(t->down))
  56. #define zzsibling(t)    (((t)==NULL)?NULL:(t->right))
  57.  
  58.  
  59. /* define global variables needed by #i stack */
  60. #define zzASTgvars                                                \
  61.     AST *zzastStack[ZZAST_STACKSIZE];                            \
  62.     int zzast_sp = ZZAST_STACKSIZE;
  63.  
  64. #define zzASTVars    AST *_ast = NULL, *_sibling = NULL, *_tail = NULL
  65. #define zzSTR        ( (_tail==NULL)?(&_sibling):(&(_tail->right)) )
  66. #define zzastCur    (zzastStack[zzast_sp])
  67. #define zzastArg(i)    (zzastStack[zztsp-i])
  68. #define zzastPush(p) zzastOvfChk; zzastStack[--zzast_sp] = p;
  69. #define zzastDPush    --zzast_sp
  70. #define zzastMARK    zztsp=zzast_sp;        /* Save state of stack */
  71. #define zzastREL    zzast_sp=zztsp;        /* Return state of stack */
  72. #define zzrm_ast    {zzfree_ast(*_root); _tail = _sibling = (*_root)=NULL;}
  73.  
  74. extern int zzast_sp;
  75. extern AST *zzastStack[];
  76.  
  77. #ifdef __STDC__
  78. void zzlink(AST **, AST **, AST **);
  79. AST *zzastnew();
  80. void zzsubchild(AST **, AST **, AST **);
  81. void zzsubroot(AST **, AST **, AST **);
  82. void zzpre_ast(AST *, void (*)(), void (*)(), void (*)());
  83. void zzfree_ast(AST *);
  84. AST *zztmake(AST *, ...);
  85. AST *zzdup_ast(AST *);
  86. void zztfree(AST *);
  87. void zzdouble_link(AST *, AST *, AST *);
  88.  
  89. #else
  90.  
  91. void zzlink();
  92. AST *zzastnew();
  93. void zzsubchild();
  94. void zzsubroot();
  95. void zzpre_ast();
  96. void zzfree_ast();
  97. AST *zztmake();
  98. AST *zzdup_ast();
  99. void zztfree();
  100. void zzdouble_link();
  101. #endif
  102.  
  103. #endif
  104.