/* @(#)20       1.13  src/bos/usr/ccs/bin/yacc/dextern, cmdlang, bos411, 9428A410j 4/14/94 12:09:57 */
/*
 * COMPONENT_NAME: (CMDLANG) Language Utilities
 *
 * FUNCTIONS: 
 *
 * ORIGINS: 27 65 71
 *
 * IBM CONFIDENTIAL -- (IBM Confidential Restricted when
 * combined with the aggregated modules for this product)
 *                  SOURCE MATERIALS
 * (C) COPYRIGHT International Business Machines Corp. 1985, 1989
 * All Rights Reserved
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */
/*
 * (c) Copyright 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC.
 * ALL RIGHTS RESERVED
 *
 * OSF/1 1.1
 */
# define _ILS_MACROS     /* 139709 - use macros for better performance */
# include <stdio.h>
# include <sys/localedef.h>
# include <nl_types.h>
# include <ctype.h>
# include "files"

        /*  MANIFEST CONSTANT DEFINITIONS */

        /* base of nonterminal internal numbers */
# define NTBASE 010000

        /* internal codes for error and accept actions */

# define ERRCODE  8190
# define ACCEPTCODE 8191

        /* sizes and limits */

# ifdef HUGE
# define ACTSIZE 70000
# define MEMSIZE 40000
# define NSTATES 5000
# define NTERMS 3000
# define NPROD 2000
# define NNONTERM 1000
# define CNAMSZ 8000
# define LSETBLOCK 600
# define BUFFER 400
# endif

# ifdef MEDIUM
# define ACTSIZE 4000
# define MEMSIZE 5200
# define NSTATES 600
# define NTERMS 127
# define NPROD 400
# define NNONTERM 200
# define CNAMSZ 4000
# define LSETBLOCK 450
# define BUFFER 250
# endif

# define NAMESIZE 50
# define NTYPES 63

# ifdef WORD32
# define TBITSET ((32+nterms)/32)

        /* bit packing macros (may be machine dependent) */
# define BIT(a,i) ((a)[(i)>>5] & (1<<((i)&037)))
# define SETBIT(a,i) ((a)[(i)>>5] |= (1<<((i)&037)))

        /* number of words needed to hold n+1 bits */
# define NWORDS(n) (((n)+32)/32)

# else

# define TBITSET ((16+nterms)/16)

        /* bit packing macros (may be machine dependent) */
# define BIT(a,i) ((a)[(i)>>4] & (1<<((i)&017)))
# define SETBIT(a,i) ((a)[(i)>>4] |= (1<<((i)&017)))

        /* number of words needed to hold n+1 bits */
# define NWORDS(n) (((n)+16)/16)
# endif

        /* relationships which must hold:
        TBITSET ints must hold NTERMS+1 bits...
        WSETSIZE >= NNONTERM
        LSETBLOCK >= NNONTERM
        TEMPSIZE >= NTERMS + NNONTERMs + 1
        TEMPSIZE >= NSTATES
        */

        /* associativities */

# define NOASC 0  /* no assoc. */
# define LASC 1  /* left assoc. */
# define RASC 2  /* right assoc. */
# define BASC 3  /* binary assoc. */

        /* flags for state generation */

# define DONE 0
# define MUSTDO 1
# define MUSTLOOKAHEAD 2

        /* flags for a rule having an action, and being reduced */

# define ACTFLAG 04
# define REDFLAG 010

        /* output parser flags */
# define YYFLAG1 (-1000)

        /* macros for getting associativity and precedence levels */

# define ASSOC(i) ((i)&03)
# define PLEVEL(i) (((i)>>4)&077)
# define TYPE(i)  ((i>>10)&077)

        /* macros for setting associativity and precedence levels */

# define SETASC(i,j) i|=j
# define SETPLEV(i,j) i |= (j<<4)
# define SETTYPE(i,j) i |= (j<<10)

        /* looping macros */

# define TLOOP(i) for(i=1;i<=ntokens;++i)
# define NTLOOP(i) for(i=0;i<=nnonter;++i)
# define PLOOP(s,i) for(i=s;i<nprod;++i)
# define SLOOP(i) for(i=0;i<nstate;++i)
# define WSBUMP(x) ++x
# define WSLOOP(s,j) for(j=s;j<cwp;++j)
# define ITMLOOP(i,p,q) q=pstate[i+1];for(p=pstate[i];p<q;++p)
# define SETLOOP(i) for(i=0;i<tbitset;++i)

