xref: /csrg-svn/usr.bin/pascal/src/yy.h (revision 742)
1*742Speter /* Copyright (c) 1979 Regents of the University of California */
2*742Speter 
3*742Speter /* static	char sccsid[] = "@(#)yy.h 1.1 08/27/80"; */
4*742Speter 
5*742Speter #include "y.tab.h"
6*742Speter /*
7*742Speter  * INPUT/OUTPUT
8*742Speter  */
9*742Speter 
10*742Speter /*
11*742Speter  * The buffer for the input file is normally "ibuf".
12*742Speter  * When files are included, however, this may be
13*742Speter  * pushed down in the stack of currently active
14*742Speter  * files. For this reason, the pointer ibp always
15*742Speter  * references the i/o buffer of the current input file.
16*742Speter  */
17*742Speter FILE		*ibuf, *ibp;
18*742Speter 
19*742Speter /*
20*742Speter  * Line and token buffers.  Charbuf is the character buffer for
21*742Speter  * input lines, token the buffer for tokens returned
22*742Speter  * by the scanner.  CBSIZE defines the maximum line
23*742Speter  * length allowed on input and is doubtless too small.
24*742Speter  * The token buffer should be a local array in yylex.
25*742Speter  */
26*742Speter #define CBSIZE 161
27*742Speter 
28*742Speter char	charbuf[CBSIZE], *bufp, token[CBSIZE];
29*742Speter 
30*742Speter #define digit(c)	(c >= '0' && c <= '9')
31*742Speter #define alph(c)		((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
32*742Speter 
33*742Speter /*
34*742Speter  * Flag to prevent reprinting current line after
35*742Speter  * an error.
36*742Speter  */
37*742Speter char	yyprtd;
38*742Speter 
39*742Speter /*
40*742Speter  * The following variables are maintained by
41*742Speter  * the scanner in the file lex and used in scanning
42*742Speter  * and in parsing.
43*742Speter  *
44*742Speter  * The variable yychar is the current scanner character.
45*742Speter  * Currently, the scanner must be called as
46*742Speter  *	yychar = yylex()
47*742Speter  * even though it should set yychar itself.
48*742Speter  * Yychar has value YEOF at end of file, and negative value if
49*742Speter  * there is no yychar, e.g. after a shift in the parser.
50*742Speter  *
51*742Speter  * The variable yycol is the current column in the line whose number
52*742Speter  * is given by yyline.  Yyecol and yyeline give the position for an
53*742Speter  * error message to flag, usually the start of an input token.
54*742Speter  * Yylval is the semantic return from the scanner.
55*742Speter  *
56*742Speter  * In fact all of these variables are "per token".
57*742Speter  * In the usual case, only the copies in the scanner token structure
58*742Speter  * 'Y' are used, and the #defines below serve to make them look
59*742Speter  * like variables.
60*742Speter  *
61*742Speter  * For the purposes of the error recovery, however, they are copied
62*742Speter  * and restored quite freely.  For the error recovery also, the
63*742Speter  * file name which the input line this token is on and the seek
64*742Speter  * pointer of this line in its source file are saved as yyefile
65*742Speter  * and yyseekp.  The global variable yylinpt is the seek pointer
66*742Speter  * of the current input line.
67*742Speter  */
68*742Speter int	yycol;
69*742Speter int	yyline;
70*742Speter int	yyseqid;
71*742Speter int	yysavc;
72*742Speter int	yylinpt;
73*742Speter 
74*742Speter /* *** NOTE ***
75*742Speter  * It would be much better to not have the Yyeline and Yyefile
76*742Speter  * in the scanner structure and to have a mechanism for mapping
77*742Speter  * seqid's to these globally.
78*742Speter  */
79*742Speter struct yytok {
80*742Speter 	int	Yychar;
81*742Speter 	int	Yylval;
82*742Speter 	int	Yyecol;
83*742Speter 	int	Yyeline;
84*742Speter 	int	Yyseekp;
85*742Speter 	char	*Yyefile;
86*742Speter 	int	Yyeseqid;
87*742Speter } Y, OY;
88*742Speter 
89*742Speter #define	yychar	Y.Yychar
90*742Speter #define	yylval	Y.Yylval
91*742Speter #define	yyecol	Y.Yyecol
92*742Speter #define	yyeline	Y.Yyeline
93*742Speter #define	yyseekp	Y.Yyseekp
94*742Speter #define	yyefile	Y.Yyefile
95*742Speter #define	yyeseqid Y.Yyeseqid
96*742Speter 
97*742Speter /*
98*742Speter  * Yyval is the semantic value returned by a reduction.
99*742Speter  * It is what "$$" is expanded to by yacc.
100*742Speter  */
101*742Speter int	*Ps, *yyval;
102*742Speter 
103*742Speter /*
104*742Speter  * N is the length of a reduction.
105*742Speter  * Used externally by "lineof" to get the left and
106*742Speter  * right margins for a reduction.
107*742Speter  */
108*742Speter int	N;
109*742Speter /*
110*742Speter  * Definitions for looking up keywords.
111*742Speter  * The keyword array is called yykey, and
112*742Speter  * lastkey points at the end of it.
113*742Speter  */
114*742Speter char	*lastkey;
115*742Speter 
116*742Speter struct kwtab {
117*742Speter 	char	*kw_str;
118*742Speter 	int	kw_val;
119*742Speter } yykey[];
120*742Speter 
121*742Speter /*
122*742Speter  * ERROR RECOVERY EXTERNALS
123*742Speter  */
124*742Speter 
125*742Speter #define	CLIMIT	40	/* see yyrecover.c */
126*742Speter char	*tokname();
127*742Speter char	*charname();
128*742Speter 
129*742Speter char	*classes[];
130*742Speter 
131*742Speter /*
132*742Speter  * Tokens which yacc doesn't define
133*742Speter  */
134*742Speter #define	YEOF	0
135*742Speter #define	ERROR	256
136*742Speter 
137*742Speter /*
138*742Speter  * Limit on the number of syntax errors
139*742Speter  */
140*742Speter #define	MAXSYNERR	100
141*742Speter 
142*742Speter /*
143*742Speter  * Big costs
144*742Speter  */
145*742Speter #define	HUGE		50
146*742Speter #define	INFINITY	100
147*742Speter 
148*742Speter /*
149*742Speter  * Kinds of panics
150*742Speter  */
151*742Speter #define	PDECL	0
152*742Speter #define	PSTAT	1
153*742Speter #define	PEXPR	2
154*742Speter #define	PPROG	3
155*742Speter 
156*742Speter #define	yyresume()	yyResume = 1;
157*742Speter 
158*742Speter char	yyResume;
159*742Speter 
160*742Speter char	dquote;
161*742Speter 
162*742Speter char	errout;
163*742Speter 
164*742Speter /*
165*742Speter  * Yyidwant and yyidhave are the namelist classes
166*742Speter  * of identifiers associated with a identifier reduce
167*742Speter  * error, set before the recovery is called.
168*742Speter  * Since they may be set again during the forward move
169*742Speter  * they must be saved by yyrecover, which uses them in printing
170*742Speter  * error messages.
171*742Speter  */
172*742Speter int	yyidhave, yyidwant;
173*742Speter 
174*742Speter /*
175*742Speter  * The variables yy*shifts are used to prevent looping and the printing
176*742Speter  * of spurious messages in the parser.  Yyshifts gives the number of
177*742Speter  * true input shifts since the last corrective action.  YyOshifts
178*742Speter  * is the value of yyshifts before it was last cleared, and is used
179*742Speter  * by yyPerror in yypanic.c to suppress messages.
180*742Speter  *
181*742Speter  * Yytshifts counts true input shifts.  It is used to prevent looping
182*742Speter  * inserting unique symbols.  If yytshifts == yyTshifts (local to
183*742Speter  * yyrecover.c) then there has been no shift over true input since
184*742Speter  * the last unique symbol insertion.  We refuse, in this case,
185*742Speter  * to insert more unique symbols so as to prevent looping.
186*742Speter  *
187*742Speter  * The recovery cannot loop because it guarantees the progress of the
188*742Speter  * parse, i.e.:
189*742Speter  *
190*742Speter  *	1) Any insertion guarantees to shift over 2 symbols, a replacement
191*742Speter  *	   over one symbol.
192*742Speter  *
193*742Speter  *	2) Unique symbol insertions are limited to one for each true
194*742Speter  *	   symbol of input, or "safe" insertion of the keywords "end"
195*742Speter  *	   and "until" at zero cost (safe since these are know to match
196*742Speter  *	   stack that cannot have been generated - e.g. "begin" or "repeat")
197*742Speter  *
198*742Speter  *	3) We never panic more than once from a given state without
199*742Speter  *	   shifting over input, i.e. we force the parse stack to shrink
200*742Speter  *	   after each unsuccessful panic.
201*742Speter  */
202*742Speter int	yyshifts, yyOshifts;
203*742Speter unsigned yytshifts;
204*742Speter 
205*742Speter #ifdef PXP
206*742Speter 
207*742Speter /*
208*742Speter  * Identifier class definitions
209*742Speter  */
210*742Speter #define	UNDEF	0
211*742Speter #define	CONST	1
212*742Speter #define	TYPE	2
213*742Speter #define	VAR	3
214*742Speter #define	ARRAY	4
215*742Speter #define	PTRFILE	5
216*742Speter #define	RECORD	6
217*742Speter #define	FIELD	7
218*742Speter #define	PROC	8
219*742Speter #define	FUNC	9
220*742Speter #define	FVAR	10
221*742Speter #define	REF	11
222*742Speter #define	PTR	12
223*742Speter #define	FILET	13
224*742Speter #define	SET	14
225*742Speter #define	RANGE	15
226*742Speter #define	LABEL	16
227*742Speter #define	WITHPTR 17
228*742Speter #define	SCAL	18
229*742Speter #define	STR	19
230*742Speter #define	PROG	20
231*742Speter #define	IMPROPER 21
232*742Speter 
233*742Speter /*
234*742Speter  * COMMENT FORMATTING DEFINITIONS
235*742Speter  */
236*742Speter 
237*742Speter /*
238*742Speter  * Count of tokens on this input line
239*742Speter  * Note that this can be off if input is not syntactically correct.
240*742Speter  */
241*742Speter int	yytokcnt;
242*742Speter int	yywhcnt;
243*742Speter 
244*742Speter /*
245*742Speter  * Types of comments
246*742Speter  */
247*742Speter #define	CLMARG	0
248*742Speter #define	CALIGN	1
249*742Speter #define	CTRAIL	2
250*742Speter #define	CRMARG	3
251*742Speter #define	CSRMARG	4
252*742Speter #define	CNL	5
253*742Speter #define	CNLBL	6
254*742Speter #define	CFORM	7
255*742Speter #define	CINCLUD	8
256*742Speter 
257*742Speter /*
258*742Speter  * Comment structure
259*742Speter  * Cmhp is the head of the current list of comments
260*742Speter  */
261*742Speter struct comment {
262*742Speter 	struct	comment *cmnext;
263*742Speter 	int	cmdelim;
264*742Speter 	struct	commline *cml;
265*742Speter 	int	cmjust;
266*742Speter 	int	cmseqid;
267*742Speter } *cmhp;
268*742Speter 
269*742Speter /*
270*742Speter  * Structure for holding a comment line
271*742Speter  */
272*742Speter struct commline {
273*742Speter 	char	*cmtext;
274*742Speter 	int	cmcol;	/* Only used for first line of comment currently */
275*742Speter 	struct	commline *cml;
276*742Speter };
277*742Speter 
278*742Speter struct W {
279*742Speter 	int	Wseqid;
280*742Speter 	int	Wcol;
281*742Speter } yyw[MAXDEPTH + 1], *yypw;
282*742Speter 
283*742Speter #define	commform()	quickcomm(CFORM)
284*742Speter #define	commnl()	quickcomm(CNL)
285*742Speter #define	commnlbl()	quickcomm(CNLBL)
286*742Speter #endif
287