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.33
26 * Terence Parr
27 * Parr Research Corporation
28 * with Purdue University and AHPCRC, University of Minnesota
29 * 1989-2000
30 */
31
32#ifndef ZZAST_H
33#define ZZAST_H
34
35#define zzastOvfChk														\
36			if ( zzast_sp <= 0 )                                        \
37            {                                                           \
38                fprintf(stderr, zzStackOvfMsg, __FILE__, __LINE__);    	\
39                exit(PCCTS_EXIT_FAILURE);                                               \
40            }
41
42#ifndef USER_DEFINED_AST
43#ifndef AST_FIELDS
44#define AST_FIELDS
45#endif
46
47typedef struct _ast {
48            struct _ast *right, *down;
49#ifdef zzAST_DOUBLE
50            struct _ast *left, *up;
51#endif
52            AST_FIELDS
53} AST;
54
55#else
56
57#ifdef zzAST_DOUBLE
58#define AST_REQUIRED_FIELDS   struct _ast *right, *down, *left, *up;
59#else
60#define AST_REQUIRED_FIELDS   struct _ast *right, *down;
61#endif
62
63#endif
64
65
66/* N o d e  a c c e s s  m a c r o s */
67#define zzchild(t)		(((t)==NULL)? (AST *) NULL:(t->down))   /* MR19 */
68#define zzsibling(t)	(((t)==NULL)? (AST *) NULL:(t->right))  /* MR19 */
69
70
71/* define global variables needed by #i stack */
72#define zzASTgvars												\
73	AST *zzastStack[ZZAST_STACKSIZE];							\
74	int zzast_sp = ZZAST_STACKSIZE;
75
76#define zzASTVars	AST *_ast = NULL, *_sibling = NULL, *_tail = NULL
77#define zzSTR		( (_tail==NULL)?(&_sibling):(&(_tail->right)) )
78#define zzastCur	(zzastStack[zzast_sp])
79#define zzastArg(i)	(zzastStack[zztsp-i])
80#define zzastPush(p) zzastOvfChk; zzastStack[--zzast_sp] = p;
81#define zzastDPush	--zzast_sp
82#define zzastMARK	zztsp=zzast_sp;		/* Save state of stack */
83#define zzastREL	zzast_sp=zztsp;		/* Return state of stack */
84#define zzrm_ast	{zzfree_ast(*_root); _tail = _sibling = (*_root)=NULL;}
85
86extern int zzast_sp;
87extern AST *zzastStack[];
88
89/* MR26 */
90
91#ifdef PCCTS_USE_STDARG
92AST *zztmake(AST *, ...);
93#else
94AST *zztmake();
95#endif
96
97#ifdef __USE_PROTOS
98void zzlink(AST **, AST **, AST **);
99void zzsubchild(AST **, AST **, AST **);
100void zzsubroot(AST **, AST **, AST **);
101void zzpre_ast(AST *, void (*)(AST *), void (*)(AST *), void (*)(AST *));
102void zzfree_ast(AST *);
103AST *zzdup_ast(AST *);
104void zztfree(AST *);
105void zzdouble_link(AST *, AST *, AST *);
106AST *zzastnew(void);
107
108#else
109
110void zzlink();
111AST *zzastnew();
112void zzsubchild();
113void zzsubroot();
114void zzpre_ast();
115void zzfree_ast();
116AST *zzdup_ast();
117void zztfree();
118void zzdouble_link();
119#endif
120
121#endif
122