xref: /csrg-svn/usr.bin/pascal/src/yy.h (revision 23622)
122256Sdist /*
222256Sdist  * Copyright (c) 1980 Regents of the University of California.
322256Sdist  * All rights reserved.  The Berkeley software License Agreement
422256Sdist  * specifies the terms and conditions for redistribution.
522256Sdist  *
6*23622Smckusick  *	@(#)yy.h	5.2 (Berkeley) 06/21/85
722256Sdist  */
8742Speter 
9742Speter #include "y.tab.h"
10*23622Smckusick #undef CBSIZE	/* from paramsys/param.h */
11742Speter /*
12742Speter  * INPUT/OUTPUT
13742Speter  */
14742Speter 
15742Speter /*
16742Speter  * The buffer for the input file is normally "ibuf".
17742Speter  * When files are included, however, this may be
18742Speter  * pushed down in the stack of currently active
19742Speter  * files. For this reason, the pointer ibp always
20742Speter  * references the i/o buffer of the current input file.
21742Speter  */
22742Speter FILE		*ibuf, *ibp;
23742Speter 
24742Speter /*
25742Speter  * Line and token buffers.  Charbuf is the character buffer for
26742Speter  * input lines, token the buffer for tokens returned
27742Speter  * by the scanner.  CBSIZE defines the maximum line
28742Speter  * length allowed on input and is doubtless too small.
29742Speter  * The token buffer should be a local array in yylex.
30742Speter  */
3112395Speter #ifdef ADDR16
32742Speter #define CBSIZE 161
3312395Speter #endif ADDR16
3412395Speter #ifdef ADDR32
3512395Speter #define CBSIZE 1024
3612395Speter #endif ADDR32
37742Speter 
38742Speter char	charbuf[CBSIZE], *bufp, token[CBSIZE];
39742Speter 
40742Speter #define digit(c)	(c >= '0' && c <= '9')
41742Speter #define alph(c)		((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
42742Speter 
43742Speter /*
44742Speter  * Flag to prevent reprinting current line after
45742Speter  * an error.
46742Speter  */
47742Speter char	yyprtd;
48742Speter 
49742Speter /*
50742Speter  * The following variables are maintained by
51742Speter  * the scanner in the file lex and used in scanning
52742Speter  * and in parsing.
53742Speter  *
54742Speter  * The variable yychar is the current scanner character.
55742Speter  * Currently, the scanner must be called as
56742Speter  *	yychar = yylex()
57742Speter  * even though it should set yychar itself.
58742Speter  * Yychar has value YEOF at end of file, and negative value if
59742Speter  * there is no yychar, e.g. after a shift in the parser.
60742Speter  *
61742Speter  * The variable yycol is the current column in the line whose number
62742Speter  * is given by yyline.  Yyecol and yyeline give the position for an
63742Speter  * error message to flag, usually the start of an input token.
64742Speter  * Yylval is the semantic return from the scanner.
65742Speter  *
66742Speter  * In fact all of these variables are "per token".
67742Speter  * In the usual case, only the copies in the scanner token structure
68742Speter  * 'Y' are used, and the #defines below serve to make them look
69742Speter  * like variables.
70742Speter  *
71742Speter  * For the purposes of the error recovery, however, they are copied
72742Speter  * and restored quite freely.  For the error recovery also, the
73742Speter  * file name which the input line this token is on and the seek
74742Speter  * pointer of this line in its source file are saved as yyefile
75742Speter  * and yyseekp.  The global variable yylinpt is the seek pointer
76742Speter  * of the current input line.
77742Speter  */
78742Speter int	yycol;
79742Speter int	yyline;
80742Speter int	yyseqid;
81742Speter int	yysavc;
82742Speter int	yylinpt;
83742Speter 
84742Speter /* *** NOTE ***
85742Speter  * It would be much better to not have the Yyeline and Yyefile
86742Speter  * in the scanner structure and to have a mechanism for mapping
87742Speter  * seqid's to these globally.
88742Speter  */
89742Speter struct yytok {
90742Speter 	int	Yychar;
91742Speter 	int	Yylval;
92742Speter 	int	Yyecol;
93742Speter 	int	Yyeline;
94742Speter 	int	Yyseekp;
95742Speter 	char	*Yyefile;
96742Speter 	int	Yyeseqid;
97742Speter } Y, OY;
98742Speter 
99742Speter #define	yychar	Y.Yychar
100742Speter #define	yylval	Y.Yylval
101742Speter #define	yyecol	Y.Yyecol
102742Speter #define	yyeline	Y.Yyeline
103742Speter #define	yyseekp	Y.Yyseekp
104742Speter #define	yyefile	Y.Yyefile
105742Speter #define	yyeseqid Y.Yyeseqid
106742Speter 
10714751Sthien /* Semantic Stack so that y.tab.c will lint */
10814751Sthien 
10914751Sthien union semstack
11014751Sthien {
11114751Sthien     int		  i_entry;
11214751Sthien     struct nl	 *nl_entry;
11314751Sthien     struct tnode *tr_entry;
11414751Sthien     char	 *cptr;
11514751Sthien } yyval;
11614751Sthien 
117742Speter /*
118742Speter  * Yyval is the semantic value returned by a reduction.
119742Speter  * It is what "$$" is expanded to by yacc.
120742Speter  */
121742Speter 
12214751Sthien int	*Ps;
12314751Sthien 
124742Speter /*
125742Speter  * N is the length of a reduction.
126742Speter  * Used externally by "lineof" to get the left and
127742Speter  * right margins for a reduction.
128742Speter  */
129742Speter int	N;
130742Speter /*
131742Speter  * Definitions for looking up keywords.
132742Speter  * The keyword array is called yykey, and
133742Speter  * lastkey points at the end of it.
134742Speter  */
135742Speter char	*lastkey;
136742Speter 
137742Speter struct kwtab {
138742Speter 	char	*kw_str;
139742Speter 	int	kw_val;
140742Speter } yykey[];
141742Speter 
142742Speter /*
143742Speter  * ERROR RECOVERY EXTERNALS
144742Speter  */
145742Speter 
146742Speter #define	CLIMIT	40	/* see yyrecover.c */
147742Speter char	*tokname();
148742Speter char	*charname();
149742Speter 
150742Speter char	*classes[];
151742Speter 
152742Speter /*
153742Speter  * Tokens which yacc doesn't define
154742Speter  */
155742Speter #define	YEOF	0
156742Speter #define	ERROR	256
157742Speter 
158742Speter /*
159742Speter  * Limit on the number of syntax errors
160742Speter  */
161742Speter #define	MAXSYNERR	100
162742Speter 
163742Speter /*
164742Speter  * Big costs
165742Speter  */
166742Speter #define	HUGE		50
167742Speter #define	INFINITY	100
168742Speter 
169742Speter /*
170742Speter  * Kinds of panics
171742Speter  */
172742Speter #define	PDECL	0
173742Speter #define	PSTAT	1
174742Speter #define	PEXPR	2
175742Speter #define	PPROG	3
176742Speter 
177742Speter #define	yyresume()	yyResume = 1;
178742Speter 
179742Speter char	yyResume;
180742Speter 
181742Speter char	dquote;
182742Speter 
18314751Sthien #ifndef PC
18414751Sthien #ifndef OBJ
185742Speter char	errout;
18614751Sthien #endif OBJ
18714751Sthien #endif PC
188742Speter 
189742Speter /*
190742Speter  * Yyidwant and yyidhave are the namelist classes
191742Speter  * of identifiers associated with a identifier reduce
192742Speter  * error, set before the recovery is called.
193742Speter  * Since they may be set again during the forward move
194742Speter  * they must be saved by yyrecover, which uses them in printing
195742Speter  * error messages.
196742Speter  */
197742Speter int	yyidhave, yyidwant;
198742Speter 
199742Speter /*
200742Speter  * The variables yy*shifts are used to prevent looping and the printing
201742Speter  * of spurious messages in the parser.  Yyshifts gives the number of
202742Speter  * true input shifts since the last corrective action.  YyOshifts
203742Speter  * is the value of yyshifts before it was last cleared, and is used
204742Speter  * by yyPerror in yypanic.c to suppress messages.
205742Speter  *
206742Speter  * Yytshifts counts true input shifts.  It is used to prevent looping
207742Speter  * inserting unique symbols.  If yytshifts == yyTshifts (local to
208742Speter  * yyrecover.c) then there has been no shift over true input since
209742Speter  * the last unique symbol insertion.  We refuse, in this case,
210742Speter  * to insert more unique symbols so as to prevent looping.
211742Speter  *
212742Speter  * The recovery cannot loop because it guarantees the progress of the
213742Speter  * parse, i.e.:
214742Speter  *
215742Speter  *	1) Any insertion guarantees to shift over 2 symbols, a replacement
216742Speter  *	   over one symbol.
217742Speter  *
218742Speter  *	2) Unique symbol insertions are limited to one for each true
219742Speter  *	   symbol of input, or "safe" insertion of the keywords "end"
220742Speter  *	   and "until" at zero cost (safe since these are know to match
221742Speter  *	   stack that cannot have been generated - e.g. "begin" or "repeat")
222742Speter  *
223742Speter  *	3) We never panic more than once from a given state without
224742Speter  *	   shifting over input, i.e. we force the parse stack to shrink
225742Speter  *	   after each unsuccessful panic.
226742Speter  */
227742Speter int	yyshifts, yyOshifts;
228742Speter unsigned yytshifts;
229742Speter 
230742Speter #ifdef PXP
231742Speter 
232742Speter /*
233742Speter  * Identifier class definitions
234742Speter  */
235742Speter #define	UNDEF	0
236742Speter #define	CONST	1
237742Speter #define	TYPE	2
238742Speter #define	VAR	3
239742Speter #define	ARRAY	4
240742Speter #define	PTRFILE	5
241742Speter #define	RECORD	6
242742Speter #define	FIELD	7
243742Speter #define	PROC	8
244742Speter #define	FUNC	9
245742Speter #define	FVAR	10
246742Speter #define	REF	11
247742Speter #define	PTR	12
248742Speter #define	FILET	13
249742Speter #define	SET	14
250742Speter #define	RANGE	15
251742Speter #define	LABEL	16
252742Speter #define	WITHPTR 17
253742Speter #define	SCAL	18
254742Speter #define	STR	19
255742Speter #define	PROG	20
256742Speter #define	IMPROPER 21
257742Speter 
258742Speter /*
259742Speter  * COMMENT FORMATTING DEFINITIONS
260742Speter  */
261742Speter 
262742Speter /*
263742Speter  * Count of tokens on this input line
264742Speter  * Note that this can be off if input is not syntactically correct.
265742Speter  */
266742Speter int	yytokcnt;
267742Speter int	yywhcnt;
268742Speter 
269742Speter /*
270742Speter  * Types of comments
271742Speter  */
272742Speter #define	CLMARG	0
273742Speter #define	CALIGN	1
274742Speter #define	CTRAIL	2
275742Speter #define	CRMARG	3
276742Speter #define	CSRMARG	4
277742Speter #define	CNL	5
278742Speter #define	CNLBL	6
279742Speter #define	CFORM	7
280742Speter #define	CINCLUD	8
281742Speter 
282742Speter /*
283742Speter  * Comment structure
284742Speter  * Cmhp is the head of the current list of comments
285742Speter  */
286742Speter struct comment {
287742Speter 	struct	comment *cmnext;
288742Speter 	int	cmdelim;
289742Speter 	struct	commline *cml;
290742Speter 	int	cmjust;
291742Speter 	int	cmseqid;
292742Speter } *cmhp;
293742Speter 
294742Speter /*
295742Speter  * Structure for holding a comment line
296742Speter  */
297742Speter struct commline {
298742Speter 	char	*cmtext;
299742Speter 	int	cmcol;	/* Only used for first line of comment currently */
300742Speter 	struct	commline *cml;
301742Speter };
302742Speter 
303742Speter struct W {
304742Speter 	int	Wseqid;
305742Speter 	int	Wcol;
306742Speter } yyw[MAXDEPTH + 1], *yypw;
307742Speter 
308742Speter #define	commform()	quickcomm(CFORM)
309742Speter #define	commnl()	quickcomm(CNL)
310742Speter #define	commnlbl()	quickcomm(CNLBL)
311742Speter #endif
312