]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | /*\r |
2 | * syn.h\r | |
3 | *\r | |
4 | * This file includes definitions and macros associated with syntax diagrams\r | |
5 | *\r | |
6 | * SOFTWARE RIGHTS\r | |
7 | *\r | |
8 | * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r | |
9 | * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r | |
10 | * company may do whatever they wish with source code distributed with\r | |
11 | * PCCTS or the code generated by PCCTS, including the incorporation of\r | |
12 | * PCCTS, or its output, into commerical software.\r | |
13 | *\r | |
14 | * We encourage users to develop software with PCCTS. However, we do ask\r | |
15 | * that credit is given to us for developing PCCTS. By "credit",\r | |
16 | * we mean that if you incorporate our source code into one of your\r | |
17 | * programs (commercial product, research project, or otherwise) that you\r | |
18 | * acknowledge this fact somewhere in the documentation, research report,\r | |
19 | * etc... If you like PCCTS and have developed a nice tool with the\r | |
20 | * output, please mention that you developed it using PCCTS. In\r | |
21 | * addition, we ask that this header remain intact in our source code.\r | |
22 | * As long as these guidelines are kept, we expect to continue enhancing\r | |
23 | * this system and expect to make other tools available as they are\r | |
24 | * completed.\r | |
25 | *\r | |
26 | * ANTLR 1.33\r | |
27 | * Terence Parr\r | |
28 | * Parr Research Corporation\r | |
29 | * with Purdue University and AHPCRC, University of Minnesota\r | |
30 | * 1989-2001\r | |
31 | */\r | |
32 | \r | |
33 | #include "set.h"\r | |
34 | \r | |
35 | #define NumNodeTypes 4\r | |
36 | #define NumJuncTypes 9\r | |
37 | \r | |
38 | /* List the different node types */\r | |
39 | #define nJunction 1\r | |
40 | #define nRuleRef 2\r | |
41 | #define nToken 3\r | |
42 | #define nAction 4\r | |
43 | \r | |
44 | /* Different types of junctions */\r | |
45 | #define aSubBlk 1\r | |
46 | #define aOptBlk 2\r | |
47 | #define aLoopBlk 3\r | |
48 | #define EndBlk 4\r | |
49 | #define RuleBlk 5\r | |
50 | #define Generic 6 /* just a junction--no unusual characteristics */\r | |
51 | #define EndRule 7\r | |
52 | #define aPlusBlk 8\r | |
53 | #define aLoopBegin 9\r | |
54 | \r | |
55 | typedef int NodeType;\r | |
56 | \r | |
57 | #define TreeBlockAllocSize 500\r | |
58 | #define JunctionBlockAllocSize 200\r | |
59 | #define ActionBlockAllocSize 50\r | |
60 | #define RRefBlockAllocSize 100\r | |
61 | #define TokenBlockAllocSize 100\r | |
62 | \r | |
63 | #ifdef __cplusplus\r | |
64 | class ActionNode;\r | |
65 | class Junction;\r | |
66 | #endif\r | |
67 | \r | |
68 | /* note that 'right' is used by the tree node allocator as a ptr for linked list */\r | |
69 | typedef struct _tree {\r | |
70 | struct _tree *down, *right;\r | |
71 | int token;\r | |
72 | union {\r | |
73 | int rk; /* if token==EpToken, => how many more tokens req'd */\r | |
74 | struct _tree *tref; /* if token==TREE_REF */\r | |
75 | set sref; /* if token==SET */\r | |
76 | } v;\r | |
77 | #ifdef TREE_DEBUG\r | |
78 | int in_use;\r | |
79 | int seq;\r | |
80 | #endif\r | |
81 | } Tree;\r | |
82 | \r | |
83 | \r | |
84 | /* a predicate is defined to be a predicate action and a token tree with\r | |
85 | * context info (if used); later, this struct may include the\r | |
86 | * "hoisting distance" when we hoist past tokens.\r | |
87 | *\r | |
88 | * A tree is used to indicate && vs ||\r | |
89 | *\r | |
90 | * p\r | |
91 | * |\r | |
92 | * q--r\r | |
93 | *\r | |
94 | * indicates p && (q||r).\r | |
95 | *\r | |
96 | * If expr is PRED_AND_LIST or PRED_OR_LIST, then it's an operation node\r | |
97 | * and indicates the start of an && or || list.\r | |
98 | */\r | |
99 | \r | |
100 | typedef struct _Predicate {\r | |
101 | struct _Predicate *down, *right; /* these have to be first */\r | |
102 | struct _Predicate *up, *left; /* doubly-link me */\r | |
103 | char *expr;\r | |
104 | Tree *tcontext; /* used if lookahead depth of > one is needed (tree) */\r | |
105 | int k; /* lookahead depth for this tcontext */\r | |
106 | set scontext[2];/* used if lookahead depth of one is needed (set) */\r | |
107 | /* scontext[0] is not used; only needed so genExprSets()\r | |
108 | routine works (it expects an array)\r | |
109 | */\r | |
110 | set completionTree; /* which lookahead depths are required to complete tcontext? */\r | |
111 | set completionSet; /* MR10 separate completion set for sets and trees */\r | |
112 | struct _PredEntry *predEntry; /* MR11 */\r | |
113 | \r | |
114 | #ifdef __cplusplus\r | |
115 | ActionNode *source; /* where did this predicate come from? */\r | |
116 | #else\r | |
117 | struct _anode *source; /* where did this predicate come from? */\r | |
118 | #endif\r | |
119 | \r | |
120 | char cloned; /* MR10 don't want to free original guard pred */\r | |
121 | char redundant; /* MR10 predicate tree simplification */\r | |
122 | char ampersandStyle; /* MR10 (g)? && <<p>>? */\r | |
123 | char inverted; /* MR11 ! predName */\r | |
124 | char isConst; /* MR11 */\r | |
125 | char constValue; /* MR11 */\r | |
126 | char conflictReported; /* MR11 */\r | |
127 | \r | |
128 | set plainSet; /* MR12b */\r | |
129 | \r | |
130 | /*** remember to change new_predicate() and predicate_dup() when changing this ***/\r | |
131 | \r | |
132 | } Predicate;\r | |
133 | \r | |
134 | typedef struct _ExceptionHandler {\r | |
135 | char *signalname;\r | |
136 | char *action;\r | |
137 | } ExceptionHandler;\r | |
138 | \r | |
139 | typedef struct _ExceptionGroup {\r | |
140 | struct _ListNode *handlers; /* list of ExceptionHandler's */\r | |
141 | char *label; /* label==""; implies not attached to any\r | |
142 | * particular rule ref.\r | |
143 | */\r | |
144 | char *altID; /* which alt did it come from (blk#:alt#) */\r | |
145 | \r | |
146 | struct _ExceptionGroup *pendingLink; /* for alternative EG MR7 */\r | |
147 | struct _ExceptionGroup *outerEG; /* for alternative EG MR7 */\r | |
148 | struct _LabelEntry *labelEntry; /* for alternative EG MR7 */\r | |
149 | int forRule; /* MR7 */\r | |
150 | int used; /* MR7 */\r | |
151 | } ExceptionGroup ;\r | |
152 | \r | |
153 | \r | |
154 | #define TokenString(_i) ((TokenInd!=NULL)?TokenStr[TokenInd[_i]]:TokenStr[_i])\r | |
155 | #define ExprString(_i) ((TokenInd!=NULL)?ExprStr[TokenInd[_i]]:ExprStr[_i])\r | |
156 | \r | |
157 | \r | |
158 | /* M e s s a g e P a s s i n g T o N o d e s */\r | |
159 | \r | |
160 | /*\r | |
161 | * assumes a 'Junction *r' exists. This macro calls a function with\r | |
162 | * the pointer to the node to operate on and a pointer to the rule\r | |
163 | * in which it is enclosed.\r | |
164 | */\r | |
165 | #define TRANS(p) {if ( (p)==NULL ) fatal("TRANS: NULL object"); \\r | |
166 | if ( (p)->ntype == nJunction ) (*(fpJTrans[((Junction *)(p))->jtype]))( p );\\r | |
167 | else (*(fpTrans[(p)->ntype]))( p );}\r | |
168 | \r | |
169 | #define PRINT(p) {if ( (p)==NULL ) fatal("PRINT: NULL object");\\r | |
170 | (*(fpPrint[(p)->ntype]))( p );}\r | |
171 | \r | |
172 | #define REACH(p,k,rk,a) {if ( (p)==NULL ) fatal("REACH: NULL object");\\r | |
173 | (a) = (*(fpReach[(p)->ntype]))( p, k, rk );}\r | |
174 | \r | |
175 | #define TRAV(p,k,rk,a) {if ( (p)==NULL ) {\\r | |
176 | if ( ContextGuardTRAV ) (a)=NULL; \\r | |
177 | else fatal("TRAV: NULL object");\\r | |
178 | } \\r | |
179 | else (a) = (*(fpTraverse[(p)->ntype]))( p, k, rk );}\r | |
180 | \r | |
181 | /**\r | |
182 | *** #define TRAV(p,k,rk,a) {if ( (p)==NULL ) fatal("TRAV: NULL object");\\r | |
183 | *** (a) = (*(fpTraverse[(p)->ntype]))( p, k, rk );}\r | |
184 | **/\r | |
185 | \r | |
186 | /* All syntax diagram nodes derive from Node -- superclass\r | |
187 | */\r | |
188 | #ifdef __cplusplus\r | |
189 | class Node {\r | |
190 | public:\r | |
191 | NodeType ntype;\r | |
192 | char *rname; /* what rule does this element live in? */\r | |
193 | int file; /* index in FileStr */\r | |
194 | int line; /* line number that element occurs on */\r | |
195 | };\r | |
196 | #else\r | |
197 | typedef struct _node {\r | |
198 | NodeType ntype;\r | |
199 | char *rname; /* what rule does this element live in? */\r | |
200 | int file; /* index in FileStr */\r | |
201 | int line; /* line number that element occurs on */\r | |
202 | } Node;\r | |
203 | #endif\r | |
204 | \r | |
205 | #ifdef __cplusplus\r | |
206 | class ActionNode : public Node {\r | |
207 | public:\r | |
208 | #else\r | |
209 | typedef struct _anode {\r | |
210 | NodeType ntype;\r | |
211 | char *rname; /* what rule does this action live in? */\r | |
212 | int file; /* index in FileStr (name of file with action) */\r | |
213 | int line; /* line number that action occurs on */\r | |
214 | #endif\r | |
215 | Node *next;\r | |
216 | char *action;\r | |
217 | int is_predicate; /* true if action is a <<...>>? predicate action */\r | |
218 | int done; /* don't dump if action dumped (used for predicates) */\r | |
219 | int init_action; /* is this the 1st action of 1st prod of block? */\r | |
220 | char *pred_fail; /* what to do/print when predicate fails */\r | |
221 | Predicate *guardpred; /* if '(context)? =>' was present, already done */\r | |
222 | unsigned char frmwarned;/* have we dumped a warning for pred yet? */\r | |
223 | unsigned char ctxwarned;/* have we dumped a warning for pred yet? */\r | |
224 | unsigned char predTooLong; /* MR10 have we dumped warning for pred yet */\r | |
225 | unsigned char noHoist; /* MR12 literally "noHoist" */\r | |
226 | Predicate *ampersandPred; /* MR10 (g)? && <<p>>? expr */\r | |
227 | #ifdef __cplusplus\r | |
228 | Junction *guardNodes; /* MR11 */\r | |
229 | #else\r | |
230 | struct _junct *guardNodes; /* MR11 */\r | |
231 | #endif\r | |
232 | struct _PredEntry *predEntry; /* MR11 */\r | |
233 | int inverted; /* MR11 <<!predSymbol>>? */\r | |
234 | #ifdef __cplusplus\r | |
235 | };\r | |
236 | #else\r | |
237 | } ActionNode;\r | |
238 | #endif\r | |
239 | \r | |
240 | #ifdef __cplusplus\r | |
241 | class TokNode : public Node {\r | |
242 | public:\r | |
243 | #else\r | |
244 | typedef struct _toknode {\r | |
245 | NodeType ntype;\r | |
246 | char *rname; /* name of rule it's in */\r | |
247 | int file; /* index in FileStr (name of file with rule) */\r | |
248 | int line; /* line number that token occurs on */\r | |
249 | #endif\r | |
250 | Node *next;\r | |
251 | int token;\r | |
252 | int astnode; /* leaf/root/excluded (used to build AST's) */\r | |
253 | unsigned char label;/* token label or expression ? */\r | |
254 | unsigned char remapped;\r | |
255 | /* used if token id's are forced to certain positions;\r | |
256 | * a function walks the tree reassigning token numbers */\r | |
257 | int upper_range; /* MR13 - was char */\r | |
258 | /* used only if Token is of type T1..T2; in this case,\r | |
259 | * use token..upper_range as the range; else\r | |
260 | * upper_range must be 0 */\r | |
261 | unsigned char wild_card;\r | |
262 | /* indicates that the token is the "." wild-card;\r | |
263 | * field token is ignored if wild_card is set\r | |
264 | */\r | |
265 | unsigned int elnum; /* element number within the alternative */\r | |
266 | #ifdef __cplusplus\r | |
267 | Junction *altstart; /* pointer to node that starts alt */\r | |
268 | #else\r | |
269 | struct _junct *altstart; /* pointer to node that starts alt */\r | |
270 | #endif\r | |
271 | struct _TCnode *tclass; /* token class if tokclass ref */\r | |
272 | set tset; /* set of tokens represented by meta token */\r | |
273 | char *el_label; /* el_label:toknode */\r | |
274 | unsigned char complement; /* complement the set? */\r | |
275 | ExceptionGroup *ex_group; /* any exception[el_label] attached? */\r | |
276 | unsigned char use_def_MT_handler;\r | |
277 | unsigned char label_used_in_semantic_pred; /* MR10 */\r | |
278 | #ifdef __cplusplus\r | |
279 | };\r | |
280 | #else\r | |
281 | } TokNode;\r | |
282 | #endif\r | |
283 | \r | |
284 | #ifdef __cplusplus\r | |
285 | class RuleRefNode : public Node {\r | |
286 | public:\r | |
287 | #else\r | |
288 | typedef struct _rrnode {\r | |
289 | NodeType ntype;\r | |
290 | char *rname; /* name of rule it's in */\r | |
291 | int file; /* index in FileStr (name of file with rule)\r | |
292 | it's in */\r | |
293 | int line; /* line number that rule ref occurs on */\r | |
294 | #endif\r | |
295 | Node *next;\r | |
296 | char *text; /* reference to which rule */\r | |
297 | char *parms; /* point to parameters of rule invocation\r | |
298 | (if present) */\r | |
299 | char *assign; /* point to left-hand-side of assignment\r | |
300 | (if any) */\r | |
301 | int linked; /* Has a FoLink already been established? */\r | |
302 | int astnode; /* excluded? (used to build AST's) */\r | |
303 | unsigned int elnum; /* element number within the alternative */\r | |
304 | #ifdef __cplusplus\r | |
305 | Junction *altstart;\r | |
306 | #else\r | |
307 | struct _junct *altstart;\r | |
308 | #endif\r | |
309 | char *el_label; /* el_label:rrnode */\r | |
310 | ExceptionGroup *ex_group; /* any exception[el_label] attached? */\r | |
311 | #ifdef __cplusplus\r | |
312 | };\r | |
313 | #else\r | |
314 | } RuleRefNode;\r | |
315 | #endif\r | |
316 | \r | |
317 | #ifdef __cplusplus\r | |
318 | class Junction : public Node {\r | |
319 | public:\r | |
320 | #else\r | |
321 | typedef struct _junct {\r | |
322 | NodeType ntype;\r | |
323 | char *rname; /* name of rule junction is in */\r | |
324 | int file; /* index in FileStr (name of file with rule)\r | |
325 | if blk == RuleBlk */\r | |
326 | int line; /* line number that rule occurs on */\r | |
327 | #endif\r | |
328 | int seq; /* MR10 sequence number */\r | |
329 | char ignore; /* used by FIRST computation to ignore\r | |
330 | empty alt added for the (...)+ blks */\r | |
331 | char visited; /* used by recursive routines to avoid\r | |
332 | infinite recursion */\r | |
333 | char pvisited; /* used by print routines to avoid\r | |
334 | infinite recursion */\r | |
335 | char fvisited; /* used by FoLink() to avoid\r | |
336 | infinite recursion */\r | |
337 | char *lock; /* used by REACH to track infinite recursion */\r | |
338 | char *pred_lock; /* used by find_predicates to track infinite recursion */\r | |
339 | int altnum; /* used in subblocks. altnum==0 means not an\r | |
340 | alt of subrule */\r | |
341 | int jtype; /* annotation for code-gen/FIRST/FOLLOW.\r | |
342 | Junction type */\r | |
343 | #ifdef __cplusplus\r | |
344 | Junction *end; /* pointer to node with EndBlk in it\r | |
345 | if blk == a block type */\r | |
346 | #else\r | |
347 | struct _junct *end; /* pointer to node with EndBlk in it\r | |
348 | if blk == a block type */\r | |
349 | #endif\r | |
350 | Node *p1, *p2;\r | |
351 | char halt; /* never move past a junction with halt==TRUE */ /* MR10 was int */\r | |
352 | char *pdecl; /* point to declaration of parameters on rule\r | |
353 | (if present) */\r | |
354 | char *parm; /* point to parameter of block invocation\r | |
355 | (if present) */\r | |
356 | char predparm; /* indicates that the 'parm' is a predicate\r | |
357 | * to be used in the while loop generated\r | |
358 | * for blocks */ /* MR10 was int */\r | |
359 | char *ret; /* point to return type of rule (if present) */\r | |
360 | char *erraction; /* point to error action (if present) */\r | |
361 | int blockid; /* this is a unique ID */\r | |
362 | char *exception_label; /* goto label for this alt */\r | |
363 | set *fset; /* used for code generation */\r | |
364 | Tree *ftree; /* used for code generation */\r | |
365 | Predicate *predicate;/* predicate that can be used to disambiguate */\r | |
366 | char guess; /* true if (...)? block */\r | |
367 | char alpha_beta_guess_end; /* MR14 1 => end block of guess sub block */\r | |
368 | Node *guess_analysis_point; /* MR14 */\r | |
369 | char approx; /* limit block to use linear approx lookahead? */\r | |
370 | set tokrefs; /* if ith element of alt is tokref then i is member */\r | |
371 | set rulerefs; /* if ith element of alt is rule ref then i is member */\r | |
372 | struct _ListNode *exceptions; /* list of exceptions groups for rule */\r | |
373 | struct _ListNode *el_labels; /* list of element labels for rule */\r | |
374 | ExceptionGroup *outerEG; /* MR7 */\r | |
375 | int curAltNum; /* MR7 */\r | |
376 | char* pFirstSetSymbol; /* #pragma FirstSetSymbol(Foo) MR21 */\r | |
377 | #ifdef __cplusplus\r | |
378 | Junction *pendingLink; /* MR7 */\r | |
379 | #else\r | |
380 | struct _junct *pendingLink; /* MR7 */\r | |
381 | #endif\r | |
382 | char overlap_warning; /* MR10 */\r | |
383 | #ifdef __cplusplus\r | |
384 | };\r | |
385 | #else\r | |
386 | } Junction;\r | |
387 | #endif\r | |
388 | \r | |
389 | typedef struct { Node *left, *right;} Graph;\r | |
390 | \r |