2 * generic.h -- generic include stuff for new PCCTS ANTLR.
4 * $Id: generic.h,v 1.2 95/06/15 18:06:55 parrt Exp $
9 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
10 * Set (PCCTS) -- PCCTS is in the public domain. An individual or
11 * company may do whatever they wish with source code distributed with
12 * PCCTS or the code generated by PCCTS, including the incorporation of
13 * PCCTS, or its output, into commerical software.
15 * We encourage users to develop software with PCCTS. However, we do ask
16 * that credit is given to us for developing PCCTS. By "credit",
17 * we mean that if you incorporate our source code into one of your
18 * programs (commercial product, research project, or otherwise) that you
19 * acknowledge this fact somewhere in the documentation, research report,
20 * etc... If you like PCCTS and have developed a nice tool with the
21 * output, please mention that you developed it using PCCTS. In
22 * addition, we ask that this header remain intact in our source code.
23 * As long as these guidelines are kept, we expect to continue enhancing
24 * this system and expect to make other tools available as they are
29 * Parr Research Corporation
30 * with Purdue University and AHPCRC, University of Minnesota
36 #define DefaultParserName "zzparser"
38 #define ZZLEXBUFSIZE 4000
40 /* Tree/FIRST/FOLLOW defines -- valid only after all grammar has been read */
41 #define ALT TokenNum+1
42 #define SET TokenNum+2
43 #define TREE_REF TokenNum+3
45 /* E r r o r M a c r o s */
47 #define fatal(err) fatalFL(err, __FILE__, __LINE__)
48 #define fatal_internal(err) fatal_intern(err, __FILE__, __LINE__)
51 #define eMsg1(s,a) eMsg3(s,a,NULL,NULL)
52 #define eMsg2(s,a,b) eMsg3(s,a,b,NULL)
54 /* S a n i t y C h e c k i n g */
57 #define require(expr, err) {if ( !(expr) ) fatal_internal(err);}
60 /* L i s t N o d e s */
62 typedef struct _ListNode {
63 void *elem; /* pointer to any kind of element */
64 struct _ListNode *next;
67 /* Define a Cycle node which is used to track lists of cycles for later
68 * reconciliation by ResolveFoCycles().
71 int croot; /* cycle root */
72 set cyclicDep; /* cyclic dependents */
73 unsigned deg; /* degree of FOLLOW set of croot */
77 int tok; /* error class name == TokenStr[tok] */
78 ListNode *elist; /* linked list of elements in error set */
80 int setdeg; /* how big is the set */
81 int lexclass; /* which lex class is it in? */
84 typedef struct _TCnode {
85 int tok; /* token class name */
86 ListNode *tlist; /* linked list of elements in token set */
88 int lexclass; /* which lex class is it in? */
89 unsigned char dumped; /* this def has been been dumped */
90 unsigned setnum; /* which set number is this guy? (if dumped) */
94 char *token; /* id of token type to remap */
95 int tnum; /* move token type to which token position */
98 #define newListNode (ListNode *) calloc(1, sizeof(ListNode));
99 #define newCycle (Cycle *) calloc(1, sizeof(Cycle));
100 #define newECnode (ECnode *) calloc(1, sizeof(ECnode));
101 #define newTCnode (TCnode *) calloc(1, sizeof(TCnode));
104 /* H a s h T a b l e E n t r i e s */
106 typedef struct _t { /* Token name or expression */
109 int token; /* token number */
110 unsigned char classname; /* is it a err/tok class name or token */
111 TCnode *tclass; /* ptr to token class */
115 typedef struct _r { /* Rule name and ptr to start of rule */
118 int rulenum; /* RulePtr[rulenum]== ptr to RuleBlk junction */
119 unsigned char noAST;/* gen AST construction code? (def==gen code) */
120 char *egroup; /* which error group (err reporting stuff) */
121 ListNode *el_labels;/* list of element labels ref in all of rule */
122 unsigned char has_rule_exception;
125 typedef struct _f { /* cache Fi/Fo set */
126 char *str; /* key == (rulename, computation, k) */
128 set fset; /* First/Follow of rule */
129 set rk; /* set of k's remaining to be done after ruleref */
130 int incomplete; /* only w/FOLLOW sets. Use only if complete */
133 typedef struct _LabelEntry { /* element labels */
136 Node *elem; /* which element does it point to? */
137 ExceptionGroup *ex_group;
138 /* Is there an exception attached to label? */
141 typedef struct _SignalEntry {
144 int signum; /* unique signal number */
147 #define newTermEntry(s) (TermEntry *) newEntry(s, sizeof(TermEntry))
148 #define newRuleEntry(s) (RuleEntry *) newEntry(s, sizeof(RuleEntry))
149 #define newCacheEntry(s) (CacheEntry *) newEntry(s, sizeof(CacheEntry))
150 #define newLabelEntry(s) (LabelEntry *) newEntry(s, sizeof(LabelEntry))
151 #define newSignalEntry(s) (SignalEntry *) newEntry(s, sizeof(SignalEntry))
154 typedef struct _UserAction {
160 /* L e x i c a l C l a s s */
162 /* to switch lex classes, switch ExprStr and Texpr (hash table) */
164 char *classnum, **exprs;
168 typedef struct _exprOrder {
174 typedef Graph Attrib;
176 /* M a x i m u m s */
178 #ifndef HashTableSize
179 #define HashTableSize 253
182 #define StrTableSize 15000 /* all tokens, nonterminals, rexprs stored here */
184 #define MaxLexClasses 50 /* how many automatons */
185 /* TokenStart and EofToken are ignored if #tokdefs meta-op is used */
186 #define TokenStart 2 /* MUST be in 1 + EofToken */
187 #define EofToken 1 /* Always predefined to be 1 */
188 #define MaxNumFiles 20
189 #define MaxFileName 300 /* largest file name size */
190 #define MaxRuleName 100 /* largest rule name size */
191 #define TSChunk 100 /* how much to expand TokenStr/ExprStr each time */
192 #define TIChunk TSChunk /* expand TokenInd by same as TokenStr to mirror them */
193 #define FoStackSize 100 /* deepest FOLLOW recursion possible */
195 #define NumPredefinedSignals 3
197 /* S t a n d a r d S i g n a l s */
199 #define sigNoSignal 0
200 #define sigMismatchedToken 1
201 #define sigNoViableAlt 2
202 #define sigNoSemViableAlt 3
206 /* AST token types */
210 #define ASTinclude 3 /* include subtree made by rule ref */
213 #define PredictionVariable "zzpr_expr"
214 #define PredictionLexClassSuffix "_zzpred"
216 #define WildCardString "WildCard"
219 #define ANTLRm(st, f, _m) zzbufsize = ZZLEXBUFSIZE;\