xref: /csrg-svn/usr.bin/pascal/eyacc/ey0.c (revision 19569)
1*19569Smckusick /*
2*19569Smckusick  * Copyright (c) 1979 Regents of the University of California.
3*19569Smckusick  * All rights reserved.  The Berkeley software License Agreement
4*19569Smckusick  * specifies the terms and conditions for redistribution.
5*19569Smckusick  */
6*19569Smckusick 
7*19569Smckusick #ifndef lint
8*19569Smckusick char copyright[] =
9*19569Smckusick "@(#) Copyright (c) 1980 Regents of the University of California.\n\
10*19569Smckusick  All rights reserved.\n";
11*19569Smckusick #endif not lint
12*19569Smckusick 
13*19569Smckusick #ifndef lint
14*19569Smckusick static char sccsid[] = "@(#)ey0.c	5.1 (Berkeley) 04/29/85";
15*19569Smckusick #endif not lint
16*19569Smckusick 
17*19569Smckusick #include <stdio.h>
18*19569Smckusick # define _actsize 2500
19*19569Smckusick # define _memsize 3000
20*19569Smckusick # define _nstates 700
21*19569Smckusick # define _nterms 95
22*19569Smckusick # define _nprod 300
23*19569Smckusick # define _nnonterm 150
24*19569Smckusick # define _tempsize 700
25*19569Smckusick # define _cnamsz 3500
26*19569Smckusick # define _lsetsize 600
27*19569Smckusick # define _wsetsize 400
28*19569Smckusick # define _maxlastate 100
29*19569Smckusick 
30*19569Smckusick # define _tbitset 6
31*19569Smckusick 
32*19569Smckusick int tbitset;  /* size of lookahed sets */
33*19569Smckusick int nolook = 0; /* flag to suppress lookahead computations */
34*19569Smckusick struct looksets { int lset[ _tbitset ]; } ;
35*19569Smckusick struct item { int *pitem; } ;
36*19569Smckusick 
37*19569Smckusick /* this file contains the definitions for most externally known data */
38*19569Smckusick 
39*19569Smckusick int nstate = 0;		/* number of states */
40*19569Smckusick struct item *pstate[_nstates];	/* pointers to the descriptions of the states */
41*19569Smckusick int apstate[_nstates];	/* index to the actions for the states */
42*19569Smckusick int tystate[_nstates];	/* contains type information about the states */
43*19569Smckusick int stsize = _nstates;	/* maximum number of states, at present */
44*19569Smckusick int memsiz = _memsize;	/* maximum size for productions and states */
45*19569Smckusick int mem0[_memsize] ; /* production storage */
46*19569Smckusick int *mem = mem0;
47*19569Smckusick int amem[_actsize];  /* action table storage */
48*19569Smckusick int actsiz = _actsize; /* action table size */
49*19569Smckusick int memact = 0;		/* next free action table position */
50*19569Smckusick int nprod = 1;	/* number of productions */
51*19569Smckusick int *prdptr[_nprod];	/* pointers to descriptions of productions */
52*19569Smckusick int prdlim = _nprod ;  /* the maximum number of productions */
53*19569Smckusick 	/* levprd - productions levels to break conflicts */
54*19569Smckusick int levprd[_nprod] = {0,0};
55*19569Smckusick   /* last two bits code associativity:
56*19569Smckusick        0 = no definition
57*19569Smckusick        1 = left associative
58*19569Smckusick        2 = binary
59*19569Smckusick        3 = right associative
60*19569Smckusick      bit 04 is 1 if the production has an action
61*19569Smckusick      the high 13 bits have the production level
62*19569Smckusick      */
63*19569Smckusick int nterms = 0;	/* number of terminals */
64*19569Smckusick int tlim = _nterms ; /* the maximum number of terminals */
65*19569Smckusick /*	the ascii representations of the terminals	*/
66*19569Smckusick int extval = 0;  /* start of output values */
67*19569Smckusick struct sxxx1 {char *name; int value;} trmset[_nterms];
68*19569Smckusick char cnames[_cnamsz];
69*19569Smckusick int cnamsz = _cnamsz;
70*19569Smckusick char *cnamp;
71*19569Smckusick int maxtmp = _tempsize;	/* the size of the temp1 array */
72*19569Smckusick int temp1[_tempsize]; /* temporary storage, indexed by terms + nterms or states */
73*19569Smckusick int temp2[_nnonterm]; /* temporary storage indexed by nonterminals */
74*19569Smckusick int trmlev[_nterms];	/* vector with the precedence of the terminals */
75*19569Smckusick   /* The levels are the same as for levprd, but bit 04 is always 0 */
76*19569Smckusick /* the ascii representations of the nonterminals */
77*19569Smckusick struct sxxx2 { char *name; } nontrst[_nnonterm];
78*19569Smckusick int ntlim = _nnonterm ; /* limit to the number of nonterminals */
79*19569Smckusick int indgo[_nstates];		/* index to the stored goto table */
80*19569Smckusick int ***pres; /* vector of pointers to the productions yielding each nonterminal */
81*19569Smckusick struct looksets **pfirst; /* vector of pointers to first sets for each nonterminal */
82*19569Smckusick int *pempty = 0 ; /* table of nonterminals nontrivially deriving e */
83*19569Smckusick int nnonter = -1;	/* the number of nonterminals */
84*19569Smckusick int lastred = 0;	/* the number of the last reduction of a state */
85*19569Smckusick FILE *ftable;		/* y.tab.c file */
86*19569Smckusick FILE *foutput;		/* y.output file */
87*19569Smckusick FILE *cout = stdout;
88*19569Smckusick int arrndx; /* used in the output of arrays on y.tab.c */
89*19569Smckusick int zzcwset = 0;
90*19569Smckusick int zzpairs = 0;
91*19569Smckusick int zzgoent = 0;
92*19569Smckusick int zzgobest = 0;
93*19569Smckusick int zzacent = 0;
94*19569Smckusick int zzacsave = 0;
95*19569Smckusick int zznsave = 0;
96*19569Smckusick int zzclose = 0;
97*19569Smckusick int zzsrconf = 0;
98*19569Smckusick int zzrrconf = 0;
99*19569Smckusick char *ctokn;
100*19569Smckusick int lineno  = 1; /* current input line number */
101*19569Smckusick int peekc = -1; /* look-ahead character */
102*19569Smckusick int tstates[ _nterms ]; /* states generated by terminal gotos */
103*19569Smckusick int ntstates[ _nnonterm ]; /* states generated by nonterminal gotos */
104*19569Smckusick int mstates[ _nstates ]; /* chain of overflows of term/nonterm generation lists  */
105*19569Smckusick 
106*19569Smckusick struct looksets clset;
107*19569Smckusick struct looksets lkst [ _lsetsize ];
108*19569Smckusick int nlset = 0; /* next lookahead set index */
109*19569Smckusick int lsetsz = _lsetsize; /* number of lookahead sets */
110*19569Smckusick 
111*19569Smckusick struct wset { int *pitem, flag, ws[_tbitset]; } wsets[ _wsetsize ];
112*19569Smckusick int cwset;
113*19569Smckusick int wssize = _wsetsize;
114*19569Smckusick int lambdarule = 0;
115*19569Smckusick 
116*19569Smckusick char stateflags[ _nstates ];
117*19569Smckusick unsigned char lookstate[ _nstates ];
118*19569Smckusick struct looksets lastate[ _maxlastate ];
119*19569Smckusick int maxlastate = _maxlastate;
120*19569Smckusick int savedlook = 1;
121*19569Smckusick 
122*19569Smckusick int numbval;  /* the value of an input number */
123*19569Smckusick int rflag = 0;  /* ratfor flag */
124*19569Smckusick int oflag = 0;  /* optimization flag */
125*19569Smckusick 
126*19569Smckusick int ndefout = 3;  /* number of defined symbols output */
127*19569Smckusick int nerrors = 0;	/* number of errors */
128*19569Smckusick int fatfl = 1;  	/* if on, error is fatal */
129*19569Smckusick int machine;   /* has a number describing the machine */
130*19569Smckusick 
131