4 * $Id: syn.h,v 1.6 95/09/26 12:58:32 parrt Exp $
7 * This file includes definitions and macros associated with syntax diagrams
11 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
12 * Set (PCCTS) -- PCCTS is in the public domain. An individual or
13 * company may do whatever they wish with source code distributed with
14 * PCCTS or the code generated by PCCTS, including the incorporation of
15 * PCCTS, or its output, into commerical software.
17 * We encourage users to develop software with PCCTS. However, we do ask
18 * that credit is given to us for developing PCCTS. By "credit",
19 * we mean that if you incorporate our source code into one of your
20 * programs (commercial product, research project, or otherwise) that you
21 * acknowledge this fact somewhere in the documentation, research report,
22 * etc... If you like PCCTS and have developed a nice tool with the
23 * output, please mention that you developed it using PCCTS. In
24 * addition, we ask that this header remain intact in our source code.
25 * As long as these guidelines are kept, we expect to continue enhancing
26 * this system and expect to make other tools available as they are
31 * Parr Research Corporation
32 * with Purdue University and AHPCRC, University of Minnesota
36 #define NumNodeTypes 4
37 #define NumJuncTypes 9
39 /* List the different node types */
45 /* Different types of junctions */
51 #define Generic 6 /* just a junction--no unusual characteristics */
58 #define TreeBlockAllocSize 500
59 #define JunctionBlockAllocSize 200
60 #define ActionBlockAllocSize 50
61 #define RRefBlockAllocSize 100
62 #define TokenBlockAllocSize 100
69 /* note that 'right' is used by the tree node allocator as a ptr for linked list */
70 typedef struct _tree {
71 struct _tree *down, *right;
74 int rk; /* if token==EpToken, => how many more tokens req'd */
75 struct _tree *tref; /* if token==TREE_REF */
76 set sref; /* if token==SET */
83 /* a predicate is defined to be a predicate action and a token tree with
84 * context info (if used); later, this struct may include the
85 * "hoisting distance" when we hoist past tokens.
87 * A tree is used to indicate && vs ||
93 * indicates p && (q||r).
95 * If expr is PRED_AND_LIST or PRED_OR_LIST, then it's an operation node
96 * and indicates the start of an && or || list.
99 typedef struct _Predicate {
100 struct _Predicate *down, *right; /* these have to be first */
101 struct _Predicate *up, *left; /* doubly-link me */
103 Tree *tcontext; /* used if lookahead depth of > one is needed (tree) */
104 int k; /* lookahead depth for this tcontext */
105 set scontext[2];/* used if lookahead depth of one is needed (set) */
106 /* scontext[0] is not used; only needed so genExprSets()
107 routine works (it expects an array)
109 set completion; /* which lookahead depths are required to complete tcontext? */
111 ActionNode *source; /* where did this predicate come from? */
113 struct _anode *source; /* where did this predicate come from? */
117 typedef struct _ExceptionHandler {
122 typedef struct _ExceptionGroup {
123 struct _ListNode *handlers; /* list of ExceptionHandler's */
124 char *label; /* label==""; implies not attached to any
125 * particular rule ref.
127 char *altID; /* which alt did it come from (blk#:alt#) */
131 #define TokenString(_i) ((TokenInd!=NULL)?TokenStr[TokenInd[_i]]:TokenStr[_i])
132 #define ExprString(_i) ((TokenInd!=NULL)?ExprStr[TokenInd[_i]]:ExprStr[_i])
135 /* M e s s a g e P a s s i n g T o N o d e s */
138 * assumes a 'Junction *r' exists. This macro calls a function with
139 * the pointer to the node to operate on and a pointer to the rule
140 * in which it is enclosed.
142 #define TRANS(p) {if ( (p)==NULL ) fatal("TRANS: NULL object"); \
143 if ( (p)->ntype == nJunction ) (*(fpJTrans[((Junction *)(p))->jtype]))( p );\
144 else (*(fpTrans[(p)->ntype]))( p );}
146 #define PRINT(p) {if ( (p)==NULL ) fatal("PRINT: NULL object");\
147 (*(fpPrint[(p)->ntype]))( p );}
149 #define REACH(p,k,rk,a) {if ( (p)==NULL ) fatal("REACH: NULL object");\
150 (a) = (*(fpReach[(p)->ntype]))( p, k, rk );}
152 #define TRAV(p,k,rk,a) {if ( (p)==NULL ) {\
153 if ( ContextGuardTRAV ) (a)=NULL; \
154 else fatal("TRAV: NULL object");\
156 else (a) = (*(fpTraverse[(p)->ntype]))( p, k, rk );}
159 #define TRAV(p,k,rk,a) {if ( (p)==NULL ) fatal("TRAV: NULL object");\
160 (a) = (*(fpTraverse[(p)->ntype]))( p, k, rk );}
163 /* All syntax diagram nodes derive from Node -- superclass
169 char *rname; /* what rule does this element live in? */
170 int file; /* index in FileStr */
171 int line; /* line number that element occurs on */
174 typedef struct _node {
176 char *rname; /* what rule does this element live in? */
177 int file; /* index in FileStr */
178 int line; /* line number that element occurs on */
183 class ActionNode : public Node {
186 typedef struct _anode {
188 char *rname; /* what rule does this action live in? */
189 int file; /* index in FileStr (name of file with action) */
190 int line; /* line number that action occurs on */
194 int is_predicate; /* true if action is a <<...>>? predicate action */
195 int done; /* don't dump if action dumped (used for predicates) */
196 int init_action; /* is this the 1st action of 1st prod of block? */
197 char *pred_fail; /* what to do/print when predicate fails */
198 Predicate *guardpred; /* if '(context)? =>' was present, already done */
199 unsigned char frmwarned;/* have we dumped a warning for pred yet? */
200 unsigned char ctxwarned;/* have we dumped a warning for pred yet? */
208 class TokNode : public Node {
211 typedef struct _toknode {
213 char *rname; /* name of rule it's in */
214 int file; /* index in FileStr (name of file with rule) */
215 int line; /* line number that token occurs on */
219 int astnode; /* leaf/root/excluded (used to build AST's) */
220 unsigned char label;/* token label or expression ? */
221 unsigned char remapped;
222 /* used if token id's are forced to certain positions;
223 * a function walks the tree reassigning token numbers */
224 unsigned char upper_range;
225 /* used only if Token is of type T1..T2; in this case,
226 * use token..upper_range as the range; else
227 * upper_range must be 0 */
228 unsigned char wild_card;
229 /* indicates that the token is the "." wild-card;
230 * field token is ignored if wild_card is set
232 unsigned int elnum; /* element number within the alternative */
234 Junction *altstart; /* pointer to node that starts alt */
236 struct _junct *altstart; /* pointer to node that starts alt */
238 struct _TCnode *tclass; /* token class if tokclass ref */
239 set tset; /* set of tokens represented by meta token */
240 char *el_label; /* el_label:toknode */
241 unsigned char complement; /* complement the set? */
242 ExceptionGroup *ex_group; /* any exception[el_label] attached? */
243 unsigned char use_def_MT_handler;
251 class RuleRefNode : public Node {
254 typedef struct _rrnode {
256 char *rname; /* name of rule it's in */
257 int file; /* index in FileStr (name of file with rule)
259 int line; /* line number that rule ref occurs on */
262 char *text; /* reference to which rule */
263 char *parms; /* point to parameters of rule invocation
265 char *assign; /* point to left-hand-side of assignment
267 int linked; /* Has a FoLink already been established? */
268 int astnode; /* excluded? (used to build AST's) */
269 unsigned int elnum; /* element number within the alternative */
273 struct _junct *altstart;
275 char *el_label; /* el_label:rrnode */
276 ExceptionGroup *ex_group; /* any exception[el_label] attached? */
284 class Junction : public Node {
287 typedef struct _junct {
289 char *rname; /* name of rule junction is in */
290 int file; /* index in FileStr (name of file with rule)
292 int line; /* line number that rule occurs on */
294 char ignore; /* used by FIRST computation to ignore
295 empty alt added for the (...)+ blks */
296 char visited; /* used by recursive routines to avoid
297 infinite recursion */
298 char pvisited; /* used by print routines to avoid
299 infinite recursion */
300 char fvisited; /* used by FoLink() to avoid
301 infinite recursion */
302 char *lock; /* used by REACH to track infinite recursion */
303 char *pred_lock; /* used by find_predicates to track infinite recursion */
304 int altnum; /* used in subblocks. altnum==0 means not an
306 int jtype; /* annotation for code-gen/FIRST/FOLLOW.
309 Junction *end; /* pointer to node with EndBlk in it
310 if blk == a block type */
312 struct _junct *end; /* pointer to node with EndBlk in it
313 if blk == a block type */
316 int halt; /* never move past a junction with halt==TRUE */
317 char *pdecl; /* point to declaration of parameters on rule
319 char *parm; /* point to parameter of block invocation
321 int predparm; /* indicates that the 'parm' is a predicate
322 * to be used in the while loop generated
324 char *ret; /* point to return type of rule (if present) */
325 char *erraction; /* point to error action (if present) */
326 int blockid; /* this is a unique ID */
327 char *exception_label; /* goto label for this alt */
328 set *fset; /* used for code generation */
329 Tree *ftree; /* used for code generation */
330 Predicate *predicate;/* predicate that can be used to disambiguate */
331 char guess; /* true if (...)? block */
332 char approx; /* limit block to use linear approx lookahead? */
333 set tokrefs; /* if ith element of alt is tokref then i is member */
334 set rulerefs; /* if ith element of alt is rule ref then i is member */
335 struct _ListNode *exceptions; /* list of exceptions groups for rule */
336 struct _ListNode *el_labels; /* list of element labels for rule */
343 typedef struct { Node *left, *right; } Graph;