/* #ident	"@(#)yacc:dextern	1.6" */
#ident	"$Header: /proj/irix6.5.7m/isms/eoe/cmd/yacc/RCS/dextern,v 1.15 1996/03/19 23:39:36 danc Exp $"

# include <stdlib.h>
# include <stddef.h>
# include <unistd.h>
# include <getopt.h>
# include <stdio.h>
# include <ctype.h>
# include <memory.h>
# include <string.h>
# include <malloc.h>
# include <values.h>
# include <locale.h>
# include <stdarg.h>
# include <pfmt.h>
# include <errno.h>

	/*  MANIFEST CONSTANT DEFINITIONS */

#if u3b || u3b15 || u3b2 || vax || uts || mips
#	define WORD32
#endif

	/* base of nonterminal internal numbers */
# define NTBASE (10000000)

	/* internal codes for error and accept actions */

# define ERRCODE  8190
# define ACCEPTCODE 8191

	/* sizes and limits */

# define ACTSIZE 24000
# define MEMSIZE 48000
# define PSTSIZE 4096
# define NSTATES 1500
# define NTERMS 600
# define NPROD 1200
# define NNONTERM 2000
# define TEMPSIZE 5200
# define CNAMSZ 6250
# define LSETSIZE 2400
# define WSETSIZE 2000
# define NAMESIZE 50
# define NTYPES 127

#ifdef WORD32
	/* 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

	/* 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
	LSETSIZE >= 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

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

	/* bit field descriptions of toklev and levprd entries */
typedef	struct toklev_s {
	unsigned int	:15;
	unsigned int	type	:7;	/* must match bit size of NTYPES */
	unsigned int	plev	:6;
	unsigned int	red	:1;
	unsigned int	assoc	:3;
	} TOKLEV;

	/* macros for getting associativity and precedence levels */
#define ASSOC(i)        ((TOKLEV*)(&i))->assoc
#define PLEVEL(i)       ((TOKLEV*)(&i))->plev
#define TYPE(i)         ((TOKLEV*)(&i))->type
#define REDBIT(i)	((TOKLEV*)(&i))->red

	/* macros for setting associativity and precedence levels */
#define SETASC(i,j)     (((TOKLEV*)(&i))->assoc |= (j))
#define SETPLEV(i,j)    (((TOKLEV*)(&i))->plev  |= (j))
#define SETTYPE(i,j)    (((TOKLEV*)(&i))->type  |= (j))
#define SETRED(i,j)	(((TOKLEV*)(&i))->red |= (j))

	/* 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<&wsets[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)

	/* I/O descriptors */

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 */

typedef struct looksets {
	int *lset;
} LOOKSETS;

typedef struct item {
	int *pitem;
	LOOKSETS *look;
} ITEM;

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

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

typedef struct wset {
	int *pitem;
	int flag;
	LOOKSETS ws;
} WSET;

	/* token information */

extern int ntokens ;	/* number of tokens */
extern TOKSYMB *tokset;
extern int ntoksz;

	/* nonterminal information */

extern int nnonter ;	/* the number of nonterminals */
extern NTSYMB *nontrst;
extern int nnontersz;

	/* 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 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 size;

	/* lookahead set information */

extern int TBITSET;
extern LOOKSETS *lkst;
extern int nolook;  /* flag to turn off lookahead computations */

	/* working set information */

extern WSET *wsets;

	/* storage for productions */

extern int *mem0;
extern int *mem;
extern int *tracemem;
extern int new_memsize;

	/* storage for action table */

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

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

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

	/* statistics collection variables */

extern int zzgoent ;
extern int zzgobest ;
extern int zzacent ;
extern int zzexcp ;
extern int zzrrconf ;
extern int zzsrconf ;
 
	/* define external functions */

extern void setup(int argc, char *argv[]);
extern void closure(int i);
extern void output_prefix(void);
extern void output(void);
extern void aryfil(int *v, int n, int c);
extern void error(const char *msgid, const char *fmt, ...);
extern void putitem(int *ptr, LOOKSETS *lptr);
extern void go2out(void);
extern void hideprod(void);
extern void callopt(void);
extern void warray(char *s, int *v, int n);
extern char *symnam(int i);
extern char *writem(int *pp);
extern void exp_mem(int flag);
extern void exp_act(int **ptr);
extern int apack(int *p, int n);
extern int state(int c);

	/* yaccpar location */

extern char *parser;

       /* Symbol Prefix */
extern char *symbol_prefix;

	/* default settings for a number of macros */

	/* name of yacc tempfiles */

# ifndef TEMPNAME
#	ifndef sgi
#	 	define TEMPNAME "yacc.tmp"
#	else
#		define TEMPNAME_FILE "yacc.tmp"
#		define TEMPNAME tempname_buf
		extern char *TEMPNAME;
#	endif
# endif

# ifndef ACTNAME
#	ifndef sgi
#	 	define ACTNAME "yacc.acts"
#	else
#		define ACTNAME_FILE "yacc.acts"
#		define ACTNAME actname_buf
		extern char *ACTNAME;
#	endif
# endif

# ifndef DEBUGNAME
#	ifndef sgi
#	 	define DEBUGNAME "yacc.debug"
#	else
#	 	define DEBUGNAME_FILE "yacc.debug"
#		define DEBUGNAME debugname_buf
		extern char *DEBUGNAME;
#	endif
# endif

	/* output file name */

# ifndef OFILE
# 	define OFILE "y.tab.c"
# endif

	/* user output file name */

# ifndef FILEU
# 	define FILEU "y.output"
# endif

	/* output file for # defines */

# ifndef FILED
# 	define FILED "y.tab.h"
# endif

	/* command to clobber tempfiles after use */

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

# ifndef PARSER
# 	define PARSER "/usr/lib/yaccpar"
# endif

extern int is_y_plus_plus;	/* use C++ style input */
