home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pccts1.zip / ANTLR / GENERIC.H < prev    next >
C/C++ Source or Header  |  1993-09-02  |  6KB  |  197 lines

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