# define OUTBUFMSG error(MSGSTR(OUTBUFSPC, "Use -Nr flag to increase buffer size to handle large grammars (default size is %d)."), NPROD)

#define ISHEX(c) (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F')))
#define ISOCTAL(c) ((c >= '0') && (c <= '7'))

        /* I/O descriptors */
extern FILE * fyinput;		/* .y input file */
extern FILE * finput;           /* input file */
extern FILE * faction;          /* file for saving actions */
extern FILE * fdefine;          /* file for # defines */
extern FILE * ftable;           /* y.tab.c file */
extern FILE * ftemp;            /* tempfile to pass 2 */
extern FILE * fdebug;           /* tempfile for two debugging info arrays */
extern FILE * foutput;          /* y.output file */

        /* structure declarations */

struct looksets {
        int *lset;
        };

struct item {
        int *pitem;
        struct looksets *look;
        };

struct toksymb {
        char *name;
        int value;
        };

struct ntsymb {
        char *name;
        int tvalue;
        };

struct wset {
        int *pitem;
        int flag;
        struct looksets ws;
        };

        /* special flag for splitting yyparse into many small routines */
extern SplitFlag;

        /* token information */       

extern int ntokens ;    /* number of tokens */
extern struct toksymb *tokset;
extern int *toklev;    /* vector with the precedence of the terminals */

        /* nonterminal information */

extern int nnonter ;    /* the number of nonterminals */
extern struct ntsymb *nontrst;

        /* grammar rule information */

extern int nprod ;      /* number of productions */
extern int **prdptr;   /* pointers to descriptions of productions */
extern int *levprd ;   /* contains production levels to break conflicts */
extern char *had_act;  /* set if reduction has associated action code */

        /* state information */

extern int nstate ;             /* number of states */
extern struct item **pstate;   /* pointers to the descriptions
                                 * of the states */
extern int *tystate;   /* contains type information about the states */
extern int *defact;    /* the default action of the state */
extern int *tstates;   /* the states deriving each token */
extern int *ntstates;  /* the states deriving each nonterminal */
extern int *mstates;   /* the continuation of the chains begun
                         * in tstates and ntstates */

        /* lookahead set information */

extern struct looksets *lkst;
extern int nolook;  /* flag to turn off lookahead computations */
extern struct looksets clset; /* temporary storage for look ahead set */

        /* working set information */

extern struct wset *wsets;
extern struct wset *cwp;

        /* storage for productions */

extern int *mem0;
extern int *mem;
extern int memsize;

        /* storage for action table */

extern int *amem;  /* action table storage */
extern int *memp ;              /* next free action table position */
extern int *indgo;             /* index to the stored goto table */

        /* storage for information about non terminals */

extern int ***pres;
extern struct looksets **pfirst;
extern int *pempty;

        /* buffer sizes */

extern int actsize;
extern int numprod;
extern int nstates;
extern int nterms;
extern int nnonterms;
extern int wsetsize;
extern int tempsize;

        /* temporary vector, indexable by states, terms, or ntokens */

extern int *temp1;
extern int lineno; /* current line number */
extern int *pgo;
extern int *yypgo;

        /* statistics collection variables */

extern int zzgoent ;
extern int zzgobest ;
extern int zzacent ;
extern int zzexcp ;
extern int zzclose ;
extern int zzrrconf ;
extern int zzsrconf ;
        /* define functions with strange types... */

extern char *cstash();
extern struct looksets *flset();
extern char *symnam();
extern char *writem();

        /* default settings for a number of macros */

        /* name of yacc tempfiles */

# ifndef TEMPNAME
# define TEMPNAME "yacc.tmp"
# endif

# ifndef ACTNAME
# define ACTNAME "yacc.acts"
# endif

# ifndef DEBUGNAME
# define DEBUGNAME "yacc.debug"
# endif

        /* output file name */

char *prefix;
char *ofile;

        /* user output file name */

char *fileu;

        /* user-defined parser name */

extern char     *ParserPath;

       /* output file for # defines */

char *filed;
extern char *infile;   /* points to the name of .y input file  */
extern int gen_lines;  /* flag for generating the # line's     */
        /* command to clobber tempfiles after use */

# ifndef ZAPFILE
# define ZAPFILE(x) unlink(x)
# endif
