home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / DTXTRN.H < prev    next >
C/C++ Source or Header  |  1989-09-29  |  7KB  |  336 lines

  1. /*
  2.   HEADER: CUG     nnn.nn;
  3.   TITLE:     YACC - Yet Another Compilier-Compilier
  4.   VERSION:     1.0 for IBM-PC
  5.   DATE:      JAN 28, 1985
  6.   DESCRIPTION:     LALR(1) Parser Generator. From UNIX
  7.   KEYWORDS:     Parser Generator Compilier-Compilier YACC
  8.   SYSTEM:     IBM-PC and Compatiables
  9.   FILENAME:      DTXTRN.H
  10.   WARNINGS:     This program is not for the casual user. It will
  11.          be useful primarily to expert developers.
  12.   CRC:         N/A
  13.   SEE-ALSO:     LEX and PREP
  14.   AUTHORS:     Scott Guthery 11100 leafwood lane Austin, TX 78750
  15.   COMPILERS:     DESMET-C
  16.   REFERENCES:     UNIX Systems Manuals
  17. */
  18.  
  19. /*
  20.  * DTXTRN.H  -- Original extern file for UNIX YACC.
  21.  *
  22.  * Modified to call in "decus" or "vax11c" .H files to set up
  23.  * parameters as appropriate.
  24.  */
  25.  
  26. #ifndef _YACC_EXTERNALS
  27.  
  28. #include <stdio.h>
  29. #include "system.h"
  30.  
  31. /*  MANIFEST CONSTANT DEFINITIONS */
  32.  
  33. /* base of nonterminal internal numbers */
  34. #define NTBASE 010000
  35.  
  36. /* internal codes for error and accept actions */
  37.  
  38. #define ERRCODE  8190
  39. #define ACCEPTCODE 8191
  40.  
  41. /* sizes and limits */
  42.  
  43. #ifdef HUGETAB
  44. #define ACTSIZE 12000
  45. #define MEMSIZE 12000
  46. #define NSTATES 750
  47. #define NTERMS 127
  48. #define NPROD 600
  49. #define NNONTERM 300
  50. #define TEMPSIZE 1200
  51. #define CNAMSZ 5000
  52. #define LSETSIZE 600
  53. #define WSETSIZE 350
  54. #endif
  55.  
  56. #ifdef MEDTAB
  57. #define ACTSIZE 4000
  58. #define MEMSIZE 5200
  59. #define NSTATES 600
  60. #define NTERMS 127
  61. #define NPROD 400
  62. #define NNONTERM 200
  63. #define TEMPSIZE 800
  64. #define CNAMSZ 4000
  65. #define LSETSIZE 450
  66. #define WSETSIZE 250
  67. #endif
  68.  
  69. #ifdef SMALLTAB
  70. #define ACTSIZE 1000
  71. #define MEMSIZE 1500
  72. #define NSTATES 450
  73. #define NTERMS 127
  74. #define NPROD 200
  75. #define NNONTERM 100
  76. #define TEMPSIZE 600
  77.  
  78. #define CNAMSZ 1000
  79. #define LSETSIZE 200
  80. #define WSETSIZE 125
  81. #endif
  82.  
  83. #define NAMESIZE 50
  84. #define NTYPES 63
  85.  
  86. #ifdef WORD32
  87. #define TBITSET ((32+NTERMS)/32)
  88.  
  89. /* bit packing macros (may be machine dependent) */
  90. #define BIT(a,i) ((a)[(i)>>5] & (1<<((i)&037)))
  91. #define SETBIT(a,i) ((a)[(i)>>5] |= (1<<((i)&037)))
  92.  
  93. /* number of words needed to hold n+1 bits */
  94. #define NWORDS(n) (((n)+32)/32)
  95.  
  96. #else
  97.  
  98. #define TBITSET ((16+NTERMS)/16)
  99.  
  100. /* bit packing macros (may be machine dependent) */
  101. #define BIT(a,i) ((a)[(i)>>4] & (1<<((i)&017)))
  102. #define SETBIT(a,i) ((a)[(i)>>4] |= (1<<((i)&017)))
  103.  
  104. /* number of words needed to hold n+1 bits */
  105. #define NWORDS(n) (((n)+16)/16)
  106. #endif
  107.  
  108. /* relationships which must hold:
  109.         TBITSET ints must hold NTERMS+1 bits...
  110.         WSETSIZE >= NNONTERM
  111.         LSETSIZE >= NNONTERM
  112.         TEMPSIZE >= NTERMS + NNONTERMs + 1
  113.         TEMPSIZE >= NSTATES
  114.         */
  115.  
  116. /* associativities */
  117.  
  118. #define NOASC 0  /* no assoc. */
  119. #define LASC 1  /* left assoc. */
  120. #define RASC 2  /* right assoc. */
  121. #define BASC 3  /* binary assoc. */
  122.  
  123. /* flags for state generation */
  124.  
  125. #define DONE 0
  126. #define MUSTDO 1
  127. #define MUSTLOOKAHEAD 2
  128.  
  129. /* flags for a rule having an action, and being reduced */
  130.  
  131. #define ACTFLAG 04
  132. #define REDFLAG 010
  133.  
  134. /* output parser flags */
  135. #define YYFLAG1 (-1000)
  136.  
  137. /* macros for getting associativity and precedence levels */
  138.  
  139. #define ASSOC(i) ((i)&03)
  140.  
  141. #define PLEVEL(i) (((i)>>4)&077)
  142. #define TYPE(i)  ((i>>10)&077)
  143.  
  144. /* macros for setting associativity and precedence levels */
  145.  
  146. #define SETASC(i,j) i|=j
  147. #define SETPLEV(i,j) i |= (j<<4)
  148. #define SETTYPE(i,j) i |= (j<<10)
  149.  
  150. /* looping macros */
  151.  
  152. #define TLOOP(i) for(i=1;i<=ntokens;++i)
  153. #define NTLOOP(i) for(i=0;i<=nnonter;++i)
  154. #define PLOOP(s,i) for(i=s;i<nprod;++i)
  155. #define SLOOP(i) for(i=0;i<nstate;++i)
  156. #define WSBUMP(x) ++x
  157. #define WSLOOP(s,j) for(j=s;j<cwp;++j)
  158. #define ITMLOOP(i,p,q) q=pstate[i+1];for(p=pstate[i];p<q;++p)
  159. #define SETLOOP(i) for(i=0;i<tbitset;++i)
  160.  
  161. /* I/O descriptors */
  162.  
  163. #ifndef y2imp
  164. extern FILE * finput;           /* input file */
  165. extern FILE * faction;          /* file for saving actions */
  166. extern FILE *fdefine;           /* file for #defines */
  167. extern FILE * ftable;           /* y.tab.c file */
  168. extern FILE * ftemp;            /* tempfile to pass 2 */
  169. extern FILE * foutput;          /* y.output file */
  170. #endif
  171.  
  172. /* structure declarations */
  173.  
  174. struct looksets
  175.    {
  176.    int lset[TBITSET];
  177.    };
  178.  
  179. struct item
  180.    {
  181.    int *pitem;
  182.    struct looksets *look;
  183.    };
  184.  
  185. struct toksymb
  186.    {
  187.    char *name;
  188.    int value;
  189.    };
  190.  
  191. struct ntsymb
  192.    {
  193.    char *name;
  194.    int tvalue;
  195.    };
  196.  
  197. struct wset
  198.    {
  199.    int *pitem;
  200.    int flag;
  201.    struct looksets ws;
  202.    };
  203.  
  204. #ifndef y2imp
  205. /* token information */
  206.  
  207. extern int ntokens ;    /* number of tokens */
  208. extern struct toksymb tokset[];
  209. extern int toklev[];    /* vector with the precedence of the terminals */
  210. #endif
  211.  
  212. /* nonterminal information */
  213.  
  214. #ifndef y2imp
  215. extern int nnonter ;    /* the number of nonterminals */
  216. extern struct ntsymb nontrst[];
  217. #endif
  218.  
  219. /* grammar rule information */
  220. #ifndef y2imp
  221. extern int nprod ;      /* number of productions */
  222. extern int *prdptr[];   /* pointers to descriptions of productions */
  223. extern int levprd[] ;   /* contains production levels to break conflicts */
  224. #endif
  225.  
  226. /* state information */
  227.  
  228. #ifndef y1imp
  229. extern int nstate ;             /* number of states */
  230. extern struct item *pstate[];   /* pointers to the descriptions of the states */
  231. extern int tystate[];   /* contains type information about the states */
  232. #ifndef y3imp
  233. extern int defact[];    /* the default action of the state */
  234. #endif
  235. extern int tstates[];   /* the states deriving each token */
  236. extern int ntstates[];  /* the states deriving each nonterminal */
  237. extern int mstates[];   /* the continuation of the chains begun in tstates and ntstates */
  238. #endif
  239.  
  240. /* lookahead set information */
  241.  
  242. #ifndef y1imp
  243. extern struct looksets lkst[];
  244. extern int nolook;  /* flag to turn off lookahead computations */
  245. #endif
  246.  
  247. /* working set information */
  248.  
  249. #ifndef y1imp
  250. extern struct wset wsets[];
  251. extern struct wset *cwp;
  252. #endif
  253.  
  254. /* storage for productions */
  255. #ifndef y2imp
  256. extern int mem0[];
  257. extern int *mem;
  258. #endif
  259.  
  260. /* storage for action table */
  261.  
  262. #ifndef y1imp
  263. extern int amem[];  /* action table storage */
  264. extern int *memp ;              /* next free action table position */
  265. extern int indgo[];             /* index to the stored goto table */
  266.  
  267. /* temporary vector, indexable by states, terms, or ntokens */
  268.  
  269. extern int temp1[];
  270. extern int lineno; /* current line number */
  271.  
  272. /* statistics collection variables */
  273.  
  274. extern int zzgoent ;
  275. extern int zzgobest ;
  276. extern int zzacent ;
  277. extern int zzexcp ;
  278. extern int zzclose ;
  279. extern int zzrrconf ;
  280. extern int zzsrconf ;
  281. #endif
  282.  
  283. /* define functions with strange types... */
  284.  
  285. extern char *cstash();
  286. extern struct looksets *flset();
  287. extern char *symnam();
  288. extern char *writem();
  289.  
  290. /* default settings for a number of macros */
  291.  
  292. #define ISIZE 400       /* Specific for static in cpres() */
  293.  
  294. /* name of yacc tempfiles */
  295.  
  296. #ifndef TEMPNAME
  297. #define TEMPNAME "yacc.tmp"
  298. #endif
  299.  
  300. #ifndef ACTNAME
  301. #define ACTNAME "yacc.act"
  302. #endif
  303.  
  304. /* output file name */
  305.  
  306. #ifndef OFILE
  307. #define OFILE "ytab.c"
  308. #endif
  309.  
  310. /* user output file name */
  311.  
  312. #ifndef FILEU
  313. #define FILEU "y.out"
  314. #endif
  315.  
  316. /* output file for #defines */
  317.  
  318. #ifndef FILED
  319. #define FILED "ytab.h"
  320. #endif
  321.  
  322. /* Size of complete filespec */
  323. #ifndef FNAMESIZE
  324. #define FNAMESIZE 32
  325. #endif
  326.  
  327. /* command to clobber tempfiles after use */
  328.  
  329. #ifndef ZAPFILE
  330. #define ZAPFILE(x) unlink(x)
  331. #endif
  332.  
  333. #define _YACC_EXTERNALS
  334. #endif
  335.  
  336.