generic.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. #define StrSame 0
  31. #define DefaultParserName "zzparser"
  32. /* MR9 JVincent@novell.com Allow user to override default ZZLEXBUFSIZE */
  33. /* MR11 thm Raise antlr's own default ZZLEXBUFSIZE to 8k */
  34. /* MR22 thm Raise antlr's own default ZZLEXBUFSIZE to 32k */
  35. #ifndef ZZLEXBUFSIZE
  36. #define ZZLEXBUFSIZE 32000
  37. #endif
  38. /* Tree/FIRST/FOLLOW defines -- valid only after all grammar has been read */
  39. #define ALT TokenNum+1
  40. #define SET TokenNum+2
  41. #define TREE_REF TokenNum+3
  42. /* E r r o r M a c r o s */
  43. #define fatal(err) fatalFL(err, __FILE__, __LINE__)
  44. #define fatal_internal(err) fatal_intern(err, __FILE__, __LINE__)
  45. #define eMsg1(s,a) eMsg3(s,a,NULL,NULL)
  46. #define eMsg2(s,a,b) eMsg3(s,a,b,NULL)
  47. /* S a n i t y C h e c k i n g */
  48. #ifndef require
  49. #define require(expr, err) {if ( !(expr) ) fatal_internal(err);}
  50. #endif
  51. /* L i s t N o d e s */
  52. typedef struct _ListNode {
  53. void *elem; /* pointer to any kind of element */
  54. struct _ListNode *next;
  55. } ListNode;
  56. /* Define a Cycle node which is used to track lists of cycles for later
  57. * reconciliation by ResolveFoCycles().
  58. */
  59. typedef struct _c {
  60. int croot; /* cycle root */
  61. set cyclicDep; /* cyclic dependents */
  62. unsigned deg; /* degree of FOLLOW set of croot */
  63. } Cycle;
  64. typedef struct _e {
  65. int tok; /* error class name == TokenStr[tok] */
  66. ListNode *elist; /* linked list of elements in error set */
  67. set eset;
  68. int setdeg; /* how big is the set */
  69. int lexclass; /* which lex class is it in? */
  70. } ECnode;
  71. typedef struct _TCnode {
  72. int tok; /* token class name */
  73. ListNode *tlist; /* linked list of elements in token set */
  74. set tset;
  75. int lexclass; /* which lex class is it in? */
  76. unsigned char dumped; /* this def has been been dumped */
  77. unsigned char dumpedComplement; /* this def has been been dumped */
  78. unsigned setnum; /* which set number is this guy? (if dumped) */
  79. unsigned setnumComplement; /* MR23 */
  80. unsigned setnumErrSet; /* MR23 which set is this #tokclass error set (if dumped) */
  81. unsigned setnumErrSetComplement; /* MR23 */
  82. } TCnode;
  83. typedef struct _ft {
  84. char *token; /* id of token type to remap */
  85. int tnum; /* move token type to which token position */
  86. } ForcedToken;
  87. typedef struct _ContextGuardPredicates { /* MR13 */
  88. Predicate *pred; /* MR13 */
  89. } ContextGuardPredicates; /* MR13 */
  90. #define newListNode (ListNode *) calloc(1, sizeof(ListNode));
  91. #define newCycle (Cycle *) calloc(1, sizeof(Cycle));
  92. #define newECnode (ECnode *) calloc(1, sizeof(ECnode));
  93. #define newTCnode (TCnode *) calloc(1, sizeof(TCnode));
  94. /* H a s h T a b l e E n t r i e s */
  95. typedef struct _t { /* Token name or expression */
  96. char *str;
  97. struct _t *next;
  98. int token; /* token number */
  99. unsigned char classname; /* is it a err/tok class name or token */
  100. TCnode *tclass; /* ptr to token class */
  101. char *action;
  102. char *akaString;
  103. } TermEntry;
  104. typedef struct _r { /* Rule name and ptr to start of rule */
  105. char *str;
  106. struct _t *next;
  107. int rulenum; /* RulePtr[rulenum]== ptr to RuleBlk junction */
  108. unsigned char noAST;/* gen AST construction code? (def==gen code) */
  109. char *egroup; /* which error group (err reporting stuff) */
  110. #if 0
  111. /* MR27 This appears to never be used. Delete this code later. */
  112. ListNode *el_labels;/* list of element labels ref in all of rule */
  113. #endif
  114. ListNode *ast_labels_in_actions; /* MR27 */
  115. unsigned char has_rule_exception;
  116. char dontComputeErrorSet; /* MR14 - don't compute error set
  117. special for rule in alpha part of
  118. (alpha)? beta block */
  119. } RuleEntry;
  120. typedef struct _f { /* cache Fi/Fo set */
  121. char *str; /* key == (rulename, computation, k) */
  122. struct _f *next;
  123. set fset; /* First/Follow of rule */
  124. set rk; /* set of k's remaining to be done after ruleref */
  125. int incomplete; /* only w/FOLLOW sets. Use only if complete */
  126. } CacheEntry;
  127. typedef struct _LabelEntry { /* element labels */
  128. char *str;
  129. struct _f *next;
  130. Node *elem; /* which element does it point to? */
  131. ExceptionGroup *ex_group;
  132. /* Is there an exception attached to label? */
  133. ExceptionGroup *outerEG; /* MR7 */
  134. /* next EG if ex_group doesn't catch it MR7 */
  135. struct _LabelEntry *pendingLink; /* MR7 */
  136. /* too lazy to use ListNode ? MR7 */
  137. int curAltNum; /* MR7 */
  138. } LabelEntry;
  139. typedef struct _SignalEntry {
  140. char *str;
  141. struct _f *next;
  142. int signum; /* unique signal number */
  143. } SignalEntry;
  144. typedef struct _PredEntry { /* MR11 predicate name and ptr to string */
  145. char *str;
  146. struct _PredEntry *next;
  147. int file;
  148. int line;
  149. Predicate *pred;
  150. char *predLiteral;
  151. } PredEntry;
  152. typedef struct _PointerStack { /* MR10 */
  153. int count;
  154. int size;
  155. void **data;
  156. } PointerStack;
  157. #define newTermEntry(s) (TermEntry *) newEntry(s, sizeof(TermEntry))
  158. #define newRuleEntry(s) (RuleEntry *) newEntry(s, sizeof(RuleEntry))
  159. #define newCacheEntry(s) (CacheEntry *) newEntry(s, sizeof(CacheEntry))
  160. #define newLabelEntry(s) (LabelEntry *) newEntry(s, sizeof(LabelEntry))
  161. #define newSignalEntry(s) (SignalEntry *) newEntry(s, sizeof(SignalEntry))
  162. #define newPredEntry(s) (PredEntry *) newEntry(s,sizeof(PredEntry))
  163. typedef struct _UserAction {
  164. char *action;
  165. int file, line;
  166. } UserAction;
  167. /* L e x i c a l C l a s s */
  168. /* to switch lex classes, switch ExprStr and Texpr (hash table) */
  169. typedef struct _lc {
  170. char *classnum, **exprs;
  171. Entry **htable;
  172. } LClass;
  173. typedef struct _exprOrder {
  174. char *expr;
  175. int lclass;
  176. } Expr;
  177. typedef Graph Attrib;
  178. /* M a x i m u m s */
  179. /* MR20 Note G. Hobbelt These values are superseded by values in hash.h */
  180. #ifndef HashTableSize
  181. #define HashTableSize 253
  182. #endif
  183. #ifndef StrTableSize
  184. #define StrTableSize 15000 /* all tokens, nonterminals, rexprs stored here */
  185. #endif
  186. #define MaxLexClasses 50 /* how many automatons */
  187. /* TokenStart and EofToken are ignored if #tokdefs meta-op is used */
  188. #define TokenStart 2 /* MUST be in 1 + EofToken */
  189. #define EofToken 1 /* Always predefined to be 1 */
  190. #ifndef MaxNumFiles
  191. #define MaxNumFiles 99
  192. #endif
  193. /**** MR9 JVincent@novell.com Move to pcctscfg.h */
  194. /**** #define MaxFileName 300 ****/ /* MR9 Move to pcctscfg.h */ /* largest file name size */
  195. #define MaxRuleName 100 /* largest rule name size */
  196. #define TSChunk 100 /* how much to expand TokenStr/ExprStr each time */
  197. #define TIChunk TSChunk /* expand TokenInd by same as TokenStr to mirror them */
  198. #define FoStackSize 100 /* deepest FOLLOW recursion possible */
  199. #define MaxClassDeclStuff 256 /* MR10 */
  200. #define NumPredefinedSignals 3
  201. /* S t a n d a r d S i g n a l s */
  202. #define sigNoSignal 0
  203. #define sigMismatchedToken 1
  204. #define sigNoViableAlt 2
  205. #define sigNoSemViableAlt 3
  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. #define PredictionVariable "zzpr_expr"
  212. #define PredictionLexClassSuffix "_zzpred"
  213. #define WildCardString "WildCard"
  214. #if 0
  215. /* Removed in version 1.33MR19
  216. Don't understand why this never caused problems before
  217. */
  218. /*********************************************************
  219. #ifndef ANTLRm
  220. #define ANTLRm(st, f, _m) zzbufsize = ZZLEXBUFSIZE;\
  221. zzmode(_m); \
  222. zzenterANTLR(f); \
  223. st; ++zzasp; \
  224. zzleaveANTLR(f);
  225. #endif
  226. *********************************************************/
  227. #endif
  228. #include "proto.h"
  229. #include "pcctscfg.h" /* MR14 */
  230. #include <string.h>