]> pd.if.org Git - pccts/blob - antlr/generic.h
auto commit for import
[pccts] / antlr / generic.h
1 /*
2  * generic.h -- generic include stuff for new PCCTS ANTLR.
3  *
4  * $Id: generic.h,v 1.2 95/06/15 18:06:55 parrt Exp $
5  * $Revision: 1.2 $
6  *
7  * SOFTWARE RIGHTS
8  *
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.
14  * 
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
25  * completed.
26  *
27  * ANTLR 1.33
28  * Terence Parr
29  * Parr Research Corporation
30  * with Purdue University and AHPCRC, University of Minnesota
31  * 1989-1995
32  */
33
34 #define StrSame                 0
35
36 #define DefaultParserName       "zzparser"
37
38 #define ZZLEXBUFSIZE 4000
39
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
44
45                                         /* E r r o r  M a c r o s */
46
47 #define fatal(err)      fatalFL(err, __FILE__, __LINE__)
48 #define fatal_internal(err)     fatal_intern(err, __FILE__, __LINE__)
49
50
51 #define eMsg1(s,a)      eMsg3(s,a,NULL,NULL)
52 #define eMsg2(s,a,b)    eMsg3(s,a,b,NULL)
53
54                                 /* S a n i t y  C h e c k i n g */
55
56 #ifndef require
57 #define require(expr, err) {if ( !(expr) ) fatal_internal(err);}
58 #endif
59
60                                         /* L i s t  N o d e s */
61
62 typedef struct _ListNode {
63                         void *elem;                     /* pointer to any kind of element */
64                         struct _ListNode *next;
65                 } ListNode;
66
67 /* Define a Cycle node which is used to track lists of cycles for later
68  * reconciliation by ResolveFoCycles().
69  */
70 typedef struct _c {
71                         int croot;                      /* cycle root */
72                         set cyclicDep;          /* cyclic dependents */
73                         unsigned deg;           /* degree of FOLLOW set of croot */
74                 } Cycle;
75
76 typedef struct _e {
77                         int tok;                        /* error class name == TokenStr[tok] */
78                         ListNode *elist;        /* linked list of elements in error set */
79                         set eset;
80                         int setdeg;                     /* how big is the set */
81                         int lexclass;           /* which lex class is it in? */
82                 } ECnode;
83
84 typedef struct _TCnode {
85                         int tok;                        /* token class name */
86                         ListNode *tlist;        /* linked list of elements in token set */
87                         set tset;
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) */
91                 } TCnode;
92
93 typedef struct _ft {
94                         char *token;            /* id of token type to remap */
95                         int tnum;                       /* move token type to which token position */
96                 } ForcedToken;
97
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));
102
103
104                                 /* H a s h  T a b l e  E n t r i e s */
105
106 typedef struct _t {                             /* Token name or expression */
107                         char *str;
108                         struct _t *next;
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 */
112                         char *action;
113                 } TermEntry;
114
115 typedef struct _r {                             /* Rule name and ptr to start of rule */
116                         char *str;
117                         struct _t *next;
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;
123                 } RuleEntry;
124
125 typedef struct _f {                             /* cache Fi/Fo set */
126                         char *str;                      /* key == (rulename, computation, k) */
127                         struct _f *next;
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 */
131                 } CacheEntry;
132
133 typedef struct _LabelEntry {    /* element labels */
134                         char *str;
135                         struct _f *next;
136                         Node *elem;                     /* which element does it point to? */
137                         ExceptionGroup *ex_group;
138                                                                 /* Is there an exception attached to label? */
139                 } LabelEntry;
140
141 typedef struct _SignalEntry {
142                         char *str;
143                         struct _f *next;
144                         int signum;                     /* unique signal number */
145                 } SignalEntry;
146
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))
152
153
154 typedef struct _UserAction {
155                         char *action;
156                         int file, line;
157                 } UserAction;
158
159
160                                         /* L e x i c a l  C l a s s */
161
162 /* to switch lex classes, switch ExprStr and Texpr (hash table) */
163 typedef struct _lc {
164                         char *classnum, **exprs;
165                         Entry **htable;
166                 } LClass;
167
168 typedef struct _exprOrder {
169                         char *expr;
170                         int lclass;
171                 } Expr;
172
173
174 typedef Graph Attrib;
175
176                                                 /* M a x i m u m s */
177
178 #ifndef HashTableSize
179 #define HashTableSize   253
180 #endif
181 #ifndef StrTableSize
182 #define StrTableSize    15000   /* all tokens, nonterminals, rexprs stored here */
183 #endif
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 */
194
195 #define NumPredefinedSignals 3
196
197            /* S t a n d a r d  S i g n a l s */
198
199 #define sigNoSignal                             0
200 #define sigMismatchedToken              1
201 #define sigNoViableAlt                  2
202 #define sigNoSemViableAlt               3
203
204
205
206 /* AST token types */
207 #define ASTexclude              0
208 #define ASTchild                1
209 #define ASTroot                 2
210 #define ASTinclude              3               /* include subtree made by rule ref */
211
212
213 #define PredictionVariable                              "zzpr_expr"
214 #define PredictionLexClassSuffix                "_zzpred"
215
216 #define WildCardString                                  "WildCard"
217
218 #ifndef ANTLRm
219 #define ANTLRm(st, f, _m)       zzbufsize = ZZLEXBUFSIZE;\
220                                                 zzmode(_m);                                     \
221                                                 zzenterANTLR(f);                        \
222                                                 st; ++zzasp;                            \
223                                                 zzleaveANTLR(f);
224 #endif                                          
225
226 #include "proto.h"
227 #include "config.h"
228 #include <string.h>