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