home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pccts.zip / pccts / antlr / generic.h < prev    next >
C/C++ Source or Header  |  1994-03-31  |  6KB  |  206 lines

  1. /*
  2.  * generic.h -- generic include stuff for new PCCTS ANTLR.
  3.  *
  4.  * $Id: generic.h,v 1.5 1994/03/25 19:40:05 parrt Exp parrt $
  5.  * $Revision: 1.5 $
  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.20
  28.  * Terence Parr
  29.  * Purdue University
  30.  * With AHPCRC, University of Minnesota
  31.  * 1989-1994
  32.  */
  33.  
  34. #define StrSame            0
  35.  
  36. /* User may redefine how line information looks */
  37. #define LineInfoFormatStr "# %d \"%s\"\n"
  38.  
  39. #define DefaultParserName    "zzparser"
  40.  
  41. #define ZZLEXBUFSIZE 4000
  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. #ifdef MPW        /* Macintosh Programmer's Workshop */
  51. #define ErrHdr "File \"%s\"; Line %d #"
  52. #else
  53. #define ErrHdr "%s, line %d:"
  54. #endif
  55.  
  56. #define fatal(err)    fatalFL(err, __FILE__, __LINE__)
  57.  
  58.  
  59. #define eMsg1(s,a)    eMsg3(s,a,NULL,NULL)
  60. #define eMsg2(s,a,b)    eMsg3(s,a,b,NULL)
  61.  
  62.                 /* S a n i t y  C h e c k i n g */
  63.  
  64. #ifndef require
  65. #define require(expr, err) {if ( !(expr) ) fatal_internal(err, __FILE__, __LINE__);}
  66. #endif
  67.  
  68.                     /* L i s t  N o d e s */
  69.  
  70. typedef struct _ListNode {
  71.             void *elem;            /* pointer to any kind of element */
  72.             struct _ListNode *next;
  73.         } ListNode;
  74.  
  75. /* Define a Cycle node which is used to track lists of cycles for later
  76.  * reconciliation by ResolveFoCycles().
  77.  */
  78. typedef struct _c {
  79.             int croot;            /* cycle root */
  80.             set cyclicDep;        /* cyclic dependents */
  81.             unsigned deg;        /* degree of FOLLOW set of croot */
  82.         } Cycle;
  83.  
  84. typedef struct _e {
  85.             int tok;            /* error class name == TokenStr[tok] */
  86.             ListNode *elist;    /* linked list of elements in error set */
  87.             set eset;
  88.             int setdeg;            /* how big is the set */
  89.             int lexclass;        /* which lex class is it in? */
  90.         } ECnode;
  91.  
  92. typedef struct _TCnode {
  93.             int tok;            /* token class name */
  94.             ListNode *tlist;    /* linked list of elements in token set */
  95.             set tset;
  96.             int lexclass;        /* which lex class is it in? */
  97.         } TCnode;
  98.  
  99. typedef struct _ft {
  100.             char *token;        /* id of token type to remap */
  101.             int tnum;            /* move token type to which token position */
  102.         } ForcedToken;
  103.  
  104. #define newListNode    (ListNode *) calloc(1, sizeof(ListNode));
  105. #define newCycle    (Cycle *) calloc(1, sizeof(Cycle));
  106. #define newECnode    (ECnode *) calloc(1, sizeof(ECnode));
  107. #define newTCnode    (TCnode *) calloc(1, sizeof(TCnode));
  108.  
  109.  
  110.                 /* H a s h  T a b l e  E n t r i e s */
  111.  
  112. typedef struct _t {                /* Token name or expression */
  113.             char *str;
  114.             struct _t *next;
  115.             int token;            /* token number */
  116.             unsigned char classname;    /* is it a err/tok class name or token */
  117.             TCnode *tclass;        /* ptr to token class */
  118.             char *action;
  119.         } TermEntry;
  120.  
  121. typedef struct _r {                /* Rule name and ptr to start of rule */
  122.             char *str;
  123.             struct _t *next;
  124. /*            int passedSomething;/* is this rule passed something? */
  125. /*            int returnsSomething;/* does this rule return something? */
  126.             int rulenum;        /* RulePtr[rulenum]== ptr to RuleBlk junction */
  127.             int noAST;            /* gen AST construction code? (def==gen code) */
  128.             char *egroup;        /* which error group (err reporting stuff) */
  129.         } RuleEntry;
  130.  
  131. typedef struct _f {                /* cache Fi/Fo set */
  132.             char *str;            /* key == (rulename, computation, k) */
  133.             struct _f *next;
  134.             set fset;            /* First/Follow of rule */
  135.             set rk;                /* set of k's remaining to be done after ruleref */
  136.             int incomplete;        /* only w/FOLLOW sets.  Use only if complete */
  137.         } CacheEntry;
  138.  
  139. #define newTermEntry(s)        (TermEntry *) newEntry(s, sizeof(TermEntry))
  140. #define newRuleEntry(s)        (RuleEntry *) newEntry(s, sizeof(RuleEntry))
  141. #define newCacheEntry(s)    (CacheEntry *) newEntry(s, sizeof(CacheEntry))
  142.  
  143.                     /* L e x i c a l  C l a s s */
  144.  
  145. /* to switch lex classes, switch ExprStr and Texpr (hash table) */
  146. typedef struct _lc {
  147.             char *classnum, **exprs;
  148.             Entry **htable;
  149.         } LClass;
  150.  
  151. typedef struct _exprOrder {
  152.             char *expr;
  153.             int lclass;
  154.         } Expr;
  155.  
  156.  
  157. typedef Graph Attrib;
  158.  
  159.                         /* M a x i m u m s */
  160.  
  161. #ifndef HashTableSize
  162. #define HashTableSize    253
  163. #endif
  164. #ifndef StrTableSize
  165. #define StrTableSize    15000    /* all tokens, nonterminals, rexprs stored here */
  166. #endif
  167. #define MaxLexClasses    50        /* how many automatons */
  168. /* TokenStart and EofToken are ignored if #tokdefs meta-op is used */
  169. #define TokenStart        2        /* MUST be in 1 + EofToken */
  170. #define EofToken        1        /* Always predefined to be 1 */
  171. #define MaxNumFiles        20
  172. #define MaxFileName        300        /* largest file name size */
  173. #define MaxRuleName        100        /* largest rule name size */
  174. #define TSChunk            100        /* how much to expand TokenStr/ExprStr each time */
  175. #define TIChunk            TSChunk    /* expand TokenInd by same as TokenStr to mirror them */
  176. #define FoStackSize        100        /* deepest FOLLOW recursion possible */
  177.  
  178. /* AST token types */
  179. #define ASTexclude        0
  180. #define ASTchild        1
  181. #define ASTroot            2
  182. #define ASTinclude        3        /* include subtree made by rule ref */
  183.  
  184.  
  185. #define PredictionVariable                "zzpr_expr"
  186. #define PredictionLexClassSuffix        "_zzpred"
  187.  
  188. #define DirectorySymbol                    "/"
  189.  
  190. #ifndef TRUE
  191. #define TRUE 1
  192. #endif
  193. #ifndef FALSE
  194. #define FALSE 0
  195. #endif
  196.  
  197. #ifndef ANTLRm
  198. #define ANTLRm(st, f, _m)    zzbufsize = ZZLEXBUFSIZE;\
  199.                         zzmode(_m);                    \
  200.                         zzenterANTLR(f);            \
  201.                         st; ++zzasp;                \
  202.                         zzleaveANTLR(f);
  203. #endif                        
  204.  
  205. #include "proto.h"
  206.