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