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