878ddf1f |
1 | /*\r |
2 | * generic.h -- generic include stuff for new PCCTS ANTLR.\r |
3 | *\r |
4 | * SOFTWARE RIGHTS\r |
5 | *\r |
6 | * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r |
7 | * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r |
8 | * company may do whatever they wish with source code distributed with\r |
9 | * PCCTS or the code generated by PCCTS, including the incorporation of\r |
10 | * PCCTS, or its output, into commerical software.\r |
11 | *\r |
12 | * We encourage users to develop software with PCCTS. However, we do ask\r |
13 | * that credit is given to us for developing PCCTS. By "credit",\r |
14 | * we mean that if you incorporate our source code into one of your\r |
15 | * programs (commercial product, research project, or otherwise) that you\r |
16 | * acknowledge this fact somewhere in the documentation, research report,\r |
17 | * etc... If you like PCCTS and have developed a nice tool with the\r |
18 | * output, please mention that you developed it using PCCTS. In\r |
19 | * addition, we ask that this header remain intact in our source code.\r |
20 | * As long as these guidelines are kept, we expect to continue enhancing\r |
21 | * this system and expect to make other tools available as they are\r |
22 | * completed.\r |
23 | *\r |
24 | * ANTLR 1.33\r |
25 | * Terence Parr\r |
26 | * Parr Research Corporation\r |
27 | * with Purdue University and AHPCRC, University of Minnesota\r |
28 | * 1989-2001\r |
29 | */\r |
30 | \r |
31 | #define StrSame 0\r |
32 | \r |
33 | #define DefaultParserName "zzparser"\r |
34 | \r |
35 | /* MR9 JVincent@novell.com Allow user to override default ZZLEXBUFSIZE */\r |
36 | /* MR11 thm Raise antlr's own default ZZLEXBUFSIZE to 8k */\r |
37 | /* MR22 thm Raise antlr's own default ZZLEXBUFSIZE to 32k */\r |
38 | \r |
39 | #ifndef ZZLEXBUFSIZE\r |
40 | #define ZZLEXBUFSIZE 32000\r |
41 | #endif\r |
42 | \r |
43 | /* Tree/FIRST/FOLLOW defines -- valid only after all grammar has been read */\r |
44 | #define ALT TokenNum+1\r |
45 | #define SET TokenNum+2\r |
46 | #define TREE_REF TokenNum+3\r |
47 | \r |
48 | /* E r r o r M a c r o s */\r |
49 | \r |
50 | #define fatal(err) fatalFL(err, __FILE__, __LINE__)\r |
51 | #define fatal_internal(err) fatal_intern(err, __FILE__, __LINE__)\r |
52 | \r |
53 | \r |
54 | #define eMsg1(s,a) eMsg3(s,a,NULL,NULL)\r |
55 | #define eMsg2(s,a,b) eMsg3(s,a,b,NULL)\r |
56 | \r |
57 | /* S a n i t y C h e c k i n g */\r |
58 | \r |
59 | #ifndef require\r |
60 | #define require(expr, err) {if ( !(expr) ) fatal_internal(err);}\r |
61 | #endif\r |
62 | \r |
63 | /* L i s t N o d e s */\r |
64 | \r |
65 | typedef struct _ListNode {\r |
66 | void *elem; /* pointer to any kind of element */\r |
67 | struct _ListNode *next;\r |
68 | } ListNode;\r |
69 | \r |
70 | /* Define a Cycle node which is used to track lists of cycles for later\r |
71 | * reconciliation by ResolveFoCycles().\r |
72 | */\r |
73 | typedef struct _c {\r |
74 | int croot; /* cycle root */\r |
75 | set cyclicDep; /* cyclic dependents */\r |
76 | unsigned deg; /* degree of FOLLOW set of croot */\r |
77 | } Cycle;\r |
78 | \r |
79 | typedef struct _e {\r |
80 | int tok; /* error class name == TokenStr[tok] */\r |
81 | ListNode *elist; /* linked list of elements in error set */\r |
82 | set eset;\r |
83 | int setdeg; /* how big is the set */\r |
84 | int lexclass; /* which lex class is it in? */\r |
85 | } ECnode;\r |
86 | \r |
87 | typedef struct _TCnode {\r |
88 | int tok; /* token class name */\r |
89 | ListNode *tlist; /* linked list of elements in token set */\r |
90 | set tset;\r |
91 | int lexclass; /* which lex class is it in? */\r |
92 | unsigned char dumped; /* this def has been been dumped */\r |
93 | unsigned char dumpedComplement; /* this def has been been dumped */\r |
94 | unsigned setnum; /* which set number is this guy? (if dumped) */\r |
95 | unsigned setnumComplement; /* MR23 */\r |
96 | unsigned setnumErrSet; /* MR23 which set is this #tokclass error set (if dumped) */\r |
97 | unsigned setnumErrSetComplement; /* MR23 */\r |
98 | } TCnode;\r |
99 | \r |
100 | typedef struct _ft {\r |
101 | char *token; /* id of token type to remap */\r |
102 | int tnum; /* move token type to which token position */\r |
103 | } ForcedToken;\r |
104 | \r |
105 | typedef struct _ContextGuardPredicates { /* MR13 */\r |
106 | Predicate *pred; /* MR13 */\r |
107 | } ContextGuardPredicates; /* MR13 */\r |
108 | \r |
109 | #define newListNode (ListNode *) calloc(1, sizeof(ListNode));\r |
110 | #define newCycle (Cycle *) calloc(1, sizeof(Cycle));\r |
111 | #define newECnode (ECnode *) calloc(1, sizeof(ECnode));\r |
112 | #define newTCnode (TCnode *) calloc(1, sizeof(TCnode));\r |
113 | \r |
114 | \r |
115 | /* H a s h T a b l e E n t r i e s */\r |
116 | \r |
117 | typedef struct _t { /* Token name or expression */\r |
118 | char *str;\r |
119 | struct _t *next;\r |
120 | int token; /* token number */\r |
121 | unsigned char classname; /* is it a err/tok class name or token */\r |
122 | TCnode *tclass; /* ptr to token class */\r |
123 | char *action;\r |
124 | char *akaString;\r |
125 | } TermEntry;\r |
126 | \r |
127 | typedef struct _r { /* Rule name and ptr to start of rule */\r |
128 | char *str;\r |
129 | struct _t *next;\r |
130 | int rulenum; /* RulePtr[rulenum]== ptr to RuleBlk junction */\r |
131 | unsigned char noAST;/* gen AST construction code? (def==gen code) */\r |
132 | char *egroup; /* which error group (err reporting stuff) */\r |
133 | #if 0\r |
134 | /* MR27 This appears to never be used. Delete this code later. */\r |
135 | \r |
136 | ListNode *el_labels;/* list of element labels ref in all of rule */\r |
137 | #endif\r |
138 | ListNode *ast_labels_in_actions; /* MR27 */\r |
139 | unsigned char has_rule_exception;\r |
140 | char dontComputeErrorSet; /* MR14 - don't compute error set\r |
141 | special for rule in alpha part of\r |
142 | (alpha)? beta block */\r |
143 | } RuleEntry;\r |
144 | \r |
145 | typedef struct _f { /* cache Fi/Fo set */\r |
146 | char *str; /* key == (rulename, computation, k) */\r |
147 | struct _f *next;\r |
148 | set fset; /* First/Follow of rule */\r |
149 | set rk; /* set of k's remaining to be done after ruleref */\r |
150 | int incomplete; /* only w/FOLLOW sets. Use only if complete */\r |
151 | } CacheEntry;\r |
152 | \r |
153 | typedef struct _LabelEntry { /* element labels */\r |
154 | char *str;\r |
155 | struct _f *next;\r |
156 | Node *elem; /* which element does it point to? */\r |
157 | ExceptionGroup *ex_group;\r |
158 | /* Is there an exception attached to label? */\r |
159 | ExceptionGroup *outerEG; /* MR7 */\r |
160 | /* next EG if ex_group doesn't catch it MR7 */\r |
161 | struct _LabelEntry *pendingLink; /* MR7 */\r |
162 | /* too lazy to use ListNode ? MR7 */\r |
163 | int curAltNum; /* MR7 */\r |
164 | } LabelEntry;\r |
165 | \r |
166 | typedef struct _SignalEntry {\r |
167 | char *str;\r |
168 | struct _f *next;\r |
169 | int signum; /* unique signal number */\r |
170 | } SignalEntry;\r |
171 | \r |
172 | typedef struct _PredEntry { /* MR11 predicate name and ptr to string */\r |
173 | char *str;\r |
174 | struct _PredEntry *next;\r |
175 | int file;\r |
176 | int line;\r |
177 | Predicate *pred;\r |
178 | char *predLiteral;\r |
179 | } PredEntry;\r |
180 | \r |
181 | typedef struct _PointerStack { /* MR10 */\r |
182 | int count;\r |
183 | int size;\r |
184 | void **data;\r |
185 | } PointerStack;\r |
186 | \r |
187 | #define newTermEntry(s) (TermEntry *) newEntry(s, sizeof(TermEntry))\r |
188 | #define newRuleEntry(s) (RuleEntry *) newEntry(s, sizeof(RuleEntry))\r |
189 | #define newCacheEntry(s) (CacheEntry *) newEntry(s, sizeof(CacheEntry))\r |
190 | #define newLabelEntry(s) (LabelEntry *) newEntry(s, sizeof(LabelEntry))\r |
191 | #define newSignalEntry(s) (SignalEntry *) newEntry(s, sizeof(SignalEntry))\r |
192 | #define newPredEntry(s) (PredEntry *) newEntry(s,sizeof(PredEntry))\r |
193 | \r |
194 | typedef struct _UserAction {\r |
195 | char *action;\r |
196 | int file, line;\r |
197 | } UserAction;\r |
198 | \r |
199 | \r |
200 | /* L e x i c a l C l a s s */\r |
201 | \r |
202 | /* to switch lex classes, switch ExprStr and Texpr (hash table) */\r |
203 | typedef struct _lc {\r |
204 | char *classnum, **exprs;\r |
205 | Entry **htable;\r |
206 | } LClass;\r |
207 | \r |
208 | typedef struct _exprOrder {\r |
209 | char *expr;\r |
210 | int lclass;\r |
211 | } Expr;\r |
212 | \r |
213 | \r |
214 | typedef Graph Attrib;\r |
215 | \r |
216 | /* M a x i m u m s */\r |
217 | \r |
218 | /* MR20 Note G. Hobbelt These values are superceded by values in hash.h */\r |
219 | \r |
220 | #ifndef HashTableSize\r |
221 | #define HashTableSize 253\r |
222 | #endif\r |
223 | #ifndef StrTableSize\r |
224 | #define StrTableSize 15000 /* all tokens, nonterminals, rexprs stored here */\r |
225 | #endif\r |
226 | #define MaxLexClasses 50 /* how many automatons */\r |
227 | /* TokenStart and EofToken are ignored if #tokdefs meta-op is used */\r |
228 | #define TokenStart 2 /* MUST be in 1 + EofToken */\r |
229 | #define EofToken 1 /* Always predefined to be 1 */\r |
230 | \r |
231 | #ifndef MaxNumFiles\r |
232 | #define MaxNumFiles 99\r |
233 | #endif\r |
234 | \r |
235 | /**** MR9 JVincent@novell.com Move to pcctscfg.h */\r |
236 | /**** #define MaxFileName 300 ****/ /* MR9 Move to pcctscfg.h */ /* largest file name size */\r |
237 | \r |
238 | #define MaxRuleName 100 /* largest rule name size */\r |
239 | #define TSChunk 100 /* how much to expand TokenStr/ExprStr each time */\r |
240 | #define TIChunk TSChunk /* expand TokenInd by same as TokenStr to mirror them */\r |
241 | #define FoStackSize 100 /* deepest FOLLOW recursion possible */\r |
242 | \r |
243 | #define MaxClassDeclStuff 256 /* MR10 */\r |
244 | \r |
245 | #define NumPredefinedSignals 3\r |
246 | \r |
247 | /* S t a n d a r d S i g n a l s */\r |
248 | \r |
249 | #define sigNoSignal 0\r |
250 | #define sigMismatchedToken 1\r |
251 | #define sigNoViableAlt 2\r |
252 | #define sigNoSemViableAlt 3\r |
253 | \r |
254 | \r |
255 | \r |
256 | /* AST token types */\r |
257 | #define ASTexclude 0\r |
258 | #define ASTchild 1\r |
259 | #define ASTroot 2\r |
260 | #define ASTinclude 3 /* include subtree made by rule ref */\r |
261 | \r |
262 | \r |
263 | #define PredictionVariable "zzpr_expr"\r |
264 | #define PredictionLexClassSuffix "_zzpred"\r |
265 | \r |
266 | #define WildCardString "WildCard"\r |
267 | \r |
268 | #if 0\r |
269 | /* Removed in version 1.33MR19\r |
270 | Don't understand why this never caused problems before\r |
271 | */\r |
272 | \r |
273 | /*********************************************************\r |
274 | #ifndef ANTLRm\r |
275 | #define ANTLRm(st, f, _m) zzbufsize = ZZLEXBUFSIZE;\\r |
276 | zzmode(_m); \\r |
277 | zzenterANTLR(f); \\r |
278 | st; ++zzasp; \\r |
279 | zzleaveANTLR(f);\r |
280 | #endif \r |
281 | *********************************************************/\r |
282 | #endif\r |
283 | \r |
284 | #include "proto.h"\r |
285 | #include "pcctscfg.h" /* MR14 */\r |
286 | #include <string.h>\r |